
    RiM                     )   d Z ddlmZ ddlmZ i Zi Zi Zi Zi Z	i Z
i Zi Zi Zi Zi Zi Zdada G d de      Z G d d      Zd	 Z G d
 de      Z G d de      Z G d de      Z G d de      Zd Zd Z eddgej:                        g dk(  sJ  eddgej:                        ddgk(  sJ  eddgej:                        g dk(  sJ  eddgej<                        g dk(  sJ  eg dej:                        g dk(  sJ  G d d      Zd  Z  e d!d"d#i d$d%d&d%d'd(d)d(d*d+d,d+d-d+d.d+d/d0d1d0d2d3d4d3d5d6d7d(d8d(d9d(d:d(i d;d<d=d<d>d<d?d<d@dAdBdAdCdDdEdDdFdGdHdGdIdGdJdGdKdLdMdLdNdLdOdPdQdRi dSdRdTdRdUdRdVdWdXdWdYdZd[dZd\d+d]d+d^dGd_dGd`dadbdadcdadddadedfdgdfdfdfdhdhdididjdjdjdjdk
g dlg dmn        e dodpdqi d$d%d&d%d'd(d)d(d*d+d,d+d-d+d.d+d/d0d1d0d2d3d4d3dd6d5d6d7d(d8d(d9d(i d:d(d;d<d=d<d>d<d?d<d@dAdBdAdCdDdEdDdFdGdHdGdIdGdJdGdKdLdMdLdNdPdOdPi dQdRdSdRdTdRdUdRdVdWdXdWdYdZd[dZd\d+d]d+d`dadbdadcdadddadedfdgdfdrdfdfdhdhdididjdjdjdjds	g dtg dun        e dvdwdxi d$d%d&d%d'd(d)d(d*d+d,d+d-d+d.d+d/d0d1d0d2d3d4d3dd6d5d6d7dRd8dRd9dRi d:dRd;d<d=d<d>d<d?d<d@dAdBdAdCdDdEdDdFdGdHdGdIdGdJdGdKdLdMdLdNdPdOdPi dQdRdSdRdTdRdUdRdVdWdXdWdYdZd[dZd\d+d]d+d^dGd_dGd`dadbdadcdadddadedfdfdfdfdhdhdididjdjdjdjdyddgg dzn        e d{d|d}i d$d%d&d%d'd(d)d(d*d+d,d+d-d+d.d+d/d0d1d0d2d3d4d3dd6d5d6d7d(d8d(d9d(i d:d(d;d<d=d<d>d<d?d<d@dAdBdAdCdDdEdDdFdGdH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jdjdjdjdyddgdOgn        e dddi d$d%d&d%d'd(d)d(d*d+d,d+d-d+d.d+d/d0d1d0d2d3d4d3d5d6d7d(d8d(d9d(d:d(i d;d<d=d<d>d<d?d<d@dAdBdAdCdDdEdDdFdGdHdGdIdGdJdGdKdLdMdLdNdLdOdPdQdRi dSdRdTdRdUdRdVdWdXdWdYdZd[dZd\d+d]d+d^dGd_dGd`dadbdadcdadddadedfdgdfdfdfdhdhdididjdjdjdjdk
g dlg dn        e dddi d$d%d&d%d'd(d)d(d*d+d,d+d-d+d.d+d/d0d1d0d2d3d4d3d5d6d7d(d8d(d9d(d:d+i d;d<d=d<d>d<d?d<d@dAdBdAdCdDdEdDdFdGdHdGdIdGdJdGdKdLdMdLdNdLdOdPdQdRi dSdRdTdRdUdRdVdWdXdWdYdZd[dZd\d+d]d+d^dGd_dGd`dadbdadcdadddadedfdgdfdfdfdhdhdididjdjdjdjdk
g dld:dOgn        e dddi d$d%d&d%d'd(d)d(d*d+d,d+d-d+d.d+d/d0d1d0d2d3d4d3dd6d5d6d7d(d8d(d9d(i d:d(d;d<d=d<d>d<d?d<d@dAdBdAdCdDdEdDdFdGdHdGdIdGdJdGdKdLdMdLdNdPdOdPi dQdRdSdRdTdRdUdRdVdWdXdWdYdZd[dZd\d+d]d+d^djd_djd`dadbdadcdadddadedfdfdfdfdhdhdididjdjdjdjdyddgg dn        e dddi d$d%d&d%d'd(d)d(d*d+d,d+d-d+d.d+d/d0d1d0dd0d2d3d4d3dd6d5d6d7d(d8d(i d9d(d:d(d;d<d=d<d>d<d?d<d@dAdBdAdCdDdEdDdFdGdHdGdIdGdJdGdKdLdMdLdNdLi dOdPdQdRdSdRdTdRdUdRdVdWdXdWdYdWd[dZd\d+d]d+d^d+d_d+d`dadbdadcdadddadfdfdfdfdhdhdididjdjdjdjddgdOgn        e dddi d$d%d&d%d'd(d)d(d*d+d,d+d-d+d.d+d/d0d1d0ddDd2d3d4d3d5d6d7d(d8d(d9d(i d:d(d;d<d=d<d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adbdadcdadddadedfdgdfdrdfdfdhdhdididjdjdjdjds	g dg dn        e dddi d$d%d&d%d'd(d)d(d*d+d,d+d-d+d.d+d/d0d1d0d2d3d4d3dd6d5d6d7d(d8d(d9d(i d:d(d;d<d=d<d>d<d?d<d@dAdBdAdCdDdEdDdFdGdHdGdIdGdJdGdKdLdMdLdNdLdOdPi dQdRdSdRdTdRdUdRdVdWdXdWdYdZd[dZd\d+d]d+d^d+d_dZd`dadbdadcdadddadedfdfdfdfdhdhdididjdjdjdjdyddgg dn        e dddi d$d%d&d%d'd(d)d(d*d+d,d+d-d+d.d+d/d0d1d0d2d3d4d3ddjd5d6d7d(d8d(d9d(i d:d(d;d<d=d<d>d<d?d<d@dAdBdAdCdDdEdDdFdGdHdGdIdGdJdGdKdLdMdLdNdLdOdPi dQdRdSdRdTdRdUdRdVdWdXdWdYdZd[dZd\d+d]d+d^dGd_dGd`dadbdadcdadddadedfdfdfdfdhdhdididjdjdjdjdyddgg dn        e dddi d$d%d&d%d'd(d)d(d*d+d,d+d-d+d.d+d/d0d1d0d2d3d4d3d5d6d7d(d8d(d9d(d:dfi d;d<d=d<d>d<d?d<d@dAdBdAdCdDdEdDdFdGdHdGdIdGdJdGdKdLdMdLdNdLdOdPdQdRi dSdRdTdRdUdRdVdWdXdWdYdZd[dZd\d+d]d+d^dGd_dGd`dadbdadcdadddadedfdgdfdfdfdhdhdididjdjdjdjdk
g dld:dOgn        e dddi d$d%d&d%d'd(d)d(d*d+d,d+d-d+d.d+d/d0d1d0ddDddDd2d3d4d3dd6d5d6d7d(i d8d(d9d(d:d(d;d<d=d<d>d<d?d<d@dAdBdAdCdDdEdDdFdGdHdGdIdGdJdGdKdLdMdLi dNdLdOdPdQdRdSdRdTdRdUdRdVdWdXdWdYdZd[dZd\d+d]d+d^dGd_dGd`dadbdadcdadadfdfdfdfdhdhdididjdjdjdjddgdOgn        e dddi d$d%d&d%d'd(d)d(d*d+d,d+d-d+d.d+d/d0d1d0ddDddDd2d3d4d3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RdVdWdXdWdYdZd[dZd\d+d]d+d^dGd_dGd`dadbdadcdadddadedfdfdfdfdhdhdididjdjdjdjdyddgg dn        e dddi d$d%d&d%d'd(d)d(d*d+d,d+d-d+d.d+d/d0d1d0dd0d2d3d4d3dd6d5d6d7d(d8d(i d9d(d:d(d;d<d=d<d>d<d?d<d@dAdBdAdCdDdEdDdFdGdHdGdIdGdJdGdKdLdMdLdNdLi dOdPdQdRdSdRdTdRdUdRdVdWdXdWdYdZd[dZd\d+d]d+d^d+d_dZd`dadbdadcdadddadfdfdfdfdhdhdididjdjdjdjddgg dn       y)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)
    )Optional)	IUPACDataNc                       e Zd ZdZy)TranslationErrorz.Container for translation specific exceptions.N)__name__
__module____qualname____doc__     K/home/agent/.friday_env/lib/python3.12/site-packages/Bio/Data/CodonTable.pyr   r   ,   s    8r   r   c                       e Zd ZU dZi Zeeef   ed<   i Zeeef   ed<   g Z	e
e   ed<   g Ze
e   ed<   ddeee	efdedz  dedz  deeef   deeef   de
e   de
e   d	dfd
Zd Zy)
CodonTablezA codon-table, or genetic code.forward_table
back_tablestart_codonsstop_codonsNnucleotide_alphabetprotein_alphabetreturnc                 X    || _         || _        || _        || _        || _        || _        yInitialize the class.N)r   r   r   r   r   r   )selfr   r   r   r   r   r   s          r   __init__zCodonTable.__init__9   s3     $7  0*$(&r   c                    | j                   rd| j                   z  }nd}| j                  r2|ddj                  | j                  D cg c]  }|s|	 c}      z   z  }| j                  }|d|v rd}nd}|dz  }|d	d
j                  d |D              z   d
z   z  }|ddj                  d |D              z   dz   z  }|D ]  }|D ]s  }|dz   }|D ]W  }||z   |z   }|d| z  }|| j                  v r|dz  }'	 | j
                  |   }	|| j                  v r
|d|	 dz  }O|d|	 dz  }Y |d|z   z  }|d|z   z  }u |ddj                  d |D              z   dz   z  } |S c c}w # t        $ r d}	Y lt        $ r d}	Y xw xY w)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
            --+---------+---------+---------+---------+--
        zTable %izTable ID unknown , TTCAGUCAGz

z  ||c              3   (   K   | ]
  }d | d  yw)z  z      Nr   .0c2s     r   	<genexpr>z%CodonTable.__str__.<locals>.<genexpr>z   s     "ErRt6?"Es   z
--++c              3       K   | ]  }d   ywz	---------Nr   r$   s     r   r'   z%CodonTable.__str__.<locals>.<genexpr>{   s     $CR[$C   z+--z |z Stop|?z(s)|z   |
c              3       K   | ]  }d   ywr*   r   r$   s     r   r'   z%CodonTable.__str__.<locals>.<genexpr>   s     (G(Gr+   )	idnamesjoinr   r   r   KeyErrorr   r   )
r   answerxlettersc1c3liner&   codonaminos
             r   __str__zCodonTable.__str__J   s   : 77$'')F'F::cDII$**&BQq&BCCCF **3'>G G 	&%#(("EW"EEEKK'CHH$C7$CCCeKK 	PB &Dy! 4BGbLEawK'D 0 00(($($6$6u$=E
 !D$5$55 awdO3D awdO3D4  b $+%'&( g(Gw(G GG%OOF+	P, M 'C6  ( ($'E/ ($'E(s$   EE4E""E<	/
E<	;E<	)r   r   r	   r
   r   dictstr__annotations__r   r   listr   r   r;   r   r   r   r   r   0   s    )$&M4S>&!#JS#X# L$s) Kc
 +/'+(5%/".!,' 4Z' *' CH~	'
 cN' 3i' #Y' 
'"Hr   r   c                 D    i }t        |       D ]
  }||| |   <    ||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)tabledefault_stop_codonr   keys       r   make_back_tablerE      s:     Je} %!$
5:%)Jtr   c                   J    e Zd ZU dZdZedz  ed<   ej                  Z	d Z
d Zy)NCBICodonTablez-Codon table for generic nucleotide sequences.Nr   c                 r    || _         || _        || _        t        ||d         | _        || _        || _        y)r   r   N)r/   r0   r   rE   r   r   r   )r   r/   r0   rB   r   r   s         r   r   zNCBICodonTable.__init__   s:    
")%Q@(&r   c                 h    | j                   j                   d| j                  d| j                  dS )z?Represent the NCBI codon table class as a string for debugging.z(id=z, names=z, ...))	__class__r   r/   r0   )r   s    r   __repr__zNCBICodonTable.__repr__   s.    ..))*$twwk$**vVVr   )r   r   r	   r
   r   r=   r>   r   protein_lettersr   r   rK   r   r   r   rG   rG      s+    7&*t* 00'Wr   rG   c                   (    e Zd ZdZej
                  Zy)NCBICodonTableDNAz*Codon table for unambiguous DNA sequences.N)r   r   r	   r
   r   unambiguous_dna_lettersr   r   r   r   rN   rN          4#;;r   rN   c                   (    e Zd ZdZej
                  Zy)NCBICodonTableRNAz*Codon table for unambiguous RNA sequences.N)r   r   r	   r
   r   unambiguous_rna_lettersr   r   r   r   rR   rR      rP   r   rR   c                       e Zd ZdZd Zd Zy)AmbiguousCodonTablez)Base codon table for ambiguous sequences.c                     t         j                  | ||t        |j                  ||      |j                  t        |j                  |      t        |j                  |             || _        yr   )	r   r   AmbiguousForwardTabler   r   list_ambiguous_codonsr   r   _codon_table)r   codon_tableambiguous_nucleotide_alphabetambiguous_nucleotide_valuesambiguous_protein_alphabetambiguous_protein_valuess         r   r   zAmbiguousCodonTable.__init__   sp     	)&!))+(
 "" "((*E "+"9"9;VW!	
$ (r   c                 .    t        | j                  |      S )z0Forward attribute lookups to the original table.)getattrrY   )r   names     r   __getattr__zAmbiguousCodonTable.__getattr__   s    t(($//r   N)r   r   r	   r
   r   rb   r   r   r   rU   rU      s    3(@0r   rU   c                    | \  }}}||   }||   }||   }i }	g }
|D ]  }|D ]  }|D ]  }	 d|	|||z   |z      <     ! |
r|	rt        d| d      t        |       t        |	      S # t         $ r |
j                  ||z   |z          Y cw xY w)z<Return all possible encoded amino acids for ambiguous codon.   zambiguous codon z( codes for both proteins and stop codons)r2   appendr   r?   )r9   r   r\   r6   r&   r7   x1x2x3possiblestopsy1y2y3s                 r   list_possible_proteinsrn      s    JBB	$R	(B	$R	(B	$R	(BHE / 	/B //<=H]27R<89/	// ""5)+ST  uo>   /LLb2./s   A'' B
		B
	c           
      &    t         fd|j                         D              }t         fd|j                         D              }t         fd|j                         D              }g }|D ]3  }|D ],  }|D ]%  }||z   |z   }	|	|vs|	 vs|j                  |	       ' . 5  dd }
|D ]^  }d}||d      D cg c]$  }||d      D ]  }||d      D ]
  }||z   |z     & c}}}D ]	  }	|	 vsd	} |sN|
j                  |       ` |
S c c}}}w )
a  Extend a codon list to include all possible ambiguous 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      K   | ]4  \  }}D ch c]  }|d    	 c}j                  t        |            r| 6 yc c}w w)r   N
issupersetsetr%   lettermeaningsr9   codonss       r   r'   z(list_ambiguous_codons.<locals>.<genexpr>  C      FH"()E!H)44S]C 	 *   A='Ac              3      K   | ]4  \  }}D ch c]  }|d    	 c}j                  t        |            r| 6 yc c}w w)rd   Nrq   rt   s       r   r'   z(list_ambiguous_codons.<locals>.<genexpr>#  rx   ry   c              3      K   | ]4  \  }}D ch c]  }|d    	 c}j                  t        |            r| 6 yc c}w w)   Nrq   rt   s       r   r'   z(list_ambiguous_codons.<locals>.<genexpr>(  rx   ry   NTr   rd   r|   F)rA   itemsre   )rw   r\   c1_listc2_listc3_list
candidatesr6   r&   r7   r9   r3   ambig_codonwanteds   `            r   rX   rX   	  s   *   ; A A C G
   ; A A C G
   ; A A C G J - 	-B -R"
*uF/B%%e,-	-- AYF! ' 2+a.A
 
1+a.A
 1+a.A	
  GbL


 
	E F"
	 MM+&'  M
s   :)D
TGATAA)r   r   TRATAG)r   r   TARUAGUAA)r   r   UAR)r   r   r   )r   r   r   r   r   c                   *    e Zd ZdZd Zd ZddZd Zy)rW   z@Forward table for translation of ambiguous nucleotide sequences.c                    || _         || _        || _        i }|j                         D ](  \  }}|D ]  }|j	                  |i       }d||<   |||<     * |j                         D ]  \  }}t        |      ||<    || _        i | _        y)r   rd   N)r   ambiguous_nucleotideambiguous_proteinr}   getr?   	_inverted_cache)	r   r   r   r   invertedra   valcr4   s	            r   r   zAmbiguousForwardTable.__init__x  s    *$8!!2*002 	 ID#  LLB'$ 	 
 ") 	'ID#!#YHTN	'!r   c                 R    	 | j                  |       y# t        t        f$ r Y yw xY w)zCheck if codon works as key for ambiguous forward_table.

        Only returns 'True' if forward_table[codon] returns a value.
        TF)__getitem__r2   r   )r   r9   s     r   __contains__z"AmbiguousForwardTable.__contains__  s0    
	U#*+ 		s    &&Nc                 H    	 | j                  |      S # t        $ r |cY S w xY w)z,Implement get for dictionary-like behaviour.)r   r2   )r   r9   failobjs      r   r   zAmbiguousForwardTable.get  s,    	##E** 	N	s    !!c                     	  j                   |   }|t        u rt        |      |t        u rt        |      |S # t        $ r Y nw xY w	  j                  |   }| j                   |<   |S # t        $ r Y nw xY w	 t	        | j                   j
                        }nR# t        $ r  t         j                   |<   t        |      dt        $ r t         j                   |<   t        |      w xY wt        |      dkD  sJ d       t        |      dk(  r|d    j                   |<   |d   S i }|D ].  } j                  |   D ]  }|j                  |d      dz   ||<    0 t        |      }g }|j                         D ]  \  }}||k(  s|j                  |        t        |      dk(  rt         j                   |<   t        |      |j                   fd       |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.
        Nr   zunambiguous codons must coderd   c                 8    t        j                  |          | fS N)lenr   )r4   r   s    r   <lambda>z3AmbiguousForwardTable.__getitem__.<locals>.<lambda>  s    S)?)?)B%CQ$G r   )rD   )r   r   r2   r   rn   r   r   r   r   r}   re   sort)	r   r9   r4   ri   ambiguous_possibler:   termnr   s	   `        r   r   z!AmbiguousForwardTable.__getitem__  s%   		E"A $$&u--H}uo%H  			""5)A!"DKKH 		
		*-t))4+D+DH  	,!)DKK5/t+ 	*!1DKK"5))	* 8}q @"@@  x=A!)!DKKA;   	OEu- O+=+A+A$+JQ+N"4(O	O M,224 	'JE3ax&	'
 x=A!1DKK"5)) 	GHQKEs.   : 	AA
