Skip to content

Keep genes whose positive counts are all 1 in poscounts size factors - #494

Open
MMatinGerami wants to merge 1 commit into
scverse:mainfrom
MMatinGerami:fix/poscounts-all-ones-genes
Open

MMatinGerami wants to merge 1 commit into
scverse:mainfrom
MMatinGerami:fix/poscounts-all-ones-genes

Conversation

@MMatinGerami

Copy link
Copy Markdown

Reference Issue or PRs

Refs #491 (bug 6 only: "poscounts size factors leave out genes whose positive counts are all 1").

What does your PR implement? Be specific.

DeseqDataSet.fit_size_factors("poscounts") filtered usable genes with (~np.isinf(logmeans)) & (logmeans > 0). logmeans is the mean of log(count) over all samples with zeros contributing 0, so a gene whose positive counts are all 1 has logmeans == 0 and was dropped from the median. The docstring says the method "will only exclude genes which have all-0 values", and DESeq2's geoMeanNZ keeps such genes (estimateSizeFactorsForMatrix filters on is.finite(loggeomeans) & cnts > 0). These genes are common in the sparse single-cell and metagenomic data that poscounts is meant for, and their omission shifts every size factor.

The filter is now (self.X > 0).any(axis=0), which keeps every gene with at least one positive count. All-zero genes are still excluded, and the values on the existing r_test_size_factors_poscount.csv fixture are unchanged.

A test on a 4 x 6 count matrix with one such gene checks the size factors against DESeq2 1.52.0 estimateSizeFactors(type = "poscounts"), with and without that gene; it fails on main and passes with this change. pytest tests passes (66 tests), ruff and mypy are clean.

LLM usage: Claude Code (Anthropic) helped draft the patch and test; I reviewed, ran and verified every changed line locally.

The poscounts filter kept genes with logmeans > 0, where logmeans is the
mean of log counts over all samples with zeros contributing 0. A gene whose
positive counts are all 1 has logmeans exactly 0 and was dropped, although
the docstring says only all-zero genes are excluded and DESeq2's geoMeanNZ
keeps it. Filter on genes with at least one positive count instead.

Add a test on a small count matrix whose expected size factors come from
DESeq2 1.52.0 estimateSizeFactors(type = "poscounts").

Refs scverse#491 (bug 6).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant