DillonHammill / CytoExploreR

Interactive Cytometry Data Analysis
61 stars 13 forks source link

Apply gate from single 'control flowframe' to all flowframes in gatingset #151

Open rwbaer opened 2 years ago

rwbaer commented 2 years ago

Briefly describe what you hope to achieve: Goal - measure phagocytosis --Bait cells - violet stained melanoma or Jurkat cells --Phagocytes - orange stained Macrophages

Definitions --Violet stained gate -- more violet than 99% of "violet" in a pure orange macrophage sample --Orange stained gate -- more orange than 99% of "orange" in a pure violet stained melanoma sample --Create these "thesholds" using openCyto:::.quantileGate(fr, channels = chnl, probs = .99) [called qg1 and qg3 because they are quantilegates on channels 1 and 3]

Help Needed Problem(s)-- --I don't know how to apply the violet stained gate and orange stained gate to the all the samples in a cytoExploreR gatingSet, once I've defined them based on the control populations. I'm guessing this should be sort of the same thing one would do with FMO controls. --Assuming I accomplish the above, is there a way to apply this to the gating template or at least the gatingSet in memory for use by other cytoExploreR functions? I'm assuming I need to at least update the in-memory gating set for cytoExploreR. --I don't know how to use these gates to get summary statistics (e.g., fraction of violet stained macrophages) using cyto_stats_compute(). This is really the ultimate goal - to be able to figure out the fraction of cells is in upper left quadrant defined in a reproducible fashion, and perhaps the median or geometric mean intensity of those cells. The reference would probably best be the total orange cells unless there is evidence that melanoma cells can paradoxically phagocytize macrophages. --I will want the cyto_stats_compute data broken down by grouping variables (i.e., treatment parameters).

NOTE: There is an existing gating tree created from the gating template. the ggcyto() command plots the gates on all samples in approximately the location I would expect if I eliminate the facet_null() at the end and don't restrict the gatingSet to samples 9:10

Rplot

Here is my approach so far, but perhaps I need to attack the problem completely differently (open to all advice ):


library(CytoExploreR)
gsTest <- cyto_setup(path = "Samples",
                     gatingTemplate = "Test-Template.csv",
                     details = "Samples-Details.csv",
                     restrict = TRUE)

# Apply compensation to samples, based on the spill matrix calculated with our calibration beads
gsTest <- cyto_compensate(gsTest,
                          spillover = "Spillover-Matrix.csv")

# 
transList <- cyto_transformer_arcsinh(gsTest)

# Apply our arcsinh transform for better viewing of our data
gsTest = cyto_transform(gsTest, trans = transList)

# Apply an automatic gating template
cyto_gatingTemplate_apply(gsTest)

# quantilegate - Macrophage
fr <- gh_pop_get_data(gsTest[[11]], "Mel", returnType = "flowFrame")
chnl <- "FL1-AREA"
qg1 <- openCyto:::.quantileGate(fr, channels = chnl, probs = .99)
mylimits <- ggcyto_par_set(limits = "instrument")
p <- autoplot(fr, chnl, bins = 256) + mylimits
p + geom_gate(qg1)
autoplot(fr, "FL3-AREA", chnl, bins = 256) + geom_gate(qg1)
pData(gsTest)

# quantileGate - Melanoma
fr <- gh_pop_get_data(gsTest[[12]], "Mac", returnType = "flowFrame")
chnl <- "FL3-AREA"
qg3 <- openCyto:::.quantileGate(fr, channels = chnl, probs = .99)
mylimits <- ggcyto_par_set(limits = "instrument")
p <- autoplot(fr, chnl, bins = 256) + mylimits
p + geom_gate(qg3)
autoplot(fr, "FL1-AREA", chnl, bins = 256) + geom_gate(qg3)

ggcyto(gsTest[9:10], subset = "singlets", 
       aes(x = `FL3-AREA`, y= `FL1-AREA`),
       limit = "instrument") +
  axis_x_inverse_trans() + 
  axis_y_inverse_trans() + 
  ggcyto_par_set(limits = "instrument") +
  geom_hex(bins = 512) +
  geom_gate(qg3) +
  geom_gate(qg1)+
facet_null()

CombinedSamples

IndividualSamples