RGLab / CytoML

A GatingML Interface for Cross Platform Cytometry Data Sharing
GNU Affero General Public License v3.0
30 stars 14 forks source link

FlowJo Transformations with flowjo_to_gatingset #104

Closed alexheubeck closed 4 years ago

alexheubeck commented 4 years ago

Hi Mike and Jacob,

I had a question about loading in FlowJo workspaces with flowjo_to_gatingset. I am currently using logicle transform in FlowJo, and I'd like to bring the same transform into R. After I adjust my gates and save the transform and workspace, the transform menu looks like this:

Screen Shot 2020-06-18 at 12 22 35 PM

I use flowjo_to_gatingset to load the workspace in R:

wsfile <- list.files(WorkingDirectory, pattern=".wsp", full = TRUE)
ws <- open_flowjo_xml(wsfile, full = TRUE)
gs <- flowjo_to_gatingset(ws,name=1)

Once the workspace is loaded,gh_get_transformationsreturns this:

`Comp-PE-Cy7-A`
function (x, deriv = 0) 
{
    deriv <- as.integer(deriv)
    if (deriv < 0 || deriv > 3) 
        stop("'deriv' must be between 0 and 3")
    if (deriv > 0) {
        z0 <- double(z$n)
        z[c("y", "b", "c")] <- switch(deriv, list(y = z$b, b = 2 * 
            z$c, c = 3 * z$d), list(y = 2 * z$c, b = 6 * z$d, 
            c = z0), list(y = 6 * z$d, b = z0, c = z0))
        z[["d"]] <- z0
    }
    res <- stats:::.splinefun(x, z)
    if (deriv > 0 && z$method == 2 && any(ind <- x <= z$x[1L])) 
        res[ind] <- ifelse(deriv == 1, z$y[1L], 0)
    res
}
<bytecode: 0x7ffe2c120f28>
<environment: 0x7ffdd3210618>
attr(,"type")
[1] "biexp"
attr(,"parameters")
attr(,"parameters")$channelRange
[1] 256

attr(,"parameters")$maxValue
[1] 1e+06

attr(,"parameters")$neg
[1] 0

attr(,"parameters")$pos
[1] 4.5

attr(,"parameters")$widthBasis
[1] -199.5262

I know FlowJo uses biexponential as it's default transform, but is there a way to bring in a different transform that was used in FlowJo?

If not, is there a efficient way to inverse transform the gating set, and retransform with logicle? Or, is there a way to only bring in the gates themselves, and apply them to an existing gating set with the correct transform? I apologize if there is an obvious answer, it looks like you have a few other open issues related to this but I just wanted to double check.

Best, Alex

> sessionInfo()
R version 4.0.0 (2020-04-24)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.5

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
 [1] knitr_1.28                gridExtra_2.3             colorRamps_2.3            scales_1.1.1              cytolib_2.1.4             CytoML_2.1.3              tibble_3.0.1             
 [8] data.table_1.12.8         ggcyto_1.17.0             ggplot2_3.3.0             ncdfFlow_2.35.0           BH_1.72.0-3               RcppArmadillo_0.9.880.1.0 flowCore_2.1.0           
[15] flowWorkspace_4.1.2       openCyto_2.1.0          
jacobpwagner commented 4 years ago

Hi @alexheubeck . This is just because logicle is a subtype of biexponential (as FlowJo's documentation discusses). This is how CytoML represents it:

https://github.com/RGLab/CytoML/blob/5dcd3e01ed81ddbd99f01473ecf06e76871dc02b/inst/include/CytoML/winFlowJoWorkspace.hpp#L807-L830

Note that it performs some adjustment of the width basis based on how it is defined for general biexponential versus logicle, which is why that looks different:

https://github.com/RGLab/CytoML/blob/5dcd3e01ed81ddbd99f01473ecf06e76871dc02b/inst/include/CytoML/winFlowJoWorkspace.hpp#L819

> -10^(2*1.15)
[1] -199.5262

So the short answer is that it already is bringing in the logicle transformation, just named as a biexponential. Of course if something looks incorrect in the data or statistics upon import, let me know and I'd be happy to look in to it.

alexheubeck commented 4 years ago

Hey @jacobpwagner, Ah, I didn't know logicle and biexponential we're related in that way, that makes sense. The statistics look correct, so I think I'm all set. Thanks once again for your help!