I have written a program for DNA, but it's not printing anything. Code:
import csv
from sys import *
if len(argv) != 2:
print("Usage: python dna.py data.csv sequence.txt")
def maxcount(n, main, seq):
l = len(main)
maxc = 0
currc = 0
for i in range(n):
cp = i
while seq[cp : cp + l]:
currc += 1
cp += l
if currc > maxc:
maxc = currc
return maxc
persons = []
strsn = {}
seq = ""
with open(argv[1], "r") as seqf:
seq = seqf.read()
seq.replace("\n", "")
dnaf = open(argv[0], "r")
dr = csv.dictReader(dnaf)
r = csv.reader(dnaf)
strs = next(r)[1 :]
for i in dr:
persons.append(i)
for j in strs:
strsn[j] = maxcount(len(j), j, seq)
for k in persons:
d = []
for z in strs:
if strsn[z] == k[z]:
d.append(True)
if d.count(True) == len(strs):
print(k["name"])
exit(0)
print("No match")
EDIT: I have changed the code a little bit, on the advice of @Sentox. Code:
import csv
import sys
if len(sys.argv) != 3:
print("Usage: python dna.py data.csv sequence.txt")
sys.exit(1)
def maxcount(l, n, main, seq):
maxc = 0
currc = 0
for i in range(n):
p = i
while p < n and seq[p : p + l] == main:
p += l + 1
currc += 1
if currc > maxc:
maxc = currc
currc = 0
return maxc
persons = []
strsn = {}
seq = ""
with open(sys.argv[2], "r") as seqf:
seq = seqf.read()
seq.replace("\n", "")
dnaf = open(sys.argv[1], "r")
dr = csv.DictReader(dnaf)
strs = dr.fieldnames[1:]
for i in dr:
persons.append(i)
for j in strs:
strsn[j] = maxcount(len(j), len(seq), j, seq)
for k in persons:
d = []
for z in strs:
if strsn[z] == int(k[z]):
d.append(True)
if len(d) == len(strsn):
print(k["name"])
exit(0)
print("No match")