Small refactor suggestion in ApproximatePatternCount.py #1

Closed
opened 2019-11-17 15:12:35 +01:00 by oekk · 1 comment

In ApproximatePatternCount.py

Since the code under the if condition is the same under the else statement, I believe you can change this:

def ApproximatePatternCount(Pattern, Text, d):
    count = 0
    for i in range(len(Text)-len(Pattern)+1):
        if Text[i:i+len(Pattern)] == Pattern:
            count += 1
        elif HammingDistance(Text[i:i+len(Pattern)], Pattern) <= d:
            count += 1
    return count

for this:

def ApproximatePatternCount(Pattern, Text, d):
    count = 0
    for i in range(len(Text)-len(Pattern)+1):
        if Text[i:i+len(Pattern)] == Pattern or HammingDistance(Text[i:i+len(Pattern)], Pattern) <= d:
            count += 1
    return count
In [ApproximatePatternCount.py](https://coolneng.duckdns.org/gitea/coolneng/biology-meets-programming/src/branch/master/Code/ApproximatePatternCount.py) Since the code under the if condition is the same under the else statement, I believe you can change this: def ApproximatePatternCount(Pattern, Text, d): count = 0 for i in range(len(Text)-len(Pattern)+1): if Text[i:i+len(Pattern)] == Pattern: count += 1 elif HammingDistance(Text[i:i+len(Pattern)], Pattern) <= d: count += 1 return count for this: def ApproximatePatternCount(Pattern, Text, d): count = 0 for i in range(len(Text)-len(Pattern)+1): if Text[i:i+len(Pattern)] == Pattern or HammingDistance(Text[i:i+len(Pattern)], Pattern) <= d: count += 1 return count
Owner

Good catch, will update it right now

Good catch, will update it right now
Sign in to join this conversation.
No Label
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: coolneng/bioinformatics-course#1
No description provided.