U
    ÅmœdÓ  ã                   @   s    d Z ddlmZmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ deeeeeeeef eeeee	d ee eeeedf eee dœdd„ZdS )z(Embed high-dimensional data using PHATE
é    )ÚOptionalÚUnion)ÚAnnDataé   )Úsettings)ÚLiteral)Úlogging)Ú	AnyRandomé   é   é   éÐ  Úautoç      ð?éd   Ú	euclideanÚmetricNF)Zclassicr   Z	nonmetric)ÚadataÚn_componentsÚkÚaÚ
n_landmarkÚtÚgammaÚn_pcaÚknn_distÚmds_distÚmdsÚn_jobsÚrandom_stateÚverboseÚcopyÚreturnc                 K   sÖ   t  d¡}|r|  ¡ n| } |dkr(tjn|}t|tƒr:|n|dk}|dkrPtjn|}zddl}W n t	k
r|   t	dƒ‚Y nX |j
f |||||||||	|
|||dœ|—Ž | ¡}|| jd< t jd|d	d
� |rÒ| S dS )uV      PHATE [Moon17]_.

    Potential of Heat-diffusion for Affinity-based Trajectory Embedding (PHATE)
    embeds high dimensional single-cell data into two or three dimensions for
    visualization of biological progressions.

    For more information and access to the object-oriented interface, read the
    `PHATE documentation <https://phate.readthedocs.io/>`__.  For
    tutorials, bug reports, and R/MATLAB implementations, visit the `PHATE
    GitHub page <https://github.com/KrishnaswamyLab/PHATE/>`__. For help
    using PHATE, go `here <https://krishnaswamylab.org/get-help>`__.

    Parameters
    ----------
    adata
        Annotated data matrix.
    n_components
        number of dimensions in which the data will be embedded
    k
        number of nearest neighbors on which to build kernel
    a
        sets decay rate of kernel tails.
        If None, alpha decaying kernel is not used
    n_landmark
        number of landmarks to use in fast PHATE
    t
        power to which the diffusion operator is powered
        sets the level of diffusion. If 'auto', t is selected
        according to the knee point in the Von Neumann Entropy of
        the diffusion operator
    gamma
        Informational distance constant between -1 and 1.
        `gamma=1` gives the PHATE log potential, `gamma=0` gives
        a square root potential.
    n_pca
        Number of principal components to use for calculating
        neighborhoods. For extremely large datasets, using
        n_pca < 20 allows neighborhoods to be calculated in
        log(n_samples) time.
    knn_dist
        recommended values: 'euclidean' and 'cosine'
        Any metric from `scipy.spatial.distance` can be used
        distance metric for building kNN graph
    mds_dist
        recommended values: 'euclidean' and 'cosine'
        Any metric from `scipy.spatial.distance` can be used
        distance metric for MDS
    mds
        Selects which MDS algorithm is used for dimensionality reduction.
    n_jobs
        The number of jobs to use for the computation.
        If `None`, `sc.settings.n_jobs` is used.
        If -1 all CPUs are used. If 1 is given, no parallel computing code is
        used at all, which is useful for debugging.
        For n_jobs below -1, (n_cpus + 1 + n_jobs) are used. Thus for
        n_jobs = -2, all CPUs but one are used
    random_state
        Random seed. Defaults to the global `numpy` random number generator
    verbose
        If `True` or an `int`/`Verbosity` â‰¥ 2/`hint`, print status messages.
        If `None`, `sc.settings.verbosity` is used.
    copy
        Return a copy instead of writing to `adata`.
    kwargs
        Additional arguments to `phate.PHATE`

    Returns
    -------
    Depending on `copy`, returns or updates `adata` with the following fields.

    **X_phate** : `np.ndarray`, (`adata.obs`, shape=[n_samples, n_components], dtype `float`)
        PHATE coordinates of data.

    Examples
    --------
    >>> from anndata import AnnData
    >>> import scanpy.external as sce
    >>> import phate
    >>> tree_data, tree_clusters = phate.tree.gen_dla(
    ...     n_dim=100,
    ...     n_branch=20,
    ...     branch_length=100,
    ... )
    >>> tree_data.shape
    (2000, 100)
    >>> adata = AnnData(tree_data)
    >>> sce.tl.phate(adata, k=5, a=20, t=150)
    >>> adata.obsm['X_phate'].shape
    (2000, 2)
    >>> sce.pl.phate(adata)
    zcomputing PHATENr
   r   z]You need to install the package `phate`: please run `pip install --user phate` in a terminal.)r   r   r   r   r   r   r   r   r   r   r   r   r    ÚX_phatez    finishedz3added
    'X_phate', PHATE coordinates (adata.obsm))ÚtimeÚdeep)ÚloggÚinfor!   r   Ú	verbosityÚ
isinstanceÚboolr   ÚphateÚImportErrorZPHATEZfit_transformZobsm)r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   ÚkwargsÚstartr(   r+   r#   © r/   úR/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/scanpy/external/tl/_phate.pyr+      sJ    n
ÿ
óòñ
ýr+   )r
   r   r   r   r   r   r   r   r   r   NNNF)Ú__doc__Útypingr   r   Zanndatar   Z	_settingsr   Z_compatr   Ú r   r&   Ú_utilsr	   ÚintÚstrÚfloatr*   r+   r/   r/   r/   r0   Ú<module>   sL                 ñ
ï