Overlap between Genome and Pattern
1
1
Entering edit mode
22 months ago

Hello everyone, I am trying to implement this method but failed to have the output answer. Can someone help me take a look what I could be missing? So basically, we have a string Genome, a Pattern, and integer of Overlap. We need to find number of matching occurrences of Pattern in Genome but with at most number of overlap. So the overlap between the Pattern can only be <= number of overlap to count.

I have attached the sample input and output, which is 2 but I lost at how to check for overlap within the string. Thank you for the feedback!

def PatternCountOverlap(Text, Pattern, overlap):
    n = len(Text)
    k = len(Pattern)
    count = 0
    for i in range(n-k+1): #iterate through the text 
        if Pattern == Text[i:i+k]:
            count +=1  #count number of matching 
            ##how to find with restriction of overlapping? 

    return count

print(PatternCountOverlap("GATATATATAC","ATATA",1))  #this would return 2, 1 is number of overlap restriction
overlap python pattern • 1.2k views
ADD COMMENT
0
Entering edit mode

Please do not paste screenshots of plain text content, it is counterproductive. You can copy paste the content directly here (using the code formatting option shown below), or use a GitHub Gist if the content volume exceeds allowed length here.

code_formatting

ADD REPLY
0
Entering edit mode

oh thanks, i will update it!

ADD REPLY
0
Entering edit mode

Also, there is no need for the bioinformatics tag (I've removed it) - every question on the site is related to bioinformatics.

ADD REPLY
0
Entering edit mode

kristenammons2 : Please do not delete posts once they have received an answer or a comment. If the answer below solved your problem then accept it (green check mark) to provide closure for this thread.

ADD REPLY
0
Entering edit mode
22 months ago
Jeremy ▴ 930

Try replacing return count with

if count <= overlap:
    return count
else:
    return overlap
ADD COMMENT
0
Entering edit mode

I prefer ternary operators:

ret_val = count if count <= overlap else overlap #assign to a variable to make debugging easier
return ret_val
ADD REPLY

Login before adding your answer.

Traffic: 1560 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6