RGLab / openCyto

A package that provides data analysis pipeline for flow cytometry.
GNU Affero General Public License v3.0
75 stars 29 forks source link

gating(gt, gs) - Applies gt to gs and other GatingSets #183

Closed DillonHammill closed 6 years ago

DillonHammill commented 6 years ago

Hi Mike,

I have just run into an issue using gating(gt,gs) to apply a gatingTemplate to a GatingSet. When multiple GatingSets are defined in the global environment it seems as if gt is applied to all GatingSets not just the GatingSet passed to the function:

# fs is a flowSet
gs <- GatingSet(fs)

gs1 <- gs
gs2 <- gs
gs3 <- gs

# gt is a gatingTemplate
gating(gt, gs1)

# Gates are successfully applied to gs1
> getNodes(gs1)
 [1] "root"                                                                
 [2] "/Cells"                                                              
 [3] "/Cells/Single Cells"                                                 
 [4] "/Cells/Single Cells/Live Cells"                                      
 [5] "/Cells/Single Cells/Live Cells/T Cells"                              
 [6] "/Cells/Single Cells/Live Cells/T Cells/CD8 T Cells"                  
 [7] "/Cells/Single Cells/Live Cells/T Cells/CD8 T Cells/CD69+ CD8 T Cells"
 [8] "/Cells/Single Cells/Live Cells/T Cells/CD4 T Cells"                  
 [9] "/Cells/Single Cells/Live Cells/T Cells/CD4 T Cells/CD69+ CD4 T Cells"
[10] "/Cells/Single Cells/Live Cells/Dendritic Cells" 

# But also gs, gs2 and any other defined GatingSets
> getNodes(gs)
 [1] "root"                                                                
 [2] "/Cells"                                                              
 [3] "/Cells/Single Cells"                                                 
 [4] "/Cells/Single Cells/Live Cells"                                      
 [5] "/Cells/Single Cells/Live Cells/T Cells"                              
 [6] "/Cells/Single Cells/Live Cells/T Cells/CD8 T Cells"                  
 [7] "/Cells/Single Cells/Live Cells/T Cells/CD8 T Cells/CD69+ CD8 T Cells"
 [8] "/Cells/Single Cells/Live Cells/T Cells/CD4 T Cells"                  
 [9] "/Cells/Single Cells/Live Cells/T Cells/CD4 T Cells/CD69+ CD4 T Cells"
[10] "/Cells/Single Cells/Live Cells/Dendritic Cells" 

> getNodes(gs2)
 [1] "root"                                                                
 [2] "/Cells"                                                              
 [3] "/Cells/Single Cells"                                                 
 [4] "/Cells/Single Cells/Live Cells"                                      
 [5] "/Cells/Single Cells/Live Cells/T Cells"                              
 [6] "/Cells/Single Cells/Live Cells/T Cells/CD8 T Cells"                  
 [7] "/Cells/Single Cells/Live Cells/T Cells/CD8 T Cells/CD69+ CD8 T Cells"
 [8] "/Cells/Single Cells/Live Cells/T Cells/CD4 T Cells"                  
 [9] "/Cells/Single Cells/Live Cells/T Cells/CD4 T Cells/CD69+ CD4 T Cells"
[10] "/Cells/Single Cells/Live Cells/Dendritic Cells" 

Obviously this is not ideal for cases where you want to apply different gates to different GatingSets. I have not had time to look at the code specifically but hopefully you have an easy fix/workaround.

Cheers, Dillon

gfinak commented 6 years ago

A gating set is not like other r objects. Consider this: gs2 <- gs1 consider gs2 as a reference to gs1, not a copy. What you do to gs2 will also be reflected in gs1. That's because a gating set is instanciated in C code. If you want a real copy, use the clone method.

DillonHammill commented 6 years ago

Oh ok, good to know. Thanks Greg!