# flashier utils Interpret a [flashier](https://willwerscheid.github.io/flashier/) matrix factorization. After one call you get a *view*: a named samples × factors activity matrix and a named features × factors effects matrix that share factor columns and reconstruct the fit. From a view you can rank the features that drive each factor, plot activity across samples, summarize and test factors against sample metadata, back-project a group contrast into feature units, and check posterior uncertainty, stability and held-out prediction. ## Installation Requires R 4.3 or later and flashier 1.0.60 or later. The install pulls the pinned flashier commit (`willwerscheid/flashier@fd44811`). CRAN flashier 1.0.7 is not enough: it rejects data with an all-missing row or column, which masked [`factor_holdout()`](https://mdmanurung.github.io/flashier-utils/reference/factor_holdout.md) creates, and it lacks `flash_plot_scree()`. The committed article tables and every recorded `basis_id` come from flashier 1.0.60. ``` r install.packages("remotes") remotes::install_github("mdmanurung/flashier-utils") ``` Optional packages unlock some functions: `psych` and `clue` for [`factor_replicability()`](https://mdmanurung.github.io/flashier-utils/reference/factor_replicability.md) and [`factor_stability()`](https://mdmanurung.github.io/flashier-utils/reference/factor_stability.md); `limma` or `variancePartition` for the matching [`test_factor_association()`](https://mdmanurung.github.io/flashier-utils/reference/test_factor_association.md) engines; `gbcd` for [`fit_gbcd_programs()`](https://mdmanurung.github.io/flashier-utils/reference/fit_gbcd_programs.md); `fastTopics` for [`test_gom_de()`](https://mdmanurung.github.io/flashier-utils/reference/test_gom_de.md); `harmony` for [`harmony_assignments()`](https://mdmanurung.github.io/flashier-utils/reference/harmony_assignments.md). Each page in the function reference names what it needs. ## Quick start Use the GTEx association z-scores bundled with flashier. Tissues occupy columns; SNP–gene pairs occupy rows. ``` r library(flashier.utils) data("gtex", package = "flashier") set.seed(1) fit <- flashier::flash(gtex, greedy_Kmax = 3, backfit = TRUE, verbose = 0) view <- standardize_factors(fit, sample_side = "columns", feature_scale = "association_z_score") plot_factor_activity(view) factor_features(view, factor = "F1", select = "largest", n = 5) ``` Your matrix needs unique row and column names. Tell [`standardize_factors()`](https://mdmanurung.github.io/flashier-utils/reference/standardize_factors.md) which side holds samples and what the values measure; the package records both and never preprocesses or rescales your data. Keep the native `fit` as well as the `view`: uncertainty functions need the fit, everything else takes the view. ## Workflow | Step | Functions | |----|----| | Remove batch shifts before fitting | [`correct_feature_batch()`](https://mdmanurung.github.io/flashier-utils/reference/correct_feature_batch.md), [`harmony_assignments()`](https://mdmanurung.github.io/flashier-utils/reference/harmony_assignments.md) | | Fit, or standardize an existing fit | [`fit_ebmf()`](https://mdmanurung.github.io/flashier-utils/reference/fit_ebmf.md), [`standardize_factors()`](https://mdmanurung.github.io/flashier-utils/reference/standardize_factors.md), [`factor_activity()`](https://mdmanurung.github.io/flashier-utils/reference/factor_activity.md), [`factor_effects()`](https://mdmanurung.github.io/flashier-utils/reference/factor_effects.md), [`factor_pve()`](https://mdmanurung.github.io/flashier-utils/reference/factor_pve.md) | | Interpret factors | [`factor_features()`](https://mdmanurung.github.io/flashier-utils/reference/factor_features.md), [`plot_factor_features()`](https://mdmanurung.github.io/flashier-utils/reference/plot_factor_features.md), [`plot_factor_weights()`](https://mdmanurung.github.io/flashier-utils/reference/plot_factor_weights.md), [`plot_factor_activity()`](https://mdmanurung.github.io/flashier-utils/reference/plot_factor_activity.md), [`plot_factor_scatter()`](https://mdmanurung.github.io/flashier-utils/reference/plot_factor_scatter.md), [`plot_factor_data()`](https://mdmanurung.github.io/flashier-utils/reference/plot_factor_data.md), [`plot_factor_embedding()`](https://mdmanurung.github.io/flashier-utils/reference/plot_factor_embedding.md), [`plot_factor_pve()`](https://mdmanurung.github.io/flashier-utils/reference/plot_factor_pve.md) | | Relate factors to metadata | [`summarize_factor_activity()`](https://mdmanurung.github.io/flashier-utils/reference/summarize_factor_activity.md), [`compare_factor_groups()`](https://mdmanurung.github.io/flashier-utils/reference/compare_factor_groups.md), [`test_factor_association()`](https://mdmanurung.github.io/flashier-utils/reference/test_factor_association.md), [`backproject_contrast()`](https://mdmanurung.github.io/flashier-utils/reference/backproject_contrast.md) | | Check uncertainty and reproducibility | [`factor_uncertainty()`](https://mdmanurung.github.io/flashier-utils/reference/factor_uncertainty.md), [`factor_intervals()`](https://mdmanurung.github.io/flashier-utils/reference/factor_intervals.md), [`factor_stability()`](https://mdmanurung.github.io/flashier-utils/reference/factor_stability.md), [`factor_replicability()`](https://mdmanurung.github.io/flashier-utils/reference/factor_replicability.md), [`factor_holdout()`](https://mdmanurung.github.io/flashier-utils/reference/factor_holdout.md) | | Transfer programs to new data | [`project_factor_activity()`](https://mdmanurung.github.io/flashier-utils/reference/project_factor_activity.md), [`project_factor_features()`](https://mdmanurung.github.io/flashier-utils/reference/project_factor_features.md) | ## Four focused tutorials | Task | Tutorial | |----|----| | Beginner: native fit, extraction, features, one plot | [Get started](https://mdmanurung.github.io/flashier-utils/articles/first-fit.html) | | Coordinates, uncertainty, group contrasts, nonnegative programs | [Advanced use](https://mdmanurung.github.io/flashier-utils/articles/advanced-use.html) | | Different priors: prediction, program agreement and known truth | [Compare priors](https://mdmanurung.github.io/flashier-utils/articles/compare-priors.html) | | Real-data interpretation and reference transfer | [Pancreas programs](https://mdmanurung.github.io/flashier-utils/articles/pancreas-programs.html) | The first uses bundled GTEx data; the middle two use explicit simulations. The pancreas example uses attributed published Jamboree data, prepared once outside package builds (about 86 MB downloaded): ``` sh FLASHIER_UTILS_PANCREAS_DIR=~/pancreas-example scripts/run-r.sh .github/scripts/prepare-pancreas.R ``` Set the same variable before running the case study. No data are downloaded by package builds. The [plot gallery](https://mdmanurung.github.io/flashier-utils/articles/plot-gallery.html) shows seventeen plotting recipes from one simulated fit, [Robustness checks](https://mdmanurung.github.io/flashier-utils/articles/robustness-checks.html) lists eight checks to run before naming a factor, [Batch correction before fitting](https://mdmanurung.github.io/flashier-utils/articles/batch-correction.html) removes cell-state-specific batch shifts, and the [function reference](https://mdmanurung.github.io/flashier-utils/reference/index.html) lists complete arguments. ## Lifecycle The package is experimental. Function names and arguments can still change before a 1.0 release; the 2.0.0 line already removed single-value arguments and renamed [`provenance()`](https://mdmanurung.github.io/flashier-utils/reference/flashier.utils-deprecated.md) and [`test_factors()`](https://mdmanurung.github.io/flashier-utils/reference/flashier.utils-deprecated.md). Every breaking change is listed in `NEWS.md`, and a renamed function keeps its old name as a deprecated alias for one release. The scientific contracts (named views, preserved orientation, conditional uncertainty semantics) are the part that is kept stable. The `flashier` version is pinned in `DESCRIPTION`; behaviour against other versions is not promised. ## Limits Unnamed fits are rejected. Native intercepts without role metadata remain ordinary factors. Group summaries are descriptive; association tests require explicit independent units. Conditional posterior uncertainty does not replace regression standard errors or biological replication. Compatibility is tested against the pinned flashier version, not every historical or future object format. ## Migrating from 1.x Version 2.0 exposes 24 public functions and makes the rest internal. Nine core functions changed positional argument order, so use named arguments, such as `factor_features(view, factor = "F1", select = "largest", n = 5)`. Defaults and calculations are unchanged; [NEWS](https://mdmanurung.github.io/flashier-utils/news/index.html) lists the removed exports and affected signatures. ## Original authors and citations flashier is by Jason Willwerscheid, Peter Carbonetto, Wei Wang and Matthew Stephens. ebnm is by Jason Willwerscheid, Matthew Stephens and Peter Carbonetto. The adapted singlecelljamboreeR feature helpers are by Peter Carbonetto and Matthew Stephens. Plotting and reconstruction workflows credit David Zemmour and the Zemmour Lab. Cite the methods used in your analysis with `citation("flashier")`, `citation("ebnm")` and the relevant optional packages. [Original authors and sources](https://mdmanurung.github.io/flashier-utils/CREDITS.md) lists the full credits and licenses. Mikhael Manurung maintains flashier.utils. ## Code of Conduct Please note that the flashier.utils project is released with a [Contributor Code of Conduct](https://mdmanurung.github.io/flashier-utils/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms. # Package index ## Prepare input - [`correct_feature_batch()`](https://mdmanurung.github.io/flashier-utils/reference/correct_feature_batch.md) : Remove batch effects from a feature matrix, cluster by cluster - [`harmony_assignments()`](https://mdmanurung.github.io/flashier-utils/reference/harmony_assignments.md) : Soft cluster assignments from Harmony ## Fit and extract factors - [`fit_ebmf()`](https://mdmanurung.github.io/flashier-utils/reference/fit_ebmf.md) : Fit a named matrix using native empirical Bayes factorization - [`fit_gbcd_programs()`](https://mdmanurung.github.io/flashier-utils/reference/fit_gbcd_programs.md) : Fit generalized binary covariance gene programs - [`standardize_factors()`](https://mdmanurung.github.io/flashier-utils/reference/standardize_factors.md) : Create matched activity and feature coordinates - [`factor_activity()`](https://mdmanurung.github.io/flashier-utils/reference/factor_activity.md) : Extract sample by factor activity - [`factor_effects()`](https://mdmanurung.github.io/flashier-utils/reference/factor_effects.md) : Extract feature by factor effects - [`factor_pve()`](https://mdmanurung.github.io/flashier-utils/reference/factor_pve.md) : Extract native factor proportions of variance explained - [`filter_cells_by_total_membership()`](https://mdmanurung.github.io/flashier-utils/reference/filter_cells_by_total_membership.md) : Filter cells by total gene-program membership ## Interpret and plot factors - [`factor_features()`](https://mdmanurung.github.io/flashier-utils/reference/factor_features.md) : Select largest and distinctive program features - [`plot_factor_features()`](https://mdmanurung.github.io/flashier-utils/reference/plot_factor_features.md) : Plot selected signed feature effects - [`plot_factor_activity()`](https://mdmanurung.github.io/flashier-utils/reference/plot_factor_activity.md) : Plot bounded sample activity with signed defaults - [`plot_factor_weights()`](https://mdmanurung.github.io/flashier-utils/reference/plot_factor_weights.md) : Plot every feature effect of a factor, ranked, with the top features labelled - [`plot_factor_scatter()`](https://mdmanurung.github.io/flashier-utils/reference/plot_factor_scatter.md) : Plot two factor activities against each other - [`plot_factor_pve()`](https://mdmanurung.github.io/flashier-utils/reference/plot_factor_pve.md) : Plot native proportion of variance explained per factor - [`plot_factor_data()`](https://mdmanurung.github.io/flashier-utils/reference/plot_factor_data.md) : Plot the observed data behind one factor - [`plot_factor_embedding()`](https://mdmanurung.github.io/flashier-utils/reference/plot_factor_embedding.md) : Display factor activity on a sample embedding - [`project_factor_features()`](https://mdmanurung.github.io/flashier-utils/reference/project_factor_features.md) : Estimate effects for new measurements with fixed existing activities - [`project_factor_activity()`](https://mdmanurung.github.io/flashier-utils/reference/project_factor_activity.md) : Transfer fixed reference programs to a new dataset ## Build and project consensus references - [`build_factor_reference()`](https://mdmanurung.github.io/flashier-utils/reference/build_factor_reference.md) : Build a consensus program reference from several datasets - [`reference_programs()`](https://mdmanurung.github.io/flashier-utils/reference/reference_programs.md) [`reference_members()`](https://mdmanurung.github.io/flashier-utils/reference/reference_programs.md) [`reference_diagnostics()`](https://mdmanurung.github.io/flashier-utils/reference/reference_programs.md) : Access a consensus reference - [`project_reference()`](https://mdmanurung.github.io/flashier-utils/reference/project_reference.md) : Project query data onto a consensus reference ## Compare samples and conditions - [`summarize_factor_activity()`](https://mdmanurung.github.io/flashier-utils/reference/summarize_factor_activity.md) : Summarize activities by explicit metadata groups - [`compare_factor_groups()`](https://mdmanurung.github.io/flashier-utils/reference/compare_factor_groups.md) : Compare two groups descriptively in matched factor and feature space - [`compare_prior_fits()`](https://mdmanurung.github.io/flashier-utils/reference/compare_prior_fits.md) [`print(`*``*`)`](https://mdmanurung.github.io/flashier-utils/reference/compare_prior_fits.md) [`plot(`*``*`)`](https://mdmanurung.github.io/flashier-utils/reference/compare_prior_fits.md) : Compare saved feature programs and their joint coverage - [`test_factor_association()`](https://mdmanurung.github.io/flashier-utils/reference/test_factor_association.md) : Test continuous factor activities using an explicit inferential engine - [`test_gom_de()`](https://mdmanurung.github.io/flashier-utils/reference/test_gom_de.md) : Grade-of-membership differential expression with fixed memberships - [`backproject_contrast()`](https://mdmanurung.github.io/flashier-utils/reference/backproject_contrast.md) : Back-project a declared factor contrast into feature units - [`validate_backprojection()`](https://mdmanurung.github.io/flashier-utils/reference/validate_backprojection.md) : Compare reconstructed and directly observed feature contrasts ## Check uncertainty and prediction - [`factor_uncertainty()`](https://mdmanurung.github.io/flashier-utils/reference/factor_uncertainty.md) : Extract native posterior standard deviations in a matched basis - [`factor_intervals()`](https://mdmanurung.github.io/flashier-utils/reference/factor_intervals.md) : Conditional equal-tail intervals from the native sampler - [`factor_stability()`](https://mdmanurung.github.io/flashier-utils/reference/factor_stability.md) : Refitting stability under explicit biological-unit resampling - [`factor_replicability()`](https://mdmanurung.github.io/flashier-utils/reference/factor_replicability.md) : Compare independently fitted feature programs - [`factor_holdout()`](https://mdmanurung.github.io/flashier-utils/reference/factor_holdout.md) : Evaluate training programs on held-out biological units ## Authors and sources - [`factor_provenance()`](https://mdmanurung.github.io/flashier-utils/reference/factor_provenance.md) : Inspect code origins and runtime dependencies # Articles ### Four focused tutorials - [Get started with a native flashier fit](https://mdmanurung.github.io/flashier-utils/articles/first-fit.md): - [Advanced use: coordinates, uncertainty, contrasts and nonnegative programs](https://mdmanurung.github.io/flashier-utils/articles/advanced-use.md): - [Case study: compare priors and recovered programs](https://mdmanurung.github.io/flashier-utils/articles/compare-priors.md): - [Case study: interpret and transfer pancreas programs](https://mdmanurung.github.io/flashier-utils/articles/pancreas-programs.md): ### Plot gallery - [Plot gallery](https://mdmanurung.github.io/flashier-utils/articles/plot-gallery.md): Choose a native flashier or flashier.utils plot from seventeen checked examples. ### Factorization case study - [EBMF versus cNMF: scores, loadings and reproducibility](https://mdmanurung.github.io/flashier-utils/articles/ebmf-cnmf-comparison.md): A bounded PBMC case study plus a planted-truth simulation: prior support, factor matching, held-out prediction and refit stability. ### Robustness checks - [Robustness checks for an EBMF fit](https://mdmanurung.github.io/flashier-utils/articles/robustness-checks.md): Eight runnable checks, each mapped to one exported function, before you trust a factor. - [Batch correction before fitting](https://mdmanurung.github.io/flashier-utils/articles/batch-correction.md): Remove cell-state-specific batch shifts from simulated expression with correct_feature_batch(), then fit EBMF. ### AI assistants - [Use flashier.utils with AI assistants](https://mdmanurung.github.io/flashier-utils/articles/ai-assistants.md): Install the flashier.utils agent skill in Claude Code or another coding agent, or point any assistant at llms.txt.