Cristiana Banila
Cristiana Banila

Reputation: 11

Translation of genetic code to protein amino acids using python

I need to write a program that asks the user for a nucleotide sequence and translates it into amino acids and use a specific genetic table. This is the code I came up with but it is not working.

def sequence(code):

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'}

seq = (seq for seq in code.split())
result = []

for x in seq:
    result.append("".join(seq[char] if x in gencode.keys() else char for char in x))
    return "".join(result)`enter code here`


if __name__ == "__main__":
    code = input("Your sequence: ")
    print (sequence(code))

Upvotes: 1

Views: 172

Answers (1)

Adri
Adri

Reputation: 599

What isn't working ?

Here, you just defined the function sequence, taking code as a parameter.

You need to call it. You can find here some informations about functions.

Upvotes: 1

Related Questions