0

import sys import csv AATG, GATA, TATC, TCTG, AGATC, GAAA, TCTAG = 1, 1, 1, 1, 1, 1, 1 TTTTTTCT = 1 temp = 0 if int(len(sys.argv)) > 3 or int(len(sys.argv)) < 3: print("Usage: python dna.py data.csv sequence.txt") if int(len(sys.argv)) == 3: f = open(sys.argv[2], 'r+') for line in f: for i in range(len(line)): if line[i:i+4] == line[i+4: (i + 8)]: if line[i:i+4] == 'A''A''T''G': AATG += 1

        elif line[i:i+4] == 'G''A''T''A'and line[i:i+4] == line[i+4: (i + 8)]:
            GATA += 1
        elif line[i:i+4] == 'T''A''T''C'and line[i:i+4] == line[i+4: (i + 8)]:
            TATC += 1
        elif line[i:i+4] == 'G''A''A''A' and line[i:i+4] == line[i+4: (i + 8)]:
            GAAA += 1
        elif line[i:i+4] == 'T''C''T''G' and line[i:i+4] == line[i+4: (i + 8)]:
            TCTG += 1
        elif line[i:i+5] == 'A''G''A''T''C'and line[i:i+5] == line[i+5: (i + 10)]:
            AGATC += 1
        elif line[i:i+5] == 'T''C''T''A''G' and line[i:i+5] == line[i+5: (i + 10)]:
            TCTAG = TCTAG + 1
        elif line[i:i+8] == 'T''T''T''T''T''T''C''T' and line[i:i+8] == line[i+8: (i + 16)]:
            TTTTTTCT = TTTTTTCT + 1
f.close()
print(AATG)
#print(AGATC,TTTTTTCT,AATG,TCTAG,GATA,TATC,GAAA,TCTG)
with open(sys.argv[1], 'r') as file:
    reader = csv.DictReader(file)
    for row in reader:
        # print(row['name'], row['AGATC'])
        if int(row['AATG']) == AATG and int(row['AGATC']) == AGATC and int(row['TATC']) == TATC:
            print(row['name'])
            break
        elif int(row['AATG']) == AATG and int(row['AGATC']) == AGATC   and int(row['TATC']) == TATC and  int(row['TTTTTTCT']) == TTTTTTCT and int(row['TCTAG']) == TCTAG and int(row['GATA']) == GATA and int(row['GAAA']) == GAAA and int(row['TCTG']) == TCTG:
            print(row['name'])
            break
    if not (int(row['AATG']) == AATG and int(row['AGATC']) == AGATC   and int(row['TATC']) == TATC and  int(row['TTTTTTCT']) == TTTTTTCT and int(row['TCTAG']) == TCTAG and int(row['GATA']) == GATA and int(row['GAAA']) == GAAA and int(row['TCTG']) == TCTG):
        print("No Match")
    elif not (int(row['AATG']) == AATG and int(row['AGATC']) == AGATC and int(row['TATC']) == TATC):
        print("No Match")
file.close()

1 Answer 1

0

You seem to count all the occurrences, not just the longest repeat. You should find the highest number of contiguous occurrences.

Also, there should be no actual sequence in your Python file, you are meant to take the STR sequences from the CSV file. As you are using DictReader, you could find those sequences in reader.fieldnames[1:]. The [1:] creates a copy starting at the second element, as the first one is 'name', which is no sequence you should find in the DNA.

6
  • thanks in advance
    – Hama Ijaz
    Mar 2, 2020 at 9:43
  • for i in range(len(dnastring)): if dnastring[i:i + dnanamelength] == dnanames: temp = temp + 1 while dnastring[i:i + dnanamelength] == dnastring[i + dnanamelength : i + (dnanamelength * 2)]: temp = temp + 1 tempmax = temp dnaConsecutivelist[dnanames] = tempmax temp = 0 print (f"inside of for loop: ", dnaConsecutivelist.items())
    – Hama Ijaz
    Mar 2, 2020 at 12:26
  • getting error again
    – Hama Ijaz
    Mar 2, 2020 at 12:26
  • I don't see how this code (which is ambiguous in the comments section as whitespace gets removed) counts contiguous repeats (is that while an infinite loop?), and I don't see how it would find the longest repeat rather than the last.
    – Blauelf
    Mar 2, 2020 at 12:38
  • can i mail u or share the link of mine code with u
    – Hama Ijaz
    Mar 2, 2020 at 14:22

You must log in to answer this question.

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