import csv
import sys

counter  = 0

def main():

if len(sys.argv) != 3:
    sys.exit("Usage: python dna.py data.csv sequence.txt")

# Open csv file and read it's contents into memory
str_sequence = {
"AGATC" : 0,
"AATG" : 0,
"TCTAG" : 0,
"GATA" : 0,
"TATC" : 0,
"GAAA" : 0,
"TCTG" : 0

dna_data = []

with open(sys.argv[1]) as file:
   reader = csv.DictReader(file)
   for row in reader:
# Open the text file and read it's contents into memory

sequences = []

file2 = open(sys.argv[2])

for pie in file2:

countsss = get_strcounts()

def get_strcounts(sequences, str_sequence):

for i in sequences:
    for pie in str_sequence:
          if (sequences[0:i] == str_sequence[pie]):
              counter += 1
    return counter


I could really use some explanation about this problem set. I am having a hard time with this transition from C to python and I would appreciate the help. I am really not able to understand how I can get the highest consecutive counts of strs and how I am supposed to actually use the function. Because for now I am just printing out the count to see if my code is correct but it gives nothing in the output.

  • are you still working on this problem? Do you still have questions?
    – kcw78
    Dec 31, 2021 at 16:01
  • Yes, I am still stuck. I don't know whether to go into the next week or just give up. I don't know why it's so hard for me. I am really having a problem with checking if the dna sequence is the same as it is in the csv file...Any help will be very much appreciated Jan 5, 2022 at 9:36
  • The instructions mention a function called longest_match(). Did you see it in the dna.py template file? You can use it to get length of longest run of a subsequence (e.g. "AGATC") in the complete DNA sequence. So, you don't need to write get_strcounts(). Note: indentation/formatting needs to be fixed in code above.
    – kcw78
    Jan 5, 2022 at 14:44


You must log in to answer this question.

Browse other questions tagged .