DillonHammill / CytoExploreR

Interactive Cytometry Data Analysis
60 stars 13 forks source link

cyto_compensate(gsSamp, select = NULL) fails with restricted channels #197

Open rwbaer opened 4 months ago

rwbaer commented 4 months ago

Describe the bug I'm trying to use the built in compensation of my data files, but it fails when I'm not using FL3-AREA and the off diagonals are all 0. cyto_spillover_extract(gsSamp[[1]]) produces NULL rather than a restricted spill matrix. cyto_compensate(gsSamp, select = NULL) claims compensation not found.

There is a matrix present in the files because I can extract it by brutt force. See below for an example. By brutt force I seem to get cyto_spillover_extract() to work after cyto_compensate(), but when I then try to use cyto_spillover_edit() I get a dimname error.

# Check what we have - note FL3-AREA is restricted
cyto_fluor_channels(gsSamp)
cyto_markers(gsSamp) 
# TIME_LSW      FSC-HEIGHT        FSC-AREA        SSC-AREA        FL1-AREA        FL2-AREA        FL4-AREA 
# "TIME"    "FSC-HEIGHT"      "FSC-AREA"      "SSC-AREA"    "CD271-AREA"     "CD44-AREA" "SytoxAAD-AREA" 

# Apply built-in spillover matrix to samples --> fails
cyto_compensate(gsSamp, select = NULL) # Use each samples built in matrix
# Error: compensation not found for: 2024-02-19_LM71_Combination_Day01.fcs

#  This produces NULL rather than correct result
# The problem appears related to not using FL3-AREA ??
spill <- cyto_spillover_extract(gsSamp[[1]])
spill
# NULL

# workaround
ff = cyto_extract(gsSamp[[1]])
sm1 = keyword(ff)$`$SPILLOVER` # spill matrix
sm1
#      FL1-AREA FL2-AREA FL3-AREA FL4-AREA
# [1,] 1.000000 0.111111        0 0.074074
# [2,] 0.000815 1.000000        0 0.053790
# [3,] 0.000000 0.000000        1 0.000000
# [4,] 0.002513 0.000000        0 1.000000

sm1 = sm1[-3,-3]
rownames(sm1) = colnames(sm1)
sm1
write.csv(sm1, "spill_matrix.csv")
cyto_compensate(gsSamp,  "spill_matrix.csv")

# now extraction seems to work as expected.  I'm not sure how this  is saved for the gating set files or if there is an extractor function
# to find out it is actually working
spill_new <- cyto_spillover_extract(gsSamp[[1]])
spill_new
# $`2024-02-19_LM71_Combination_Day01.fcs`
# FL1-AREA FL2-AREA FL4-AREA
# FL1-AREA 1.000000 0.111111 0.074074
# FL2-AREA 0.000815 1.000000 0.053790
# FL4-AREA 0.002513 0.000000 1.000000

# Even now, cyto_spillover_edit fails
#  cyto_spillover_edit(gsSamp) Error in dimnames(x) <- dn :    length of 'dimnames' [2] not equal to array extent

Desktop (please complete the following information): Windows 11 version _
platform x86_64-w64-mingw32
arch x86_64
os mingw32
crt ucrt
system x86_64, mingw32
status
major 4
minor 3.3
year 2024
month 02
day 29
svn rev 86002
language R
version.string R version 4.3.3 (2024-02-29 ucrt) nickname Angel Food Cake

Additional context

sessionInfo() R version 4.3.3 (2024-02-29 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 11 x64 (build 26063)

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.8.0 patchwork_1.2.0 CytoExploreR_1.1.0 openCyto_2.14.0 flowWorkspace_4.14.2 flowCore_2.14.1
[7] xlsx_0.6.5 readxl_1.4.3 dplyr_1.1.4 ggplot2_3.5.0

loaded via a namespace (and not attached): [1] changepoint_2.2.4 tidyselect_1.2.0 fastmap_1.1.1 EmbedSOM_2.1.2 promises_1.2.1 XML_3.99-0.16.1 digest_0.6.34
[8] rsvd_1.0.5 mime_0.12 lifecycle_1.0.4 ellipsis_0.3.2 magrittr_2.0.3 compiler_4.3.3 rlang_1.1.3
[15] sass_0.4.8 tools_4.3.3 yaml_2.3.8 utf8_1.2.4 data.table_1.15.0 knitr_1.45 askpass_1.2.0
[22] htmlwidgets_1.6.4 reticulate_1.35.0 plyr_1.8.9 RColorBrewer_1.1-3 pkgload_1.3.4 Rtsne_0.17 withr_3.0.0
[29] purrr_1.0.2 RProtoBufLib_2.14.0 BiocGenerics_0.48.1 grid_4.3.3 stats4_4.3.3 fansi_1.0.6 xtable_1.8-4
[36] colorspace_2.1-0 flowAI_1.32.0 scales_1.3.0 MASS_7.3-60.0.1 cli_3.6.2 rmarkdown_2.25 ncdfFlow_2.48.0
[43] generics_0.1.3 umap_0.2.10.0 rstudioapi_0.15.0 robustbase_0.99-2 RSpectra_0.16-1 reshape2_1.4.4 visNetwork_2.1.2
[50] cachem_1.0.8 stringr_1.5.1 zlibbioc_1.48.0 parallel_4.3.3 rhandsontable_0.3.8 cellranger_1.1.0 matrixStats_1.2.0
[57] vctrs_0.6.5 Matrix_1.6-5 jsonlite_1.8.8 cytolib_2.14.1 S4Vectors_0.40.2 RBGL_1.78.0 Rgraphviz_2.46.0
[64] jquerylib_0.1.4 tidyr_1.3.1 glue_1.7.0 DEoptimR_1.1-3 rJava_1.0-11 stringi_1.8.3 gtable_0.3.4
[71] later_1.3.2 munsell_0.5.0 tibble_3.2.1 pillar_1.9.0 xlsxjars_0.6.1 htmltools_0.5.7 openssl_2.1.1
[78] graph_1.80.0 R6_2.5.1 evaluate_0.23 lattice_0.22-5 Biobase_2.62.0 png_0.1-8 memoise_2.0.1
[85] httpuv_1.6.14 bslib_0.6.1 Rcpp_1.0.12 flowClust_3.40.0 xfun_0.42 fs_1.6.3 zoo_1.8-12
[92] pkgconfig_2.0.3