Created
February 11, 2021 02:04
-
-
Save matthewbordas/6047852fd949923bfddac1afc3637e3b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_longest_homopolymer(seq): | |
if seq == None or seq == '': | |
return 0 | |
polymer_lengths = [] | |
curr_len = 0 | |
polymer_nt = seq[0] | |
for nt in seq: | |
if nt != polymer_nt: | |
polymer_lengths.append(curr_len) | |
polymer_nt = nt | |
curr_len = 1 | |
else: | |
curr_len += 1 | |
polymer_lengths.append(curr_len) | |
return max(polymer_lengths) | |
print(find_longest_homopolymer(None)) # 0 | |
print(find_longest_homopolymer('')) # 0 | |
print(find_longest_homopolymer('G')) # 1 | |
print(find_longest_homopolymer('GGTT')) # 2 | |
print(find_longest_homopolymer('CCCAAAA')) # 4 | |
print(find_longest_homopolymer('AAAAAAAAAAG')) # 10 | |
print(find_longest_homopolymer('TGGGGGGGGAGGGGGCGGG')) # 8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment