Skip to main content

Package for PCA-based spatial domain identification in single-cell spatial transcriptomics data

Project description

NichePCA

Tests

Package for PCA-based spatial domain identification in single-cell spatial transcriptomics data. The corresonding manuscript was published in Bioinformatics.

Getting started

Given an AnnData object adata, you can run nichepca starting from raw counts as follows:

import scanpy as sc
import nichepca as npc

npc.wf.nichepca(adata, knn=25)
sc.pp.neighbors(adata, use_rep="X_npca")
sc.tl.leiden(adata, resolution=0.5)

Multi-sample support

If you have multiple samples in adata.obs['sample'], you can provide the key sample to npc.wf.nichepca this uses harmony by default:

npc.wf.nichepca(adata, knn=25, sample_key="sample")

If you have cell type labels in adata.obs['cell_type'], you can directly provide them to nichepca as follows (we found this sometimes works better for multi-sample domain identification). However, in this case we need to run npc.cl.leiden_unique to handle potential duplicate embeddings:

npc.wf.nichepca(adata, knn=25, obs_key='cell_type', sample_key="sample")
npc.cl.leiden_unique(adata, use_rep="X_npca", resolution=0.5, n_neighbors=15)

Customization

The nichepca functiopn also allows to customize the original ("norm", "log1p", "agg", "pca") pipeline, e.g., without median normalization:

npc.wf.nichepca(adata, knn=25, pipeline=["log1p", "agg", "pca"])

or with "pca" before "agg":

npc.wf.nichepca(adata, knn=25, pipeline=["norm", "log1p", "pca", "agg"])

or without "pca" at all:

npc.wf.nichepca(adata, knn=25, pipeline=["norm", "log1p", "agg"])

Setting parameters

We found that higher number of neighbors e.g., knn=25 lead to better results in brain tissue, while knn=10 works well for kidney data. We recommend to qualitatively optimize these parameters on a small subset of your data. The number of PCs (n_comps=30 by default) seems to have negligible effect on the results.

Installation

You need to have Python 3.10 or newer installed on your system. If you don't have Python installed, we recommend installing Mambaforge or Miniconda.

To create a new conda environment with Python 3.10:

conda create -n npc-env python=3.10 -y
conda activate npc-env

Install the latest development version:

pip install git+https://github.com/imsb-uke/nichepca.git@main

Contributing

If you want to contribute you can follow this guide. In short fork the repository, setup a dev environment using this command:

conda create -n npc-dev python=3.10 -y
conda activate npc-dev
git clone https://github.com/{your-username}/nichepca.git
pip install -e ".[dev, test]"

And then make your changes, run the tests and submit a pull request.

Release notes

See the changelog.

Contact

For questions, help requests, and bug reports, please use the issue tracker.

Citation

If you use NichePCA in your research, please cite:

@article{schaub2025pca,
  title={PCA-based spatial domain identification with state-of-the-art performance},
  author={Schaub, Darius P and Yousefi, Behnam and Kaiser, Nico and Khatri, Robin and Puelles, Victor G and Krebs, Christian F and Panzer, Ulf and Bonn, Stefan},
  journal={Bioinformatics},
  volume={41},
  number={1},
  pages={btaf005},
  year={2025},
  publisher={Oxford University Press}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nichepca-0.0.1.tar.gz (296.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nichepca-0.0.1-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file nichepca-0.0.1.tar.gz.

File metadata

  • Download URL: nichepca-0.0.1.tar.gz
  • Upload date:
  • Size: 296.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nichepca-0.0.1.tar.gz
Algorithm Hash digest
SHA256 9d9bab1dbf3d17f28f3d3ce839ed220081dd0c4862312b9b6df98a7b37689f3a
MD5 e895352f45d77e95bd8ad5b4ec7500c9
BLAKE2b-256 8c422774ecc98fb4a81e3a03da4a54c914bac7752f345add32f54d029593563f

See more details on using hashes here.

Provenance

The following attestation bundles were made for nichepca-0.0.1.tar.gz:

Publisher: release.yaml on imsb-uke/nichepca

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nichepca-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: nichepca-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 16.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nichepca-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f1f01bd09f79d63b73db9362f04900e500acf31a622fc15ff2aa82362d883d95
MD5 46a710d99943377662e8319e78a46328
BLAKE2b-256 fbb2d190bbd3ea639fad7f15180090160cacf477b53569d3f9fd716efa767113

See more details on using hashes here.

Provenance

The following attestation bundles were made for nichepca-0.0.1-py3-none-any.whl:

Publisher: release.yaml on imsb-uke/nichepca

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page