A* *	A65A6:!B AC+r   )r   r   r	   r
   r   r   r   r   r   r   r   rW   rW   u  s    J&	Mr   rW   c                    | j                  dd      j                  dd      j                  d      D cg c]  }|j                          }}t        |||gz   |||      }t	        |t
        j                  t
        j                  t
        j                  t
        j                        }	i }
i }|j                         D ]&  \  }}|||<   |j                  dd      }|||<   ||
|<   ( g }g }|D ]K  }|j                  |       d|v r#|j                  dd      }|j                  |       |j                  |       M g }g }|D ]K  }|j                  |       d|v r#|j                  dd      }|j                  |       |j                  |       M t        |||gz   |||      }t        t
        j                  j                               }d|d<   t	        |d|t
        j                  t
        j                        }t        |||gz   |
||      }t	        |t
        j                   t
        j                  t
        j                  t
        j                        }|dk(  r|a|a|t&        |<   |t(        |<   |t*        |<   |	t,        |<   |t.        |<   |t0        |<   ||j                  |       |D ]8  } |t2        | <   |t4        | <   |t6        | <   |	t8        | <   |t:        | <   |t<        | <   : yc c}w )z_Turn codon table data into objects (PRIVATE).

    The data is stored in the dictionaries.
    z and z; r   r   UNrd   )replacesplitstriprN   rU   r   ambiguous_dna_lettersambiguous_dna_valuesextended_protein_lettersextended_protein_valuesr}   re   rG   r<   ambiguous_rna_valuesrR   ambiguous_rna_lettersstandard_dna_tablestandard_rna_tableunambiguous_dna_by_idunambiguous_rna_by_idgeneric_by_idambiguous_dna_by_idambiguous_rna_by_idambiguous_generic_by_idunambiguous_dna_by_nameunambiguous_rna_by_namegeneric_by_nameambiguous_dna_by_nameambiguous_rna_by_nameambiguous_generic_by_name)ra   alt_namer/   rB   r   r   r4   r0   dna	ambig_dna	rna_tablegeneric_tabler9   r   rna_start_codonsgeneric_start_codonsrna_stop_codonsgeneric_stop_codonsgeneric_merged_valuesambig_genericrna	ambig_rnas                          r   register_ncbi_tabler     s     <<6>>tTJPPQUV	E  B
 2E<
