0

Can anyone please give me a hint? I've been working on my code for days now and I don't have a clue how to fix it. My code is included below.

import csv
from sys import argv, exit

#initialize variables
i = j = substring_counter = max_substring = 0
substring = []
all_max_substring = []
sequence = []

#Function definition for finding max repeats for each substring type
def find_and_append_max_substring(sequence, substring):
    if sequence[i: i + len(substring)] == substring:
        substring_counter == 1
        while sequence[i: i + len(substring)] == sequence[i - len(substring): i]:
            substring_counter += 1
            if substring_counter > max_substring:
                max_substring = substring_counter
    int(max_substring)
    #add max to datastructure
    all_max_substring.append(max_substring)

def main():
    #verify the number of arguments (Python is not an argument)
    if len(argv) != 3:
        print("Usage: python dna.py data.csv sequence.txt")
        exit(1)

    #open the csv database, read it and convert it to a list
    with open(argv[1], "r") as csvfile:
        reader = csv.reader(csvfile)
        database = list(reader)

        #open the textfile, read it and store it as a string
        with open(argv[2], "r") as dnafile:
            sequence = dnafile.read()

            #Check for each position in the sequence how many times a specific substring repeats subsequently:
            for i in range(len(sequence) - len(substring), 1, 1):
                if substring == "AGAT":
                    find_and_append_max_substring(sequence, substring)
                elif substring == "AATG":
                    find_and_append_max_substring(sequence, substring)
                elif substring == "TATC":
                    find_and_append_max_substring(sequence, substring)

            #Check if there is someone in the csvfile having the same max number repeats of the substring's as in all_max-substring
            for row in reader:
                if argv[1] == databases/small.csv:
                    #row = [name, AGAT, AATG, TATC]
                    if row[1] == all_max_substring[0] and row[2] == all_max_substring[1] and row[3] == all_max_substring[2]:
                        print(f"Name: {row[0]}")
                    else:
                        print("No match")
                else:
                    #row = [name, AGAT, TTTTTTCT, AATG, TCTAG, GATA, TATC, GAAA, TCTG]
                    if row[1] == all_max_substring[0] and row[3] == all_max_substring[1] and row[6] == all_max_substring[2]:
                        print(f"Name: {row[0]}")
                    else:
                        print("No match")

main()

You must log in to answer this question.

Browse other questions tagged .