Python Programs for Beginner Bioinformatics — Part 3

Symbol C A C G C C C A C
Index 0 1 2 3 4 5
Array 2 1 2 2 3 2
def SymbolArray(Genome, symbol):
array = {}
n = len(Genome)
ExtendedGenome = Genome + Genome[0:n//2]
for i in range(n):
array[i] = PatternCount(ExtendedGenome[i:i+(n//2)], symbol)
return array
def SymbolArray(genome, symbol):
return {i: half_string_symbol_count(genome, symbol, i) for i in range(0, len(genome))}
def half_string_symbol_count(text, symbol, index):
length = len(text)
extended_text = text + text[0:length // 2]
return PatternCount(extended_text[index:index+(length // 2)], symbol)
def FasterSymbolArray(genome, symbol):
initial_value = half_string_symbol_count(genome, symbol, 0)
genome_length = len(genome)
extended_genome = genome + genome[0:genome_length // 2]
indices = list(range(1, genome_length))
constructed_list = list(accumulate(indices,
lambda result, index: update_half_array_symbol_count(extended_genome, index,
genome_length, result, symbol), initial=initial_value))
return dict(enumerate(constructed_list))

def update_half_array_symbol_count(extended_genome, index, original_genome_length, previous_value,
symbol):
return previous_value \
- int(extended_genome[index - 1] == symbol) \
+ int(extended_genome[index + original_genome_length // 2 - 1] == symbol)
Input: CATGGGCATCGGCCATACGCC
Output: 0 -1 -1 -1 0 1 2 1 1 1 0 1 2 1 0 0 0 0 -1 0 -1 -2
Input: TAAAGACTGCCGAGAGGCCAACACGAGTGCTAGAACGAGGGGCGTAAACGCGGGTCCGAT
Output: 11 24
def SkewArray(Genome):
nucleotide_to_value = {"A":0, "T":0, "G":1, "C":-1}
array = list(accumulate(Genome, lambda result, nucleotide: result + nucleotide_to_value[nucleotide], initial = 0))
return array

def MinimumSkew(Genome):
skew_array = SkewArray(Genome)
minimum_skew = min(skew_array)
return [index for index in range(len(skew_array)) if skew_array[index] == minimum_skew]

--

--

--

Educator, Founder @ Interleap

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Embedded-Rust: Build & Flash binary to STM32F3DISCOVERY

What is HTML ?

Turn your Python Script into a ‘Real’ Program with Docker

Starting a career in A.I: A MythBuster (Part 2)

Yet Another Raspberry Pi k8’s Cluster — Part 2: K3s Installation.

Using the 3 S’s to influence operational behaviors and get better results

Bruce Wayne’s Guide To Develop A Car Parking App

An empty car parking space is no more a hassle

We hire skilled AWS Solutions Architects, not just paper-certified ones

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Abhinav

Abhinav

Educator, Founder @ Interleap

More from Medium

Capstone — Week 9

Recognizing Handwritten Digits with Scikit-Learn

ADORING ENGLISH

Python Code for the Beginner Bioinformatics Course — Part 1