DillonHammill / CytoExploreR

Interactive Cytometry Data Analysis
61 stars 13 forks source link

Creating a quad gate fails #212

Open rwbaer opened 3 months ago

rwbaer commented 3 months ago

Describe the bug When creating a manual quad gate with cyto_gate_draw(), The graphical portion of the gate creation seems to work, but an error iis produced and the gate(s) are not added to the gating template.

To Reproduce Steps to reproduce the behavior: Execute this code on a loaded gating set called gsSamp

> cyto_gate_draw(gsSamp, 
+                parent = "Single Cells", 
+                alias = c("necrotic", "necrotic-apoptotic", "apoptotic", "live"), 
+                channels = c("FL2-AREA", "FL4-AREA"), 
+                type = "quadrant",
+                limits = "instrument")
Select the center point to construct quadrant gates. 

Adding newly constructed gate(s) to Samples-Template.csv .
...
Error in length(gs_nodes) == 0 || !popAlias %in% gs_nodes : 
  'length = 4' in coercion to 'logical(1)'
In addition: Warning message:
In par(pars) : argument 1 does not name a graphical parameter

Expected behavior I expect the four components of a quad gate to be created and added to the gating template.

Screenshots Graphically, things appear to be working: image

Desktop (please complete the following information):

> sessionInfo()
R version 4.4.1 (2024-06-14 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 11 x64 (build 22631)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8  LC_CTYPE=English_United States.utf8    LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C                           LC_TIME=English_United States.utf8    

time zone: America/Chicago
tzcode source: internal

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

other attached packages:
[1] shiny_1.9.0          CytoExploreR_1.1.0   openCyto_2.16.1      flowWorkspace_4.16.0 flowCore_2.16.0     

loaded via a namespace (and not attached):
 [1] changepoint_2.2.4   tidyselect_1.2.1    dplyr_1.1.4         fastmap_1.2.0       EmbedSOM_2.1.2     
 [6] promises_1.3.0      XML_3.99-0.17       digest_0.6.36       rsvd_1.0.5          mime_0.12          
[11] lifecycle_1.0.4     magrittr_2.0.3      compiler_4.4.1      rlang_1.1.4         sass_0.4.9         
[16] tools_4.4.1         yaml_2.3.10         utf8_1.2.4          data.table_1.15.4   knitr_1.48         
[21] askpass_1.2.0       htmlwidgets_1.6.4   reticulate_1.38.0   plyr_1.8.9          RColorBrewer_1.1-3 
[26] KernSmooth_2.23-24  Rtsne_0.17          purrr_1.0.2         RProtoBufLib_2.16.0 BiocGenerics_0.50.0
[31] grid_4.4.1          stats4_4.4.1        fansi_1.0.6         xtable_1.8-4        colorspace_2.1-1   
[36] flowAI_1.34.0       ggplot2_3.5.1       scales_1.3.0        MASS_7.3-60.2       cli_3.6.3          
[41] rmarkdown_2.27      ncdfFlow_2.50.0     generics_0.1.3      umap_0.2.10.0       rstudioapi_0.16.0  
[46] robustbase_0.99-3   RSpectra_0.16-2     reshape2_1.4.4      visNetwork_2.1.2    cachem_1.1.0       
[51] stringr_1.5.1       zlibbioc_1.50.0     parallel_4.4.1      rhandsontable_0.3.8 matrixStats_1.3.0  
[56] vctrs_0.6.5         Matrix_1.7-0        jsonlite_1.8.8      cytolib_2.16.0      S4Vectors_0.42.0   
[61] RBGL_1.80.0         Rgraphviz_2.48.0    jquerylib_0.1.4     tidyr_1.3.1         glue_1.7.0         
[66] DEoptimR_1.1-3      stringi_1.8.4       gtable_0.3.5        later_1.3.2         munsell_0.5.1      
[71] tibble_3.2.1        pillar_1.9.0        htmltools_0.5.8.1   openssl_2.2.0       graph_1.82.0       
[76] R6_2.5.1            evaluate_0.24.0     Biobase_2.64.0      lattice_0.22-6      png_0.1-8          
[81] memoise_2.0.1       httpuv_1.6.15       bslib_0.8.0         Rcpp_1.0.13         flowClust_3.42.0   
[86] xfun_0.46           fs_1.6.4            zoo_1.8-12          pkgconfig_2.0.3    

Additional query about a warning Side query. For some time now I have been receiving the warning. I don't believe I used to get it. Is it something of known origin that I should be worried about? In addition: Warning message: In par(pars) : argument 1 does not name a graphical parameter

rwbaer commented 2 months ago

This issue report could be related to/confounded with issue #210.

As a follow-up, I deleted my samples-template.csv and tried creating my quad gate BEFORE creating my two interval gates. I was able to successfully add my quad gate without an error. I can't prove this; just a theory?


> library(CytoExploreR)
> gsSamp <- cyto_setup(path = "Samples",
+                  gatingTemplate = "Samples-Template.csv",
+                  details = "Samples-Details.csv",
+                  restrict = TRUE)
Loading FCS files into a GatingSet...
Assigning markers to channels...
Experiment-Markers.csv found in working directory.
Updating experiment details...
Samples-Details.csv found in working directory.
Removing unassigned channels...
Setting Samples-Template.csv as the active gatingTemplate...
Creating Samples-Template.csv ...
Done!
> # Apply compensation to samples, based on the spill matrix calculated with our calibration beads
> gsSamp <- cyto_compensate(gsSamp,
+                       spillover = "Spillover-Matrix.csv")
> # Show us what we have
> cyto_channels(gsSamp)
 [1] "TIME_MSW"   "TIME_LSW"   "FSC-HEIGHT" "FSC-AREA"   "FSC-WIDTH"  "SSC-HEIGHT" "SSC-AREA"   "SSC-WIDTH" 
 [9] "FL2-AREA"   "FL4-AREA"  
> cyto_markers(gsSamp)
       TIME_MSW      FSC-HEIGHT        FSC-AREA        SSC-AREA        FL2-AREA        FL4-AREA 
         "TIME"    "FSC-HEIGHT"      "FSC-AREA"      "SSC-AREA" "AnnexinV-AREA" "SytoxAAD-AREA" 
> cyto_fluor_channels(gsSamp)
[1] "FL2-AREA" "FL4-AREA"

> # We use asinh because logicle fails out of the box.
> transList <- cyto_transformer_arcsinh(gsSamp)
Warning messages:
1: In par(pars) : argument 1 does not name a graphical parameter
2: In par(pars) : argument 1 does not name a graphical parameter
> # Apply our asinh transform for better viewing of our data
> # never do this line more than once.  Start over if in doubt.
> gsSamp = cyto_transform(gsSamp, trans = transList)
Warning messages:
1: In par(pars) : argument 1 does not name a graphical parameter
2: In par(pars) : argument 1 does not name a graphical parameter
> # Gate (non-debris) Cells (gating template Samples.csv)
>############
> # Draw Gates
>############
> cyto_gate_draw(gsSamp,
+                parent = "root",
+                alias = "Non-Debris",
+                channels = c("FSC-AREA", "SSC-AREA"))
Select at least 3 points to construct a polygon gate around the Non-Debris population. 

Adding newly constructed gate(s) to Samples-Template.csv .
...
done
Warning message:
In par(pars) : argument 1 does not name a graphical parameter
> # Gate Single Cells (gating template Samples.csv)
> cyto_gate_draw(gsSamp,
+                parent = "Non-Debris",
+                alias = "Single Cells",
+                channels = c("FSC-AREA", "FSC-HEIGHT"))
Select at least 3 points to construct a polygon gate around the Single Cells population. 

Adding newly constructed gate(s) to Samples-Template.csv .
...
done
Warning message:
In par(pars) : argument 1 does not name a graphical parameter
>###################
> # Draw Quad gate
>###################
> # necrosis and apoptosis
> # Quad gate - named clockwise from upper left
> cyto_gate_draw(gsSamp, 
+                parent = "Single Cells", 
+                alias = c("necrotic", "necrotic-apoptotic", "apoptotic", "live"), 
+                channels = c("FL2-AREA", "FL4-AREA"), 
+                type = "quadrant",
+                limits = "instrument")
Select the center point to construct quadrant gates. 

Adding newly constructed gate(s) to Samples-Template.csv .
...
done
Warning message:
In par(pars) : argument 1 does not name a graphical parameter
> # Gate Live Single Cells
> # Gate SytoxAAD on Unstained
> cyto_gate_draw(gsSamp,
+                parent = "Single Cells",
+                alias = c("Live", "Dead"),
+                channels = "FL4-AREA",
+                type = "interval",
+                negate = TRUE)
Select the lower and upper bounds of the Live population to construct an interval gate. 

Adding newly constructed gate(s) to Samples-Template.csv .
...
done
Warning message:
In par(pars) : argument 1 does not name a graphical parameter
> # Gate Annexin-pos Cells
> cyto_gate_draw(gsSamp,
+                parent = "Single Cells",
+                alias = c("Annexin+", "Annexin-"),
+                channels = "FL2-AREA",
+                type = "interval",
+                negate = TRUE)
Select the lower and upper bounds of the Annexin+ population to construct an interval gate. 

Adding newly constructed gate(s) to Samples-Template.csv .
...
done
Warning message:
In par(pars) : argument 1 does not name a graphical parameter
> # cyto_plot_gating_scheme(gsSamp)
> cyto_plot_gating_tree(gsSamp)   # Cytoexplorer version of gating tree

The gates appear to create properly: image

So, it now seems everything has gone well, but try to apply the Sample-Template

> cyto_gatingTemplate_apply(gsSamp, gatingTemplate = "Samples-Template")
Applying Samples-Template.csv to the GatingSet...
Preprocessing for 'Non-Debris'
Gating for 'Non-Debris'
done!
done.
Preprocessing for 'Single Cells'
Gating for 'Single Cells'
done!
done.
Preprocessing for 'Annexin+'
Gating for 'Annexin+'
done!
done.
Annexin- gating...
done!
done.
Preprocessing for 'Live'
Gating for 'Live'
done!
done.
Dead gating...
done!
done.
Error in length(gs_nodes) == 0 || !popAlias %in% gs_nodes : 
  'length = 4' in coercion to 'logical(1)'

We see the same error that we did when I was trying to add the quad gate before. This makes it look like issue #210 is involved.