3
?\                 @   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d Zedd Zedd
dZedddZdS )    N)checkhandle_errorsz/../examples/matricesz/../examples/datafilesc              C   s   dd t jtD } | S )z,
    Return list of available matrices.
    c             S   s,   g | ]$}d |krdj |jddd qS )z.txt.N   )joinsplit).0name r   ../../logomaker/src/examples.py
<listcomp>   s    z)list_example_matrices.<locals>.<listcomp>)oslistdir
matrix_dir)valid_matricesr   r   r   list_example_matrices   s    r   c              C   s   dd t jtD } | S )z.
    Return list of available data files.
    c             S   s8   g | ]0}t |jd dkrt |jd d dkr|qS )r      r   )lenr   )r	   r
   r   r   r   r       s    z*list_example_datafiles.<locals>.<listcomp>)r   r   data_dir)valid_datafilesr   r   r   list_example_datafiles   s    r   Tc             C   s   t  }t| |kd| djdd |D f  dt| f }tjj|sPtd| |rtd|   t	|d.}|j
 }d	d |D }d
j|}t| W dQ R X tj|ddddS )a`  
    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.
    z3Matrix "%s" not recognized. Please choose from: 
%s
c             S   s   g | ]}t |qS r   )repr)r	   xr   r   r   r   C   s    z&get_example_matrix.<locals>.<listcomp>z	%s/%s.txtzFile %s does not exist!z#Description of example matrix "%s":rc             S   s(   g | ] }t |d kr|d  dkr|qS )r   #)r   )r	   lr   r   r   r   N   s     N	r   r   )sep	index_colcomment)r   r   r   r   r   pathisfileAssertionErrorprintopen	readlinespdread_csv)r
   print_descriptionr   	file_nameflinesdescriptionr   r   r   get_example_matrix(   s    
r0   c          
   C   s   t  }t| |kd| djdd |D f  dt| f }tjj|sPtd| |rtd|   t	|d.}|j
 }d	d |D }d
j|}t| W dQ R X t|dkr|dd dkrtj	|d}n
t	|d}|S )aG  
    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
    z3Matrix "%s" not recognized. Please choose from: 
%sr   c             S   s   g | ]}t |qS r   )r   )r	   r   r   r   r   r   q   s    z)open_example_datafile.<locals>.<listcomp>z%s/%szFile %s does not exist!z#Description of example matrix "%s":r   c             S   s(   g | ] }t |d kr|d  dkr|qS )r   r   )r   )r	   r   r   r   r   r   |   s    r   N   z.gz)r   r   r   r   r   r#   r$   r%   r&   r'   r(   r   gzip)r
   r+   r   r,   r-   r.   r/   r   r   r   open_example_datafileV   s"    

r4   )NT)NT)pandasr)   r   r3   logomaker.src.error_handlingr   r   r#   dirnameabspath__file__r   r   r   r   r0   r4   r   r   r   r   <module>   s   -