-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathORF.py
34 lines (28 loc) · 953 Bytes
/
ORF.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
#!/usr/bin/env python
# Open Reading Frames
from Bio import SeqIO
from Bio.Seq import Seq
import re
import itertools
import bisect
record = SeqIO.read("data/rosalind_orf.txt","fasta")
dna_f = str(record.seq)
dna_r_comp = str(Seq(dna_f).reverse_complement())
proteins = []
def orf(dna):
frames = []
for i in range(3):
dna_tr_i = str(Seq(dna[i:]).translate())
frames.append(dna_tr_i)
for frame in frames:
frame = frame.replace('*', 'B')
start_position = [m.start() for m in re.finditer('M', frame)]
stop_position = [m.start() for m in re.finditer('B', frame)]
for start in start_position:
if start < max(stop_position):
protein_stop = stop_position[bisect.bisect(sorted(stop_position), start)]
proteins.append(frame[start:protein_stop])
orf(dna_f)
orf(dna_r_comp)
for p in list(set(proteins)):
print(p)