Skip to main content

sc-apl-py

PyPI

Python implementation of Association Plots (APL) (Gralinska and Vingron, JRSSSC 2023 paper)

Installation

pip install sc_apl_py

The core package depends only on anndata, numpy, scipy and pandas. The plotting functions in apl_py.pl need matplotlib, which comes with the plot extra:

pip install "sc_apl_py[plot]"

Usage

import scanpy as sc
import sc_apl_py as apl

adata = sc.datasets.pbmc3k()
sc.pp.filter_genes(adata, min_cells=3)
sc.pp.normalize_total(adata)
sc.pp.log1p(adata)                 # APL's vignette runs CA on logcounts
# ... clustering, e.g. sc.tl.leiden(adata)

apl.tl.ca(adata, top=5000)         # correspondence analysis
n = apl.tl.pick_dims(adata, "elbow_rule")
apl.tl.association_coords(adata, "2", groupby="leiden", n_comps=n)
apl.tl.apl_score(adata)            # S-alpha scores

apl.get.apl_df(adata)              # ranked genes: x, y, score, rank
apl.pl.association_plot(adata)
apl.pl.scree(adata)
apl.pl.biplot(adata, color="leiden")
sc.pl.embedding(adata, basis="ca", color="leiden")

apl.tl.apl(adata, "2", groupby="leiden") runs the whole workflow (runAPL).

apl.tl.apl_groups(adata, "leiden") ranks genes for every cluster at once and returns a long table (group, gene, x, y, score, rank); the cutoff angle for each group is stored in uns["apl_groups"]["alpha"].

Use apl.tl.ca(adata, mask_var="highly_variable", top=None) to run CA on genes chosen by sc.pp.highly_variable_genes instead of APL's selection by chi-square variance. For plain arrays, apl.correspondence_analysis(X) returns a CAResult, and apl.association_coords(ca, group) works on it.

Where results are stored

Result Location
Cell standard coordinates obsm["X_ca"]
Gene principal coordinates varm["ca_princ"] (NaN for unused genes)
Masses / inertias obs/var columns ca_mass, ca_inertia
Singular values, parameters uns["ca"]
AP coordinates obs/var columns apl_x, apl_y; group in obs["apl_group"]
S-alpha score var["apl_score"]; cutoff angle in uns["apl"]

Everything is stored in plain AnnData fields, so it round-trips through .h5ad, and key_added lets you keep APs for several clusters side by side.

R → Python

Orientation is transposed: R's APL uses genes × cells, AnnData uses cells × genes, so R's "rows" are var and its "columns" are obs.

R (APL) Python
cacomp apl.tl.ca / apl.correspondence_analysis
var_rows apl.variable_scores (used via top=)
pick_dims apl.tl.pick_dims, apl.pl.scree
subset_dims n_comps= on AP functions, CAResult.subset_dims
apl_coords apl.tl.association_coords
apl_score apl.tl.apl_score
apl apl.pl.association_plot
ca_biplot apl.pl.biplot
runAPL apl.tl.apl
as.cacomp apl.get.ca

Differences from R:

  • The SVD uses SciPy: LAPACK for small problems, ARPACK otherwise. For the default (unclipped Pearson) residuals, the residual matrix is used as an implicit operator and never densified.
  • R's clip argument has no effect in APL (Pearson residuals are bounded by 1), so it is dropped; cutoff still clips.
  • Negative-binomial residuals follow APL, which differs from scanpy's normalize_pearson_residuals: APL computes them on the frequency table.
  • Not ported: apl_topGO/plot_enrichment (use var["apl_score"] with a prerank tool such as gseapy or decoupler), ca_3Dplot, plotly output, and caching of permuted data (store_perm).

Examples

The examples directory contains marimo notebooks that demonstrate the plotting functions:

  • plotting_basics.py: simulated data (runs offline). Covers the scree plot, biplots and Association Plot variants, with a cluster picker.
  • pbmc3k.py: a scanpy workflow on 10x PBMC 3k (downloads about 6 MB), with a comparison to Wilcoxon marker genes and rankings for every cluster.
uv run --extra examples marimo edit examples/plotting_basics.py

Development

uv sync
uv run pytest

Tests check AP coordinates against the reference outputs from APL's R test suite (tests/data).

AI usage disclosure

Claude Code was used to port code from R to Python.

Metadata

Release files for sc_apl_py 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sc_apl_py 0.1.1
File Size Uploaded Provenance Actions
sc_apl_py-0.1.1.tar.gz 167.9 kB Without provenance Details for sc_apl_py-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sc_apl_py 0.1.1
File Interpreter ABI Platform Actions
sc_apl_py-0.1.1-py3-none-any.whl Python 3 none any Details for sc_apl_py-0.1.1-py3-none-any.whl

Total release size: 202.3 kB

Release files / sc_apl_py-0.1.1.tar.gz

Download URL sc_apl_py-0.1.1.tar.gz
Size 167.9 kB
Tags Source
SHA-256 checksum
How to use checksums
70db4d9285f18502d03df822a8050a976a615f294131eba58241fca4cc2f3d7a
BLAKE2b-256 checksum
How to use checksums
a84ee013313713043434bf58bd3a45bfc3a0f8a164d705b140aa3999218d2eba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.22 {"installer":{"name":"uv","version":"0.12.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / sc_apl_py-0.1.1-py3-none-any.whl

Download URL sc_apl_py-0.1.1-py3-none-any.whl
Size 34.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ce7abe87160a670f542892eb5ac58aa406084f7aa511ede22c320ea7c1f363b1
BLAKE2b-256 checksum
How to use checksums
9b72ea9fa9fdc04be4b80ed4c95fa618cc4181a6dba3893c4d40a9979c460609
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.22 {"installer":{"name":"uv","version":"0.12.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for sc_apl_py 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page