-2

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

1 Answers1

0

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 += '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('-', '')
supersquires
  • 141
  • 3
  • Hmmm, I am getting an AttributeError when I run this code. (AttributeError: 'str' object has no attribute 'append'). What does this mean and how do I fix it? – Mykita Zolov Nov 02 '22 at 22:15
  • Is there any way I could go about this using the previous function "transcribe()" that I made? – Mykita Zolov Nov 02 '22 at 22:42
  • Sorry about that, got tripped up with C++ haha. As edited above, use `+=` rather than `.append()` – supersquires Nov 08 '22 at 21:59
  • You can certainly use the function; It would make the most sense to include everything in it. So, let the function body be the `dna_list[i] = seq.replace('T', 'U').replace('-', '')`, then call the function for every sequence – supersquires Nov 08 '22 at 22:00