U
    md                     @   s  d Z ddlmZmZ ddlmZmZmZmZm	Z	 ddl
Z
ddlZddlZddlZddlmZ ddlZddlmZmZmZmZmZmZmZ ddlmZ dd	lmZ dd
lmZ ddl m!Z!m"Z" ddl#m$Z% dddddhZ&ddddddddhe&B Z'ddddddde"feee(f eed  ee( ee( ee( e)ee( e)eed de!f ed
ddZdfee(ef ee( e)ee( ed!d"d#Z*ddd$d%d&Z+e,e
j-d'd(d)Z.dd*d+d,Z/dgd-dd dd.ee(ef ee( e(e(ee) eee(ef  ed/d0d1Z0d2d de"d fdd3eee(f ed4 e)e)eed de!f e)e(ed5d6d7Z1d2d de"fd8d3d9d:Z2d2d de"fd8d3d;d<Z3dhee(ef eeed>  eed  ee4 d?d@dAZ5dieee(f e)ee(ee4e6e)e(df f dBdCdDZ7eee(f dEdFdGZ8djedHdIdJZ9ee(ef e(dKdLdMZ:ee(e;ee	f edNdOdPZ<e(e6dQdRdSZ=e(e)dQdTdUZ>e(ee)e)f dQdVdWZ?e(ee4e6e)e(df dQdXdYZ@dZd[ ZAdked\d]d^ZBe(ed_d`daZCdldbdcZDdmedHdddeZEdS )nzReading and Writing
    )PathPurePath)UnionDictOptionalTupleBinaryION)imread)AnnDataread_csv	read_text
read_excelread_mtx	read_loomread_hdf)read   )settings)Literal)Empty_empty)loggingcsvtsvtabdatatxtanndataxlsxh5h5admtxmtx.gzsoft.gzloomF)rzr+)gzipZlzf)
filenamebackedsheetext	delimiterfirst_column_names
backup_urlcachecache_compressionreturnc	                 K   s~   t | } t| r2t| f||||||||d|	S t| }
tj|
d tj  } |  srtd|
d| dt	 dt
| |dS )a      Read file and return :class:`~anndata.AnnData` object.

    To speed up reading, consider passing ``cache=True``, which creates an hdf5
    cache file.

    Parameters
    ----------
    filename
        If the filename has no file extension, it is interpreted as a key for
        generating a filename via ``sc.settings.writedir / (filename +
        sc.settings.file_format_data)``.  This is the same behavior as in
        ``sc.read(filename, ...)``.
    backed
        If ``'r'``, load :class:`~anndata.AnnData` in ``backed`` mode instead
        of fully loading it into memory (`memory` mode). If you want to modify
        backed attributes of the AnnData object, you need to choose ``'r+'``.
    sheet
        Name of sheet/table in hdf5 or Excel file.
    ext
        Extension that indicates the file type. If ``None``, uses extension of
        filename.
    delimiter
        Delimiter that separates data within text file. If ``None``, will split at
        arbitrary number of white spaces, which is different from enforcing
        splitting at any single white space ``' '``.
    first_column_names
        Assume the first column stores row names. This is only necessary if
        these are not strings: strings in the first column are automatically
        assumed to be row names.
    backup_url
        Retrieve the file from an URL if not present on disk.
    cache
        If `False`, read from source, if `True`, read from fast 'h5ad' cache.
    cache_compression
        See the h5py :ref:`dataset_compression`.
        (Default: `settings.cache_compression`)
    kwargs
        Parameters passed to :func:`~anndata.read_loom`.

    Returns
    -------
    An :class:`~anndata.AnnData` object
    )r(   r)   r*   r+   r,   r-   r.   r/   .zReading with filekey z failed, the inferred filename zx does not exist. If you intended to provide a filename, either use a filename ending on one of the available extensions z or pass the parameter `ext`.r(   )r   is_valid_filename_readstrr   writedirfile_format_dataexists
