How can I write a code to find the most frequent 2-mer of "GATCCAGATCCCCATAC". I have written this code but it seems that I am wrong, please help in correcting me.
def PatternCount(Pattern, Text):
count = 0
for i in range(len(Text)-len(Pattern)+1):
if Text[i:i+len(Pattern)] == Pattern:
count = count+1
return count
This code prints the most frequent k-mer in a string but it don't give me the 2-mer in the given string.
In general, when I want to count things with python I use a
CounterThis prints
[('CC', 4)], a list of the1most common 2-mers in a tuple with their count in the string.In fact, we can generalize this to the find the most common n-mer for a given
n.