Learn R Programming

OmicFlow (version 1.5.1)

foldchange: Computes Log2(A) - Log2(B) Fold Change of (non-) paired data.

Description

Computes (non-)paired Log2(A) - Log2(B) Fold Change. This function is built into the class omics with method DFE() and inherited by other omics classes, such as; metagenomics and proteomics. The function handles zero's, and doesn't return +/- infinites.

Usage

foldchange(
  data,
  feature_rank,
  condition_A,
  condition_B,
  condition_labels,
  paired = FALSE
)

Value

A data.table

Arguments

data

A data.table.

feature_rank

A character variable of the feature level (e.g. "Genus" in taxonomy).

condition_A

A vector of categorical characters, it is possible to specify multiple labels.

condition_B

A vector of categorical characters, it is possible to specify multiple labels.

condition_labels

A vector character wherein condition_A and condition_B are present.

paired

A Boolean value to perform paired or non-paired test, see wilcox.test.

Examples

Run this code
#-------------------------#
##      NON-PAIRED       ##
#-------------------------#
library(data.table)

# Define parameters and variables
sample_ids <- c("S1", "S2", "S3", "S4", "S5", "S6")
groups <- c("A", "A", "B", "B", "C", "C")
feature_ids <- c("Feature1", "Feature2", "Feature3")

# Simulated abundance matrix (features x samples)
abundances <- matrix(
  c(
    100, 120, 110, 55, 60, 65,
    50, 65, 60, 130, 120, 125,
    80, 85, 90, 80, 85, 90
  ),
  nrow = 3, byrow = TRUE,
  dimnames = list(feature_ids, sample_ids)
)

# Convert to a data.table
mock_data <- OmicFlow::matrix_to_dtable(abundances)
mock_data$Genus <- feature_ids

# It uses exact matching and multiple conditions are allowed.
res <- foldchange(
  data = mock_data,
  feature_rank = "Genus",
  condition_A = c("A", "B"),
  condition_B = c("B", "C"),
  condition_labels = groups,
  paired = FALSE
)
print(res)

#---------------------#
##      PAIRED       ##
#---------------------#
library(data.table)

# In the paired case both conditions A and B must be of the same length!
# We re-use the above mock_data and only change group labels
groups <- c("A", "A", "B", "B", "A", "B")

res <- foldchange(
  data = mock_data,
  feature_rank = "Genus",
  condition_A = c("A"),
  condition_B = c("B"),
  condition_labels = groups,
  paired = TRUE
)
print(res)

Run the code above in your browser using DataLab