ValueError
avail_exts	read_h5ad)r'   r(   r)   r*   r+   r,   r-   r.   r/   kwargsZfilekey r=   I/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/scanpy/readwrite.pyr   6   s.    8
r   T)r'   genomegex_onlyr-   r0   c           	   	   C   s   t d|  }t| |d}|s0t d|   tt| d}d|k}W 5 Q R X |rt| |d}|r||jd j	krt
d| d	|  d
t|jd   d|dd|jd |kf }|r|dd|jd dkf }|jr| }nt| ||d}|S )a      Read 10x-Genomics-formatted hdf5 file.

    Parameters
    ----------
    filename
        Path to a 10x hdf5 file.
    genome
        Filter expression to genes within this genome. For legacy 10x h5
        files, this must be provided if the data contains more than one genome.
    gex_only
        Only keep 'Gene Expression' data and ignore other feature types,
        e.g. 'Antibody Capture', 'CRISPR Guide Capture', or 'Custom'
    backup_url
        Retrieve the file from an URL if not present on disk.

    Returns
    -------
    Annotated data matrix, where observations/cells are named by their
    barcode and variables/genes by gene name. Stores the following information:

    :attr:`~anndata.AnnData.X`
        The data matrix is stored
    :attr:`~anndata.AnnData.obs_names`
        Cell names
    :attr:`~anndata.AnnData.var_names`
        Gene names
    :attr:`~anndata.AnnData.var`\ `['gene_ids']`
        Gene IDs
    :attr:`~anndata.AnnData.var`\ `['feature_types']`
        Feature types
    reading r-   ... did not find original file r%   z/matrixstartr?   z-Could not find data corresponding to genome '' in ''. Available genomes are: r1   Nfeature_typesGene Expressionr?   rE   )logginfo$_check_datafile_present_and_downloaddebugh5pyFiler5   _read_v3_10x_h5varvaluesr9   listuniqueZis_viewcopy_read_legacy_10x_h5)	r'   r?   r@   r-   rE   
is_presentfZv3adatar=   r=   r>   read_10x_h5   s(    &$
r[   rJ   c             
   C   s|  t t| d`}z8t| }|sRt|dkrHtd|  d| |d }n"||krttd| d|  d| i }t|||  dd	lm	} |d
 \}}|d }	|d j
t
dkr|d d}	|d |	dd< ||	|d |d f||fd}
t|
t|d tdt|d t|d tdd}tjd|d |W W  5 Q R  S  tk
rl   tdY nX W 5 Q R X dS )zA
    Read hdf5 file from Cell Ranger v2 or earlier versions.
    r%   r   'z' contains more than one genome. For legacy 10x h5 files you must specify the genome if more than one is present. Available genomes are: r   zCould not find genome 'rF   rG   
csr_matrixshaper   int32float32Nindicesindptrr_   barcodes	obs_names
gene_namesgenes)	var_namesgene_idsobsrR    time.File is missing one or more required datasets.)rO   rP   r5   rT   keyslenr9   _collect_datasetsscipy.sparser^   dtypenpviewr
   dictastyperK   rL   KeyError	Exception)r'   r?   rE   rY   childrendsetsr^   MNr   matrixrZ   r=   r=   r>   rW      sJ    
rW   )r~   groupc                 C   s:   |  D ],\}}t|tjr*|d | |< qt| | qd S )Nr=   )items
isinstancerO   ZDatasetrt   )r~   r   kvr=   r=   r>   rt      s    rt   rD   c          
      C   s6  t t| d}zi }t||d  ddlm} |d \}}|d }|d jtdkrz|d d}|d |d	d	< |||d
 |d f||fd}t	|t
|d tdt
|d t|d t|d t|d tdd}	tjd|d |	W W  5 Q R  S  tk
r&   tdY nX W 5 Q R X d	S )z?
    Read hdf5 file from Cell Ranger v3 or later versions.
    r%   r   r   r]   r_   r   r`   ra   Nrb   rc   rd   re   rf   nameidZfeature_typer?   )rj   rk   rH   r?   rl   rn   ro   rq   )rO   rP   r5   rt   ru   r^   rv   rw   rx   r
   ry   rz   rK   rL   r{   r|   )
r'   rE   rY   r~   r^   r   r   r   r   rZ   r=   r=   r>   rQ     s8    
rQ   zfiltered_feature_bc_matrix.h5)
count_file
library_idload_imagessource_image_path)pathr?   r   r   r   r   r0   c             	      sR  t | } t| | |d}t |jd< ddlm} || | ddtj W 5 Q R X |dkrrt dd d	}t |jd |< |rNt| d
 | d | d | d d}|	 D ]F
 stfdddD rtd d qtd dqt |jd | d< dD ]Z}	z,tt||	 d |jd | d |	< W n& tk
