0

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')```

0

Looks like you are not comparing the correct items. If I print out the code you have here:

for people in databaselist:
    print(people[1:], str(list(maxstr_counts)))
    if people[1:] == str(list(maxstr_counts)): #compare to database
        print(databaselist[people][0])
        exit()
print('No match')

It prints the following:

['2', '8', '3'] ['AGATC', 'AATG', 'TATC']
['4', '1', '5'] ['AGATC', 'AATG', 'TATC']
['3', '2', '5'] ['AGATC', 'AATG', 'TATC']

Find a way to compare the dict values for each person to the max values (not keys) of the maxstr.

I used the enumerate method to access correct values in my equivalent maxstr. the print function really helped me troubleshoot this assignemt - which I FINALLY finished. Good luck

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .