/
Genome.py
36 lines (28 loc) · 1.02 KB
/
Genome.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from potential_gene import is_potential_gene
class Genome:
def __init__(self, sequence):
if len(sequence) % 3 != 0:
raise Exception('DNA sequence must have a length that is multiple of 3')
self._sequence = sequence
def __iadd__(self, codons):
if len(codons) % 3 != 0:
raise Exception('codon length must have a length that is multiple of 3')
self._sequence += codons
return self
def __str__(self):
return self._sequence
def __getitem__(self, index):
if isinstance(index, int):
return self._sequence[index: index+3]
def __iter__(self):
for i in range(0, len(self._sequence)//3):
yield self[i]
def base_at(self, index):
return self._sequence[index]
def is_potential_gene(self):
return is_potential_gene(self._sequence)
if __name__ == "__main__":
a = 'ATGCGCCTGCGTCTGTACTAG'
g = Genome(a)
print(g, g.base_at(3), g.is_potential_gene(), g[0])
print(tuple(g))