Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No error message v.4.0.0 when count matrix has no rownames e.g. a data.table object passed #4063

Closed
vhorvath opened this issue Feb 11, 2021 · 3 comments
Labels
bug Something isn't working

Comments

@vhorvath
Copy link

When you initialize a Seurat Object in Seurat v3.2.3, CreateSeuratObject() will report that rownames ar missing. But v.4.0.0 will proceed silently with creating the object which is then will result in all kinds of errors, especially with subsetting. Those errors do not tell you much about what went wrong.

One can easily try to pass a data.frame looking object, e.g. a data.table as the input for count matrix which no longer supports the rownames attribute. Since data.table offers a very quick way of loading data and it is also memory efficient, it is popular. However, when interfacing with Seurat, one needs to make sure it is turned into something that supports rownames because that holds the feature identifiers. (This can be done via a simple as.sparse() call, but rownames still need to be manually added.)

A basic check on the presence and validity of rownames, i.e. if they are not just sequential integers would be very helpful at the time of initialization because currently, v4.0.0 is silent about the issue.

The code below will produce an error in v3.2.3, which is the expected behavior. v4.0.0 will be silent.

meta.data <- matrix(runif(100), 10, 10)
rownames(meta.data) <- paste0("cell", 1:10)
colnames(meta.data) <- paste0("attribute", 1:10)
meta.data <- data.frame(meta.data)

counts <- matrix(runif(1000), 100, 10)
colnames(counts) <- rownames(meta.data)
counts <- data.table::data.table(counts)
rownames(counts) <- paste0("feature", 1:100)

so_obj <- CreateSeuratObject(counts, project = "test", meta.data = meta.data)
Error in CreateAssayObject(counts = counts, min.cells = min.cells, min.features = min.features) : 
  No feature names (rownames) names present in the input matrix

In addition, since it seems to me that the trend is not to use rownames at all with the more advanced data structures e.g. tibble, data.table. It would be great if CreateSeuratObject() would support supplying the feature vector as a separate vector, and perhaps allowing for the meta.data input to have a cellnames/barcodes vector as well. Both could be by default rownames of the classic data.frames: i.e. features = rownames(counts) and barcodes = rownames(meta.data). This could also explicitly specify the requirements in the function definition. Seurat could still use the traditional data.frames internally.

SessionInfo:

R version 4.0.3 (2020-10-10)
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=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8       
 [4] LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8   
 [7] LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C          
[10] LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   

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

other attached packages:
[1] data.table_1.13.6  SeuratObject_4.0.0 Seurat_4.0.0      

loaded via a namespace (and not attached):
 [1] httr_1.4.2           tidyr_1.1.2          jsonlite_1.7.2      
 [4] viridisLite_0.3.0    splines_4.0.3        leiden_0.3.7        
 [7] shiny_1.6.0          ggrepel_0.9.1        globals_0.14.0      
[10] pillar_1.4.7         lattice_0.20-41      glue_1.4.2          
[13] reticulate_1.18      digest_0.6.27        polyclip_1.10-0     
[16] RColorBrewer_1.1-2   promises_1.1.1       colorspace_2.0-0    
[19] cowplot_1.1.1        htmltools_0.5.1.1    httpuv_1.5.5        
[22] Matrix_1.3-2         plyr_1.8.6           pkgconfig_2.0.3     
[25] listenv_0.8.0        purrr_0.3.4          xtable_1.8-4        
[28] patchwork_1.1.1      scales_1.1.1         RANN_2.6.1          
[31] tensor_1.5           later_1.1.0.1        Rtsne_0.15          
[34] spatstat.utils_2.0-0 tibble_3.0.6         mgcv_1.8-33         
[37] generics_0.1.0       ggplot2_3.3.3        ellipsis_0.3.1      
[40] ROCR_1.0-11          pbapply_1.4-3        lazyeval_0.2.2      
[43] deldir_0.2-9         survival_3.2-7       magrittr_2.0.1      
[46] crayon_1.4.1         mime_0.9             future_1.21.0       
[49] parallelly_1.23.0    nlme_3.1-152         MASS_7.3-53         
[52] ica_1.0-2            tools_4.0.3          fitdistrplus_1.1-3  
[55] lifecycle_0.2.0      matrixStats_0.58.0   stringr_1.4.0       
[58] plotly_4.9.3         munsell_0.5.0        cluster_2.1.0       
[61] irlba_2.3.3          compiler_4.0.3       rlang_0.4.10        
[64] scattermore_0.7      grid_4.0.3           ggridges_0.5.3      
[67] goftest_1.2-2        RcppAnnoy_0.0.18     htmlwidgets_1.5.3   
[70] igraph_1.2.6         miniUI_0.1.1.1       gtable_0.3.0        
[73] codetools_0.2-18     abind_1.4-5          reshape2_1.4.4      
[76] R6_2.5.0             gridExtra_2.3        zoo_1.8-8           
[79] dplyr_1.0.4          uwot_0.1.10          fastmap_1.1.0       
[82] future.apply_1.7.0   KernSmooth_2.23-18   spatstat.data_2.0-0 
[85] stringi_1.5.3        spatstat_1.64-1      parallel_4.0.3      
[88] Rcpp_1.0.6           rpart_4.1-15         png_0.1-7           
[91] vctrs_0.3.6          sctransform_0.3.2    tidyselect_1.1.0    
[94] lmtest_0.9-38
@timoast
Copy link
Collaborator

timoast commented Feb 12, 2021

Thanks for the detailed bug report, I have opened a PR in the SeuratObject repo that solves this issue

@mojaveazure
Copy link
Member

mojaveazure commented Feb 12, 2021

Hi Viktor, this has been addressed in the latest development version of SeuratObject. You can install this with the following:

remotes::install_github("mojaveazure/SeuratObject", ref = "develop")

@vhorvath
Copy link
Author

Thanks @mojaveazure & @timoast!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants