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

Error in COMPASSContainerFromGatingSet due to boolean gate? #83

Open
pbMCs opened this issue Aug 7, 2024 · 0 comments
Open

Error in COMPASSContainerFromGatingSet due to boolean gate? #83

pbMCs opened this issue Aug 7, 2024 · 0 comments

Comments

@pbMCs
Copy link

pbMCs commented Aug 7, 2024

Hello! It's my first time using COMPASS and I have tried to resolve this issue by myself and looking at other people's scripts but I can't figure it out... My cytokine gates for IL-2 and IFNg came from a quadrant gate previously gated on flowjo, so for this analysis I previously created two new gates through a boolean filter taking the events from the corresponding quadrants with the gs_pop_add function from the flowWorkspace package:

bgIL2<- booleanFilter(CD4+/Q2: IL2+ , IFNG+|CD4+/Q3: IL2+ , IFNG-, filterId = "IL-2")
gs_pop_add(gs1, bgIL2, parent= "CD4+")

bgIFNG<- booleanFilter(CD4+/Q1: IL2- , IFNG+|CD4+/Q2: IL2+ , IFNG+, filterId = "IFNg")
gs_pop_add(gs1, bgIFNG, parent= "CD4+")

These gates seem correctly added to the gatingset and appear as "child nodes" of CD4+ when running gs_get_pop_path():

gs_get_pop_paths(gs1)
[1] "root"
[2] "/Time"
[3] "/Time/Single Cells SSC"
[4] "/Time/Single Cells SSC/Single Cells FSC"
[5] "/Time/Single Cells SSC/Single Cells FSC/Lymphocytes"
[6] "/Time/Single Cells SSC/Single Cells FSC/Lymphocytes/Live Cells"
[7] "/Time/Single Cells SSC/Single Cells FSC/Lymphocytes/Live Cells/CD3+"
[8] "/Time/Single Cells SSC/Single Cells FSC/Lymphocytes/Live Cells/CD3+/CD4+"
[9] "/Time/Single Cells SSC/Single Cells FSC/Lymphocytes/Live Cells/CD3+/CD4+/CD40L+"
[10] "/Time/Single Cells SSC/Single Cells FSC/Lymphocytes/Live Cells/CD3+/CD4+/GRZB"
[11] "/Time/Single Cells SSC/Single Cells FSC/Lymphocytes/Live Cells/CD3+/CD4+/IL-4"
[12] "/Time/Single Cells SSC/Single Cells FSC/Lymphocytes/Live Cells/CD3+/CD4+/IL-13"
[13] "/Time/Single Cells SSC/Single Cells FSC/Lymphocytes/Live Cells/CD3+/CD4+/IL-21"
[14] "/Time/Single Cells SSC/Single Cells FSC/Lymphocytes/Live Cells/CD3+/CD4+/TNFa"
[15] "/Time/Single Cells SSC/Single Cells FSC/Lymphocytes/Live Cells/CD3+/CD4+/IL-2"
[16] "/Time/Single Cells SSC/Single Cells FSC/Lymphocytes/Live Cells/CD3+/CD4+/IFNg"

But then when creating the compass container from the gating set I get this error (which disappears when removing those nodes):

