Add pathway-informed TCGA-BRCA multi-omics tutorial - #206
Conversation
for more information, see https://pre-commit.ci
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #206 +/- ##
==========================================
- Coverage 90.60% 90.60% -0.01%
==========================================
Files 56 56
Lines 5739 5746 +7
==========================================
+ Hits 5200 5206 +6
- Misses 539 540 +1
🚀 New features to boost your workflow:
|
| self._device = map_location | ||
| # map_location may be None (e.g. MOFAFLEX.load without an explicit device); fall back to the | ||
| # default device so methods that need it (e.g. PCGSE in get_significant_annotations) still work. | ||
| self._device = default_torch_device(map_location) |
There was a problem hiding this comment.
I don't think this works. map_location is currently only used by the GP prior for the GP state (required for get_gps with new covariates). If map_location=None, the GP state will be loaded on GPU, but self._device will be CPU, so get_gps will fail. I think a better solution is setting map_location=state["train_opts"]["device"] in _core/mofaflex.py:554
| model: MOFAFLEX, | ||
| group_by: Literal["group", "view"] = "group", | ||
| term: str | None = None, | ||
| annotated_only: bool = False, |
There was a problem hiding this comment.
Can we generalize that? For example, passing in a predicate function that filters factors by name?
| ): | ||
| df = df.assign(feature=lambda x: x.feature.str + "_" + x.view.str) | ||
| df = df.assign(feature=lambda x: pd.Categorical(x.feature, categories=x.feature.unique())) | ||
| # A feature can be among the top features of several factors. With a single global feature category, those |
There was a problem hiding this comment.
this is addressed in a cleaner way by #174. There doesn't seem to be a timeline for plotnine 0.16 release, but if we decide to release mofaflex 0.2 before that, worst case we can depend on plotnine>=0.16a10 (or whatever the current pre-release will be by then). Or we can finalize and merge #174 now, with the caveat that we may need to regenerate the test baseline images a few times before the plotnine 0.16 final release.
| seed=42, | ||
| batch_size=batch_size, | ||
| n_particles=n_particles, | ||
| save_path=save_path, |
There was a problem hiding this comment.
in that case, there's no need for the with chdir... context
Fix `map_location` Replace `annotated_only` with `factor_filter`
| def _results_to_df( | ||
| self, | ||
| results: Mapping[str, np.ndarray], | ||
| results: Mapping[str, np.ndarray | pd.DataFrame], |
There was a problem hiding this comment.
why these changes? This method is explicitly meant to convert arrays to data frames, and every dynamic API function returning factors (marked by has_factors=True in its API properties) should be returning an array. If that is not the case somewhere, that should be changed in the dynamic API of the respective prior.
There was a problem hiding this comment.
Its a slip up from the other branch I'm working on related GPs over features, will fix right away..
ilia-kats
left a comment
There was a problem hiding this comment.
Just a few tweaks to the changelog, and then it's good to go.
| ### Fixed | ||
| - `pl.factor_significance` now ranks factors by the variance they explain within the selected `views`/`groups`, | ||
| rather than the overall variance, so restricting `views` reorders the plot accordingly. | ||
| - `pl.top_weights` orders features per facet, fixing the scrambled ordering when a feature is among the top |
There was a problem hiding this comment.
no longer true with this PR.
| - Training with sparse inputs and minibatching is about 1.5 times faster. | ||
|
|
||
| ### Fixed | ||
| - `pl.factor_significance` now ranks factors by the variance they explain within the selected `views`/`groups`, |
There was a problem hiding this comment.
I would put this in Changed.
Adds a pathway-informed TCGA-BRCA multi-omics tutorial, plus the supporting plotting/loading changes the tutorial relies on:
pl.variance_explained: add afactor_filterpredicate to plot only factors whose names satisfy it (e.g. the annotation-informed factors of anInformedHorseshoeprior, dropping the dense uninformed ones).pl.factor_significance: rank factors by the variance explained within the selectedviews/groups, rather than the overall variance, so restrictingviewsreorders the plot accordingly.MOFAFLEX.load: whenmap_locationis omitted, fall back to the device the model was trained on (stored in the file) instead of the live default, so methods that need the device (e.g.pl.factor_significance/PCGSE, GP priors) work on reloaded models.Testing
variance_explained_factor-filtercovering thefactor_filterpredicate.MOFAFLEX.loadwithoutmap_locationreloads onto the serialized training device (incl. a GP-prior case viatest_load_uses_training_device_for_gp), and that PCGSE (get_significant_annotations) works on the reloaded model.