
:>"^                 @   s-  d  Z  d d l m Z d d l m Z d d l m Z i  Z i  Z i  Z	 i  Z
 i  Z i  Z i  Z i  Z i  Z i  Z i  Z i  Z d a d a Gd d   d e  Z Gd d	   d	 e  Z d
 d   Z Gd d   d e  Z Gd d   d e  Z Gd d   d e  Z Gd d   d e  Z d d   Z d d   Z e d d g e j   d d d g k s_t!  e d d g e j   d d g k st!  e d d g e j   d d d g k st!  e d d g e j"  d d d g k st!  e d d d g e j   d d d d d g k st!  Gd  d!   d! e  Z# d" d#   Z$ e$ d$ d% d& d' d( d) d* d+ d, d- d, d. d/ d0 d/ d1 d2 d3 d2 d4 d2 d5 d2 d6 d7 d8 d7 d9 d: d; d: d< d= d> d/ d? d/ d@ d/ dA d/ dB dC dD dC dE dC dF dC dG dH dI dH dJ dK dL dK dM dN dO dN dP dN dQ dN dR dS dT dS dU dS dV dW dX dY dZ dY d[ dY d\ dY d] d^ d_ d^ d` da db da dc d2 dd d2 de dN df dN dg dh di dh dj dh dk dh dl dm dn dm do dm dp dm dq dr ds dr dt du dv du dw dx dy dx dz dx d{ dx i= d| d d d g d} d0 dA dV g  e$ d$ d~ d& d d( d d* d+ d, d- d, d. d/ d0 d/ d1 d2 d3 d2 d4 d2 d5 d2 d6 d7 d8 d7 d9 d: d; d: d d= d< d= d> d/ d? d/ d@ d/ dA d/ dB dC dD dC dE dC dF dC dG dH dI dH dJ dK dL dK dM dN dO dN dP dN dQ dN dR dS dT dS dU dW dV dW dX dY dZ dY d[ dY d\ dY d] d^ d_ d^ d` da db da dc d2 dd d2 dg dh di dh dj dh dk dh dl dm dn dm do dm dp dm dq dr ds dr dt du dv du dw dx dy dx dz dx d{ dx i< d| d d de df g d} dR dT dU dV dk g  e$ d$ d d& d d( d d* d+ d, d- d, d. d/ d0 d/ d1 d2 d3 d2 d4 d2 d5 d2 d6 d7 d8 d7 d9 d: d; d: d d= d< d= d> dY d? dY d@ dY dA dY dB dC dD dC dE dC dF dC dG dH dI dH dJ dK dL dK dM dN dO dN dP dN dQ dN dR dS dT dS dU dW dV dW dX dY dZ dY d[ dY d\ dY d] d^ d_ d^ d` da db da dc d2 dd d2 de dN df dN dg dh di dh dj dh dk dh dl dm dn dm do dm dp dm dq dr ds dr dt du dv du dw dx dy dx dz dx d{ dx i> d| d d g d} dU dV dk g  e$ d$ d d& d d( d d* d+ d, d- d, d. d/ d0 d/ d1 d2 d3 d2 d4 d2 d5 d2 d6 d7 d8 d7 d9 d: d; d: d d= d< d= d> d/ d? d/ d@ d/ dA d/ dB dC dD dC dE dC dF dC dG dH dI dH dJ dK dL dK dM dN dO dN dP dN dQ dN dR dS dT dS dU dS dV dW dX dY dZ dY d[ dY d\ dY d] d^ d_ d^ d` da db da dc d2 dd d2 de dN df dN dg dh di dh dj dh dk dh dl dm dn dm do dm dp dm dq dr ds dr dt du dv du dw dx dy dx dz dx d{ dx i> d| d d g d} d. d0 dA dR dT dU dV dk g  e$ d$ d d& d d( d d* d+ d, d- d, d. d/ d0 d/ d1 d2 d3 d2 d4 d2 d5 d2 d6 d7 d8 d7 d9 d: d; d: d d= d< d= d> d/ d? d/ d@ d/ dA d/ dB dC dD dC dE dC dF dC dG dH dI dH dJ dK dL dK dM dN dO dN dP dN dQ dN dR dS dT dS dU dW dV dW dX dY dZ dY d[ dY d\ dY d] d^ d_ d^ d` da db da dc d2 dd d2 de d2 df d2 dg dh di dh dj dh dk dh dl dm dn dm do dm dp dm dq dr ds dr dt du dv du dw dx dy dx dz dx d{ dx i> d| d d g d} d0 dR dT dU dV dk g  e$ d$ d d& d d( d d* d+ d, d- d, d. d/ d0 d/ d1 d2 d3 d2 d4 d2 d5 d2 d6 d7 d8 d7 d dK d dK d9 d: d; d: d< d= d> d/ d? d/ d@ d/ dA d/ dB dC dD dC dE dC dF dC dG dH dI dH dJ dK dL dK dM dN dO dN dP dN dQ dN dR dS dT dS dU dS dV dW dX dY dZ dY d[ dY d\ dY d] d^ d_ d^ d` da db da dc d2 dd d2 de dN df dN dg dh di dh dj dh dk dh dl dm dn dm do dm dp dm dq dr ds dr dt du dv du dw dx dy dx dz dx d{ dx i? d| d g d} dV g  e$ d$ d d& d d( d d* d+ d, d- d, d. d/ d0 d/ d1 d2 d3 d2 d4 d2 d5 d2 d6 d7 d8 d7 d9 d: d; d: d d= d< d= d> d/ d? d/ d@ d/ dA d/ dB dC dD dC dE dC dF dC dG dH dI dH dJ dK dL dK dM dN dO dN dP dN dQ dN dR dS dT dS dU dS dV dW dX dY dZ dY d[ dY d\ dY d] d^ d_ d^ d` d^ db da dc d2 dd d2 de d2 df d2 dg dh di dh dj dh dk dh dl dm dn dm do dm dp dm dq dr ds dr dt du dv du dw dx dy dx dz dx d{ dx i> d| d d g d} dV dk g  e$ d$ d d& d d( d d* d+ d, d- d, d. d/ d0 d/ d1 d2 d3 d2 d4 d2 d5 d2 d6 d7 d8 d7 d9 d: d; d: d d: d< d= d> d/ d? d/ d@ d/ dA d/ dB dC dD dC dE dC dF dC dG dH dI dH dJ dK dL dK dM dN dO dN dP dN dQ dN dR dS dT dS dU dS dV dW dX dY dZ dY d[ dY d\ dY d] d^ d_ d^ d` da db da dc d2 dd d2 de dN df dN dg dh di dh dj dh dk dh dl dm dn dm do dm dp dm dq dr ds dr dt du dv du dw dx dy dx dz dx d{ dx i> d| d d g d} dV g  e$ d$ d d& d d( d d* d+ d, d- d, d. d/ d0 d/ d1 d2 d3 d2 d4 d2 d5 d2 d6 d7 d8 d7 d9 d: d; d: d< d= d> d/ d? d/ d@ d/ dA d/ dB dC dD dC dE dC dF dC dG dH dI dH dJ dK dL dK dM dN dO dN dP dN dQ dN dR dS dT dS dU dS dV dW dX dY dZ dY d[ dY d\ dY d] d^ d_ d^ d` da db da dc d2 dd d2 de dN df dN dg dh di dh dj dh dk dh dl dm dn dm do dm dp dm dq dr ds dr dt du dv du dw dx dy dx dz dx d{ dx i= d| d d d g d} d0 dA dR dT dU dV dk g  e$ d$ d d& d d( d d* d+ d, d- d, d. d/ d0 d/ d1 d2 d3 d2 d4 d2 d5 d2 d6 d7 d8 d7 d9 d: d; d: d< d= d> d/ d? d/ d@ d/ dA d2 dB dC dD dC dE dC dF dC dG dH dI dH dJ dK dL dK dM dN dO dN dP dN dQ dN dR dS dT dS dU dS dV dW dX dY dZ dY d[ dY d\ dY d] d^ d_ d^ d` da db da dc d2 dd d2 de dN df dN dg dh di dh dj dh dk dh dl dm dn dm do dm dp dm dq dr ds dr dt du dv du dw dx dy dx dz dx d{ dx i= d| d d d g d} dA dV g  e$ d$ d d& d d( d d* d+ d, d- d, d. d/ d0 d/ d1 d2 d3 d2 d4 d2 d5 d2 d6 d7 d8 d7 d9 d: d; d: d d= d< d= d> d/ d? d/ d@ d/ dA d/ dB dC dD dC dE dC dF dC dG dH dI dH dJ dK dL dK dM dN dO dN dP dN dQ dN dR dS dT dS dU dW dV dW dX dY dZ dY d[ dY d\ dY d] d^ d_ d^ d` da db da dc d2 dd d2 de dx df dx dg dh di dh dj dh dk dh dl dm dn dm do dm dp dm dq dr ds dr dt du dv du dw dx dy dx dz dx d{ dx i> d| d d g d} d0 dU dV dk g  e$ d$ d d& d d( d d* d+ d, d- d, d. d/ d0 d/ d1 d2 d3 d2 d4 d2 d5 d2 d6 d7 d8 d7 d d7 d9 d: d; d: d d= d< d= d> d/ d? d/ d@ d/ dA d/ dB dC dD dC dE dC dF dC dG dH dI dH dJ dK dL dK dM dN dO dN dP dN dQ dN dR dS dT dS dU dS dV dW dX dY dZ dY d[ dY d\ dY d] d^ d_ d^ d` d^ db da dc d2 dd d2 de d2 df d2 dg dh di dh dj dh dk dh dl dm dn dm do dm dp dm dq dr ds dr dt du dv du dw dx dy dx dz dx d{ dx i? d| d g d} dV g  e$ d$ d d& d d( d d* d+ d, d- d, d. d/ d0 d/ d1 d2 d3 d2 d4 d2 d5 d2 d6 d7 d8 d7 d dK d9 d: d; d: d< d= d> d/ d? d/ d@ d/ dA d/ dB dC dD dC dE dC dF dC dG dH dI dH dJ dK dL dK dM dN dO dN dP dN dQ dN dR dS dT dS dU dS dV dW dX dY dZ dY d[ dY d\ dY d] d^ d_ d^ d` da db da dc d2 dd d2 de dN df dN dg dh di dh dj dh dk dh dl dm dn dm do dm dp dm dq dr ds dr dt du dv du dw dx dy dx dz dx d{ dx i> d| d d g d} dV g  e$ d$ d d& d d( d d* d+ d, d- d, d. d/ d0 d/ d1 d2 d3 d2 d4 d2 d5 d2 d6 d7 d8 d7 d d/ d9 d: d; d: d< d= d> d/ d? d/ d@ d/ dA d/ dB dC dD dC dE dC dF dC dG dH dI dH dJ dK dL dK dM dN dO dN dP dN dQ dN dR dS dT dS dU dS dV dW dX dY dZ dY d[ dY d\ dY d] d^ d_ d^ d` da db da dc d2 dd d2 de dN df dN dg dh di dh dj dh dk dh dl dm dn dm do dm dp dm dq dr ds dr dt du dv du dw dx dy dx dz dx d{ dx i> d| d d g d} dV g  e$ d$ d d& d d( d d* d+ d, d- d, d. d/ d0 d/ d1 d2 d3 d2 d4 d2 d5 d2 d6 d7 d8 d7 d9 d: d; d: d d= d< d= d> d/ d? d/ d@ d/ dA d/ dB dC dD dC dE dC dF dC dG dH dI dH dJ dK dL dK dM dN dO dN dP dN dQ dN dR dS dT dS dU dW dV dW dX dY dZ dY d[ dY d\ dY d] d^ d_ d^ d` d^ db da dc d2 dd d2 de d2 df d2 dg dh di dh dj dh dk dh dl dm dn dm do dm dp dm dq dr ds dr dt du dv du dw dx dy dx dz dx d{ dx i> d| d d g d} dV dk g  e$ d$ d d& d d( d d* d+ d, d- d, d. d/ d0 d/ d1 d2 d3 d2 d5 d2 d6 d7 d8 d7 d d/ d9 d: d; d: d< d= d> d/ d? d/ d@ d/ dA d/ dB dC dD dC dE dC dF dC dG dH dI dH dJ dK dL dK dM dN dO dN dP dN dQ dN dR dS dT dS dU dS dV dW dX dY dZ dY d[ dY d\ dY d] d^ d_ d^ d` da db da dc d2 dd d2 de dN df dN dg dh di dh dj dh dk dh dl dm dn dm do dm dp dm dq dr ds dr dt du dv du dw dx dy dx dz dx d{ dx i= d| d4 d d g d} dV g  e$ d$ d d& d d( d d* d+ d, d- d, d0 d/ d1 d2 d3 d2 d4 d2 d5 d2 d6 d7 d8 d7 d9 d: d; d: d< d= d> d/ d? d/ d@ d/ dA d/ dB dC dD dC dE dC dF dC dG dH dI dH dJ dK dL dK dM dN dO dN dP dN dQ dN dR dS dT dS dU dS dV dW dX dY dZ dY d[ dY d\ dY d] d^ d_ d^ d` da db da dc d2 dd d2 de dN df dN dg dh di dh dj dh dk dh dl dm dn dm do dm dp dm dq dr ds dr dt du dv du dw dx dy dx dz dx d{ dx i< d| d. d d d g d} dR dV dk g  e$ d$ d d& d d( d d* d+ d, d- d, d. d/ d0 d/ d1 d2 d3 d2 d4 d2 d5 d2 d6 d7 d8 d7 d9 d: d; d: d d= d< d= d> d/ d? d/ d@ d/ dA d/ dB dC dD dC dE dC dF dC dG dH dI dH dJ dK dL dK dM dN dO dN dP dN dQ dN dR dS dT dS dU dS dV dW dX dY dZ dY d[ dY d\ dY d] d^ d_ d^ d` da db da dc d2 dd d2 de d2 df da dg dh di dh dj dh dk dh dl dm dn dm do dm dp dm dq dr ds dr dt du dv du dw dx dy dx dz dx d{ dx i> d| d d g d} d0 dA dV dk g  e$ d$ d d& d d( d d* d+ d, d- d, d. d/ d0 d/ d1 d2 d3 d2 d4 d2 d5 d2 d6 d7 d8 d7 d9 d: d; d: d dx d< d= d> d/ d? d/ d@ d/ dA d/ dB dC dD dC dE dC dF dC dG dH dI dH dJ dK dL dK dM dN dO dN dP dN dQ dN dR dS dT dS dU dS dV dW dX dY dZ dY d[ dY d\ dY d] d^ d_ d^ d` da db da dc d2 dd d2 de dN df dN dg dh di dh dj dh dk dh dl dm dn dm do dm dp dm dq dr ds dr dt du dv du dw dx dy dx dz dx d{ dx i> d| d d g d} d0 dV dk g  e$ d$ d d& d d( d d* d+ d, d- d, d. d/ d0 d/ d1 d2 d3 d2 d4 d2 d5 d2 d6 d7 d8 d7 d9 d: d; d: d< d= d> d/ d? d/ d@ d/ dA dm dB dC dD dC dE dC dF dC dG dH dI dH dJ dK dL dK dM dN dO dN dP dN dQ dN dR dS dT dS dU dS dV dW dX dY dZ dY d[ dY d\ dY d] d^ d_ d^ d` da db da dc d2 dd d2 de dN df dN dg dh di dh dj dh dk dh dl dm dn dm do dm dp dm dq dr ds dr dt du dv du dw dx dy dx dz dx d{ dx i= d| d d d g d} dA dV g  e$ d$ d d& d d( d d* d+ d, d- d, d. d/ d0 d/ d1 d2 d3 d2 d4 d2 d5 d2 d6 d7 d8 d7 d dK d dK d9 d: d; d: d d= d< d= d> d/ d? d/ d@ d/ dA d/ dB dC dD dC dE dC dF dC dG dH dI dH dJ dK dL dK dM dN dO dN dP dN dQ dN dR dS dT dS dU dS dV dW dX dY dZ dY d[ dY d\ dY d] d^ d_ d^ d` da db da dc d2 dd d2 de dN df dN dg dh di dh dj dh dk dh dl dm dn dm do dm dp dm dq dr ds dr dt du dv du dw dx dy dx dz dx d{ dx i@ d| d g d} dV g  e$ d$ d d& d d( d d* d+ d, d- d, d. d/ d0 d/ d1 d2 d3 d2 d4 d2 d5 d2 d6 d7 d8 d7 d dK d dK d9 d: d; d: d d= d< d= d> d/ d? d/ d@ d/ dA d/ dB dC dD dC dE dC dF dC dG dH dI dH dJ dK dL dK dM dN dO dN dP dN dQ dN dR dS dT dS dU dS dV dW dX dY dZ dY d[ dY d\ dY d] d^ d_ d^ d` da db da dc d2 dd d2 de dN df dN dg dh di dh dj dh dk dh dl dm dn dm do dm dp dm dq dr ds dr dt du dv du dw dx dy dx dz dx d{ dx i@ d| d d d g d} dV g  e$ d$ d d& d d( d d* d+ d, d- d, d. d/ d0 d/ d1 d2 d3 d2 d4 d2 d5 d2 d6 d7 d8 d7 d d7 d d7 d9 d: d; d: d< d= d> d/ d? d/ d@ d/ dA d/ dB dC dD dC dE dC dF dC dG dH dI dH dJ dK dL dK dM dN dO dN dP dN dQ dN dR dS dT dS dU dS dV dW dX dY dZ dY d[ dY d\ dY d] d^ d_ d^ d` da db da dc d2 dd d2 de dN df dN dg dh di dh dj dh dk dh dl dm dn dm do dm dp dm dq dr ds dr dt du dv du dw dx dy dx dz dx d{ dx i? d| d g d} dV g  e$ d$ d d& d d( d d* d+ d, d- d, d. d/ d0 d/ d1 d2 d3 d2 d4 d2 d5 d2 d6 d7 d8 d7 d du d du d9 d: d; d: d< d= d> d/ d? d/ d@ d/ dA d/ dB dC dD dC dE dC dF dC dG dH dI dH dJ dK dL dK dM dN dO dN dP dN dQ dN dR dS dT dS dU dS dV dW dX dY dZ dY d[ dY d\ dY d] d^ d_ d^ d` da db da dc d2 dd d2 de dN df dN dg dh di dh dj dh dk dh dl dm dn dm do dm dp dm dq dr ds dr dt du dv du dw dx dy dx dz dx d{ dx i? d| d g d} dV g  e$ d$ d d& d d( d d* d+ d, d- d, d. d/ d0 d/ d1 d2 d3 d2 d4 d2 d5 d2 d6 d7 d8 d7 d du d du d9 d: d; d: d d= d< d= d> d/ d? d/ d@ d/ dA d/ dB dC dD dC dE dC dF dC dG dH dI dH dJ dK dL dK dM dN dO dN dP dN dQ dN dR dS dT dS dU dS dV dW dX dY dZ dY d[ dY d\ dY d] d^ d_ d^ d` da db da dc d2 dd d2 de dN df dN dg dh di dh dj dh dk dh dl dm dn dm do dm dp dm dq dr ds dr dt du dv du dw dx dy dx dz dx d{ dx i@ d| d d g d} dV g  e$ d$ d d& d d( d d* d+ d, d- d, d. d/ d0 d/ d1 d2 d3 d2 d4 d2 d5 d2 d6 d7 d8 d7 d d= d9 d: d; d: d< d= d> d/ d? d/ d@ d/ dA d/ dB dC dD dC dE dC dF dC dG dH dI dH dJ dK dL dK dM dN dO dN dP dN dQ dN dR dS dT dS dU dS dV dW dX dY dZ dY d[ dY d\ dY d] d^ d_ d^ d` da db da dc d2 dd d2 de dN df dN dg dh di dh dj dh dk dh dl dm dn dm do dm dp dm dq dr ds dr dt du dv du dw dx dy dx dz dx d{ dx i> d| d d d g d} d0 dA dR dT dU dV dk g  d S)zCodon tables based on those from the NCBI.

