Rework perturbation spaces around a perturbation-level API#1032
Merged
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1032 +/- ##
==========================================
- Coverage 78.00% 77.99% -0.02%
==========================================
Files 50 50
Lines 6557 6694 +137
==========================================
+ Hits 5115 5221 +106
- Misses 1442 1473 +31
🚀 New features to boost your workflow:
|
Every perturbation space now returns one observation per perturbation and composes with the others, and the shared base class gains operations that act directly on a perturbation space. Phase 1 (consolidation): - MLPClassifierSpace averages its penultimate-layer activations per perturbation instead of returning one embedding per cell. - Classifiers default to target_col="perturbation" and emit the label under target_col with perturbation-named obs_names, so spaces chain cleanly. - Reproducible random_state (int / Generator / RandomState / None via the new RandomStateLike type), sparse-aware JAXDataset, shared obs-carry helpers, and typing cleanup. Phase 2 (distances + neighbors): - DistanceSpace wraps Distance.pairwise into a perturbation space (matrix in .X and .obsp["distances"]). - PerturbationSpace.nearest_perturbations and plot_similarity. Phase 3 (new capabilities): - EmbeddingSpace ingests external per-perturbation embeddings. - evaluate_combinations scores an additive model against measured combinations. - dose_response quantifies effect size versus dose. Also upgrades DBSCANSpace to HDBSCANSpace and updates the tutorial (submodule). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Zethson
force-pushed
the
feature/pert_spaces
branch
2 times, most recently
from
July 6, 2026 12:39
ce99aaf to
2adba76
Compare
PerturbationSpace.plot_similarity references seaborn, but seaborn was not in the intersphinx mapping, so the nitpicky RTD build failed. Add seaborn to intersphinx and reference seaborn.clustermap (which has an inventory target) for both the kwargs and the returned grid. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Zethson
force-pushed
the
feature/pert_spaces
branch
from
July 6, 2026 12:40
2adba76 to
28caf3e
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.
Reworks
pertpy's perturbation space module so that every space returns one observation per perturbation and the spaces compose with each other, and adds distance/embedding spaces plus combination and dose analyses.MLPClassifierSpaceaverages its penultimate-layer activations per perturbation (was one embedding per cell).target_col="perturbation"and emit the label undertarget_colwith perturbation-namedobs_names, soclassifier → distance/cluster/neighborschains work.random_stateacceptingint | Generator | RandomState | None(newRandomStateLikeinpertpy/_types.py).JAXDataset(per-batch densification), shared obs-carry helpers, and typing cleanup (str | None, dropped# type: ignores).DistanceSpace— wrapsDistance.pairwiseinto a perturbation space (matrix in.Xand.obsp["distances"]), feeding clustering/neighbors directly.PerturbationSpace.nearest_perturbations— rank perturbations by proximity (mechanism-of-action lookup).PerturbationSpace.plot_similarity— clustered heatmap of perturbation distances.EmbeddingSpace— ingest an external per-perturbation embedding (e.g. scGPT/Geneformer gene embeddings).evaluate_combinations— score an additive model (effect(A)+effect(B)) against the measured combination effect.dose_response— effect size of each perturbation versus dose.DBSCANSpace→HDBSCANSpace(sklearnHDBSCAN).Breaking changes (clean break, no shims)
target_coldefault"perturbations"→"perturbation"; output column followstarget_colinstead of the hardcoded"perturbations".MLPClassifierSpacereturns perturbation-level (not cell-level) embeddings.DBSCANSpaceremoved in favor ofHDBSCANSpace.