rf   td|	 dY nX qt|d  |jd | d<  fdddD |jd | d< tj|d  dd!}
d"d#d$d%d&d'g|
_|
d" |
_|jj|
d(d)|_|jd'd&g  |jd< |jjd"d'd&gd*d+ |dk	rNtt | }t||jd | d d,< |S )-a      Read 10x-Genomics-formatted visum dataset.

    In addition to reading regular 10x output,
    this looks for the `spatial` folder and loads images,
    coordinates and scale factors.
    Based on the `Space Ranger output docs`_.

    See :func:`~scanpy.pl.spatial` for a compatible plotting function.

    .. _Space Ranger output docs: https://support.10xgenomics.com/spatial-gene-expression/software/pipelines/latest/output/overview

    Parameters
    ----------
    path
        Path to directory for visium datafiles.
    genome
        Filter expression to genes within this genome.
    count_file
        Which file in the passed directory to use as the count file. Typically would be one of:
        'filtered_feature_bc_matrix.h5' or 'raw_feature_bc_matrix.h5'.
    library_id
        Identifier for the visium library. Can be modified when concatenating multiple adata objects.
    source_image_path
        Path to the high-resolution tissue image. Path will be included in
        `.uns["spatial"][library_id]["metadata"]["source_image_path"]`.

    Returns
    -------
    Annotated data matrix, where observations/cells are named by their
    barcode and variables/genes by gene name. Stores the following information:

    :attr:`~anndata.AnnData.X`
        The data matrix is stored
    :attr:`~anndata.AnnData.obs_names`
        Cell names
    :attr:`~anndata.AnnData.var_names`
        Gene names
    :attr:`~anndata.AnnData.var`\ `['gene_ids']`
        Gene IDs
    :attr:`~anndata.AnnData.var`\ `['feature_types']`
        Feature types
    :attr:`~anndata.AnnData.uns`\ `['spatial']`
        Dict of spaceranger output files with 'library_id' as key
    :attr:`~anndata.AnnData.uns`\ `['spatial'][library_id]['images']`
        Dict of images (`'hires'` and `'lowres'`)
    :attr:`~anndata.AnnData.uns`\ `['spatial'][library_id]['scalefactors']`
        Scale factors for the spots
    :attr:`~anndata.AnnData.uns`\ `['spatial'][library_id]['metadata']`
        Files metadata: 'chemistry_description', 'software_version', 'source_image_path'
    :attr:`~anndata.AnnData.obsm`\ `['spatial']`
        Spatial spot coordinates, usable as `basis` by :func:`~scanpy.pl.embedding`.
    )r?   Zspatialr   )rP   r%   modeNZlibrary_idsutf-8z!spatial/tissue_positions_list.csvzspatial/scalefactors_json.jsonzspatial/tissue_hires_image.pngzspatial/tissue_lowres_image.png)tissue_positions_filescalefactors_json_filehires_imagelowres_imagec                 3   s   | ]}|t  kV  qd S )N)r5   .0x)rY   r=   r>   	<genexpr>  s     zread_visium.<locals>.<genexpr>)r   r   z6You seem to be missing an image file.
Could not find 'z'.zCould not find 'r\   Zimages)ZhiresZlowresZ_imagez_image'r   Zscalefactorsc                    s:   i | ]2}| kr|t  | tr.t | d n | qS )r   )r   bytesr5   r   r   )attrsr=   r>   
<dictcomp>  s    zread_visium.<locals>.<dictcomp>)Zchemistry_descriptionZsoftware_versionmetadatar   headerZbarcodeZ	in_tissueZ	array_rowZ	array_colZpxl_col_in_fullresZpxl_row_in_fullresleft)howT)columnsZinplacer   )r   r[   ry   ZunsrO   rP   r   r5   poprS   r8   anyrK   warningOSErrorr	   r|   jsonloads
read_bytespdr   r   indexrm   joinZto_numpyZobsmZdropresolve)r   r?   r   r   r   r   rZ   rP   filesresZ	positionsr=   )r   rY   r>   read_visium)  sx    >




