Build a consensus program reference from several datasets
Source:R/reference-class.R
build_factor_reference.RdCombine factors fitted independently in several source datasets into one catalog of consensus programs. Each factor's feature effects become a comparison profile. All cross-dataset pairs are compared, a nearest-neighbour graph links similar factors, and a greedy, density-checked merge groups them with at most one factor per dataset. A program is the mean member profile on a common feature basis. Source fits are not modified.
Usage
build_factor_reference(
fits,
dataset_id = names(fits),
comparison_manifest,
source_feature_sets = NULL,
source_feature_sd = NULL,
reference_features = NULL,
metric = NULL,
min_shared_features = 2L,
min_similarity = NULL,
rank_max = NULL,
reciprocal = NULL,
min_cluster_density = NULL,
min_datasets = 2L,
projection_manifest = NULL,
keep_source_objects = FALSE
)Arguments
- fits
List of native fits from
fit_ebmf()or views fromstandardize_factors(), one per source dataset, each with a declaredfeature_scaleand zero offsets.- dataset_id
Character dataset IDs, one per element of
fits. Defaults tonames(fits).- comparison_manifest
Named list declaring the comparison contract:
mode("generic"or"starcat2025"),feature_scale(must match every source) andpreprocessing_compatibility = "user_declared". Optionalprofile_normalization("auto") andfeature_standardization("none"in generic mode,"source_sd"in starcat2025 mode).- source_feature_sets, source_feature_sd
For
"starcat2025"only: lists named by dataset ID with each dataset's discovery (overdispersed) feature IDs and its named per-feature SD in the declared linear scale.- reference_features
Optional feature IDs measured in every dataset to use as the reference basis. Default: all shared features (generic) or the union of source feature sets within the shared features (starcat2025).
- metric
Generic mode:
"congruence"(default),"cosine"(the same statistic) or"pearson". starcat2025 always uses Pearson.Minimum features a pair must share (default 2).
- min_similarity
Similarity a candidate edge must strictly exceed. Required in generic mode, where no threshold is universal; 0.5 in starcat2025 mode.
- rank_max
Keep only each factor's
rank_maxmost similar factors from other datasets.NULL: no rank limit (generic) or the number of datasets (starcat2025; STARCAT used 7 for its T cell catalog).- reciprocal
Keep only edges chosen from both ends. Default
FALSE(generic); starcat2025 requiresTRUE.- min_cluster_density
Merge threshold. Generic mode: accepted edges inside the merged set divided by its pair count must be at least this (default 2/3). starcat2025: directed candidate links between the two sets divided by
2 |X| |Y|must exceed this (default 0.666).- min_datasets
Datasets a cluster needs to become a program (default 2). Singletons stay in the diagnostics.
- projection_manifest
Optional named list declaring the query basis:
feature_scale,scope,transformation,compatibility, and an optionalactivity_prior(an ebnm function name). Without it the reference is for inspection only andproject_reference()refuses it.- keep_source_objects
TRUEstores the source views for debugging. DefaultFALSEkeeps the object small.
Value
A factor_reference: $programs (features by programs),
$program_constraints, $programs_table, $members_table,
$similarity (all pairs, with reasons), $graph, $clusters,
$excluded_members, $source_table, $build_settings,
$projection_ready and a content hash $reference_id.
Details
Experimental: arguments and outputs may change in a later release.
Two modes exist. "generic" suits ordinary EBMF factors: congruence on the
features two datasets share, L1 profiles for non-negative effects and L2
profiles otherwise, sign flips only between signed/signed factors, and no
default similarity cut-off. "starcat2025" follows the STARCAT catalog
construction (Kotliar et al. 2025): spectra summed to 1e6 on shared
features and divided by each dataset's feature SD, Pearson correlation on
the union of the two datasets' feature sets, reciprocal top-ranked
neighbours above 0.5, and starCAT's cross-cluster density rule (> 0.666).
Origin: NEW_ORCHESTRATION / none. Use factor_provenance("build_factor_reference") for audited sources. Cross-dataset recurrence is descriptive; it does not by itself establish a biological program.
References
Kotliar D, Curtis M, Agnew R, et al. (2025). Reproducible single-cell annotation of programs underlying T cell subsets, activation states and functions. Nature Methods 22, 1964-1980. doi:10.1038/s41592-025-02793-1
Author
Mikhael Manurung. Conceptual method: STARCAT, Dylan Kotliar and Michelle Curtis; no source reuse. Full source and dependency credits: https://github.com/mdmanurung/flashier-utils/blob/main/CREDITS.md.
Examples
set.seed(1)
programs <- matrix(rnorm(60), 30, 2)
fits <- lapply(1:3, function(d) {
X <- tcrossprod(matrix(rnorm(80), 40, 2), programs) + matrix(rnorm(1200, sd = 0.3), 40, 30)
dimnames(X) <- list(paste0("d", d, "_s", 1:40), paste0("g", 1:30))
fit_ebmf(X, "rows",
max_factors = 2, seed = 1, verbose = 0, nullcheck = FALSE, backfit = TRUE,
ebnm_fn = list(ebnm::ebnm_normal, ebnm::ebnm_point_laplace),
feature_scale = "simulated_intensity"
)
})
names(fits) <- c("A", "B", "C")
ref <- build_factor_reference(fits,
comparison_manifest = list(
mode = "generic", feature_scale = "simulated_intensity",
preprocessing_compatibility = "user_declared"
),
min_similarity = 0.8
)
ref
#> <factor_reference> generic mode, 3 datasets, 2 programs on 30 features
#> clusters: 2 (0 singletons); excluded factors: 0
#> projection ready: FALSE
#> reference_id: e5ea8b3ef76e636b
reference_members(ref)
#> member_id dataset_id factor_id
#> 1 A::F1 A F1
#> 2 A::F2 A F2
#> 3 B::F1 B F1
#> 4 B::F2 B F2
#> 5 C::F1 C F1
#> 6 C::F2 C F2
#> basis_id
#> 1 d74a19da4bc8035bb8f0d5cc9f598c9bf6e7a96a82606500c2fd58794db35c7a
#> 2 d74a19da4bc8035bb8f0d5cc9f598c9bf6e7a96a82606500c2fd58794db35c7a
#> 3 5ae58c304f9961191f5e5c91936e68d89028561dfdc7e068284d716d7ad92d72
#> 4 5ae58c304f9961191f5e5c91936e68d89028561dfdc7e068284d716d7ad92d72
#> 5 4d88773ca00ef8cf1bf8ad7df4c0808ddc47776ae8f1510a5ad2469d683c7fba
#> 6 4d88773ca00ef8cf1bf8ad7df4c0808ddc47776ae8f1510a5ad2469d683c7fba
#> feature_scale activity_support effect_support n_features zero_activity
#> 1 simulated_intensity signed signed 30 FALSE
#> 2 simulated_intensity signed signed 30 FALSE
#> 3 simulated_intensity signed signed 30 FALSE
#> 4 simulated_intensity signed signed 30 FALSE
#> 5 simulated_intensity signed signed 30 FALSE
#> 6 simulated_intensity signed signed 30 FALSE
#> zero_effect eligible reason cluster_id program_id
#> 1 FALSE TRUE eligible RP001 RP001
#> 2 FALSE TRUE eligible RP002 RP002
#> 3 FALSE TRUE eligible RP001 RP001
#> 4 FALSE TRUE eligible RP002 RP002
#> 5 FALSE TRUE eligible RP001 RP001
#> 6 FALSE TRUE eligible RP002 RP002