U
    f                     @   s   d dl Zd dlZd dlZd dlmZmZ ejej	e
d Zeje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 tD } | S )z,
    Return list of available matrices.
    c                 S   s,   g | ]$}d |krd |ddd qS )z.txt.N)joinsplit.0name r   =/tmp/pip-target-lpfmz8o1/lib/python/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 tD } | S )z.
    Return list of available data files.
    c                 S   s8   g | ]0}t |d dkrt |d d dkr|qS )r      r   )lenr   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dd |D f  tt|tdt|  dt| f }tj	|sht
d| |rtd|   t|d	.}| }d
d |D }d|}t| W 5 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.
    3Matrix "%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>3type(print_description) = %s; must be of type bool z	%s/%s.txtFile %s does not exist!#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   S   s        	r   r#   )sepZ	index_colcomment)r   r   r   
isinstancebooltyper   r   pathisfileAssertionErrorprintopen	readlinespdZread_csv)r
   print_descriptionr   	file_nameflinesdescriptionr   r   r   get_example_matrix(   s*    

r:   c              	   C   s   t  }t| |kd| ddd |D f  tt|tdt|  dt| f }tj	|sht
d| |rtd|   t|d	.}| }d
d |D }d|}t| W 5 Q R X t|dkr|dd dkrt|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
    r   r   c                 S   s   g | ]}t |qS r   r   r   r   r   r   r   v   s     z)open_example_datafile.<locals>.<listcomp>r   z%s/%sr   r    r!   c                 S   s(   g | ] }t |d kr|d  dkr|qS r"   r$   r%   r   r   r   r      s       r'      Nz.gz)r   r   r   r+   r,   r-   r   r   r.   r/   r0   r1   r2   r3   r   gzip)r
   r5   r   r6   r7   r8   r9   r   r   r   open_example_datafile[   s0    


r>   )NT)NT)Zpandasr4   r   r=   Zlogomaker.src.error_handlingr   r   r.   dirnameabspath__file__r   r   r   r   r:   r>   r   r   r   r   <module>   s"   

2