I'm trying to record the longest run of each STR I need and I'm close. Without the final "else" the code works fine with small dictionary and almost fine with long (because the count I useonce doesn't get back to zero if another run of the same STR starts again) But if I put the "else" to solve that problem the code says that the longest run is always 1. Why is the "else" messing everything up? here is my code:
with open (argv[2], 'r') as (txtfile):
dna = txtfile.read()
countAGATC = 0
countAATG = 0
countTATC = 0
maxAGATC = 0
maxAATG = 0
maxTATC = 0
for i in range(len(dna)):
if dna[i:i+5] == 'AGATC':
countAATG = 0
countTATC = 0
countAGATC += 1
i = i+5
if countAGATC > maxAGATC:
maxAGATC = countAGATC
elif dna[i:i+4] == 'AATG':
countAGATC = 0
countTATC = 0
countAATG += 1
i = i+4
if countAATG > maxAATG:
maxAATG = countAATG
elif dna[i:i+4] == 'TATC':
countAGATC = 0
countAATG = 0
countTATC += 1
i = i+4
if countTATC > maxTATC:
maxTATC = countTATC
else:
countAGATC = 0
countAATG = 0
countTATC = 0
result without else:
small dictionary : 4,1,5 and correct answer is 4,1,5
large dictionary: 37,12,51 and correct answer is 37,10,48
result with else: (1,1,1) with both dictionaries
thanks for your time!