PYTHON.\" Write a function called start_codon which accepts a DNA sequence as it
ID: 3862450 • Letter: P
Question
PYTHON." Write a function called start_codon which accepts a DNA sequence as its argument and returns the first codon as a string. Assume the sequence is in frame." I'm new to python and can't really figure out how to do this.
Explanation / Answer
def orf_find(st0): seq_0="" for i in range(0,len(st0),3): if len(st0[i:i+3])==3: seq_0 = seq_0 + st0[i:i+3]+ " " ms_1 =[m.start() for m in re.finditer('ATG', seq_0)] ms_2 =[m.start() for m in re.finditer('(TAA)|(TAG)|(TGA)', seq_0)] def get_next(arr,value): for a in arr: if a > value: return a return -1 codons = [] start_codon=ms_1[0] while (True): stop_codon = get_next(ms_2,start_codon) if stop_codon == -1: break codons.append((start_codon,stop_codon)) start_codon = get_next(ms_1,stop_codon) if start_codon==-1: break max_val = 0 selected_tupple = () for i in codons: k=i[1]-i[0] if k > max_val: max_val = k selected_tupple = i print "selected tupple is ", selected_tupple final_seq=seq_0[selected_tupple[0]:selected_tupple[1]+3] print final_seq print "The longest orf length is " + str(max_val) output_file = open('Longorf.txt','w') output_file.write(str(orf_find(st0))) output_file.close()
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.