These tables are based on parsing the NCBI file
ftp://ftp.ncbi.nih.gov/entrez/misc/data/gc.prt
using Scripts/update_ncbi_codon_table.py

Last updated at Version 4.4 (May 2019)
    )Alphabet)IUPAC)	IUPACDataNc               @   s   e  Z d  Z d Z d S)TranslationErrorz.Container for translation specific exceptions.N)__name__
__module____qualname____doc__ r
   r
   8/tmp/pip-build-ww9dw3qa/biopython/Bio/Data/CodonTable.pyr   -   s   r   c               @   sj   e  Z d  Z d Z e j Z e j Z i  Z	 i  Z
 g  Z g  Z e e e	 e
 e e d d  Z d d   Z d S)
CodonTablezA codon-table, or genetic code.c             C   s:   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ d S)zInitialize the class.N)nucleotide_alphabetprotein_alphabetforward_table
back_tablestart_codonsstop_codons)selfr   r   r   r   r   r   r
   r
   r   __init__?   s    					zCodonTable.__init__c       	      C   s  |  j  r d |  j  } n d } |  j rO | d d j d d   |  j D  7} |  j j } t |  j t j  s | d k	 r d | k r d	 } n d
 } | d 7} | d d j d d   | D  d 7} | d d j d d   | D  d 7} x'| D]} x | D] } | d } x | D] } | | | } | d | 7} | |  j k rZ| d 7} qy |  j	 | } Wn/ t
 k
 rd } Yn t k
 rd } Yn X| |  j k r| d | 7} q| d | 7} qW| d | 7} | d | 7} qW| d d j d d   | D  d 7} q W| S)a  Return a simple text representation of the codon table.

        e.g.::

            >>> import Bio.Data.CodonTable
            >>> print(Bio.Data.CodonTable.standard_dna_table)
            Table 1 Standard, SGC0
            <BLANKLINE>
              |  T      |  C      |  A      |  G      |
            --+---------+---------+---------+---------+--
            T | TTT F   | TCT S   | TAT Y   | TGT C   | T
            T | TTC F   | TCC S   | TAC Y   | TGC C   | C
            ...
            G | GTA V   | GCA A   | GAA E   | GGA G   | A
            G | GTG V   | GCG A   | GAG E   | GGG G   | G
            --+---------+---------+---------+---------+--
            >>> print(Bio.Data.CodonTable.generic_by_id[1])
            Table 1 Standard, SGC0
            <BLANKLINE>
              |  U      |  C      |  A      |  G      |
            --+---------+---------+---------+---------+--
            U | UUU F   | UCU S   | UAU Y   | UGU C   | U
            U | UUC F   | UCC S   | UAC Y   | UGC C   | C
            ...
            G | GUA V   | GCA A   | GAA E   | GGA G   | A
            G | GUG V   | GCG A   | GAG E   | GGG G   | G
            --+---------+---------+---------+---------+--
        zTable %izTable ID unknown z, c             S   s   g  |  ] } | r |  q Sr
   r
   ).0xr
   r
   r   
