Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gs_cyto_data and gatingset_to_flowjo, or how to update FCS files for flowjo export #135

Open
baj12 opened this issue May 3, 2021 · 1 comment

Comments

@baj12
Copy link

baj12 commented May 3, 2021

I am trying to modify an FCS file and work with the changed files in FlowJO.

I can export FCS files using wirte.FCS (and when loading into FlowJo they contain the added information)
and I can export gating sets to a FlowJo wsp file that can be read in FlowJo.
Unfortunately, the FCS in FlowJo is not the updated one.

It would be great if you could help me understand what is going wrong.

From #122 I understand that the file name of the FCS file can be modified. I haven't any documentation on this. Could you point me please to some more in-depth information on this issue, too?

Thanks for your continued support !!!

library(flowWorkspace)
#> As part of improvements to flowWorkspace, some behavior of
#> GatingSet objects has changed. For details, please read the section
#> titled "The cytoframe and cytoset classes" in the package vignette:
#> 
#>   vignette("flowWorkspace-Introduction", "flowWorkspace")
library(CytoML)
path <- system.file("extdata",package="flowWorkspaceData")
gs_path <- list.files(path, pattern = "gs_manual",full = TRUE)
gs <- load_gs(gs_path)
gs
#> A GatingSet with 1 samples

save_cytoset(gs, "tempCS")
#> Done
#> To reload it, use 'load_cytoset' function
cs = load_cytoset("tempCS")
cs_unlock(cs)
col2add = sample.int(20, gh_pop_get_count(gs[[1]],"root"), replace = TRUE)
mm = matrix(ncol = 1, col2add, dimnames = list(NULL, "randomNo"))
cs[[1]] <- cf_append_cols(cs[[1]], mm)
gs_cyto_data(gs) <- cs
recompute(gs)
#> done!

#output to flowJo
outFile <- "test.wsp"
gatingset_to_flowjo(gs, outFile)
#> Using docker image public.ecr.aws/x4k5d9i7/cytoverse/gs-to-wsp:latest to write FlowJo workspace...

for (fpIdx in seq_len(length(gs))) {
  outFile = sampleNames(gs[fpIdx])
  flowCore::write.FCS(gs_cyto_data(gs)[[fpIdx]], filename = outFile)
}

sessionInfo()
#> R version 4.0.4 (2021-02-15)
#> Platform: x86_64-apple-darwin17.0 (64-bit)
#> Running under: macOS Big Sur 10.16
#> 
#> Matrix products: default
#> BLAS:   /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.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] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] CytoML_2.3.4        flowWorkspace_4.3.8
#> 
#> loaded via a namespace (and not attached):
#>  [1] Biobase_2.50.0      httr_1.4.2          jsonlite_1.7.2     
#>  [4] RcppParallel_5.1.2  assertthat_0.2.1    highr_0.9          
#>  [7] stats4_4.0.4        latticeExtra_0.6-29 RBGL_1.66.0        
#> [10] yaml_2.2.1          pillar_1.6.0        backports_1.2.1    
#> [13] lattice_0.20-41     glue_1.4.2          digest_0.6.27      
#> [16] RColorBrewer_1.1-2  colorspace_2.0-0    ggcyto_1.18.0      
#> [19] htmltools_0.5.1.1   plyr_1.8.6          XML_3.99-0.6       
#> [22] pkgconfig_2.0.3     zlibbioc_1.36.0     purrr_0.3.4        
#> [25] flowCore_2.3.2      scales_1.1.1        jpeg_0.1-8.1       
#> [28] tibble_3.1.1        aws.s3_0.3.21       styler_1.4.1       
#> [31] generics_0.1.0      ggplot2_3.3.3       ellipsis_0.3.1     
#> [34] withr_2.4.2         BiocGenerics_0.36.1 hexbin_1.28.2      
#> [37] magrittr_2.0.1      crayon_1.4.1        evaluate_0.14      
#> [40] fs_1.5.0            fansi_0.4.2         xml2_1.3.2         
#> [43] graph_1.68.0        tools_4.0.4         data.table_1.14.0  
#> [46] ncdfFlow_2.36.0     lifecycle_1.0.0     matrixStats_0.58.0 
#> [49] stringr_1.4.0       S4Vectors_0.28.1    munsell_0.5.0      
#> [52] reprex_2.0.0        compiler_4.0.4      rlang_0.4.10       
#> [55] grid_4.0.4          aws.signature_0.6.0 base64enc_0.1-3    
#> [58] rmarkdown_2.7       cytolib_2.3.9       gtable_0.3.0       
#> [61] DBI_1.1.1           curl_4.3            R6_2.5.0           
#> [64] RProtoBufLib_2.3.5  gridExtra_2.3       knitr_1.33         
#> [67] dplyr_1.0.5         utf8_1.2.1          Rgraphviz_2.34.0   
#> [70] stringi_1.5.3       parallel_4.0.4      Rcpp_1.0.6         
#> [73] vctrs_0.3.7         png_0.1-7           tidyselect_1.1.0   
#> [76] xfun_0.22

Created on 2021-05-03 by the reprex package (v2.0.0)

@mikejiang
Copy link
Member

fcs files generated from writing gs data won't work here since flowJo expect the original fcs file, i.e. the raw data. e.g.

> cf <- load_cytoframe_from_fcs("~/rdp-shared/CytoTrol_CytoTrol_1.fcs")
> range(cf)
     FSC-A  FSC-H  FSC-W  SSC-A B710-A R660-A R780-A V450-A V545-A G560-A G780-A   Time
min      0      0      0      0   -111   -111   -111   -111   -111   -111   -111      0
max 262143 262143 262143 262143 262143 262143 262143 262143 262143 262143 262143 262143

gs stores the data that has been compensated and transformed.

> cf = gs_cyto_data(gs)[[1]]
> range(cf)
     FSC-A  FSC-H  FSC-W  SSC-A  <B710-A>  <R660-A>  <R780-A>  <V450-A>  <V545-A>  <G560-A>  <G780-A>    Time
min      0      0      0      0  426.3119  518.5215  877.4007 -903.5115  213.4429  110.2343  448.9122   0.002
max 262142 262142 262142 262142 4096.7871 4096.4653 4093.4397 4097.7808 4097.2637 4097.4038 4096.7227 294.392

Some channels are also prefixed here, so it won't match up to the wsp file you are trying to load into flowjo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants