Last active
January 27, 2016 16:50
-
-
Save cthoyt/6ca3a3e0bf0d92754619 to your computer and use it in GitHub Desktop.
Solves the BLAST Problem from Bioinformatics Class on 27.01.16
This file contains 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
#!/usr/bin/env python | |
# Author: Charlie Hoyt | |
import itertools as itt | |
s = { | |
('A','A'): 5, | |
('A','R'): -2, | |
('A','N'): -1, | |
('A','D'): -2, | |
('R','A'): -2, | |
('R','R'): 7, | |
('R','N'): -1, | |
('R','D'): -2, | |
('N','A'): -1, | |
('N','R'): -1, | |
('N','N'): 7, | |
('N','D'): 2, | |
('D','A'): -2, | |
('D','R'): -2, | |
('D','N'): 2, | |
('D','D'): 8 | |
} | |
alphabet = "ARND" | |
target ="RRDNARD" | |
substring_len = 4 | |
threshold = 3 | |
valid_count = 0 | |
# iterate over all possible elements of alphabet^substring_len | |
for perm in itt.product(alphabet, repeat=substring_len): | |
# start with worst possible score | |
max_score = min(s.values()) * substring_len | |
# slide window and calculate score for each | |
for i in range(len(target) - substring_len): | |
score = sum(s[matching] for matching in zip(perm, target[i:i + substring_len])) | |
if max_score < score: | |
max_score = score | |
if threshold <= max_score: | |
print(''.join(perm), max_score) | |
valid_count += 1 | |
print(valid_count) | |
# Answer: 238 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Full output: