I'm currently trying to find the complementary strand of DNA, meaning I have to replace all Ts with As, As with Ts, Cs with Gs, and Gs with Cs. I have been trying to find a way to do this that doesn't result in the program returning entirely one letter and I think I found the way but now every time I run it I receive an error telling me to convert a line to str and I can't place where it should be or why, here's the code I have currently:
#open file with DNA strand
df = open('dnafile.txt','r')
#function for finding complementary strand
def encode(code,DNA):
for k in code:
DNA = DNA.replace(k,code[k])
print('The complementary strand is: ' + DNA)
#carrying out function
code = {ord('A'):'T', ord('T'):'A', ord('G'):'C', ord('C'):'G'}
DNA = df.read()
encode(code,DNA)