BodenmillerGroup / imcRtools

An R package for handling and analysing imaging mass cytometry data
https://bodenmillergroup.github.io/imcRtools/
20 stars 9 forks source link

Error when trying to perform spillover correction on spe #110

Closed marleneweiss closed 1 year ago

marleneweiss commented 1 year ago

Hi,

I am facing an error that I haven't been able to resolve when running this code chunk: spe <- compCytof(spe, sm, transform = TRUE, cofactor = 1, isotope_list = isotope_list, overwrite = FALSE)

The error message is the following:

Error in .check_sm(x, isotope_list) : The supplied spillover matrix is invalid as it contains entries greater than 1. Valid spill values are non-negative and mustn't exceed 1.

However, the spillover matrix/corresponding csv file does not contain any values >1.

Have you encountered this error before?

sm.csv

Best, Marlene

nilseling commented 1 year ago

Hi @marleneweiss

did you visualize the spillover matrix? You have a spillover of 63900000% between Yb171 and Er168. Please have a look in your spillover acquisition if anything went wrong with acquiring these two channels.

marleneweiss commented 1 year ago

Hi @nilseling,

thank you for the quick reply! I did visualize the matrix and weirdly, it didn't show up there. sm_visualization_7_31

nilseling commented 1 year ago

And what's the output of plotSpotHeatmap(sce)?

marleneweiss commented 1 year ago

spotHeatmap

nilseling commented 1 year ago

Hmm, ok, thanks. That's strange. In general the plots look ok and I can't see why there is such a large entry on the spillover matrix. Could you send me the individual TXT files of the spillover acquisition to nils.eling@uzh.ch?

nilseling commented 1 year ago

Hi @marleneweiss

I was not able to reproduce the issue using the following code:

library(imcRtools)
library(CATALYST)
library(pheatmap)

sce <- readSCEfromTXT("Desktop/test_spillover/") 

assay(sce, "exprs") <- asinh(counts(sce)/5)

plotSpotHeatmap(sce)

bc_key <- as.numeric(unique(sce$sample_mass))
bc_key <- bc_key[order(bc_key)]

sce <- assignPrelim(sce, bc_key = bc_key)
sce <- estCutoffs(sce)
sce <- applyCutoffs(sce)

cur_table <- table(sce$bc_id, sce$sample_mass)

pheatmap(log10(cur_table + 1),
         cluster_rows = FALSE,
         cluster_cols = FALSE)

sce <- filterPixels(sce, minevents = 40, correct_pixels = TRUE)

cur_table <- table(sce$bc_id, sce$sample_mass)

pheatmap(log10(cur_table + 1),
         cluster_rows = FALSE,
         cluster_cols = FALSE)

sce <- computeSpillmat(sce)

isotope_list <- CATALYST::isotope_list
isotope_list$G <- 190

plotSpillmat(sce, isotope_list = isotope_list)

sm <- metadata(sce)$spillover_matrix

The spillover matrix does not contain values smaller than 0 or larger than 1. Could you please check and run your code again?

My sessionInfo is:

R version 4.3.0 (2023-04-21)
Platform: x86_64-apple-darwin20 (64-bit)
Running under: macOS Big Sur 11.7.4

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: Europe/Zurich
tzcode source: internal

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

other attached packages:
 [1] pheatmap_1.0.12             CATALYST_1.24.0             imcRtools_1.6.3             SpatialExperiment_1.10.0    SingleCellExperiment_1.22.0 SummarizedExperiment_1.30.2 Biobase_2.60.0             
 [8] GenomicRanges_1.52.0        GenomeInfoDb_1.36.1         IRanges_2.34.1              S4Vectors_0.38.1            BiocGenerics_0.46.0         MatrixGenerics_1.12.2       matrixStats_1.0.0          

