Here is the corrected code from shane.neely, which is otherwise very elegant and useful:
beans = "TGACTGTGTTTCTGAACAATAAATGACTTAAACCAGGTATGGCTGCCGATGGTTATCTT"
gencode = {
'ATA':'I', 'ATC':'I', 'ATT':'I', 'ATG':'M',
'ACA':'T', 'ACC':'T', 'ACG':'T', 'ACT':'T',
'AAC':'N', 'AAT':'N', 'AAA':'K', 'AAG':'K',
'AGC':'S', 'AGT':'S', 'AGA':'R', 'AGG':'R',
'CTA':'L', 'CTC':'L', 'CTG':'L', 'CTT':'L',
'CCA':'P', 'CCC':'P', 'CCG':'P', 'CCT':'P',
'CAC':'H', 'CAT':'H', 'CAA':'Q', 'CAG':'Q',
'CGA':'R', 'CGC':'R', 'CGG':'R', 'CGT':'R',
'GTA':'V', 'GTC':'V', 'GTG':'V', 'GTT':'V',
'GCA':'A', 'GCC':'A', 'GCG':'A', 'GCT':'A',
'GAC':'D', 'GAT':'D', 'GAA':'E', 'GAG':'E',
'GGA':'G', 'GGC':'G', 'GGG':'G', 'GGT':'G',
'TCA':'S', 'TCC':'S', 'TCG':'S', 'TCT':'S',
'TTC':'F', 'TTT':'F', 'TTA':'L', 'TTG':'L',
'TAC':'Y', 'TAT':'Y', 'TAA':'_', 'TAG':'_',
'TGC':'C', 'TGT':'C', 'TGA':'_', 'TGG':'W'}
basepairs = {'A':'T', 'C':'G', 'G':'C', 'T':'A'}
def translate_frameshifted( sequence ):
translate = ''.join([gencode.get(sequence[3*i:3*i+3],'X') for I in range(len(sequence)//3)])
return translate
def reverse_complement( sequence ):
reversed_sequence = (sequence[::-1])
rc = ''.join([basepairs.get(reversed_sequence[i], 'X') for I in range(len(sequence))])
return rc
print(translate_frameshifted(beans[0:])) # first frame
print(translate_frameshifted(beans[1:])) # second frame
print(translate_frameshifted(beans[2:])) # third frame
print(translate_frameshifted(reverse_complement(beans))) # negative first frame
print(translate_frameshifted(reverse_complement(beans[:len(beans)-1]))) # negative second frame
print(translate_frameshifted(reverse_complement(beans[:len(beans)-2]))) # negative third frame
# This ::-1 syntax in python means reverse the string.
Hello, the Emboss util doesn't work:
Even though a minimum size for ORFs is set, smaller ORFs are reported, and the first AA is not always M, but it should be.