0

I am trying to replace a character in a string but it shows "None". This is related to Bioinformatics where we convert a string of sequence from DNA sequence to mRNA sequence to a protein. I want to make the following code work:

li = "ATGC"
def translate(self):
  for a in li:
    if a == "T":
      print(a.replace("T", "U"))
    else:
      print(a)
     
li = translate(li)
li = str(li)
print(li)

li = [li[n:n+3] for n in range(0, len(li), 3)]

nucleotide_sequence_lookup_table = {
    'AUG': "M",
    'UUU': "F",
    'UUC': "F",
    'UUA': "L",
    'UUG': "L",
    'CUU': "L",
    'CUC': "L",
    'CUA': "L",
    'CUG': "L",
    'AUU': "I",
    'AUC': "I",
    'AUA': "I",
    'GUU': "V",
    'GUC': "V",
    'GUA': "V",
    'GUG': "V",
    'UCU': "S",
    'UCC': "S",
    'UCA': "S",
    'UCG': "S",
    'CCU': "P",
    'CCC': "P",
    'CCA': "P",
    'CCG': "P",
    'ACU': "T",
    'ACC': "T",
    'ACA': "T",
    'ACG': "T",
    'GCU': "A",
    'GCC': "A",
    'GCA': "A",
    'GCG': "A",
    'UAU': "Y",
    'UAC': "Y",
    'UAA': "STOP",
    'UAG': "STOP",
    'CAU': "H",
    'CAC': "H",
    'CAA': "Q",
    'CAG': "Q",
    'AAU': "N",
    'AAC': "N",
    'AAA': "K",
    'AAG': "K",
    'GAU': "D",
    'GAC': "D",
    'GAA': "E",
    'GAG': "E",
    'UGU': "C",
    'UGC': "C",
    'UGA': "STOP",
    'UGG': "W",
    'CGU': "R",
    'CGC': "R",
    'CGA': "R",
    'CGG': "R",
    'AGU': "S",
    'AGC': "S",
    'AGA': "R",
    'AGG': "R",
    'GGU': "G",
    'GGC': "G",
    'GGA': "G",
    'GGG': "G",
  }
Amino_acid_list = [nucleotide_sequence_lookup_table [i] for i in li[0:-1]]
print(Amino_acid_list)

output of print after function:

A U G C None

Can anyone suggest how can we drop the none in the string and use the rest of the string for translation and transcription?

  • 2
    When you don't add a ```return``` to function, it returns ```None``` by default. In your code, you are printing the values in your function, but ```li = translate(li)``` takes what is returned from function. Since there is no ```return``` statement, you get ```None``` –  Jun 08 '21 at 05:16
  • 1
    Several problems with you program. 1) Inside your `translate` function, you are printing some values in console, but you are not returning any value from the function. 2) Because of that, when you do `li = translate(li)`, you are substituting the value of `li` with `None`, that is what a function returns when you don't specify a return value. 3) When you do `a.replace("T", "U")` you are not replacing that letter in the word, only the letter that you took for iteration – Rodrigo Rodrigues Jun 08 '21 at 05:20
  • ok, Thanks for explaining But my question is how can I get 'li' as a string of AUGC? even if I use 'return' it just returns a particular letter in the sequence and doesn't return the whole string. – Maninder Preet Singh Puri Jun 08 '21 at 14:15

0 Answers0