Skip to content

Rewrite ContextNet tutorials: runnable, reproducible, biologically framed - #2

Merged
Huangy57 merged 3 commits into
mainfrom
huangy57/contextnet-tutorials
May 20, 2026
Merged

Huangy57 merged 3 commits into
mainfrom
huangy57/contextnet-tutorials

Conversation

@Huangy57

Copy link
Copy Markdown
Collaborator

What this does

Makes the three ContextNet tutorial notebooks runnable and reproducible for a
public audience, building on the earlier "reframe around biological questions"
work (already on main). Each tutorial opens with a biological question and reads
ContextNet outputs as communication hypotheses, not proof of secretion,
receptor binding, spatial contact, or causality.

  • 01 — Getting Started: which ligands are consistent with the basal
    epithelial identity program (cell-type comparison).
  • 02 — Standard Workflow: which sender ligands track basal-cell C-vs-N change
    (within-receiver condition comparison) + ligand-target heatmaps + Sankey.
  • 03 — Multi-Condition Workflow: which L-R programs change reproducibly across
    samples (replicate-aware MultiNicheNet pseudobulk).

Reproducibility / runnability fixes

  • Portable kernel — all three notebooks switched from a private
    MultiNicheNet_v2 kernel to the standard ir IRkernel; normalized to nbformat
    4.5. Execution also supports --ExecutePreprocessor.kernel_name=ir.
  • Stale outputs / private absolute paths removed — notebooks are committed
    output-free (this is the bulk of the NB02 deletions).
  • Local-data paths — no "download-if-missing" in the executed path; NB01
    verifies the NicheNet priors are present locally and the optional Zenodo
    download lives in a clearly-labeled, non-executed cell.
  • No cross-notebook /tmp dependency — the reusable network is cached under a
    repo-local data/cache/; NB03 reuses it if present but is otherwise
    self-contained.
  • ccflowR is optional — the Sankey data table is always built and printed;
    rendering is guarded by requireNamespace("ccflowR") and degrades gracefully
    with an install hint when absent.
  • N_CORES <- 1 in NB03 by default to avoid FORK/socket failures.
  • Docs: notebooks/README.md gains data-requirements + example-data strategy +
    troubleshooting; the micromamba install guide adds the bootstrap one-shot and
    an IRkernel registration step; README.md notes the full-local-data tutorials
    and optional ccflowR.

Testing

  • Package reinstalled; check_ecosystem() clean.
  • All three notebooks execute 0-error via nbconvert (the ir kernel)
    against the full local dataset, including MultiNicheNet at n_cores = 1.
  • Targeted unit tests pass (class / import / config / validate / serialize /
    export). The full devtools::test() is expected to fail locally on
    parallel-backend and Zenodo-reaching tests; the tutorials deliberately avoid
    those modes (n_cores = 1, nichenet_database = "data").

Review

Independently reviewed before this PR — verdict ready-with-minor-fixes, zero
must-fix, all 8 tracking-issue requirements pass
. The 5 nice-to-have polish
items (cat-newline style, AUPR_c naming consistency, data-footprint note, a dead
variable, ASCII-box alignment) were applied in the final commit.

Scope

This PR carries the two remaining tutorial commits (e6e8daf, cfffd01); the
earlier reframe commit is already on main via the install-audit merge, so the
diff is tutorial/doc-only (6 files) with no package-source, license, or env
changes.

Tracking issue: settylab/sarah-nexus#27

Huangy57 and others added 3 commits May 20, 2026 00:39
… paths, optional ccflowR

- Switch all three notebooks from the private `MultiNicheNet_v2` kernel to the
  portable `ir` IRkernel; normalize to nbformat 4.5 with cell ids.
- Clear all executed outputs (removes stale private absolute paths).
- Replace the cross-notebook /tmp/contextnet_network.rds dependency with a
  repo-local data/cache/ convention; tutorial 03 is now self-contained.
- 01: replace "download-if-missing" with verify-local-priors; move the Zenodo
  download to an optional, non-executed cell. Fix defunct GetAssayData(slot=)
  -> layer= for Seurat 5.
- 03: default N_CORES <- 1 to avoid FORK/socket failures.
- Keep ccflowR optional everywhere; simplify dead-code ccflowR fallbacks.
- Docs: notebooks/README data requirements + example-data strategy +
  troubleshooting; installation guide bootstrap + IRkernel registration; README
  notes full-local-data tutorials and optional ccflowR.

All three notebooks execute end-to-end via nbconvert (ir kernel) against local
data; targeted unit tests pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Addresses the 5 nice-to-haves from the independent review (review-27); no
must-fix items, no behavior change (notebooks not re-executed).

- NB02/NB03: replace literal newlines embedded in cat() strings with "\n"
  (7 in NB02, 4 in NB03) to match NB01's style; output is byte-identical.
- NB02: harmonize the metric name to corrected AUPR / AUPR_c (bar-plot axis,
  interpretation prose, and heatmap column/legend) — the plotted column is
  aupr_corrected.
- notebooks/README: state the full ~1.8 GB data/ footprint (Seurat ~1.2 GB;
  LT matrix >250 MB), not just the LT-matrix size.
- NB03: drop the dead `contrast_col` variable in the ligand-summary cell.
- All notebooks: realign the USER CONFIGURATION ASCII box right border, and
  note that the abundance-based auto-sender set can include the receiver cell
  type itself (autocrine).

Verified: nbformat 4.5 valid, all code cells R-parse, 0 residual cat bugs,
cat() output confirmed identical.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Huangy57
Huangy57 merged commit 2271ef9 into main May 20, 2026
1 of 9 checks passed
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