Skip to main content

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

Project description

pyNebulosa

PyPI Documentation License: GPL v3

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

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.0.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.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pynebulosa-0.1.0.tar.gz
Algorithm Hash digest
SHA256 847745de9a7aa8edc505ee488506d753111937dc9f691541e688b6e4a39565c6
MD5 331aef1ad370f532ed3984ed434767d5
BLAKE2b-256 5638dd289c5d1e3c1894779df30a5aed1afde6ed9ff1924b7a2ca74142790b48

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynebulosa-0.1.0.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.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for pynebulosa-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fba2192ff0acb1f108946c4c9baffb0268e0b70347a90399e3e540a947cab5a7
MD5 d340ea6fcc54276731de3b77a16b8e94
BLAKE2b-256 ba29492c801d7ea67f51f06fd72685ad166805ac80c251b5b0bd6cbac6d6dc05

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynebulosa-0.1.0-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