Skip to content

Support non-perturbed scRNA-seq and mouse data - #20

Open
OlgaPushkarev wants to merge 4 commits into
ruff-formatfrom
nonperturbed-mouse-data
Open

OlgaPushkarev wants to merge 4 commits into
ruff-formatfrom
nonperturbed-mouse-data

Conversation

@OlgaPushkarev

@OlgaPushkarev OlgaPushkarev commented Oct 10, 2026 •

Copy link
Copy Markdown

Summary

Lets the pipeline run on scRNA-seq data without perturbations (no guide information) and on mouse data. Human perturbation runs are unchanged.

Third of three stacked PRs. It is based on #19 (ruff format), which is based on #18 (lab-content cleanup). Merge those first; GitHub then retargets this PR to main. Replaces #17.

Non-perturbed data (no guides)

  • K-selection plots: new --no_perturbation and --no_trait flags skip the perturbation and trait inputs and their plots. The regulator row shared by both panel functions is moved into one helper and hidden when there is no perturbation data.
  • Program analysis: a missing uns['guide_targets'] is handled; perturbed-gene annotations are left empty, with a message.
  • Excel summary: the Targets Summary sheet (and the specificity scores it writes) is skipped when there are no guides. The gene-symbol lookup falls back to var_names when the --gene_names_key column is absent.
  • Evaluation: with --Perform_perturbation, every input h5mu is checked for guide information before any metric runs, with a clear error. A wrong --prog_key is reported as such.

Mouse data

  • Curated ortholog mapping (new src/Stage2_Evaluation/A_Metrics/src/orthologs.py): mouse genes are matched to the human Enrichr libraries and to human gene summaries through orthologs (the union of MGI HOM_MouseHumanSequence and Ensembl BioMart homologs), instead of upper-casing symbols. Upper-casing misses orthologs with different names (e.g. Zfp451 → ZNF451, mouse H2-* → human HLA-*) and sometimes picks a non-orthologous human gene.
    • Cache: the table is downloaded once and cached in src/Stage2_Evaluation/Resources/; --ortholog_table pins a fixed copy.
    • Download safety: a truncated BioMart response is rejected (completion stamp required). The cache is written atomically, and a failed download points to --ortholog_table.
    • Mapping rules: mouse genes without a human ortholog are excluded from enrichment. A gene with several human orthologs contributes to all of them; a human gene with several mouse orthologs keeps the highest loading. MSigDB mouse gene sets keep mouse symbols.
  • --organism: accepts only human or mouse (case-insensitive) in evaluation and the Excel summary.
  • Excel summary: with --organism mouse, each gene is annotated with its human orthologs' MyGene summaries, in a new Human ortholog column.
  • Evaluation: trait (GWAS) enrichment is human-only (OpenTargets) and is skipped with a message for mouse data.
  • Plotting utilities: the MyGene helpers now honor their species argument.

Other changes

  • ensure_umap reuses embeddings stored as obsm['UMAP'] / obsm['PCA'] (e.g. Seurat conversions) instead of computing a different UMAP.
  • Docs: README section "Non-perturbed and mouse data" (per-stage flags), parameter tables, and CHANGELOG entries. ⚠️ Mouse enrichment output changes.

Testing

  • New tests (synthetic data, offline):

    • tests/Script/test_non_perturbed.py
    • tests/Script/Stage2_Evaluation/test_orthologs.py
    • tests/Script/Stage3_Interpretation/A_Plotting/Program/test_ensure_umap.py

    25 tests, all passing. Against the previous code, the tests for new behavior fail and the tests for unchanged behavior pass.

  • Regression:

    • The existing Stage 2 metrics and Stage 3 suites give identical per-test outcomes before and after.
    • On human test data, the Reactome and GO enrichment outputs are byte-identical to main's.
  • End to end: a 4,000-cell subsample of a public mouse endothelial scRNA-seq dataset without perturbations ran through inference, evaluation, K-selection, program analysis and the Excel summary. With ortholog mapping:

    • An MHC class II program (top genes Cd74, H2-Ab1, H2-Aa, H2-Eb1, Ciita) is correctly annotated as antigen presentation. Upper-casing had dropped its H2-* genes and returned "regulation of cell migration".
    • 90% of top program genes get a gene summary.
  • An independent review of the changes was done before opening.

