satijalab / sctransform

R package for modeling single cell UMI expression data using regularized negative binomial regression
GNU General Public License v3.0
208 stars 33 forks source link

warning: solve(): system is singular; attempting approx solution Error in h(simpleError(msg, call)) : #134

Closed lima1 closed 2 years ago

lima1 commented 2 years ago

Hi,

I have a crash in SCTransform in a slightly odd Visium core needle biopsy sample (small tissue patches of very high coverage). The crash is fixed in sctransform2, but maybe the output makes it obvious for you what's the issue with the count matrix? There were a couple of similar closed issues, but I think this crash is new.

Our production pipelines are unfortunately not yet on Seurat 4.1, so looking for a v1 workaround if possible.

Calculating cell attributes from input UMI matrix: log_umi
Variance stabilizing transformation of count matrix of size 16561 by 410
Model formula is y ~ log_umi
Get Negative Binomial regression parameters per gene
Using 2000 genes, 410 cells
  |                                                                      |   0%
warning: solve(): system is singular; attempting approx solution
Error in h(simpleError(msg, call)) : 
  error in evaluating the argument 'x' in selecting a method for function 't': missing value where TRUE/FALSE needed
Calls: normalize_spatial ... resolve.list -> signalConditionsASAP -> signalConditions
In addition: Warning message:
In sparseMatrix(i = indices[] + 1, p = indptr[], x = as.numeric(x = counts[]),  :
  'giveCsparse' has been deprecated; setting 'repr = "T"' for you

Here with v2:

vst.flavor='v2' set, setting model to use fixed slope and exclude poisson genes.
Calculating cell attributes from input UMI matrix: log_umi
Total Step 1 genes: 16561
Total overdispersed genes: 10872
Excluding 5689 genes from Step 1 because they are not overdispersed.
Variance stabilizing transformation of count matrix of size 16561 by 410
Model formula is y ~ log_umi
Get Negative Binomial regression parameters per gene
Using 2000 genes, 410 cells
  |======================================================================| 100%
Setting estimate of  130 genes to inf as theta_mm/theta_mle < 1e-3
# of step1 poisson genes (variance < mean): 0
# of low mean genes (mean < 0.001): 0
Total # of Step1 poisson genes (theta=Inf; variance < mean): 130
Total # of poisson genes (theta=Inf; variance < mean): 5689
Calling offset model for all 5689 poisson genes
Found 130 outliers - those will be ignored in fitting/regularization step

Ignoring theta inf genes
Replacing fit params for 5689 poisson genes by theta=Inf
Setting min_variance based on median UMI:  0.04
Second step: Get residuals using fitted parameters for 16561 genes
  |======================================================================| 100%
Computing corrected count matrix for 16561 genes
  |======================================================================| 100%
Calculating gene attributes
Wall clock passed: Time difference of 11.19019 secs
Determine variable features
Place corrected count matrix in counts slot
Centering data matrix
  |======================================================================| 100%
> sessionInfo()
R version 4.1.1 (2021-08-10)
Platform: x86_64-conda-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS/LAPACK: /home/riestma1/miniconda3/envs/R/lib/libopenblasp-r0.3.18.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.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] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] sttkit_0.1.2        ggplot2_3.3.5       SeuratObject_4.0.4 
[4] Seurat_4.1.0        reshape2_1.4.4      futile.logger_1.4.3
[7] optparse_1.6.6     

loaded via a namespace (and not attached):
  [1] Rtsne_0.15             colorspace_2.0-3       deldir_1.0-6          
  [4] ellipsis_0.3.2         ggridges_0.5.3         XVector_0.34.0        
  [7] spatstat.data_2.1-2    leiden_0.3.9           listenv_0.8.0         
 [10] getopt_1.20.3          ggrepel_0.9.1          bit64_4.0.5           
 [13] AnnotationDbi_1.56.1   fansi_1.0.2            codetools_0.2-18      
 [16] splines_4.1.1          cachem_1.0.6           polyclip_1.10-0       
 [19] jsonlite_1.8.0         ica_1.0-2              cluster_2.1.2         
 [22] png_0.1-7              uwot_0.1.11            shiny_1.7.1           
 [25] sctransform_0.3.3      spatstat.sparse_2.1-0  compiler_4.1.1        
 [28] httr_1.4.2             assertthat_0.2.1       Matrix_1.4-0          
 [31] fastmap_1.1.0          lazyeval_0.2.2         later_1.2.0           
 [34] formatR_1.11           htmltools_0.5.2        tools_4.1.1           
 [37] igraph_1.2.11          GenomeInfoDbData_1.2.7 gtable_0.3.0          
 [40] glue_1.6.2             RANN_2.6.1             dplyr_1.0.7           
 [43] Rcpp_1.0.8             Biobase_2.54.0         scattermore_0.8       
 [46] Biostrings_2.62.0      vctrs_0.3.8            nlme_3.1-155          
 [49] lmtest_0.9-39          spatstat.random_2.1-0  stringr_1.4.0         
 [52] globals_0.14.0         mime_0.12              miniUI_0.1.1.1        
 [55] lifecycle_1.0.1        irlba_2.3.5            goftest_1.2-3         
 [58] future_1.24.0          zlibbioc_1.40.0        MASS_7.3-55           
 [61] zoo_1.8-9              scales_1.1.1           spatstat.core_2.4-0   
 [64] promises_1.2.0.1       spatstat.utils_2.3-0   parallel_4.1.1        
 [67] lambda.r_1.2.4         RColorBrewer_1.1-2     memoise_2.0.1         
 [70] reticulate_1.24        pbapply_1.5-0          gridExtra_2.3         
 [73] rpart_4.1.16           stringi_1.7.6          RSQLite_2.2.8         
 [76] S4Vectors_0.32.3       BiocGenerics_0.40.0    GenomeInfoDb_1.30.0   
 [79] bitops_1.0-7           rlang_0.4.12           pkgconfig_2.0.3       
 [82] matrixStats_0.61.0     lattice_0.20-45        ROCR_1.0-11           
 [85] purrr_0.3.4            tensor_1.5             patchwork_1.1.1       
 [88] htmlwidgets_1.5.4      cowplot_1.1.1          bit_4.0.4             
 [91] tidyselect_1.1.1       parallelly_1.30.0      RcppAnnoy_0.0.19      
 [94] plyr_1.8.6             magrittr_2.0.2         R6_2.5.1              
 [97] IRanges_2.28.0         generics_0.1.2         DBI_1.1.2             
[100] pillar_1.7.0           withr_2.5.0            mgcv_1.8-39           
[103] fitdistrplus_1.1-6     RCurl_1.98-1.6         KEGGREST_1.34.0       
[106] survival_3.3-1         abind_1.4-5            tibble_3.1.6          
[109] future.apply_1.8.1     hdf5r_1.3.3            crayon_1.5.0          
[112] futile.options_1.0.1   KernSmooth_2.23-20     utf8_1.2.2            
[115] spatstat.geom_2.3-2    plotly_4.10.0          grid_4.1.1            
[118] data.table_1.14.2      blob_1.2.2             digest_0.6.27         
[121] xtable_1.8-4           tidyr_1.2.0            httpuv_1.6.5          
[124] stats4_4.1.1           munsell_0.5.0          viridisLite_0.4.0   
saketkc commented 2 years ago

Can you try invoking glmGamPoi method inside SCTransform: SCTransform(method="glmGamPoi")

lima1 commented 2 years ago

Worked, thanks!