Skip to main content

Single-cell data visualization using kernel gene-weighted density estimation

Project description

pyNebulosa

PyPI Documentation License: MIT

Single-cell data visualization using kernel gene-weighted density estimation.

pyNebulosa is a Python package (ported from the original R/Bioconductor package) that recovers gene expression signals lost to dropout in single-cell data by using weighted kernel density estimation on low-dimensional embeddings. It integrates natively with scanpy and AnnData.

Motivation

Standard feature plots in single-cell analysis are plagued by sparsity — many cells show zero expression even for marker genes, making it hard to see biological signal. pyNebulosa addresses this by computing a gene-weighted kernel density estimate (KDE) on the embedding space, effectively smoothing expression over neighbouring cells.

Standard feature plot pyNebulosa density plot
Sparse, hard to interpret Smooth, recovers signal

Standard vs Density

R vs Python

pyNebulosa was originally an R/Bioconductor package (Nebulosa) for Seurat and SingleCellExperiment objects. This Python port provides an equivalent API for the scanpy/AnnData ecosystem, producing identical density estimates.

R vs Python comparison

R (Seurat)Python (scanpy)
library(Nebulosa)
library(Seurat)
pbmc <- pbmc3k.SeuratData::pbmc3k.final
plot_density(pbmc, "NKG7")
plot_density(pbmc, c("NKG7", "GNLY"),
             joint = TRUE)
import scanpy as sc
import pynebulosa as nb
adata = sc.datasets.pbmc3k_processed()
nb.plot_density(adata, "NKG7")
nb.plot_density(adata, ["NKG7", "GNLY"],
                joint=True)

Installation

pip install pynebulosa

With scanpy (recommended):

pip install "pynebulosa[scanpy]"

Quick start

import scanpy as sc
import pynebulosa as nb

adata = sc.datasets.pbmc3k_processed()

# Single gene density plot
nb.plot_density(adata, "NKG7")

Multi-marker panels

Visualize multiple markers at once to identify cell populations:

nb.plot_density(adata, ["MS4A1", "NKG7", "CST3", "PPBP"], ncols=4)

Multi-marker density

Joint density

Find co-expressing cell populations by computing the product of individual gene densities:

nb.plot_density(adata, ["NKG7", "GNLY"], joint=True)

Joint density

API

Function Purpose
nb.plot_density(adata, features) Main visualization function
nb.calculate_density(weights, coords) Compute density values programmatically
nb.wkde2d(x, y, w) Low-level weighted 2D KDE

Key parameters

Parameter Description Default
joint Compute joint density across features False
reduction Embedding key in adata.obsm Auto-detect (X_umap)
method "wkde" (custom) or "ks" (scipy) "wkde"
adjust Bandwidth adjustment factor 1.0
cmap Matplotlib colormap "viridis"
layer Expression layer adata.X

How it differs from similar tools

Tool Approach Use case
scanpy.tl.embedding_density Unweighted KDE per category Where are cells of group X?
pyUCell Rank-based scoring + KNN smoothing Gene signature scoring
pyNebulosa Gene-weighted KDE on embeddings Recovering dropout signal

Documentation

Contributing

We welcome contributions of all kinds! If you'd like to contribute to pyNebulosa, please:

  1. Fork the repository and create a feature branch.
  2. Make your changes and add tests where appropriate.
  3. Ensure all tests pass with pytest tests/ -v.
  4. Submit a pull request describing your changes.

Please report bugs and feature requests on the issue tracker.

License

pyNebulosa is licensed under the MIT License.

Citation

If you use pyNebulosa, please cite:

Alquicira-Hernandez, J., Powell, J.E. Nebulosa recovers single-cell gene expression signals by kernel density estimation. Bioinformatics, 37(16), 2485-2487, 2021. doi:10.1093/bioinformatics/btab003

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

pynebulosa-0.1.1.tar.gz (3.7 MB view details)

Uploaded Source

Built Distribution

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

pynebulosa-0.1.1-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file pynebulosa-0.1.1.tar.gz.

File metadata

  • Download URL: pynebulosa-0.1.1.tar.gz
  • Upload date:
  • Size: 3.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pynebulosa-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7bc86ab5cea69e9af724676423ed136d5cd425264f8e340fa0cdbc0887a5e61a
MD5 6caeb751d6647b9a10f62e4dfa26b5e4
BLAKE2b-256 33cb56ff1e4d510e1ecd77a3f906001498ebc774bd21170611318ccf73f2d671

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynebulosa-0.1.1.tar.gz:

Publisher: publish.yml on mdmanurung/pyNebulosa

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

File details

Details for the file pynebulosa-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pynebulosa-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pynebulosa-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bf4ffba215a3531ba70ff3952fd26684cf67fc4fd7e3d354fa23e4640dd0454c
MD5 9f57fa357e62fe1fdf197cd27a77e3f9
BLAKE2b-256 a23a9647f447137a168e2759c82cb83852f080ae8bff37088c4ba7e9e312007b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynebulosa-0.1.1-py3-none-any.whl:

Publisher: publish.yml on mdmanurung/pyNebulosa

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