UC#''&&**))I IMkkm 
s"ec3'"e	%	
  '##E* %<MM#s+E ''.&' O &""5)%<MM#s+E&&u-u%& 
EXJ/CEXG
 )88>>@ANN3'**))M 
EXJ	+;_C $''&&**))I 
Qw   #" #"M"''"/BX 8(+%(+% '&/d#&/d#*7!$'8es   K StandardSGC0rd   TTTFTTCTTALTTGTCTSTCCTCATCGTATYTACTGTCTGCTGGWCTTCTCCTACTGCCTPCCCCCACCGCATHCACCAAQCAGCGTRCGCCGACGGATTIATCATAATGMACTr   ACCACAACGAATNAACAAAKAAGAGTAGCAGAAGGGTTVGTCGTAGTGGCTAGCCDEG)
GCAGCGGATGACGAAGAGGGTGGCGGAGGG)r   r   r   )r   r   r   )ra   r   r/   rB   r   r   zVertebrate MitochondrialSGC1r|   r  )	r  r  r  r  r  r  r  r  r  )r   r   r  r  )r   r   r   r   r  zYeast MitochondrialSGC2   )r  r  r  r  r  r  r  r  r  r  r  )r   r   r  z`Mold Mitochondrial; Protozoan Mitochondrial; Coelenterate Mitochondrial; Mycoplasma; SpiroplasmaSGC3   )r   r   r   r   r   r   r   r  zInvertebrate MitochondrialSGC4   )r   r   r   r   r   r  z8Ciliate Nuclear; Dasycladacean Nuclear; Hexamita NuclearSGC5   )r  r  r  r  r  r  r  r  r  r  r  r  z0Echinoderm Mitochondrial; Flatworm MitochondrialSGC8	   zEuplotid NuclearSGC9
   z%Bacterial, Archaeal and Plant Plastid   )r   r   r   r   r   r   r  zAlternative Yeast Nuclear   zAscidian Mitochondrial   )r   r   r   r  z"Alternative Flatworm Mitochondrial   zBlepharisma Macronuclear   zChlorophycean Mitochondrial   zTrematode Mitochondrial   z"Scenedesmus obliquus Mitochondrial   )r   r   r   zThraustochytrium Mitochondrial   )r   r   r   r   )r   r   r  zPterobranchia Mitochondrial   )r   r   r   r  z*Candidate Division SR1 and Gracilibacteria   )r   r   r  zPachysolen tannophilus Nuclear   zKaryorelict Nuclear   )r  r  r  r  r  r  r  r  r  r  r  r  r  zCondylostoma Nuclear   zMesodinium Nuclear   zPeritrich Nuclear   zBlastocrithidia Nuclear   zBalanophoraceae Plastid    zCephalodiscidae Mitochondrial!   )!r
   typingr   Bio.Datar   r   r   r   r   r   r   r   r   r   r   r   r   r   r   	Exceptionr   r   rE   rG   rN   rR   rU   rn   rX   r   r   rW   r   r   r   r   <module>rA     sG                 9y 9b bJWZ W(< << <%0* %0P4>B eU^Y-K-KL Q   
 eU^Y-K-KL		Q    eU^Y-K-KL Q   
 eU^Y-K-KL Q   
 2I4R4RS X   0u up`8\ 	s3 %s,13s3 %s,13 	s 3 	s	 3	 -23	
 	s
 3
 !&s
 -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 (+33s33s3!$ &&/4 	#s3 %s,13s3 %s,13 	s 3 	s	 3	 !&s	 -23	
 	s
 3
 !&s
 -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 	s 3 !&s -23 	s 3 !&s 473s33s3!$ -4/4 	s3 %s,13s3 %s,13 	s 3 	s	 3	 !&s	 -23	
 	s
 3
 !&s
 -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s s33s33s3!$ &/4 
-s3 %s,13s3 %s,13 	s 3 	s	 3	 !&s	 -23	
 	s
 3
 !&s
 -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s s33s33s3!$ I16 	%s3 %s,13s3 %s,13 	s 3 	s	 3	 !&s	 -23	
 	s
 3
 !&s
 -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s s33s33s3!$ ;/4 	Cs3 %s,13s3 %s,13 	s 3 !&s -23 	s	 3	 -23	
 	s
 3
 !&s
 -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 3s33s33s3!$ /4 	;s3 %s,13s3 %s,13 	s 3 	s	 3	 !&s	 -23	
 	s
 3
 !&s
 -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s s33s33s3!$ /4 		s3 %s,13s3 %s,13 	s 3 	s	 3	 !&s	 -23	
 	s
 3
 !&s
 -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s s33s33s3!$ /4 	0	s3 %s,13s3 %s,13 	s 3 	s	 3	 -23	
 	s
 3
 !&s
 -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 (+33s33s3!$ &B/4 	$	s3 %s,13s3 %s,13 	s 3 	s	 3	 -23	
 	s
 3
 !&s
 -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 (+33s33s3!$ &/4 	!	s3 %s,13s3 %s,13 	s 3 	s	 3	 !&s	 -23	
 	s
 3
 !&s
 -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s s33s33s3!$ -/4 	-	s3 %s,13s3 %s,13 	s 3 !&s 	s	 3	 !&s	 -23	
 	s
 3
 !&s
 -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 3s33s33s3!$ /4 	#	s3 %s,13s3 %s,13 	s 3 -23 	s	 3	 -23	
 	s
 3
 !&s
 -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s s33s33s3!$ /4 	&	s3 %s,13s3 %s,13 	s 3 -23 	s	 3	 -23	
 	s
 3
 !&s
 -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s s33s33s3!$ /4 	"	s3 %s,13s3 %s,13 	s 3 	s	 3	 !&s	 -23	
 	s
 3
 !&s
 -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s s33s33s3!$ /4 	-	s3 %s,13s3,13 	s 3 -23 	s	 3	 -23	
 	s
 3
 !&s
 -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 (+33s33s3!$ &/4 	)	s3,13s3 %s,13 	s 3 	s	 3	 -23	
 	s
 3
 !&s
 -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s 473s33s3!$ -&/4 	&	s3 %s,13s3 %s,13 	s 3 	s	 3	 !&s	 -23	
 	s
 3
 !&s
 -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s s33s33s3!$ -/4 	5	s3 %s,13s3 %s,13 	s 3 	s	 3	 !&s	 -23	
 	s
 3
 !&s
 -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s s33s33s3!$ &/4 	)	s3 %s,13s3 %s,13 	s 3 	s	 3	 -23	
 	s
 3
 !&s
 -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 (+33s33s3!$ &/4 		s3 %s,13s3 %s,13 	s 3 !&s -23 	s	 3	 !&s	 -23	
 	s
 3
 !&s
 -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s 473s33s33s3!$ /4 		s3 %s,13s3 %s,13 	s 3 !&s -23 	s	 3	 !&s	 -23	
 	s
 3
 !&s
 -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s 473s33s33s3!$ &/4 		s3 %s,13s3 %s,13 	s 3 !&s -23 	s	 3	 -23	
 	s
 3
 !&s
 -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 3s33s33s3!$ /4 		s3 %s,13s3 %s,13 	s 3 !&s -23 	s	 3	 -23	
 	s
 3
 !&s
 -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 3s33s33s3!$ /4 	"	s3 %s,13s3 %s,13 	s 3 !&s -23 	s	 3	 !&s	 -23	
 	s
 3
 !&s
 -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s 473s33s33s3!$ /4 	"	s3 %s,13s3 %s,13 	s 3 -23 	s	 3	 -23	
 	s
 3
 !&s
 -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s s33s33s3!$ B/4 	(	s3 %s,13s3 %s,13 	s 3 !&s 	s	 3	 !&s	 -23	
 	s
 3
 !&s
 -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 	s 3 !&s -23 3s33s33s3!$ -/r   