ó
į?Æ\c           @   sĘ   d  d l  Z d  d l Z d  d l Z d  d l m Z m Z e j j e j j	 e
   d Z e j j e j j	 e
   d Z e d    Z e d    Z e d e d   Z e d e d   Z d S(	   iĸĸĸĸN(   t   checkt   handle_errorss   /../examples/matricess   /../examples/datafilesc          C   sH   g  t  j t  D]. }  d |  k r d j |  j d  d   ^ q } | S(   s,   
    Return list of available matrices.
    s   .txtt   .iĸĸĸĸ(   t   ost   listdirt
   matrix_dirt   joint   split(   t   namet   valid_matrices(    (    s   ../../logomaker/src/examples.pyt   list_example_matrices   s    Ac          C   s`   g  t  j t  D]F }  t |  j d   d k r t |  j d  d  d k r |  ^ q } | S(   s.   
    Return list of available data files.
    R   i   i    (   R   R   t   data_dirt   lenR   (   R   t   valid_datafiles(    (    s   ../../logomaker/src/examples.pyt   list_example_datafiles   s
    +c   	   	   C   s  t    } t |  | k d |  d j g  | D] } t |  ^ q(  f  d t |  f } t j j |  sz t d |   | rĸ d |  GHt	 | d  b } | j
   } g  | D]. } t |  d k rŪ | d d k rŪ | ^ qŪ } d	 j |  } | GHWd
 QXn  t j | d d d d d d S(   s`  
    Returns an example matrix from which a logo can be made.

    parameters
    ----------

    name: (None or str)
        Name of example matrix.

    print_description: (bool)
        If true, a description of the example matrix will be printed

    returns
    -------

    df: (data frame)
        A data frame containing an example matrix.
    s3   Matrix "%s" not recognized. Please choose from: 
%ss   
s	   %s/%s.txts   File %s does not exist!s#   Description of example matrix "%s":t   ri    t   #t    Nt   seps   	t	   index_colt   comment(   R
   R    R   t   reprR   R   t   patht   isfilet   AssertionErrort   opent	   readlinesR   t   pdt   read_csv(	   R   t   print_descriptionR	   t   xt	   file_namet   ft   linest   lt   description(    (    s   ../../logomaker/src/examples.pyt   get_example_matrix(   s    	0"	;c   	   	   C   sI  t    } t |  | k d |  d j g  | D] } t |  ^ q(  f  d t |  f } t j j |  sz t d |   | rĸ d |  GHt	 | d  b } | j
   } g  | D]. } t |  d k rŪ | d d k rŪ | ^ qŪ } d	 j |  } | GHWd
 QXn  t |  d k r6| d d k r6t j	 | d  } n t	 | d  } | S(   sG  
    Returns a file handle to an example dataset

    parameters
    ----------

    name: (None or str)
        Name of example matrix.

    print_description: (bool)
        If true, a description of the example matrix will be printed

    returns
    -------

    f: (file handle)
        A handle to the requested file
    s3   Matrix "%s" not recognized. Please choose from: 
%ss   
s   %s/%ss   File %s does not exist!s#   Description of example matrix "%s":R   i    R   R   Ni   iýĸĸĸs   .gz(   R   R    R   R   R   R   R   R   R   R   R   R   t   gzip(	   R   R   R   R   R   R    R!   R"   R#   (    (    s   ../../logomaker/src/examples.pyt   open_example_datafileV   s"    	0"	;"(   t   pandasR   R   R%   t   logomaker.src.error_handlingR    R   R   t   dirnamet   abspatht   __file__R   R   R
   R   t   Nonet   TrueR$   R&   (    (    (    s   ../../logomaker/src/examples.pyt   <module>   s   -