Error in COMPASSContainerFromGatingSet(gs1[[2]], node = parent_node, individual_id = id, :
IL-2|IFNg are not the children node of /Time/Single Cells SSC/Single Cells FSC/Lymphocytes/Live Cells/CD3+/CD4+

To Reproduce

library(flowWorkspace)
#> Warning: package 'flowWorkspace' was built under R version 4.3.3
#> 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(COMPASS)
library(CytoML)
library(flowCore)
#> Warning: package 'flowCore' was built under R version 4.3.3
setwd("C:/Users/mcanyelles/Documents/Malaria Immunology/Studies/MAL067 T Cell Study/Results/Exploratory ICS MainBoost/COMPASS")

fcs_path<- "C:/Users/mcanyelles/Documents/Malaria Immunology/Studies/MAL067 T Cell Study/Results/Exploratory ICS MainBoost/COMPASS/data/fcs/20220526 TFH FCS"
ws1<- open_flowjo_xml("C:/Users/mcanyelles/Documents/Malaria Immunology/Studies/MAL067 T Cell Study/Results/Exploratory ICS MainBoost/COMPASS/data/20220526 ICS.wsp")
keywords2import=c("TUBE NAME","EXPERIMENT NAME")
SampleGroup<- "Test Samples"

gs1<- flowjo_to_gatingset(ws1, name=SampleGroup, keywords= keywords2import, path= fcs_path, extend_val= -10000)
# 
# pop_lists <- lapply(gs1, gh_get_pop_paths)
# unique(pop_lists)

gs1 <- gs_remove_redundant_channels(gs1) 

# will need to handle the IFNG and IL2 gates being quadrants 
# create a boolean gate to unify the 2 positive quadrants for each marker 

bgIL2<- booleanFilter(`CD4+/Q2: IL2+ , IFNG+|CD4+/Q3: IL2+ , IFNG-`, filterId = "IL-2")
gs_pop_add(gs1, bgIL2, parent= "CD4+")
#> [1] 262
bgIFNG<- booleanFilter(`CD4+/Q1: IL2- , IFNG+|CD4+/Q2: IL2+ , IFNG+`, filterId = "IFNg")
gs_pop_add(gs1, bgIFNG, parent= "CD4+")
#> [1] 263
recompute(gs1, "IL-2")
#> done!
recompute(gs1, "IFNg")
#> done!
# autoplot(gs1, "IL-2")
# autoplot(gs1, "IFNg")
# 
# gs_pop_remove(gs1, "CD4+/Q1: IL2- , IFNG+")
# gs_pop_remove(gs1, "CD4+/Q2: IL2+ , IFNG+")
# gs_pop_remove(gs1, "CD4+/Q3: IL2+ , IFNG-")
# gs_pop_remove(gs1, "CD4+/Q4: IL2- , IFNG-")
# gs_pop_remove(gs1, "CD40L+ or Q2: IL2+ , IFNG+ or Q3: IL2+ , IFNG-+ or TNFa+")

dput(unname(pData(parameters(gh_pop_get_data(gs1[[1]])))[,2]))
#> structure(c(NA, NA, NA, NA, "CD45RA", "IL21", "PD1", "CXCR5", 
#> "IL2", "IL4", "TNFA", "CCR7", "IL13", "CD8", "CD40L", "CD3", 
#> "CD14_AVID", "IFNG", "CD56", "CD4", "GRZMB", NA), class = "AsIs")
# structure(c(NA, NA, NA, NA, "CD45RA", "IL21", "PD1", "CXCR5", 
#             "IL2", "IL4", "TNFA", "CCR7", "IL13", "CD8", "CD40L", "CD3", 
#             "CD14_AVID", "IFNG", "CD56", "CD4", "GRZMB", NA), class = "AsIs")

markernames <- c("FSC-A", "FSC-H", "SSC-A", "SSC-H", "CD45RA", "IL21", "PD1", "CXCR5", 
                 "IL2", "IL4", "TNFA", "CCR7", "IL13", "CD8", "CD40L", "CD3", 
                 "CD14_AVID", "IFNG", "CD56", "CD4", "GRZMB", "Time" )
names(markernames) <- pData(parameters(gh_pop_get_data(gs1[[1]])))[,1]
markernames(gs1) <- markernames
pData(parameters(gh_pop_get_data(gs1[[1]])))[,c(1,2)]
#>                         name      desc
#> $P1                    FSC-A     FSC-A
#> $P2                    FSC-H     FSC-H
#> $P3                    SSC-A     SSC-A
#> $P4                    SSC-H     SSC-H
#> $P5  Comp-640-780_60-750LP-A    CD45RA
#> $P6        Comp-640-660_20-A      IL21
#> $P7  Comp-561-780_60-750LP-A       PD1
#> $P8  Comp-561-610_20-600LP-A     CXCR5
#> $P9  Comp-561-582_15-570LP-A       IL2
#> $P10 Comp-488-710_50-685LP-A       IL4
#> $P11 Comp-488-525_50-505LP-A      TNFA
#> $P12 Comp-403-780_60-750LP-A      CCR7
#> $P13 Comp-403-710_50-685LP-A      IL13
#> $P14 Comp-403-670_50-635LP-A       CD8
#> $P15 Comp-403-620_40-595LP-A     CD40L
#> $P16 Comp-403-585_42-570LP-A       CD3
#> $P17 Comp-403-525_50-505LP-A CD14_AVID
#> $P18       Comp-403-450_50-A      IFNG
#> $P19 Comp-350-730_45-685LP-A      CD56
#> $P20       Comp-350-379_28-A       CD4
#> $P21 Comp-640-710_50-690LP-A     GRZMB
#> $P22                    Time      Time
nodes_to_remove<- c("CD8+", "CD3-, CD56dim","CD3-, CD56hi",  "NKT-like","CD8-, CD4 -", "Q5: CCR7- , CD45RA+", "Q6: CCR7+ , CD45RA+ (Naïve)", 
                    "Q7: CCR7+ , CD45RA- (TCM)", "Q8: CCR7- , CD45RA- (TEM)", "CXCR5")

lapply(nodes_to_remove, function(node){
  gs1<- gs_pop_remove(gs1, node)
})

# plot(gs1, fontsize=70, bool=T)

get_stim <- function(x) {
  if (grepl("DMSO", x)) {
    "NC"
  } else {
    "CSP"
  }
}

pData(gs1)$stim<- sapply(pData(gs1)$name, get_stim)

get_id <- function(tube_name) {
  sub("_.*", "", tube_name)}


pData(gs1)$ID<- sapply(pData(gs1)$`TUBE NAME`, get_id)

# save_gs(gs1, file.path(getwd(),"out/GatingSet"))

# save_gslist()

set.seed(123)

parent_node<- "CD4+"

id<- "ID"

markernames(gs1)
#> Comp-640-780_60-750LP-A       Comp-640-660_20-A Comp-561-780_60-750LP-A 
#>                "CD45RA"                  "IL21"                   "PD1" 
#> Comp-561-610_20-600LP-A Comp-561-582_15-570LP-A Comp-488-710_50-685LP-A 
#>                 "CXCR5"                   "IL2"                   "IL4" 
#> Comp-488-525_50-505LP-A Comp-403-780_60-750LP-A Comp-403-710_50-685LP-A 
#>                  "TNFA"                  "CCR7"                  "IL13" 
#> Comp-403-670_50-635LP-A Comp-403-620_40-595LP-A Comp-403-585_42-570LP-A 
#>                   "CD8"                 "CD40L"                   "CD3" 
#> Comp-403-525_50-505LP-A       Comp-403-450_50-A Comp-350-730_45-685LP-A 
#>             "CD14_AVID"                  "IFNG"                  "CD56" 
#>       Comp-350-379_28-A Comp-640-710_50-690LP-A 
#>                   "CD4"                 "GRZMB"
markermap<- list("IL2", 
                 "IL4", "IL21", "TNFA", "IL13", "CD40L", "IFNG", "GRZMB")

names(markermap)<- c("IL-2", "IL-4", "IL-21", "TNFa", "IL-13", "CD40L+", "IFNg", "GRZB")

cc<- COMPASSContainerFromGatingSet(gs1[[2]],
                                   node= parent_node,
                                   individual_id= id,
                                   mp= markermap,
                                   countFilterThreshold = 5000,
                                   filter.fun= NULL)
#> Extracting cell counts
#> Fetching CD4+
#> Fetching child nodes
#> common markers are:
#> FSC-A FSC-H SSC-A SSC-H CD45RA IL21 PD1 CXCR5 IL2 IL4 TNFA CCR7 IL13 CD8 CD40L CD3 CD14_AVID IFNG CD56 CD4 GRZMB Time
#> Extracting single cell data for IL-2|IL-4|IL-21|TNFa|IL-13|CD40L+|IFNg|GRZB
#> Error in COMPASSContainerFromGatingSet(gs1[[2]], node = parent_node, individual_id = id, : IL-2|IFNg are not the children node of /Time/Single Cells SSC/Single Cells FSC/Lymphocytes/Live Cells/CD3+/CD4+

Created on 2024-08-07 with reprex v2.1.1

sessionInfo():
R version 4.3.1 (2023-06-16 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale:
[1] LC_COLLATE=Spanish_Spain.utf8 LC_CTYPE=Spanish_Spain.utf8 LC_MONETARY=Spanish_Spain.utf8 LC_NUMERIC=C
[5] LC_TIME=Spanish_Spain.utf8

time zone: Europe/Madrid
tzcode source: internal

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

other attached packages:
[1] ggcyto_1.30.2 ncdfFlow_2.48.0 BH_1.84.0-0 ggplot2_3.5.1 flowViz_1.66.0 lattice_0.22-6
[7] openCyto_2.14.0 COMPASS_1.40.0 flowWorkspace_4.14.3 flowCore_2.14.2 CytoML_2.14.0

loaded via a namespace (and not attached):
[1] gtable_0.3.5 xfun_0.45 latticeExtra_0.6-30 Biobase_2.62.0 vctrs_0.6.5 tools_4.3.1
[7] generics_0.1.3 stats4_4.3.1 parallel_4.3.1 tibble_3.2.1 fansi_1.0.6 cluster_2.1.6
[13] pkgconfig_2.0.3 KernSmooth_2.23-24 data.table_1.15.4 RColorBrewer_1.1-3 S4Vectors_0.40.2 graph_1.80.0
[19] lifecycle_1.0.4 farver_2.1.2 compiler_4.3.1 deldir_2.0-4 pdist_1.2.1 munsell_0.5.1
[25] clue_0.3-65 yaml_2.3.8 hexbin_1.28.3 pillar_1.9.0 tidyr_1.3.1 MASS_7.3-60.0.1
[31] abind_1.4-5 RProtoBufLib_2.14.1 tidyselect_1.2.1 dplyr_1.1.4 purrr_1.0.2 labeling_0.4.3
[37] flowClust_3.40.0 grid_4.3.1 colorspace_2.1-0 cli_3.6.2 magrittr_2.0.3 RBGL_1.78.0
[43] XML_3.99-0.16.1 utf8_1.2.4 withr_3.0.0 scales_1.3.0 matrixStats_1.3.0 jpeg_0.1-10
[49] interp_1.1-6 gridExtra_2.3 cytolib_2.14.1 png_0.1-8 knitr_1.47 rlang_1.1.3
[55] Rcpp_1.0.12 glue_1.7.0 Rgraphviz_2.46.0 BiocGenerics_0.48.1 rstudioapi_0.16.0 jsonlite_1.8.8
[61] R6_2.5.1 plyr_1.8.9 IDPmisc_1.1.21 zlibbioc_1.48.2

Here is the link to the workspace and fcs files to reproduce the error (I only included 2 samples): https://www.dropbox.com/scl/fo/hi5rj6kf7a3gqbjzjiwi2/AKjr-kB96d_V67eLR9PhDIc?rlkey=ujqo7jgbrjhmj6b1mjyrgwuh3&st=ab5jl4yg&dl=0

Thank you very much, any comment or suggestion will be very useful!

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

1 participant