RGLab / CytoML

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

Error applying xpathApply to FlowJo workspace doc after update to R 4 / Bioc 3.11 #109

Closed PedroMilanezAlmeida closed 4 years ago

PedroMilanezAlmeida commented 4 years ago

Today I updated my R and Bioc installations from 3.6.2 and 3.10 and started getting the following error:

ws <- CytoML::open_flowjo_xml(wspName)

##find raw .fcs files
#find path of all fcs files in workspace
sampleFCS_paths <- XML::xpathApply(ws@doc,
                                   file.path("/Workspace/SampleList/Sample","DataSet"),
                                   function(x)
                                     XML::xmlGetAttr(x,"uri") %>%
                                     gsub(pattern = "%20", replacement = " ", x = .) %>%
                                     gsub(pattern = "file:", replacement = "", x = .)) %>%
  unlist

Error in UseMethod("xpathApply") : 
  no applicable method for 'xpathApply' applied to an object of class "externalptr"

Apparently ws@doc is now an an object of class "externalptr" (a pointer), on which xpathApply does not work anymore.

Did the last update change the class of ws@doc?

In case, I would really appreciate if someone could point out a work around for me to find the paths to the .fcs files.

sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Mojave 10.14.6

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] C

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

other attached packages:
 [1] ggcyto_1.16.0             ncdfFlow_2.34.0          
 [3] BH_1.72.0-3               RcppArmadillo_0.9.900.2.0
 [5] ggplot2_3.3.2             flowCore_2.0.1           
 [7] flowUtils_1.52.0          CytoML_2.0.5             
 [9] flowWorkspace_4.0.6       FlowSOM_1.20.0           
[11] igraph_1.2.5              XML_3.99-0.5             
[13] magrittr_1.5              glue_1.4.1               
[15] Rcpp_1.0.5                gridExtra_2.3            
[17] pheatmap_1.0.12           foreach_1.5.0            
[19] BiocManager_1.30.10      

loaded via a namespace (and not attached):
 [1] lattice_0.20-41             corpcor_1.6.9              
 [3] RProtoBufLib_2.0.0          png_0.1-7                  
 [5] digest_0.6.25               R6_2.4.1                   
 [7] plyr_1.8.6                  stats4_4.0.2               
 [9] pillar_1.4.6                zlibbioc_1.34.0            
[11] rlang_0.4.7                 data.table_1.13.0          
[13] Rgraphviz_2.32.0            hexbin_1.28.1              
[15] RUnit_0.4.32                stringr_1.4.0              
[17] munsell_0.5.0               compiler_4.0.2             
[19] pkgconfig_2.0.3             ConsensusClusterPlus_1.52.0
[21] BiocGenerics_0.34.0         base64enc_0.1-3            
[23] tidyselect_1.1.0            tibble_3.0.3               
[25] codetools_0.2-16            matrixStats_0.56.0         
[27] crayon_1.3.4                dplyr_1.0.1                
[29] withr_2.2.0                 grid_4.0.2                 
[31] RBGL_1.64.0                 tsne_0.1-3                 
[33] jsonlite_1.7.0              gtable_0.3.0               
[35] lifecycle_0.2.0             scales_1.1.1               
[37] graph_1.66.0                RcppParallel_5.0.2         
[39] stringi_1.4.6               latticeExtra_0.6-29        
[41] xml2_1.3.2                  ellipsis_0.3.1             
[43] generics_0.0.2              vctrs_0.3.2                
[45] RColorBrewer_1.1-2          iterators_1.0.12           
[47] tools_4.0.2                 Biobase_2.48.0             
[49] purrr_0.3.4                 jpeg_0.1-8.1               
[51] parallel_4.0.2              yaml_2.2.1                 
[53] colorspace_1.4-1            cluster_2.1.0              
[55] cytolib_2.0.3
PedroMilanezAlmeida commented 4 years ago

I may have found a way by first parsing the the wsp file using XML::xmlParse(wspName) instead of applying xpathApply directly on the ws@doc:

sampleFCS_paths <- XML::xmlParse(wspName) %>%
  XML::xpathApply(.,
                  file.path("/Workspace/SampleList/Sample","DataSet"),
                  function(x)
                    XML::xmlGetAttr(x,"uri") %>%
                    gsub(pattern = "%20", replacement = " ", x = .) %>%
                    gsub(pattern = "file:", replacement = "", x = .)) %>%
  unlist
gfinak commented 4 years ago

Did you solve your problem? CytoMl and flowWorkspace will search for FCS files automatically in the provided directory. Is there a reason you need to get the path from the XML? I'm asking because it's not directly supported by the API but we could add support if there's a use case.

PedroMilanezAlmeida commented 4 years ago

Hey Greg, thanks for your quick reply!

I think my issue is solved by the code I posted (re-parsing the wsp/xml file).

In terms of the need for sample paths, I am building a FlowJo plugin which needs the path to the fcs file on which the plugin was called within FlowJo. It would be great if the API would natively support that, but I already have a code for this, which of course I could share if needed.

Just as heads up, later today I will post another issue with the new version not being able to apply the gates when transform = FALSE in open_flowjo_xml. I also need this functionality for the plugin, in particular for cases when the data has been transformed outside FlowJo and imported into FJ via a csv file, for example. For us, this is particularly important for CITEseq data.

EDIT: I meant flowjo_to_gatingset not open_flowjo_xml above.