-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathORF.py
More file actions
36 lines (31 loc) · 1.13 KB
/
ORF.py
File metadata and controls
36 lines (31 loc) · 1.13 KB
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
# Finding the Longest Open Reading Frame (ORF)
def find_orfs(dna_sequence):
"""
Finds all open reading frames (ORFs) in the DNA sequence and returns the longest one.
ORF = starts with 'ATG' and ends with a stop codon ('TAA', 'TAG', 'TGA').
"""
stop_codons = ["TAA", "TAG", "TGA"]
longest_orf = ""
for frame in range(3): # 3 possible reading frames
i = frame
while i < len(dna_sequence) - 2:
codon = dna_sequence[i:i+3]
if codon == "ATG": # Start codon
j = i
while j < len(dna_sequence) - 2:
next_codon = dna_sequence[j:j+3]
if next_codon in stop_codons:
orf = dna_sequence[i:j+3]
if len(orf) > len(longest_orf):
longest_orf = orf
break
j += 3
i += 3
return longest_orf
# Example DNA sequence
dna = "ATGAAATGAAAAATAGGGTGACATGCCCTAA"
# Run the function
longest = find_orfs(dna)
print("DNA Sequence:", dna)
print("Longest ORF:", longest)
print("Length of ORF:", len(longest))