0

I have divided my code into three main pieces:

1- open the CSV file and read its contents into memory and open the DNA sequence and read its contents into memory

2- compute the longest run of consecutive repeats of the STR in the DNA sequence

3- print out the results

if you don't have time to look at my entire code you can just take a look at on piece of it and advice me on that. any help will be highly appreciated! Thank you in advance.

from sys import argv, exit
import csv
# command line argument
if len(argv) != 3:
    print("missing command-line argument")
    exit(1)

# open the CSV file and read its contents into memory
with open(argv[1]) as csvfile:
    in_memory_file = csvfile.read()
    readCSV = csv.reader(in_memory_file, delimiter=',')
    for raw in readCSV:
        pass
    
# Your program should open the DNA sequence and read its contents into memory
last_char = ""
current_seq_len = 0
max_seq_len = 0
with open(argv[2], "r") as seq:
    filecontent = seq.readlines()
    # For each of the STRs (from the first line of the CSV file),
    # your program should compute the longest run of consecutive 
    # repeats of the STR in the DNA sequence to identify.
    for line in filecontent:
        if raw == last_char:
            current_seq_len += 1
            if current_seq_len > max_seq_len:
                max_seq_len = current_seq_len
        else:
            current_seq_len = 1
            last_char = raw
print(max_seq_len)

# If the STR counts match exactly with any of the individuals in the CSV file, 
# your program should print out the name of the matching individual.
for colum in readCSV:
    for row in readCSV:
      if max_seq_len == readCSV[colum][row]:
          print(f"match with {readCSV[0][row]}")
      else:
          print("no match")

You must log in to answer this question.

Browse other questions tagged .