Repository navigation
Add the guides of Compare conditions, with executed figures - #61
Merged
Merged
Conversation
parashardhapola
force-pushed
the
50-sumrank
branch
from
October 26, 2026 21:11
941b81f to
98e2e49
Compare
Six short guides, each an executed notebook with the figures users expect: normalization, filtering and sample quality; genes that change in each cell type (Kang et al. 2018); repeated measures and donors (dream, Kenward-Roger, F-tests, variance partitioning); cell-type composition; gene sets and pathways (fry, roast, camera, over-representation, GSEA); and pathway and regulator activity (CollecTRI, PROGENy, GSVA). The simulated tutorial moves to Start here as "From cells to results".
parashardhapola
marked this pull request as ready for review
October 26, 2026 21:16
parashardhapola
force-pushed
the
38b-compare-conditions-guides
branch
from
October 26, 2026 21:16
a3ef790 to
024a278
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The section Compare conditions had one simulated tutorial. It now has six short guides, one per question: normalization, filtering and sample quality; genes that change in each cell type; repeated measures and donors; cell-type composition; gene sets and pathways; pathway and regulator activity. Each is an executed notebook whose cells mostly draw the figures users know from limma, edgeR, speckle, variancePartition, fgsea, GSVA and decoupler through
cytepool.plotting, ends with a short Choices section, and links to How the statistics work for the theory. Real data (Kang et al. 2018) where it shows the method, simulation where the truth must be known. Documentation only: no library code changed.Pages
check-outputsin CIguides/normalization_and_quality.ipynbfilter_by_expression, and how many genes the paired design and the condition keep; TMM, RLE, upper-quartile and DESeq2 factors (the interferon response takes a fifth of the stimulated libraries; factors 1.19 against 0.83); plotSA after robust moderation (217 outlying variances: hemoglobin and response genes; prior df 11.4 to 27.7); sample quality weights for the noisy bulk sample (0.30) and their effect on calls against the truth;Design.checkon a mislabelled sampleplot_mds(2 panels),plot_mean_variance(2),plot_residual_variances,plot_mds+plot_sample_weightskang2018,simulated_bulkguides/genes_per_cell_type.ipynbmin_cellsleaves out; the paired design and its check;limma_voomon all eight cell types; MD and volcano plots and a top table of the monocytes; voom against trend, with each cell type's spread of library sizes; adjustment within or across cell types (across is not stricter everywhere: the monocytes lose calls, the others gain)plot_cell_numbers,plot_significant_genes,plot_md+plot_volcano,plot_significant_genes(2 panels, twice)kang2018guides/repeated_measures.ipynbdream_voomwith Kenward-Roger and an F-test across time points, calls against the truth, the calibration of the test between donors against profiles pooled by donor; variance partitioning of the monocytesplot_p_values(2 panels),plot_variance_fractions+plot_gene_variance_fractionskang2018, page simulationguides/composition.ipynbpropelleron the simulated study where only the monocytes change: every cell type tests significant, and the proportion ratios (0.77 to 0.81 for the others) show why; the same test within the lymphocytes finds nothing; paired against unpaired designs, logit against arcsineplot_composition,plot_proportions(twice)simulated_pbmcguides/gene_sets.ipynbplot_barcode,plot_gene_sets,plot_over_representation,plot_enrichment,plot_gsea_tablekang2018,hallmark_interferon_alpha, CollecTRI (downloaded on first use)guides/pathway_activity.ipynbplot_top_activities,plot_activities(twice),plot_pathway_scoreskang2018, CollecTRI and PROGENy (downloaded on first use)collectri()is called with its default, the licence level a company may use, and the pages say so. Every figure has a description for its alternative text. Warm execution takes 2 to 5 s per page (12 s cold for the first).Changes to shared files
docs/source/myst.yml: the six guides under Compare conditions, in the agreed order with Pathway and regulator activity added after Gene sets and pathways;differential_expression.ipynbmoved to Start here, after the Quick start, as "From cells to results".docs/source/differential_expression.ipynb: its heading becomes "From cells to results", and a sentence points to the guides. Prose only; its outputs and code fingerprint are unchanged (check-outputs: current).docs/source/index.md: the tutorial's link text, and the "Where to read" cells of five questions (genes per cell type, composition, pathways and regulators, donor variation, effects of time and context) point to the guides.docs/coverage_exemptions.toml: 14[planned]entries removed, now covered:plot_barcode,plot_cell_numbers,plot_composition,plot_gene_sets,plot_md,plot_mds,plot_mean_variance,plot_p_values,plot_proportions,plot_residual_variances,plot_sample_weights,plot_significant_genes,plot_volcano,Table.to_pandas..github/workflows/docs.yml:guides/compositionappended to thecheck-outputspages; the five other guides need the Kang download.tests/test_documentation.pyalready covers the new notebooks (80 tests, 74 before).Design notes
differential_expression.ipynbstays the simulated tutorial. The guide on genes per cell type is a new page on the Kang data rather than a rewrite of it, because the two answer different needs: the tutorial walks from simulated cells to a cube, a result and its provenance trace, with the truth known, which is what the agreed quick start becomes; the guide answers one question on real data with its choices. The tutorial also holds what no other page has yet (tracing a result back to the cube's profiles, a rank-deficient cell type, a cell type that is not fitted, which the guide links to), and it runs without downloads in CI. It moved to Start here, so that Compare conditions holds guides only; the quick start pull request can take it over and remove it.read_gmtworks under its provider's terms.gsea's warning that the MYC regulon (383 genes, enrichment score -0.25) has too few random scores of its sign; the text explains it. More permutations (10,000) did not change it.Findings
limma_voomon the profiles pooled by donor (Cube.collapse_samples("donor")) gave 4.8 to 5.0%. In runs with a constant dispersion it was 9.5 to 10.5% with 3 donors per group and 6.9% with 8, and there the unmoderated Kenward-Roger tests (fixed_effect_testson the same fits) gave 3.6 to 5.2% and the pooled profiles 4.2 to 5.5%. Run as a black box on the same counts (CytePool's filtered genes, library sizes times TMM factors), variancePartition 1.36.2'svoomWithDreamWeights,dream(Kenward-Roger at 18 samples),eBayesandtopTable(coef = "diseasepatient")give the same 8.83%, with p-values within 1.0e-5 (relative) ofdream_voom(span=0.5). A likely cause: the moderated tests take the test's degrees of freedom plus the prior's, while the prior describes the variance within donors and a contrast between donors rests mostly on the donor variance, estimated from six donors. The page shows it (cells 2 to 4) and recommends pooling by donor for such questions; the mixed-models statistics page anddream_voom's docstring could say it too. Reproducer: the imports and the second to fourth code cells ofdocs/source/guides/repeated_measures.ipynb, whose simulation needs no download.plot_significant_genescan draw the count of the longest bar over the left frame. It sets the limits to 1.2 times the longest bar, which leaves too little room for a five-character label at 8 points in a narrow panel:kanganddesignas on the genes page). In a single default figure the count "1,549" oflimma_voomtouches it.Design.checkdoes not flag numeric donor ids. Ids such as 101, 1015, 1016 enter the model as one slope without a warning, becausenumeric_codesasks for consecutive values:Awkward APIs, for the API and language pull request
VoomResult, not a cube's cell type or aDifferentialExpressionResultasgsea,over_representation,gsvaandulmdo: the gene-set page repeatslimma_voom's steps by hand (layer,filter_by_expressionwith the design,tmm_factors,voom, the kept genes' symbols), and a user whose samplesmin_cellsleft out must also subset the design.DifferentialExpressionResultkeeps no fit, so plotSA and voom's plot of alimma_voomrun need the fit redone (the quality page does it).expression_filterhas no grouping: with a paired design the design-based filter keeps genes with counts in about two samples (5,125 genes in the monocytes, 3,651 with the condition as the group), anddream_voom, which filters with its fixed effects, tests different genes fromlimma_voomon the same data.moderated_statistics(contrasts_fit(fit_linear_model(x.scores, Design(...)), design.contrasts), trend=...)andadjust_p_values, and the design is built again fromPathwayScores.samplesorActivities.profiles(two names for the same table) with the same levels and contrasts; the pages build the samelevelsandcontrastsfor four designs. A way to reuse a design on another sample table, and one call that tests scores, would remove most of it.Networkbecomes aGeneSetsonly by a comprehension,GeneSets({s: list(t) for s, t in network.items()}, source=..., version=..., licence=...), which loses its provenance unless copied by hand.gene_ids(camera, fry, roast; a features column forgsvaandulmon a cube) andid_column(gsea,over_representation,ulmon a result).roastreturns one row per alternative while camera and fry return one row per set, so reading its "up" p-value takes a filter.gsea's warning recommendsn_permutations=10000, which did not help the MYC regulon here.Note for the PCA pull request
Normalization, filtering and sample quality shows the samples with
plot_mdsin "Do the samples group as expected?".plot_pcabelongs beside it (DESeq2'splotPCAof the same monocytes), with a line in the page's Choices on the MDS plot's leading fold changes against PCA's most variable genes. The page has no placeholder for it.Needed change in
THIRD_PARTY_NOTICES.mdUnder "Test, validation and documentation data", the paragraph on the documentation's data lists only the datasets of
docs/datasets.py. Two guides now download the networks: add thatdocs/source/guides/gene_sets.ipynbanddocs/source/guides/pathway_activity.ipynbcallcollectri()(both) andprogeny()(the second), which download CollecTRI and PROGENy into the cache outside the repository, and name the documentation besidecytepool/networks.pyandvalidation/activity.pyin the sections "CollecTRI" and "PROGENy".Merging
The edits to shared files are local: one appended page in the
check-outputsline ofdocs.yml(likely to meet another guide's addition on the same line), removed lines in[planned], the navigation of Start here and Compare conditions, five cells of the Overview's table, and one sentence per statistics page.Checks
make -C docs htmlwith Node.js 24 first onPATH: built, without warnings beyond Node.js's notice abouturl.parse(); the API pages list the new guides under "Used in".make -C docs check-outputs PAGES="quickstart differential_expression guides/export_cubes guides/bulk_rna_seq guides/composition": outputs current; the five Kang guides are also current when run again locally.uv run pytest tests/test_documentation.py: 80 passed.uv run python docs/coverage_report.py: 243 public names, 183 used or explained in a page, 53 exempt, 7 planned (before: 169, 53, 21); no problems.uv run ruff check docsanduv run ruff format --check docs(which include the notebooks): clean.