简体   繁体   中英

Translation and Use of Stop Codon using list comprehension python

I'm trying to write a function about open reading frame using a dictionary of only the stop codon. The program takes in three letter at a time and if that three letter is one of that stop codon, the program stops and counts the number of letters (the stop codon is NOT counted, nor is anything afterwards). For example, nextStop2('AAAAAAAGTGGGTGCTAGGTTGGC') should return 15. I'm not sure why but the code I wrote below doesn't seem to work. Can anyone give me any advice on how to improve? Thanks!

def nextStop2(Seq):
    GeneticCodeStop = {'TAA':'X', 'TAG':'X', 'TGA':'X'}
    seq2 = ''.join(end_of_loop() if GeneticCodeStop[i]=='X' else i for i in Seq)
    return len((seq2)/3)

your parens are off you should write len(seq2)/3. but you don't want to divide by 3 (you expect 15 and not 5) so just return len(seq2).

def nextStop2(Seq):
    GeneticCodeStop = ['TAA', 'TAG', 'TGA']
    seq2=''
    for i in range(0,len(Seq),3) :
        codon=Seq[i:i+3]
        if codon in GeneticCodeStop:
            break
        seq2+=codon
    return len(seq2)
    
print(nextStop2('AAAAAAAGTGGGTGCTAGGTTGGC') )
>>> 15

but i don't know biopython, and i think it should have a function to do this

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM