Error in conversion of SCE object to Seurat Object.
1
0
Entering edit mode
@rohitsatyam102-24390
Last seen 24 days ago
India

Hi Everyone

I was trying to convert my Single Cell Experiment Object into Seurat, but for some reason, it is failing. Can I get some help here? I looked up the source code of Tsparse of Package Matrix and it's breaking somewhere there. But I don't know the workaround!!

Below is the code and session info:

seurat <- as.Seurat(sce_clean,counts = "counts", data = "logcounts",assay = 'RNA',project = 'SingleCellExperiment')
Warning: Non-unique cell names (colnames) present in the input matrix, making unique
Warning: Feature names cannot have underscores ('_'), replacing with dashes ('-')
Warning: Feature names cannot have underscores ('_'), replacing with dashes ('-')
Error in intI(j, n = d[2], dn[[2]], give.dn = FALSE) : 
  invalid character indexing
> sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-conda-linux-gnu (64-bit)
Running under: Ubuntu 20.04.2 LTS

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

locale:
 [1] LC_CTYPE=en_IN.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_IN.UTF-8        LC_COLLATE=en_IN.UTF-8    
 [5] LC_MONETARY=en_IN.UTF-8    LC_MESSAGES=en_IN.UTF-8   
 [7] LC_PAPER=en_IN.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_IN.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
 [1] SeuratObject_4.0.0          Seurat_4.0.1               
 [3] scDblFinder_1.4.0           scran_1.18.7               
 [5] BiocSingular_1.6.0          harmony_1.0                
 [7] Rcpp_1.0.6                  scater_1.18.6              
 [9] ggplot2_3.3.3               DropletUtils_1.10.3        
[11] scales_1.1.1                SingleCellExperiment_1.12.0
[13] SummarizedExperiment_1.20.0 Biobase_2.50.0             
[15] GenomicRanges_1.42.0        GenomeInfoDb_1.26.7        
[17] IRanges_2.24.1              MatrixGenerics_1.2.1       
[19] matrixStats_0.58.0          S4Vectors_0.28.1           
[21] BiocGenerics_0.36.1        

loaded via a namespace (and not attached):
  [1] utf8_1.2.1                reticulate_1.19          
  [3] R.utils_2.10.1            tidyselect_1.1.1         
  [5] htmlwidgets_1.5.3         grid_4.0.3               
  [7] BiocParallel_1.24.1       Rtsne_0.15               
  [9] devtools_2.4.0            munsell_0.5.0            
 [11] codetools_0.2-18          ica_1.0-2                
 [13] statmod_1.4.35            xgboost_1.4.1.1          
 [15] future_1.21.0             miniUI_0.1.1.1           
 [17] withr_2.4.2               colorspace_2.0-0         
 [19] rstudioapi_0.13           ROCR_1.0-11              
 [21] tensor_1.5                listenv_0.8.0            
 [23] labeling_0.4.2            GenomeInfoDbData_1.2.4   
 [25] polyclip_1.10-0           farver_2.1.0             
 [27] rhdf5_2.34.0              rprojroot_2.0.2          
 [29] parallelly_1.24.0         vctrs_0.3.8              
 [31] generics_0.1.0            R6_2.5.0                 
 [33] ggbeeswarm_0.6.0          rsvd_1.0.5               
 [35] locfit_1.5-9.4            bitops_1.0-7             
 [37] rhdf5filters_1.2.0        spatstat.utils_2.1-0     
 [39] cachem_1.0.4              DelayedArray_0.16.3      
 [41] assertthat_0.2.1          promises_1.2.0.1         
 [43] beeswarm_0.3.1            gtable_0.3.0             
 [45] beachmat_2.6.4            globals_0.14.0           
 [47] processx_3.5.1            goftest_1.2-2            
 [49] rlang_0.4.10              splines_4.0.3            
 [51] lazyeval_0.2.2            spatstat.geom_2.1-0      
 [53] BiocManager_1.30.12       yaml_2.2.1               
 [55] reshape2_1.4.4            abind_1.4-5              
 [57] httpuv_1.6.0              usethis_2.0.1            
 [59] tools_4.0.3               ellipsis_0.3.2           
 [61] spatstat.core_2.1-2       RColorBrewer_1.1-2       
 [63] sessioninfo_1.1.1         ggridges_0.5.3           
 [65] plyr_1.8.6                sparseMatrixStats_1.2.1  
 [67] zlibbioc_1.36.0           purrr_0.3.4              
 [69] RCurl_1.98-1.3            ps_1.6.0                 
 [71] prettyunits_1.1.1         rpart_4.1-15             
 [73] deldir_0.2-10             pbapply_1.4-3            
 [75] viridis_0.6.0             cowplot_1.1.1            
 [77] zoo_1.8-9                 ggrepel_0.9.1            
 [79] cluster_2.1.2             fs_1.5.0                 
 [81] magrittr_2.0.1            data.table_1.14.0        
 [83] RSpectra_0.16-0           scattermore_0.7          
 [85] lmtest_0.9-38             RANN_2.6.1               
 [87] fitdistrplus_1.1-3        pkgload_1.2.1            
 [89] patchwork_1.1.1           mime_0.10                
 [91] xtable_1.8-4              gridExtra_2.3            
 [93] testthat_3.0.2            compiler_4.0.3           
 [95] tibble_3.1.1              KernSmooth_2.23-18       
 [97] crayon_1.4.1              R.oo_1.24.0              
 [99] htmltools_0.5.1.1         mgcv_1.8-35              
