RGLab / flowWorkspace

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

Error Replacing Cytoset in GatingSet with a Subset #366

Closed DillonHammill closed 2 years ago

DillonHammill commented 2 years ago

Hi @mikejiang,

Hope you are well.

I am encountering an error when I try to update a cytoset in a GatingSet with a smaller cytoset.

library(CytoExploreR)
library(CytoExploreRData)

gs <- GatingSet(
  flowSet_to_cytoset(
    Activation[1]
  )
)
nrow(gs)
cs <- gs_pop_get_data(gs)
nrow(cs)

gs_cyto_data(gs) <- cytoset(
  list(
    "Activation_1.fcs" = cs[[1]][1:1000, ]
  )
)
nrow(gs)

gs_pop_get_data(gs)
Error in get_cytoset_from_node(obj@pointer, y) : 
  The size of the new row index (0,49999) is not within the original mat size (0, 1000)

The matrix sizes are muddled up in the error message, the original matrix has 50000 rows and the new matrix only has 1000 rows. I am not trying to replace the cytoset with a larger one.

Thanks for your help!

Dillon

mikejiang commented 2 years ago

replace the cytoset with different size is explicitly prohibited in the API (for the good reasons). You will need to create a separate gatingset for the new cs object.

DillonHammill commented 2 years ago

How would you ensure that all the features of the original GatingSet (e.g. gates, compensation and transformations) are retained in the new one? Should I loop through the original GatingHierarchies and apply them to each element of the cytoset using gh_apply_to_cs() and then merge the resulting GatingSets (i.e. GatingSetList)?

DillonHammill commented 2 years ago

From the docs it looks like gh_apply_to_cs() actually re-applies the transformations and optionally applies the compensation. In my use case I wouldn't want to re-apply the compensation or transformations as the data is already compensated and transformed. I would just want to update the underlying data but keep the compensation and transformations attached. All good if there is no easy way to do this, I might have to add gates to the original GatingSet instead.

mikejiang commented 2 years ago

We should look at the gatingset as an atomic unit , probably don't want to mutate some parts of it (in this case its cytoset) in an unsupported fashion (subset by rows in this case). You may want to revise your workflow to build new gatingset from scratch through normal way

DillonHammill commented 2 years ago

Thanks @mikejiang, will do.