PHATE (Potential of Heat-diffusion for Affinity-based Trajectory Embedding)

repository·main·Indexed 20 days ago

https://github.com/krishnaswamylab/phate

A dimensionality reduction tool designed to visualize high-dimensional biological data by preserving both local and global structures to reveal transitions and manifolds. PHATE provides implementations for Python, R (via phateR), and MATLAB, supporting data types such as numpy arrays, scipy sparse matrices, pandas DataFrames, and AnnData.

Tokens
9.5K
Snippets
39
Records
52
Agent score
68%

What's inside PHATE

  1. Install phateR for R

    main

    Using PHATE in R requires the Python phate package to be installed first.

    Option 1: Standard Installation

    1. Install the Python package via terminal:
      pip install --user phate
    2. Install phateR from CRAN in R:
      install.packages("phateR")

    Option 2: Development Installation (using devtools and reticulate) This installs the development version directly from GitHub:

    if (!suppressWarnings(require(devtools))) install.packages("devtools")
    reticulate::py_install("phate", pip=TRUE)
    devtools::install_github("KrishnaswamyLab/phateR")
  2. Quick Start with PHATE in Python

    main

    To perform PHATE dimensionality reduction on a dataset in Python, initialize a phate.PHATE() operator and call fit_transform(data).

    Input Data Requirements:

    • The data matrix should have cells (observations) on rows and genes (features) on columns.
    • Supported data types: numpy.array, scipy.spmatrix, pandas.DataFrame, and anndata.AnnData.
    import phate
    phate_op = phate.PHATE()
    data_phate = phate_op.fit_transform(data)
  3. Install PHATE from source (Python)

    main

    To install the Python version from the GitHub repository, clone the repository recursively and run the setup script.

    git clone --recursive git://github.com/KrishnaswamyLab/PHATE.git
    cd PHATE/Python
    python setup.py install --user
  4. Run PHATE on a dataset using the Python API

    main

    To perform PHATE dimensionality reduction, instantiate a phate.PHATE operator, then use the fit_transform method on your input data. You can adjust parameters using set_params. After fitting, you can use transform() to project data into a different number of components (e.g., moving from 2D to 3D).

    import phate
    import scprep
    
    # Generate or load your data
    tree_data, tree_clusters = phate.tree.gen_dla()
    
    # Initialize the PHATE operator
    # k: number of neighbors
    # t: diffusion time
    phate_operator = phate.PHATE(k=15, t=100)
    
    # Fit and transform the data to 2D
    tree_phate = phate_operator.fit_transform(tree_data)
    scprep.plot.scatter2d(tree_phate, c=tree_clusters)
    
    # Change dimensionality to 3D
    phate_operator.set_params(n_components=3)
    tree_phate = phate_operator.transform()
    scprep.plot.rotate_scatter3d(tree_phate, c=tree_clusters)