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

Create Dual Assay Seurat Object error #118

Closed
dgrutherford opened this issue Aug 1, 2023 · 11 comments
Closed

Create Dual Assay Seurat Object error #118

dgrutherford opened this issue Aug 1, 2023 · 11 comments
Labels
bug Something isn't working

Comments

@dgrutherford
Copy link

Hi Sam,
You really have created a wonderful resource here, thank you so much!

I am having issues with creating the dual assay Seurat object after running CellBender.
I have created two merged matrix's cell_bender and cell_ranger, but when I "CreateAssayObject" I get the following error:

Error in CreateAssayObject(counts = counts, min.cells = min.cells, min.features = min.features, :
No cell names (colnames) names present in the input matrix

Any help would be gratefully received!
Thanks
Duncan

cell_bender_merged <- Read_CellBender_h5_Multi_File(data_dir = "CB_input/", custom_name = "_e32.h5",
                                                    sample_names = c("WT1", "WT2"), merge=TRUE)


cell_ranger_merged <- Read_CellBender_h5_Multi_File(data_dir = "CB_input/", custom_name = "matrix.h5",
                                                    sample_names = c("WT1"), parallel = FALSE, num_cores = 1)



dual_seurat <- Create_CellBender_Merged_Seurat(raw_cell_bender_matrix = cell_bender_merged, raw_counts_matrix = cell_ranger_merged,
                                               raw_assay_name = "RAW")
sessionInfo() output
R version 4.3.1 (2023-06-16 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22621)

Matrix products: default


locale:
[1] LC_COLLATE=English_United Kingdom.utf8 
[2] LC_CTYPE=English_United Kingdom.utf8   
[3] LC_MONETARY=English_United Kingdom.utf8
[4] LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.utf8    

time zone: Europe/London
tzcode source: internal

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

other attached packages:
 [1] Matrix_1.6-0          SeuratData_0.2.1      SeuratDisk_0.0.0.9020
 [4] patchwork_1.1.2       lubridate_1.9.2       forcats_1.0.0        
 [7] stringr_1.5.0         purrr_1.0.1           readr_2.1.4          
[10] tidyr_1.3.0           tibble_3.2.1          ggplot2_3.4.2        
[13] tidyverse_2.0.0       dplyr_1.1.2           qs_0.25.5            
[16] scCustomize_1.1.3     SeuratObject_4.1.3    Seurat_4.3.0.1       
[19] viridis_0.6.4         viridisLite_0.4.2    

loaded via a namespace (and not attached):
  [1] RColorBrewer_1.1-3     rstudioapi_0.15.0      jsonlite_1.8.7        
  [4] shape_1.4.6            magrittr_2.0.3         spatstat.utils_3.0-3  
  [7] ggbeeswarm_0.7.2       GlobalOptions_0.1.2    vctrs_0.6.2           
 [10] ROCR_1.0-11            spatstat.explore_3.2-1 paletteer_1.5.0       
 [13] janitor_2.2.0          htmltools_0.5.5        sctransform_0.3.5     
 [16] parallelly_1.36.0      KernSmooth_2.23-21     htmlwidgets_1.6.2     
 [19] ica_1.0-3              plyr_1.8.8             plotly_4.10.2         
 [22] zoo_1.8-12             igraph_1.5.0.1         mime_0.12             
 [25] lifecycle_1.0.3        pkgconfig_2.0.3        R6_2.5.1              
 [28] fastmap_1.1.1          fitdistrplus_1.1-11    future_1.33.0         
 [31] shiny_1.7.4.1          snakecase_0.11.0       digest_0.6.33         
 [34] colorspace_2.1-0       rematch2_2.1.2         tensor_1.5            
 [37] irlba_2.3.5.1          progressr_0.13.0       fansi_1.0.4           
 [40] spatstat.sparse_3.0-2  timechange_0.2.0       httr_1.4.6            
 [43] polyclip_1.10-4        abind_1.4-5            compiler_4.3.1        
 [46] remotes_2.4.2.1        withr_2.5.0            bit64_4.0.5           
 [49] R.utils_2.12.2         MASS_7.3-60            rappdirs_0.3.3        
 [52] tools_4.3.1            vipor_0.4.5            lmtest_0.9-40         
 [55] beeswarm_0.4.0         httpuv_1.6.11          future.apply_1.11.0   
 [58] goftest_1.2-3          R.oo_1.25.0            glue_1.6.2            
 [61] nlme_3.1-162           promises_1.2.0.1       grid_4.3.1            
 [64] Rtsne_0.16             cluster_2.1.4          reshape2_1.4.4        
 [67] generics_0.1.3         hdf5r_1.3.8            gtable_0.3.3          
 [70] spatstat.data_3.0-1    tzdb_0.4.0             R.methodsS3_1.8.2     
 [73] hms_1.1.3              RApiSerialize_0.1.2    data.table_1.14.8     
 [76] stringfish_0.15.8      sp_2.0-0               utf8_1.2.3            
 [79] spatstat.geom_3.2-4    RcppAnnoy_0.0.21       ggrepel_0.9.3         
 [82] RANN_2.6.1             pillar_1.9.0           ggprism_1.0.4         
 [85] later_1.3.1            circlize_0.4.15        splines_4.3.1         
 [88] lattice_0.21-8         bit_4.0.5              survival_3.5-5        
 [91] deldir_1.0-9           tidyselect_1.2.0       miniUI_0.1.1.1        
 [94] pbapply_1.7-2          gridExtra_2.3          scattermore_1.2       
 [97] matrixStats_1.0.0      stringi_1.7.12         lazyeval_0.2.2        
[100] codetools_0.2-19       BiocManager_1.30.21.1  cli_3.6.1             
[103] RcppParallel_5.1.7     uwot_0.1.16            xtable_1.8-4          
[106] reticulate_1.30        munsell_0.5.0          Rcpp_1.0.11           
[109] globals_0.16.2         spatstat.random_3.1-5  png_0.1-8             
[112] ggrastr_1.0.2          parallel_4.3.1         ellipsis_0.3.2        
[115] listenv_0.9.0          scales_1.2.1           ggridges_0.5.4        
[118] crayon_1.5.2           writexl_1.4.2          leiden_0.4.3          
[121] rlang_1.1.0            cowplot_1.1.1  
@samuel-marsh
Copy link
Owner

Hi,

Thanks for kind words!

Can you post the following:

head(colnames(cell_bender_merged))

head(colnames(cell_ranger_merged))

Thanks!
Sam

@samuel-marsh samuel-marsh self-assigned this Aug 1, 2023
@samuel-marsh samuel-marsh added the more-info-needed Further information is requested label Aug 1, 2023
@dgrutherford
Copy link
Author

Thanks Sam,
"

head(colnames(cell_bender_merged))
[1] "WT1_AAACAAGCAAACAAGA-1" "WT1_AAACAAGCAAACAATC-1" "WT1_AAACAAGCAAACACGC-1" "WT1_AAACAAGCAAACCCAA-1" "WT1_AAACAAGCAAACCGTA-1"
[6] "WT1_AAACAAGCAAACCTGA-1"

head(colnames(cell_ranger_merged))
NULL"

I guess this is where one issue may lie.

However when i read in data using the following:
e32_1_cellranger_f= Seurat::Read10X(data.dir = "CB_input/raw_features/")

then i get the following:
head(colnames(e32_1_cellranger_f))
[1] "AAACAAGCAAACAAGA-1" "AAACAAGCAAACAATC-1" "AAACAAGCAAACACGC-1" "AAACAAGCAAACCCAA-1" "AAACAAGCAAACCGTA-1" "AAACAAGCAAACCTGA-1"

But still get "No cell names (colnames) names present in the input matrix" when combining this file with CreateSeuratObject

Thanks
Duncan

@samuel-marsh
Copy link
Owner

Hi Duncan,

Give this a try. Instead of using Read_CellBender_h5_Multi_File to read the cellranger file use Read10X_h5_GEO instead. Does that solve the issue?

@dgrutherford
Copy link
Author

Hi Sam,

I do not think that solves issue. Read10x_h5_GEO makes a list which cannot be read into CreateAssayObject or CreateSeuratObject.

Thanks, Duncan

@samuel-marsh
Copy link
Owner

Hi Duncan,

Sorry yes that list can be merged but I missed that you tried with just Read10X. So even with Read10X and CreateSeuratObject just in Seurat alone you still get the error?

Best,
Sam

@dgrutherford
Copy link
Author

Hi Sam,

Yes, when I use Read10x for the cell ranger data I get the following error:

Filtering Cell Bender matrix for cells present in raw counts matrix.
Creating Seurat Object from Cell Bender matrix.
Warning: Feature names cannot have underscores ('_'), replacing with dashes ('-')
Filtering raw counts matrix to match Seurat Object.
Error in .subscript.2ary(x, i, j, drop = TRUE) : subscript out of bounds

Thanks
Duncan

@samuel-marsh
Copy link
Owner

Hi Duncan,

Ok so just clarifying things looking back at your original code. When you read in CellBender data you have 2 samples WT1 and WT2 but when you read in Cell Ranger data you only specified WT1. Is there another file with WT2 from cell ranger?

The Dual assay function is meant to create object with overlapping cells. I'm wondering if the issue is actually with overlapping cells given that error.

When you read in the cell bender files and merge them it appends the sample ID as barcode prefix to retain unique barcodes per sample. However, when you just read in via Read10X it does not add the extra prefix. Therefore I'd recommend running this below to create merged matrix with proper prefixes. And then try making the object again.

cell_ranger <- Read10X_h5_GEO(..., sample_names = c("WT1", "WT2"), merge = TRUE)

Best,
Sam

@dgrutherford
Copy link
Author

Thanks Sam,

I have read both ( filtered and unfiltered) cell ranger and cell bender files. And assigned samples names to each file.
However I am still getting the same error, I have also checked this is not an isolated file issue.
error:

head(colnames(cell_ranger))
[1] "WT1_AAACAAGCAAACAAGA-1" "WT1_AAACAAGCAAACAATC-1" "WT1_AAACAAGCAAACACGC-1" "WT1_AAACAAGCAAACCCAA-1" "WT1_AAACAAGCAAACCGGT-1" "WT1_AAACAAGCAAACCTGA-1"
head(colnames(cell_bender_merged))
[1] "WT1_AAACAAGCAAACAAGA-1" "WT1_AAACAAGCAAACAATC-1" "WT1_AAACAAGCAAACACGC-1" "WT1_AAACAAGCAAACCCAA-1" "WT1_AAACAAGCAAACCGGT-1" "WT1_AAACAAGCAAACCTGA-1"
dual_seurat <- Create_CellBender_Merged_Seurat(raw_cell_bender_matrix = cell_bender_merged, raw_counts_matrix = cell_ranger,

  •                                            raw_assay_name = "RAW")
    

Filtering Cell Bender matrix for cells present in raw counts matrix.
Creating Seurat Object from Cell Bender matrix.
Warning: Feature names cannot have underscores ('_'), replacing with dashes ('-')
Filtering raw counts matrix to match Seurat Object.
Error in .subscript.2ary(x, i, j, drop = TRUE) : subscript out of bounds

Any further ideas? Thanks
Duncan

@samuel-marsh
Copy link
Owner

Hey Duncan,

Thanks for trying that. Are you able to share cell bender and cell ranger files? I have some other ideas but might be easier if I can examine the files directly.

If you can share please send me email [email protected] and I will share link to Google drive folder for upload.

Best,
Sam

@samuel-marsh
Copy link
Owner

Hi Duncan,

Thanks again for sharing the files and glad to say the issue turned out to straightforward fix. There is now a fix deployed in develop branch v1.1.3.9003.

The issue was due to the fact that feature matrices from both cell ranger and cell bender had underscores in feature names which Seurat doesn't allow: Warning: Feature names cannot have underscores ('_'), replacing with dashes ('-').

The way the function was originally written it:

  • Created object from CellBender matrix and filtered by min.cell & min.features
  • Extracted cell and feature names
  • Subsetted Cell Ranger dgCMatrix
  • Created Cell Ranger Assay Object
  • Added assay to CellBender object

So when Seurat changed the feature names upon import the subsequent subsetting of other dgCMatrix was failing because the names weren't present. I have updated the function to avoid this issue and it worked as expected testing on your files.

If you continue to have any issues creating object after updating to the develop branch please let me know!

Best,
Sam

@samuel-marsh samuel-marsh added bug Something isn't working and removed more-info-needed Further information is requested labels Aug 3, 2023
@dgrutherford
Copy link
Author

dgrutherford commented Aug 3, 2023 via email

@samuel-marsh samuel-marsh removed their assignment Aug 4, 2023
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

2 participants