Stuck on CS-50 DNA, my code is able to accurately derived the STR sequence for the small csv files: Alice and Bob, but when passed the large csv files the programs over counts the number of consecutive repeats of the sequence.

Any tips, would be greatly appreciated!!!

My code includes a bunch of print statement.

import csv
import sys
STR_num = 1

## Variable Declariation
STR = []
STR_num = 1
STR_long = {}

## declaration of temp vairable
STR_counter = 0
STR_index = 0
STR_list = []

## Checking to make sure that the user provided a valid input
if len(sys.argv) < 3:
    print('Please provide a valid input')

## Open data.csv and read content into memory, saving the first line of the file into a variable dna_data
        dna_data = open(sys.argv[1], 'r')
        dna_reader = csv.reader(dna_data)
        STR = next(dna_reader)

## Removing null terminator from current STR sequence
        for s in range(len(STR)):
            STR[s] =  STR[s].replace('\n', '')

## Open and read individial dna sequence .. text file format
        f = open(sys.argv[2])
        sequences = f.read()

## outer loop for each STR seqeunce, excluding the name field
        for i in range(len(STR) - 1):

## rest all temp vairable
            STR_counter = 0
            STR_list = []
            STR_index = 0

## innner loop to count the STR repeats at each point in the DNA sequence

            for i in range(len(sequences)):

                if STR[STR_num] == sequences[i: i + len(STR[STR_num]) ]:
                    STR_counter += 1

                    STR_list.insert(STR_index , STR_counter)
                    STR_index = 1

## Updating dictionary to store the longest STR of the current DNA sequence

            STR_long.update({STR[STR_num]: max(STR_list)})

## check if the current DNA sequence matches any person

## To Do

## Print Test code

            STR_num +=1

## compare STR counts to CSV file to determine if there is any matches

## Print the match if applicable

## close file



You must log in to answer this question.

Browse other questions tagged .