DillonHammill / CytoExploreR

Interactive Cytometry Data Analysis
60 stars 13 forks source link

isolate population inside gate for further analyses #166

Closed avdvloet closed 1 year ago

avdvloet commented 1 year ago

Hi,

I would like to gate for a specific population of particles (nuclei) in a plot using cyto_gate_draw, which works perfectly. In a next step, I would like to seperate this specific population and work further with this alone (plot it separately, make a histogram, etc.).

My code up untill and including the gating (which all works fine)

# Load .fcs files in specified path to a cytoset 
path <- '~/Nextcloud/PhD/Flow Cytometry/Trial 2/FCM data'
files <- list.files(path, full.names = TRUE)
cf_list <- lapply(files, function(file){load_cytoframe_from_fcs(file, emptyValue = FALSE)})
names(cf_list) <- basename(files) # input needs to be a named list
cs <- cytoset_to_flowSet(cytoset(cf_list))
# log transformation
cs <- cyto_transform(cs, channels=c('YL2-A', 'SSC-A'), type='log')

### overview plot
cyto_plot(cs, channels=c('YL2-A', 'SSC-A'))

### haploid sample
cyto_plot_profile(cs[[1]])
graphics.off()
cyto_plot(cs[[1]], channels=c('YL2-A', 'SSC-A'))

# gate for nuclei
gate_nuclei <- cyto_gate_draw(cs[[1]],
               parent = NULL,
               channels = c('YL2-A', 'SSC-A'),
               alias = 'nuclei',
               type = "rectangle",
               contour_lines = 15
)

But after this I am stuck. How do I proceed now with the subset of particles which are in my case nuclei.

Thanks in advance, Antoine

DillonHammill commented 1 year ago

@avdvloet, I would recommend following the workflow from the "Getting Started" section on the CytoExploreR website: https://dillonhammill.github.io/CytoExploreR/articles/CytoExploreR.html

In general, cytoframe and cytoset objects are to be treated as an internal data structure that you shouldn't interact with, instead you should use GatingSet objects which will store the gates as populations that you can query. cyto_setup() will take care of importing your FCS files into a GatingSet that you can use for downstream analyses - in much the same way as you have done for cytosets.

avdvloet commented 1 year ago

@DillonHammill thank you very much for the quick response, this workflow has enabled me to solve the problem.