ROGUE-inspired cluster purity scoring for count matrices
Project description
dodgey
ROGUE-inspired cluster purity scoring for count matrices.
dodgey provides a lightweight, NumPy-like API for computing a heterogeneity
score inspired by the ROGUE method used in scRNA-seq cluster QC. This is not
a verbatim port of ROGUE; it is a deterministic, documented implementation that
captures the core idea while keeping dependencies minimal.
Installation
pip install dodgey
Optional integrations:
pip install dodgey[scanpy]
Quickstart
Score a matrix
import numpy as np
import dodgey as dg
X = np.random.poisson(1.0, size=(200, 300)) # cells x genes
score = dg.score_matrix(X, k=45.0, axis="cells_by_genes")
print(score)
Score clusters by labels
import numpy as np
import dodgey as dg
X = np.random.poisson(1.0, size=(200, 300))
labels = np.repeat(["A", "B"], 100)
result = dg.score_labels(X, labels)
print(result)
Score an AnnData object (optional)
import dodgey as dg
scores = dg.score_adata(adata, cluster_key="leiden", layer="counts")
print(scores.head())
What the metric means
Given a count matrix, dodgey computes per-gene summary statistics over cells,
fits a smooth expected relationship between those statistics, and measures how
much each gene deviates from expectation. Genes with significant deviations
contribute to a sig_value, and the final score is:
score = 1 - sig_value / (sig_value + k)
Higher scores indicate more homogeneous clusters (lower heterogeneity), and lower scores indicate more heterogeneous clusters. The input is expected to be raw or lightly processed counts (not already log-transformed).
Scoring details
The method is ROGUE-inspired and intentionally lightweight:
- Compute per-gene proxies across cells:
entropy_proxy = mean(log(expr + 1))mean_expr_proxy = log(mean(expr) + r)
- Fit a smooth expected relationship
entropy_proxy ~ mean_expr_proxyusing LOWESS/LOESS (statsmodels). The LOWESSspanmaps to thefracparameter. - Compute residuals:
ds = fitted_entropy - observed_entropy. - Estimate p-values using a normal approximation on
ds:p = 1 - NormalCDF(ds; mean(ds), sd(ds))sdis guarded with a small epsilon to avoid division by zero.
- Apply Benjamini–Hochberg FDR correction.
- Significant genes satisfy
p < cutoffandq < cutoff. sig_value = sum(abs(ds))over significant genes.- Final score:
score = 1 - sig_value / (sig_value + k)in[0, 1].
Notes:
- This implementation is deterministic: LOWESS is fitted on sorted mean expression, then mapped back to the original gene order.
- Sparse matrices are processed without densifying.
- If the input appears already log-transformed, a warning is emitted.
Formal definition
Let (X \in \mathbb{R}^{n \times g}) be a non-negative count matrix with cells as rows and genes as columns. For gene (j):
H_j = (1/n) * sum_i log(X_ij + 1)
M_j = log((1/n) * sum_i X_ij + r)
Fit a LOWESS curve (\hat{H}(M)) and compute residuals:
ds_j = \\hat{H}(M_j) - H_j
Let (\mu) and (\sigma) be the mean and standard deviation of ds. Then:
p_j = 1 - Phi((ds_j - mu) / sigma)
Apply Benjamini–Hochberg FDR to obtain q_j. Significant genes satisfy
p_j < cutoff and q_j < cutoff.
sig_value = sum_j |ds_j| for significant genes
score = 1 - sig_value / (sig_value + k)
Worked example (tiny)
X = [[2, 0, 1],
[3, 0, 0],
[0, 1, 0],
[1, 0, 0]]
For gene 1 (index 0) with r = 1.0:
mean = (2 + 3 + 0 + 1) / 4 = 1.5
M_1 = log(1.5 + 1.0) = log(2.5)
H_1 = mean(log([3, 4, 1, 2])) / 4
Repeat for all genes, fit LOWESS over M_j vs H_j, compute ds_j, then the
final score. In real use, larger gene sets are needed for stable LOWESS fits.
Key parameters
k: scale parameter (default45.0for droplet/UMI; use500.0for full-length)cutoff: p-value and FDR threshold (default0.05)span: LOWESS span (frac) controlling smoothing (default0.5)r: small offset added inside the log for mean expression (default1.0)axis:"auto","cells_by_genes", or"genes_by_cells"(auto uses a simple heuristic: if rows < columns, assume cells by genes; otherwise genes by cells)
Acknowledgement
This package is ROGUE-inspired and is not intended as a verbatim reimplementation of the original method.
Citations
If you use dodgey in your research, please consider citing:
McKenna, A. (2025). dodgey: ROGUE-inspired cluster purity scoring for count matrices. GitHub. https://github.com/AxelMMalaghan/DODGEY
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dodgey-0.1.0.tar.gz.
File metadata
- Download URL: dodgey-0.1.0.tar.gz
- Upload date:
- Size: 12.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b3bfdb8e4305eff28eee1d31c9a69300904099655631f764d8a7d8fcca85d4bc
|
|
| MD5 |
37001b2680d8d1c1aa716dc2ed23de0d
|
|
| BLAKE2b-256 |
137846bb76a6d8c5e12e9e470d01d5dd87f66035e3657f19e0703d461b1ab770
|
Provenance
The following attestation bundles were made for dodgey-0.1.0.tar.gz:
Publisher:
pypi-publish.yml on AxelMMalaghan/DODGEY
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dodgey-0.1.0.tar.gz -
Subject digest:
b3bfdb8e4305eff28eee1d31c9a69300904099655631f764d8a7d8fcca85d4bc - Sigstore transparency entry: 792145352
- Sigstore integration time:
-
Permalink:
AxelMMalaghan/DODGEY@32052858df8c1e1a636a00892c08b6ade51291f9 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/AxelMMalaghan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@32052858df8c1e1a636a00892c08b6ade51291f9 -
Trigger Event:
release
-
Statement type:
File details
Details for the file dodgey-0.1.0-py3-none-any.whl.
File metadata
- Download URL: dodgey-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7bd4a176c8223198510b3ed7e8d3426aa2b507eef87407e2c103f6421ea31e80
|
|
| MD5 |
e80760fcea8a85b4d5fb5bfbe108d074
|
|
| BLAKE2b-256 |
c371dea9ed93b414a28602128df46f3ea571ca43bc0c1e18de7b70574cdb26f2
|
Provenance
The following attestation bundles were made for dodgey-0.1.0-py3-none-any.whl:
Publisher:
pypi-publish.yml on AxelMMalaghan/DODGEY
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dodgey-0.1.0-py3-none-any.whl -
Subject digest:
7bd4a176c8223198510b3ed7e8d3426aa2b507eef87407e2c103f6421ea31e80 - Sigstore transparency entry: 792145439
- Sigstore integration time:
-
Permalink:
AxelMMalaghan/DODGEY@32052858df8c1e1a636a00892c08b6ade51291f9 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/AxelMMalaghan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@32052858df8c1e1a636a00892c08b6ade51291f9 -
Trigger Event:
release
-
Statement type: