0

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)

1 Answer 1

0

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

1
  • Thanks for your suggestion Himanshi, but I think that part is returning what I expected. Have a good day! Commented Jul 29, 2020 at 7:54

You must log in to answer this question.

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