
:>"^                 @   s   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 Gd d   d e  Z d d   Z d d   Z	 d S)aR  Parser for PHD files output by PHRED and used by PHRAP and CONSED.

This module can be 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.
    )Seq)generic_dnaZCHROMAT_FILEZABI_THUMBPRINTZPHRED_VERSIONZCALL_METHODZQUALITY_LEVELSZTIMEZTRACE_ARRAY_MIN_INDEXZTRACE_ARRAY_MAX_INDEXZTRIMZTRACE_PEAK_AREA_RATIOZCHEMZDYEc               @   s"   e  Z d  Z d Z d d   Z d S)Recordz!Hold information from a PHD file.c             C   sU   d |  _  i  |  _ x! t D] } d |  j | j   <q Wg  |  _ d |  _ d |  _ d S)zInitialize the class. N)	file_namecomments	CKEYWORDSlowersitesseqseq_trimmed)selfkw r   7/tmp/pip-build-ww9dw3qa/biopython/Bio/Sequencing/Phd.py__init__)   s    				zRecord.__init__N)__name__
__module____qualname____doc__r   r   r   r   r   r   &   s   r   c       	   
   C   s  xD |  D]8 } | j  d  r t   } | d d  j   | _ Pq Wd Sx* |  D] } | j  d  rN PqN Wt d   x|  D]} | j   } | s q{ | d k r P| j d d  \ } } | j   } | j   } | d# k r | | j | <q{ | d$ k rt	 |  | j | <q{ | d k r3t
 |  | j | <q{ | d k r{ | j   \ } } } t	 |  t	 |  t
 |  f | j | <q{ Wt d   x* |  D] } | j  d  rPqWt d   xd |  D]\ } | j  d  rPq| j   } t |  d% k r| j j t |   qt d   qWx* |  D] } | j  d  r'Pq'Wt d   t j d  j d! d"   | j D  t  | _ | j d d k	 r| j d d d  \ } } | j | |  | _ | S)&zRead the next PHD record from the file, return it as a Record object.

    This function reads PHD file data line by line from the handle,
    and returns a single Record object.
    ZBEGIN_SEQUENCE   NZBEGIN_COMMENTz!Failed to find BEGIN_COMMENT lineZEND_COMMENT:   chromat_filephred_versioncall_methodchemdyetimebasecaller_versiontrace_processor_versionabi_thumbprintquality_levelstrace_array_min_indextrace_array_max_indexZtrace_peak_area_ratioZtrimzFailed to find END_COMMENT lineZ	BEGIN_DNAzFailed to find BEGIN_DNA lineZEND_DNA      zODNA line must contain a base and quality score, and optionally a peak location.ZEND_SEQUENCEz Failed to find END_SEQUENCE liner   c             s   s   |  ] } | d  Vq d S)r   Nr   ).0nr   r   r   	<genexpr>   s    zread.<locals>.<genexpr>)r   r   r   r   r   ztimer   r    )r!   r"   r#   r$   )r%   r&   )
startswithr   rstripr   
ValueErrorstripsplitr	   r   intfloatlenr
   appendtupler   joinr   r   r   )	handlelinerecordkeywordvaluefirstlastZprobpartsr   r   r   read4   s|    	       	   	,.r=   c             c   s&   x t  |   } | s d S| Vq Wd S)a  Iterate over a file yielding 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)r=   )r5   r7   r   r   r   parse   s
    r>   N)
r   ZBior   ZBio.Alphabetr   r   objectr   r=   r>   r   r   r   r   <module>   s"   	[