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

Problem with 1_QC_Setup_GSList_TBAgs Script- error using flow_to_gatingset #1

Open
rachel7p opened this issue Jun 17, 2022 · 2 comments

Comments

@rachel7p
Copy link

I am trying to run the code from your publication to adapt the code to my needs. I have run into a problem when trying to Parse the Flow workspace.

library(here)
library(flowWorkspace)
library(plyr)

projectDir <- here::here()
source(file.path(projectDir, "Documents/ResisterCOMPASSAnalysis-master/scripts/flowHelperFunctions.R")) # for boxplot.cell.counts and prepare.gating.set.list.4.compass

# Task: Read in FlowJo workspaces, perform QC, and prepare a GatingSetList for the COMPASS run.

flowJoXmlPath1 <- file.path(projectDir, "Documents/ResisterCOMPASSAnalysis-master/data/TBAgs/20170605_RSTR_OMIP14_ICS_Batch1/20170607_RSTR_ICS_Batch1.xml")
flowJoXmlPath2 <- file.path(projectDir, "Documents/ResisterCOMPASSAnalysis-master/data/TBAgs/20170612_RSTR_OMIP14_ICS_Batch2/20170614_RSTR_ICS_Batch2.xml")
batch1FcsDirPath <- file.path(projectDir, "Documents/ResisterCOMPASSAnalysis-master/data/TBAgs/20170605_RSTR_OMIP14_ICS_Batch1/20170607_RSTR_OMIP14_ICS")
batch2FcsDirPath <- file.path(projectDir, "Documents/ResisterCOMPASSAnalysis-master/data/TBAgs/20170612_RSTR_OMIP14_ICS_Batch2/20170614_RSTR_OMIP14_ICS_Batch2")

# Additional variables
qcOutDir <- file.path(projectDir, "Documents/ResisterCOMPASSAnalysis-master/out/QC/TBAgs")
patientStatusFilePath <- file.path(projectDir, "Documents/ResisterCOMPASSAnalysis-master/data/20170518_HiRisk_VisitA_Only_1.txt")
gatingSetListOutDir <- file.path(projectDir, "Documents/ResisterCOMPASSAnalysis-master/out/GatingSets/AllBatchesForCompass_TBAgs")
flowJoWorkspace_sampleID_FileMapping <- read.table(file.path(projectDir, "Documents/ResisterCOMPASSAnalysis-master/data/flowJoWorkspace_sampleID_FileMapping.tsv"), sep = "\t",
                                                   header = T, colClasses = c("character", "numeric", "character"))


# First read in the flowJoXmlPaths with desired keywords
ws1 <-open_flowjo_xml(flowJoXmlPath1)
keywords2import=c("PATIENT ID", "Comp", "Antigen", "Status", "PLATE NAME", "TUBE NAME", "WELL ID")
sampleGroup <- "Samples"
ws1_filemap <- subset(flowJoWorkspace_sampleID_FileMapping, Experiment == "TBAgs_B1")[, c("sampleID", "file")]
missingFiles_b1 <- c("Specimen_001_B2_B02_012.fcs", "Specimen_001_B4_B04_014.fcs", "Specimen_001_B6_B06_016.fcs", "Specimen_001_B8_B08_018.fcs", "Specimen_001_B10_B10_020.fcs", "Specimen_001_C6_C06_066.fcs", "Specimen_001_C8_C08_068.fcs", "Specimen_001_A2_A02_112.fcs", "Specimen_001_A4_A04_114.fcs", "Specimen_001_A6_A06_116.fcs", "Specimen_001_A8_A08_118.fcs", "Specimen_001_A10_A10_120.fcs", "Specimen_001_A2_A02_192.fcs", "Specimen_001_A4_A04_194.fcs", "Specimen_001_A6_A06_196.fcs", "Specimen_001_A8_A08_198.fcs", "Specimen_001_A10_A10_200.fcs")
ws1_filemap <- ws1_filemap[which(!(ws1_filemap$file %in% missingFiles_b1)),]
ws1_filemap$file <- file.path(batch1FcsDirPath, ws1_filemap$file)
gs1 <-flowjo_to_gatingset(ws1, name=sampleGroup, keywords = keywords2import, path=ws1_filemap) # batch1FcsDirPath
#########################

The last line of code using flow_to_gatingset() returns the error "Error in path.expand(path) : invalid 'path' argument"

Is there a workaround or fix for this? Thanks!

@joliephan
Copy link

Hi there,

It looks like the "path" argument for flowjo_to_gatingset() should be the path wherever the FCS files are stored, like so:
gs1 <- flowjo_to_gatingset(ws1, name=sampleGroup, keywords=keywords2import, path=batch1FcsDirPath)

