Project new data into a known factor space
project_data.Rd
This function uses the feature weights learned by a MOFA2 model to project unseen data to the factor space
Arguments
- model
A MOFA2 model.
- test_data
A dataframe in multiview representation as generated by
MOFAcellulaR::pb_dat2MOFA
Details
This function calculates the pseudoinverse of the feature weights of a MOFA2
model and uses it to
project unseen data into the factor space. Only shared features are used for the projection
Examples
inputs_dir <- base::system.file("extdata", package = "MOFAcellulaR")
load(file.path(inputs_dir, "testpbcounts.rda"))
load(file.path(inputs_dir, "testcoldata.rda"))
pb_obj <- create_init_exp(counts = testpbcounts, coldata = testcoldata)
ct_list <- filt_profiles(pb_dat = pb_obj,
cts = c("Fib","CM"),
ncells = 5,
counts_col = "cell_counts",
ct_col = "cell_type")
ct_list <- filt_gex_byexpr(pb_dat_list = ct_list,
min.count = 5,
min.prop = 0.25)
#> Warning: All samples appear to belong to the same group.
#> Warning: All samples appear to belong to the same group.
ct_list <- tmm_trns(pb_dat_list = ct_list,
scale_factor = 1000000)
ct_list <- center_views(pb_dat_list = ct_list)
multiview_dat <- pb_dat2MOFA(pb_dat_list = ct_list)
trained_model <- MOFA2::load_model(file.path(inputs_dir, "testmodel.hdf5"))
#> Warning: Factor(s) 1 are strongly correlated with the total number of expressed features for at least one of your omics. Such factors appear when there are differences in the total 'levels' between your samples, *sometimes* because of poor normalisation in the preprocessing steps.
projected_factors <- project_data(model = trained_model, test_data = multiview_dat)