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

merging VisiumHD objects fails due to RenameCells #230

Open
ddiez opened this issue Dec 9, 2024 · 3 comments
Open

merging VisiumHD objects fails due to RenameCells #230

ddiez opened this issue Dec 9, 2024 · 3 comments

Comments

@ddiez
Copy link
Contributor

ddiez commented Dec 9, 2024

I am trying to merge 2 Seurat objects containing data loaded from VisiumHD technology:

> x1 <- RenameCells(x1, add.cell.id="B1")
> x2 <- RenameCells(x2, add.cell.id="B2")
> merge(x1, x2)
Warning: Some cell names are duplicated across objects provided. Renaming to enforce unique cell names.
Error in `RenameCells()`:
! the length of 'new.names' (492460) must be the same as the number of cells (98917)
Run `rlang::last_trace()` to see where the error occurred.
> head(colnames(x1))
[1] "B1_s_016um_00052_00082-1" "B1_s_016um_00150_00268-1"
[3] "B1_s_016um_00144_00175-1" "B1_s_016um_00165_00109-1"
[5] "B1_s_016um_00297_00147-1" "B1_s_016um_00287_00091-1"
> head(colnames(x1[["Spatial.008um"]]))
[1] "s_008um_00301_00321-1" "s_008um_00602_00290-1" "s_008um_00515_00112-1"
[4] "s_008um_00383_00696-1" "s_008um_00526_00291-1" "s_008um_00681_00396-1"
@ddiez
Copy link
Contributor Author

ddiez commented Dec 10, 2024

This does not happen if we read one of the bin sizes only:

> x1 <- Load10X_Spatial("Mouse_Kidney", bin.size=8)
> x2 <- Load10X_Spatial("Visium_HD_Mouse_Brain", bin.size=8)
> x1 <- RenameCells(x1, add.cell.id="B1")
> x2 <- RenameCells(x2, add.cell.id="B2")
> x <- merge(x1, x2)
Warning message:
Key ‘slice1008um_’ taken, using ‘slice1008um2_’ instead

Session information:

> sessionInfo()
R version 4.4.2 (2024-10-31)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 24.04.1 LTS

Matrix products: default
BLAS:   /media/diez/Backup/local/R-4.4.2/build/lib/libRblas.so 
LAPACK: /media/diez/Backup/local/R-4.4.2/build/lib/libRlapack.so;  LAPACK version 3.12.0

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

time zone: Asia/Tokyo
tzcode source: system (glibc)

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

other attached packages:
[1] Seurat_5.1.0       SeuratObject_5.0.2 sp_2.1-4

[... truncated ...]

@dcollins15
Copy link
Collaborator

@ddiez thanks for bringing this to our attention 🙂

The issue doesn't seem to be limited to VisiumHD datasets, I'm able to reproduce the error by merging any two datasets where:

  1. At least one of the objects contains multiple assays
  2. The two objects have overlapping cell names

In this case, CheckDuplicateCellNames will try to loop over each object.list and add a unique suffix onto the object's cell names, here. CheckDuplicateCellNames passed in a character vector of length ncol(object[[i]]) but this check inside RenameCells.Seurat seems to expect a vector of length ncol(object[[DefaultAssay(object)]]), hence the error.

I think this change may have been introduced to make the behavior of RenameCells.Seurat consistent with the new Cells.Seurat generic but it also seems to have broken CheckDuplicateNames 🤷 At any rate, we've added this bug to our backlog and we should have some bandwidth to resolve it in the next month or so. I'll let you know if/when there are any updates.

Thanks again

@ddiez
Copy link
Contributor Author

ddiez commented Jan 28, 2025

@dcollins15 Excellent. Thanks for the additional information. I noticed while digging into the problem about the cell length mismatch but couldn't get enough knowledge at the time to figure out where it was coming from.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants