Install Palantir via pip
masterYou can install Palantir directly using pip for Python 3 environments.
pip install palantirrepository·master·Indexed 43 days ago
https://github.com/dpeerlab/palantirPalantir is an algorithm for aligning cells along differentiation trajectories in multidimensional single-cell data, such as Mass cytometry and single-cell RNA-seq. It models differentiation as a stochastic process through a low-dimensional phenotypic manifold. Version 1.4.5 provides compatibility with Python 3.12/3.13, pandas 2/3, and AnnData >= 0.11. The package includes optional GAM support for computing gene expression trends.
You can install Palantir directly using pip for Python 3 environments.
pip install palantirPalantir is available through the bioconda and conda-forge channels. Use the following commands depending on your package manager:
Using conda:
conda install -c conda-forge -c bioconda palantirUsing mamba:
mamba install -c conda-forge -c bioconda palantirUsing micromamba:
micromamba install -c conda-forge -c bioconda palantirTo learn how to use Palantir and visualize results for single cell RNA-seq data, refer to the following resources:
Palantir allows for optional installation of pygam for computing gene expression trends. You can install the full suite of features using the [gam] or [full] extras.
pip install palantir[gam]
# OR
pip install palantir[full]pip install palantir[gam]Version 1.4.5 introduced several critical compatibility fixes and changes:
ValueError: assignment destination is read-only errors in run_palantir and select_branch_cells caused by pandas 3's mandatory Copy-on-Write.TypeError in cluster_gene_trends for anndata >= 0.11 by casting arrays with .astype(np.float32) instead of using the removed dtype keyword in AnnData.__init__.numpy.random.Generator instead of the legacy numpy.random.RandomState. Requires numpy >= 1.17.PCG64 instead of Mersenne Twister, so numerical outputs will differ from previous versions. For exact reproducibility, pin to a prior version.Palantir is an algorithm designed to align cells along differentiation trajectories, identify differentiation endpoints, and estimate cell-fate probabilities in single-cell data. The package is organized into the following functional modules:
config: Configuration settings for Palantir.core: Core functions for running the Palantir algorithm.presults: Class for storing and accessing Palantir results.io: Input/output functions for loading and saving data.preprocess: Preprocessing functions for single-cell data.utils: Utility functions for analysis.plot: Visualization functions.After running sc.tl.dpt, the following information is added to the AnnData object:
ad.obs['dpt_pseudotime']. This represents the progression of cells along the diffusion trajectories.ad.obs['dpt_groups']. This identifies which lineage or branch a cell belongs to.You can use these columns to color embeddings like t-SNE (ad.obsm['X_tsne']) to visualize developmental trajectories and lineage splits.
The Palantir manuscript provides three replicates of human_cd34_bm data in .h5ad format. You can access these using scanpy in Python. Each object contains processed counts, raw counts, MAGIC-imputed data, t-SNE maps, clustering information, and Palantir-specific outputs like pseudotime, differentiation potential, and branch probabilities.
import scanpy as sc
# Read in the data, with backup URLs provided
adata_Rep1 = sc.read(
"../data/human_cd34_bm_rep1.h5ad",
backup_url="https://s3.amazonaws.com/dp-lab-data-public/palantir/human_cd34_bm_rep1.h5ad",
)
adata_Rep2 = sc.read(
"../data/human_cd34_bm_rep2.h5ad",
backup_url="https://s3.amazonaws.com/dp-lab-data-public/palantir/human_cd34_bm_rep2.h5ad",
)
adata_Rep3 = sc.read(
"../data/human_cd34_bm_rep3.h5ad",
backup_url="https://s3.amazonaws.com/dp-lab-data-public/palantir/human_cd34_bm_rep3.h5ad",
)You can extract and visualize how specific genes change along defined developmental paths (lineages).
sc.pl.paga_path with return_data=True to retrieve the underlying trend data for a specific path.# Example: Extracting trend data for a path
# path = (description, [list_of_cluster_indices])
paths = [('Ery', [0, 5, 4]), ('Mono', [0, 3, 8, 9])]
trends = pd.Series()
for ipath, (descr, path) in enumerate(paths):
_, data = sc.pl.paga_path(
ad,
path,
genes,
groups_key='dpt_groups',
return_data=True,
show=False
)
trends[descr] = data
# Now 'trends[descr]' contains the distance and gene expression dataTo use FateID results within the Palantir ecosystem, you must export your single-cell data to a CSV format compatible with the FateID R script, run the R analysis, and then load the exported results back into Python.
RaceID and FateID R packages to perform clustering and compute fate biases.probs.csv (fate probabilities), tsne.csv (dimensionality reduction coordinates), and *_order.csv (pseudo-time ordering for each cell type) files into Python using pandas.# Exporting data for FateID
import os
import pandas as pd
fateid_dir = 'fateid/'
os.makedirs(fateid_dir, exist_ok=True)
# Extract counts from AnnData
counts = pd.DataFrame(ad.raw.X.todense(), index=ad.obs_names, columns=ad.var_names)
# Transpose and save to CSV
pd.DataFrame(counts.T).to_csv(f'{fateid_dir}/counts.csv')This notebook demonstrates how to compare Palantir results with Monocle 2 by exporting data from an AnnData object, running a Monocle 2 R wrapper, and visualizing the resulting trajectories and gene expressions.
AnnData object and identify boundary clusters and gene subsets.counts.csv) and a list of ordering genes (genes.csv) to a directory.monocle_wrapper.R) via Rscript to perform dimensionality reduction (DDRTree) and cell ordering.phenodata.csv and red_dims.csv back into Python to plot states and gene expression across the trajectory.To use Slingshot, you must export Palantir's multi-scale data, cluster assignments, and gene expression matrices to a directory. The Slingshot R script expects three specific CSV files:
data.csv: The multi-scale data (from ms_data).clusters.csv: Cluster assignments from ad.obs['clusters'].exprs.csv: Gene expression matrix where rows are genes and columns are cell names.Note: Ensure the directory exists before exporting.
# Export data
slignshot_dir = 'slingshot/'
os.makedirs(slignshot_dir, exist_ok=True)
# Genes
# Expression matrices
pd.DataFrame(ms_data).to_csv(f'{slignshot_dir}/data.csv', index=None, header=None)
pd.DataFrame(ad.obs['clusters']).to_csv(f'{slignshot_dir}/clusters.csv', index=None, header=None)
pd.DataFrame(ad[:, genes].X.T, index=genes, columns=ad.obs_names).to_csv(f'{slignshot_dir}/exprs.csv')