I've been stuck on this pset for days, trying to get some help here :x Basically my program only outputs no match no matter what I do. I tested my re.finditer separately and it prints out what I want, so I'm guessing the problem is when I compare the list of STRs generated with the database list. Would be great if someone could see if I'm missing something! Thanks so much :)
import csv
import sys
import re
l = len(sys.argv)
if l != 3:
print('Usage: python dna.py data.csv sequence.txt')
sys.exit()
file = open(sys.argv[1])
database = csv.reader(file)
#get STRs
firstrow = next(database)
STRs = firstrow[1:]
databaselist = [row for row in database]
with open(sys.argv[2]) as file2:
sequences = file2.read()
maxstr_counts = {}
for STR in STRs:
maxstr_counts[STR] = 0
current_str_list = []
for STR in STRs:
key = rf"({STR})+"
matches = re.finditer(key, sequences) #find repeated STRs
for match in matches:
totallength = match.end() - match.start() #determine longest repetition
STRcount = totallength / len(STR)
current_str_list.append(STRcount)
maxstr_counts[STR] = max(current_str_list)
current_str_list.clear()
for people in databaselist:
if people[1:] == str(list(maxstr_counts)): #compare to database
print(databaselist[people][0])
exit()
print('No match')```