0

Currently my code functions in so far that I get the appropriate results for the maximum STR counts when I pass a certain sequence. However, I have no clue as to what I should do to progress; I tried searching from the csv file after using DictReader but I get errors saying it's not subscriptable. From what I can tell, I need to actually pass those csv values into an actual dictionary after reading it, then search for the results. Also, even if I do find that the STRs match, how do I go about printing the appropriate name or finding the proper key to said name. (*count is a function I made that counts the maximum number of consecutive STRs in a given sequence)

if len(sys.argv)!=3:
    print("python dna.py data.csv sequence.txt")
    exit()
if os.path.isfile(sys.argv[2]) and os.path.isfile(sys.argv[1]):
    with open(sys.argv[1], 'r') as file: #opening the database file for reading
        reader = csv.DictReader(file) #using Dict reader to store csv into dict
        AGATC = count(string, 'AGATC')
            TTTTTTCT = count(string, 'TTTTTTCT')
            AATG = count(string, 'AATG')
            TCTAG = count(string, 'TCTAG')
            GATA = count(string, 'GATA')
            TATC = count(string, 'TATC')
            GAAA = count(string, 'GAAA')
            TCTG = count(string, 'TCTG')

1

Got the solution via a very cheeky way; storing the values in a list, checking each row of values for each STR, then comparing those database values with the ones I got using my count function.

        if sys.argv[1] == 'databases/large.csv':
            AGATC = count(string, 'AGATC')
            TTTTTTCT = count(string, 'TTTTTTCT')
            AATG = count(string, 'AATG')
            TCTAG = count(string, 'TCTAG')
            GATA = count(string, 'GATA')
            TATC = count(string, 'TATC')
            GAAA = count(string, 'GAAA')
            TCTG = count(string, 'TCTG')
            for row in database:
                a = int(row["AGATC"])
                b = int(row["TTTTTTCT"])
                c = int(row["AATG"])
                d = int(row["TCTAG"])
                e = int(row["GATA"])
                f = int(row["TATC"])
                g = int(row["GAAA"])
                h = int(row["TCTG"])
                if AGATC == a and TTTTTTCT == b and AATG == c and TCTAG == d and GATA == e and TATC == f and GAAA == g and TCTG == h:
                    print(row["name"])
                    exit()
            print("No match")



        elif sys.argv[1] == 'databases/small.csv':
            string = file1.read()
            AGATC = count(string, 'AGATC')
            AATG = count(string, 'AATG')
            TATC = count(string, 'TATC')
            for row in database:
                j = int(row["AGATC"])
                k = int(row["AATG"])
                l = int(row["TATC"])
                if AGATC == j and AATG == k and TATC == l:
                    print(row["name"])
                    exit()
            print("No match")
| improve this answer | |
  • Suggest you edit the working code out of the answer , lest you violate the academic honesty policy. – DinoCoderSaurus Apr 7 at 15:52
  • Welp, changed the code on both the question and the answer. Hope I have not angered the gods – Sorphil Apr 7 at 18:47

You must log in to answer this question.

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