My code works fine for the small csv file; however, when I get to the big csv file, my counts for the number of consecutive STR are less than the actual value by about 1 or 2.
Here is my code:
import csv
from sys import argv, exit
def main():
argcheck()
header = read_header()
sample = read_sequence()
repeat = comp_repeats(header, sample)
check(header, repeat)
def argcheck():
if len(argv) != 3:
print("Usage: python program csvfile txtfile")
exit(1)
return
def read_header():
header = list()
with open(argv[1], "r") as file:
preview = csv.reader(file)
header = next(preview)
return header
def read_sequence():
sample = ""
with open(argv[2], "r") as file:
sample = file.read()
return sample
def comp_repeats(header, sample):
repeat = dict()
for STR in header[1:]:
length = len(STR)
index = 0
final = 0
if STR not in sample:
repeat[STR] = final
else:
for nucleotide in sample:
counter = 0
if nucleotide != STR[0]:
index += 1
continue
else:
while sample[index:index + length] == STR:
counter += 1
index += length
if counter > final:
final = counter
index += 1
repeat[STR] = final
return repeat
def check(header, repeat):
database = dict()
with open(argv[1], "r") as file:
database = csv.DictReader(file)
for row in database:
for STR in header[1:]:
if repeat[STR] == int(row[STR]):
pass
else:
break
if STR == header[-1]:
print(row["name"])
exit(1)
print("No match")
main()
I tried using debug50 but the amount of time it takes to iterate over the entire string of the longer sequences for every STR is far too great to get to the exact moment/moments to see where my code is going wrong. I'm hoping that there's something blatantly wrong with my code that I'm just missing somehow. I would greatly appreciate any help or feedback on my code!