r   gene_symbols)prefix)r   rk   )r   rj   make_uniquer.   r/   r@   r   r0   c                C   s   t | } |dkrdn|}| | d  }|r2tnt}|t| |||||d}	|sV|sZ|	S ttdd |	jd }
|	dd|
f  S dS )a      Read 10x-Genomics-formatted mtx directory.

    Parameters
    ----------
    path
        Path to directory for `.mtx` and `.tsv` files,
        e.g. './filtered_gene_bc_matrices/hg19/'.
    var_names
        The variables index.
    make_unique
        Whether to make the variables index unique by appending '-1',
        '-2' etc. or not.
    cache
        If `False`, read from source, if `True`, read from fast 'h5ad' cache.
    cache_compression
        See the h5py :ref:`dataset_compression`.
        (Default: `settings.cache_compression`)
    gex_only
        Only keep 'Gene Expression' data and ignore other feature types,
        e.g. 'Antibody Capture', 'CRISPR Guide Capture', or 'Custom'
    prefix
        Any prefix before `matrix.mtx`, `genes.tsv` and `barcodes.tsv`. For instance,
        if the files are named `patientA_matrix.mtx`, `patientA_genes.tsv` and
        `patientA_barcodes.tsv` the prefix is `patientA_`.
        (Default: no prefix)

    Returns
    -------
    An :class:`~anndata.AnnData` object
    Nrn   	genes.tsv)rj   r   r.   r/   r   c                 S   s   | dkS )NrI   r=   )r   r=   r=   r>   <lambda>      zread_10x_mtx.<locals>.<lambda>rH   )	r   is_file_read_legacy_10x_mtx_read_v3_10x_mtxr5   rT   maprR   rV   )r   rj   r   r.   r/   r@   r   Zgenefile_existsr   rZ   Zgex_rowsr=   r=   r>   read_10x_mtx  s$    )r   rn   c                C   s   t | } t| | d ||dj}tj| | d ddd}|dkr||d j}|rdtjt	|}||_
|d	 j|jd
< n.|d
kr|d	 j|_
|d j|jd< ntdtj| | d ddd	 j|_|S )zF
    Read mex from output from Cell Ranger v2 or earlier versions
    z
matrix.mtxr.   r/   r   N	r   sepr   r   r   rk   4`var_names` needs to be 'gene_symbols' or 'gene_ids'zbarcodes.tsvr   r   r   Tr   r   rS   r   utilsZmake_index_uniqueIndexrj   rR   r9   rg   r   rj   r   r.   r/   r   rZ   ri   r=   r=   r>   r     s&    
 r   c                C   s   t | } t| | d ||dj}tj| | d ddd}|dkr||d j}|rdtjt	|}||_
|d	 j|jd
< n.|d
kr|d	 j|_
|d j|jd< ntd|d j|jd< tj| | d ddd	 j|_|S )zD
    Read mtx from output from Cell Ranger v3 or later versions
    zmatrix.mtx.gzr   zfeatures.tsv.gzNr   r   r   r   r   rk   r      rH   zbarcodes.tsv.gzr   r   r   r=   r=   r>   r     s,    
r   r&   )r   r   r   Znpz)r'   rZ   r*   compressioncompression_optsc                 C   s   t | } t| r@| } t| dd}|dkr.|}q`||kr`tdn | }|dkrRtjn|}t||} |dkrt||  n|j| ||d dS )a      Write :class:`~anndata.AnnData` objects to file.

    Parameters
    ----------
    filename
        If the filename has no file extension, it is interpreted as a key for
        generating a filename via `sc.settings.writedir / (filename +
        sc.settings.file_format_data)`. This is the same behavior as in
        :func:`~scanpy.read`.
    adata
        Annotated data matrix.
    ext
        File extension from wich to infer file format. If `None`, defaults to
        `sc.settings.file_format_data`.
    compression
        See http://docs.h5py.org/en/latest/high/dataset.html.
    compression_opts
        See http://docs.h5py.org/en/latest/high/dataset.html.
    T
return_extNzxIt suffices to provide the file type by providing a proper extension to the filename.One of "txt", "csv", "h5" or "npz".r   )r   r   )r   r3   r9   r   r7   _get_filename_from_keyZ
write_csvswrite)r'   rZ   r*   r   r   Zext_keyr=   r=   r>   r   B  s(    
  r   )r'   asheaderr0   c                 C   s   t | } ddlm} |g }t| D ]^}d|kr$|r>|dr$|drT|dd n|}|d\}}| }| }t|||< q$|S )a      Read parameter dictionary from text file.

    Assumes that parameters are specified in the format::

        par1 = value1
        par2 = value2

    Comments that start with '#' are allowed.

    Parameters
    ----------
    filename
        Filename of data file.
    asheader
        Read the dictionary from the header (comment section) of a file.

    Returns
    -------
    Dictionary that stores parameters.
    r   )OrderedDict=#r   N)r5   collectionsr   open
