RGLab / flowWorkspace

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

Decompensate method for GatingHierarchy/GatingSet #333

Open DillonHammill opened 4 years ago

DillonHammill commented 4 years ago

Hi @mikejiang & @jacobpwagner,

I am looking into adding a decompensate method for GatingHierarchy/GatingSet objects in CytoExploreR, using the following approach:

# gs is uncompensated GatingSet - spill is spillover matrix
gs <- compensate(gs, spill)

# decompensate approach
cs_comp <- gs_cyto_data(gs)
cf_list <- lapply(cs_comp, function(fr){
   fr <- decompensate(fr, spill)
   flowFrame_to_cytoframe(fr)
})
names(cf_list) <- sampleNames(gs)
cs_decomp <- cytoset(cf_list)
gs_cyto_data(gs) <- cs_decomp

This works fine but still results in spillover matrices being extracted when calling gs_get_compensations(). Is there a way that I can tell it that the spillover matrices have been removed so that gs_get_compensations() returns NULL? Perhaps there is a better way to do this?

jacobpwagner commented 4 years ago

Hey @DillonHammill . We can maybe just add decompensate methods for cytoframe/cytoset and GatingHiearchy/GatingSet in to flowWorkspace, as well as the removal of the compensation from the GatingHierarchy/GatingSet. But first, what exactly is the use case? Our main concern is how we manage the state of transformations and gate definitions under the decompensation.

DillonHammill commented 4 years ago

@jacobpwagner, within CytoExploreR I perform these operations at the cytoset level where I don't have to worry about gates, but I do make sure that the data is appropriately transformed at each step.

Since compensation usually occurs every early in the analysis pipeline, if you happen to apply the incorrect spillover matrix it means that you have to go all the way back to the initial GatingSet() call to fix this. This is because most users prefer to assign compensated/transformed/gated data under the same R object (e.g. gs) instead of creating separate objects for each step of the analysis pipeline (e.g. gs, gs_comp, gs_trans, gs_gated) - which makes it difficult to go backwards without having to start at the beginning. Since the transformation definitions are attached to the GatingSet it would be nice if there was a wrapper that inversed the transformations, decompensated the linear data and then re-applied the transformations. I am just trying to simplify this operation for users, I think many would prefer to use a decompensate() method that takes care of everything instead of having to start over.

I do use gs_get_compensations() to identify whether the data has been compensated in my cyto_spillover() functions, so if there is a decompensate() method it would be great if the spillover matrices would be removed from this output as well.