plotRidgelines: Plot ridgeline plots

View source: R/plotRidgelines.R

plotRidgelinesR Documentation

Plot ridgeline plots

Description

Plot ridgeline plots

Usage

plotRidgelines(
  input,
  batch = NULL,
  channels,
  colors = NULL,
  transformList = NULL,
  quantiles = c(seq(0, 1, 0.1))
)

Arguments

input

Paths to fcs files.

batch

Optional vector with a batch label for each file

channels

Channels to plot

colors

Optional vector with a color for each batch

transformList

In case the data from the fcs files still needs to be transformed. Default NULL, in which case no transformation happens.

quantiles

Optional vector specifying the quantiles that need to be highlighted and connected.

Value

Named list with a plot per channel

Examples


dir <- system.file("extdata", package = "CytoNorm")
files <- list.files(dir, pattern = "fcs$")
ff <- flowCore::read.FCS(file.path(dir, files[1]))
channels <- grep("Di$", flowCore::colnames(ff), value = TRUE)
transformList <- flowCore::transformList(channels,
                                         cytofTransform)
beforeNorm <- plotRidgelines(input = file.path(dir, files), 
                             batch = stringr::str_match(files, "PTLG[0-9]*")[,1],
                             channels = c("Er170Di", "La139Di"),
                             colors = c("PTLG021" = "#d8e2dc", 
                                        "PTLG028" = "#ffe5d9",
                                        "PTLG034" = "#ffcad4"),
                             transformList = transformList,
                             quantiles = c(0.01, 0.25, 0.5, 0.75, 0.99))
                             
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.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 = 15,
                                              ydim = 15,
                                              nClus = 10,
                                              scale = FALSE),
                        normParams = list(nQ = 99),
                        seed = 1,
                        verbose = TRUE)

CytoNorm.normalize(model = model,
                   files = validation_data$Path,
                   labels = validation_data$Batch,
                   transformList = transformList,
                   transformList.reverse = transformList.reverse,
                   outputDir = "Normalized",
                   verbose = TRUE)

files <- list.files("Normalized", pattern = "fcs$")
afterNorm <- plotRidgelines(input = file.path("Normalized", files), 
                            batch = stringr::str_match(files, "PTLG[0-9]*")[,1],
                            channels = c("Er170Di", "La139Di"),
                            colors = c("PTLG021" = "#d8e2dc", 
                                       "PTLG028" = "#ffe5d9",
                                       "PTLG034" = "#ffcad4"),
                            transformList = transformList,
                            quantiles = c(0.01, 0.25, 0.5, 0.75, 0.99))

p <- list()
for (i in 1:length(beforeNorm)){
  p[[length(p)+1]] <- ggpubr::ggarrange(beforeNorm[[i]], afterNorm[[i]], nrow =1)
}


saeyslab/CytoNorm documentation built on Feb. 21, 2025, 3:27 a.m.