Skip to content

Commit

Permalink
Only create one shared version of each ambiguous table, rather than o…
Browse files Browse the repository at this point in the history
…ne copy for each different name of the table
  • Loading branch information
peterc committed Jun 29, 2008
1 parent a9bf6fb commit 5e9a724
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions Bio/Data/CodonTable.py
Expand Up @@ -673,56 +673,47 @@ def _sort(x, y, table = self.ambiguous_protein):
self._cache[codon] = x
return x


#Prepare the ambiguous tables for DNA, RNA and Generic (DNA or RNA)
ambiguous_dna_by_name = {}
for key, val in unambiguous_dna_by_name.items():
ambiguous_dna_by_name[key] = AmbiguousCodonTable(val,
IUPAC.ambiguous_dna,
IUPACData.ambiguous_dna_values,
IUPAC.extended_protein,
IUPACData.extended_protein_values)
ambiguous_dna_by_id = {}
for key, val in unambiguous_dna_by_id.items():
ambiguous_dna_by_id[key] = AmbiguousCodonTable(val,
IUPAC.ambiguous_dna,
IUPACData.ambiguous_dna_values,
IUPAC.extended_protein,
IUPACData.extended_protein_values)
for name in unambiguous_dna_by_name:
ambiguous_dna_by_name[name] = ambiguous_dna_by_id[key]

ambiguous_rna_by_name = {}
for key, val in unambiguous_rna_by_name.items():
ambiguous_rna_by_name[key] = AmbiguousCodonTable(val,
IUPAC.ambiguous_rna,
IUPACData.ambiguous_rna_values,
IUPAC.extended_protein,
IUPACData.extended_protein_values)
ambiguous_rna_by_id = {}
for key, val in unambiguous_rna_by_id.items():
ambiguous_rna_by_id[key] = AmbiguousCodonTable(val,
IUPAC.ambiguous_rna,
IUPACData.ambiguous_rna_values,
IUPAC.extended_protein,
IUPACData.extended_protein_values)
for name in unambiguous_rna_by_name:
ambiguous_rna_by_name[name] = ambiguous_rna_by_id[key]

#The following isn't very elegant, but seems to work nicely.
_merged_values = dict(IUPACData.ambiguous_rna_values.iteritems())
_merged_values["T"] = "U"

for key, val in generic_by_name.items():
ambiguous_generic_by_name[key] = AmbiguousCodonTable(val,
Alphabet.NucleotideAlphabet(),
_merged_values,
IUPAC.extended_protein,
IUPACData.extended_protein_values)

for key, val in generic_by_id.items():
ambiguous_generic_by_id[key] = AmbiguousCodonTable(val,
Alphabet.NucleotideAlphabet(),
_merged_values,
IUPAC.extended_protein,
IUPACData.extended_protein_values)
for name in generic_by_name:
ambiguous_generic_by_name[name] = ambiguous_generic_by_id[key]

#Basic sanity tests,
assert len(ambiguous_dna_by_name.keys()) == len(unambiguous_dna_by_name.keys())
assert len(ambiguous_rna_by_name.keys()) == len(unambiguous_rna_by_name.keys())
assert len(ambiguous_generic_by_name.keys()) == len(generic_by_name.keys())

#Basic sanity test,
for id in ambiguous_generic_by_id.keys() :
assert ambiguous_rna_by_id[id].forward_table["GUU"] == "V"
assert ambiguous_rna_by_id[id].forward_table["GUN"] == "V"
Expand Down

0 comments on commit 5e9a724

Please sign in to comment.