Hi there I am having an issue comparing the data I have extracted from the sequence and the database files for now I am doing a sort of in efficient way but later I will fix it I am not sure really how to fix my code.

so for now I am kind of testing out if it works for the small db but when i run my code all I get is the output "nooo" instead of "yaaa" which is just for testing.

if anyone could help me and give me a better way to check because I dont think my is the best way possible please help me because I have been stuck on this question for a while now thank you :D

this is my code:

    from sys import argv
    import csv
    import re

    db_file = argv[1]
    dna_sequence = argv[2]

    if len(argv) > 3:
        print("Oops! there are 2 arguments")

    dna_data = []
    # reads from database
    with open(db_file, 'r') as f:
        reader = csv.reader(f)
        for row in reader:
            for col in row:

    # reads dna sequence from the files
    with open(dna_sequence, 'r') as sq_file:
        dna_sequence = sq_file.readline().rstrip("\n")

    # for calculating the amount of formations in the txt file
    dna_formations_large = ["AGATC","TTTTTTCT","TCTAG","AATG","GATA","TATC","GAAA","TCTG"]

    dna_formations_small = ["AGATC","AATG","TATC"]

    if db_file == "databases/small.csv":
        for i in range(3):
            formation_count_small.append(len(re.findall(dna_formations_small[i], dna_sequence)))
        for i in range(8):
            formation_count_large.append(len(re.findall(dna_formations_large[i], dna_sequence)))

    if db_file == "databases/small.csv":
        for i in range(len(dna_data)):
            for j in range(3):
                if dna_data[i] == formation_count_small[j]:

1 Answer 1


The answer to your specific question is that if dna_data[i] == formation_count_small[j] compares an int to a string.
However, there are several other problems, so I'm going to offer advice.

  • Don't hardcode the specific sequences being looked for. The first line of the csv file has the information, get it from there. Then there's no need to look at the exact input filename.
  • Create a data structure as the database is read in. An unstructured list mixes names and numbers. This leads to comparing Charlie to 4 later on.
  • Thank you so much I tried it and it helped :D
    – Arsham
    Commented Apr 4, 2021 at 2:49

You must log in to answer this question.

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