This is the complete code:
"""
- open csv file and sequence , read contents
- for each str, compute longest chain
- compare str counts aganist ech row in csv file
"""
import sys as s
import csv as c
# raising error
argc = len(s.argv)
if argc != 3:
print("Usage: python dna.py data.csv sequence.txt")
s.exit(1)
db = c.DictReader(open(s.argv[1], "r"))
sequence = open(s.argv[2], "r")
def main():
read_s = sequence.read()
# # loading db into a list
db_list = []
for i in db:
db_list.append(i)
str_list = ["AGATC", "TTTTTTCT", "AATG", "TCTAG", "GATA", "TATC", "GAAA", "TCTG"]
str_s_list = ['AGATC', 'AATG', 'TATC']
str_counts = []
found = False
if s.argv[1] == 'databases/small.csv':
for i in range(len(str_s_list)):
str_max = read_s.count(str_s_list[i])
str_counts.append(str_max)
for person in db_list:
if int(person["AGATC"]) == int(str_counts[0]) and int(person["AATG"]) == str_counts[1] and int(person["TATC"]) == str_counts[2]:
print(person["name"])
found == True
return
if found != True:
print("No match")
return
if s.argv[1] == 'databases/large.csv':
for i in range(len(str_list)):
str_max = read_s.count(str_list[i])
str_counts.append(str_max)
# print(str_counts)
print(db_list[3])
for person in db_list:
if int(person["AGATC"]) == str_counts[0] and int(person["TTTTTTCT"]) == str_counts[1] and int(person["AATG"]) == str_counts[2] and int(person["TCTAG"]) == str_counts[3] and int(person["GATA"]) == str_counts[4] and int(person["TATC"]) == str_counts[5] and int(person["GAAA"]) == str_counts[6] and int(person["TCTG"]) == str_counts[7]:
print("name", person["name"])
found = True
return
if found != True:
print("No match")
return
if __name__ == "__main__":
main()
sequence.close()
And there is a bug in:
if s.argv[1] == 'databases/large.csv':
for i in range(len(str_list)):
str_max = read_s.count(str_list[i])
str_counts.append(str_max)
Please help me correct it
j
Usingcount
function won't fetch you the maxCount of STR's. It will print the total count of STR'S. Also found == True is a boolean expression, not an assignment operationj
was redundant, I've removed it.