import csv
import sys
import copy

dbPath = sys.argv[1]
seqPath = sys.argv[2]

if len(sys.argv) > 3:

str_list = []
DB = open(dbPath, 'r')
DBreader = csv.DictReader(DB)
for row in DBreader:
    #    print(DBreader.fieldnames)
    # Store the str for checking in SEQ
    str_list = DBreader.fieldnames
#Remove "Name" field from list

seq_dict ={}
seq_dict = dict.fromkeys(str_list,1)

cur_count = 1
SQ = open(seqPath, "r")
for line in SQ:
    for y in range(len(str_list)):
        for i in range(len(line)):
            #Check for condition of matching fieldname
            if line[i:i+len(str_list[y])] == str_list[y] and line[i:i+len(str_list[y])] == line[i+len(str_list[y]):i+2*len(str_list[y])]:
                #seq_dict[str_list[y]] += 1
                cur_count += 1
                #Replace the value in Dict with Cur_count if exceed
                #To obtain only the largest count of consequtive repeat
                if cur_count > seq_dict[str_list[y]]:
                    seq_dict[str_list[y]] = cur_count
                    cur_count = 1

Per my code above, I've created a dict seq_dict with key:value pairs to store the DNA STR as key and repeat count as value.

The problem I'm facing is that i've created cur_count as a temporary counter to count the consecutive repeat, it will be reset to 1 once the repeats break.

by doing the following line: seq_dict[str_list[y]] = cur_count

I'm passing the pointer of the seq_dict[key] to the cur_count.

Are there any concise value to pass by value in this case?


The first cur_count = 1 would have to be inside the y loop, so numbers don't carry over. Rare case, but still.

If you like to do it that way, I'd write a while loop instead of for i in range, and increment the index manually, incrementing by the str length on a match, and by one on a mismatch/counter reset. Also, I'd use 0 as the starting value, if you advance in the right step size, there's no need to check for actual repetitions.

You must log in to answer this question.

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