<listcomp>m   s   	 z&CodonTable.__str__.<locals>.<listcomp>NTZTCAGZUCAGz

z  ||c             s   s   |  ] } d  | Vq d S)z
  %s      Nr
   )r   c2r
   r
   r   	<genexpr>|   s    z%CodonTable.__str__.<locals>.<genexpr>z
--++c             s   s   |  ] } d  Vq d S)z	---------Nr
   )r   r   r
   r
   r   r   }   s    z+--z |z %sz Stop|?z %s(s)|z %s   |
c             s   s   |  ] } d  Vq d S)z	---------Nr
   )r   r   r
   r
   r   r      s    )idnamesjoinr   letters
isinstancer   ZDNAAlphabetr   r   KeyErrorr   r   )	r   answerr#   c1c3liner   codonaminor
   r
   r   __str__K   sD    		'	
((

,zCodonTable.__str__N)r   r   r   r	   r   generic_nucleotider   Zgeneric_proteinr   r   r   r   r   r   r,   r
   r
   r
   r   r   3   s   			r   c             C   s9   i  } x" t  |   D] } | | |  | <q W| | d <| S)zBack a back-table (naive single codon mapping).

    ONLY RETURNS A SINGLE CODON, chosen from the possible alternatives
    based on their sort order.
    N)sorted)tableZdefault_stop_codonr   keyr
   r
   r   make_back_table   s
    