Pre-existing issues (not changed here)

  • 6 Stage 3 tests and 1 torch inference test fail on main because they are stale (see also Fix stale tests and empty significant-programs crash #15).
  • gseapy's Biomart client currently fails ("Method Not Allowed") because www.ensembl.org redirects. get_idconversion uses it for Ensembl-ID-to-symbol conversion and falls back silently. The new ortholog code queries an Ensembl mirror directly.
  • cNMF_program_analysis.py rejects --output_format HTML without --perturb_path_base, although the HTML exporter now handles missing perturbation data. The README documents using PDF/SVG for now; relaxing the guard could be a follow-up.

🤖 Generated with Claude Code

OlgaPushkarev and others added 4 commits October 9, 2026 17:33
Non-perturbed data (no guide information):
- K-selection: new --no_trait / --no_perturbation flags skip the trait and
  perturbation inputs and plots; the shared regulator row is factored into
  _plot_regulator_row and hidden when there is no perturbation data.
- Program analysis: tolerate a missing uns['guide_targets'].
- Excel summary: skip the Targets Summary sheet (and the specificity
  scores it writes) when there are no guides; fall back to var_names when
  the gene symbol column is absent.
- Evaluation: fail early with a clear message when --Perform_perturbation
  is requested without guide information.

Mouse data:
- Mouse genes are matched to human gene-set libraries and gene summaries
  through curated orthologs (union of MGI and Ensembl, new orthologs.py)
  instead of upper-casing symbols. The table is downloaded once and cached
  in src/Stage2_Evaluation/Resources/; --ortholog_table pins a fixed copy.
  Genes without a human ortholog are excluded from enrichment; one-to-many
  orthologs keep all human genes. MSigDB mouse gene sets keep mouse symbols.
- Excel summary: --organism mouse annotates genes with their human
  orthologs' MyGene summaries and a 'Human ortholog' column.
- Evaluation: trait (GWAS) enrichment is human-only and is skipped with a
  message for other organisms.
- Plotting utilities: honor the species argument of the MyGene helpers.

Human runs are unchanged: existing Stage 2/3 tests give identical
per-test outcomes before and after, and human evaluation outputs match
apart from gene order within the Genes column and last-digit rounding.

Tests: tests/Script/test_non_perturbed.py and
tests/Script/Stage2_Evaluation/test_orthologs.py (synthetic data, offline).
Docs: README section on non-perturbed and mouse data, parameter tables.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Data converted from Seurat stores its embeddings as obsm['UMAP'] /
obsm['PCA'] (often as DataFrames), which scanpy does not see, so program
and perturbed-gene plots recomputed a different UMAP. ensure_umap now
copies such embeddings to 'X_umap' (first two columns) / 'X_pca' before
deciding whether to compute one. Existing X_umap/X_pca entries and the
original keys are left untouched; files without these keys behave as
before.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- orthologs.py: require BioMart's completion stamp so a truncated Ensembl
  response is rejected instead of cached; write the cache atomically
  (temp file + os.replace) so parallel jobs never read a partial table;
  on download failure, point to --ortholog_table.
- Excel summary: map all top genes to orthologs once instead of once per
  program.
- --organism accepts only human/mouse (case-insensitive) in evaluation and
  the Excel summary.
- Evaluation checks for guide information in every h5mu before computing
  any metric when --Perform_perturbation is set.
- run_add_umap.sh: correct the header (no SBATCH_MAIL_USER; create the log
  directory on the manual path); search_nature.py: generic data-source text.
- Docs: CHANGELOG entries; README notes that program plots without
  perturbation results need PDF/SVG output and that custom gene sets for
  mouse data must use human symbols; Human ortholog column documented.
- Tests for the download handling, organism validation, and the early
  guide check.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- Evaluation guide pre-check: if the --prog_key modality is not in the
  h5mu, say so instead of reporting missing guide information.
- orthologs.py: remove the temporary file if writing the cache fails.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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