-2

I need some assistance in writing a code that will convert a given RNA nucleotide sequence into an Amino Acid sequence.

I've currently been given 2 dictionaries to use: one of Amino Acid codons and their respective 3-letter codes, and one of the 3-letter codes and their corresponding 1-letter code.

I need to write a code that will take a give RNA sequence and output the single letter code. Below I've included the 2 provided dictionaries.

RNA_codon_table = {
# U
'UUU': 'Phe', 'UCU': 'Ser', 'UAU': 'Tyr', 'UGU': 'Cys', # UxU
'UUC': 'Phe', 'UCC': 'Ser', 'UAC': 'Tyr', 'UGC': 'Cys', # UxC
'UUA': 'Leu', 'UCA': 'Ser', 'UAA': '---', 'UGA': '---', # UxA
'UUG': 'Leu', 'UCG': 'Ser', 'UAG': '---', 'UGG': 'Trp', # UxG

# C
'CUU': 'Leu', 'CCU': 'Pro', 'CAU': 'His', 'CGU': 'Arg', # CxU
'CUC': 'Leu', 'CCC': 'Pro', 'CAC': 'His', 'CGC': 'Arg', # CxC
'CUA': 'Leu', 'CCA': 'Pro', 'CAA': 'Gln', 'CGA': 'Arg', # CxA
'CUG': 'Leu', 'CCG': 'Pro', 'CAG': 'Gln', 'CGG': 'Arg', # CxG

# A
'AUU': 'Ile', 'ACU': 'Thr', 'AAU': 'Asn', 'AGU': 'Ser', # AxU
'AUC': 'Ile', 'ACC': 'Thr', 'AAC': 'Asn', 'AGC': 'Ser', # AxC
'AUA': 'Ile', 'ACA': 'Thr', 'AAA': 'Lys', 'AGA': 'Arg', # AxA
'AUG': 'Met', 'ACG': 'Thr', 'AAG': 'Lys', 'AGG': 'Arg', # AxG

# G
'GUU': 'Val', 'GCU': 'Ala', 'GAU': 'Asp', 'GGU': 'Gly', # GxU
'GUC': 'Val', 'GCC': 'Ala', 'GAC': 'Asp', 'GGC': 'Gly', # GxC
'GUA': 'Val', 'GCA': 'Ala', 'GAA': 'Glu', 'GGA': 'Gly', # GxA
'GUG': 'Val', 'GCG': 'Ala', 'GAG': 'Glu', 'GGG': 'Gly'  # GxG
}


singleletter = {'Cys': 'C', 'Asp': 'D', 'Ser': 'S', 'Gln': 'Q', 'Lys': 'K',
'Trp': 'W', 'Asn': 'N', 'Pro': 'P', 'Thr': 'T', 'Phe': 'F', 'Ala': 'A',
'Gly': 'G', 'Ile': 'I', 'Leu': 'L', 'His': 'H', 'Arg': 'R', 'Met': 'M',
'Val': 'V', 'Glu': 'E', 'Tyr': 'Y', '---': '*'}
Chris_Rands
  • 38,994
  • 14
  • 83
  • 119
P. Di Maso
  • 11
  • 4
  • 3
    Coding your Specs does not fit into SO Q&A format - sorry. Good luck with your coding. If you happen to get a solution you could post it as answer to this non-question. If you have a specific problem, consider studying [how-to-ask](https://stackoverflow.com/help/how-to-ask) and [on topic](https://stackoverflow.com/help/on-topic) , provide code respecting [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) and your exception / expectation that do not get met by your code and I am sure SO will help you out. – Patrick Artner Jan 17 '18 at 13:46

1 Answers1

2

You can do this with a list comprehension:

[singleletter[RNA_codon_table[s[i:i+3]]] for i in range(0, len(s),3)]

For example,

>>> s = 'UUUGAUAGC'
>>> [s[i:i+3] for i in range(0, len(s),3)]
['UUU', 'GAU', 'AGC']
>>> [RNA_codon_table[s[i:i+3]] for i in range(0, len(s),3)]
['Phe', 'Asp', 'Ser']
>>> [singleletter[RNA_codon_table[s[i:i+3]]] for i in range(0, len(s),3)]
['F', 'D', 'S']

Or, with BioPython:

>>> from Bio.Seq import Seq
>>> from Bio.Alphabet import IUPAC
>>> s = Seq('UUUGAUAGC', IUPAC.unambiguous_rna)
>>> s.translate()
Seq('FDS', IUPACProtein())
Chris_Rands
  • 38,994
  • 14
  • 83
  • 119