RGLab / flowWorkspace

flowWorkspace
GNU Affero General Public License v3.0
44 stars 21 forks source link

How to remove all trace of a gatingSet? #395

Closed hrj21 closed 8 months ago

hrj21 commented 8 months ago

Hello,

Thank you for an excellent package. My question is about how to remove all traces of a gatingSet from the session. If I overwrite a gatingSet object with another, it seems to retain properties of the original such as spillover matrices and gates. I include a small reprex below illustrating the behaviour.

# Load packages
library(flowWorkspace)

# Read example data
fcs_path  <- system.file("extdata", package = "flowWorkspaceData")
fcs_files <- list.files(pattern = "CytoTrol", fcs_path, full = TRUE)
cs <- load_cytoset_from_fcs(fcs_files)

# Create gatingSet
gs <- GatingSet(cs)

# Compensate data
comp_mat <- spillover(cs[[1]])$SPILL
compensate(gs, comp_mat)

# Remove gs
rm(gs)

# Recreate gs from cs
gs <- GatingSet(cs)

# Show that gs retains spillover
gs_get_compensations(gs)

I understand that the way cytoSets and gatingSets are stored is different to most of the R classes we work with, but my question is: how do I completely remove all traces of a gatingSet / overwrite one, without having to restart the R session?

SessionInfo:

R version 4.1.0 (2021-05-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252   
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] flowWorkspace_4.6.0

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.10         RColorBrewer_1.1-3  compiler_4.1.0      pillar_1.9.0       
 [5] cytolib_2.6.2       base64enc_0.1-3     tools_4.1.0         zlibbioc_1.40.0    
 [9] aws.s3_0.3.21       digest_0.6.31       lattice_0.21-8      lifecycle_1.0.3    
[13] tibble_3.2.1        png_0.1-8           pkgconfig_2.0.3     rlang_1.1.0        
[17] graph_1.72.0        DBI_1.1.3           cli_3.6.1           rstudioapi_0.14    
[21] Rgraphviz_2.38.0    curl_5.0.0          interp_1.1-4        httr_1.4.5         
[25] dplyr_1.1.2         xml2_1.3.3          generics_0.1.3      S4Vectors_0.32.4   
[29] vctrs_0.6.1         stats4_4.1.0        grid_4.1.0          tidyselect_1.2.0   
[33] glue_1.6.2          data.table_1.14.8   Biobase_2.54.0      R6_2.5.1           
[37] jpeg_0.1-10         fansi_1.0.4         XML_3.99-0.14       latticeExtra_0.6-30
[41] deldir_1.0-6        RProtoBufLib_2.6.0  magrittr_2.0.3      scales_1.2.1       
[45] matrixStats_0.63.0  BiocGenerics_0.40.0 colorspace_2.1-0    aws.signature_0.6.0
[49] flowCore_2.6.0      ncdfFlow_2.40.0     utf8_1.2.3          munsell_0.5.0      
[53] RcppParallel_5.1.7 

Many thanks Hefin

mikejiang commented 8 months ago

cs and gs share the same underlying c++ data structures, i.e. when you

gs <- GatingSet(cs)

gs is simply a different view of cs object, thus any mutation to gs will implicitly impact cs. to have a clean state of original cs without having to recreate it after you mutate the gs, you can

gs1 = gs_clone(gs)

then do whatever to gs1, won't affect cs and gs objects.