loaded via a namespace (and not attached):
  [1] splines_4.3.0               later_1.3.1                 bitops_1.0-7                tibble_3.2.1                R.oo_1.25.0                 svgPanZoom_0.3.4            polyclip_1.10-4            
  [8] XML_3.99-0.14               lifecycle_1.0.3             rstatix_0.7.2               sf_1.0-14                   edgeR_3.42.4                doParallel_1.0.17           lattice_0.21-8             
 [15] vroom_1.6.3                 MASS_7.3-60                 backports_1.4.1             magrittr_2.0.3              limma_3.56.2                plotrix_3.8-2               httpuv_1.6.11              
 [22] sp_2.0-0                    cowplot_1.1.1               DBI_1.1.3                   RColorBrewer_1.1-3          ConsensusClusterPlus_1.64.0 multcomp_1.4-25             abind_1.4-5                
 [29] zlibbioc_1.46.0             Rtsne_0.16                  purrr_1.0.1                 R.utils_2.12.2              ggraph_2.1.0                RCurl_1.98-1.12             TH.data_1.1-2              
 [36] sandwich_3.0-2              tweenr_2.0.2                circlize_0.4.15             GenomeInfoDbData_1.2.10     ggrepel_0.9.3               RTriangle_1.6-0.12          irlba_2.3.5.1              
 [43] terra_1.7-39                units_0.8-2                 dqrng_0.3.0                 svglite_2.1.1               DelayedMatrixStats_1.22.1   codetools_0.2-19            DropletUtils_1.20.0        
 [50] DelayedArray_0.26.6         DT_0.28                     scuttle_1.10.1              ggforce_0.4.1               tidyselect_1.2.0            shape_1.4.6                 raster_3.6-23              
 [57] farver_2.1.1                ScaledMatrix_1.8.1          viridis_0.6.4               GetoptLong_1.0.5            BiocNeighbors_1.18.0        e1071_1.7-13                ellipsis_0.3.2             
 [64] tidygraph_1.2.3             scater_1.28.0               ggridges_0.5.4              survival_3.5-5              iterators_1.0.14            systemfonts_1.0.4           foreach_1.5.2              
 [71] ggnewscale_0.4.9            tools_4.3.0                 Rcpp_1.0.11                 glue_1.6.2                  gridExtra_2.3               EBImage_4.42.0              dplyr_1.1.2                
 [78] HDF5Array_1.28.1            shinydashboard_0.7.2        withr_2.5.0                 fastmap_1.1.1               rhdf5filters_1.12.1         fansi_1.0.4                 rsvd_1.0.5                 
 [85] digest_0.6.33               R6_2.5.1                    mime_0.12                   colorspace_2.1-0            gtools_3.9.4                jpeg_0.1-10                 R.methodsS3_1.8.2          
 [92] utf8_1.2.3                  tidyr_1.3.0                 generics_0.1.3              data.table_1.14.8           class_7.3-22                graphlayouts_1.0.0          htmlwidgets_1.6.2          
 [99] S4Arrays_1.0.5              pkgconfig_2.0.3             gtable_0.3.3                RProtoBufLib_2.12.1         ComplexHeatmap_2.16.0       XVector_0.40.0              htmltools_0.5.5            
[106] carData_3.0-5               fftwtools_0.9-11            clue_0.3-64                 scales_1.2.1                png_0.1-8                   colorRamps_2.3.1            rstudioapi_0.15.0          
[113] reshape2_1.4.4              tzdb_0.4.0                  rjson_0.2.21                zoo_1.8-12                  proxy_0.4-27                rhdf5_2.44.0                GlobalOptions_0.1.2        
[120] stringr_1.5.0               KernSmooth_2.23-22          parallel_4.3.0              vipor_0.4.5                 concaveman_1.1.0            pillar_1.9.0                grid_4.3.0                 
[127] vctrs_0.6.3                 ggpubr_0.6.0                promises_1.2.0.1            BiocSingular_1.16.0         car_3.1-2                   cytolib_2.12.1              distances_0.1.9            
[134] beachmat_2.16.0             xtable_1.8-4                cluster_2.1.4               archive_1.1.5               beeswarm_0.4.0              readr_2.1.4                 magick_2.7.4               
[141] mvtnorm_1.2-2               cli_3.6.1                   locfit_1.5-9.8              compiler_4.3.0              rlang_1.1.1                 crayon_1.5.2                ggsignif_0.6.4             
[148] classInt_0.4-9              FlowSOM_2.8.0               plyr_1.8.8                  flowCore_2.12.2             ggbeeswarm_0.7.2            stringi_1.7.12              viridisLite_0.4.2          
[155] BiocParallel_1.34.2         nnls_1.4                    cytomapper_1.12.0           munsell_0.5.0               tiff_0.1-11                 Matrix_1.6-0                hms_1.1.3                  
[162] sparseMatrixStats_1.12.2    bit64_4.0.5                 ggplot2_3.4.2               Rhdf5lib_1.22.0             shiny_1.7.4.1               drc_3.0-1                   broom_1.0.5                
[169] igraph_1.5.0.1              bit_4.0.5 
nilseling commented 1 year ago

Btw, I would recommend excluding Ir191 and Ir193 from spillover correction as nothing was spotted there.

marleneweiss commented 1 year ago

I ran the code again (the exact same code you sent) and the csv file does not include values > 1 but I still get the same error message when trying the compCytof code chunk. sm_3.csv spillmat_4_26

nilseling commented 1 year ago

I tested this on my side and

CATALYST:::.check_sm(sm, l = isotope_list)

does not return an error. Could you also send me the SPE object that you are trying to correct?

nilseling commented 1 year ago

Hi @marleneweiss

I cannot reproduce the issues you are having with the SPE you send me. The compensation works perfectly fine.

image

nilseling commented 1 year ago

Please restart your R session and start fresh - the error should then go away. And please close this issue once it works.

marleneweiss commented 1 year ago

It worked now, thank you so much!