Im struggling with the PSET6 DNA solution. So far I have opened the dna file and converted it into a dictionary as well as reading the text file. I'm trying to count the consecutive times an STR occurs in the text file but my code does not seem to work. In my code as per below I've tried to execute:
For each key in the newly established dictionary which corresponds to a STR and for each character in the text file if the ith character plus the length of the key is equal to the key while the next sequence is the same as the one before then increment a temp counter and if the temp counter is greater than the max_count then replace the max_count with the temp variable. Would appreciate any tips or suggestions with my code below! Thanks!
from sys import argv
import csv
if len(argv) != 3:
print("Usage: python dna.py data.csv sequence.txt")
with open(argv[1], "r") as dna_file:
dna_list = csv.reader(dna_file)
for row in dna_list:
dna_samples = row
dna_samples.pop(0)
print(dna_samples)
break
dna_dict = {}
for item in dna_samples:
dna_dict[item] = 0
print(dna_dict)
with open(argv[2], "r") as f:
text_data = f.read()
for key in dna_dict:
l = len(key)
for i in range(0, len(text_data)):
if text_data[i:l] == key:
temp = 0
max_count = 0
while text_data[i: i + l] == text_data[i - l: i]:
temp += 1
i += l
if temp > max_count:
max_count = temp
print(temp)
print(max_count)