How to fix missing values error message after SCTransform (Seurat)?
1
1
Entering edit mode
18 months ago
Pratik ▴ 840

Hey ya'll,

This is the error I am getting:

> scfp3 <- SCTransform(scfp3, method = "glmGamPoi", vars.to.regress = "percent.mt", verbose = FALSE)

Error in density.default(x = genes_log_gmean_step1, bw = "nrd", adjust = 1) : 
  'x' contains missing values
In addition: Warning message:
In vst(method = "glmGamPoi", umi = new("dgCMatrix", i = c(0L, 2L,  :
  NaNs produced

I think this error might be because there are zero integers in the expression matrix. For example the data frame looks like this enter image description here

Could someone help me solve this, please? I have been messing around with changing Na to zeros and vice versa, no solution yet. I will keep trying.

Seurat R SCTransform • 2.1k views
ADD COMMENT
2
Entering edit mode

I'd expect the genes with no expression may be messing things up, but the inner workings of SCTranscform are pretty opaque to me. I'd try removing all genes with no reads in any cells.

ADD REPLY
0
Entering edit mode

Thank you very much for responding @jared.andrews07! You've really helped me improve my scRNA-seq skills for sure through answering other questions.


So removing all genes with no reads in any cells helped reduce the size of the data frame.

I reran the commands, but obtained same results : (

I really do think those pesky zero's without decimal places are the problem.

Here's what a sample of the data frame looks like now:

enter image description here

Those zeros (in the W1738 column) are there. I think it has something to do with integer(0), and, I think, that's what those zeros are. Now if I could just find a way to convert them to the way the others zero's are (0.000) are. I think that might be the solution, maybe?

Or perhaps the zero's that are 0.000 have actual numbers in like the millionth place, making them like that.... hmmm

ADD REPLY
1
Entering edit mode

How are you reading in your counts? You might try converting them all to integers:

storage.mode(matrix_object) <- "integer"

I guess this could maybe be from cells that have no counts as well, but I'm guessing you would have already filtered any such offenders.

ADD REPLY
0
Entering edit mode

Thank you again Jared.

I tried:

storage.mode(mat) <- "integer"

And got the error:

Error in storage.mode(mat) <- "integer" : 
  'list' object cannot be coerced to type 'integer'

This is everything up until the error:

scRNA-seq of fetal pancreas 7-10 wpc

Link to datset: https://cells.ucsc.edu/?ds=human-pancreas-dev

Direct Expression Matrix Link: https://cells.ucsc.edu/human-pancreas-dev/fetal-pancreas/exprMatrix.tsv.gz

Direct Meta Data Link: https://cells.ucsc.edu/human-pancreas-dev/fetal-pancreas/meta.tsv

#Reading Matrix Matrix
mat <- read.table("~/Projects/fetal-pancreas-7-10wpc/exprMatrix.tsv", header=T, sep="\t")

#Converting ENSEMBL gene names to HGNC
library(biomaRt)
mart <- useMart('ENSEMBL_MART_ENSEMBL')
mart <- useDataset('hsapiens_gene_ensembl', mart)
annotLookup <- getBM(
  mart = mart,
  attributes = c(
    'hgnc_symbol',
    'ensembl_gene_id'),
  uniqueRows = TRUE)
colnames(annotLookup) <- c("gene", "ensembl")
colnames(mat)[1] <- c("ensembl")
mat <- merge(annotLookup, mat, by = "ensembl")

#removing ENSEMBL gene rows with no corresponding HGNC symbol
mat <- mat[!(is.na(mat$gene) | mat$gene==""), ]

#removing duplicate HGNC gene reads
mat = mat[!duplicated(mat$gene),]

#fixing up matrix
rownames(mat) <- mat$gene
mat$ensembl <- NULL
mat$gene <- NULL

#cleaning environment
rm("annotLookup", "mart")

#removing all genes with no reads in any cells.
mat <- mat[rowSums(mat[, -1])>0, ]
#removing cells with zero counts
mat <- mat[, colSums(mat == 0) != nrow(mat)] 

And now for Seurat...

################
#Loading Seurat#
################
library(dplyr)
library(Seurat)
library(patchwork)
library(ggplot2)
library(sctransform)
library("glmGamPoi")


scfp3 <- CreateSeuratObject(counts = mat, project = "scfp7to10wpc", meta.data=meta)
scfp3[["percent.mt"]] <- PercentageFeatureSet(scfp3, pattern = "^MT")
scfp3 <- SCTransform(scfp3, method = "glmGamPoi", vars.to.regress = "percent.mt", verbose = FALSE)



Warning in vst(method = "glmGamPoi", umi = new("dgCMatrix", i = c(0L, 2L,  :
  NaNs produced
Error in density.default(x = genes_log_gmean_step1, bw = "nrd", adjust = 1) : 
  'x' contains missing values

and then lastly:

> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.2 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8       
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] glmGamPoi_1.4.0    ggplot2_3.3.3      patchwork_1.1.1    SeuratObject_4.0.1
[5] Seurat_4.0.2       dplyr_1.0.6        sctransform_0.3.2  biomaRt_2.48.0    

loaded via a namespace (and not attached):
  [1] BiocFileCache_2.0.0         plyr_1.8.6                  igraph_1.2.6               
  [4] lazyeval_0.2.2              splines_4.1.0               listenv_0.8.0              
  [7] scattermore_0.7             GenomeInfoDb_1.28.0         digest_0.6.27              
 [10] htmltools_0.5.1.1           fansi_0.5.0                 magrittr_2.0.1             
 [13] memoise_2.0.0               tensor_1.5                  cluster_2.1.2              
 [16] ROCR_1.0-11                 globals_0.14.0              Biostrings_2.60.0          
 [19] matrixStats_0.58.0          spatstat.sparse_2.0-0       prettyunits_1.1.1          
 [22] colorspace_2.0-1            blob_1.2.1                  rappdirs_0.3.3             
 [25] ggrepel_0.9.1               xfun_0.23                   crayon_1.4.1               
 [28] RCurl_1.98-1.3              jsonlite_1.7.2              spatstat.data_2.1-0        
 [31] survival_3.2-11             zoo_1.8-9                   glue_1.4.2                 
 [34] polyclip_1.10-0             gtable_0.3.0                zlibbioc_1.38.0            
 [37] XVector_0.32.0              leiden_0.3.8                DelayedArray_0.18.0        
 [40] future.apply_1.7.0          BiocGenerics_0.38.0         abind_1.4-5                
 [43] scales_1.1.1                DBI_1.1.1                   miniUI_0.1.1.1             
 [46] Rcpp_1.0.6                  viridisLite_0.4.0           xtable_1.8-4               
 [49] progress_1.2.2              reticulate_1.20             spatstat.core_2.1-2        
 [52] bit_4.0.4                   stats4_4.1.0                htmlwidgets_1.5.3          
 [55] httr_1.4.2                  RColorBrewer_1.1-2          ellipsis_0.3.2             
 [58] ica_1.0-2                   pkgconfig_2.0.3             XML_3.99-0.6               
 [61] sass_0.4.0                  uwot_0.1.10                 dbplyr_2.1.1               
 [64] deldir_0.2-10               utf8_1.2.1                  tidyselect_1.1.1           
 [67] rlang_0.4.11                reshape2_1.4.4              later_1.2.0                
 [70] AnnotationDbi_1.54.0        munsell_0.5.0               tools_4.1.0                
 [73] cachem_1.0.5                generics_0.1.0              RSQLite_2.2.7              
 [76] ggridges_0.5.3              evaluate_0.14               stringr_1.4.0              
 [79] fastmap_1.1.0               yaml_2.2.1                  goftest_1.2-2              
 [82] knitr_1.33                  bit64_4.0.5                 fitdistrplus_1.1-3         
 [85] purrr_0.3.4                 RANN_2.6.1                  KEGGREST_1.32.0            
 [88] pbapply_1.4-3               future_1.21.0               nlme_3.1-152               
 [91] mime_0.10                   xml2_1.3.2                  compiler_4.1.0             
 [94] rstudioapi_0.13             plotly_4.9.3                filelock_1.0.2             
 [97] curl_4.3.1                  png_0.1-7                   spatstat.utils_2.1-0       
[100] tibble_3.1.2                bslib_0.2.5.1               stringi_1.6.2              
[103] lattice_0.20-44             Matrix_1.3-3                vctrs_0.3.8                
[106] pillar_1.6.1                lifecycle_1.0.0             jquerylib_0.1.4            
[109] spatstat.geom_2.1-0         lmtest_0.9-38               RcppAnnoy_0.0.18           
[112] data.table_1.14.0           cowplot_1.1.1               bitops_1.0-7               
[115] irlba_2.3.3                 httpuv_1.6.1                GenomicRanges_1.44.0       
[118] R6_2.5.0                    promises_1.2.0.1            KernSmooth_2.23-20         
[121] gridExtra_2.3               IRanges_2.26.0              parallelly_1.25.0          
[124] codetools_0.2-18            MASS_7.3-54                 assertthat_0.2.1           
[127] SummarizedExperiment_1.22.0 withr_2.4.2                 S4Vectors_0.30.0           
[130] GenomeInfoDbData_1.2.6      mgcv_1.8-35                 parallel_4.1.0             
[133] hms_1.1.0                   grid_4.1.0                  rpart_4.1-15               
[136] tidyr_1.1.3                 rmarkdown_2.8               MatrixGenerics_1.4.0       
[139] Rtsne_0.15                  Biobase_2.52.0              shiny_1.6.0   

I guess I should reach out on the Seurat/SCTransform GitHub?

ADD REPLY
1
Entering edit mode

What does any(is.na(mat)), any(is.nan(as.matrix(mat))), and any(is.null(as.matrix(mat))) yield? If all of those are FALSE, then yeah, I'd open an issue. If TRUE, then something with your matrix is screwy.

ADD REPLY
0
Entering edit mode

All FALSE.

Opened an issue: https://github.com/satijalab/seurat/issues/4546

Thank you for everything Jared. Hopefully, someone will swoop in there and save the day : )

ADD REPLY
2
Entering edit mode
18 months ago
Pratik ▴ 840

Turns out the data was already normalized (log-transformed).

This is why I wasn't able to run SCTransform on it.

https://github.com/satijalab/seurat/issues/4546#issuecomment-850074482

ADD COMMENT

Login before adding your answer.

Traffic: 1537 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6