# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/71_biol.ipynb.

# %% auto 0
__all__ = ['isfilteredmatrixpath', 'isadatafile', 'isfilteredmatrixdir', 'isfmatdir', 'isfmat', 'issensitivitypath',
           'issensitivitydir', 'issensdir', 'issens']

# %% ../nbs/71_biol.ipynb 4
from pathlib import Path
from typing import TypeGuard

# %% ../nbs/71_biol.ipynb 5
from .atyp import PathLike

# %% ../nbs/71_biol.ipynb 8
def isfilteredmatrixpath(p: PathLike) -> TypeGuard[PathLike]:
    '''Check if the current path is a filtered matrix path'''
    return Path(p).name == 'filtered_matrix'

# %% ../nbs/71_biol.ipynb 9
def isadatapath(p: PathLike) -> TypeGuard[PathLike]:
    '''Check if the current path is an anndatat file path'''
    name = Path(p).name
    return name == 'adata.h5ad' or 'data.h5' in name

def isbarcodespath(p: PathLike) -> TypeGuard[PathLike]:
    '''Check if the current path is a barcodes file path'''
    return Path(p).name == 'barcodes.tsv'

def isfeaturespath(p: PathLike) -> TypeGuard[PathLike]:
    '''Check if the current path is a filtered matrix path'''
    return Path(p).name == 'features.tsv'

def ismatrixpath(p: PathLike) -> TypeGuard[PathLike]:
    '''Check if the current path is a filtered matrix path'''
    return Path(p).name == 'matrix.mtx'

# %% ../nbs/71_biol.ipynb 10
def isbarcodesfile(p: PathLike) -> TypeGuard[PathLike]:
    '''Check if the current path is a barcodes file'''
    return isbarcodespath(p) and Path(p).is_file()

def isfeaturesfile(p: PathLike) -> TypeGuard[PathLike]:
    '''Check if the current path is a features file'''
    return isfeaturespath(p) and Path(p).is_file()

def ismatrixfile(p: PathLike) -> TypeGuard[PathLike]:
    '''Check if the current path is a matrix file'''
    return ismatrixpath(p) and Path(p).is_file()

# %% ../nbs/71_biol.ipynb 11
def isadatafile(p: PathLike) -> TypeGuard[PathLike]:
    '''Check if the current path is an adata file'''
    return isadatapath(p) and Path(p).is_file()

# %% ../nbs/71_biol.ipynb 12
def isfilteredmatrixdir(p: PathLike, checkname: bool = True, checkfiles: bool = False) -> TypeGuard[PathLike]:
    '''Check if the current path is a filtered matrix path

    Parameters
    ----------
    p : PathLike
        Path to check
    checkname : bool, optional
        Check if the path name is `filtered_matrix`, by default True
    checkfiles : bool, optional
        Check if the path contains the required files, by default False
    
    See Also
    --------
    isfmat : Alias for `isfilteredmatrixdir`.
    isfmatdir : Alias for `isfilteredmatrixdir`.
    '''
    p = Path(p)
    isnamedir = isfilteredmatrixpath(p) and p.is_dir()
    has_files = (
        isbarcodespath(p / 'barcodes.tsv') and 
        isfeaturespath(p / 'features.tsv') and 
        ismatrixpath(p / 'matrix.mtx')
    )
    return (checkname and isnamedir) or (checkfiles and has_files)

def isfmatdir(p: PathLike, checkname: bool = True, checkfiles: bool = True) -> TypeGuard[PathLike]:
    '''Check if the current path is a filtered matrix path
    
    Parameters
    ----------
    p : PathLike
        Path to check
    checkname : bool, optional
        Check if the path name is `filtered_matrix`, by default True
    checkfiles : bool, optional
        Check if the path contains the required files, by default False

    See Also
    --------
    isfilteredmatrixdir : Alias for `isfmatdir`.
    '''
    return isfilteredmatrixdir(p, checkname, checkfiles)


def isfmat(p: PathLike, checkname: bool = True, checkfiles: bool = True) -> TypeGuard[PathLike]:
    '''Check if the current path is a filtered matrix path
    
    Parameters
    ----------
    p : PathLike
        Path to check
    checkname : bool, optional
        Check if the path name is `filtered_matrix`, by default True
    checkfiles : bool, optional
        Check if the path contains the required files, by default False

    See Also
    --------
    isfilteredmatrixdir : Alias for `isfmat`.
    '''
    return isfilteredmatrixdir(p, checkname, checkfiles)

# %% ../nbs/71_biol.ipynb 13
def issensitivitypath(p: PathLike) -> TypeGuard[PathLike]:
    '''Check if the current path is a sensitivity path'''
    return Path(p).name.startswith('sensitivity')

def issensitivitydir(
    p: PathLike,
    checkname: bool = True, checkfiles: bool = False, checkparent: bool = False
) -> TypeGuard[PathLike]:
    '''Check if the current path is a sensitivity dir

    Parameters
    ----------
    p : PathLike
        Path to check
    checkname : bool, default=True
        Check if the path name has `sensitivity`, by default True
    checkfiles : bool, default=False
        Check if the path contains the required files, by default False
    checkparent : bool, default=False
        Check if the path parent is `filtered_matrix`, by default False
    
    See Also
    --------
    issens : Alias for `issensitivitydir`.
    issensdir : Alias for `issensitivitydir`.
    '''
    p = Path(p)
    if not (checkfiles and checkparent): checkname = True
    sname = issensitivitypath(p) and p.is_dir()
    files = isfilteredmatrixdir(p, checkname=False, checkfiles=checkfiles)
    fpath = isfilteredmatrixdir(p, checkname=True, checkfiles=False)
    return (checkname and sname) or (checkfiles and files) or (checkparent and fpath)


def issensdir(p: PathLike, checkname: bool = True, checkfiles: bool = False, checkparent: bool = False) -> TypeGuard[PathLike]:
    '''Check if the current path is a sensitivity dir

    Parameters
    ----------
    p : PathLike
        Path to check
    checkname : bool, default=True
        Check if the path name has `sensitivity`, by default True
    checkfiles : bool, default=False
        Check if the path contains the required files, by default False
    checkparent : bool, default=False
        Check if the path parent is `filtered_matrix`, by default False
    
    See Also
    --------
    issensitivitydir : Alias for `issensdir`.
    '''
    return issensitivitydir(p, checkname, checkfiles, checkparent)

def issens(
    p: PathLike,
    checkname: bool = True, checkfiles: bool = False, checkparent: bool = False
) -> TypeGuard[PathLike]:
    '''Check if the current path is a sensitivity dir

    Parameters
    ----------
    p : PathLike
        Path to check
    checkname : bool, default=True
        Check if the path name has `sensitivity`, by default True
    checkfiles : bool, default=False
        Check if the path contains the required files, by default False
    checkparent : bool, default=False
        Check if the path parent is `filtered_matrix`, by default False
    
    See Also
    --------
    issensitivitydir : Alias for `issens`.
    '''
    return issensitivitydir(p, checkname, checkfiles, checkparent)
