Adding quadGate.tmix to gating set with gs_pop_add
1
1
Entering edit mode
alavy ▴ 30
@alavy-23451
Last seen 4.7 years ago

Hi, I've successfully created a gate with .singletGate and added it to a gate set with gs_pop_add. However I could not do the same thing for a .quadGate.tmix gate. Here is the code I used for both gates:

ncfs  <- read.ncdfFlowSet(fcsFiles, alter.names=TRUE, transformation=FALSE, truncate_max_range=FALSE)
ncfs

#create gating element
gs <- GatingSet(ncfs)

#look at one of the frames
fr <- ncfs[[6]]

#make a first gate with a singleGate
chnl <- c("Parameter_13", "Parameter_11")
gate1 <- openCyto:::.singletGate(fr, channels = chnl, filterId = "singlet")

#look at the current gating paths
gs_get_pop_paths(gs)
#Add gate1
gs_pop_add(gs, gate1, parent = "root")
#look at the gates again
gs_get_pop_paths(gs)
#Compute population in gate
recompute(gs, "singlet")

#This part worked fine, and the gate was added to gs successfully.

#make another gate with a quadGate
chnl <- c("Parameter_13", "Parameter_11")
gate2 <- openCyto:::.quadGate.tmix(fr, channels = chnl, K = 4, usePrior = "no", filterId = "quad")

#look at the current gating paths
gs_get_pop_paths(gs)
#Add gate2 to root
gs_pop_add(gs, gate2, parent = "root")

The error message is: Error in gs_pop_add(gs, gate2, parent = "root") : names of gate list do not match with the sample names in the gating set!

Aren't the sample names suppose to be identical because the gate was built based on fr which is derived from the same set as gs ?

gs_pop_add quadGate openCyto • 1.7k views
ADD COMMENT
3
Entering edit mode
Jake Wagner ▴ 310
@jake-wagner-19995
Last seen 4.2 years ago

The issue here is that gate2 actually has 4 filter objects (polygon gates specifically). gs_pop_add is expecting you to add a single filter (the same gate will be applied to all samples) or, in the case of a list of filter objects, a filter for each sample in the GatingSet. In that case, in order to disambiguate which gate goes with which sample, it expects you to name the filter objects in the list.

In your case, you have a polygon gate for each of the 4 quadrants. You want to apply each of these gates in turn to all samples. So it will look something like this (I'm just using a built-in example GatingSet from flowWorkspaceData as a starting point).

library(flowCore)
library(flowWorkspace)
library(openCyto)

gs <- load_gs(system.file("extdata", "gs_manual", package="flowWorkspaceData"))
chnl <- c("<B710-A>", "<R780-A>")
qg <- openCyto:::.quadGate.tmix(gh_pop_get_data(gs[[1]]), channels = chnl, K = 4, usePrior = "no", filterId = "quad")
# Manually naming the gates by their markers rather than channels
qg[[1]]@filterId <- "CD4-CD8+"
qg[[2]]@filterId <- "CD4+CD8+"
qg[[3]]@filterId <- "CD4+CD8-"
qg[[4]]@filterId <- "CD4-CD8-"

for(gate in qg)
  gs_pop_add(gs, gate, parent = "singlets")
recompute(gs)

I am currently in the process of appropriately hooking this in to the gs_add_gating_method machinery so you will just be able to add all 4 quadrants that way. I will update this issue when that's ready, but for now you can manually add each quadrant as above.

ADD COMMENT
2
Entering edit mode

Thank you Jake! That totally explains it and solves the issue I had !

ADD REPLY
1
Entering edit mode

After this commit, it should be possible to use gs_add_gating_method to accomplish the same thing.

Using my example GatingSet above:

library(flowCore)
library(flowWorkspace)
library(openCyto)

gs <- load_gs(system.file("extdata", "gs_manual", package="flowWorkspaceData"))
gs_add_gating_method(gs,
                     pop = "+/-+/-",
                     parent = "singlets",
                     dims="CD4,CD8",
                     gating_method = "gate_quad_tmix",
                     gating_args = "K=4")
ADD REPLY

Login before adding your answer.

Traffic: 407 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6