Skip to contents

Generates a tidy dataframe for factors of interest useful for plotting functions.

Usage

get_tidy_factors(
  model,
  metadata,
  factor,
  group = FALSE,
  sample_id_column = "sample"
)

Arguments

model

A MOFA2 model.

metadata

A data frame containing the annotations of the samples included in the MOFA model.

factor

A string character to define the factor to be extracted. Alternatively, "all" to get all factors.

group

Boolean flag TRUE/FALSE, to specify if a grouped MOFA model is provided.

sample_id_column

A string character that refers to the column in metadata where the sample identifier is located.

Value

A dataframe in a tidy format containing the factor scores per sample together with metadata

Details

This function simplifies the extraction of factor scores from MOFA models.

Examples

inputs_dir <- base::system.file("extdata", package = "MOFAcellulaR")
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.
metadata <- readRDS(file.path(inputs_dir, "testmetadata.rds"))
all_factors <- get_tidy_factors(model = model,
                                metadata = metadata,
                                factor = "all",
                                sample_id_column = "sample")
Factor3 <- get_tidy_factors(model = model,
                            metadata = metadata,
                            factor = "Factor3",
                            sample_id_column = "sample")