def translateGene(dnaStrand, startPos, stop):
protein = []
def aminoAcid(dnaCodon):
return(dnaCode[dnaCodon])
maybeCodon = [dnaStrand[i:i +3] for i in range (startPos, stop-1)]
for j in maybeCodon:
if j == (dnaCode[dnaCodon]):
protein.append(j)
return protein
This function takes a string, an integer as a starting index in the string and an integer as an ending index in the string. The idea of the program is to split the string into 3 letter acronyms with the letters from the starting point to the endpoint. Then it should look up a given dictionary for all the acronyms and if they are present in the dictionary, add their results to the protein list but my code above leaves protein empty. The function Aminoacid has been created for me to use as part of this function, but I'm not sure if I've called it correctly. My code above leaves protein empty.
Can anyone explain why. Any help is greatly appreciated.
First, I think that your code should be indenting adjusted to:
Then test it.
and notice that, It seems that you have two global
dnaCode
,dnCodon
, which is known before calling the function.