QuantileNorm.train: QuantileNorm.train

View source: R/QuantileNorm.R

QuantileNorm.trainR Documentation

QuantileNorm.train

Description

Learn the batch effects from control samples. This function computes quantiles to describe the distribution of the data, and infers spline functions to equalize these distributions over the files. Typically, you will use the function QuantileNorm.normalize after this function to reverse the batch effects on other files.

Usage

QuantileNorm.train(
  files,
  labels,
  channels,
  transformList,
  nQ = 99,
  limit = NULL,
  quantileValues = NULL,
  goal = "mean",
  verbose = FALSE,
  plot = FALSE,
  plotTitle = "Quantiles",
  ...
)

Arguments

files

Full paths of to the fcs files of the control samples

labels

A label for every file, indicating to which batch it belongs, e.g. the plate ID.

channels

Names of the channels to normalize

transformList

Transformation list to pass to the flowCore transform function

nQ

Number of quantiles to use. Default = 99, which results in quantiles for every percent of the data.

limit

These values will be modelled to map onto themselves by the spline

quantileValues

If specified, it should be a vector of length nQ with values between 0 and 1, giving the percentages at which the quantiles should be computed. If NULL (default), the quantiles will be evenly distributed, including 0 and 1.

goal

Goal distribution. Default "mean", can also be nQ numeric values or one of the batch labels.

verbose

If TRUE, progress updates are printed. Default = FALSE.

plot

If TRUE, a plot is generated (using the layout function) showing all quantiles. Default = FALSE.

plotTitle

Title to use in the plot. Default = "Quantiles".

...

Additional arguments to pass to read.FCS

Value

A list containing all the splines and quantile information. This can be used as input for the QuantileNorm.normalize function.

See Also

CytoNorm.train, QuantileNorm.normalize

Examples


dir <- system.file("extdata", package = "CytoNorm")
files <- list.files(dir, pattern = "fcs$")
data <- data.frame(File = files,
                   Path = file.path(dir, files),
                   Type = stringr::str_match(files, "_([12]).fcs")[,2],
                   Batch = stringr::str_match(files, "PTLG[0-9]*")[,1],
                   stringsAsFactors = FALSE)
data$Type <- c("1" = "Train", "2" = "Validation")[data$Type]
train_data <- dplyr::filter(data, Type == "Train")

ff <- flowCore::read.FCS(data$Path[1])
channels <- grep("Di$", flowCore::colnames(ff), value = TRUE)
transformList <- flowCore::transformList(channels,
                                         cytofTransform)

png("nQ99.png",
    width = length(channels) * 300,
    height = (nrow(train_data) * 2 + 1) * 300)
model_nQ_99 <- QuantileNorm.train(
  files = train_data$Path,
  labels = train_data$Batch,
  channels = channels,
  transformList = transformList,
  nQ = 99,
  plot = TRUE)
dev.off()

png("nQ99_limited.png",
    width = length(channels) * 300,
    height = (nrow(train_data) * 2 + 1) * 300)
model_nQ_99 <- QuantileNorm.train(
  files = train_data$Path,
  labels = train_data$Batch,
  channels = channels,
  transformList = transformList,
  nQ = 99,
  limit = c(0,8),
  plot = TRUE)
dev.off()

png("nQ_2.png",
    width = length(channels) * 300,
    height = (nrow(train_data) * 2 + 1) * 300)
model_nQ_2 <- QuantileNorm.train(
  files = train_data$Path,
  labels = train_data$Batch,
  channels = channels,
  transformList = transformList,
  nQ = 2,
  quantileValues = c(0.001, 0.999),
  plot = TRUE)
dev.off()

model_goal_mean <- QuantileNorm.train(
  files = train_data$Path,
  labels = train_data$Batch,
  channels = channels,
  transformList = transformList)

model_goal_batch1 <- QuantileNorm.train(
  files = train_data$Path,
  labels = train_data$Batch,
  channels = channels,
  transformList = transformList,
  goal = "PTLG021")

model_goal_fixed <- QuantileNorm.train(
  files = train_data$Path,
  labels = train_data$Batch,
  channels = channels,
  transformList = transformList,
  nQ = 99,
  goal = seq(0.01, 0.99, by = 0.01))


saeyslab/CytoNorm documentation built on Nov. 2, 2024, 12:39 p.m.