CytoNorm.train: CytoNorm.train

View source: R/CytoNorm.R

CytoNorm.trainR Documentation

CytoNorm.train

Description

CytoNorm learns batch effects, using control samples which should be the the same per batch. The cells are first split into rough groups using the FlowSOM algorithm, after which splines are trained to map the quantiles for each control group to an average distribution Typically, you will use the function CytoNorm.normalize after this function to reverse the batch effects in other files.

Usage

CytoNorm.train(
  files,
  labels,
  channels,
  transformList,
  outputDir = "./tmp",
  FlowSOM.params = list(nCells = 1e+06, xdim = 15, ydim = 15, nClus = 10, scale = FALSE),
  normMethod.train = QuantileNorm.train,
  normParams = list(nQ = 101),
  seed = NULL,
  clean = TRUE,
  plot = FALSE,
  verbose = FALSE,
  recompute = FALSE,
  ...
)

Arguments

files

Full paths to the fcs files or a flowSet of the control samples.

labels

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

channels

Column names of the channels that need to be normalized

transformList

Transformation list to pass to the flowCore transform function

outputDir

Directory to put the temporary files in. Default = "./tmp"

FlowSOM.params

Extra parameters to be passed to the FlowSOM function, such as the number of cells (nCells), the xdim and y dim or the number of clusters (nClus)

normMethod.train

Normalization method to use for each cluster. Default = QuantileNorm.train

normParams

Parameters to pass to the normalization method. Default, assuming QuantileNorm.train: list(nQ = 101)). nQ is the number of quantiles to use.

seed

Set a seed for reproducable results.

clean

Whether to remove the temporary files again at the end. Default = TRUE.

plot

If TRUE, plots are saved to the current dir. Default = FALSE.

verbose

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

recompute

If FALSE, will try to reuse previously saved FlowSOM model. If so, a warning message will be printed. Default = FALSE.

...

Additional arguments to pass to read.FCS

Details

Temporary fcs files splitting the data into clusters are written to outputDir and will be removed again by default (depending on clean).

Value

A list containing two elements: the FlowSOM clustering and a list containing all the splines per cluster. This can be used as input for the CytoNorm.normalize function.

See Also

QuantileNorm.train, CytoNorm.normalize, prepareFlowSOM

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")
validation_data <- dplyr::filter(data, Type == "Validation")

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

model <- CytoNorm.train(files = train_data$Path,
                        labels = train_data$Batch,
                        channels = channels,
                        transformList = transformList,
                        FlowSOM.params = list(nCells = 10000, #1000000
                                              xdim = 10,
                                              ydim = 10,
                                              nClus = 10,
                                              scale = FALSE),
                        normParams = list(nQ = 101),
                        seed = 1)

CytoNorm.normalize(model = model,
                   files = validation_data$Path,
                   labels = validation_data$Batch,
                   transformList = transformList,
                   transformList.reverse = transformList.reverse)


saeyslab/CytoNorm documentation built on March 19, 2024, 6:43 p.m.