ó
ÊOIc           @   sF  d  Z  d d l m Z d d l m Z d d d d d d	 d
 d d d d d g Z d d# d „  ƒ  YZ d „  Z d „  Z d d l m	 Z	 d d l
 Td d$ d „  ƒ  YZ d e f d „  ƒ  YZ d d% d „  ƒ  YZ d e f d „  ƒ  YZ e d k rBd GHe d  ƒ Z e e ƒ Z x# e D] Z e j Ge e j ƒ GHqWe j ƒ  d! GHn  d" S(&   sX  
Parser for PHD files output by PHRED and used by PHRAP and CONSED.

This module can be used used directly which will return Record objects
which should contain all the original data in the file.

Alternatively, using Bio.SeqIO with the "phd" format will call this module
internally.  This will give SeqRecord objects for each contig sequence.
iÿÿÿÿ(   t   Seq(   t   generic_dnat   CHROMAT_FILEt   ABI_THUMBPRINTt   PHRED_VERSIONt   CALL_METHODt   QUALITY_LEVELSt   TIMEt   TRACE_ARRAY_MIN_INDEXt   TRACE_ARRAY_MAX_INDEXt   TRIMt   TRACE_PEAK_AREA_RATIOt   CHEMt   DYEt   Recordc           B   s   e  Z d  Z d „  Z RS(   s!   Hold information from a PHD file.c         C   sU   d |  _  i  |  _ x! t D] } d  |  j | j ƒ  <q Wg  |  _ d |  _ d |  _ d  S(   Nt    (   t	   file_namet   commentst	   CKEYWORDSt   Nonet   lowert   sitest   seqt   seq_trimmed(   t   selft   kw(    (    s…   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Phd.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/Phd.pyR      s   c      
   C   sÃ  xA |  D]5 } | j  d ƒ r t ƒ  } | d j ƒ  | _ Pq q Wd Sx- |  D] } | j  d ƒ rK PqK qK Wt d ƒ ‚ x|  D]
} | j ƒ  } | s™ q{ n  | d k r© Pn  | j d d ƒ \ } } | j ƒ  } | j ƒ  } | d  k rõ | | j | <q{ | d! k rt	 | ƒ | j | <q{ | d k r9t
 | ƒ | j | <q{ | d k r{ | j ƒ  \ } } } t	 | ƒ t	 | ƒ t
 | ƒ f | j | <q{ q{ Wt d ƒ ‚ x- |  D] } | j  d ƒ rœPqœqœWt d ƒ ‚ xO |  D]G } | j  d ƒ råPqÌ| j ƒ  \ } }	 }
 | j j | |	 |
 f ƒ qÌWx- |  D] } | j  d ƒ rPqqWt d ƒ ‚ t j d j g  | j D] } | d ^ q]ƒ t ƒ | _ | j d d k	 r¿| j d d  \ } } | j | | !| _ n  | S("   s»   Reads the next PHD record from the file, returning it as a Record object.

    This function reads PHD file data line by line from the handle,
    and returns a single Record object.
    t   BEGIN_SEQUENCEi   Nt   BEGIN_COMMENTs!   Failed to find BEGIN_COMMENT linet   END_COMMENTt   :i   t   chromat_filet   phred_versiont   call_methodt   chemt   dyet   timet   basecaller_versiont   trace_processor_versiont   abi_thumbprintt   quality_levelst   trace_array_min_indext   trace_array_max_indext   trace_peak_area_ratiot   trims   Failed to find END_COMMENT linet	   BEGIN_DNAs   Failed to find BEGIN_DNA linet   END_DNAt   END_SEQUENCEs    Failed to find END_SEQUENCE lineR   i    i   (   R"   R#   R$   R%   R&   R'   R(   R)   (   R*   R+   R,   R-   (   t
   startswithR   t   rstripR   t
   ValueErrort   stript   splitR   R   t   intt   floatR   t   appendR    t   joinR   R   R   R   (   t   handlet   linet   recordt   keywordt   valuet   firstt   lastt   probt   baset   qualityt   locationt   n(    (    s…   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Phd.pyt   read#   sr    	      	  	/8c         c   s,   x% t  r' t |  ƒ } | s d S| Vq Wd S(   sƒ  Iterates over a file returning multiple PHD records.

    The data is read line by line from the handle. The handle can be a list
    of lines, an open file, or similar; the only requirement is that we can
    iterate over the handle to retrieve lines from it.

    Typical usage:

    records = parse(handle)
    for record in records:
        # do something with the record object
    N(   t   TrueRH   (   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/Phd.pyt   parsep   s
    	(   t   File(   t   *t   Iteratorc           B   s,   e  Z d  Z d d „ Z d „  Z d „  Z RS(   s   Iterates over a file of multiple PHD records (DEPRECATED).
    
    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  Create a new iterator.
        
        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ÿÿÿÿNs•   Bio.Sequencing.Phd.Iterator is deprecated. Please use Bio.Sequencing.Phd.parse(handle) instead of Bio.Sequencing.Phd.Iterator(handle, RecordParser())(   t   warningst   warnt   DeprecationWarningRK   t
   UndoHandlet   _uhandlet   _parser(   R   R<   t   parserRN   (    (    s…   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Phd.pyR   ‘   s    c         C   s¢   g  } xT |  j  j ƒ  } | s" Pn  | rL | d  d k rL |  j  j | ƒ Pn  | j | ƒ q	 W| sg d  Sd j | ƒ } |  j d  k	 rž |  j j t j	 | ƒ ƒ S| S(   Ni   R   R   (
   RR   t   readlinet   savelineR:   R   R;   RS   RJ   RK   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/Phd.pyt   next   s    c         C   s   t  |  j d ƒ S(   s+   Iterate over the PHY file record by record.N(   t   iterRZ   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/Phd.pyt   __iter__±   s    N(   R   R   R   R   R   RZ   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/Phd.pyRM   Š   s   	t   RecordParserc           B   s    e  Z d  Z d „  Z d „  Z RS(   s7   Parses PHD file data into a Record object (DEPRECATED).c         C   s8   d d  l  } | j d t ƒ t ƒ  |  _ t ƒ  |  _ d  S(   Niÿÿÿÿs”   Bio.Sequencing.Phd.RecordParser is deprecated. Please use Bio.Sequencing.Phd.read(handle) instead of Bio.Sequencing.Phd.RecordParser().parse(handle)(   RN   RO   RP   t   _Scannert   _scannert   _RecordConsumert	   _consumer(   R   RN   (    (    s…   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Phd.pyR   ·   s    c         C   sJ   t  | t j ƒ r | } n t j | ƒ } |  j j | |  j ƒ |  j j S(   N(   t
   isinstanceRK   RQ   R_   t   feedRa   RY   (   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/Phd.pyRJ   ½   s
    	(   R   R   R   R   RJ   (    (    (    s…   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Phd.pyR]   µ   s   	R^   c           B   s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s_   Scans a PHD-formatted file (DEPRECATED).
    
    Methods:
    feed - Feed one PHD record.
    c         C   sA   t  | t j ƒ s t d ƒ ‚ | j ƒ  r= |  j | | ƒ n  d S(   s÷   Reads in PDH data from the handle for scanning.

        Feed in PHD data for scanning.  handle is a file-like object
        containing PHD data.  consumer is a Consumer object that will
        receive events as the PHD data is scanned.
        s   handle must be an UndoHandleN(   Rb   RK   RQ   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/Phd.pyRc   Ì   s    	c         C   s>   |  j  | | ƒ |  j | | ƒ |  j | | ƒ | j ƒ  d  S(   N(   t   _scan_begin_sequencet   _scan_commentst	   _scan_dnat   end_sequence(   R   Rd   Rh   (    (    s…   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Phd.pyRg   Ø   s    c         C   s   t  | | j d d ƒd  S(   Nt   startR   (   t   read_and_callt   begin_sequence(   R   Rd   Rh   (    (    s…   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Phd.pyRi   Þ   s    c         C   s·   t  | | j d d ƒt | | j d d ƒt  | | j d d ƒxB x; t D]2 } t | t | | j ƒ  ƒ d | d ƒrL PqL qL WPqE Wt  | | j d d ƒt | | j d d ƒd  S(   Nt   blanki   Rm   R   R!   R    (   t   read_and_call_whilet   noeventRn   R   t   attempt_read_and_callt   getattrR   (   R   Rd   Rh   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/Phd.pyRj   á   s    (c         C   sR   xK | j  ƒ  } t | ƒ s | d k r- q n | d k r= Pn  | j | ƒ q Wd  S(   Ns
   BEGIN_DNA
s   END_DNA
(   RU   t   is_blank_linet   read_dna(   R   Rd   Rh   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/Phd.pyRk   ñ   s    (   R   R   R   Rc   Rg   Ri   Rj   Rk   (    (    (    s…   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Phd.pyR^   Æ   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 RS(   sD   Consumer that converts a PHD record to a Record object (DEPRECATED).c         C   s   d  |  _ d  S(   N(   R   RY   (   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/Phd.pyR   ý   s    c         C   s&   t  ƒ  |  _ | d j ƒ  |  j _ d  S(   Ni   (   R   RY   R4   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/Phd.pyRo      s    c         C   sœ   t  j  d j g  |  j j D] } | d ^ q ƒ t ƒ |  j _ |  j j d d  k	 r˜ |  j j d d } |  j j d d } |  j j | | !|  j _ n  d  S(   NR   i    R/   i   (	   R    R;   RY   R   R   R   R   R   R   (   R   RG   RA   RB   (    (    s…   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Phd.pyRl     s
    >c         C   s!   | d d !j  ƒ  |  j j d <d  S(   Ni   iÿÿÿÿR"   (   R6   RY   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/Phd.pyR"     s    c         C   s'   t  | d d !j ƒ  ƒ |  j j d <d  S(   Ni   iÿÿÿÿR*   (   R8   R6   RY   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/Phd.pyR*     s    c         C   s!   | d d !j  ƒ  |  j j d <d  S(   Ni   iÿÿÿÿR#   (   R6   RY   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/Phd.pyR#     s    c         C   s!   | d d !j  ƒ  |  j j d <d  S(   Ni   iÿÿÿÿR$   (   R6   RY   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/Phd.pyR$     s    c         C   s'   t  | d d !j ƒ  ƒ |  j j d <d  S(   Ni   iÿÿÿÿR+   (   R8   R6   RY   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/Phd.pyR+     s    c         C   s!   | d d !j  ƒ  |  j j d <d  S(   Ni   iÿÿÿÿR'   (   R6   RY   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/Phd.pyR'     s    c         C   s'   t  | d d !j ƒ  ƒ |  j j d <d  S(   Ni   iÿÿÿÿR,   (   R8   R6   RY   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/Phd.pyR,     s    c         C   s'   t  | d d !j ƒ  ƒ |  j j d <d  S(   Ni   iÿÿÿÿR-   (   R8   R6   RY   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/Phd.pyR-      s    c         C   sK   | d d !j  ƒ  \ } } } t | ƒ t | ƒ t | ƒ f |  j j d <d  S(   Ni   iÿÿÿÿR/   (   R7   R8   R9   RY   R   (   R   R=   RA   RB   RC   (    (    s…   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Phd.pyR/   #  s    c         C   s'   t  | d d !j ƒ  ƒ |  j j d <d  S(   Ni   iÿÿÿÿR.   (   R9   R6   RY   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/Phd.pyR.   '  s    c         C   s!   | d d !j  ƒ  |  j j d <d  S(   Ni   iÿÿÿÿR%   (   R6   RY   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/Phd.pyR%   *  s    c         C   s!   | d d !j  ƒ  |  j j d <d  S(   Ni   iÿÿÿÿR&   (   R6   RY   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/Phd.pyR&   -  s    c         C   s5   | j  ƒ  \ } } } |  j j j | | | f ƒ d  S(   N(   R7   RY   R   R:   (   R   R=   RD   RE   RF   (    (    s…   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Phd.pyRv   0  s    (   R   R   R   R   Ro   Rl   R"   R*   R#   R$   R+   R'   R,   R-   R/   R.   R%   R&   Rv   (    (    (    s…   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Sequencing/Phd.pyR`   û   s"   															t   __main__s   Quick self tests   ../../Tests/Phd/phd1t   DoneN(    (    (    (   R   t   BioR    t   Bio.AlphabetR   R   R   RH   RJ   RK   t   Bio.ParserSupportRM   t   AbstractParserR]   R^   t   AbstractConsumerR`   R   t   openR<   t   recordsR>   R   t   lenR   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/Phd.pyt   <module>   s,   	M	
+59
