convert_to_fa: Convert a tidy tibble into a format compatible with the...

View source: R/convert.R

convert_to_faR Documentation

Convert a tidy tibble into a format compatible with the "Functional Analysis" module in 'MetaboAnalyst'

Description

Creates a tibble with columns m.z, p.value, t.score and optionally r.t to use in the "Functional Analysis" module in 'MetaboAnalyst'. Metrics are calculated using a t.test.

Usage

convert_to_fa(
  data,
  m_z_col,
  rt_col = NULL,
  group_column,
  groups_to_compare,
  batch_column = NULL,
  batch = NULL,
  adjust_p = FALSE,
  log2_before = FALSE,
  ...
)

Arguments

data

A tidy tibble created by read_featuretable.

m_z_col

Which column holds the precursor m/z? Uses args_data_masking.

rt_col

Optional. Which column holds the precursor retention times? Uses args_data_masking.

group_column

Which column should be used for grouping? Usually group_column = Group. Uses args_data_masking.

groups_to_compare

Names of the groups which should be compared as a character vector. Those are the group names in the group_column. They are usually provided in the form of a metadata tibble and joined via join_metadata.

batch_column

Which column contains the batch information? Usually batch_column = Batch. Only relevant if data contains multiple batches. For example, if data contains 2 batches and each batch contains measurements of separate controls, group_column and batch arguments should be provided. Otherwise controls of both batches will be considered when calculating the p-value and log2 fold change. Uses args_data_masking.

batch

The names of the batch(es) that should be included when calculating p-value and log2 fold change.

adjust_p

Should the p-value be adjusted? Can be either FALSE, (the default) in case no adjustment should be made or any or the name from p.adjust.methods (e.g., adjust_p = "fdr").

log2_before

A logical. Should the data be log2 transformed prior to calculating the p-values?

...

Arguments passed on to t.test. If none are provided (the default), a Welch Two Sample t-test will be performed.

Value

A tibble with columns m.z, p.value, t.score and optionally r.t.

Examples

# Without optional retention time column
toy_metaboscape %>%
  join_metadata(toy_metaboscape_metadata) %>%
  convert_to_fa(group_column = Group,
                groups_to_compare = c("control", "treatment"),
                return_tbl = TRUE,
                alternative = "two.sided",
                m_z_col = `m/z`)

# With optional retention time column
toy_metaboscape %>%
  join_metadata(toy_metaboscape_metadata) %>%
  convert_to_fa(group_column = Group,
                groups_to_compare = c("control", "treatment"),
                return_tbl = TRUE,
                m_z_col = `m/z`,
                rt_col = RT)

metamorphr documentation built on Nov. 22, 2026, 5:07 p.m.