r1   c               @   s@   e  Z d  Z d Z e j Z e j Z	 d d   Z
 d d   Z d S)NCBICodonTablez-Codon table for generic nucleotide sequences.c             C   sG   | |  _  | |  _ | |  _ t | | d  |  _ | |  _ | |  _ d S)zInitialize the class.r   N)r    r!   r   r1   r   r   r   )r   r    r!   r/   r   r   r
   r
   r   r      s    				zNCBICodonTable.__init__c             C   s   d |  j  j |  j |  j f S)z?Represent the NCBI codon table class as a string for debugging.z%s(id=%r, names=%r, ...))	__class__r   r    r!   )r   r
   r
   r   __repr__   s    zNCBICodonTable.__repr__N)r   r   r   r	   r   r-   r   r   Zproteinr   r   r4   r
   r
   r
   r   r2      s
   			r2   c               @   s   e  Z d  Z d Z e j Z d S)NCBICodonTableDNAz*Codon table for unambiguous DNA sequences.N)r   r   r   r	   r   Zunambiguous_dnar   r
   r
   r
   r   r5      s   r5   c               @   s   e  Z d  Z d Z e j Z d S)NCBICodonTableRNAz*Codon table for unambiguous RNA sequences.N)r   r   r   r	   r   Zunambiguous_rnar   r
   r
   r
   r   r6      s   r6   c               @   s.   e  Z d  Z d Z d d   Z d d   Z d S)AmbiguousCodonTablez)Base codon table for ambiguous sequences.c          
   C   sV   t  j |  | | t | j | |  | j t | j |  t | j |   | |  _ d S)zInitialize the class.N)	r   r   AmbiguousForwardTabler   r   list_ambiguous_codonsr   r   _codon_table)r   Zcodon_tableZambiguous_nucleotide_alphabetambiguous_nucleotide_valuesZambiguous_protein_alphabetZambiguous_protein_valuesr
   r
   r   r      s    				
