Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
52 changes: 33 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,44 @@
# NichePCA

[![Version](https://img.shields.io/pypi/v/nichepca)](https://pypi.org/project/nichepca/)
[![License](https://img.shields.io/pypi/l/nichepca)](https://github.com/imsb-uke/nichepca)
[![Python Version Required](https://img.shields.io/pypi/pyversions/nichepca)](https://pypi.org/project/nichepca/)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)
[![PyPI downloads](https://img.shields.io/pepy/dt/nichepca?label=PyPI%20downloads&logo=pypi)](https://pepy.tech/project/nichepca)
[![Tests][badge-tests]][link-tests]

<!-- [![Documentation][badge-docs]][link-docs] -->

[badge-tests]: https://img.shields.io/github/actions/workflow/status/imsb-uke/nichepca/test.yaml?branch=main
[link-tests]: https://github.com/imsb-uke/nichepca/actions/workflows/test.yaml
[badge-docs]: https://img.shields.io/readthedocs/nichepca

Package for PCA-based spatial domain identification in single-cell spatial transcriptomics data. The corresonding manuscript was published in [Bioinformatics](https://academic.oup.com/bioinformatics/article/41/1/btaf005/7945104?).
Package for PCA-based spatial domain identification in single-cell spatial transcriptomics data. The corresponding manuscript was published in [Bioinformatics](https://academic.oup.com/bioinformatics/article/41/1/btaf005/7945104?).

## 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](https://github.com/conda-forge/miniforge#mambaforge) or [Miniconda](https://docs.anaconda.com/miniconda/miniconda-install/).

To create a new conda environment with Python 3.11:

```bash
conda create -n npc-env python=3.11 -y
conda activate npc-env
```

NichePCA can be installed from PyPI:

```bash
pip install nichepca
```

To install the latest development version:

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

## Getting started

Expand Down Expand Up @@ -55,25 +86,8 @@ or without `"pca"` at all:
npc.wf.nichepca(adata, knn=25, pipeline=["norm", "log1p", "agg"])
```

## Setting parameters
## Hyperparameter choice
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](https://github.com/conda-forge/miniforge#mambaforge) or [Miniconda](https://docs.anaconda.com/miniconda/miniconda-install/).

To create a new conda environment with Python 3.10:

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

Install the latest development version:

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

## Contributing

Expand Down
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ maintainers = [
urls.Documentation = "https://nichepca.readthedocs.io/"
urls.Source = "https://github.com/imsb-uke/nichepca"
urls.Home-page = "https://github.com/imsb-uke/nichepca"
classifiers = [
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
]
dependencies = [
"scanpy (>=1.11.4,<2.0.0)",
"torch (>=2.8.0,<3.0.0)",
Expand Down
7 changes: 7 additions & 0 deletions src/nichepca/workflows/_nichepca.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def nichepca(
aggr: str = "mean",
allow_harmony: bool = True,
max_iter_harmony: int = 50,
remove_graph: bool = False,
**kwargs,
):
"""
Expand Down Expand Up @@ -67,6 +68,9 @@ def nichepca(
Whether to allow Harmony integration.
max_iter_harmony : int, optional
Maximum number of iterations for Harmony.
remove_graph : bool, optional
Whether to remove the constructed graph from ``adata.uns`` after the workflow
completes.
**kwargs : dict
Additional keyword arguments.

Expand Down Expand Up @@ -195,3 +199,6 @@ def nichepca(
index=ad_tmp.var_names,
columns=[f"PC{i}" for i in range(n_comps)],
)

if remove_graph and "graph" in adata.uns:
del adata.uns["graph"]
5 changes: 5 additions & 0 deletions tests/test_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ def test_nichepca_single():

assert np.all(X_npca_0 == X_npca_1)

# test graph removal
adata = generate_dummy_adata()
npc.wf.nichepca(adata, knn=5, pipeline=pipeline, remove_graph=True)
assert "graph" not in adata.uns

# test with pca on raw counts
pipeline = ("pca", "agg")

Expand Down