Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
daf25be
test io
katosh Nov 28, 2023
f2c892c
simplify readme
katosh Nov 28, 2023
ac36ad3
move manuscript data processing to a notebook
katosh Nov 28, 2023
f4df4e1
remove old reference
katosh Nov 28, 2023
7adcde6
test density functions and multiscale
katosh Nov 29, 2023
cbf4a11
fix determine_multiscale_space test
katosh Nov 29, 2023
fb2aab9
numeric stability and progtess for run_local_variability
katosh Jan 11, 2024
906bddf
fix version reference in readme
katosh Jan 17, 2024
0b3e33c
better error message for highlight_cells_on_umap with string
katosh Apr 4, 2024
e1d810c
update scanpy _color_vector usage
katosh Apr 4, 2024
4b87cfa
update to new scanpy api
katosh Apr 4, 2024
60623e4
close figures in plot testing
katosh Apr 4, 2024
cdb8bcd
update Readme
katosh Apr 4, 2024
629be90
version bump to 1.3.3
katosh Apr 4, 2024
fe7f21d
make sphinx documentation
katosh Apr 4, 2024
5801a16
add readthedocs config
katosh Apr 21, 2024
12e363b
avoid devision by zero (#139)
katosh Apr 22, 2024
fd9ea28
reference readthedocs documentation
katosh Apr 22, 2024
c3c0290
udpate relsease notes of v1.3.3
katosh Apr 22, 2024
3203a45
udpate relsease notes of v1.3.4rc
katosh Apr 22, 2024
b99f4ca
avoid depreication
katosh Apr 22, 2024
a210f63
update plot_stats doc
katosh Apr 22, 2024
61dd6f7
document kwargs for some plotting functions
katosh Apr 22, 2024
7ca5ce8
drop Python 3.8 testing
katosh May 13, 2024
b973139
update notebook link to github file
katosh May 13, 2024
069b34b
specify testing packages as extras_require
katosh May 13, 2024
61fc8b9
fix sphinx syntax highlighting
katosh May 15, 2024
6b7f60f
black formatting
katosh May 15, 2024
644a4a3
ignore build paths
katosh May 15, 2024
03587b6
branch selection robust against NaNs
katosh May 15, 2024
2a48176
expose q and eps in tutorial
katosh May 15, 2024
66971d4
do not ignore the source code
katosh May 15, 2024
30046bc
do not plot nan cluster
katosh May 15, 2024
0ec5ee6
change dependency from matplotlib to matplotlib-base
katosh May 30, 2024
b0e87db
Revert "change dependency from matplotlib to matplotlib-base"
katosh May 30, 2024
6b69de7
reference bioconda package in readme
katosh May 31, 2024
101ce30
suggest `-c conda-forge` in readme
katosh Jun 13, 2024
5fe3b46
clearer doc for cell finding utilities
katosh Jun 13, 2024
856c18e
forward scanpy kwars in `plot_trajectory`
katosh Sep 26, 2024
81fa893
bugfix if DM is already a DataFrame
katosh Nov 16, 2024
41d5fa8
update deprecated cmap retrival
katosh Nov 16, 2024
d0adcf1
bugfix: None colormap
katosh Nov 19, 2024
185780e
Fix #39 again
katosh Nov 19, 2024
3fbcb77
bump version v1.3.4
katosh Nov 20, 2024
e2e7947
update readme
katosh Nov 20, 2024
898c8fa
add options for clipping small values to 0
jordanc17 Nov 25, 2024
b0f949e
turn sparsified matrix into sparse format
katosh Nov 26, 2024
a2b7705
Merge branch 'master' into magic-sparsity
katosh Nov 26, 2024
1225414
bump bersion to 1.3.5rc
katosh Nov 26, 2024
e893cd5
update readme
katosh Nov 26, 2024
ede1ca2
update tests for magic_imputation and keep sparsity in anndata
katosh Nov 26, 2024
4d0f031
Merge pull request #153 from settylab/magic-sparsity
katosh Nov 26, 2024
d5d13be
fix `run_local_variability`
katosh Nov 30, 2024
e8a03c7
Merge branch 'master' of github.com:dpeerlab/Palantir
katosh Nov 30, 2024
3e6a74f
fix readme
katosh Nov 30, 2024
b307d29
version bump v1.3.5
katosh Nov 30, 2024
9f4c5a9
deal with non-sparse distance matrix
katosh Nov 30, 2024
e7f0093
version bump v1.3.6
katosh Nov 30, 2024
c43ecf5
make v1.4.0
katosh Feb 28, 2025
1d4ab0b
fix import errors in new tests
katosh Feb 28, 2025
eee8a67
flake8 adjustments
katosh Mar 2, 2025
fe7b7f9
drop python 3.8 support, add 3.12 and 3.13
katosh Mar 2, 2025
bb5ab54
v1.4.0 release notes
katosh Mar 3, 2025
32e3ee6
add codecov token
katosh Mar 3, 2025
9efe61e
allow user-selected distance metric
jordanc17 May 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v3
Expand All @@ -27,8 +27,9 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest coverage typing-extensions
python -m pip install flake8 pytest pytest-cov coverage typing-extensions
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
python -m pip install -e .
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
Expand All @@ -39,6 +40,8 @@ jobs:
env:
PYTHONPATH: ./src/
run: |
coverage run --source=src/palantir/ -m pytest tests/*.py
python -m pytest --cov=src/palantir
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ __pycache__/
*.h5ad
build/
palantir.egg-info/
.coverage
.coverage*
notebooks/testing.ipynb
.pytest_cache/
dist/
.vscode/
data/
166 changes: 80 additions & 86 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,97 +4,59 @@
Palantir
------

Palantir is an algorithm to align cells along differentiation trajectories. Palantir models differentiation as a stochastic process where stem cells differentiate to terminally differentiated cells by a series of steps through a low dimensional phenotypic manifold. Palantir effectively captures the continuity in cell states and the stochasticity in cell fate determination. Palantir has been designed to work with multidimensional single cell data from diverse technologies such as Mass cytometry and single cell RNA-seq.
Palantir is an algorithm to align cells along differentiation trajectories. Palantir models differentiation as a stochastic process where stem cells differentiate to terminally differentiated cells by a series of steps through a low dimensional phenotypic manifold. Palantir effectively captures the continuity in cell states and the stochasticity in cell fate determination. Palantir has been designed to work with multidimensional single cell data from diverse technologies such as Mass cytometry and single cell RNA-seq.

## Installation
Palantir has been implemented in Python3 and can be installed using:

#### Installation and dependencies
1. Palantir has been implemented in Python3 and can be installed using:

pip install palantir

2. Palantir depends on a number of `python3` packages available on pypi and these dependencies are listed in `setup.py`
### Using pip
```sh
pip install palantir
```

All the dependencies will be automatically installed using the above commands
### Using conda, mamba, or micromamba from the bioconda channel
You can also install Palantir via conda, mamba, or micromamba from the bioconda channel:

3. To uninstall:

pip uninstall palantir

4. Palantir can also be used with [**Scanpy**](https://github.com/theislab/scanpy). It is fully integrated into Scanpy, and can be found under Scanpy's external modules ([link](https://scanpy.readthedocs.io/en/latest/api/scanpy.external.html#external-api))
#### Using conda
```sh
conda install -c conda-forge -c bioconda palantir
```

#### Using mamba
```sh
mamba install -c conda-forge -c bioconda palantir
```

#### Usage
#### Using micromamba
```sh
micromamba install -c conda-forge -c bioconda palantir
```

A tutorial on Palantir usage and results visualization for single cell RNA-seq data can be found in this notebook: http://nbviewer.jupyter.org/github/dpeerlab/Palantir/blob/master/notebooks/Palantir_sample_notebook.ipynb
These methods ensure that all dependencies are resolved and installed efficiently.


#### Processed data and metadata
```scanpy anndata``` objects are available for download for the three replicates generated in the manuscript: [Rep1](https://s3.amazonaws.com/dp-lab-data-public/palantir/human_cd34_bm_rep1.h5ad), [Rep2](https://s3.amazonaws.com/dp-lab-data-public/palantir/human_cd34_bm_rep2.h5ad), [Rep3](https://s3.amazonaws.com/dp-lab-data-public/palantir/human_cd34_bm_rep3.h5ad)
## Usage

Each object has the following elements
* `.X`: Filtered, normalized and log transformed count matrix
* `.raw`: Filtered raw count matrix
* `.obsm['MAGIC_imputed_data']`: Imputed count matrix using MAGIC
* `.obsm['tsne']`: tSNE maps presented in the manuscript generated using scaled diffusion components as inputs
* `.obs['clusters']`: Clustering of cells
* `.obs['palantir_pseudotime']`: Palantir pseudo-time ordering
* `.obs['palantir_diff_potential']`: Palantir differentation potential
* `.obsm['palantir_branch_probs']`: Palantir branch probabilities
* `.uns['palantir_branch_probs_cell_types']`: Column names for branch probabilities
* `.uns['ct_colors']`: Cell type colors used in the manuscript
* `.uns['cluster_colors']`: Cluster colors used in the manuscript
* `.varm['mast_diff_res_pval']`: MAST p-values for differentially expression in each cluster compared to others
* `.varm['mast_diff_res_statistic']`: MAST statistic for differentially expression in each cluster compared to others
* `.uns['mast_diff_res_columns']`: Column names for the differential expression results
A tutorial on Palantir usage and results visualization for single cell RNA-seq
data can be found in this notebook:
https://github.com/dpeerlab/Palantir/blob/master/notebooks/Palantir_sample_notebook.ipynb

More tutorials and a documentation of all the Palantir components can be found
here: https://palantir.readthedocs.io

#### Comparison to trajectory detection algorithms
Notebooks detailing the generation of results comparing Palantir to trajectory detection algorithms are available [here](https://github.com/dpeerlab/Palantir/blob/master/notebooks/comparisons)
## Processed data and metadata

`scanpy anndata` objects are available for download for the three replicates generated in the manuscript:
- [Replicate 1 (Rep1)](https://s3.amazonaws.com/dp-lab-data-public/palantir/human_cd34_bm_rep1.h5ad)
- [Replicate 2 (Rep2)](https://s3.amazonaws.com/dp-lab-data-public/palantir/human_cd34_bm_rep2.h5ad)
- [Replicate 3 (Rep3)](https://s3.amazonaws.com/dp-lab-data-public/palantir/human_cd34_bm_rep3.h5ad)

#### Convert to Seurat objects
Use the snippet below to convert `anndata` to `Seurat` objects
```
library("SeuratDisk")
library("Seurat")
library("reticulate")
use_condaenv(<conda env>, required = T) # before, install "anndata" into <conda env>
anndata <- import('anndata')

#link to Anndata files
url_Rep1 <- "https://s3.amazonaws.com/dp-lab-data-public/palantir/human_cd34_bm_rep1.h5ad"
curl::curl_download(url_Rep1, basename(url_Rep1))
url_Rep2 <- "https://s3.amazonaws.com/dp-lab-data-public/palantir/human_cd34_bm_rep2.h5ad"
curl::curl_download(url_Rep2, basename(url_Rep2))
url_Rep3 <- "https://s3.amazonaws.com/dp-lab-data-public/palantir/human_cd34_bm_rep3.h5ad"
curl::curl_download(url_Rep3, basename(url_Rep3))

#H5AD files are compressed using the LZF filter.
#This filter is Python-specific, and cannot easily be used in R.
#To use this file with Seurat and SeuratDisk, you'll need to read it in Python and save it out using the gzip compression
#https://github.com/mojaveazure/seurat-disk/issues/7
adata_Rep1 = anndata$read("human_cd34_bm_rep1.h5ad")
adata_Rep2 = anndata$read("human_cd34_bm_rep2.h5ad")
adata_Rep3 = anndata$read("human_cd34_bm_rep3.h5ad")

adata_Rep1$write_h5ad("human_cd34_bm_rep1.gzip.h5ad", compression="gzip")
adata_Rep2$write_h5ad("human_cd34_bm_rep2.gzip.h5ad", compression="gzip")
adata_Rep3$write_h5ad("human_cd34_bm_rep3.gzip.h5ad", compression="gzip")


#convert gzip-compressed h5ad file to Seurat Object
Convert("human_cd34_bm_rep1.gzip.h5ad", dest = "h5seurat", overwrite = TRUE)
Convert("human_cd34_bm_rep2.gzip.h5ad", dest = "h5seurat", overwrite = TRUE)
Convert("human_cd34_bm_rep3.gzip.h5ad", dest = "h5seurat", overwrite = TRUE)

human_cd34_bm_Rep1 <- LoadH5Seurat("human_cd34_bm_rep1.gzip.h5seurat")
human_cd34_bm_Rep2 <- LoadH5Seurat("human_cd34_bm_rep2.gzip.h5seurat")
human_cd34_bm_Rep3 <- LoadH5Seurat("human_cd34_bm_rep3.gzip.h5seurat")
```
Thanks to Anne Ludwig from University Hospital Heidelberg for the tip!
This notebook details how to use the data in `Python` and `R`: http://nbviewer.jupyter.org/github/dpeerlab/Palantir/blob/master/notebooks/manuscript_data.ipynb

## Comparison to trajectory detection algorithms
Notebooks detailing the generation of results comparing Palantir to trajectory detection algorithms are available [here](https://github.com/dpeerlab/Palantir/blob/master/notebooks/comparisons)

#### Citations
## Citations
Palantir manuscript is available from [Nature Biotechnology](https://www.nature.com/articles/s41587-019-0068-4). If you use Palantir for your work, please cite our paper.

@article{Palantir_2019,
Expand All @@ -110,16 +72,48 @@ ____

Release Notes
-------------
### Version 1.4.0
* Made pygam an optional dependency that can be installed with `pip install palantir[gam]` or `pip install palantir[full]`
* Added proper conditional imports and improved error handling for pygam
* Enhanced `run_magic_imputation` to return appropriate data types for different inputs
* Updated code to use direct AnnData imports for newer compatibility
* Improved version detection using `importlib.metadata` with graceful fallbacks
* Fixed Series indexing deprecation warnings in early cell detection functions
* Expanded and standardized documentation with NumPy-style docstrings throughout the codebase
* Added comprehensive type hints to improve code quality and IDE support
* Remove dependency from `_` methods in scanpy for plotting.

#### Testing and Quality Improvements
* Added comprehensive tests for optional pygam dependency
* Improved test coverage for run_magic_imputation with various input/output types
* Added integration tests against expected results
* Enhanced test infrastructure to work with newer library versions
* Expanded test coverage to catch edge cases in data processing

### Version 1.3.6
* `run_magic_imputation` now has a boolean parameter `sparse` to control output sparsity
* **bugfix**: `run_local_variability` for dense expression arrays now runs much faster and more accurate

### Version 1.3.4
* avoid devision by zero in `select_branch_cells` for very small datasets
* make branch selection robust against NaNs
* do not plot unclustered trends (NaN cluster) in `plot_gene_trend_clusters`

### Version 1.3.3
* optional progress bar with `progress=True` in `palantir.utils.run_local_variability`
* avoid NaN in local variablility output
* compatibility with `scanpy>=1.10.0`

### Version 1.3.2
* require `python>=3.8`
* require `python>=3.9`
* implement CI for testing
* fixes for edge cases discoverd through extended testing
* fixes for edge cases discovered through extended testing
* implement `plot_trajectory` function to show trajectory on the umap
* scale pseudotime to unit intervall in anndata
* scale pseudotime to unit interval in anndata

### Version 1.3.1
* implemented `palantir.plot.plot_stats` to plot arbitray cell-wise statistics as x-/y-positions.
* reduce memory usgae of `palantir.presults.compute_gene_trends`
* implemented `palantir.plot.plot_stats` to plot arbitrary cell-wise statistics as x-/y-positions.
* reduce memory usage of `palantir.presults.compute_gene_trends`
* removed seaborn dependency
* refactor `run_diffusion_maps` to split out `compute_kernel` and `diffusion_maps_from_kernel`
* remove unused dependencies `tables`, `Cython`, `cmake`, and `tzlocal`.
Expand All @@ -130,28 +124,28 @@ Release Notes
#### New Features
* Enable an AnnData-centric workflow for improved usability and interoperability with other single-cell analysis tools.
* Introduced new utility functions
* `palantir.utils.early_cell` To automate fining an early cell based on cell type and diffusion components.
* `palantir.utils.early_cell` To automate finding an early cell based on cell type and diffusion components.
* `palantir.utils.find_terminal_states` To automate finding terminal cell states based on cell type and diffusion components.
* `palantir.presults.select_branch_cells` To find cells associated to each branch based on fate probability.
* `palantir.plot.plot_branch_selection` To inspect the cell to branch association.
* `palantir.utils.run_local_variability` To compute local gene expression variability.
* `palantir.utils.run_density` A wrapper for [mellon.DensityEstimator](https://mellon.readthedocs.io/en/latest/model.html#mellon.model.DensityEstimator).
* `palantir.utils.run_density_evaluation` Evaluate computed density on a different dataset.
* `palantir.utils.run_low_density_variability`. To aggregate local gene expression variability in low density.
* `palantir.plot.plot_branch`. To plot branch-selected cells over pseudotime in arbitrary y-postion and coloring.
* `palantir.plot.plot_trend`. To plot the gene trend ontop of `palantir.plot.plot_branch`.
* `palantir.plot.plot_branch`. To plot branch-selected cells over pseudotime in arbitrary y-position and coloring.
* `palantir.plot.plot_trend`. To plot the gene trend on top of `palantir.plot.plot_branch`.
* Added input validation for better error handling and improved user experience.
* Expanded documentation within docstrings, providing additional clarity for users and developers.

#### Enhancements
* Updated tutorial notebook to reflect the new workflow, guiding users through the updated processes.
* Implemented gene trend computation using [Mellon](https://github.com/settylab/Mellon), providing more robust and efficient gene trend analysis.
* Enable annotation in `palantir.plot.highight_cells_on_umap`.
* Enable annotation in `palantir.plot.highlight_cells_on_umap`.

#### Changes
* Replaced PhenoGraph dependency with `scanpy.tl.leiden` for gene trend clustering.
* Deprecated the `run_tsne`, `determine_cell_clusters`, and `plot_cell_clusters` functions. Use corresponding implementations from [Scanpy](https://scanpy.readthedocs.io/en/stable/), widely used single-cell analysis library and direct dependecy of Palantir.
* Rename `palantir.plot.highight_cells_on_tsne` to `palantir.plot.highight_cells_on_umap`
* Deprecated the `run_tsne`, `determine_cell_clusters`, and `plot_cell_clusters` functions. Use corresponding implementations from [Scanpy](https://scanpy.readthedocs.io/en/stable/), widely used single-cell analysis library and direct dependency of Palantir.
* Rename `palantir.plot.highlight_cells_on_tsne` to `palantir.plot.highlight_cells_on_umap`
* Depend on `anndata>=0.8.0` to avoid issues writing dataframes in `ad.obsm`.

#### Fixes
Expand Down
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)

if "%1" == "" goto help

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
10 changes: 10 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sphinxcontrib-autoprogram
sphinxcontrib-napoleon
sphinx-autodocgen
sphinx-github-style>=1.2.2
sphinx-mdinclude
m2r2
nbsphinx
furo
typing-extensions
IPython
Loading