startswithsplitstripconvert_string)r'   r   r   paramsliner   valr=   r=   r>   read_paramsz  s    r   )r   c              	   O   s   t | } | j s | jjdd t|dkr8|d |d< | dZ}| D ]J\}}|dk	rn|d| d | D ]\}}|| d	| d
 qvqLW 5 Q R X dS )zc    Write parameters to file, so that it's readable by read_params.

    Uses INI file format.
    Tparentsr   r   Nw[z]
z = 
)r   parentis_dirmkdirrs   r   r   r   )r   argsmapsrY   r   r   r   r   r=   r=   r>   write_params  s    
r   )r'   c
                 K   sB  |d k	r |t kr tdt  nt| dd}t| |d}|sLtd|   |dkr|d krht| |dS td| d	|   t| |S tj	t
| d
| d }|jdkr|d}|r| rtd|  t|S |std|  d
td|   |s|	std |dks(|dkrH|d kr<tdn
t| |}n|dkr\t| }n|dkrtt| |d}nx|dkr|dkrtd td t| ||}nB|dkrt| }n.|dkrtf d| i|
}ntd| d
|r>td tj d! |tkrtj}|j s0|jjdd" |j||d# |S )$Nz0Please provide one of the available extensions.
Tr   rB   rC   >   r    r   r2   zreading sheet z from file r1   z.h5ad>   .gz.bz2rn   z... reading from cache file zDid not find file rA   zlThis might be very slow. Consider passing `cache=True`, which enables much faster reading from a cache file.r   Zxlsz5Provide `sheet` parameter when reading '.xlsx' files.>   r"   r!   r   )r,   >   r   r   r   r   r   zA... assuming '.data' means tab or white-space separated text filez'change this by passing `ext` to sc.readr#   r$   r'   zUnknown extension z... writing an z( cache file to speedup reading next timer   )r   )r:   r9   r3   rM   rK   rN   r;   r   r   Zcachedir_slugifyreplacesuffixwith_suffixr   rL   FileNotFoundErrorhintr   r   r   r   _read_softgzr   r7   r   r/   r   r   r   r   )r'   r(   r)   r*   r+   r,   r-   r.   r/   Zsuppress_cache_warningr<   rX   Z
path_cacherZ   r=   r=   r>   r4     sv    
 













r4   )r   r0   c                 C   s   t | tst| } t| j}|d dkr4|d n4t|d dkrh|d dd dkrh|d d |d< d|}d|kst||dd drt||S )	zMake a path into a filename.r   /   r   Nz:\-:)	r   r   rT   partsr   rs   r   AssertionErrorr   )r   r   r'   r=   r=   r>   r     s    

$
r   )r'   r0   c              	      s|  ddl }|j| dd"}i |D ]p}|dr6 qq"|drT|dd  }q"|d	r"|dd d
}dd |D }|D ]}||< qq"|  ddd tD }fdd|D fddD }g g  }	}
|D ]J}|dr  q6|d  fdd|D }|
| |	 d  qW 5 Q R X t	|
j
}
tjd|id}tj|	d}t|
|||
jdS )a-      Read a SOFT format data file.

    The SOFT format is documented here
    http://www.ncbi.nlm.nih.gov/geo/info/soft2.html.

    Notes
    -----
    The function is based on a script by Kerby Shedden.
    http://dept.stat.lsa.umich.edu/~kshedden/Python-Workshop/gene_expression_comparison.html
    r   Nrtr   z!dataset_table_beginz!subset_descriptionr   r   z!subset_sample_id,c                 S   s   g | ]}|  qS r=   )r   r   r=   r=   r>   
<listcomp>5  s     z _read_softgz.<locals>.<listcomp>r   c                 S   s   g | ]\}}| d r|qS )ZGSM)r   )r   ir   r=   r=   r>   r   ;  s     
 c                    s   g | ]} | qS r=   r=   r   r   )sample_namesr=   r>   r   =  s     c                    s   g | ]} | qS r=   r=   r   )samples_infor=   r>   r   ?  s     z!dataset_table_endc                    s   g | ]}t  | qS r=   )floatr   )Vr=   r>   r   K  s     groups)r   )Xrm   rR   rv   )r&   r   r   r   r   readline	enumerateappendrw   arrayr   r   Z	DataFramer
   rv   )r'   r&   filer   Zsubset_descriptionZ
subset_idsr   rb   r   rh   r   r   rm   rR   r=   )r   r   r   r>   r     s:    





