0

My pset has some issues,can you please tell me what do i have to change in the main function in order to print name of longest DNA matched person.

import csv import sys

def main():

# TODO: Check for command-line usage
if len(sys.argv) != 3:
   print("Usage: python dna.py data.csv sequence.txt")
arr = []
counter = 0

# TODO: Read database file into a variable
with open(sys.argv[1], "r") as file1: # persons dna
    db_file_reader = csv.reader(file1)
    for data in db_file_reader:
        arr.append(data)


substr = data[1:]
# TODO: Read DNA sequence file into a variable
with open(sys.argv[2], "r") as file2: # sequence of dna to compare with db_file_reader
     seq_file_reader = csv.reader(file2)

# TODO: Find longest match of each STR in DNA sequence


     for seq in seq_file_reader:
         match = longest_match(seq, substr)


# TODO: Check database for matching profiles

     if match == substr:
        print(substr["name"])
     else:
        print("No match")

return

def longest_match(sequence, subsequence): """Returns length of longest run of subsequence in sequence."""

# Initialize variables
longest_run = 0
subsequence_length = len(subsequence)
sequence_length = len(sequence)

# Check each character in sequence for most consecutive runs of subsequence
for i in range(sequence_length):

    # Initialize count of consecutive runs
    count = 0

    # Check for a subsequence match in a "substring" (a subset of characters) within sequence
    # If a match, move substring to next potential match in sequence
    # Continue moving substring and checking for matches until out of consecutive matches
    while True:

        # Adjust substring start and end
        start = i + count * subsequence_length
        end = start + subsequence_length

        # If there is a match in the substring
        if sequence[start:end] == subsequence:
            count += 1

        # If there is no match in the substring
        else:
            break

    # Update most consecutive matches found
    longest_run = max(longest_run, count)

# After checking for runs at each character in seqeuence, return longest run found
return longest_run

main()

1 Answer 1

0

you forgot to put an sys.exit(0) in the line three under your if statement .

You must log in to answer this question.

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