DillonHammill / CytoExploreR

Interactive Cytometry Data Analysis
61 stars 13 forks source link

cyto_gatingTemplate_apply() after adding an additional gate #103

Closed rwbaer closed 3 years ago

rwbaer commented 3 years ago

Briefly describe what you hope to achieve: I would like to add a new gate called "Live Single Cells" and update the Gating Set to use it for stats. The Gating set already has a gate called live cells. cyto_gatingTemplate_apply() seems to think that the gate "already exists when I use cyto_gatingTemplate_apply(), but when I try to use the new gate, "Live Single Cells", to get statistics, it can't be found.

If I clear everything and rebuild the gating set, stats work fine on single live cells. Am I doing something wrong in the way I'm applying the updated gating to the gating set, or is this a bug?

Outline the steps taken to attempt to reach this goal (paste code below):

Adding newly constructed gate(s) to Samples.csv .

...

done

cyto_gatingTemplate_apply(gsSamp, "Samples")

Applying Samples.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.

Skip preprocessing! Population 'Live Single Cells' already exists.

Skip gating! Population 'Live Single Cells' already exists.

Skip preprocessing! Population 'Myeloid' already exists.

Skip gating! Population 'Myeloid' already exists.

Skip preprocessing! Population 'WM278' already exists.

Skip gating! Population 'WM278' already exists.

finished.

A GatingSet with 20 samples

statLiveFreqWide = cyto_stats_compute(gsSamp, parent = "Single Cells", alias = 'Live Single Cells', channels = c('FL1-AREA', 'FL2-AREA', 'FL3-AREA', 'FL4-AREA'), trans = logicleTransSamp, format = "wide", stat = "freq", save_as = paste("statLiveFreqWide", eDate, ".csv"))

Error in get_cytoset_from_node(obj@pointer, y) :

Live Single Cells not found!

DillonHammill commented 3 years ago

@rwbaer, I am going to need some more information if I am going be able to help.

What is the output of cyto_gatingTemplate_active()?

If you open up the gatingTemplate after adding the gate does the new population appear as a new row?

rwbaer commented 3 years ago

cyto_gatingTemplate_active() shows "Samples" Yes, the gating template appears in a new row.

> cyto_gatingTemplate_active()
[1] "Samples.csv"
> # Gate Live Single Cells
> cyto_gate_draw(gsSamp[idxMyeloid],
+                parent = "Single Cells",
+                alias = "Live Single Cells2",
+                channels = c("FL4-AREA", "FSC-AREA"))
Select at least 3 points to construct a polygon gate around the Live Single Cells2 population. 

Adding newly constructed gate(s) to Samples.csv .
...
done

> cyto_gatingTemplate_active()
[1] "Samples.csv"

# 1st column of samples.csv
> #alias
> #Non-Debris
> #Single Cells
> #WM278
> #Myeloid
> #Live Single Cells
> #Live Single Cells2
> 
> MedFI_LiveSingleCells = cyto_stats_compute(gsSamp, parent = "Single Cells", 
+                                            alias = 'Live Single Cells2', 
+                                            channels = c('FL1-AREA', 'FL2-AREA', 'FL3-AREA', 'FL4-AREA'), 
+                                            trans = logicleTransSamp, format = "wide", stat = "median", 
+                                            save_as = paste("./Reports/Report_MedFI_LiveSingleCells", "_", eDate, ".csv"))
Error in get_cytoset_from_node(obj@pointer, y) : 
  Live Single Cells2 not found!
> 
> 
> cyto_gatingTemplate_active()
[1] "Samples.csv"

> cyto_gatingTemplate_apply(gsSamp, "Samples")
Applying Samples.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.
Skip preprocessing! Population 'Live Single Cells2' already exists.
Skip gating! Population 'Live Single Cells2' already exists.
Skip preprocessing! Population 'Live Single Cells' already exists.
Skip gating! Population 'Live Single Cells' already exists.
Skip preprocessing! Population 'Myeloid' already exists.
Skip gating! Population 'Myeloid' already exists.
Skip preprocessing! Population 'WM278' already exists.
Skip gating! Population 'WM278' already exists.
finished.
A GatingSet with 20 samples

> cyto_gatingTemplate_apply(gsSamp, "Samples")
Applying Samples.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.
Skip preprocessing! Population 'Live Single Cells2' already exists.
Skip gating! Population 'Live Single Cells2' already exists.
Skip preprocessing! Population 'Live Single Cells' already exists.
Skip gating! Population 'Live Single Cells' already exists.
Skip preprocessing! Population 'Myeloid' already exists.
Skip gating! Population 'Myeloid' already exists.
Skip preprocessing! Population 'WM278' already exists.
Skip gating! Population 'WM278' already exists.
finished.
A GatingSet with 20 samples

> cyto_gatingTemplate_active()
[1] "Samples.csv"
DillonHammill commented 3 years ago

Aha! The issue is that you are only gating a subset of the samples in cyto_gate_draw(). You should always supply the entire GatingSet here otherwise the gate will not be present in all of your samples.

rwbaer commented 3 years ago

So many ways to go wrong ;-) Thanks as always!

Hopefully it also works to only request stats on those samples where the gate exists since some samples in the gating set are purely melanoma cells, and analyzing a "myeloid gate percentage" for those samples makes no sense. They have different intrinsic forward scatter and side scatter.

DillonHammill commented 3 years ago

@rwbaer, it is fine to perform subsetting within cyto_stats_compute(). I would recommend using the select argument to pull out the relevant data.