ó
jÜxec           @   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;   /tmp/pip-install-l3LICk/logomaker/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;   /tmp/pip-install-l3LICk/logomaker/logomaker/src/examples.pyt   list_example_datafiles   s
    +c   	   	   C   s>  t  ƒ  } t |  | k d |  d j g  | D] } t | ƒ ^ q( ƒ f ƒ t t | t ƒ d t | ƒ ƒ d t |  f } t j	 j
 | ƒ sš 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   
s3   type(print_description) = %s; must be of type bool 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   reprt
   isinstancet   boolt   typeR   R   t   patht   isfilet   AssertionErrort   opent	   readlinesR   t   pdt   read_csv(	   R   t   print_descriptionR	   t   xt	   file_namet   ft   linest   lt   description(    (    s;   /tmp/pip-install-l3LICk/logomaker/logomaker/src/examples.pyt   get_example_matrix(   s"    	0"	;c   	   	   C   si  t  ƒ  } t |  | k d |  d j g  | D] } t | ƒ ^ q( ƒ f ƒ t t | t ƒ d t | ƒ ƒ d t |  f } t j	 j
 | ƒ sš 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 rV| d d k rV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   
s3   type(print_description) = %s; must be of type bool 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   R   R   R   t   gzip(	   R   R    R   R!   R"   R#   R$   R%   R&   (    (    s;   /tmp/pip-install-l3LICk/logomaker/logomaker/src/examples.pyt   open_example_datafile[   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;   /tmp/pip-install-l3LICk/logomaker/logomaker/src/examples.pyt   <module>   s   2