|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +""" |
| 3 | +Created on Thu Nov 16 21:04:20 2017 |
| 4 | +
|
| 5 | +@author: Prince Adeyemi |
| 6 | +""" |
| 7 | + # check the length of the sequence is divisible by 3: |
| 8 | + # loop through the sequence |
| 9 | + # extract codon |
| 10 | + # save result in a var |
| 11 | + # tested with real dna strands downloaded from ncbi |
| 12 | + # data from https://www.ncbi.nlm.nih.gov/search/?term=NM_207618.2 |
| 13 | + |
| 14 | +def translate_dna(seq): |
| 15 | + """ DNA Translator translates a string containing |
| 16 | + nucleotide sequence into a string containing the corresponding |
| 17 | + sequence of amino acids. Nuclotides are translated in triplet |
| 18 | + using the table dictionary; each amino acid is encoded in a string |
| 19 | + of length 3 . Tested with real dna strands downloaded from ncbi |
| 20 | + # data from https://www.ncbi.nlm.nih.gov/search/?term=NM_207618.2""" |
| 21 | + |
| 22 | + table = { |
| 23 | + 'ATA':'I', 'ATC':'I', 'ATT':'I', 'ATG':'M', |
| 24 | + 'ACA':'T', 'ACC':'T', 'ACG':'T', 'ACT':'T', |
| 25 | + 'AAC':'N', 'AAT':'N', 'AAA':'K', 'AAG':'K', |
| 26 | + 'AGC':'S', 'AGT':'S', 'AGA':'R', 'AGG':'R', |
| 27 | + 'CTA':'L', 'CTC':'L', 'CTG':'L', 'CTT':'L', |
| 28 | + 'CCA':'P', 'CCC':'P', 'CCG':'P', 'CCT':'P', |
| 29 | + 'CAC':'H', 'CAT':'H', 'CAA':'Q', 'CAG':'Q', |
| 30 | + 'CGA':'R', 'CGC':'R', 'CGG':'R', 'CGT':'R', |
| 31 | + 'GTA':'V', 'GTC':'V', 'GTG':'V', 'GTT':'V', |
| 32 | + 'GCA':'A', 'GCC':'A', 'GCG':'A', 'GCT':'A', |
| 33 | + 'GAC':'D', 'GAT':'D', 'GAA':'E', 'GAG':'E', |
| 34 | + 'GGA':'G', 'GGC':'G', 'GGG':'G', 'GGT':'G', |
| 35 | + 'TCA':'S', 'TCC':'S', 'TCG':'S', 'TCT':'S', |
| 36 | + 'TTC':'F', 'TTT':'F', 'TTA':'L', 'TTG':'L', |
| 37 | + 'TAC':'Y', 'TAT':'Y', 'TAA':'_', 'TAG':'_', |
| 38 | + 'TGC':'C', 'TGT':'C', 'TGA':'_', 'TGG':'W', |
| 39 | + } |
| 40 | + |
| 41 | + protein = "" |
| 42 | + if len(seq) % 3 == 0: |
| 43 | + for i in range(0, len(seq), 3): |
| 44 | + codon = seq[i : i+3] |
| 45 | + protein += table[codon] |
| 46 | + |
| 47 | + return protein |
0 commit comments