[101] later_1.2.0               tidyr_1.1.3              
[103] DBI_1.1.1                 MASS_7.3-53.1            
[105] Matrix_1.3-2              cli_2.5.0                
[107] R.methodsS3_1.8.1         igraph_1.2.6             
[109] pkgconfig_2.0.3           plotly_4.9.3             
[111] scuttle_1.0.4             spatstat.sparse_2.0-0    
[113] vipor_0.4.5               dqrng_0.2.1              
[115] XVector_0.30.0            stringr_1.4.0            
[117] callr_3.7.0               digest_0.6.27            
[119] sctransform_0.3.2         RcppAnnoy_0.0.18         
[121] spatstat.data_2.1-0       leiden_0.3.7             
[123] uwot_0.1.10               edgeR_3.32.1             
[125] DelayedMatrixStats_1.12.3 shiny_1.6.0              
[127] lifecycle_1.0.0           nlme_3.1-152             
[129] jsonlite_1.7.2            Rhdf5lib_1.12.1          
[131] BiocNeighbors_1.8.2       desc_1.3.0               
[133] viridisLite_0.4.0         limma_3.46.0             
[135] fansi_0.4.2               pillar_1.6.0             
[137] lattice_0.20-41           fastmap_1.1.0            
[139] httr_1.4.2                pkgbuild_1.2.0           
[141] survival_3.2-11           remotes_2.3.0            
[143] glue_1.4.2                png_0.1-7                
[145] bluster_1.0.0             stringi_1.5.3            
[147] HDF5Array_1.18.1          memoise_2.0.0            
[149] dplyr_1.0.5               irlba_2.3.3              
[151] future.apply_1.7.0
SingleCellExperiment • 4.7k views
ADD COMMENT
0
Entering edit mode
traceback()
    9: stop("invalid character indexing")
    8: intI(j, n = d[2], dn[[2]], give.dn = FALSE)
    7: subCsp_ij(x, i, j, drop = drop)
    6: new.data[new.features, colnames(x = object), drop = FALSE]
    5: new.data[new.features, colnames(x = object), drop = FALSE]
    4: SetAssayData.Assay(object = a, slot = "data", new.data = mats$data)
    3: SetAssayData(object = a, slot = "data", new.data = mats$data)
    2: as.Seurat.SingleCellExperiment(sce_clean)
    1: as.Seurat(sce_clean)
ADD REPLY
2
Entering edit mode

Even if this might not be the correct platform to ask about this I just though I could share that I got exactly the same error and ensuring my cellnames were unique solved the problem for me.

# this did the trick for me
colnames(sce) <- sce$Barcodes
# you could also try something like
colnames(sce) <- make.unique(colnames(sce))

I hope that helps

ADD REPLY
0
Entering edit mode

Well !! The seurat function worked after all. Couldn't figure out what was the issue

counts <- assays(sce_clean)[[1]]
seurat <- CreateSeuratObject(counts = counts, project = "Harmony_All", min.cells = 5)
t2 <- seurat@meta.data
t <- data.frame(colData(sce_clean))
t3 <- data.frame(t,t2)
seurat@meta.data <- t3

I tried this code though. I am inquisitive why you used make.unique function and what will happen if I don't use that?

ADD REPLY
0
Entering edit mode

In my case colnames(sce) was NULL and that was causing the error you were getting. Seurat expects colnames to be present so I added them, copying from the metadata under the sce$Barcodes. However, again in my case, these Barcodes were not unique so it was still yielding an error. I did modify the colnames in a sensible way for my experiment, and here I just suggested make.unique() as an easy workaround ( this adds a .1 to the string if the Barcode is duplicated). I will post that issue here, where a similar problem was discussed in the Seurat github page, they might be able to solve it or give better advise.

ADD REPLY
0
Entering edit mode
Peter Hickey ▴ 670
@petehaitch
Last seen 12 days ago
WEHI, Melbourne, Australia

This is a Seurat function, right? Although SCE is a Bioconductor data structure, Bioconductor don't control how the Seurat authors attempt to convert from an SCE to a Seurat object.

Have you asked the Seurat authors for support?

ADD COMMENT

Login before adding your answer.

Traffic: 781 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