library(tidyverse)
library(CytoRSuite)
library(ggcyto)
library(here)

 
 

Read in fcs files:

fcs_files <- list.files(here("FlowRepository_FR-FCM-ZZ36_files/"), full.names = TRUE, pattern = ".fcs")
fs <- read.ncdfFlowSet("FlowRepository_FR-FCM-ZZ36_files/pbmc_luca.fcs")
gs <- GatingSet(fs)
FCS_gate1_fun <- function(fr, pp_res = NULL, channels = "FSC-A"){
  peaks_found <- openCyto:::.find_peaks(x = as.numeric(unname(unlist(exprs(fr[, channels])))), num_peaks = 3)
  openCyto::gate_mindensity2(fr, channel = channels, gate_range = sort(peaks_found$x)[1:2])
}
registerPlugins(FCS_gate1_fun, "FCS_gate1")
## [1] TRUE

 
 

Add the gates and plot:

add_pop(gs, alias = "nonDebris",  pop = "+", parent = "root", dims = "FSC-A", gating_method = "FCS_gate1")
cyto_plot(x = gs, parent = "root", channels = c("FSC-A", "SSC-A"), gate = getGate(gs, "nonDebris"))

add_pop(gs, alias = "nonDebris2",  pop = "-", parent = "nonDebris", dims = "FSC-A", gating_method = "mindensity2")
autoplot(gs, "nonDebris2", bins = 256)

 
 

This looks ok, but if you use Dillon Hammill’s CytoRSuite::cyto_plot it generates the plot below.

 
 

cyto_plot(gs, parent = "nonDebris", channels = c("FSC-A", "SSC-A"), gate = getGate(gs, "nonDebris2"))
## No text supplied for labels - labels will show percent only.

And the gate dims are actually:

getGate(gs, "nonDebris2")
## $pbmc_luca.fcs
## Rectangular gate 'nonDebris2' with dimensions:
##   FSC-A: (244703.838155759,Inf)

Min = 244703.8

Max = Inf

So not surprising the gate is drawn on the right. The populations seem ok though.

getStats(gs)