ó
4˙Hc           @   sđ  d  Z  d d- d     YZ d d. d     YZ d d/ d     YZ d d0 d     YZ d	 d1 d
     YZ d d2 d     YZ d d3 d     YZ d d4 d     YZ d d5 d     YZ	 d d6 d     YZ
 d d7 d     YZ d   Z d d8 d     YZ d   Z d d l m Z d d l Td d9 d     YZ d  e f d!     YZ d" e f d#     YZ d$ d: d%     YZ d& e f d'     YZ e d( k rěd) GHe d*  Z e e  Z x0 e D]( Z e j Ge e j   Ge e j!  GHqŽWe j"   d+ GHn  d, S(;   sË  
Parser for ACE files output by PHRAP.

Written by Frank Kauff (fkauff@duke.edu) and
Cymon J. Cox (cymon@duke.edu)

Uses the Biopython Parser interface: ParserSupport.py

Usage:

There are two ways of reading an ace file:
1) The function 'read' reads the whole file at once;
2) The function 'parse' reads the file contig after contig.
    
1) Parse whole ace file at once:

        from Bio.Sequencing import Ace
        acefilerecord=Ace.read(open('my_ace_file.ace'))

This gives you:
        acefilerecord.ncontigs (the number of contigs in the ace file)
        acefilerecord.nreads (the number of reads in the ace file)
        acefilerecord.contigs[] (one instance of the Contig class for each contig)

The Contig class holds the info of the CO tag, CT and WA tags, and all the reads used
for this contig in a list of instances of the Read class, e.g.:

        contig3=acefilerecord.contigs[2]
        read4=contig3.reads[3]
        RD_of_read4=read4.rd
        DS_of_read4=read4.ds

CT, WA, RT tags from the end of the file can appear anywhere are automatically
sorted into the right place.

see _RecordConsumer for details.

2) Or you can iterate over the contigs of an ace file one by one in the ususal way:

        from Bio.Sequencing import Ace
        contigs=Ace.parse(open('my_ace_file.ace'))
        for contig in contigs:
            print contig.name
            ...

