0

I've been doing this for quite some time now, but I'm struggling to get the appropriate output. In the below code (which is incomplete as of now, but the main pieces are all on the board), I'm not able to print out cells corresponding to the right number of consecutive STRs, which is weird because if I try to print agatc_count for instance, it will give me the number of consecutive AGATCs which should have been detected by the program but isn't (in the nested for loop in the last block of code). I'm sure that me using a nested loop to scan through each and every cell of the table is correct, is it not? Where else the could the problem be?

from sys import argv, exit
import csv
from csv import reader, DictReader
import re

agatc_count = 0
tttct_count = 0
aatg_count = 0
tatc_count = 0

if len(argv) != 3:
    print("missing command-line argument")
    exit(1)

f = open(argv[2], "r")
s = f.readline()
str = len(s)

while True:
    agatc = re.findall(r'(?:AGATC)+', s)
    if not agatc:
        break
    largest = max(agatc, key=len)
    agatc_count = len(largest) // 5
    break

while True:
    tttct = re.findall(r'(?:TTTTTTCT)+', s)
    if not tttct:
        break
    largest = max(tttct, key=len)
    tttct_count = len(largest) // 5
    break

while True:
    aatg = re.findall(r'(?:AATG)+', s)
    if not aatg:
        break
    largest = max(aatg, key=len)
    aatg_count = len(largest) // 4
    break

while True:
    tatc = re.findall(r'(?:TATC)+', s)
    if not tatc:
        break
    largest = max(tatc, key=len)
    tatc_count = len(largest) // 4
    break


with open(argv[1], 'r') as temp:
    reader = csv.reader(temp)
    for row in reader:
        for column in row:
            if column == agatc_count:
                print(column)
                exit(1)
            if column == tttct_count:
                print(column)
                exit(1)
            if column == aatg_count:
                print(column)
                exit(1)
            if column == tatc_count:
                print(column)
                exit(1)
0

I think the issue could be that your counts will never equal the columns. They might equal the individual cells but they would be referenced differently. (I'm also new to this so if someone else could confirm that's the current issue that would be awesome!)

Couple of other issues I've noticed.

From looking at your code you appear to have hard-coded the STRs into the programme which will mean you'll need to edit the code before running it with the large DB that has more, and different, STRs. Also, at the end of your programme, you aren't meant to be printing the counts, but the name of the person who's DNA matches those STR counts. Your loops at the moment will attempt to print the number from the first person that matches, but that isn't what you're looking to do. You want to find the person that has STR counts that match all of the max values. If no-one does that then there isn't a match.

On the upside, you're on the right track with using max and findall just try to think about how you can implement it so it doesn't matter what the STR is.

| improve this answer | |

You must log in to answer this question.

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