r   )stringr0   c                 C   s*   zt |  W dS  tk
r$   Y dS X dS )zCheck whether string is float.

    See also
    --------
    http://stackoverflow.com/questions/736043/checking-if-a-string-can-be-converted-to-float-in-python
    TFN)r   r9   r  r=   r=   r>   is_float[  s
    r  c                 C   s*   zt |  W dS  tk
r$   Y dS X dS )z Check whether string is integer.TFN)intr9   r  r=   r=   r>   is_inti  s
    r
  c                 C   s    | dkrdS | dkrdS dS dS )z Check whether string is boolean.True)TTFalse)TF)FFNr=   r  r=   r=   r>   convert_boolr  s
    r  c                 C   sL   t | rt| S t| r t| S t| d r8t| d S | dkrDdS | S dS )z%Convert string to int, float or bool.r   r   NoneN)r
  r	  r  r   r  r  r=   r=   r>   r   |  s    r   c               	   C   sj   ddl } dd |  D }g }|D ]>}z"| }|D ]}||j q4W q" | jk
r^   Y q"X q"t|S )z-Get files used by processes with name scanpy.r   Nc                 s   s   | ]}|  d kr|V  qdS )ZscanpyN)r   )r   procr=   r=   r>   r     s     z!get_used_files.<locals>.<genexpr>)psutilZprocess_iterZ
open_filesr  r   ZNoSuchProcessset)r  Zloop_over_scanpy_processes	filenamesr  flistntr=   r=   r>   get_used_files  s    r  )r0   c                 C   s&   |d krt jn|}t j|  d|  S )Nr1   )r   r7   r6   )r   r*   r=   r=   r>   r     s    r   )urlr   c                 C   s  zdd l }ddlm} W n  tk
r8   ddlm} Y nX ddlm}m} ddlm} d}d}z|| ddid}	z||	}
W nJ |k
r   t	
d	 dd
lm} ddlm} ||	|| dd}
Y nX |
}| dd }|dddd|d kr|nt|dZ}|dD}||}|rN|| |d7 }|t| ||}qW 5 Q R X W 5 Q R X W 5 Q R X W n. ttfk
r   | r|   Y nX d S )Nr   )tqdm)urlopenRequest)URLErrori    z
User-agentzscanpy-user)headerszFFailed to open the url with default certificates, trying with certifi.)where)create_default_context)cafile)contextzcontent-lengthBTr   i   )unitZ
unit_scaleZminitersZunit_divisortotalwb)
ipywidgetsZ	tqdm.autor  ImportErrorurllib.requestr  r  urllib.errorr  rK   r   certifir  sslr  rL   getr	  r   r   r   updaters   KeyboardInterruptr|   r   unlink)r  r   r$  r  r  r  r  	blocksizeblocknumreqZopen_urlr  r  respr"  trY   blockr=   r=   r>   	_download  sV     

0
r4  c                 C   sl   t | } |  rdS |dkr dS td| d | j s^td| j d | jjdd t||  dS )	z6Check whether the file is present, otherwise download.TNFztry downloading from url
z0
... this may take a while but only happens oncezcreating directory z/ for saving datar   )r   r   rK   rL   r   r   r   r4  )r   r-   r=   r=   r>   rM     s    


rM   c                 C   s  | j }t|dkr>td| d|dd  d |dd }t|dkr|d dd tkr|d dd d	kr|r|d dd S d
S |r|d dd tkr|r|d dd S d
S d|dkr|rdS d
S d|dkr|rdS d
S |sdS t| dt ddS )z)Check whether the argument is a filename.r   z,Your filename has more than two extensions: z!.
Only considering the two last: Nr1   r   r   )gzbz2Trn   z.soft.gzr#   z.mtx.gzr"   FzU does not end on a valid extension.
Please, provide one of the available extensions.
z<
Text files with .gz and .bz2 extensions are also supported.)suffixesrs   rK   r   	text_extsr:   r   r9   )r'   r   r*   r=   r=   r>   r3     s*    4r3   )NTN)N)Nr&   N)F)	NNNNNNFNF)N)N)F)F__doc__pathlibr   r   typingr   r   r   r   r   rO   r   numpyrw   Zpandasr   Zmatplotlib.imager	   r   r
   r   r   r   r   r   r   r   r;   Z	_settingsr   Z_compatr   _utilsr   r   rn   r   rK   r:  r:   r5   boolr[   rW   ry   Grouprt   rQ   r   r   r   r   r	  r   r   r   r   r4   r   r   r   r  r
  r  r   r  r   r4  rM   r3   r=   r=   r=   r>   <module>   s.  $		

V   
>5& 
 
@$(   


9 
 '         T?	
3
