RGLab / flowWorkspace

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

GatingSet constructor #304

Closed melemieux closed 4 years ago

melemieux commented 4 years ago

Hi, Just installed the latest CytoML, etc., on a new machine to run a few hundred samples using scripts I developed over the last couple of months. I had been using the GatingSet constructor but now that doesn't work. I've poked around the discussions but haven't come across how to transition to the new flowWorkspace. I'd appreciate advice or a link to the relevant doc. Thanks! Madeleine

This is the code that was working before but breaks now: nist <- read.FCS(sample.details['nist',2]) nist.gs <- GatingSet(as(nist,'flowSet')) nist.gs <- compensate(nist.gs,spill) nist <- transform(nist.gs[[1]]@data[[1]],transList)

Error in transform(nist.gs[[1]]@data[[1]], transList) : no slot of name "data" for this object of class "GatingHierarchy" In addition: There were 41 warnings (use warnings() to see them)

class(nist) [1] "flowFrame" attr(,"package") [1] "flowCore" class(nist.gs) [1] "GatingSet" attr(,"package") [1] "flowWorkspace"

sessionInfo() R version 3.6.2 (2019-12-12) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 18.04.1 LTS

Matrix products: default BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1 LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1

locale: [1] LC_CTYPE=C.UTF-8 LC_NUMERIC=C LC_TIME=C.UTF-8
[4] LC_COLLATE=C.UTF-8 LC_MONETARY=C.UTF-8 LC_MESSAGES=C.UTF-8
[7] LC_PAPER=C.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C

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

other attached packages: [1] flowStats_3.45.2 flowClust_3.25.0
[3] gridExtra_2.3 flowCut_0.99.17
[5] flowViz_1.51.0 lattice_0.20-38
[7] ggcyto_1.15.0 flowWorkspace_3.35.8
[9] ncdfFlow_2.33.0 BH_1.72.0-3
[11] RcppArmadillo_0.9.850.1.0 flowCore_1.53.10
[13] ggplot2_3.2.1 openCyto_1.25.2
[15] CytoML_1.13.7

mikejiang commented 4 years ago

Direct access to the data slots of S4 object through @ is generally discouraged because the internal data structures are subject to change overtime, which is what is happening here. Also it is recommended to transform the GatingSet directly with a transformerList. e.g.

transformer.obj <- flowjo_biexp_trans()
transformerList1 <- transformerList(channels, transformer.obj)
gs <- transform(gs, transformerList1)

This will ensure the transformations are stored with gs and can be retrieved later for other purpose (e.g. inverse the data or visualizations)

That said, you can alternatively transform the underlying cytoset (used to be flowSet/ncdfFlowSet) with transformList, even though it is not the recommended workflow

transform.func <- flowjo_biexp()
translist <- transformList(channels, transform.func)
cs <- gs_cyto_data(gs)
cs <- transform(cs, translist) #data is updated inplace so no need to assign cs back to gs

And it is even less ideal to just transform each sample individually like what you were trying to do, but this is what it would look like if you insist on your original workflow

cs <- gs_cyto_data(gs)
cf <- get_cytoframe_from_cs(cs, 1)
transform(cf, translist) #again data is updated in-place for cs and gs thus no need to assign them back
melemieux commented 4 years ago

Thanks for the quick reply. I still don't know how to create the GatingSet in the first place from a flowFrame.

melemieux commented 4 years ago

Actually, I suspect that what I'm missing is an understanding of the relationship between cytoset/cytoframe and flowset/flowframe.

mikejiang commented 4 years ago

Your existing code should still work as it is regarding to creating the GatingSet

melemieux commented 4 years ago

You're right, of course, a gating set is created but I don't know what the structure is anymore. Is there documentation somewhere I could read to understand what has changed?

mikejiang commented 4 years ago

All the original methods/functions still work, as I said, you should not use or rely on the internal structure of GatingSet. Try to stick to the public APIs exposed through the package namespace. Please refer to the package vignette for cytoset/cytoframe

melemieux commented 4 years ago

Thanks for the advice.