ó
LAêIc           @   se  d  Z  d Z d d l Z d d l Z d d l Z y
 e Z Wn! e k
 r] d d l m Z n Xd d l	 Z	 d d l	 m
 Z
 d d l m Z m Z d d l m Z d „  Z e e ƒ Z e e ƒ Z d	 e f d
 „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d „  Z d e d d „ Z d d e d „ Z d „  Z d „  Z e d k rae ƒ  n  d S(   s  Provides objects to represent biological sequences with alphabets.

See also U{http://biopython.org/wiki/Seq} and the chapter in our tutorial:
 - U{http://biopython.org/DIST/docs/tutorial/Tutorial.html}
 - U{http://biopython.org/DIST/docs/tutorial/Tutorial.pdf}
s
   epytext eniÿÿÿÿN(   t   Set(   t   IUPAC(   t   ambiguous_dna_complementt   ambiguous_rna_complement(   t
   CodonTablec         C   sZ   d j  |  j ƒ  ƒ } d j  |  j ƒ  ƒ } | | j ƒ  } | | j ƒ  } t j | | ƒ S(   s¶  Makes a python string translation table (PRIVATE).

    Arguments:
     - complement_mapping - a dictionary such as ambiguous_dna_complement
       and ambiguous_rna_complement from Data.IUPACData.

    Returns a translation table (a string of length 256) for use with the
    python string's translate method to use in a (reverse) complement.
    
    Compatible with lower case and upper case sequences.

    For internal use only.
    t    (   t   joint   keyst   valuest   lowert   stringt	   maketrans(   t   complement_mappingt   beforet   after(    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyt
   _maketrans   s
    t   Seqc           B   sg  e  Z d  Z e j d „ Z d „  Z e d d „  d e d d ƒ Z d „  Z	 d	 „  Z
 d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d e j d „ Z d e j d „ Z d e j d „ Z d e j d „ Z d e j d „ Z d$ d d „ Z d$ d d „ Z d$ d „ Z d$ d „ Z d$ d „ Z d „  Z d „  Z  d „  Z! d  „  Z" d! d" e# d# „ Z$ RS(%   sy  A read-only sequence object (essentially a string with an alphabet).

    Like normal python strings, our basic sequence object is immutable.
    This prevents you from doing my_seq[5] = "A" for example, but does allow
    Seq objects to be used as dictionary keys.

    The Seq object provides a number of string like methods (such as count,
    find, split and strip), which are alphabet aware where appropriate.

    The Seq object also provides some biological methods, such as complement,
    reverse_complement, transcribe, back_transcribe and translate (which are
    not applicable to sequences with a protein alphabet).
    c         C   sL   t  | ƒ t  d ƒ k s6 t  | ƒ t  d ƒ k s6 t ‚ | |  _ | |  _ d S(   s'  Create a Seq object.

        Arguments:
         - seq      - Sequence, required (string)
         - alphabet - Optional argument, an Alphabet object from Bio.Alphabet
        
        You will typically use Bio.SeqIO to read in sequences from files as
        SeqRecord objects, whose sequence will be exposed as a Seq object via
        the seq property.

        However, will often want to create your own Seq objects directly:

        >>> from Bio.Seq import Seq
        >>> from Bio.Alphabet import IUPAC
        >>> my_seq = Seq("MKQHKAMIVALIVICITAVVAALVTRKDLCEVHIRTGQTEVAVF",
        ...              IUPAC.protein)
        >>> my_seq
        Seq('MKQHKAMIVALIVICITAVVAALVTRKDLCEVHIRTGQTEVAVF', IUPACProtein())
        >>> print my_seq
        MKQHKAMIVALIVICITAVVAALVTRKDLCEVHIRTGQTEVAVF
        R   u    N(   t   typet   AssertionErrort   _datat   alphabet(   t   selft   dataR   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyt   __init__D   s    	c         C   s)   d d  l  } | j d t ƒ | |  _ d  S(   Niÿÿÿÿs8   Writing to the Seq object's .data propery is deprecated.(   t   warningst   warnt   DeprecationWarningR   (   R   t   valueR   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyt	   _set_dataa   s    	t   fgetc         C   s
   t  |  ƒ S(   N(   t   str(   R   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyt   <lambda>h   s    t   fsett   docs!   Sequence as a string (DEPRECATED)c         C   sv   t  |  ƒ d k rI d |  j j t |  ƒ d  t |  ƒ d t |  j ƒ f Sd |  j j t |  j ƒ t |  j ƒ f Sd S(   sC   Returns a (truncated) representation of the sequence for debugging.i<   s   %s('%s...%s', %s)i6   iýÿÿÿs
   %s(%s, %s)N(   t   lent	   __class__t   __name__R   t   reprR   R   (   R   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyt   __repr__l   s    c         C   s   |  j  S(   sU  Returns the full sequence as a python string.

        Note that Biopython 1.44 and earlier would give a truncated
        version of repr(my_seq) for str(my_seq).  If you are writing code
        which need to be backwards compatible with old Biopython, you
        should continue to use my_seq.tostring() rather than str(my_seq).
        (   R   (   R   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyt   __str__y   s    c         C   s   t  |  j ƒ S(   N(   R"   R   (   R   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyt   __len__–   s    c         C   s5   t  | t ƒ r |  j | St |  j | |  j ƒ Sd  S(   N(   t
   isinstancet   intR   R   R   (   R   t   index(    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyt   __getitem__˜   s    c         C   sÆ   t  | d ƒ r t j |  j | j g ƒ sU t d t |  j ƒ t | j ƒ f ƒ ‚ n  t j |  j | j g ƒ } |  j t |  ƒ t | ƒ | ƒ St	 | t
 ƒ r¼ |  j t |  ƒ | |  j ƒ St ‚ d S(   s0   Add another sequence or string to this sequence.R   s    Incompatable alphabets %s and %sN(   t   hasattrt   Alphabett   _check_type_compatibleR   t	   TypeErrorR%   t   _consensus_alphabetR#   R   R)   t
   basestring(   R   t   othert   a(    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyt   __add__£   s    % c         C   sÆ   t  | d ƒ r t j |  j | j g ƒ sU t d t |  j ƒ t | j ƒ f ƒ ‚ n  t j |  j | j g ƒ } |  j t | ƒ t |  ƒ | ƒ St	 | t
 ƒ r¼ |  j | t |  ƒ |  j ƒ St ‚ d  S(   NR   s    Incompatable alphabets %s and %s(   R-   R.   R/   R   R0   R%   R1   R#   R   R)   R2   (   R   R3   R4   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyt   __radd__´   s    % c         C   s
   t  |  ƒ S(   s¨   Returns the full sequence as a python string.

        Although not formally deprecated, you are now encouraged to use
        str(my_seq) instead of my_seq.tostring().(   R   (   R   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyt   tostringÄ   s    c         C   s   t  t |  ƒ |  j ƒ S(   s»  Returns the full sequence as a MutableSeq object.

        >>> from Bio.Seq import Seq
        >>> from Bio.Alphabet import IUPAC
        >>> my_seq = Seq("MKQHKAMIVALIVICITAVVAAL",
        ...              IUPAC.protein)
        >>> my_seq
        Seq('MKQHKAMIVALIVICITAVVAAL', IUPACProtein())
        >>> my_seq.tomutable()
        MutableSeq('MKQHKAMIVALIVICITAVVAAL', IUPACProtein())

        Note that the alphabet is preserved.
        (   t
   MutableSeqR   R   (   R   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyt	   tomutableË   s    c         C   sl   y | j  } Wn t k
 r! | SXt j |  j  | g ƒ sb t d t |  j  ƒ t | ƒ f ƒ ‚ n  t | ƒ S(   s  string/Seq/MutableSeq to string, checking alphabet (PRIVATE).

        For a string argument, returns the string.

        For a Seq or MutableSeq, it checks the alphabet is compatible
        (raising an exception if it isn't), and then returns a string.
        s    Incompatable alphabets %s and %s(   R   t   AttributeErrorR.   R/   R0   R%   R   (   R   t   other_sequencet   other_alpha(    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyt   _get_seq_str_and_check_alphabetÛ   s    "i    c         C   s(   |  j  | ƒ } t |  ƒ j | | | ƒ S(   s¶  Non-overlapping count method, like that of a python string.

        This behaves like the python string method of the same name,
        which does a non-overlapping count!

        Returns an integer, the number of occurrences of substring
        argument sub in the (sub)sequence given by [start:end].
        Optional arguments start and end are interpreted as in slice
        notation.
    
        Arguments:
         - sub - a string or another Seq object to look for
         - start - optional integer, slice start
         - end - optional integer, slice end

        e.g.

        >>> from Bio.Seq import Seq
        >>> my_seq = Seq("AAAATGA")
        >>> print my_seq.count("A")
        5
        >>> print my_seq.count("ATG")
        1
        >>> print my_seq.count(Seq("AT"))
        1
        >>> print my_seq.count("AT", 2, -1)
        1

        HOWEVER, please note because python strings and Seq objects (and
        MutableSeq objects) do a non-overlapping search, this may not give
        the answer you expect:

        >>> "AAAA".count("AA")
        2
        >>> print Seq("AAAA").count("AA")
        2

        A non-overlapping search would give the answer as three!
        (   R=   R   t   count(   R   t   subt   startt   endt   sub_str(    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyR>   ð   s    )c         C   s(   |  j  | ƒ } t |  ƒ j | | | ƒ S(   sÏ  Find method, like that of a python string.

        This behaves like the python string method of the same name.

        Returns an integer, the index of the first occurrence of substring
        argument sub in the (sub)sequence given by [start:end].

        Arguments:
         - sub - a string or another Seq object to look for
         - start - optional integer, slice start
         - end - optional integer, slice end

        Returns -1 if the subsequence is NOT found.

        e.g. Locating the first typical start codon, AUG, in an RNA sequence:

        >>> from Bio.Seq import Seq
        >>> my_rna = Seq("GUCAUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAGUUG")
        >>> my_rna.find("AUG")
        3
        (   R=   R   t   find(   R   R?   R@   RA   RB   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyRC     s    c         C   s(   |  j  | ƒ } t |  ƒ j | | | ƒ S(   sç  Find from right method, like that of a python string.

        This behaves like the python string method of the same name.

        Returns an integer, the index of the last (right most) occurrence of
        substring argument sub in the (sub)sequence given by [start:end].

        Arguments:
         - sub - a string or another Seq object to look for
         - start - optional integer, slice start
         - end - optional integer, slice end

        Returns -1 if the subsequence is NOT found.

        e.g. Locating the last typical start codon, AUG, in an RNA sequence:

        >>> from Bio.Seq import Seq
        >>> my_rna = Seq("GUCAUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAGUUG")
        >>> my_rna.rfind("AUG")
        15
        (   R=   R   t   rfind(   R   R?   R@   RA   RB   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyRD   6  s    c         C   s‘   t  | t ƒ re g  | D] } |  j | ƒ ^ q } x- | D]% } t |  ƒ j | | | ƒ r8 t Sq8 Wt S|  j | ƒ } t |  ƒ j | | | ƒ Sd S(   s)  Does the Seq start with the given prefix?  Returns True/False.

        This behaves like the python string method of the same name.

        Return True if the sequence starts with the specified prefix
        (a string or another Seq object), False otherwise.
        With optional start, test sequence beginning at that position.
        With optional end, stop comparing sequence at that position.
        prefix can also be a tuple of strings to try.  e.g.
        
        >>> from Bio.Seq import Seq
        >>> my_rna = Seq("GUCAUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAGUUG")
        >>> my_rna.startswith("GUC")
        True
        >>> my_rna.startswith("AUG")
        False
        >>> my_rna.startswith("AUG", 3)
        True
        >>> my_rna.startswith(("UCC","UCA","UCG"),1)
        True
        N(   R)   t   tupleR=   R   t
   startswitht   Truet   False(   R   t   prefixR@   RA   t   pt   prefix_stringst
   prefix_str(    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyRF   P  s    c         C   s‘   t  | t ƒ re g  | D] } |  j | ƒ ^ q } x- | D]% } t |  ƒ j | | | ƒ r8 t Sq8 Wt S|  j | ƒ } t |  ƒ j | | | ƒ Sd S(   s  Does the Seq end with the given suffix?  Returns True/False.

        This behaves like the python string method of the same name.

        Return True if the sequence ends with the specified suffix
        (a string or another Seq object), False otherwise.
        With optional start, test sequence beginning at that position.
        With optional end, stop comparing sequence at that position.
        suffix can also be a tuple of strings to try.  e.g.

        >>> from Bio.Seq import Seq
        >>> my_rna = Seq("GUCAUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAGUUG")
        >>> my_rna.endswith("UUG")
        True
        >>> my_rna.endswith("AUG")
        False
        >>> my_rna.endswith("AUG", 0, 18)
        True
        >>> my_rna.endswith(("UCC","UCA","UUG"))
        True
        N(   R)   RE   R=   R   t   endswithRG   RH   (   R   t   suffixR@   RA   RJ   t   suffix_stringst
   suffix_str(    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyRM   u  s    iÿÿÿÿc         C   sD   |  j  | ƒ } g  t |  ƒ j | | ƒ D] } t | |  j ƒ ^ q( S(   sP  Split method, like that of a python string.

        This behaves like the python string method of the same name.

        Return a list of the 'words' in the string (as Seq objects),
        using sep as the delimiter string.  If maxsplit is given, at
        most maxsplit splits are done.  If maxsplit is ommited, all
        splits are made.

        Following the python string method, sep will by default be any
        white space (tabs, spaces, newlines) but this is unlikely to
        apply to biological sequences.
        
        e.g.

        >>> from Bio.Seq import Seq
        >>> my_rna = Seq("GUCAUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAGUUG")
        >>> my_aa = my_rna.translate()
        >>> my_aa
        Seq('VMAIVMGR*KGAR*L', HasStopCodon(ExtendedIUPACProtein(), '*'))
        >>> my_aa.split("*")
        [Seq('VMAIVMGR', HasStopCodon(ExtendedIUPACProtein(), '*')), Seq('KGAR', HasStopCodon(ExtendedIUPACProtein(), '*')), Seq('L', HasStopCodon(ExtendedIUPACProtein(), '*'))]
        >>> my_aa.split("*",1)
        [Seq('VMAIVMGR', HasStopCodon(ExtendedIUPACProtein(), '*')), Seq('KGAR*L', HasStopCodon(ExtendedIUPACProtein(), '*'))]

        See also the rsplit method:

        >>> my_aa.rsplit("*",1)
        [Seq('VMAIVMGR*KGAR', HasStopCodon(ExtendedIUPACProtein(), '*')), Seq('L', HasStopCodon(ExtendedIUPACProtein(), '*'))]
        (   R=   R   t   splitR   R   (   R   t   sept   maxsplitt   sep_strt   part(    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyRQ   ›  s     c         C   sÉ   |  j  | ƒ } y9 g  t |  ƒ j | | ƒ D] } t | |  j ƒ ^ q+ SWnz t k
 rÄ g  t |  ƒ d d d … j | d d d … | ƒ D]% } t | d d d … |  j ƒ ^ q‹ } | j ƒ  | SXd S(   sˆ  Right split method, like that of a python string.

        This behaves like the python string method of the same name.

        Return a list of the 'words' in the string (as Seq objects),
        using sep as the delimiter string.  If maxsplit is given, at
        most maxsplit splits are done COUNTING FROM THE RIGHT.
        If maxsplit is ommited, all splits are made.

        Following the python string method, sep will by default be any
        white space (tabs, spaces, newlines) but this is unlikely to
        apply to biological sequences.
        
        e.g. print my_seq.rsplit("*",1)

        See also the split method.
        Niÿÿÿÿ(   R=   R   t   rsplitR   R   R:   RQ   t   reverse(   R   RR   RS   RT   RU   t   wordt   words(    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyRV   Á  s    6[
c         C   s.   |  j  | ƒ } t t |  ƒ j | ƒ |  j ƒ S(   s´  Returns a new Seq object with leading and trailing ends stripped.

        This behaves like the python string method of the same name.

        Optional argument chars defines which characters to remove.  If
        ommitted or None (default) then as for the python string method,
        this defaults to removing any white space.
        
        e.g. print my_seq.strip("-")

        See also the lstrip and rstrip methods.
        (   R=   R   R   t   stripR   (   R   t   charst	   strip_str(    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyRZ   á  s    c         C   s.   |  j  | ƒ } t t |  ƒ j | ƒ |  j ƒ S(   s­  Returns a new Seq object with leading (left) end stripped.

        This behaves like the python string method of the same name.

        Optional argument chars defines which characters to remove.  If
        ommitted or None (default) then as for the python string method,
        this defaults to removing any white space.
        
        e.g. print my_seq.lstrip("-")

        See also the strip and rstrip methods.
        (   R=   R   R   t   lstripR   (   R   R[   R\   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyR]   ò  s    c         C   s.   |  j  | ƒ } t t |  ƒ j | ƒ |  j ƒ S(   s%  Returns a new Seq object with trailing (right) end stripped.

        This behaves like the python string method of the same name.

        Optional argument chars defines which characters to remove.  If
        ommitted or None (default) then as for the python string method,
        this defaults to removing any white space.
        
        e.g. Removing a nucleotide sequence's polyadenylation (poly-A tail):

        >>> from Bio.Alphabet import IUPAC
        >>> from Bio.Seq import Seq
        >>> my_seq = Seq("CGGTACGCTTATGTCACGTAGAAAAAA", IUPAC.unambiguous_dna)
        >>> my_seq
        Seq('CGGTACGCTTATGTCACGTAGAAAAAA', IUPACUnambiguousDNA())
        >>> my_seq.rstrip("A")
        Seq('CGGTACGCTTATGTCACGTAG', IUPACUnambiguousDNA())

        See also the strip and lstrip methods.
        (   R=   R   R   t   rstripR   (   R   R[   R\   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyR^     s    c         C   s   t  j |  j ƒ } t | t  j ƒ r3 t d ƒ ‚ n  t | t  j ƒ rN t } n“ t | t  j ƒ ri t	 } nx d |  j
 k s‡ d |  j
 k r´ d |  j
 k s¥ d |  j
 k r´ t d ƒ ‚ n- d |  j
 k sÒ d |  j
 k rÛ t	 } n t } t t |  ƒ j | ƒ |  j ƒ S(   s=  Returns the complement sequence. New Seq object.

        >>> from Bio.Seq import Seq
        >>> from Bio.Alphabet import IUPAC
        >>> my_dna = Seq("CCCCCGATAG", IUPAC.unambiguous_dna)
        >>> my_dna
        Seq('CCCCCGATAG', IUPACUnambiguousDNA())
        >>> my_dna.complement()
        Seq('GGGGGCTATC', IUPACUnambiguousDNA())

        You can of course used mixed case sequences,

        >>> from Bio.Seq import Seq
        >>> from Bio.Alphabet import generic_dna
        >>> my_dna = Seq("CCCCCgatA-GD", generic_dna)
        >>> my_dna
        Seq('CCCCCgatA-GD', DNAAlphabet())
        >>> my_dna.complement()
        Seq('GGGGGctaT-CH', DNAAlphabet())

        Note in the above example, ambiguous character D denotes
        G, A or T so its complement is H (for C, T or A).
        
        Trying to complement a protein sequence raises an exception.

        >>> my_protein = Seq("MAIVMGR", IUPAC.protein)
        >>> my_protein.complement()
        Traceback (most recent call last):
           ...
        ValueError: Proteins do not have complements!
        s!   Proteins do not have complements!t   Ut   ut   Tt   ts   Mixed RNA/DNA found(   R.   t   _get_base_alphabetR   R)   t   ProteinAlphabett
   ValueErrort   DNAAlphabett   _dna_complement_tablet   RNAAlphabett   _rna_complement_tableR   R   R   t	   translate(   R   t   baset   ttable(    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyt
   complement  s     			c         C   s   |  j  ƒ  d d d … S(   sA  Returns the reverse complement sequence. New Seq object.

        >>> from Bio.Seq import Seq
        >>> from Bio.Alphabet import IUPAC
        >>> my_dna = Seq("CCCCCGATAGNR", IUPAC.ambiguous_dna)
        >>> my_dna
        Seq('CCCCCGATAGNR', IUPACAmbiguousDNA())
        >>> my_dna.reverse_complement()
        Seq('YNCTATCGGGGG', IUPACAmbiguousDNA())

        Note in the above example, since R = G or A, its complement
        is Y (which denotes  C or T).

        You can of course used mixed case sequences,

        >>> from Bio.Seq import Seq
        >>> from Bio.Alphabet import generic_dna
        >>> my_dna = Seq("CCCCCgatA-G", generic_dna)
        >>> my_dna
        Seq('CCCCCgatA-G', DNAAlphabet())
        >>> my_dna.reverse_complement()
        Seq('C-TatcGGGGG', DNAAlphabet())

        Trying to complement a protein sequence raises an exception:

        >>> my_protein = Seq("MAIVMGR", IUPAC.protein)
        >>> my_protein.reverse_complement()
        Traceback (most recent call last):
           ...
        ValueError: Proteins do not have complements!
        Niÿÿÿÿ(   Rm   (   R   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyt   reverse_complementO  s    !c         C   sÄ   t  j |  j ƒ } t | t  j ƒ r3 t d ƒ ‚ n  t | t  j ƒ rT t d ƒ ‚ n  |  j t j k rr t j	 } n' |  j t j
 k r t j } n	 t  j } t t |  ƒ j d d ƒ j d d ƒ | ƒ S(   s   Returns the RNA sequence from a DNA sequence. New Seq object.

        >>> from Bio.Seq import Seq
        >>> from Bio.Alphabet import IUPAC
        >>> coding_dna = Seq("ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG",
        ...                  IUPAC.unambiguous_dna)
        >>> coding_dna
        Seq('ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG', IUPACUnambiguousDNA())
        >>> coding_dna.transcribe()
        Seq('AUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAG', IUPACUnambiguousRNA())

        Trying to transcribe a protein or RNA sequence raises an exception:

        >>> my_protein = Seq("MAIVMGR", IUPAC.protein)
        >>> my_protein.transcribe()
        Traceback (most recent call last):
           ...
        ValueError: Proteins cannot be transcribed!
        s   Proteins cannot be transcribed!s   RNA cannot be transcribed!Ra   R_   Rb   R`   (   R.   Rc   R   R)   Rd   Re   Rh   R   t   unambiguous_dnat   unambiguous_rnat   ambiguous_dnat   ambiguous_rnat   generic_rnaR   R   t   replace(   R   Rk   R   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyt
   transcriber  s    	c         C   sÄ   t  j |  j ƒ } t | t  j ƒ r3 t d ƒ ‚ n  t | t  j ƒ rT t d ƒ ‚ n  |  j t j k rr t j	 } n' |  j t j
 k r t j } n	 t  j } t t |  ƒ j d d ƒ j d d ƒ | ƒ S(   s)  Returns the DNA sequence from an RNA sequence. New Seq object.

        >>> from Bio.Seq import Seq
        >>> from Bio.Alphabet import IUPAC
        >>> messenger_rna = Seq("AUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAG",
        ...                     IUPAC.unambiguous_rna)
        >>> messenger_rna
        Seq('AUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAG', IUPACUnambiguousRNA())
        >>> messenger_rna.back_transcribe()
        Seq('ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG', IUPACUnambiguousDNA())

        Trying to back-transcribe a protein or DNA sequence raises an
        exception:

        >>> my_protein = Seq("MAIVMGR", IUPAC.protein)
        >>> my_protein.back_transcribe()
        Traceback (most recent call last):
           ...
        ValueError: Proteins cannot be back transcribed!
        s$   Proteins cannot be back transcribed!s   DNA cannot be back transcribed!R_   Ra   R`   Rb   (   R.   Rc   R   R)   Rd   Re   Rf   R   Rp   Ro   Rr   Rq   t   generic_dnaR   R   Rt   (   R   Rk   R   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyt   back_transcribe”  s    	t   Standardt   *c         C   s  y t  | ƒ } Wn t k
 r) d } n Xt | t ƒ rf t | ƒ d k rf t d d d d ƒ ‚ n  t t j |  j ƒ t j	 ƒ r“ t d ƒ ‚ n  |  j t
 j k rÑ | d k rÁ t j | } q8t j | } ng |  j t
 j k r| d k rÿ t j | } q8t j | } n) | d k r+t j | } n t j | } t t |  ƒ | | | ƒ } | | k rzt j | j d | ƒ} n	 | j } t | | ƒ S(	   sª	  Turns a nucleotide sequence into a protein sequence. New Seq object.

        This method will translate DNA or RNA sequences, and those with a
        nucleotide or generic alphabet.  Trying to translate a protein
        sequence raises an exception.

        Arguments:
         - table - Which codon table to use?  This can be either a name
                   (string) or an NCBI identifier (integer).  This defaults
                   to the "Standard" table.
         - stop_symbol - Single character string, what to use for terminators.
                         This defaults to the asterisk, "*".
         - to_stop - Boolean, defaults to False meaning do a full translation
                     continuing on past any stop codons (translated as the
                     specified stop_symbol).  If True, translation is
                     terminated at the first in frame stop codon (and the
                     stop_symbol is not appended to the returned protein
                     sequence).

        e.g. Using the standard table:

        >>> coding_dna = Seq("GTGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG")
        >>> coding_dna.translate()
        Seq('VAIVMGR*KGAR*', HasStopCodon(ExtendedIUPACProtein(), '*'))
        >>> coding_dna.translate(stop_symbol="@")
        Seq('VAIVMGR@KGAR@', HasStopCodon(ExtendedIUPACProtein(), '@'))
        >>> coding_dna.translate(to_stop=True)
        Seq('VAIVMGR', ExtendedIUPACProtein())

        Now using NCBI table 2, where TGA is not a stop codon:

        >>> coding_dna.translate(table=2)
        Seq('VAIVMGRWKGAR*', HasStopCodon(ExtendedIUPACProtein(), '*'))
        >>> coding_dna.translate(table=2, to_stop=True)
        Seq('VAIVMGRWKGAR', ExtendedIUPACProtein())

        If the sequence has no in-frame stop codon, then the to_stop argument
        has no effect:

        >>> coding_dna2 = Seq("TTGGCCATTGTAATGGGCCGC")
        >>> coding_dna2.translate()
        Seq('LAIVMGR', ExtendedIUPACProtein())
        >>> coding_dna2.translate(to_stop=True)
        Seq('LAIVMGR', ExtendedIUPACProtein())

        NOTE - Ambiguous codons like "TAN" or "NNN" could be an amino acid
        or a stop codon.  These are translated as "X".  Any invalid codon
        (e.g. "TA?" or "T-A") will throw a TranslationError.

        NOTE - Does NOT support gapped sequences.

        NOTE - This does NOT behave like the python string's translate
        method.  For that use str(my_seq).translate(...) instead.
        i   s.   The Seq object translate method DOES NOT take s*   a 256 character string mapping table like s-   the python string object's translate method. s'   Use str(my_seq).translate(...) instead.s   Proteins cannot be translated!t   stop_symbolN(   R*   Re   t   NoneR)   R   R"   R.   Rc   R   Rd   R   Ro   R   t   unambiguous_dna_by_namet   unambiguous_dna_by_idRp   t   unambiguous_rna_by_namet   unambiguous_rna_by_idt   ambiguous_generic_by_namet   ambiguous_generic_by_idt   _translate_strt   HasStopCodont   protein_alphabetR   (   R   t   tableRz   t   to_stopt   table_idt   codon_tablet   proteinR   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyRj   ·  s6    7
!
	N(%   R$   t
   __module__t   __doc__R.   t   generic_alphabetR   R   t   propertyR   R&   R'   R(   R,   R5   R6   R7   R9   R=   t   syst   maxintR>   RC   RD   RF   RM   R{   RQ   RV   RZ   R]   R^   Rm   Rn   Ru   Rw   RH   Rj   (    (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyR   6   s<   											,%&& 	3	#	"	#t
   UnknownSeqc           B   s•   e  Z d  Z e j d d „ Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d e j d	 „ Z d
 „  Z d „  Z d „  Z d „  Z d „  Z RS(   s£  A read-only sequence object of known length but unknown contents.

    If you have an unknown sequence, you can represent this with a normal
    Seq object, for example:

    >>> my_seq = Seq("N"*5)
    >>> my_seq
    Seq('NNNNN', Alphabet())
    >>> len(my_seq)
    5
    >>> print my_seq
    NNNNN

    However, this is rather wasteful of memory (especially for large
    sequences), which is where this class is most usefull:

    >>> unk_five = UnknownSeq(5)
    >>> unk_five
    UnknownSeq(5, alphabet = Alphabet(), character = '?')
    >>> len(unk_five)
    5
    >>> print(unk_five)
    ?????

    You can add unknown sequence together, provided their alphabets and
    characters are compatible, and get another memory saving UnknownSeq:

    >>> unk_four = UnknownSeq(4)
    >>> unk_four
    UnknownSeq(4, alphabet = Alphabet(), character = '?')
    >>> unk_four + unk_five
    UnknownSeq(9, alphabet = Alphabet(), character = '?')

    If the alphabet or characters don't match up, the addition gives an
    ordinary Seq object:
    
    >>> unk_nnnn = UnknownSeq(4, character = "N")
    >>> unk_nnnn
    UnknownSeq(4, alphabet = Alphabet(), character = 'N')
    >>> unk_nnnn + unk_four
    Seq('NNNN????', Alphabet())

    Combining with a real Seq gives a new Seq object:

    >>> known_seq = Seq("ACGT")
    >>> unk_four + known_seq
    Seq('????ACGT', Alphabet())
    >>> known_seq + unk_four
    Seq('ACGT????', Alphabet())
    c         C   sÁ   t  | ƒ |  _ |  j d k  r- t d ƒ ‚ n  | |  _ | ri t | ƒ d k r] t d ƒ ‚ n  | |  _ nT t j | ƒ } t | t j	 ƒ r– d |  _ n' t | t j
 ƒ r´ d |  _ n	 d |  _ d S(	   s®   Create a new UnknownSeq object.

        If character is ommited, it is determed from the alphabet, "N" for
        nucleotides, "X" for proteins, and "?" otherwise.
        i    s   Length must not be negative.i   s4   character argument should be a single letter string.t   Nt   Xt   ?N(   R*   t   _lengthRe   R   R"   t
   _characterR.   Rc   R)   t   NucleotideAlphabetRd   (   R   t   lengthR   t	   characterRk   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyR   S  s    	c         C   s   |  j  S(   s2   Returns the stated length of the unknown sequence.(   R”   (   R   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyR(   m  s    c         C   s   |  j  |  j S(   s@   Returns the unknown sequence as full string of the given length.(   R•   R”   (   R   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyR'   q  s    c         C   s&   d |  j  t |  j ƒ t |  j ƒ f S(   Ns-   UnknownSeq(%i, alphabet = %s, character = %s)(   R”   R%   R   R•   (   R   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyR&   u  s    c         C   sa   t  | t ƒ rG | j |  j k rG t t |  ƒ t | ƒ |  j |  j ƒ St t |  ƒ |  j ƒ | S(   N(   R)   R   R•   R"   R   R   R   (   R   R3   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyR5   y  s
    c         C   sa   t  | t ƒ rG | j |  j k rG t t |  ƒ t | ƒ |  j |  j ƒ S| t t |  ƒ |  j ƒ S(   N(   R)   R   R•   R"   R   R   R   (   R   R3   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyR6   ‚  s
    c         C   sH   t  | t ƒ r t |  ƒ | St t d |  j | ƒ |  j |  j ƒ Sd  S(   Nt   #(   R)   R*   R   R   R"   R”   R   R•   (   R   R+   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyR,   ‹  s    i    c         C   sæ   |  j  | ƒ } t | ƒ d k r{ t | ƒ |  j k rt | d k rX | |  j k rX |  j St |  ƒ j | | | ƒ Sqâ d Sng t | ƒ t |  j ƒ k rÞ | d k rÂ | |  j k rÂ |  j t | ƒ St |  ƒ j | | | ƒ Sn d Sd S(   sž  Non-overlapping count method, like that of a python string.

        This behaves like the python string (and Seq object) method of the
        same name, which does a non-overlapping count!

        Returns an integer, the number of occurrences of substring
        argument sub in the (sub)sequence given by [start:end].
        Optional arguments start and end are interpreted as in slice
        notation.
    
        Arguments:
         - sub - a string or another Seq object to look for
         - start - optional integer, slice start
         - end - optional integer, slice end

        >>> "NNNN".count("N")
        4
        >>> Seq("NNNN").count("N")
        4
        >>> UnknownSeq(4, character="N").count("N")
        4
        >>> UnknownSeq(4, character="N").count("A")
        0
        >>> UnknownSeq(4, character="N").count("AA")
        0

        HOWEVER, please note because that python strings and Seq objects (and
        MutableSeq objects) do a non-overlapping search, this may not give
        the answer you expect:

        >>> UnknownSeq(4, character="N").count("NN")
        2
        >>> UnknownSeq(4, character="N").count("NNN")
        1
        i   i    N(   R=   R"   R   R•   R”   R>   t   set(   R   R?   R@   RA   RB   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyR>   ”  s    $c         C   s1   t  t j |  j ƒ t j ƒ r- t d ƒ ‚ n  |  S(   ss  The complement of an unknown nucleotide equals itself.

        >>> my_nuc = UnknownSeq(8)
        >>> my_nuc
        UnknownSeq(8, alphabet = Alphabet(), character = '?')
        >>> print my_nuc
        ????????
        >>> my_nuc.complement()
        UnknownSeq(8, alphabet = Alphabet(), character = '?')
        >>> print my_nuc.complement()
        ????????
        s!   Proteins do not have complements!(   R)   R.   Rc   R   Rd   Re   (   R   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyRm   Ì  s    c         C   s1   t  t j |  j ƒ t j ƒ r- t d ƒ ‚ n  |  S(   s’  The reverse complement of an unknown nucleotide equals itself.

        >>> my_nuc = UnknownSeq(10)
        >>> my_nuc
        UnknownSeq(10, alphabet = Alphabet(), character = '?')
        >>> print my_nuc
        ??????????
        >>> my_nuc.reverse_complement()
        UnknownSeq(10, alphabet = Alphabet(), character = '?')
        >>> print my_nuc.reverse_complement()
        ??????????
        s!   Proteins do not have complements!(   R)   R.   Rc   R   Rd   Re   (   R   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyRn   Þ  s    c         C   s4   t  |  j |  j ƒ j ƒ  } t |  j | j |  j ƒ S(   sŸ  Returns unknown RNA sequence from an unknown DNA sequence.

        >>> my_dna = UnknownSeq(10, character="N")
        >>> my_dna
        UnknownSeq(10, alphabet = Alphabet(), character = 'N')
        >>> print my_dna
        NNNNNNNNNN
        >>> my_rna = my_dna.transcribe()
        >>> my_rna
        UnknownSeq(10, alphabet = RNAAlphabet(), character = 'N')
        >>> print my_rna
        NNNNNNNNNN
        (   R   R•   R   Ru   R   R”   (   R   t   s(    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyRu   ð  s    c         C   s4   t  |  j |  j ƒ j ƒ  } t |  j | j |  j ƒ S(   s¸  Returns unknown DNA sequence from an unknown RNA sequence.

        >>> my_rna = UnknownSeq(20, character="N")
        >>> my_rna
        UnknownSeq(20, alphabet = Alphabet(), character = 'N')
        >>> print my_rna
        NNNNNNNNNNNNNNNNNNNN
        >>> my_dna = my_rna.back_transcribe()
        >>> my_dna
        UnknownSeq(20, alphabet = DNAAlphabet(), character = 'N')
        >>> print my_dna
        NNNNNNNNNNNNNNNNNNNN
        (   R   R•   R   Rw   R   R”   (   R   R›   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyRw     s    c         K   sG   t  t j |  j ƒ t j ƒ r- t d ƒ ‚ n  t |  j d t j d ƒ S(   s‹  Translate an unknown nucleotide sequence into an unknown protein.

        e.g.

        >>> my_seq = UnknownSeq(11, character="N")
        >>> print my_seq
        NNNNNNNNNNN
        >>> my_protein = my_seq.translate()
        >>> my_protein
        UnknownSeq(3, alphabet = ProteinAlphabet(), character = 'X')
        >>> print my_protein
        XXX

        In comparison, using a normal Seq object:

        >>> my_seq = Seq("NNNNNNNNNNN")
        >>> print my_seq
        NNNNNNNNNNN
        >>> my_protein = my_seq.translate()
        >>> my_protein
        Seq('XXX', ExtendedIUPACProtein())
        >>> print my_protein
        XXX

        s   Proteins cannot be translated!i   R’   (	   R)   R.   Rc   R   Rd   Re   R   R”   t   generic_protein(   R   t   kwargs(    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyRj     s    N(   R$   RŠ   R‹   R.   RŒ   R{   R   R(   R'   R&   R5   R6   R,   RŽ   R   R>   Rm   Rn   Ru   Rw   Rj   (    (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyR      s   2									8				R8   c           B   sæ   e  Z d  Z e j d „ Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d d „ Z d „  Z d e j d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s]  An editable sequence object (with an alphabet).

    Unlike normal python strings and our basic sequence object (the Seq class)
    which are immuatable, the MutableSeq lets you edit the sequence in place.
    However, this means you cannot use a MutableSeq object as a dictionary key.

    >>> from Bio.Seq import MutableSeq
    >>> from Bio.Alphabet import generic_dna
    >>> my_seq = MutableSeq("ACTCGTCGTCG", generic_dna)
    >>> my_seq
    MutableSeq('ACTCGTCGTCG', DNAAlphabet())
    >>> my_seq[5]
    'T'
    >>> my_seq[5] = "A"
    >>> my_seq
    MutableSeq('ACTCGACGTCG', DNAAlphabet())
    >>> my_seq[5]
    'A'
    >>> my_seq[5:8] = "NNN"
    >>> my_seq
    MutableSeq('ACTCGNNNTCG', DNAAlphabet())
    >>> len(my_seq)
    11

    Note that the MutableSeq object does not support as many string-like
    or biological methods as the Seq object.
    c         C   sF   t  | ƒ t  d ƒ k r0 t j d | ƒ |  _ n	 | |  _ | |  _ d  S(   NR   t   c(   R   t   arrayR   R   (   R   R   R   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyR   P  s    	c         C   ss   t  |  ƒ d k rI d |  j j t |  d  ƒ t |  d ƒ t |  j ƒ f Sd |  j j t |  ƒ t |  j ƒ f Sd S(   sC   Returns a (truncated) representation of the sequence for debugging.i<   s   %s('%s...%s', %s)i6   iýÿÿÿs   %s('%s', %s)N(   R"   R#   R$   R   R%   R   (   R   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyR&   W  s    	c         C   s   d j  |  j ƒ S(   sV  Returns the full sequence as a python string.

        Note that Biopython 1.44 and earlier would give a truncated
        version of repr(my_seq) for str(my_seq).  If you are writing code
        which needs to be backwards compatible with old Biopython, you
        should continue to use my_seq.tostring() rather than str(my_seq).
        R   (   R   R   (   R   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyR'   e  s    	c         C   s¿   t  | d ƒ r“ t j |  j | j g ƒ sU t d t |  j ƒ t | j ƒ f ƒ ‚ n  t | t ƒ rw t |  j	 | j	 ƒ St t
 |  ƒ t
 | ƒ ƒ Sn( t | t ƒ rµ t t
 |  ƒ | ƒ St ‚ d S(   sm  Compare the sequence for to another sequence or a string.

        If compared to another sequence the alphabets must be compatible.
        Comparing DNA to RNA, or Nucleotide to Protein will raise an
        exception.

        Otherwise only the sequence itself is compared, not the precise
        alphabet.

        This method indirectly supports ==, < , etc.R   s    Incompatable alphabets %s and %sN(   R-   R.   R/   R   R0   R%   R)   R8   t   cmpR   R   R2   (   R   R3   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyt   __cmp__p  s    %c         C   s   t  |  j ƒ S(   N(   R"   R   (   R   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyR(     s    c         C   s5   t  | t ƒ r |  j | St |  j | |  j ƒ Sd  S(   N(   R)   R*   R   R8   R   (   R   R+   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyR,     s    c         C   sŒ   t  | t ƒ r | |  j | <ni t  | t ƒ rA | j |  j | <nG t  | t |  j ƒ ƒ ri | |  j | <n t j d t | ƒ ƒ |  j | <d  S(   NRž   (   R)   R*   R   R8   R   RŸ   R   (   R   R+   R   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyt   __setitem__š  s    c         C   s   |  j  | =d  S(   N(   R   (   R   R+   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyt   __delitem__ª  s    c         C   sø   t  | d ƒ r¼ t j |  j | j g ƒ sU t d t |  j ƒ t | j ƒ f ƒ ‚ n  t j |  j | j g ƒ } t | t ƒ r™ |  j	 |  j
 | j
 | ƒ S|  j	 t |  ƒ t | ƒ | ƒ Sn8 t | t ƒ rî |  j	 t |  ƒ t | ƒ |  j ƒ St ‚ d S(   sZ   Add another sequence or string to this sequence.

        Returns a new MutableSeq object.R   s    Incompatable alphabets %s and %sN(   R-   R.   R/   R   R0   R%   R1   R)   R8   R#   R   R   R2   (   R   R3   R4   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyR5   ²  s    %##c         C   sø   t  | d ƒ r¼ t j |  j | j g ƒ sU t d t |  j ƒ t | j ƒ f ƒ ‚ n  t j |  j | j g ƒ } t | t ƒ r™ |  j	 | j
 |  j
 | ƒ S|  j	 t | ƒ t |  ƒ | ƒ Sn8 t | t ƒ rî |  j	 t | ƒ t |  ƒ |  j ƒ St ‚ d  S(   NR   s    Incompatable alphabets %s and %s(   R-   R.   R/   R   R0   R%   R1   R)   R8   R#   R   R   R2   (   R   R3   R4   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyR6   Ê  s    %##c         C   s   |  j  j | ƒ d  S(   N(   R   t   append(   R   Rž   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyR¤   ß  s    c         C   s   |  j  j | | ƒ d  S(   N(   R   t   insert(   R   t   iRž   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyR¥   â  s    iÿÿÿÿc         C   s   |  j  | } |  j  | =| S(   N(   R   (   R   R¦   Rž   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyt   popå  s    
c         C   sQ   x> t  t |  j ƒ ƒ D]' } |  j | | k r |  j | =d  Sq Wt d ƒ ‚ d  S(   Ns#   MutableSeq.remove(x): x not in list(   t   rangeR"   R   Re   (   R   t   itemR¦   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyt   removeê  s
    
i    c         C   sµ   y | j  ƒ  } Wn t k
 r) | } n Xt | t ƒ sH t d ƒ ‚ n  t | ƒ d k r˜ d } x1 |  j | | !D] } | | k rq | d 7} qq qq W| S|  j  ƒ  j | | | ƒ Sd S(   sà  Non-overlapping count method, like that of a python string.

        This behaves like the python string method of the same name,
        which does a non-overlapping count!

        Returns an integer, the number of occurrences of substring
        argument sub in the (sub)sequence given by [start:end].
        Optional arguments start and end are interpreted as in slice
        notation.
    
        Arguments:
         - sub - a string or another Seq object to look for
         - start - optional integer, slice start
         - end - optional integer, slice end

        e.g.
        
        >>> from Bio.Seq import MutableSeq
        >>> my_mseq = MutableSeq("AAAATGA")
        >>> print my_mseq.count("A")
        5
        >>> print my_mseq.count("ATG")
        1
        >>> print my_mseq.count(Seq("AT"))
        1
        >>> print my_mseq.count("AT", 2, -1)
        1
        
        HOWEVER, please note because that python strings, Seq objects and
        MutableSeq objects do a non-overlapping search, this may not give
        the answer you expect:

        >>> "AAAA".count("AA")
        2
        >>> print MutableSeq("AAAA").count("AA")
        2

        A non-overlapping search would give the answer as three!
        s$   expected a string, Seq or MutableSeqi   i    N(   R7   R:   R)   R2   R0   R"   R   R>   (   R   R?   R@   RA   t   searchR>   Rž   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyR>   ñ  s    (
 c         C   sG   x4 t  t |  j ƒ ƒ D] } |  j | | k r | Sq Wt d ƒ ‚ d  S(   Ns"   MutableSeq.index(x): x not in list(   R¨   R"   R   Re   (   R   R©   R¦   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyR+   ,  s    c         C   s   |  j  j ƒ  d S(   sQ   Modify the mutable sequence to reverse itself.

        No return value.
        N(   R   RW   (   R   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyRW   2  s    c            sD  t  t j |  j ƒ t j ƒ r- t d ƒ ‚ n  |  j t j t j f k rQ t	 ‰  no |  j t j
 t j f k ru t ‰  nK d |  j k r¢ d |  j k r¢ t d ƒ ‚ n d |  j k rº t ‰  n t	 ‰  t g  ˆ  j ƒ  D]$ \ } } | j ƒ  | j ƒ  f ^ qÐ ƒ } ˆ  j | ƒ t ‡  f d †  |  j ƒ |  _ t j d |  j ƒ |  _ d S(   sŸ   Modify the mutable sequence to take on its complement.

        Trying to complement a protein sequence raises an exception.

        No return value.
        s!   Proteins do not have complements!R_   Ra   s   Mixed RNA/DNA foundc            s   ˆ  |  S(   N(    (   Rž   (   t   d(    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyR   P  s    Rž   N(   R)   R.   Rc   R   Rd   Re   R   Rq   Ro   R   Rr   Rp   R   R   t   dictt	   iteritemsR	   t   updatet   mapRŸ   (   R   t   xt   yRž   (    (   R¬   sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyRm   9  s     			=c         C   s   |  j  ƒ  |  j j ƒ  d S(   s¯   Modify the mutable sequence to take on its reverse complement.

        Trying to reverse complement a protein sequence raises an exception.

        No return value.
        N(   Rm   R   RW   (   R   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyRn   S  s    
c         C   s[   t  | t ƒ r6 xE | j D] } |  j j | ƒ q Wn! x | D] } |  j j | ƒ q= Wd  S(   N(   R)   R8   R   R¤   (   R   R3   Rž   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyt   extend`  s
    c         C   s   d j  |  j ƒ S(   s   Returns the full sequence as a python string.

        Although not formally deprecated, you are now encouraged to use
        str(my_seq) instead of my_seq.tostring().

        Because str(my_seq) will give you the full sequence as a python string,
        there is often no need to make an explicit conversion.  For example,
        
        print "ID={%s}, sequence={%s}" % (my_name, my_seq)

        On Biopython 1.44 or older you would have to have done this:

        print "ID={%s}, sequence={%s}" % (my_name, my_seq.tostring())
        R   (   R   R   (   R   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyR7   h  s    c         C   s   t  d j |  j ƒ |  j ƒ S(   sÐ  Returns the full sequence as a new immutable Seq object.

        >>> from Bio.Seq import Seq
        >>> from Bio.Alphabet import IUPAC
        >>> my_mseq = MutableSeq("MKQHKAMIVALIVICITAVVAAL",                                  IUPAC.protein)
        >>> my_mseq
        MutableSeq('MKQHKAMIVALIVICITAVVAAL', IUPACProtein())
        >>> my_mseq.toseq()
        Seq('MKQHKAMIVALIVICITAVVAAL', IUPACProtein())

        Note that the alphabet is preserved.
        R   (   R   R   R   R   (   R   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyt   toseqy  s    (   R$   RŠ   R‹   R.   RŒ   R   R&   R'   R¡   R(   R,   R¢   R£   R5   R6   R¤   R¥   R§   Rª   RŽ   R   R>   R+   RW   Rm   Rn   R³   R7   R´   (    (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyR8   4  s.   												;						c         C   sX   t  |  t ƒ r |  j ƒ  St  |  t ƒ r8 |  j ƒ  j ƒ  S|  j d d ƒ j d d ƒ Sd S(   s-  Transcribes a DNA sequence into RNA.

    If given a string, returns a new string object.

    Given a Seq or MutableSeq, returns a new Seq object with an RNA alphabet.

    Trying to transcribe a protein or RNA sequence raises an exception.

    e.g.
    
    >>> transcribe("ACTGN")
    'ACUGN'
    Ra   R_   Rb   R`   N(   R)   R   Ru   R8   R´   Rt   (   t   dna(    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyRu     s
    
c         C   sX   t  |  t ƒ r |  j ƒ  St  |  t ƒ r8 |  j ƒ  j ƒ  S|  j d d ƒ j d d ƒ Sd S(   s8  Back-transcribes an RNA sequence into DNA.

    If given a string, returns a new string object.
    
    Given a Seq or MutableSeq, returns a new Seq object with an RNA alphabet.

    Trying to transcribe a protein or DNA sequence raises an exception.

    e.g.

    >>> back_transcribe("ACUGN")
    'ACTGN'
    R_   Ra   R`   Rb   N(   R)   R   Rw   R8   R´   Rt   (   t   rna(    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyRw   ¢  s
    
Ry   R’   c         C   s[  |  j  ƒ  }  g  } | j } | j } | j j d k	 rQ t | j j j  ƒ  ƒ } n( t t j j j  ƒ  t j	 j j  ƒ  ƒ } t
 |  ƒ }	 xÆ t d |	 |	 d d ƒ D]ª }
 |  |
 |
 d !} y | j | | ƒ Wq  t t j f k
 rI| | j k r| rþ Pn  | j | ƒ qJ| j t | ƒ ƒ r3| j | ƒ qJt j d | ƒ ‚ q  Xq  Wd j | ƒ S(   s  Helper function to translate a nucleotide string (PRIVATE).

    Arguments:
     - sequence    - a string
     - table       - a CodonTable object (NOT a table name or id number)
     - stop_symbol - a single character string, what to use for terminators.
     - to_stop     - boolean, should translation terminate at the first
                     in frame stop codon?  If there is no in-frame stop codon
                     then translation continues to the end.
     - pos_stop    - a single character string for a possible stop codon
                     (e.g. TAN or NNN)

    Returns a string.

    e.g.

    >>> from Bio.Data import CodonTable
    >>> table = CodonTable.ambiguous_dna_by_id[1]
    >>> _translate_str("AAA", table)
    'K'
    >>> _translate_str("TAR", table)
    '*'
    >>> _translate_str("TAN", table)
    'X'
    >>> _translate_str("TAN", table, pos_stop="@")
    '@'
    >>> _translate_str("TA?", table)
    Traceback (most recent call last):
       ...
    TranslationError: Codon 'TA?' is invalid
    i    i   s   Codon '%s' is invalidR   N(   t   uppert   forward_tablet   stop_codonst   nucleotide_alphabett   lettersR{   Rš   R   Rq   Rr   R"   t   xrangeR¤   t   KeyErrorR   t   TranslationErrort
   issupersetR   (   t   sequenceR…   Rz   R†   t   pos_stopt   amino_acidsR¸   R¹   t   valid_letterst   nR¦   t   codon(    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyR‚   ·  s.    !		! Rx   c         C   s™   t  |  t ƒ r" |  j | | | ƒ St  |  t ƒ rJ |  j ƒ  j | | | ƒ Sy t j t | ƒ } Wn t k
 r t j	 | } n Xt
 |  | | | ƒ Sd S(   s£  Translate a nucleotide sequence into amino acids.

    If given a string, returns a new string object. Given a Seq or
    MutableSeq, returns a Seq object with a protein alphabet.

    Arguments:
     - table - Which codon table to use?  This can be either a name
               (string) or an NCBI identifier (integer).  Defaults
               to the "Standard" table.
     - stop_symbol - Single character string, what to use for any
                     terminators, defaults to the asterisk, "*".
     - to_stop - Boolean, defaults to False meaning do a full
                 translation continuing on past any stop codons
                 (translated as the specified stop_symbol).  If
                 True, translation is terminated at the first in
                 frame stop codon (and the stop_symbol is not
                 appended to the returned protein sequence).

    A simple string example using the default (standard) genetic code:
    
    >>> coding_dna = "GTGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG"
    >>> translate(coding_dna)
    'VAIVMGR*KGAR*'
    >>> translate(coding_dna, stop_symbol="@")
    'VAIVMGR@KGAR@'
    >>> translate(coding_dna, to_stop=True)
    'VAIVMGR'
     
    Now using NCBI table 2, where TGA is not a stop codon:

    >>> translate(coding_dna, table=2)
    'VAIVMGRWKGAR*'
    >>> translate(coding_dna, table=2, to_stop=True)
    'VAIVMGRWKGAR'

    Note that if the sequence has no in-frame stop codon, then the to_stop
    argument has no effect:

    >>> coding_dna2 = "GTGGCCATTGTAATGGGCCGC"
    >>> translate(coding_dna2)
    'VAIVMGR'
    >>> translate(coding_dna2, to_stop=True)
    'VAIVMGR'
    
    NOTE - Ambiguous codons like "TAN" or "NNN" could be an amino acid
    or a stop codon.  These are translated as "X".  Any invalid codon
    (e.g. "TA?" or "T-A") will throw a TranslationError.

    NOTE - Does NOT support gapped sequences.
    
    It will however translate either DNA or RNA.
    N(   R)   R   Rj   R8   R´   R   R   R*   Re   R€   R‚   (   RÀ   R…   Rz   R†   Rˆ   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyRj   õ  s    5c         C   s¸   t  |  t ƒ r |  j ƒ  St  |  t ƒ r8 |  j ƒ  j ƒ  Sd |  k sP d |  k rw d |  k sh d |  k rw t d ƒ ‚ n' d |  k s d |  k r˜ t } n t } |  j | ƒ d d d … S(   sH  Returns the reverse complement sequence of a nucleotide string.

    If given a string, returns a new string object.
    Given a Seq or a MutableSeq, returns a new Seq object with the same alphabet.

    Supports unambiguous and ambiguous nucleotide sequences.

    e.g.

    >>> reverse_complement("ACTG-NH")
    'DN-CAGT'
    R_   R`   Ra   Rb   s   Mixed RNA/DNA foundNiÿÿÿÿ(	   R)   R   Rn   R8   R´   Re   Ri   Rg   Rj   (   RÀ   Rl   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyRn   7  s    
	c          C   s$   d GHd d l  }  |  j ƒ  d GHd S(   s"   Run the Bio.Seq module's doctests.s   Runing doctests...iÿÿÿÿNt   Done(   t   doctestt   testmod(   RÇ   (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyt   _testY  s    
t   __main__(   R‹   t   __docformat__R
   RŸ   RŽ   Rš   t	   NameErrort   setsR    R.   R   t   Data.IUPACDataR   R   t   Bio.DataR   R   Rg   Ri   t   objectR   R   R8   Ru   Rw   RH   R‚   Rj   Rn   RÉ   R$   (    (    (    sz   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Seq.pyt   <module>   s>   
	ÿ ÿ ìÿ ÿ Z		=B	"	