mofa-mofax

Inspect trained MOFA+ HDF5 models in Python with factor, weight, and variance accessors.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires mofax, h5py, numpy, pandas, seaborn, matplotlib.

What problem does it solve? After training a MOFA+ model with mofapy2 or MOFA2, inspecting the resulting HDF5 file requires low-level h5py code. This Skill provides DataFrame-level accessors and ready-made plots for factors, weights, variance explained, and MEFISTO covariates without re-implementing the MOFA2 R plot family. ## Core Features & Use Cases - Read-side model access: Load a trained model.hdf5 in readonly mode and pull Z factors, per-view W weights, R² tables, and sample metadata as pandas DataFrames. - Plot library: Generate seaborn-based factor scatters, weight heatmaps, R² barplots, and MEFISTO interpolation or smoothness plots. - MEFISTO support: Access covariates, interpolated factors, group kernels, and per-factor smoothness for spatiotemporal models. - Use Case: You trained a multi-omics MOFA+ model on RNA and methylation views and want to plot Factor1 versus Factor2 colored by condition, list the top 20 weight features per view, and export the per-factor variance-explained table for a report. ## Quick Start Load my trained model.hdf5 with mofax, show the variance explained per factor and view, and plot Factor1 against Factor2 colored by sample condition.

Frequently Asked Questions about mofa-mofax

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

FAQPage Schema
How do I load a trained MOFA+ model in Python?▼

Use mofax.mofa_model("model.hdf5") to open the file in readonly mode, then call get_factors(df=True), get_weights(df=True), and get_r2() to retrieve factors, weights, and variance explained as pandas DataFrames. Call model.close() when finished to release the HDF5 handle.

How do I plot MOFA factors and weights in Python?▼

mofax provides seaborn-backed wrappers such as plot_factors, plot_weights, plot_weights_heatmap, and plot_r2 that mirror the MOFA2 R plot family. Pass the loaded mofa_model object plus factor and view names to generate the figures directly.

Can mofax train or fit a MOFA model?▼

No, mofax is strictly read-only and cannot fit models. Train with mofapy2 in Python or MOFA2 in R first, then use mofax to inspect the resulting HDF5 file.

Why does get_weights return a dict instead of a DataFrame?▼

Weights are stored per view, so get_weights(df=True) returns one DataFrame per view keyed by view name. Concatenate them with pd.concat(w_dict, names=["view", "feature"]) if a single combined frame is needed.

Why is model.metadata empty after loading?▼

mofapy2 does not always serialize samples_metadata into the HDF5 file. Build the DataFrame yourself and assign it via model.metadata = my_df, then color plots by those columns.

When should I not use mofax for MOFA analysis?▼

Avoid mofax when you need to fit a model, and do not expect a biplot since Z and W have independent scalings and cannot share axes. Also remember it holds an open readonly HDF5 handle that must be closed explicitly.