ó
²“Ic           @   sl   d  Z  d d l m Z d d d „  ƒ  YZ d e f d „  ƒ  YZ d d d „  ƒ  YZ d	 e f d
 „  ƒ  YZ d S(   sÅ   
Bio.SeqIO support module (not for general use).

Unless you are writing a new parser or writer for Bio.SeqIO, you should not
use this module.  It provides base classes to try and simplify things.
iÿÿÿÿ(   t   generic_alphabett   SequenceIteratorc           B   s,   e  Z d  Z e d „ Z d „  Z d „  Z RS(   s³   Base class for building SeqRecord iterators.

    You should write a next() method to return SeqRecord
    objects.  You may wish to redefine the __init__
    method as well.
    c         C   s   | |  _  | |  _ d S(   sT  Create a SequenceIterator object.

        handle - input file
        alphabet - optional, e.g. Bio.Alphabet.generic_protein

        Note when subclassing:
        - there should be a single non-optional argument,
          the handle.
        - you do not have to require an alphabet.
        - you can add additional optional arguments.N(   t   handlet   alphabet(   t   selfR   R   (    (    s‡   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SeqIO/Interfaces.pyt   __init__   s    	c         C   s   t  d ƒ ‚ d S(   sx   Return the next record in the file.

        This method should be replaced by any derived class to do something useful.s    This object should be subclassedN(   t   NotImplementedError(   R   (    (    s‡   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SeqIO/Interfaces.pyt   next(   s    c         C   s   t  |  j d ƒ S(   s(  Iterate over the entries as a SeqRecord objects.

        Example usage for Fasta files:

        myFile = open("example.fasta","r")
        myFastaReader = FastaIterator(myFile)
        for record in myFastaReader :
            print record.id
            print record.seq
        myFile.close()N(   t   iterR   t   None(   R   (    (    s‡   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SeqIO/Interfaces.pyt   __iter__3   s    (   t   __name__t
   __module__t   __doc__R    R   R   R
   (    (    (    s‡   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SeqIO/Interfaces.pyR      s   	t   InterlacedSequenceIteratorc           B   sD   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s€  Base class for any iterator of a non-sequential file type.

    This object is not intended for use directly.
    
    When writing a parser for any interlaced sequence file where the whole
    file must be read in order to extract any single record, then you should
    subclass this object.

    All you need to do is to define your own:
    (1) __init__ method to parse the file and call self.move_start()
    (2) __len__ method to return the number of records
    (3) __getitem__ to return any requested record.

    This class will then provide the iterator methods including next(), but relies
    on knowing the total number of records and tracking the pending record index in
    as self._n

    It is up to the subclassed object to decide if it wants to generate a cache of
    SeqRecords when initialised, or simply use its own lists and dicts and create
    SeqRecords on request.
    c         C   s   |  j  ƒ  t d ƒ ‚ d S(   sg   Create the object.

        This method should be replaced by any derived class to do something useful.s'   This object method should be subclassedN(   t
   move_startR   (   R   (    (    s‡   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SeqIO/Interfaces.pyR   W   s    
c         C   s   t  d ƒ ‚ d S(   sr   Return the number of records.

        This method should be replaced by any derived class to do something useful.s'   This object method should be subclassedN(   R   (   R   (    (    s‡   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SeqIO/Interfaces.pyt   __len__b   s    c         C   s   t  d ƒ ‚ d S(   s«   Return the requested record.

        This method should be replaced by any derived class to do something
        useful.

        It should NOT touch the value of self._ns'   This object method should be subclassedN(   R   (   R   t   i(    (    s‡   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SeqIO/Interfaces.pyt   __getitem__k   s    c         C   s   d |  _  d  S(   Ni    (   t   _n(   R   (    (    s‡   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SeqIO/Interfaces.pyR   w   s    c         C   s8   |  j  } | t |  ƒ k  r0 | d |  _  |  | Sd  Sd  S(   Ni   (   R   t   lenR	   (   R   t   next_record(    (    s‡   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SeqIO/Interfaces.pyR   z   s
    	c         C   s   t  |  j d  ƒ S(   N(   R   R   R	   (   R   (    (    s‡   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SeqIO/Interfaces.pyR
   ƒ   s    (	   R   R   R   R   R   R   R   R   R
   (    (    (    s‡   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SeqIO/Interfaces.pyR   @   s   							t   SequenceWriterc           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   sÞ   This class should be subclassed.

    Interlaced file formats (e.g. Clustal) should subclass directly.

    Sequential file formats (e.g. Fasta, GenBank) should subclass
    the SequentialSequenceWriter class instead.
    c         C   s   | |  _  d S(   si   Creates the writer object.

        Use the method write_file() to actually record your sequence records.N(   R   (   R   R   (    (    s‡   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SeqIO/Interfaces.pyR   Ž   s    c         C   sa   y | j  j ƒ  SWnI t k
 r\ | j  d k rF t d | j ƒ ‚ q] t d | j ƒ ‚ n Xd S(   s6   Use this to catch errors like the sequence being None.s,   SeqRecord (id=%s) has None for its sequence.s*   SeqRecord (id=%s) has an invalid sequence.N(   t   seqt   tostringt   AttributeErrorR	   t	   TypeErrort   id(   R   t   record(    (    s‡   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SeqIO/Interfaces.pyt   _get_seq_string”   s    c         C   s?   | } x& d d g D] } | j  | d ƒ } q W| j  d d ƒ S(   s1   Use this to avoid getting newlines in the output.s   
s   t    s     (   t   replace(   R   t   textt   answert   x(    (    s‡   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SeqIO/Interfaces.pyt   clean¦   s    c         C   s   t  d ƒ ‚ d S(   sì   Use this to write an entire file containing the given records.

        records - A list or iterator returning SeqRecord objects

        Should return the number of records (as an integer).

        This method can only be called once.s    This object should be subclassedN(   R   (   R   t   records(    (    s‡   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SeqIO/Interfaces.pyt
   write_file­   s    	(   R   R   R   R   R   R#   R%   (    (    (    s‡   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SeqIO/Interfaces.pyR   †   s
   			t   SequentialSequenceWriterc           B   sD   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sù  This class should be subclassed.

    It is intended for sequential file formats with an (optional)
    header, repeated records, and an (optional) footer.

    In this case (as with interlaced file formats), the user may
    simply call the write_file() method and be done.

    However, they may also call the write_header(), followed
    by multiple calls to write_record() and/or write_records()
    followed finally by write_footer().

    Users must call write_header() and write_footer() even when
    the file format concerned doesn't have a header or footer.
    This is to try and make life as easy as possible when
    switching the output format.
    
    Note that write_header() cannot require any assumptions about
    the number of records.
    c         C   s(   | |  _  t |  _ t |  _ t |  _ d  S(   N(   R   t   Falset   _header_writtent   _record_writtent   _footer_written(   R   R   (    (    s‡   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SeqIO/Interfaces.pyR   Ð   s    			c         C   sO   |  j  s t d ƒ ‚ |  j s, t d ƒ ‚ |  j sB t d ƒ ‚ t |  _  d  S(   Ns%   You have aleady called write_header()s8   You have aleady called write_record() or write_records()s%   You have aleady called write_footer()(   R(   t   AssertionErrorR)   R*   t   True(   R   (    (    s‡   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SeqIO/Interfaces.pyt   write_headerÖ   s    c         C   sM   |  j  s t d ƒ ‚ |  j s* t d ƒ ‚ |  j s@ t d ƒ ‚ t |  _ d  S(   Ns"   You must call write_header() firsts9   You have not called write_record() or write_records() yets%   You have aleady called write_footer()(   R(   R+   R)   R*   R,   (   R   (    (    s‡   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SeqIO/Interfaces.pyt   write_footerÜ   s    c         C   sD   |  j  s t d ƒ ‚ |  j s+ t d ƒ ‚ t |  _ t d ƒ ‚ d S(   sþ   Write a single record to the output file.

        record - a SeqRecord object

        Once you have called write_header() you can call write_record()
        and/or write_records() as many times as needed.  Then call
        write_footer() and close().s"   You must call write_header() firsts&   You have already called write_footer()s    This object should be subclassedN(   R(   R+   R*   R,   R)   R   (   R   R   (    (    s‡   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SeqIO/Interfaces.pyt   write_recordâ   s    	c         C   sf   |  j  s t d ƒ ‚ |  j s+ t d ƒ ‚ d } x% | D] } |  j | ƒ | d 7} q8 Wt |  _ | S(   sT  Write multiple record to the output file.

        records - A list or iterator returning SeqRecord objects

        Once you have called write_header() you can call write_record()
        and/or write_records() as many times as needed.  Then call
        write_footer() and close().

        Returns the number of records written.
        s"   You must call write_header() firsts&   You have already called write_footer()i    i   (   R(   R+   R*   R/   R,   R)   (   R   R$   t   countR   (    (    s‡   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SeqIO/Interfaces.pyt   write_recordsò   s    	c         C   s'   |  j  ƒ  |  j | ƒ } |  j ƒ  | S(   sç   Use this to write an entire file containing the given records.

        records - A list or iterator returning SeqRecord objects

        This method can only be called once.  Returns the number of records
        written.
        (   R-   R1   R.   (   R   R$   R0   (    (    s‡   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SeqIO/Interfaces.pyR%     s    

(	   R   R   R   R   R-   R.   R/   R1   R%   (    (    (    s‡   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SeqIO/Interfaces.pyR&   »   s   					N(    (    (   R   t   Bio.AlphabetR    R   R   R   R&   (    (    (    s‡   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SeqIO/Interfaces.pyt   <module>
   s
   2F5