ó
¤>dc           @   s­   d  d l  m Z d  d l Z d  d l Z d  d l m Z d  d l m Z m	 Z	 m
 Z
 d  d l m Z m Z m Z d  d l m Z d d d „  ƒ  YZ d	 e f d
 „  ƒ  YZ d S(   iÿÿÿÿ(   t   ConfigParserN(   t   deque(   t   VBZt   raise_missing_vbz_error_readt   raise_missing_vbz_error_write(   t   _sanitize_data_for_readingt   _sanitize_data_for_writingt   _clean(   t   LEGACY_COMPONENT_NAMESt   AbstractFast5c           B   s_   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z e d „  ƒ Z d „  Z	 d „  Z
 d „  Z RS(	   c         C   s   |  S(   N(    (   t   self(    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt	   __enter__   s    c         C   s   |  j  ƒ  t S(   N(   t   closet   False(   R
   t   exception_typet   exception_valuet	   traceback(    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt   __exit__   s    
c         C   s   t  ƒ  ‚ d  S(   N(   t   NotImplementedError(   R
   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt	   get_reads   s    c         C   s   t  ƒ  ‚ d  S(   N(   R   (   R
   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt   get_read_ids   s    c         C   s   t  ƒ  ‚ d  S(   N(   R   (   R
   t   read_id(    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt   get_read   s    c         C   s   t  |  j ƒ d k S(   Nu   <Closed HDF5 file>(   t   reprt   handle(   R
   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt   _is_open   s    c         C   s(   |  j  s$ t d j |  j ƒ ƒ ‚ n  d  S(   Ns   Fast5 file is not open: {}(   R   t   IOErrort   formatt   filename(   R
   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt   assert_open!   s    	c         C   s>   |  j  ƒ  |  j d k r: t d j |  j |  j ƒ ƒ ‚ n  d  S(   Nt   rs'   Fast5 file is in read-only mode '{}' {}(   R   t   modeR   R   R   (   R
   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt   assert_writeable%   s    
c         C   sM   |  j  rI d |  _ |  j r4 |  j j ƒ  d |  _ n  d |  _ d |  _ n  d S(   s    Closes the object.
        N(   R   t   NoneR   R   R   R   t   status(   R
   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyR   *   s    				(   t   __name__t
   __module__R   R   R   R   R   t   propertyR   R   R    R   (    (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyR	      s   							t	   Fast5Readc           B   sß  e  Z d  Z d „  Z d „  Z d „  Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z	 e d „  ƒ Z
 d* e d „ Z e d	 „ Z e d
 „ Z d* d „ Z d* d* d* e d „ Z d* d „ Z e d „ Z d „  Z d „  Z d „  Z e d „ Z d „  Z e d „  ƒ Z d „  Z e d „ Z d „  Z d „  Z d „  Z d „  Z  d „  Z! d „  Z" d* d „ Z# e d „ Z$ d „  Z% d* d  „ Z& e d! „ Z' e( d" „  ƒ Z) e( d# „  ƒ Z* d$ „  Z+ d% „  Z, e d& „ Z- d' „  Z. d( „  Z/ d) „  Z0 RS(+   t    c         C   sB   | |  _  | j |  _ | j |  _ | j d | |  _ | |  _ d  S(   Nt   read_(   t   parentR   R   R   R   (   R
   R)   R   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt   __init__9   s
    	c         C   s   t  d ƒ |  j S(   NsN   'read.get_run_id()' will be deprecated. Use the property 'read.run_id' instead(   t   DeprecationWarningt   run_id(   R
   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt
   get_run_idA   s    
c         C   s   t  d ƒ |  j S(   NsP   'read.get_read_id()' will be deprecated. Use the property 'read.read_id' instead(   R+   R   (   R
   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt   get_read_idE   s    
c         C   s   |  j  d S(   Ns   /Signal(   t   raw_dataset_group_name(   R
   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt   raw_dataset_nameI   s    c         C   s   d S(   Nt   Raw(    (   R
   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyR/   M   s    c         C   s   |  j  |  j j S(   N(   R   R0   t   _filters(   R
   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt   raw_compression_filtersQ   s    c         C   s   |  j  |  j d j d S(   Nt   tracking_idR,   (   R   t
   global_keyt   attrs(   R
   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyR,   U   s    c         C   sç   |  j  ƒ  |  j |  j k r2 |  j j |  j ƒ n  |  j |  j k rk d } t | j |  j |  j ƒ ƒ ‚ n  y0 |  j |  j j	 d d | d d t
 | ƒ Wn t k
 rº } t | ƒ n X| d k	 rã |  j |  j | d t ƒn  d S(   sÀ    Add raw data for a read.

        :param data: The raw data DAQ values (16 bit integers).

        The read must already exist in the file. It must not already
        have raw data.
        s4   Fast5 file already has raw data for read '{}' in: {}t   Signalt   datat   dtypet   i2t   clearN(   R    R/   R   t   create_groupR0   t   KeyErrorR   R   R   t   create_datasett   varst
   ValueErrorR   R!   t   _add_attributest   True(   R
   R8   R6   t   compressiont   msgt   e(    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt   add_raw_dataY   s    
!c         C   sC   |  j  ƒ  d |  j k r, |  j j d ƒ n  |  j d | | ƒ d S(   s   Add channel info data to the channel_id group.

        :param data: A dictionary of key/value pairs. Keys must be strings.
            Values can be strings or numeric values.
        :param clear: If set, any existing channel info data will be removed.
        t
   channel_idN(   R    R   R<   RA   (   R
   R6   R;   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt   add_channel_infop   s    
c         C   s@   |  j  ƒ  d |  j k r, |  j j d ƒ n  |  j | | ƒ d  S(   NR4   (   R    R   R<   t   set_tracking_id(   R
   R6   R;   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt   add_tracking_id|   s    
c         C   s»   |  j  ƒ  d |  j k r, |  j j d ƒ n  d j | ƒ } d j | ƒ } | j ƒ  } | | d <|  j | | ƒ |  j | j d ƒ |  j | j d ƒ | d k	 r· |  j | | ƒ n  d S(   sh   Add a new analysis group to the file.

        :param component: The component name.
        :param group_name: The name to use for the group. Must not already
            exist in the file e.g. 'Test_000'.
        :param attrs: A dictionary containing the key-value pairs to
            put in the analysis group as attributes. Keys must be strings,
            and values must be strings or numeric types.
        :param config: A dictionary of dictionaries. The top level keys
            should be the name of analysis steps, and should contain
            key value pairs for analysis parameters used.
        t   Analysess   Analyses/{}s   {}/Configurationt	   componentt   Summaryt   ConfigurationN(   R    R   R<   R   t   copyt
   _add_groupR!   t   _add_attribute_tree(   R
   RL   t
   group_nameR6   t   configt   groupt	   cfg_groupt   group_attrs(    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt   add_analysis‚   s    

c         C   s/   | r t  j d ƒ n  |  j |  j | | | ƒ S(   Ns*   Read number is not used for MultiReadFast5(   t   warningst   warnt	   _load_rawR0   (   R
   t   read_numbert   startt   endt   scale(    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt   get_raw_dataœ   s    c         C   sä   |  j  ƒ  g  } d |  j k r# | S|  j d j ƒ  } x§ | D]Ÿ } |  j d j | ƒ j } d | k r{ t | d ƒ } n' | d  t k rœ t | d  } n d } | d k	 r= | d k sÆ | | k r= | j | | f ƒ q= q= W| S(   sö    Provides a list of all analyses groups.

        :param component: Optional component name. If provided, only
            analyses of that component will be returned.
        :returns: A list of component-name/group-name pairs (tuples).
        RK   s   Analyses/{}RL   iüÿÿÿN(	   R   R   t   keysR   R6   R   R   R!   t   append(   R
   RL   t   analysest
   ana_groupsRR   RV   t   comp(    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt   list_analyses¡   s    
$c         C   sÛ   |  j  ƒ  |  j ƒ  } g  } x6 | D]. } | d d  | k r# | j | d ƒ q# q# Wt | ƒ d k r‰ d	 } | r… d j | ƒ } n  | St | ƒ d } | r× t | d ƒ d } d j | t | ƒ j	 d ƒ ƒ } n  | S(
   sL   Return the latest analysis group with the specified
            base name.

        :param group_base: The name of the analysis group, excluding
            the _### at the end e.g. 'Alignment' rather than 'Alignment_000'
        :param increment: If set, this will find the name of the latest
            analysis group, increment the index by 1, and return
            the results. If there aren't any, it will give an index
            of 000.
        :returns: The group name with the highest index, or None if
            there are no analyses with the specified base name.
        i   iüÿÿÿi    s   {}_000iÿÿÿÿiýÿÿÿs   {}_{}i   N(
   R   Re   Ra   t   lenR!   R   t   sortedt   intt   strt   zfill(   R
   t
   group_baset	   incrementt   all_analysest   selectedt   analysist   resultt   count(    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt   get_latest_analysisº   s     
$c         C   sf   |  j  ƒ  xE | j ƒ  D]7 \ } } | j d ƒ sD d j | ƒ } n  | | | <q W|  j | | ƒ d S(   sã  
        Adds the component chain to ``group_name`` in the fast5.
        These are added as attributes to the group.

        :param group_name: The group name you wish to add chaining data to,
            e.g. ``Test_000``
        :param component_map: The set of components and corresponding
            group names or group paths that contribute data to the analysis.
            If group names are provided, these will be converted into group
            paths.

            If ``Test_000`` uses data from the results of
            ``first_component`` stored at ``Analyses/First_000/``
            the component_map could be ``{'first_component': 'First_000'}`` or
            ``{'first_component': 'Analyses/First_000'}``.

        s	   Analyses/s   Analyses/{}N(   R    t   itemst
   startswithR   t   add_analysis_attributes(   R
   RR   t   component_mapRL   t   path(    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt	   add_chainØ   s    
c         C   s<  |  j  ƒ  d j | ƒ } |  j | j } d | k rB | d } n t | d  } t ƒ  } | j | | f ƒ t ƒ  } | j | ƒ x­ t | ƒ d k r1| j ƒ  } |  j | j } xx | j	 ƒ  D]j \ } }	 t
 |	 ƒ j d ƒ rÀ | |	 d f }
 |
 | k r| j |
 ƒ n  | j |
 ƒ | j |	 ƒ qÀ qÀ Wq… Wt | ƒ S(   sG   Provides the component and group names for an analysis chain.

        :param group_name: The group name of the last step in the analysis
            chain e.g. 'Basecall_1D_000'
        :returns: A list of component-name/group-name pairs (tuples). This
            will include each component of the chain, in order.
        s   Analyses/{}RL   iüÿÿÿi    s	   Analyses/i	   (   R   R   R   R6   R   R   Ra   Rf   t   popleftRs   Ri   Rt   t   removet   list(   R
   RR   t   endgroupt   attrRL   t   chaint   groups_to_checkRT   t   keyt   valuet   chain_entry(    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt	   get_chainó   s*    
		c         C   s;   |  j  ƒ  |  j |  j d j j ƒ  } d „  | Dƒ } | S(   s>    Returns a dictionary of tracking-id key/value pairs.
        R4   c         S   s%   i  |  ] \ } } t  | ƒ | “ q S(    (   R   (   t   .0R€   R   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pys
   <dictcomp>  s   	 (   R   R   R5   R6   Rs   (   R
   t   tracking(    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt   get_tracking_id  s    
c         C   s(   |  j  ƒ  |  j |  j d | | ƒ d S(   s   Add tracking-id data to the tracking_id group.

        :param data: A dictionary of key/value pairs. Keys must be strings.
            Values can be strings or numeric values.
        :param clear: If set, any existing tracking-id data will be removed. 
        R4   N(   R    RA   R5   (   R
   R8   R;   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyRI     s    
c         C   sO   |  j  ƒ  |  j |  j d j j ƒ  } d „  | Dƒ } t | d ƒ | d <| S(   sF    Returns a dictionary of channel information key/value pairs.
        RG   c         S   s%   i  |  ] \ } } t  | ƒ | “ q S(    (   R   (   R„   R€   R   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pys
   <dictcomp>,  s   	 t   channel_number(   R   R   R5   R6   Rs   Rh   (   R
   t   channel_info(    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt   get_channel_info'  s
    
c         C   s   d |  j  k S(   Nt   context_tags(   R   (   R
   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt   has_context_tags0  s    c         C   sB   |  j  ƒ  |  j r> |  j |  j d j j ƒ  } d „  | Dƒ Si  S(   s>    Returns a dictionary of context tag key/value pairs.
        RŠ   c         S   s%   i  |  ] \ } } t  | ƒ | “ q S(    (   R   (   R„   R€   R   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pys
   <dictcomp>:  s   	 (   R   R‹   R   R5   R6   Rs   (   R
   t   tags(    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt   get_context_tags4  s
    
	c         C   sK   |  j  ƒ  |  j r0 |  j |  j d | | ƒ n |  j |  j d | ƒ d S(   s   Replaces any existing context tag data with the provided values.

        :param data: A dictionary of key/value pairs. Keys must be strings.
            Values can be strings or numeric values.
        :param clear: If set, any existing context tag data will be removed. 
        RŠ   N(   R    R‹   RA   R5   RP   (   R
   R8   R;   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt   add_context_tags=  s    
	c         C   s   t  d ƒ ‚ d  S(   Ns[   Cannot add_existing_read() to a Fast5Read(). Use MultiFast5File.create_empty_read() instead(   R   (   R
   R[   R   t
   start_timet   durationt   muxt   median_before(    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt   add_readJ  s    c         C   sV   |  j  ƒ  | |  j k r, |  j | i  ƒ n  t | ƒ } |  j | j | d | ƒd S(   sí    Add a log the file.
        :param group_name: Global group name. Cave: No 'Analyses' is prepended.
        :param field_name: A field {group_name}/{field_name} will be written.
        :param log_string: content to be written.
        R8   N(   R    R   RP   R   R>   (   R
   RR   t
   field_namet
   log_stringt   sanitized_data(    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt   add_logN  s
    
c         C   s0   |  j  ƒ  d j | | ƒ } |  j | | ƒ d S(   sg   Set the summary data for an analysis group.

        :param group_name: The name of the analysis group.
        :param section_name: The analysis step. This will become a
            subfolder in the Summary section.
        :param data: A dictionary containing keys which are the summary
            fields, and values which are the summary values.
        s   Analyses/{}/Summary/{}N(   R    R   RP   (   R
   RR   t   section_nameR8   RT   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt   set_summary_dataZ  s    	
c         C   sè   |  j  ƒ  d j | ƒ |  j k rF d } t | j | |  j ƒ ƒ ‚ n  t | t ƒ r’ i  } xg | j ƒ  D]# } d „  | j | ƒ Dƒ | | <qh Wn3 t | t	 ƒ rª | } n t
 d j t | ƒ ƒ ƒ ‚ d j | ƒ } |  j | | ƒ d S(   s@   Set Configuration data for analysis group.  The ``config`` can
            be passed as a dict of dicts e.g. ``{'section': {'key': 'value'}}``
            or can be passed directly as a ConfigParser object.

        :param group_name: The name of the analysis group e.g. Example_000
        :param config: Representation of configuration as ConfigParser or
            dict of dicts.
        :raises KeyError: if group_name does not exist in fast5 or
            fast5 is not open for writing
        :raises TypeError: if ``config`` is not ConfigParser or dict obj.
        s   Analyses/{}s@   Dataset cannot be added to non-existent group: Analyses/{} in {}c         S   s   i  |  ] \ } } | | “ q S(    (    (   R„   t   kt   v(    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pys
   <dictcomp>z  s   	 s,   config must be a ConfigParser or dict not {}s   Analyses/{}/ConfigurationN(   R    R   R   R=   R   t
   isinstanceR    t   sectionsRs   t   dictt	   TypeErrort   typeRQ   (   R
   RR   RS   RD   t   config_dictt   sectiont   config_path(    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt   set_analysis_configg  s    
$	c         C   sD   |  j  ƒ  d j | ƒ } d } | |  j k r@ |  j | ƒ } n  | S(   sx   Gets any config data saved for the analysis.

        :param group_name: The name of the analysis group.
        :returns: A dictionary of dictionaries. Each key represents
            an analysis step. Each value is a dictionary containing the
            analysis parameters as key/value pairs. Returns None if no
            configuration exists for the analysis.
        s   Analyses/{}/ConfigurationN(   R   R   R!   R   t   _parse_attribute_tree(   R
   RR   RT   RS   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt   get_analysis_configƒ  s    	
c         C   sD   |  j  ƒ  d j | ƒ } d } | |  j k r@ |  j | ƒ } n  | S(   s?   Get the summary data for an analysis group.

        :param group_name: The name of the analysis group to pull summary
            data for.
        :returns: A dictionary whose keys are analysis steps, and whose
            values are dictionaries of key/value pairs for the results of
            that step.
        s   Analyses/{}/SummaryN(   R   R   R!   R   R¥   (   R
   RR   RT   t   summary(    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt   get_summary_data“  s    	
c         C   s0   |  j  ƒ  d j | | ƒ } |  j | | ƒ d S(   s   Add a new subgroup to an existing analysis group.

        :param group_name: The name of the analysis group you are adding to.
        :param subgroup_name: The name of the new subgroup.
        :param attrs: A dictionary representing the attributes to assign to
            the subgroup.

        The new subgroup must not already exist.

        The subgroup name can be a nested name, such as "Template/Data". This
        will create the "Template" subgroup (if it does not exist), and the
        "Data" subgroup below it.
        s   Analyses/{}/{}N(   R    R   RP   (   R
   RR   t   subgroup_nameR6   RT   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt   add_analysis_subgroup£  s    
c         C   s0   |  j  ƒ  d j | ƒ } |  j | | | ƒ d S(   s   Add attributes on the group or dataset specified.

        :param group_name: The name of the group (or dataset).
        :param attrs: A dictionary representing the attributes to add.
        :param clear: If set, any existing attributes will be cleared.

        The specified group name can be any existing path (relative to the
        "Analyses" group. It can be a group or a dataset.
        s   Analyses/{}N(   R    R   RA   (   R
   RR   R6   R;   RT   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyRu   µ  s    

c         C   s[   |  j  ƒ  d j | ƒ } d } | |  j k rW |  j | j j ƒ  } d „  | Dƒ } n  | S(   sõ    Returns the attributes for the specified group or dataset.

        :param group_name: The path of the group or dataset, relative to the
            "Analyses" group.
        :returns: A dictionary representing the attributes (if any).
        s   Analyses/{}c         S   s%   i  |  ] \ } } t  | ƒ | “ q S(    (   R   (   R„   R€   R   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pys
   <dictcomp>Ï  s   	 N(   R   R   R!   R   R6   Rs   (   R
   RR   RT   R}   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt   get_analysis_attributesÃ  s    
c   	      C   sß   |  j  ƒ  d j | ƒ } | |  j k rL d } t | j | |  j ƒ ƒ ‚ n  t | ƒ } t j | ƒ d k rŠ |  j | j | d | ƒn  |  j | j | d | d d ƒ| d k	 rÛ d j | | ƒ } |  j
 | | ƒ n  d S(	   sö   Add a dataset to the specified group.

        :param group_name: The path of the group the dataset will be added to,
            relative to the "Analyses" group.
        :param dataset_name: The name of the new dataset.
        :param data: A numpy array representing the data to be written.
        :param attrs: A dictionary of attributes to be added to the dataset.
        :raises KeyError: If dataset is being added to non-existant group or
            if file is not open for writing.
        s   Analyses/{}s@   Dataset cannot be added to non-existent group: Analyses/{} in {}R8   RC   t   gzips   {}/{}N(    (   R    R   R   R=   R   R   t   npt   shapeR>   R!   RA   (	   R
   RR   t   dataset_nameR8   R6   t
   group_pathRD   R–   Rw   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt   add_analysis_datasetÒ  s    

c         C   sZ   |  j  ƒ  d j | | ƒ } d } | |  j k rV |  j | } | sV t | ƒ } qV n  | S(   s   Return the specified dataset, as a numpy array.

        :param group_name: The path of the group containing the dataset,
            relative to the "Analyses" group.
        :param dataset_name: The name of the dataset.
        :param skip_decoding: If True, this will directly return the h5py dataset.
            If False, it will load the data into a Numpy array and decode any byte-strings
        :return: A numpy array containing the data. Returns None if the dataset
            does not exist.
        s   Analyses/{}/{}N(   R   R   R!   R   R   (   R
   RR   R¯   t   skip_decodingR8   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt   get_analysis_datasetï  s    
c         C   s   t  d ƒ ‚ d  S(   Ns;   read_summary_data() is not implemented for MultiFast5 reads(   R   (   t   fnameRL   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt   read_summary_data  s    c         C   s   t  d ƒ ‚ d  S(   Ns.   Cannot update legacy file for a MultiFast5Read(   R   (   R´   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt   update_legacy_file  s    c         C   s¤   y |  j  | | | !} Wn t k
 r7 } t | ƒ n X| r  |  j  |  j d j } | d } | d }	 | d }
 |	 | } t j | | |
 d t j ƒ} n  | S(   NRG   t   digitisationt   ranget   offsetR9   (   R   t   OSErrorR   R5   R6   R­   t   arrayt   float32(   R
   R¯   R\   R]   R^   t   rawt   errRˆ   t   digit   parangeR¹   t   scaling(    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyRZ     s    



#c         C   s3   |  j  j | ƒ | d k	 r/ |  j | | ƒ n  d S(   sQ   
        :param group: group_name
        :param attrs:
        :return:
        N(   R   R<   R!   RA   (   R
   RT   R6   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyRP     s    c         C   sh   |  j  | } | j } | r= x | j ƒ  D] } | | =q) Wn  x$ | j ƒ  D] \ } } | | | <qJ Wd  S(   N(   R   R6   R`   Rs   (   R
   Rw   R6   R;   t   path_grpt	   path_attrR€   R   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyRA   $  s    	c         C   s    |  j  | } | j } t | ƒ S(   s„   
        :param path: filepath within fast5
        :return: dictionary of attributes found at ``path``
        :rtype dict
        (   R   R6   Rž   (   R
   Rw   RÂ   RÃ   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt   _get_attributes-  s    	c         C   sC   x< | j  ƒ  D]. \ } } d j | | ƒ } |  j | | ƒ q Wd  S(   Ns   {}/{}(   Rs   R   RP   (   R
   RT   RS   t   folderR8   Rw   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyRQ   7  s    c         C   sj   i  } |  j  | j ƒ  } xJ | D]B } d j | | ƒ } |  j  | j j ƒ  } d „  | Dƒ | | <q  W| S(   Ns   {}/{}c         S   s%   i  |  ] \ } } t  | ƒ | “ q S(    (   R   (   R„   R€   R   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pys
   <dictcomp>B  s   	 (   R   R`   R   R6   Rs   (   R
   RT   R8   t   foldersRÅ   Rw   R}   (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyR¥   <  s    N(1   R#   R$   R5   R*   R-   R.   R%   R0   R/   R3   R,   R!   R   RF   R   RH   RJ   RW   R_   Re   Rr   Rx   Rƒ   R†   RI   R‰   R‹   R   RŽ   R“   R—   R™   R¤   R¦   R¨   Rª   Ru   R«   R±   R³   t   staticmethodRµ   R¶   RZ   RP   RA   RÄ   RQ   R¥   (    (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyR&   6   sT   					!														
		
	(    (   t   configparserR    t   numpyR­   RX   t   collectionsR   t"   ont_fast5_api.compression_settingsR   R   R   t   ont_fast5_api.data_sanitisationR   R   R   t   ont_fast5_api.static_dataR   R	   R&   (    (    (    sA   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/fast5_read.pyt   <module>   s   *