0

The problem happens with the count when i try to count STRs, it counts some str right and some wrong, which is strange for me, and when i deal with small csv all works fine. can someone help me in this code? i've commented some prints that will help anyone to get my code, but the idea is that i get each title and compare it with the sequence stream and do an offset whenever i see an STR like "AATG" By Four to get the first letter after 4 characters to search

from sys import argv, exit
import csv

#To ensure user had put the write input
if len(argv) != 3:
    print("ERROR! Usage: python dna.py CSVfile sequence Of DNA")
    exit(1)

filename = argv[1]
textfile = argv[2]

fields = []
rows = []

with open(filename, "r") as file:

    csvreader = csv.reader(file)
    fields = next(csvreader)

    for row in csvreader:
        rows.append(row)

# print("rows= ", rows)
# print("fields= ", fields)

with open(textfile, "r") as sequence:

    results = []
    
    # print("seq = ",sequence)
    s = sequence.readline()
    print("S= ", s)

    #to loop over each field to search it in sequence given, for example: AATG in 1.txt
    for i in range(1, len(fields)):

        counter = 0
        maxcount = 0

        # print("len(fields)", len(fields))
        # print("fields[i]", fields[i])
        # print("len(fields[i])", len(fields[i]))

        index = s.find(fields[i])
        # print("index", index)

        for j in range(index, len(s) +1, len(fields[i])):

            if s[j : j + len(fields[i])] == fields[i]:

                counter += 1
            else:

                if counter > maxcount:
                    maxcount = counter
                counter = 0
        results.append(maxcount)

print(results)


for i in range(
    0, csvreader.line_num - 1):
    
    counter = 1
    for j in range(1, len(fields)):
        
        if int(rows[i][j]) == results[j - 1]:
            counter += 1
            # print("counter = ",counter, "len(feilds) = ", len(fields))
    
    #this means all fields are equal to results
    if counter == len(fields):
        print(rows[i][0])
        exit(0)
        
print("No match")
1
  • For example, some STR like "AATG" counts right and for other texts it don't count right, i don't know how the same sequence sometimes works right and sometimes doesn't work for the same STR!
    – Mazen
    Nov 24 '20 at 23:33
-1

I am having a similar issue. Were you able to solve the problem?

1

You must log in to answer this question.

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