Home > Net >  Transcribe a function and remove blank characters (-)
Transcribe a function and remove blank characters (-)

Time:11-03

Write a function make_vax, which takes a list of arbitrary number of dna sequences, and both removes gaps ("-" characters) and transcribes the sequence to mRNA. It returns a list with gap-less mRNA sequences of the same length as the input list.

def make_vax(dna_list):
# your code here
mRNA = transcribe(dna_list)
for i in range(mRNA):
    if i == '-':
        mRNA.pop(i)

return mRNA

This is the idea that I have but I do not know where to go from here.

My test cases for make_vax are the following, and both of them need to be true.

print(make_vax(["ATGCAT---GCT"])==['AUGCAUGCU'])
print(make_vax(["TTTTTTTTTTTT","ATGCAT---GCT"])==['UUUUUUUUUUUU','AUGCAUGCU'])

I also already have a function which transcribes a inputted dna sequence.

def transcribe(dna):
"""This function will return a RNA sequence after replacing 'T' with 'U'."""
# your code here    
rna = dna.replace("T", "U")

return rna

CodePudding user response:

You almost had it. Your loop should be for i in range(len(mRNA)).

More concisely:

rna_list=[]
for seq in dna_list:
    mRNA = ''
    for char in seq:
        if char == 'T':
            mRNA.append('U')
        elif char != '-':
            mRNA.append(char)
    rna_list.append(mRNA)

Or, even more concisely:

for i, seq in enumerate(dna_list):
    dna_list[i] = seq.replace('T', 'U').replace('-', '')
  • Related