0

My program always return 'no match' and it's because it can't count the occurence of a substring. I have spent a lot of time trying to figure it out, so I hope someone can help me.

here's the function. The 'substring' argument is either AGATC, TTTTTTCT, AATG, TCTAG, GATA, TATC, GAAA or TCTG.

def analyse(substring):
with open(sys.argv[2], 'r') as file2:
    dna = file2.read()
    substring_len = len(substring)
    check = 0
    occurence = 0
    i = 0
    for i in range(0, len(dna), i + substring_len):
        check = 0
        for j in range(substring_len):
            if j > substring_len:
                break
            elif dna[i + j] == substring[j]:
                check = check + 1
            else:
                break
        if check == substring_len:
            occurence = occurence + 1
    return occurence
2
  • Have you checked the number of occurrences you are getting for each substring? – Vsjain Oct 22 '20 at 8:43
  • My function returns 0 occurrences – Thomaslusignan Oct 22 '20 at 20:55

You must log in to answer this question.

Browse other questions tagged .