I've been working on DNA for a while now and thought I was done, but there's a problem with my code. Everytime I run it, the program just prints the first name on the database, so either 'Albus' or 'Alice'. I relied heavily on code I found online (will cite my sources when I turn it in) so don't really know what's wrong. Any help would be greatly appreciated!

from csv import reader, DictReader
from sys import argv

def main():
    # Number of command line arguments
    if len(argv) != 3:
        print ("Incorrect number of command line arguments")
        exit ()

    # Reading database
    with open(argv[2]) as dnafile:
        dnareader = reader(dnafile)
        for row in dnareader:
            dnalist = row
    #Storing it in a string
    dna = dnalist[0]
    #Creating a dictionary with sequences we want to count
    sequences = {}

    #Opening the sequence
    with open(argv[2]) as peoplefile:
        people = reader(peoplefile)
        for row in people:
            dnaSequences = row
    #Copying the list in a dictionary where the genes are the keys
    for item in dnaSequences:
        sequences[item] = 1
    #Iterating through the different STRs
    for key in sequences:
        l = len(key)
        countMax = 0
        count = 0
        #Iterating over the dna sequence
        for i in range(len(dna)):
            while count > 0:
                count -= 1;
            #Finding repeated STRs
            if dna[i : i + l] == key:
                while dna[i - l : i] == dna[i: i + l]:
                    count += 1
                    i += l
            #Finding maximum number of repeats
            if count > countMax:
                countMax = count
        #Putting final amount in dictionary
        sequences[key] += countMax
    #Matching people with DNA
    with open(argv[1], newline='') as peoplefile:
        people = DictReader(peoplefile)
        for person in people:
            match = 0
            # compares the sequences to every person and prints name before leaving the program if there is a match
            for dna in sequences:
                if sequences[dna] == int(person[dna]):
                    match += 1
            if match == len(sequences):
        print("No match")

  • Have you tried running debug50 and stepping through your code to see how the contents of variables are changing etc?
    – Sentox
    Nov 29 '20 at 6:02

You must log in to answer this question.

Browse other questions tagged .