My dna program always returns no match and after debugging it I've pin pointed the problem to the counter not updating correctly. My program finds the correct number of matches, which I've confirmed by printing them out, but the counter doesn't increment itself for some reason.
for str in header[1:]:# look at data for first str
for char in range(len(tf)): #looking at every char for the length of the text file
if str == tf[char:char+len(str)]: #compare the current str against the next set of values that are the same length as the str
cc += 1 #if its a match add to the counter
if char + len(str) < len(tf):
char += len(str)-1 # subtract 1 since it already iterates by 1
#example we start at 0 and its a match so move it up 4 and well start at index 4 next, which is the next set to test
print(str)
else: #if its not a match
if cc > tmax: #if the current count is larger then
tmax = cc #change the temp max
cc = 0 #reset the count
print(tmax)
Maxlist.append(tmax)#set the current index to the max we found, appending it on since the list wasnt predefined
tmax = 0 #reset the max for the next str
cc = 0 #reset the count
Printing in different parts of the code I can get results like this, and I can see that before tmax is appended to the list it's only 1, despite printing the match in the same section where the counter should have increased by 1:
AGATC
AGATC
AGATC
AGATC
1
AATG
1
TATC
TATC
TATC
TATC
TATC
1
No Match
[1, 1, 1]
So my code can correctly find the correct amount of sequential strs to what the first check is looking for, i.e. Bob, but the counter remains at 1 no matter how many correct sequences it finds. What am I missing here? Also if it matters, the output doesn't change if I increment char with char += len(str)-1 or char += len(str), I thought I'd need to subtract 1 since the for loop already increments char by 1 on it's own, but it doesn't make any difference.