Created
April 26, 2012 15:24
-
-
Save sammyrulez/2500335 to your computer and use it in GitHub Desktop.
Reverse protein matcher
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
from Bio.Data import CodonTable | |
def full_back_table(codon_table): | |
base_table = codon_table.forward_table | |
out_table = {} | |
for codon in base_table: | |
p = base_table[codon] | |
if out_table.has_key(p): | |
out_table[p].append(codon) | |
else: | |
out_table[p] = [codon , ] | |
return out_table | |
def multiplex(input_p,dictionary,prefix=""): | |
count = 0 | |
out = [] | |
p = input_p[0] | |
cases = dictionary[p] | |
count = count +1 | |
fract = input_p[count:] | |
for c in cases: | |
actual_prefix = prefix + ' ' +c | |
if fract: | |
for m in multiplex("%s" % fract, dictionary , actual_prefix): | |
out.append(m) | |
else: | |
out.append(actual_prefix) | |
return out | |
def test(): | |
input_p = 'MAKVHYVNSL' | |
base_table = full_back_table(CodonTable.unambiguous_dna_by_id[1]) | |
print base_table , '\n ------------------------------------- \n' | |
out = multiplex(input_p,base_table) | |
for o in out: | |
print o , "\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment