Skip to contents

Which features define published pancreas programs, and how do those programs transfer to another measurement technology? This case study restores published NMF programs as a view, ranks their features, summarizes activity by cell type, then projects the fixed programs onto cells from a second platform. It adapts Peter Carbonetto’s single-cell Jamboree tutorial. The CEL-Seq2 cells originate from Muraro et al. (2016), assembled in the benchmark of Luecken et al. (2022); source pages link the original studies.

Prepare the attributed data

From a repository clone, run once outside package builds (about 86 MB downloaded; preparation loads a roughly 640 MiB sparse matrix):

FLASHIER_UTILS_PANCREAS_DIR=~/pancreas-example scripts/run-r.sh .github/scripts/prepare-pancreas.R

The helper pins Jamboree revision 6cf9aa720cc16dc543e93b36d57bc1a85555860d and records source hashes. It selects 48 reference and 24 query cells while retaining 14,528 genes. Set the same environment variable before running below. Without the cache, examples are skipped; no download runs during a package build.

cache <- readRDS(file.path(pancreas_dir, "pancreas-worked-example.rds"))
source("restore-programs.R")
view <- restore_programs(cache$reference, cache)
factor_features(view, factor = "F4", select = "both", n = 5)[,
  c("feature", "estimate", "selection")]
#> Warning: scaling = 'raw' leaves effect columns on different scales, so
#> distinctiveness is not comparable across factors; use scaling = 'ldf' with
#> d_location = 'activity'.
#>    feature  estimate   selection
#> 1      INS 1.0000000     largest
#> 2     IAPP 0.7255013     largest
#> 3     SCGN 0.6501594     largest
#> 4  SLC30A8 0.6393897     largest
#> 5    ABCC8 0.6297135     largest
#> 6      INS 1.0000000 distinctive
#> 7     IAPP 0.7255013 distinctive
#> 8    NPTX2 0.5859416 distinctive
#> 9     MAFA 0.5125813 distinctive
#> 10 ADCYAP1 0.3997708 distinctive
plot_factor_weights(view, factors = c("F4", "F1"), n_label = 8)
Ranked gene effects for programs F4 and F1 with the eight largest genes labelled.

Ranked gene effects for two restored programs. Labels mark the eight largest effects.

restore_programs() restores published NMF coordinates through public native initialization; it does not claim an independently fitted model. Largest effects show contribution; distinctive effects depend on the selected competitors and coordinate scaling. Biological labels need evidence beyond a ranking.

metadata <- cache$metadata[match(rownames(view$activity), cache$metadata$id), ]
stopifnot("metadata rows match activity rows" = identical(as.character(metadata$id), rownames(view$activity)))
metadata$sample <- as.character(metadata$id)
head(summarize_factor_activity(view, metadata, by = "celltype"))
#>   celltype factor n n_units        mean         sd       median          q25
#> 1   acinar     F1 8      NA 4.960317135 0.17188257 4.9673494973 4.8094918715
#> 2   acinar     F2 8      NA 5.298236081 0.71510923 5.4066908000 5.0327110691
#> 3   acinar     F3 8      NA 0.028109184 0.07856296 0.0002971724 0.0001654456
#> 4   acinar     F4 8      NA 0.006590019 0.00685528 0.0033418977 0.0018643056
#> 5   acinar     F5 8      NA 0.041561361 0.08518224 0.0107757610 0.0055407631
#> 6   acinar     F6 8      NA 0.092777175 0.20941121 0.0007699101 0.0005378540
#>            q75                                                         basis_id
#> 1 5.0929693546 fcebd5337b83f1de0ddf0229a0da4193c799574523365fef14abdca1bda40d83
#> 2 5.6925397386 fcebd5337b83f1de0ddf0229a0da4193c799574523365fef14abdca1bda40d83
#> 3 0.0005835381 fcebd5337b83f1de0ddf0229a0da4193c799574523365fef14abdca1bda40d83
#> 4 0.0092359167 fcebd5337b83f1de0ddf0229a0da4193c799574523365fef14abdca1bda40d83
#> 5 0.0213696778 fcebd5337b83f1de0ddf0229a0da4193c799574523365fef14abdca1bda40d83
#> 6 0.0370257832 fcebd5337b83f1de0ddf0229a0da4193c799574523365fef14abdca1bda40d83
plot_factor_activity(view, metadata = metadata, group = "celltype")

These cells have published cell-type labels but no donor identifiers. Summaries are descriptive; technology is not a biological replicate.

Transfer the fixed feature programs

project_factor_activity() keeps the reference effects fixed and estimates new activities for the query cells.

projected <- project_factor_activity(view, cache$query_expression,
  sample_side = "rows", feature_scale = view$manifest$feature_scale,
  preprocessing = view$manifest$preprocessing, maxiter = 1000)
projected$reconstruction
#>             rmse              mae           fit_r2      correlation 
#>     5.700255e-01     3.509025e-01     3.316271e-01     5.777496e-01 
#> n_scored_entries 
#>     3.486720e+05
stopifnot(identical(projected$representation$effects, view$effects))
query_metadata <- cache$metadata[match(rownames(projected$representation$activity),
                                       cache$metadata$id), ]
stopifnot("metadata rows match query rows" =
  identical(as.character(query_metadata$id), rownames(projected$representation$activity)))
query_metadata$sample <- as.character(query_metadata$id)
plot_factor_activity(projected$representation, metadata = query_metadata,
                     group = "celltype")
Heatmap of projected program activity in query cells grouped by published cell type.

Projected activity of the fixed programs in the Smart-seq2 query cells, grouped by cell type.

Query counts use the reference library-size normalization and shifted-log rule. Source effects stay fixed while query activities are re-estimated. Reconstruction uses the same query observations used for activity inference, so it is fit agreement, not held-out prediction. Query-set composition can change empirical Bayes estimates; arbitrary row chunking is not exact. Transfer does not establish biological conservation. See Compare priors for masked prediction and Advanced use for coordinate uncertainty.

Credits

Published programs/tutorial: Peter Carbonetto and the cited study authors. Native FLASH/EBNM authors and feature-helper authors appear in Get started. Display workflows credit David Zemmour / Zemmour Lab and, for ranked weights, the MOFA2 plotting workflow of Ricard Argelaguet, Damien Arnol, Danila Bredikhin and Britta Velten (conceptual only); reference transfer conceptually credits STARCAT (Dylan Kotliar and Michelle Curtis). No upstream workflow source or input data are redistributed. Full credits and licenses.