Hi,
I'm trying to use the gate_mindensity2
from the openCyto package to gate out debris from my .fcs files. I'm using https://flowrepository.org/id/FR-FCM-ZZ36 as an example.
I can gate out the debris at the lower end (i.e. left hand side of the gate) but if I want to apply a gate to remove the events on the right hand side, I am unable to do so, even if I set the positive
argument to TRUE.
I've probably just missed something, but has the positive=TRUE
argument to gate_mindensity2
been removed from the recent version of openCyto.
Reprex and link to reprex output below. The issue I have is from applying FCSgate2fun to the gating set and expecting the filter to take the real line to the left of the cutpoint
Many thanks, Miha
https://github.com/Biomiha/FACS/blob/master/FACS_reprex.html
library(tidyverse)
library(openCyto)
library(ggcyto)
PBMC_luca <- list.files(path = "FR-FCM-ZZ36/", pattern = ".fcs", full.names = TRUE) %>%
grep(pattern = "luca", value = TRUE) %>%
read.ncdfFlowSet(.)
PBMC_luca[[1]] %>%
ggcyto(aes(x = `FSC-A`)) +
geom_density()
PBMC_luca_gatingSet <- GatingSet(PBMC_luca)
FCS_gate1_fun <- function(fr, channel = "FSC-A"){
peaks_found <- openCyto:::.find_peaks(x = as.numeric(unname(unlist(exprs(fr[, channel])))), num_peaks = 3)
openCyto::gate_mindensity2(fr, channel = channel, gate_range = sort(peaks_found$x)[1:2])
}
FCS_gate1_fun(getData(PBMC_luca_gatingSet[[1]]))
if(require(openCyto)){
thisData <- getData(PBMC_luca_gatingSet)
nonDebris_gate <- fsApply(thisData, FCS_gate1_fun)
add(PBMC_luca_gatingSet, nonDebris_gate, parent = "root", name = "nonDebris")
recompute(PBMC_luca_gatingSet)
}
getData(PBMC_luca_gatingSet[[1]]) %>%
ggcyto(aes(x = `FSC-A`)) +
geom_density() +
geom_gate(FCS_gate1_fun(getData(PBMC_luca_gatingSet[[1]])))
getData(PBMC_luca_gatingSet[[1]], y = "nonDebris") %>%
ggcyto(aes(x = `FSC-A`)) +
geom_density()
FCS_gate2_fun <- function(fr, channel = "FSC-A"){
openCyto::gate_mindensity2(fr, channel = channel, positive = TRUE) #not sure if this argument exists anymore
}
getData(PBMC_luca_gatingSet[[1]], y = "nonDebris") %>%
ggcyto(aes(x = `FSC-A`)) +
geom_density() +
geom_gate(FCS_gate2_fun(getData(PBMC_luca_gatingSet[[1]], y = "nonDebris")))
if(require(openCyto)){
thisData <- getData(PBMC_luca_gatingSet, y = "nonDebris")
nonDebris_gate2 <- fsApply(thisData, FCS_gate2_fun)
add(PBMC_luca_gatingSet, nonDebris_gate2, parent = "nonDebris", name = "nonDebris2")
recompute(PBMC_luca_gatingSet)
}
getData(PBMC_luca_gatingSet[[1]], y = "nonDebris") %>%
ggcyto(aes(x = `FSC-A`)) +
geom_density()
getData(PBMC_luca_gatingSet[[1]], y = "nonDebris2") %>%
ggcyto(aes(x = `FSC-A`)) +
geom_density()
sessionInfo()
I've figured out the reason. At least in my version of
openCyto::gate_mindensity2
the last 3 lines of code are:Meaning that any positive argument passed to
gate_mindensity2
is irrelevant as the coords are hardwired to bec(g$final_cut, Inf)
. I'm not sure if this was done deliberately, but I've noticed the same for the other gates, e.g.openCyto::gate_tail
.I've generated my own version of the gating function. Attached below.