zAmbiguousCodonTable.__init__c             C   s   t  |  j |  S)z0Forward attribute lookups to the original table.)getattrr:   )r   namer
   r
   r   __getattr__   s    zAmbiguousCodonTable.__getattr__N)r   r   r   r	   r   r>   r
   r
   r
   r   r7      s   r7   c             C   s   |  \ } } } | | } | | } | | } i  }	 g  }
 xt | D]l } xc | D][ } xR | D]J } y d |	 | | | | <WqZ t  k
 r |
 j | | |  YqZ XqZ WqM Wq@ W|
 r |	 r t d |    t  |    t |	  S)z<Return all possible encoded amino acids for ambiguous codon.   z:ambiguous codon %r codes for both proteins and stop codons)r%   appendr   list)r*   r   r;   r'   r   r(   x1Zx2Zx3possibleZstopsy1y2Zy3r
   r
   r   list_possible_proteins   s&    


&
rF   c                s]  t   f d d    j   D  } t   f d d    j   D  } t   f d d    j   D  } g  } xc | D][ } xR | D]J } xA | D]9 } | | | }	 |	 | k r |	  k r | j |	  q Wq Wq| W d d  }
 xk | D]c   d } xA    f d d      d	 D D] }	 |	  k r#d
 } q#q#W| r |
 j    q W|
 S)a  Extend a codon list to include all possible ambigous codons.

    e.g.::

         ['TAG', 'TAA'] -> ['TAG', 'TAA', 'TAR']
         ['UAG', 'UGA'] -> ['UAG', 'UGA', 'URA']

    Note that ['TAG', 'TGA'] -> ['TAG', 'TGA'], this does not add 'TRR'
    (which could also mean 'TAA' or 'TGG').
    Thus only two more codons are added in the following:

    e.g.::

        ['TGA', 'TAA', 'TAG'] -> ['TGA', 'TAA', 'TAG', 'TRA', 'TAR']

    Returns a new (longer) list of codon strings.
    c             3   s=   |  ]3 \ } } d  d     D j  t |   r | Vq d S)c             S   s   h  |  ] } | d   q S)r   r
   )r   r*   r
   r
   r   	<setcomp>  s   	z2list_ambiguous_codons.<locals>.<genexpr>.<setcomp>N)