The "path" argument used to accept either a character scalar of the path to the FCS files or a data.frame containing sample IDs and their absolute paths (like ws1_filemap here). However, it looks like the functionality for the latter has been dropped in the updated versions of CytoML (see: RGLab/CytoML#112).

@malisas
Copy link
Contributor

malisas commented Jun 21, 2022

Hi @rachel7p and @joliephan, thanks for your comments. Like @joliephan mentioned, the path argument to flowjo_to_gatingset stopped supporting objects of type data.frame after we initially published this repository. I pushed a commit which should resolve the issue you mention (and I tested it on my Ubuntu machine to make sure it works). Due to the modification of FCS keywords by ImmPort, flowjo_to_gatingset needs help to match FlowJo workspace entries to FCS files. The previous workaround was the data.frame path argument. The new workaround builds up a named cytoset and passes that to the flowjo_to_gatingset function (see here).

By the way, if your primary purpose is to adapt the code for your own project, there is also this repository (specifically the R_v4.0.3 branch), which was published more recently (and I think the code is neater, though there is more of it). For example, the script to run COMPASS in that project uses parallelization, and I also have an alternative heatmap plotting function which uses ComplexHeatmap which might be useful (thought I'm not sure how well it generalizes to other datasets so it might need to be adapted a lot).

Thanks for giving the code a go!

For posterity, here is the sessionInfo() for my current test of the latest commit:

> sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.4 LTS

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

locale:
 [1] LC_CTYPE=C.UTF-8           LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=C.UTF-8        
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=C.UTF-8       
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
 [1] ggsignif_0.6.3           coin_1.4-2               survival_3.3-1          
 [4] svglite_2.1.0            cowplot_1.1.1            extrafont_0.18          
 [7] plyr_1.8.7               ggcyto_1.22.0            ncdfFlow_2.40.0         
[10] BH_1.78.0-0              RcppArmadillo_0.11.2.0.0 flowCore_2.6.0          
[13] data.table_1.14.2        COMPASS_1.32.0           forcats_0.5.1           
[16] stringr_1.4.0            dplyr_1.0.9              purrr_0.3.4             
[19] readr_2.1.2              tidyr_1.2.0              tibble_3.1.7            
[22] ggplot2_3.3.6            tidyverse_1.3.1          flowWorkspace_4.6.0     
[25] CytoML_2.6.0             here_1.0.1              

loaded via a namespace (and not attached):
 [1] TH.data_1.1-1       colorspace_2.0-3    ellipsis_0.3.2     
 [4] modeltools_0.2-23   rprojroot_2.0.3     cytolib_2.6.2      
 [7] base64enc_0.1-3     fs_1.5.2            clue_0.3-61        
[10] rstudioapi_0.13     hexbin_1.28.2       fansi_1.0.3        
[13] mvtnorm_1.1-3       lubridate_1.8.0     xml2_1.3.3         
[16] codetools_0.2-18    splines_4.1.2       libcoin_1.0-9      
[19] knitr_1.39          jsonlite_1.8.0      broom_0.8.0        
[22] Rttf2pt1_1.3.10     cluster_2.1.2       dbplyr_2.2.0       
[25] png_0.1-7           graph_1.72.0        compiler_4.1.2     
[28] httr_1.4.3          backports_1.4.1     assertthat_0.2.1   
[31] Matrix_1.4-0        cli_3.3.0           tools_4.1.2        
[34] gtable_0.3.0        glue_1.6.2          Rcpp_1.0.8.3       
[37] Biobase_2.54.0      cellranger_1.1.0    vctrs_0.4.1        
[40] extrafontdb_1.0     xfun_0.31           rvest_1.0.2        
[43] lifecycle_1.0.1     XML_3.99-0.10       zlibbioc_1.40.0    
[46] MASS_7.3-55         zoo_1.8-10          scales_1.2.0       
[49] RProtoBufLib_2.6.0  hms_1.1.1           parallel_4.1.2     
[52] RBGL_1.70.0         sandwich_3.0-2      RColorBrewer_1.1-3 
[55] yaml_2.3.5          curl_4.3.2          aws.signature_0.6.0
[58] gridExtra_2.3       latticeExtra_0.6-29 stringi_1.7.6      
[61] S4Vectors_0.32.4    BiocGenerics_0.40.0 rlang_1.0.2        
[64] pkgconfig_2.0.3     systemfonts_1.0.4   matrixStats_0.62.0 
[67] lattice_0.20-45     pdist_1.2.1         tidyselect_1.1.2   
[70] magrittr_2.0.3      R6_2.5.1            generics_0.1.2     
[73] multcomp_1.4-19     DBI_1.1.3           pillar_1.7.0       
[76] haven_2.5.0         withr_2.5.0         abind_1.4-5        
[79] modelr_0.1.8        crayon_1.5.1        utf8_1.2.2         
[82] tzdb_0.3.0          aws.s3_0.3.21       jpeg_0.1-9         
[85] readxl_1.4.0        Rgraphviz_2.38.0    reprex_2.0.1       
[88] digest_0.6.29       RcppParallel_5.1.5  stats4_4.1.2       
[91] munsell_0.5.0      

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

3 participants