1

Logic: I'm trying to do this in such a way that I check the database first, then I check the DNA sequence to see if that information corresponds to any of the information in my database.

I want to convert all my numbers that are, by default of using DictReader, strings to integers. Then I can multiply my current STR by the number associate with that person

E.g Multiply 'AGATC' * 2 as it is for Alice in small.csv.

THEN check if that matches any part of my DNA sequence.

Issue: Of course firstly I'll need to convert my actual numbers to ints. The way I'm iterating over my dict I'm always hitting my name column. How can I exclude this without removing it as I'll need it as a reference later?

Code

 def main():
 
     if len(sys.argv) != 3:
         sys.exit("Usage: python dna.py data.csv sequence.txt")
 
     # some placeholding lists
     memory = []
 
     database = sys.argv[1]
     seq = sys.argv[2]
 
 
     with open(database, "r") as fdata, open(seq, "r") as sequence:
         reader = csv.DictReader(fdata)
         strs = sequence.read()
         for line in reader:
             memory.append(line)
 
         for row in memory:
             for column in row:
                 row[column] = int(row[column])
                 if column * int(row[column]) in strs:
                     print(f"found", column)
                 else:
                     (f"Not this", column)
0
 def main():
 
     if len(sys.argv) != 3:
         sys.exit("Usage: python dna.py data.csv sequence.txt")
 
     # some placeholding lists
     memory = []
 
     database = sys.argv[1]
     seq = sys.argv[2]
 
 
     with open(database, "r") as fdata, open(seq, "r") as sequence:
         reader = csv.DictReader(fdata)

         # Get names of STR'S as a list
         fields = reader.fieldnames[1:] 
         strs = sequence.read()
         for line in reader:
             memory.append(line)
 
         for row in memory:

             # Convert only STR counts to int, leaving name
             for column in fields: 
                 row[column] = int(row[column])
                 if column * int(row[column]) in strs:
                     print(f"found", column)
                 else:
                     print(f"Not this", column)

You must log in to answer this question.

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