issupersetset)r   lettermeanings)codonsr
   r   r     s    		z(list_ambiguous_codons.<locals>.<genexpr>c             3   s=   |  ]3 \ } } d  d     D j  t |   r | Vq d S)c             S   s   h  |  ] } | d   q S)r?   r
   )r   r*   r
   r
   r   rG      s   	z2list_ambiguous_codons.<locals>.<genexpr>.<setcomp>N)rH   rI   )r   rJ   rK   )rL   r
   r   r     s    		c             3   s=   |  ]3 \ } } d  d     D j  t |   r | Vq d S)c             S   s   h  |  ] } | d   q S)   r
   )r   r*   r
   r
   r   rG   $  s   	z2list_ambiguous_codons.<locals>.<genexpr>.<setcomp>N)rH   rI   )r   rJ   rK   )rL   r
   r   r   "  s    		NTc                sH   g  |  ]> }    d  D]) }    d D] } | | |  q* q q S)r?   rM   r
   )r   r'   r   r(   )ambig_codonr;   r
   r   r   3  s   	z)list_ambiguous_codons.<locals>.<listcomp>r   F)r.   itemsr@   )rL   r;   Zc1_listZc2_listZc3_list
candidatesr'   r   r(   r*   r&   Zwantedr
   )rN   r;   rL   r   r9     s0    r9   ZTGAZTAAZTRAZTAGZTARZUAGZUAAZUARc               @   sI   e  Z d  Z d Z d d   Z d d   Z d d d  Z d	 d
   Z d S)r8   z@Forward table for translation of ambiguous nucleotide sequences.c       	      C   s   | |  _  | |  _ | |  _ i  } xQ | j   D]C \ } } x4 | D], } | j | i   } d | | <| | | <qA Wq. Wx* | j   D] \ } } t |  | | <q W| |  _ i  |  _ d S)zInitialize the class.r?   N)r   ambiguous_nucleotideambiguous_proteinrO   getrA   	_inverted_cache)	r   r   rQ   rR   Zinvertedr=   valcr   r
   r
   r   r   d  s    			
	zAmbiguousForwardTable.__init__c             C   s8   y |  j  |  d SWn t t f k
 r3 d SYn Xd S)zCheck if codon works as key for ambiguous forward_table.

        Only returns 'True' if forward_table[codon] returns a value.
        TFN)__getitem__r%   r   )r   r*   r
   r
   r   __contains__w  s
    z"AmbiguousForwardTable.__contains__Nc             C   s.   y |  j  |  SWn t k
 r) | SYn Xd S)z,Implement get for dictionary-like behaviour.N)rX   r%   )r   r*   failobjr
   r
   r   rS     s    zAmbiguousForwardTable.getc       	         sA  y   j  | } Wn t k
 r% Yn5 X| t k r> t |   | t k rV t |   | Sy"   j | } |   j  | <| SWn t k
 r Yn Xy t |   j   j  } WnU t k
 r t   j  | <t |   Yn+ t k
 rt   j  | <t |   Yn Xt |  d k s#t d   t |  d k rN| d   j  | <| d Si  } x@ | D]8 } x/   j | D]  } | j	 | d  d | | <qoWq[Wt |  } g  } x3 | j
   D]% \ } } | | k r| j |  qWt |  d k r
