ó
¤>dc           @   sn   d  Z  d d l Z d d l Z d d l m Z d d l m Z d e f d „  ƒ  YZ	 d e f d „  ƒ  YZ
 d S(	   s:    Helper class for getting information about a fast5 file.
iÿÿÿÿN(   t   version(   t   _cleant   ReadInfoc           B   s   e  Z d  Z d d d „ Z RS(   s6    This object provides basic details about a read.
    i    g      ð¿c         C   sU   | |  _  | |  _ t |  _ | |  _ t |  _ d |  _ | |  _ | |  _ | |  _	 d S(   s¹   Constructs an object describing a read.
        
        :param read_number: A read number, unique for the channel.
        :param read_id: A globally unique read id.
        :param start_time: The start time of the read (in samples).
        :param duration: The duration of the read (in samples).
        :param mux: The mux of the channel when the read occurred.
        :param median_before: The median current before the read.
        i    N(
   t   read_numbert   read_idt   Falset   has_raw_datat   durationt   has_event_datat   event_data_countt
   start_timet	   start_muxt   median_before(   t   selfR   R   R
   R   t   muxR   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_info.pyt   __init__   s    								(   t   __name__t
   __module__t   __doc__R   (    (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_info.pyR      s   t	   Fast5Infoc           B   s    e  Z d  Z d „  Z d „  Z RS(   s<   This object provides some basic details about a read fast5 file.
    
    **Fields**
      * **valid:** Indicates whether the fast5 file is valid or not.
      * **version:** Indicates the version of the read fast5 file
        specification the file conforms to (if any).
      * **read_info:** A list of ReadInfo objects. One entry for each read.
      * **read_number_map:** A dictionary giving the index into the read_info
        list for each read number.
      * **read_id_map:** A dictionary giving the index into the read_info
        list for each read-id.
    c         C   sÂ  t  |  _ d |  _ g  |  _ i  |  _ i  |  _ yKt j | d ƒ 3} d | j	 k r¦ t
 | j	 d ƒ |  _ t j d ƒ } t j t |  j ƒ ƒ | k  r¸ t |  _ q¸ n t |  _ d |  _ | j ƒ  } d | k rã | d j ƒ  } n  d | k r|  j ƒ  rt |  _ n  d | k r t |  _ n  | d j	 j d	 ƒ |  _ |  j d k r`|  j ƒ  r`t |  _ n  d
 | k rû| d j ƒ  } x”| D]q} d j | ƒ } | | }	 |	 j	 }
 t
 |
 d ƒ } d |
 k rÚt
 |
 d ƒ } n* |  j ƒ  sòt |  _ n t j j | ƒ } t
 |
 d ƒ } t
 |
 d ƒ } t
 |
 j d d ƒ ƒ } t
 |
 j d d ƒ ƒ } t | | | | | | ƒ } d |	 k r‡t  | _ n0 |  j ƒ  r·d |	 k r«t  | _ q·t |  _ n  |  j j | ƒ t |  j ƒ d } | |  j | <| |  j | <qƒWn |  j ƒ  st |  _ n  d | k r5t | d j ƒ  ƒ n g  } x3| d d d … D]} | j d ƒ rOd j | ƒ } | | k r…qOn  | | j ƒ  } xÑ| D]É} d j | | ƒ } | | }	 |	 j	 }
 t
 |
 d ƒ } d |
 k röt
 |
 d ƒ } n- |  j ƒ  st |  _ qœn t j j | ƒ } t
 |
 d ƒ } t
 |
 d ƒ } t
 |
 j d d ƒ ƒ } t
 |
 j d d ƒ ƒ } t | | | | | | ƒ } d |	 k r¹t  | _ t |	 d ƒ | _ n t | _ d | _ | |  j k r|  j | } | j |  j | _ | j |  j | _ qœ|  j ƒ  s(t |  _ n  |  j j | ƒ t |  j ƒ d } | |  j | <| |  j | <qœWPqOqOWWd QXWn t |  _ ‚  n X|  j ƒ  r¾t |  j ƒ d k r¾t |  _ q¾n  d S(   st    Constructs a status object from a file.

        :param fname: Filename of fast5 file to read status from.
        t   rt   file_versions   0.6g        t   UniqueGlobalKeyt   tracking_idt
   channel_ids   UniqueGlobalKey/channel_idt   channel_numbert   Raws	   Raw/Readss   Raw/Reads/{}R   R   R
   R   R   i    R   g      ð¿t   Signalt   Datai   t   AnalysesNiÿÿÿÿt   EventDetections   Analyses/{}/Readss   {}/{}t   Events(    t   Truet   validt   Nonet   channelt	   read_infot   read_number_mapt   read_id_mapt   h5pyt   Filet   attrsR   R    t   packaging_versiont   Versiont   parset   strR   t   keyst   _legacy_versiont   gett   formatt   ost   patht   basenameR   R   t   appendt   lent   sortedt
   startswithR   R	   (   R   t   fnamet   handlet   minimum_valid_versiont
   top_groupst   global_keyst   readst   readt   read_group_namet
   read_groupt
   read_attrsR   R   R
   R   R   R   R$   t   nt   analysest   anat   reads_group_namet
   read_index(    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_info.pyR   3   sÆ    								
	(
						c         C   s+   t  j d ƒ } t  j t |  j ƒ ƒ | k  S(   Ns   1.1(   R*   R+   R,   R-   R    (   R   t   legacy_cutoff(    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_info.pyR/   ¬   s    (   R   R   R   R   R/   (    (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_info.pyR   %   s   	y(   R   R2   R'   t	   packagingR    R*   t   ont_fast5_api.data_sanitisationR   t   objectR   R   (    (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_info.pyt   <module>   s   