Please note that for memory efficiency, when using the iterator approach, only one
contig is kept in memory at once.  However, there can be a footer to the ACE file
containing WA, CT, RT or WR tags which contain additional meta-data on the contigs.
Because the parser doesn't see this data until the final record, it cannot be added to
the appropriate records.  Instead these tags will be returned with the last contig record.
Thus an ace file does not entirerly suit the concept of iterating. If WA, CT, RT, WR tags
are needed, the 'read' function rather than the 'parse' function might be more appropriate.
t   rdc           B   s   e  Z d  Z d   Z RS(   s5   RD (reads), store a read with its name, sequence etc.c         C   s1   d |  _  d  |  _ d  |  _ d  |  _ d |  _ d  S(   Nt    (   t   namet   Nonet   padded_basest
   info_itemst	   read_tagst   sequence(   t   self(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Ace.pyt   __init__>   s
    				(   t   __name__t
   __module__t   __doc__R	   (    (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Ace.pyR    <   s   t   qac           B   s   e  Z d  Z d d  Z RS(   sI   QA (read quality), including which part if any was used as the consensus.c         C   s~   d  |  _ d  |  _ d  |  _ d  |  _ | rz t t | j   d  } | d |  _ | d |  _ | d |  _ | d |  _ n  d  S(   Ni   i    i   i   (   R   t   qual_clipping_startt   qual_clipping_endt   align_clipping_startt   align_clipping_endt   mapt   evalt   split(   R   t   linet   header(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Ace.pyR	   G   s    				N(   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/Sequencing/Ace.pyR   E   s   t   dsc           B   s   e  Z d  Z d d  Z RS(   s:   DS lines, include file name of a read's chromatogram file.c      	   C   s(  d |  _  d |  _ d |  _ d |  _ d |  _ d |  _ d |  _ | r$d d d d d d d g } t | j |  } t	 t
 | |   } d	 | k r | d	 =n  | j   } | j   xn t
 | | d
 t |  d
 g  D]E \ } } t |  | | j   | | t | |  d
 | !j    qŘ Wn  d  S(   NR   t   CHROMAT_FILEt   PHD_FILEt   TIMEt   CHEMt   DYEt   TEMPLATEt	   DIRECTIONi˙˙˙˙i   (   t   chromat_filet   phd_filet   timet   chemt   dyet   templatet	   directionR   t   findt   dictt   zipt   keyst   sortt   lent   setattrt   lowert   strip(   R   R   t   tagst   posst   tagpost   pst   p1t   p2(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Ace.pyR	   U   s"    							

1N(   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/Sequencing/Ace.pyR   S   s   t   afc           B   s   e  Z d  Z d d  Z RS(   s<   AF lines, define the location of the read within the contig.c         C   sa   d |  _  d  |  _ d  |  _ | r] | j   } | d |  _  | d |  _ t | d  |  _ n  d  S(   NR   i   i   i   (   R   R   t   corut   padded_startR   t   int(   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/Sequencing/Ace.pyR	   k   s    			N(   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/Sequencing/Ace.pyR5   i   s   t   bsc           B   s   e  Z d  Z d d  Z RS(   sL   "BS (base segment), which read was chosen as the consensus at each position.c         C   sg   d |  _  d  |  _ d  |  _ | rc | j   } t | d  |  _ t | d  |  _ | d |  _  n  d  S(   NR   i   i   i   (   R   R   R7   t
   padded_endR   R8   (   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/Sequencing/Ace.pyR	   w   s    			N(   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/Sequencing/Ace.pyR9   u   s   t   rtc           B   s   e  Z d  Z d d  Z RS(   s<   RT (transient read tags), generated by crossmatch and phrap.c         C   sŠ   d |  _  d |  _ d |  _ d  |  _ d  |  _ d |  _ | rĽ | j   } | d |  _  | d |  _ | d |  _ t | d  |  _ t | d  |  _ | d |  _ n  d  S(   NR   i    i   i   i   i   i   (	   R   t   tag_typet   programR   R7   R:   t   dateR   R8   (   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/Sequencing/Ace.pyR	      s    						N(   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/Sequencing/Ace.pyR;      s   t   ctc           B   s   e  Z d  Z d d  Z RS(   s   CT (consensus tags).c         C   sć   d |  _  d |  _ d |  _ d  |  _ d  |  _ d |  _ d |  _ g  |  _ g  |  _	 | râ | j
   } | d |  _  | d |  _ | d |  _ t | d  |  _ t | d  |  _ | d |  _ t |  d k râ | d	 |  _ qâ n  d  S(
   NR   i    i   i   i   i   i   i   i   (   R   R<   R=   R   R7   R:   R>   t   notranst   infot   commentR   R8   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/Sequencing/Ace.pyR	      s&    									N(   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/Sequencing/Ace.pyR?      s   t   wac           B   s   e  Z d  Z d d  Z RS(   sG   WA (whole assembly tag), holds the assembly program name, version, etc.c         C   sd   d |  _  d |  _ d |  _ g  |  _ | r` | j   } | d |  _  | d |  _ | d |  _ n  d  S(   NR   i    i   i   (   R<   R=   R>   RA   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/Sequencing/Ace.pyR	   Ź   s    				N(   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/Sequencing/Ace.pyRC   Ş   s   t   wrc           B   s   e  Z d  Z d d  Z RS(   s	   WR lines.c         C   sq   d |  _  d |  _ d |  _ g  |  _ | rm | j   } | d |  _  | d |  _ | d |  _ | d |  _ n  d  S(   NR   i    i   i   i   (   R   t   alignedR=   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/Sequencing/Ace.pyR	   š   s    				N(   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/Sequencing/Ace.pyRD   ˇ   s   t   Readsc           B   s   e  Z d  Z d d  Z RS(   s8   Holds information about a read supporting an ACE contig.c         C   s¤   d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ | r  t   |  _ | j   } | d |  j _ t | d  |  j _	 t | d  |  j _
 t | d  |  j _ n  d  S(   Ni   i   i   i   (   R   R    R   R   R;   RD   R   R   R8   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/Sequencing/Ace.pyR	   Ç   s    					N(   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/Sequencing/Ace.pyRF   Ĺ   s   t   Contigc           B   s   e  Z d  Z d d  Z RS(   s4   Holds information about a contig from an ACE record.c         C   sŘ   d |  _  d  |  _ d  |  _ d  |  _ d  |  _ d |  _ g  |  _ g  |  _ g  |  _	 g  |  _
 d  |  _ d  |  _ | rÔ | j   } | d |  _  t | d  |  _ t | d  |  _ t | d  |  _ | d |  _ n  d  S(   NR   i   i   i   i   i   (   R   R   t   nbasest   nreadst	   nsegmentst   uorcR   t   qualityR5   R9   t   readsR?   RC   R   R8   (   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/Sequencing/Ace.pyR	   ×   s&    												N(   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/Sequencing/Ace.pyRG   Ő   s   c         c   s	  t  |   }  d } xđt ry0 x) t rI | j d  r: Pn  |  j   } q! WWn t k
 r_ d SXt |  } x3 |  D]+ } | j   } | s Pn  | j | 7_ qs Wx |  D] } | j   rŠ PqŠ qŠ W| j d  sá t d   n  x= |  D]5 } | j   sţ Pn  | j	 j
 t t | j     qč Wx |  D] } | j   r(Pq(q(Wxc t r§| j d  s^Pn  | j j t |   y |  j   } WqEt k
 rŁt d   qEXqEWxJ t rô| j   rÁPn  y |  j   } WqŤt k
 rđt d   qŤXqŤWxc t rZ| j d	  sPn  | j j t |   y |  j   } Wqřt k
 rVt d
   qřXqřWxt rűy0 x) t r| j d  rPn  |  j   } qjWWn t k
 rłt d   n X| j j t |   x= |  D]5 } | j   } | síPn  | j d j j | 7_ qŃWx |  D] } | j   rPqqW| j d  sIt d   n  t |  | j d _ x |  D] } | j   rfPqfqfWP| j d  rŻt |  | j d _ d } n  x3t räy- x& t ră| j   rÔPn  |  j   } qžWWn t k
 růPn X| j d  r| j d j d k r2g  | j d _ n  xG |  D]? } | j   } | d k r[Pn  | j d j j t |   q9Wd } q˛| j d  r| j d j d k r˝g  | j d _ n  xG |  D]? } | j   } | d k rćPn  | j d j j t |   qÄWd } q˛| j d  rÍ| j d k r:g  | _ n  y |  j   } Wn t k
 rit d   n X| j j t |   xA |  D]9 } | j   } | d k rŠPn  | j d j j |  qWd } q˛| j d  rŕ| j d k r÷g  | _ n  y |  j   } Wn t k
 r&t d   n X| j j t |   x |  D] } | j   } | d k rŹxn |  D]< } | j   } | j d  rPn  | j d j j |  qiWqD| d k rźPqD| j d j j |  qDWd } q˛Pq˛W| j d  s^Pq^q^W| Vq Wd S(   sG  parse(handle)
        
    where handle is a file-like object.
    
    This function returns an iterator that allows you to iterate
    over the ACE file record by record:

        records = parse(handle)
        for record in records:
            # do something with the record

    where each record is a Contig object.
    R   t   CONt   BQs   Failed to find BQ lines   AF s   Unexpected end of AF blocks   Unexpected end of files   BS s   Failed to find end of BS blocks   RD s   Failed to find RD linei˙˙˙˙s   QA s   Failed to find QA lines   DS s   RT{t   }s   WR{s   WA{s   Failed to read WA blocks   CT{s   Failed to read CT blocks   COMMENT{s   C}t   RD(   t   itert   Truet
   startswitht   nextt   StopIterationRG   R.   R   t
   ValueErrorRL   t   extendR   R8   R   R5   t   appendR9   RM   RF   R    R   R   R;   R   RD   RC   RA   R?   t   endswithRB   (   t   handleR   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/Sequencing/Ace.pyt   parseě   s   		#								 !	 !	 		t   ACEFileRecordc           B   s    e  Z d  Z d   Z d   Z RS(   s   Holds data of an ACE file.
    c         C   s(   d  |  _ d  |  _ g  |  _ d  |  _ d  S(   N(   R   t   ncontigsRI   t   contigsRC   (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Ace.pyR	   °  s    			c         C   sŚ  g  } g  } g  } xÂt  t |  j   D]Ť} |  j | } | j ro |  j sY g  |  _ n  |  j j | j  n  | j rĐ g  | j D] } | j | j k r | ^ q } t |  j | j j |  | j |  n  x t  t | j	   D]é } | j	 | }	 |	 j
 rdg  |	 j
 D]! }
 |
 j |	 j j k r|
 ^ q} t |  j | j	 | j
 j |  | j |  n  |	 j rć g  |	 j D]! } | j |	 j j k rw| ^ qw} t |  j | j	 | j j |  | j |  qć qć Wq( WxČt  t |  j   D]ą} |  j | } xc | D][ } | j | j k r|  j | j d k rHg  |  j | _ n  |  j | j j |  qqW| sr| ríx)t  t | j	   D]} | j	 | }	 x{ | D]s }
 |
 j |	 j j k r˘|  j | j	 | j
 d k rôg  |  j | j	 | _
 n  |  j | j	 | j
 j |
  q˘q˘Wx{ | D]s } | j |	 j j k r |  j | j	 | j d k rrg  |  j | j	 | _ n  |  j | j	 | j j |  q q WqWqíqíWd S(   sT   Sorts wr, rt and ct tags into the appropriate contig / read instance, if possible.  N(   t   rangeR+   R`   RC   RX   R?   R   R   t   removeRM   R;   R    RD   R   RY   (   R   R?   R;   RD   t   it   ct   ct_tagt   newctst   jt   rt   rt_tagt   newrtst   wr_tagt   newwrs(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Ace.pyR*   ś  sV    			.	1!	1!%(   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/Sequencing/Ace.pyR^   ­  s   	c         C   s´   t  |   }  t   } y |  j   } Wn t k
 rD t d   n X| j d  sc t d   n  | j   } t t | d d ! \ | _	 | _
 t t |    | _ | j   | S(   s2   Parses the full ACE file in list of contigs.

    s   Premature end of filet   ASs   File does not start with 'AS'.i   i   (   RR   R^   RU   RV   RW   RT   R   R   R8   R_   RI   t   listR]   R`   R*   (   R[   R\   R   t   words(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Ace.pyt   readç  s    	"
i˙˙˙˙(   t   File(   t   *t   Iteratorc           B   s,   e  Z d  Z d d  Z d   Z d   Z RS(   s   Iterates over an ACE-file with multiple contigs.
    
    Methods: 
    next    Return the next record from the stream, or None.
    c         C   s;   d d l  } | j d t  t j |  |  _ | |  _ d S(   s  __init__(self, handle, parser=None)
        
        Create a new iterator.  handle is a file-like object.  parser
        is an optional Parser object to change the results into another form.
        If set to None, then the raw contents of the file will be returned.
        i˙˙˙˙Nsm   Ace.Iterator is deprecated. Instead of Ace.Iterator(handle, Ace.RecordParser()), please use Ace.parse(handle)(   t   warningst   warnt   DeprecationWarningRq   t
   UndoHandlet   _uhandlet   _parser(   R   R[   t   parserRt   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Ace.pyR	     s    c         C   să   g  } x> |  j  j   } | s" d S| d  d k r	 | j |  Pq	 q	 WxT |  j  j   } | sc Pn  | r | d  d k r |  j  j |  Pn  | j |  qJ W| s¨ d Sd j |  } |  j d k	 rß |  j j t j	 |   S| S(   s{   next(self) -> object

        Return the next contig record from the file. If no more records
        return None.
        i   RN   R   N(
   Rx   t   readlineR   RY   t   savelinet   joinRy   R]   Rq   t   StringHandle(   R   t   linesR   t   data(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Ace.pyRU     s,    c         C   s   t  |  j d  S(   s+   Iterate over the ACE file record by record.N(   RR   RU   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/Sequencing/Ace.pyt   __iter__A  s    N(   R
   R   R   R   R	   RU   R   (    (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Ace.pyRs     s   	"t   RecordParserc           B   s    e  Z d  Z d   Z d   Z RS(   s*   Parses ACE file data into a Record object.c         C   s   t    |  _ t   |  _ d  S(   N(   t   _Scannert   _scannert   _RecordConsumert	   _consumer(   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Ace.pyR	   G  s    c         C   sJ   t  | t j  r | } n t j |  } |  j j | |  j  |  j j S(   N(   t
   isinstanceRq   Rw   R   t   feedR   R   (   R   R[   t   uhandle(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Ace.pyR]   K  s
    	(   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/Sequencing/Ace.pyR   E  s   	t	   ACEParserc           B   s    e  Z d  Z d   Z d   Z RS(   s.   Parses full ACE file in list of contigs.

    c         C   s,   d d  l  } | j d t  t   |  _ d  S(   Ni˙˙˙˙sb   Ace.ACEParser is deprecated. Instead of Ace.ACEParser().parse(handle), please use Ace.read(handle)(   Rt   Ru   Rv   R^   R   (   R   Rt   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Ace.pyR	   X  s    c         C   s   | j    } | d  d k r+ t d   n  t | j   d  |  j _ t | j   d  |  j _ t |  } t |  |  j _	 |  j j
   |  j S(   Ni   Rm   s   File does not start with 'AS'.i   (   R{   RW   R   R   R   R_   RI   R]   Rn   R`   R*   (   R   R[   t	   firstlinet   records(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Ace.pyR]   ]  s    (   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/Sequencing/Ace.pyR   S  s   	R   c           B   s;   e  Z d  Z d   Z d   Z d   Z d   Z d   Z RS(   sS   Scans an ACE-formatted file.
    
    Methods:
    feed - Feed one ACE record.
    c         C   sA   t  | t j  s t d   | j   r= |  j | |  n  d S(   sä   feed(self, handle, consumer)

        Feed in ACE data for scanning.  handle is a file-like object
        containing ACE data.  consumer is a Consumer object that will
        receive events as the ACE data is scanned.
        s   handle must be an UndoHandleN(   R   Rq   Rw   t   AssertionErrort   peeklinet   _scan_record(   R   R[   t   consumer(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Ace.pyR   v  s    	c         C   sÉ  | j    t | | j d d | j |  j |   t | | j d d t | | j d d | j |  j	 | |   t | | j d d t | | j
 d d t | | j d d t | | j d d xďt | | j d d t | | j d d | j |  j |   t | | j d d t | | j d d	 y0 t | | j d d t | | j d d
 Wn t k
 r| j   d  SXxy t | | j d d Wn t k
 rÎ| j   d  SXt | | j d d r | j |  j |   qt | | j d d r1| j |  j |   qt | | j d d rb| j |  j |   qt | | j d d r| j |  j |   qt |  } PqW| j d  sÖ | j   PqÖ qÖ Wd  S(   Nt   starts   CO t   blanki   RO   s   AF s   BS s   RD s   QA s   DS t   RTt   WRt   WAt   CTRQ   (   t   begin_contigt   read_and_callt	   co_headert   co_datat   _scan_sequence_datat   read_and_call_whilet   noeventt	   bq_headert   bq_datat   _scan_bq_dataR5   R9   t   read_and_call_untilt	   rd_headert   rd_dataR   t   attempt_read_and_callR   RW   t
   end_contigt   rt_startt   rt_datat   _scan_bracket_tagst   wr_startt   wr_datat   wa_startt   wa_datat   ct_startt   ct_datat   safe_peeklineRT   (   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/Sequencing/Ace.pyR     sR    



c         C   sH   d } x; | j    } t |  r2 | j |  Pn  | d | 7} q	 W| S(   s;   Scans multiple lines of quality data and concatenates them.R   t    (   R{   t   is_blank_lineR|   (   R   R   R   t   qualR   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Ace.pyR    ź  s    c         C   sJ   d } x= | j    } t |  r2 | j |  Pn  | | j   7} q	 W| S(   s<   Scans multiple lines of sequence data and concatenates them.R   (   R{   Rą   R|   R.   (   R   R   t   seqR   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Ace.pyR   Č  s    c         C   sr   g  } xe | j    j   } | j |  | j d  r	 | d d  | d <| d d k rf | d  } n  Pq	 q	 W| S(   s!   Reads the data lines of a {} tag.RP   i˙˙˙˙R   (   R{   R.   RY   RZ   (   R   R   t   fulltagR   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Ace.pyR¨   Ô  s    (   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/Sequencing/Ace.pyR   p  s   		:		R   c           B   sË   e  Z 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   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s%   Reads the ace tags into data records.c         C   s   d  |  _ d  S(   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/Sequencing/Ace.pyR	   ĺ  s    c         C   s   t    |  _ d  S(   N(   RG   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/Sequencing/Ace.pyR   č  s    c         C   s   d  S(   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/Sequencing/Ace.pyRĽ   ë  s    c         C   sr   | j    } | d |  j _ t | d  |  j _ t | d  |  j _ t | d  |  j _ | d |  j _ d  S(   Ni   i   i   i   i   (   R   R   R   R   RH   RI   RJ   RK   (   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/Sequencing/Ace.pyR   î  s    c         C   s   | |  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/Sequencing/Ace.pyR   ö  s    c         C   s   d  S(   N(    (   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/Sequencing/Ace.pyR   ů  s    c         C   s   t  t | j    |  j _ d  S(   N(   R   R   R   R   RL   (   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/Sequencing/Ace.pyR   ü  s    c         C   sY   | j    } t   } | d | _ | d | _ t | d  | _ |  j j j |  d  S(   Ni   i   i   (   R   R5   R   R6   R   R7   R   RY   (   R   R   R   t   afdata(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Ace.pyR5   ˙  s    	c         C   s_   | j    } t   } t | d  | _ t | d  | _ | d | _ |  j j j |  d  S(   Ni   i   i   (   R   R9   R   R7   R:   R   R   RY   (   R   R   R   t   bsdata(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Ace.pyR9     s    	c         C   s   | j    } |  j j j t    t   } | d | _ t | d  | _ t | d  | _	 t | d  | _
 | |  j j d _ d  S(   Ni   i   i   i   i˙˙˙˙(   R   R   RM   RY   RF   R    R   R   R   R   R   (   R   R   R   t   rddata(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Ace.pyR˘     s    	c         C   s   | |  j  j d j _ d  S(   Ni˙˙˙˙(   R   RM   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/Sequencing/Ace.pyRŁ     s    c         C   sm   t  t | j   d  } t   } | d | _ | d | _ | d | _ | d | _ | |  j j	 d _ d  S(   Ni   i    i   i   i˙˙˙˙(
   R   R   R   R   R   R   R   R   R   RM   (   R   R   R   t   qadata(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Ace.pyR     s    	c   	   	   C   sü   t    } d d d d d d d g } t | j |  } t t | |   } d | k ra | d =n  | j   } | j   xk t | | d	 t |  d	 g  D]E \ } } t | | | j	   | | t | |  d	 | !j
    q W| |  j j d _  d  S(
   NR   R   R   R   R   R   R   i˙˙˙˙i   (   R   R   R&   R'   R(   R)   R*   R+   R,   R-   R.   R   RM   (	   R   R   t   dsdataR/   R0   R1   R2   R3   R4   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Ace.pyR   &  s    	

1=c         C   se   | j    j d  s$ t d   n  t   } |  j j d  k rN g  |  j _ n  |  j j j |  d  S(   Nt   {s   CT tag does not start with CT{(   R.   RZ   RW   R?   R   R   RY   (   R   R   t   ctdata(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Ace.pyR­   3  s    	c         C   s  t  |  d k  r! t d   n  | d j   } | d |  j j d _ | d |  j j d _ | d |  j j d _ t | d  |  j j d _	 t | d  |  j j d _
 | d |  j j d _ t  |  d	 k ró | d
 |  j j d _ n  | d |  j j d _ d  S(   Ni   s   Missing header line in CT tagi    i˙˙˙˙i   i   i   i   i   i   (   R+   RW   R   R   R?   R   R<   R=   R   R7   R:   R>   R@   RA   (   R   t   taglinesR   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Ace.pyRŽ   ;  s    c         C   sz   | j    j d  s$ t d   n  t   } |  j j d j d  k r\ g  |  j j d _ n  |  j j d j j |  d  S(   NRş   s   RT tag does not start with RT{i˙˙˙˙(   R.   RZ   RW   R;   R   RM   R   RY   (   R   R   t   rtdata(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Ace.pyRŚ   I  s    	c         C   ső   t  |  d k  r! t d   n  | d j   } | d |  j j d j d _ | d |  j j d j d _ | d |  j j d j d _ t	 | d  |  j j d j d _
 t	 | d  |  j j d j d _ | d |  j j d j d _ d  S(	   Ni   s   Missing header line in RT tagi    i˙˙˙˙i   i   i   i   (   R+   RW   R   R   RM   R;   R   R<   R=   R   R7   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/Sequencing/Ace.pyR§   S  s    $$c         C   se   | j    j d  s$ t d   n  t   } |  j j d  k rN g  |  j _ n  |  j j j |  d  S(   NRş   s   WA tag does not start with WA{(   R.   RZ   RW   RC   R   R   RY   (   R   R   t   wadata(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Ace.pyRŤ   ^  s    	c         C   s   t  |  d k  r! t d   n  | d j   } | d |  j j d _ | d |  j j d _ | d |  j j d _ | d |  j j d _ d  S(   Ni   s   Missing header line in WA tagi    i˙˙˙˙i   (	   R+   RW   R   R   RC   R<   R=   R>   RA   (   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/Sequencing/Ace.pyRŹ   f  s    c         C   sz   | j    j d  s$ t d   n  t   } |  j j d j d  k r\ g  |  j j d _ n  |  j j d j j |  d  S(   NRş   s   WR tag does not start with WR{i˙˙˙˙(   R.   RZ   RW   RD   R   RM   R   RY   (   R   R   t   wrdata(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Ace.pyRŠ   o  s    	c         C   s­   t  |  d k  r! t d   n  | d j   } | d |  j j d j d _ | d |  j j d j d _ | d |  j j d j d _ | d |  j j d j d _	 d  S(   Ni   s   Missing header line in WR tagi    i˙˙˙˙i   i   (
   R+   RW   R   R   RM   RD   R   RE   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/Sequencing/Ace.pyRŞ   w  s    (   R
   R   R   R	   R   RĽ   R   R   R   R   R5   R9   R˘   RŁ   R   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/Sequencing/Ace.pyR   â  s,   																	
					t   __main__s   Quick self tests   ../../Tests/Ace/contig1.acet   DoneN(    (    (    (    (    (    (    (    (    (    (    (    (    (    (#   R   R    R   R   R5   R9   R;   R?   RC   RD   RF   RG   R]   R^   Rp   t   BioRq   t   Bio.ParserSupportRs   t   AbstractParserR   R   R   t   AbstractConsumerR   R
   t   openR[   R`   t   contigR   R+   R   RM   t   close(    (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Ace.pyt   <module>9   s:   		Á:	"
9r&