t   j  | <t |   | j d   f d d    | d } |   j  | <| S)a  Implement dictionary-like behaviour for AmbiguousForwardTable.

        forward_table[codon] will either return an amino acid letter,
        or throws a KeyError (if codon does not encode an amino acid)
        or a TranslationError (if codon does encode for an amino acid,
        but either is also a stop codon or does encode several amino acids,
        for which no unique letter is available in the given alphabet.
        r   zunambiguous codons must coder?   r0   c                s   t    j |   |  f S)N)lenrR   )r   )r   r
   r   <lambda>  s    z3AmbiguousForwardTable.__getitem__.<locals>.<lambda>)rU   r%   r   r   rF   rQ   r[   AssertionErrorrT   rS   rO   r@   sort)	r   r*   r   rC   Zambiguous_possibler+   ZtermnrV   r
   )r   r   rX     sZ    	"
z!AmbiguousForwardTable.__getitem__)r   r   r   r	   r   rY   rS   rX   r
   r
   r
   r   r8   a  s
   r8   c             C   s  d d   |  j  d d  j  d d  j d  D } t | | | g | | |  } t | t j t j t j t j	  } i  }	 i  }
 xJ | j
   D]< \ } } | |
 | <| j  d d  } | |
 | <| |	 | <q Wg  } g  } xS | D]K } | j |  d | k r!| j  d d  } | j |  | j |  q Wg  } g  } xS | D]K } | j |  d | k r| j  d d  } | j |  | j |  qEWt | | | g |
 | |  } t t j j
    } d | d <t | t j   | t j t j	  } t | | | g |	 | |  } t | t j t j t j t j	  } | d k rQ| a | a | t | <| t | <| t | <| t | <| t | <| t | <| d	 k	 r| j |  xJ | D]B }  | t |  <| t |  <| t |  <| t |  <| t |  <| t  |  <qWd	 S)
