mofa-r

Fit MOFA2 multi-omics factor models from R and plot factors, weights, and variance explained.

1|Updated Nov 20, 2025
One-click install
npx skills add https://github.com/tony-zhelonkin/scio --skill mofa-r-tony-zhelonkin
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: mofa-r
Source: https://github.com/tony-zhelonkin/scio/tree/main/skills/mofa-r
Command: npx skills add https://github.com/tony-zhelonkin/scio --skill mofa-r-tony-zhelonkin

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires MOFA2, mofapy2, reticulate, basilisk, ggplot2.

What problem does it solve? Multi-omics studies need a way to decompose several assay matrices into shared latent factors, but wiring R/Bioconductor objects to the Python mofapy2 engine and interpreting the results correctly (no biplot, non-partitioned R², sign ambiguity) is error-prone. ## Core Features & Use Cases - R-side model fitting: Build MOFA objects from named matrix lists, MultiAssayExperiment, or long data.frames with create_mofa, configure data/model/training options, and run the mofapy2 engine via basilisk or reticulate. - Downstream analysis: Extract factors and weights, correlate factors with sample covariates, summarise factors per group, and compute per-view per-factor variance explained. - ggplot2-native plotting: Produce factor scatter plots, weight scatter and bar plots, data heatmaps, and variance-explained heatmaps as composable ggplot objects. - Use Case: Given RNA-seq and ATAC-seq matrices for the same samples, fit a 10-factor MOFA model from R, correlate the factors with clinical covariates, and plot the top weights driving each factor. ## Quick Start Fit a MOFA2 model from my named list of omics matrices with 10 factors and a fixed seed, then plot factors 1 and 2 colored by condition.

Frequently Asked Questions about mofa-r

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fit a MOFA2 model in R?▼

Create a model with create_mofa() from a named list of feature-by-sample matrices, configure it with prepare_mofa() using the default data, model, and training options, then call run_mofa() which invokes the mofapy2 Python engine and writes an HDF5 output file.

MOFA2 R vs mofapy2 Python: which should I use?▼

Use the MOFA2 R bindings when your pipeline is in R/Bioconductor, your inputs are SingleCellExperiment or MultiAssayExperiment objects, or you want ggplot2-native plots. Use mofapy2 directly when the rest of the workflow is Python-based; both share the same engine and HDF5 format.

Why does run_mofa() fail with 'mofapy2 not found'?▼

MOFA2 calls the Python mofapy2 engine, so a Python environment is required. Either let basilisk provision its conda env automatically on the first run_mofa() call, or point reticulate::use_python() at a Python with mofapy2 installed before loading MOFA2.

Does MOFA2 support biplots of factors and loadings?▼

No. MOFA2 has no biplot function because Z and W are scaled independently with no shared singular values. Use the L1 supplementary-projection approach instead, projecting covariate correlations or group barycenters onto the factor map.

Why does the sum of per-factor variance explained not equal the total R²?▼

Per-factor R² in calculate_variance_explained() is computed against the full data matrix, not against residuals after previous factors, so it is not a partition. Treat it as a per-factor diagnostic rather than an additive variance budget.

Why do factor signs or orders flip between MOFA2 runs?▼

The bilinear model Y ≈ ZW^T is sign-flip equivariant per factor, and factors are only sorted post-hoc by total R². For cross-run comparisons, impose a canonical sign, for example flipping so the largest absolute loading is positive.