DillonHammill / CytoExploreR

Interactive Cytometry Data Analysis
60 stars 13 forks source link

Apply a gate to other files in gating set #115

Closed rwbaer closed 3 years ago

rwbaer commented 3 years ago

Briefly describe what you hope to achieve: I have a gating set that consist of 9 files. One of those files is a negative (or positive) control that I'd like to use to draw a gate. The question is, once drawn, how do I apply the gate to the rest of the files in the gating set?

# gsSamp is a gating set of 9 samples with several housekeeping gates in place already.  The 9th sample
# is a control
# Use a control sample to define a gate position
cyto_gate_draw(gsSamp[9],
                parent = "Single Cells",
                alias = "test1",
                channels = c("FL1-AREA", "FL2-AREA"),
                type = "interval")
# How do I apply to the rest of gsSamp

Related sanity question: gsSamp[9] is a gating (sub)set itself. Should I instead be starting from gsSamp[[9]] which, I think, is a gating hierarchy? Either way the main question is how to approach this.

Sorry for such a basic question. Can't find the documentation to help me. Can I do it from within CytoExploreR? Do I need to look at openCyto or FlowWorkspace for this functionality? Glad to read if you point me at it.

EDIT: Perhaps this works, but I don't know how to avoid the error.

> cyto_gatingTemplate_apply(gsSamp, "Samples-gatingTemplate.csv")
Applying Samples-gatingTemplate.csv to the GatingSet...
Skip preprocessing! Population 'Non-Debris' already exists.
Skip gating! Population 'Non-Debris' already exists.
Skip preprocessing! Population 'Single Cells' already exists.
Skip gating! Population 'Single Cells' already exists.
Preprocessing for 'test1'
Gating for 'test1'
Error in .cpp_addGate(ptr, sn, filterObject, parent, name) : 
  test1 already exists!

Am I on the right track?

DillonHammill commented 3 years ago

@rwbaer, you should always pass the entire GatingSet to cyto_gate_draw() otherwise the gates will not be applied to all samples (hence the error above).

You can just overlay the sample that you want to use as a reference. I would recommend adding an experimental variable to make selecting this sample easier. For example, you could add a column called control and set it values to TRUE/FALSE.

# Select control sample using control variable
gs_control <- cyto_select(gs, control =  TRUE)
# Extract data from control for overlay
cs_control <- cyto_extract(gs, "Single Cells")
# Draw gate
cyto_gate_draw(gsSamp,
                parent = "Single Cells",
                alias = "test1",
                channels = c("FL1-AREA", "FL2-AREA"),
                type = "interval",
                overlay = cs_control[[1]])

P.S. you can modify experimental details of GatingSet by running:

# Supply the name of the file created by `cyto_setup()` so that changes are saved to file
gs <- cyto_details_edit(gs, file = "220421-Experiment-Details.csv")
rwbaer commented 3 years ago

Very helpful answer in that addresses the specific question and also fills in some holes about setting up gating sets if I would at some point want sample specific gates if these become important. It also helped me better understand how to actually deploy the groups I was creating in Experiment Details. I've been doing convoluted pData stuff. :-(

Anyway, I'm closing this although as a result I opened up 2 derivative issues. Sorry about that. P.S. Just noticed you have updated the version and some docs so I'll see what's new on that front as well.