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")

# 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")
            # Save the match with the most repeats in a variable
            max_repeat = max(matches)
            # Store the number of repeats of the STR in the STR_count dict
            STR_count[STR] = (len(max_repeat) / len(STR))
        for row in database:
            if row[STR] == STR_count[f'{STR}']:
                print("No match found")

It looks like you are counting all the STR being repeated in the sequence and not just consecutive ones. We are supposed to count only the consecutively repeating STR and count the max consecutive repeats. But I am not too familiar with this syntax as I myself am a newbie to all this so cant be 100% sure i understood your code correctly. Have a good day :)

  • Thanks for your suggestion Himanshi, but I think that part is returning what I expected. Have a good day! – Ewan Willsmer Jul 29 '20 at 7:54

You must log in to answer this question.

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