0

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

4
  • what's the point of using j Using count 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 operation
    – C--
    Apr 26 at 8:04
  • Sorry, that j was redundant, I've removed it. Apr 26 at 8:13
  • Please read everything I've pointed out
    – C--
    Apr 26 at 9:23
  • thanks I got it. Apr 26 at 10:31
0

I found the fix finally:

if s.argv[1] == 'databases/large.csv':
        # NOTE - this is adapted from: https://stackoverflow.com/questions/61131768/how-to-count-consecutive-substring-in-a-string-in-python-3
        
        for i in str_list:
            expected = i
            str_max = 0
            while expected in read_s:
                str_max += 1
                expected += i

You must log in to answer this question.

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