0
import csv
import sys

def maxrepeats(sequences, substring):
    # calculate maximum consecutive frequency for each STR
    repeats = [0] * (len(sequences)+1)

    for i in range(len(sequences)-len(substring), -1, -1):
        if sequences[i:i+len(substring)] == substring:
            repeats[i] = 1 + repeats[i+len(substring)]

    return(max(repeats))


def main():
    # comand line argument check
    while len(sys.argv) is not 3:
        print("Usage: python dna.py data.csv sequence.txt")

        if len(sys.argv) is 3:
            break

    # open database
    csv_file = open(sys.argv[1])
    database = csv.reader(csv_file)

    # open sequences
    dna_file = open(sys.argv[2])
    sequences = dna_file.read()

    # For each of the STRs (from the first line of the CSV file), find the longest run of consecutive repeats
    sequencevalues = next(database)[1:]
    maxcounts = [maxrepeats(sequences, substring) for substring in sequencevalues]

    for line in sequences:
        person = line[0]
        numbers = [int(value) for value in line[1:]]
        # compare calculated values for maximum consecutive STR frequency with data in csv file
        if numbers == maxcounts:
            print(person)
            return

    print("No match")



main()

As mentioned above, no matter which database and sequence I use the code always returns "No match". I suspect an error with my loops and sub-strings but I can't figure out where...

Thank you for taking a look :)

0

OK so the error was because I looped through the wrong file. I was looping through the DNA sequence instead of the database for the names :/

You must log in to answer this question.

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