The print statements seem to turn out what I hoped for up until trying to compare the STR counts to the database STR counts.
I would just appreciate any pointers of where I'm going wrong thanks.
import sys
import csv
import re
# Checking usage
if len(sys.argv) != 3:
print("Correct program usage: python dna.py database sequence")
sys.exit(1)
# Open the CSV file and DNA sequence, read contents into memory.
# Open the database file in read mode
with open(sys.argv[1], newline='') as csvfile:
database = csv.DictReader(csvfile)
# Open the sequence file in read mode
with open(sys.argv[2], mode='r') as sequence_file:
sequence = sequence_file.read()
# Loop through dictionary keys from the first STR
keys = database.fieldnames
STRS = keys[1:]
for STR in STRS:
# Save STR counts in data structure
STR_count = {STR: 0}
# Using regex, create a list of each match between the STR and sequence
matches = re.findall(rf'(?:{STR})+', sequence)
if not matches:
print("No match found")
exit(2)
print(matches)
# Save the match with the most repeats in a variable
max_repeat = max(matches)
print(max_repeat)
# Store the number of repeats of the STR in the STR_count dict
STR_count[STR] = (len(max_repeat) / len(STR))
print(STR_count)
for row in database:
if row[STR] == STR_count[f'{STR}']:
print(row[0])
else:
print("No match found")
exit(3)