Back to index

python-biopython  1.60
Public Member Functions | Public Attributes | Private Attributes
Bio.Data.CodonTable.AmbiguousForwardTable Class Reference

List of all members.

Public Member Functions

def __init__
def get
def __getitem__

Public Attributes

 forward_table
 ambiguous_nucleotide
 ambiguous_protein

Private Attributes

 _inverted
 _cache

Detailed Description

Definition at line 276 of file CodonTable.py.


Constructor & Destructor Documentation

def Bio.Data.CodonTable.AmbiguousForwardTable.__init__ (   self,
  forward_table,
  ambiguous_nucleotide,
  ambiguous_protein 
)

Definition at line 277 of file CodonTable.py.

00277 
00278     def __init__(self, forward_table, ambiguous_nucleotide, ambiguous_protein):
00279         self.forward_table = forward_table
00280 
00281         self.ambiguous_nucleotide = ambiguous_nucleotide
00282         self.ambiguous_protein = ambiguous_protein
00283 
00284         inverted = {}
00285         for name, val in ambiguous_protein.iteritems():
00286             for c in val:
00287                 x = inverted.get(c, {})
00288                 x[name] = 1
00289                 inverted[c] = x
00290         for name, val in inverted.iteritems():
00291             inverted[name] = val.keys()
00292         self._inverted = inverted
00293         
00294         self._cache = {}

Here is the caller graph for this function:


Member Function Documentation

Definition at line 301 of file CodonTable.py.

00301 
00302     def __getitem__(self, codon):
00303         try:
00304             x = self._cache[codon]
00305         except KeyError:
00306             pass
00307         else:
00308             if x is TranslationError:
00309                 raise TranslationError(codon)   # no unique translation
00310             if x is KeyError:
00311                 raise KeyError(codon)  # it's a stop codon
00312             return x
00313         try:
00314             x = self.forward_table[codon]
00315             self._cache[codon] = x
00316             return x
00317         except KeyError:
00318             pass
00319 
00320         # XXX Need to make part of this into a method which returns
00321         # a list of all possible encodings for a codon!
00322         try:
00323             possible = list_possible_proteins(codon,
00324                                               self.forward_table,
00325                                               self.ambiguous_nucleotide)
00326         except KeyError:
00327             self._cache[codon] = KeyError
00328             raise KeyError(codon)  # stop codon
00329         except TranslationError:
00330             self._cache[codon] = TranslationError
00331             raise TranslationError(codon)  # does not code
00332         assert len(possible) > 0, "unambiguous codons must code"
00333 
00334         # Hah!  Only one possible protein, so use it
00335         if len(possible) == 1:
00336             self._cache[codon] = possible[0]
00337             return possible[0]
00338 
00339         # See if there's an ambiguous protein encoding for the multiples.
00340         # Find residues which exist in every coding set.
00341         ambiguous_possible = {}
00342         for amino in possible:
00343             for term in self._inverted[amino]:
00344                 ambiguous_possible[term] = ambiguous_possible.get(term, 0) + 1
00345 
00346         n = len(possible)
00347         possible = []
00348         for amino, val in ambiguous_possible.iteritems():
00349             if val == n:
00350                 possible.append(amino)
00351 
00352         # No amino acid encoding for the results
00353         if len(possible) == 0:
00354             self._cache[codon] = TranslationError
00355             raise TranslationError(codon)   # no valid translation
00356 
00357         # All of these are valid, so choose one
00358         # To be unique, sort by smallet ambiguity then alphabetically
00359         # Can get this if "X" encodes for everything.
00360         #def _sort(x, y, table = self.ambiguous_protein):
00361         #    a = cmp(len(table[x]), len(table[y]))
00362         #    if a == 0:
00363         #        return cmp(x, y)
00364         #    return a
00365 
00366         #Sort by key is 2.x and 3.x compatible
00367         possible.sort(key=lambda x:(len(self.ambiguous_protein[x]), x))
00368                           
00369         x = possible[0]
00370         self._cache[codon] = x
00371         return x
00372 

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.Data.CodonTable.AmbiguousForwardTable.get (   self,
  codon,
  failobj = None 
)

Definition at line 295 of file CodonTable.py.

00295 
00296     def get(self, codon, failobj = None):
00297         try:
00298             return self.__getitem__(codon)
00299         except KeyError:
00300             return failobj
        

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 293 of file CodonTable.py.

Definition at line 291 of file CodonTable.py.

Definition at line 280 of file CodonTable.py.

Definition at line 281 of file CodonTable.py.

Definition at line 278 of file CodonTable.py.


The documentation for this class was generated from the following file: