TypeError: object of type 'function' has no len()

2.4k views Asked by At

I'm writing a program that is supposed to take a DNA chain and then change it into an RNA chain, after doing this it's supposed to take the RNA chain and find the amino acids. It seems that my code has a problem on line 30 but I can't find the solution to it. If someone can help me, I will very thankful. Thank you very much.

DNA = input("Good day, please write your DNA chain: ")

DNA = list(DNA)

DNA = (letter.upper() for letter in DNA)


def letters_check (DNAchain) :
    nitrogenbases = ["C", "A", "T", "G"]
    others = [symbol for symbol in DNAchain if symbol not in nitrogenbases]
    if others :
        print("Sorry, but these", others, "are not the DNA elements needed")
    else :
        print("Magnific! This is a great DNA chain")



def mRNA (DNAchain) :
    replacements = {"C":"G","T":"A","G":"C","A":"U"}
    return "".join([replacements[base] for base in DNAchain])
    return "".join([replacements[base] for base in dnachain])

print ("mRNA(DNA): " ,mRNA(DNA))



def findStartStop(DNAchain):
    for x in range(len(DNAchain)):
        if DNAchain[x:x+3] == "AUG" :
            tmprna = DNAchain[x:]
            print("Found the start! tmprna: ", tmprna)
            return tmprna
    for x in range(len(tmprna)):
        tmprna2 = tmprna[x:x+3]
        if tmprna2 == "UAG" or tmprna2 == "UAA" or tmprna2 == "UGA" :
            tmprna2 = tmprna[:x+3]
            print("Found the stop! tmprna2: ",tmprna2)
            break


def finalrna(tmprna2) :
   Translation = {"UUU":"Phe", "UUC":"Phe", "UUA":"Leu", "UUG":"Leu", 'UCU':'Ser', 'UAU':'Tyr', 'UGU':'Cys', 'UCC':'Ser', 'UAC':'Tyr', 'UGC':'Cys', 'UCA':'Ser', 'UAA':'Stop', 'UGA':'Stop', 'UCG':'Ser', 'UAG':'Stop', 'UGG':'Trp', 'CUU':'Leu', 'CCU':'Pro', 'CAU':'His', 'CGU':'Arg', 'CUC':'Leu', 'CCC':'Pro', 'CAC':'His', 'CGC':'Arg', 'CUA':'Leu', 'CCA':'Pro', 'CAA':'Gln', 'CGA':'Arg', 'CUG':'Leu', 'CCG':'Pro', 'CAG':'Gln', 'CGG':'Arg', 'AUU':'Ile', 'ACU':'Thr', 'AAU':'Asn', 'AGU':'Ser', 'AUC':'Ile', 'ACC':'Thr', 'AAC':'Asn', 'AGC':'Ser', 'AUA':'Ile', 'ACA':'Thr', 'AAA':'Lys', 'AGA':'Arg', 'AUG':'Met', 'ACG':'Thr', 'AAG':'Lys', 'AGG':'Arg', 'GUU':'Val', 'GCU':'Ala', 'GAU':'Asp', 'GGU':'Gly', 'GUC':'Val', 'GCC':'Ala', 'GAC':'Asp', 'GGC':'Gly', 'GUA':'Val', 'GCA':'Ala', 'GAA':'Glu', 'GGA':'Gly','GUG':'Val','GCG':'Ala','GAG':'Glu','GGG':'Gly'}
    for y in range(0,len(tmprna2),3):
        print(Translation[tmprna2[x:x+3]])
        print("This is your new code! finalrna: ",  tmprna2[x:x+3])


print(letters_check(DNA))
print("your RNA is:", mRNA(DNA))
print(findStartStop(mRNA))
print(finalrna(tmprna2))

#Taken from: http://www.hgvs.org/mutnomen/codon.html and       http://www.dia.uniroma3.it/~paoluzzi/web/did/bioinf/2010/slides/lezione10.pdf
1

There are 1 answers

0
Gerrat On

This line:

DNA = (letter.upper() for letter in DNA)

creates a generator function. ...and you can't get the len() of a function.

You probably want to just make a list here:

DNA = [letter.upper() for letter in DNA]

...and you should probably also remove this line:

return "".join([replacements[base] for base in dnachain])

It has the wrong case for your DNAchain variable, and the line won't be reached anyway.