0

so i m a bit confused...i have been testing my code using the small database and what i have so far produced what i expected .... more specifically the STRcounts (i marked that part #?????). it is supposed to find the STR patterns (given in the dictionary) in the dna sequence ...and the numbers match when i test the small database but when i use the large one the counts don`t match ....i think the code is logical unless i misunderstood the .findall() function...? any clarifications would be much appreciated

import sys
import csv
import re


# promp for command line arguments
if len(sys.argv) != 3:
    print("Usage: python dna.py data.csv sequence.txt")

# open sequence (txt file) and save its contents into memory
with open(sys.argv[2], "r") as seq:
    dna_seq = seq.read()

# get a list of the STRs in the file
with open(sys.argv[1], "r") as f:
    reader = csv.reader(f)
    STRs = next(reader)
print(STRs)
  

# calculate the repetions of each STR given in the csv file(in the header)
STRcounts = []
for i in range(1, len(STRs)):
    x = re.findall(STRs[i], dna_seq)    #???????????
    STRcounts.append(len(x))
print(STRcounts)
    
with open(sys.argv[1], "r") as file:
    #calculate the number of rows in the database
    row_count = sum(1 for row in file)
print(row_count)

results = {}
# insert strs and their count into the dictionary
for i in range(len(STRcounts)):
    results[STRs[i + 1]] = STRcounts[i]
0

oh well..i was dumb...the STRs have to repeat next to each other ... re.findall() just returns all of them no matter where they are in the sequence ...

You must log in to answer this question.

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