Reputation: 69
I have a program that reads in a input text file (DNA.txt) of a DNA sequence, and then translates the DNA sequence (saved as a string) into various amino acid SLC codes using this function:
def translate(uppercase_dna_sequence, codon_list):
slc = ""
for i in range(0, len(uppercase_dna_sequence), 3):
codon = uppercase_dna_sequence[i:i+3]
if codon in codon_list:
slc = slc + codon_list[codon]
else:
slc = slc + "X"
return slc
I then have a function that creates two output text files called:
normalDNA.txt and mutatedDNA.txt
Each of these files has one long DNA sequence.
I now want to write a function that allows me to read both these files as input files, and use the "translate" function mentioned above to translate the DNA sequences that are in the containing text files. (just like I did the original DNA.txt file mentioned at the top of this explanation) but using the original translate function. (So I assume I am trying to inherit the other function's properties to this one). I have this code:
def txtTranslate(translate):
with open('normalDNA.txt') as inputfile:
normalDNA_input = inputfile.read()
print normalDNA_input
with open('mutatedDNA.txt') as inputfile:
mutatedDNA_input = inputfile.read()
print mutatedDNA_input
return txtTranslate
The program runs when I call it with:
print txtTranslate(translate)
But it prints:
function txtTranslate at 0x103bf39b0>
I want the second function (txtTranslate) to read in the external text files, and then have the first function translate the inputs and "print"out the result to the user...
I have my full code available on request, but i think I'm missing something small, hopefully! or should I put everything into classes with OOP?
I'm new to linking two functions, so please excuse the lack of knowledge in the second function...
Upvotes: 0
Views: 918
Reputation: 76244
This doesn't have anything to do with inheritance. If you want txtTranslate
to execute translate
, you have to actually call it. Try:
def txtTranslate():
with open('normalDNA.txt') as inputfile:
normalDNA_input = inputfile.read()
print normalDNA_input
with open('mutatedDNA.txt') as inputfile:
mutatedDNA_input = inputfile.read()
print mutatedDNA_input
#todo: get codon_list from somewhere
print translate(normalDNA_input, codon_list)
print translate(mutatedDNA_input, codon_list)
txtTranslate()
Upvotes: 2