Write a function named one_frame
that takes one argument seq
and performs the tasks specified below. The argument seq
is to be a string that contains information for the bases of a DNA sequence.
get_orf
on the slice of the string beginning at that start codon.get_orf
is added to a list of ORFs.The function should return a list of all ORFs it has found.
def one_frame(seq):
start_codon = 'ATG'
list_of_codons = []
y = 0
while y < len(seq):
subORF = seq[y:y + 3]
if start_codon in subORF:
list_of_codons.append(get_orf(seq))
return list_of_codons
else:
y += 3
one_frame('ATGAGATGAACCATGGGGTAA')
one_frame
at the very bottom is a test case. It is supposed to be equal to ['ATGAGA', 'ATGGGG']
, however my code only returns the first item in the list.You have several problems:
You have return list_of_codons
inside the loop. So you return as soon as you find the first match and only return that one. Put that at the end of the function, not inside the loop.
You have y += 3
in the else:
block. So you won't increment y
when you find a matching codon, and you'll be stuck in a loop.
You need to call get_orf()
on the slice of the string starting at y
, not the whole string (task b).
Task d says you have to skip to the point after the ORF that was returned in task b, not just continue at the next codon.
def one_frame(seq):
start_codon = 'ATG'
list_of_orfs = []
y = 0
while y < len(seq):
subORF = seq[y:y + 3]
if start_codon = subORF:
orf = get_orf(seq[y:])
list_of_orfs.append(orf)
y += len(orf)
else:
y += 3
return list_of_orfs
one_frame('ATGAGATGAACCATGGGGTAA')