z_Turn codon table data into objects (PRIVATE).

    The data is stored in the dictionaries.
    c             S   s   g  |  ] } | j     q Sr
   )strip)r   r   r
   r
   r   r     s   	 z'register_ncbi_table.<locals>.<listcomp>z and z; z, r   Ur?   N)!replacesplitr5   r7   r   Zambiguous_dnar   ambiguous_dna_valuesZextended_proteinZextended_protein_valuesrO   r@   r2   dictambiguous_rna_valuesr   ZNucleotideAlphabetr6   Zambiguous_rnastandard_dna_tablestandard_rna_tableunambiguous_dna_by_idunambiguous_rna_by_idgeneric_by_idambiguous_dna_by_idambiguous_rna_by_idambiguous_generic_by_idunambiguous_dna_by_nameunambiguous_rna_by_namegeneric_by_nameambiguous_dna_by_nameambiguous_rna_by_nameambiguous_generic_by_name)r=   alt_namer    r/   r   r   r!   ZdnaZ	ambig_dnaZ	rna_tableZgeneric_tabler*   rV   Zrna_start_codonsZgeneric_start_codonsZrna_stop_codonsZgeneric_stop_codonsZgenericZ_merged_valuesZambig_genericZrnaZ	ambig_rnar
   r
   r   register_ncbi_table  s    		


	










rv   r=   ZStandardru   ZSGC0r    r?   r/   ZTTTFZTTCZTTALZTTGZTCTSZTCCZTCAZTCGZTATYZTACZTGTCZTGCZTGGWZCTTZCTCZCTAZCTGZCCTPZCCCZCCAZCCGZCATHZCACZCAAQZCAGZCGTRZCGCZCGAZCGGZATTIZATCZATAZATGMZACTr   ZACCZACAZACGZAATNZAACZAAAKZAAGZAGTZAGCZAGAZAGGZGTTVZGTCZGTAZGTGZGCTAZGCCZGCAZGCGZGATDZGACZGAAEZGAGZGGTGZGGCZGGAZGGGr   r   zVertebrate MitochondrialZSGC1rM   zYeast MitochondrialZSGC2   z`Mold Mitochondrial; Protozoan Mitochondrial; Coelenterate Mitochondrial; Mycoplasma; SpiroplasmaZSGC3   zInvertebrate MitochondrialZSGC4   z8Ciliate Nuclear; Dasycladacean Nuclear; Hexamita NuclearZSGC5   z0Echinoderm Mitochondrial; Flatworm MitochondrialZSGC8	   zEuplotid NuclearZSGC9
   z%Bacterial, Archaeal and Plant Plastid   zAlternative Yeast Nuclear   zAscidian Mitochondrial   z"Alternative Flatworm Mitochondrial   zBlepharisma Macronuclear   zChlorophycean Mitochondrial   zTrematode Mitochondrial   z"Scenedesmus obliquus Mitochondrial   zThraustochytrium Mitochondrial   zPterobranchia Mitochondrial   z*Candidate Division SR1 and Gracilibacteria   zPachysolen tannophilus Nuclear   zKaryorelict Nuclear   zCondylostoma Nuclear   zMesodinium Nuclear   zPeritrich Nuclear   zBlastocrithidia Nuclear   zBalanophoraceae Plastid    )%r	   ZBior   ZBio.Alphabetr   ZBio.Datar   ro   ri   rp   rj   rq   rk   rr   rl   rs   rm   rt   rn   rg   rh   	Exceptionr   objectr   r1   r2   r5   r6   r7   rF   r9   rd   r]   rf   r8   rv   r
   r
   r
   r   <module>   sh  d#<xe	


	



	

	
	

