Skip to content

Commit

Permalink
code changes to support version 2 of the submission
Browse files Browse the repository at this point in the history
  • Loading branch information
phauchamps committed Jan 26, 2024
1 parent b6a97dc commit cb920c9
Show file tree
Hide file tree
Showing 2 changed files with 182 additions and 7 deletions.
21 changes: 14 additions & 7 deletions R/4_Results_Benchmark.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ summaryDF <- melt(benchmarkDFPipeComp,
"recallPeacoQC", "recallFlowAI"))

summaryDF$pipeline <- ifelse(grepl("PeacoQC", summaryDF$indicator_pipe),
"PeacoQC",
"flowAI")
summaryDF$pipeline <- factor(summaryDF$pipeline, levels = c("PeacoQC", "flowAI"))
"PeacoQC-based",
"flowAI-based")
summaryDF$pipeline <- factor(summaryDF$pipeline,
levels = c("PeacoQC-based", "flowAI-based"))

summaryDF$indicator <- ifelse(summaryDF$pipeline == "PeacoQC",
summaryDF$indicator <- ifelse(summaryDF$pipeline == "PeacoQC-based",
gsub("PeacoQC", "", summaryDF$indicator_pipe),
gsub("FlowAI", "", summaryDF$indicator_pipe))

Expand Down Expand Up @@ -85,8 +86,14 @@ colnames(summaryDF2) <- c("dataset", "indicator", "PeacoQC", "flowAI")

useRepel <- TRUE

# combination of increased box.padding,
# "" labels for non highlighted points,
# and increased x and y coordinates, as advised in:
# https://stackoverflow.com/questions/52397363/r-ggplot2-ggrepel-label-a-subset-of-points-while-being-aware-of-all-points
geom_text_repel_high_overlap <- function(...){
geom_text_repel(..., max.overlaps = 100)
geom_text_repel(..., max.overlaps = 100,
box.padding = 1,
min.segment.length = 0)
}

toDisplay <- c("D93_A05", "D91_C07", "D91_D03")
Expand Down Expand Up @@ -116,10 +123,10 @@ p <-
geom_text_FUN(mapping = aes(label = label), hjust=0.5, vjust=1,
size = 2.5) +
geom_abline(intercept = 0., slope = 1., colour = "blue", linetype = 2) +
coord_cartesian(xlim=c(0, 1), ylim=c(0, 1)) +
coord_cartesian(xlim=c(-0.25, 1.25), ylim=c(-0.25, 1.25)) +
scale_colour_manual(values = c("false" = normalCol,
"true" = highlightCol)) +
xlab("PeacoQC pipeline") + ylab("flowAI pipeline") +
xlab("PeacoQC-based pipeline") + ylab("flowAI-based pipeline") +
theme(legend.position="none") +
ggplot2::facet_wrap(~ indicator)
p
Expand Down
168 changes: 168 additions & 0 deletions R/5_Discussion_NbOfEvents.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
require(CytoPipeline)
require(reshape2)
require(ggplot2)
require(patchwork)

# Figure 14

collectNbOfEvents <- function(
experimentName,
path = ".",
whichSampleFiles) {

pipL <- CytoPipeline::buildCytoPipelineFromCache(
experimentName = experimentName,
path = path
)

if (missing(whichSampleFiles)) {
whichSampleFiles <- CytoPipeline::sampleFiles(pipL)
}

nEventPerSampleList <- list()
allStepNames <- c()
for (s in seq_along(whichSampleFiles)) {
message("Collecting nb of events for sample file ", whichSampleFiles[s],
"...")
objInfos <- CytoPipeline::getCytoPipelineObjectInfos(
pipL,
whichQueue = "pre-processing",
sampleFile = whichSampleFiles[s])
objInfos <- objInfos[objInfos[,"ObjectClass"] == "flowFrame",]

nEventPerSampleList[[s]] <- lapply(
objInfos[,"ObjectName"],
FUN = function(objName) {
message("Reading object ", objName, "...")
ff <- CytoPipeline::getCytoPipelineFlowFrame(
pipL,
path = path,
whichQueue = "pre-processing",
sampleFile = whichSampleFiles[s],
objectName = objName)
flowCore::nrow(ff)})

stepNames <- vapply(objInfos[,"ObjectName"],
FUN = function(str){
gsub(x = str,
pattern = "_obj",
replacement = "")
},
FUN.VALUE = character(length = 1))

names(nEventPerSampleList[[s]]) <- stepNames

allStepNames <- union(allStepNames, stepNames)
}

nSampleFiles <- length(whichSampleFiles)
nAllSteps <- length(allStepNames)
eventNbs <- matrix(rep(NA, nSampleFiles * nAllSteps),
nrow = nSampleFiles)
rownames(eventNbs) <- as.character(whichSampleFiles)
colnames(eventNbs) <- allStepNames

for (s in seq_along(whichSampleFiles)) {
stepNames <- names(nEventPerSampleList[[s]])
for (st in seq_along(stepNames)) {
eventNbs[as.character(whichSampleFiles)[s],
stepNames[st]] <-
nEventPerSampleList[[s]][[st]]
}
}

eventNbs

}

selectedExpName <- "HBVMouse_PQC"
selectedSamples <- c("D91_C07.fcs", "D93_A05.fcs", "D91_D03.fcs")

eventNbPeacoQC <- collectNbOfEvents(
experimentName = selectedExpName,
whichSampleFiles = selectedSamples
)

eventFracPeacoQC <- t(apply(
eventNbPeacoQC,
MARGIN = 1,
FUN = function(line) {
if (length(line) == 0 || is.na(line[1])) {
as.numeric(rep(NA, length(line)))
} else {
line/line[1]
}
}
))

selectedExpName <- "HBVMouse_flowAI"

eventNbFlowAI <- collectNbOfEvents(
experimentName = selectedExpName,
whichSampleFiles = selectedSamples
)

eventFracFlowAI <- t(apply(
eventNbFlowAI,
MARGIN = 1,
FUN = function(line) {
if (length(line) == 0 || is.na(line[1])) {
as.numeric(rep(NA, length(line)))
} else {
line/line[1]
}
}
))

stepNames <- colnames(eventFracPeacoQC)
DFPeacoQC <- as.data.frame(eventFracPeacoQC)
DFPeacoQC$sampleFile <- rownames(DFPeacoQC)
DFPeacoQC2 <- reshape(data = DFPeacoQC,
direction = "long",
v.names = "eventFrac",
varying = stepNames,
timevar = "step",
times = stepNames)

DFPeacoQC2$step <- factor(DFPeacoQC2$step,
levels = stepNames)

p1 <- ggplot(DFPeacoQC2,
mapping = aes(x = step,
y = eventFrac,
group = sampleFile,
col = sampleFile)) +
geom_line() +
scale_y_continuous(limits=c(0,1)) +
theme(axis.text.x = element_text(angle = 90),
legend.position = "none") +
labs(y = "fraction of events kept",
title = "PeacoQC-based pipeline")

stepNames <- colnames(eventFracFlowAI)
DFFlowAI <- as.data.frame(eventFracFlowAI)
DFFlowAI$sampleFile <- rownames(DFFlowAI)
DFFlowAI2 <- reshape(data = DFFlowAI,
direction = "long",
v.names = "eventFrac",
varying = stepNames,
timevar = "step",
times = stepNames)

DFFlowAI2$step <- factor(DFFlowAI2$step,
levels = stepNames)

p2 <- ggplot(DFFlowAI2,
mapping = aes(x = step,
y = eventFrac,
group = sampleFile,
col = sampleFile)) +
geom_line() +
scale_y_continuous(limits=c(0,1)) +
theme(axis.text.x = element_text(angle = 90)) +
labs(y = "fraction of events kept",
title = "flowAI-based pipeline")


p1+p2

0 comments on commit cb920c9

Please sign in to comment.