Hi I`m currently working on a small project for school and the task is to write a function which takes a dna strand and a position and checks whether the DNA is complement before and after the picked position. this is the code i came up with so far. the translate function is just to check complementarity and it workes just fine. but if i try to feed a DNA to the lis function, i get an error.
File "xxx", line 37, in lis
while translate(dna[pos(1-i)],dna[pos(1+i)])=="TRUE":
TypeError: 'int' object is not callable
does anybody know what is going wrong there?
def translate(seq, comp):
#matchlist and checklist
basecomplement = {'A': 'T', 'C': 'G', 'G': 'C', 'T': 'A'}
baselist = ["A","T","G","C"]
#check wether the input is a DNA
if seq not in baselist:
print("FALSE")
elif comp not in baselist:
print("FALSE")
#check if the two (or more) bases are complements
else:
aaseq = []
comp = [comp]
for character in seq:
aaseq.append(basecomplement[character])
print(aaseq)
#print result
if aaseq == comp:
print("TRUE")
else:
print("FALSE")
def lis(dna, pos):
#make a list from DNA input
dna = [dna]
#go to pos in DNA list
for pos in range(len(dna)):
i=1
#check if position before and after pos are complements
#and advance a position if true else stop
while translate(dna[pos(1-i)],dna[pos(1+i)])=="TRUE":
i+=1
return(pos-i + pos+i)
break
A few things for you to fix in here...
pos
is an integer, not a function so pos(1-i)
is causing the error in your post. This should be something like dna[pos-1]
and dna[pos+1]
range
starts at 0 so 0-1
is going to be -1
and will throw an out of range error as welltranslate()
isn't returning anything, only printing. You need return ("TRUE")
. You'd also be better off using boolean True
and False
here instead of strings.I didn't go through your entire snippet, so there may be more quirks...