seurat-object
seurat-object copied to clipboard
Merge runs forever without error if `x` is inside a named vector
Had a part of my script that looked like this:
all_objs <- c()
for (i in seq_along(dirs)) {
samplename <- basename(dirs[i])
obj <- Load10X_Spatial(data.dir=dirs[i],
filename='filtered_feature_bc_matrix.h5')
all_objs[[samplename]] <- obj
}
obj_combined <- merge(all_objs[1], y = all_objs[-1],
add.cell.ids = names(all_objs),
project = "Spatial Seq")
This was taking upwards of several hours, even when I restricted my all_objs
to contain only two objects. After some tinkering, I found that the offending part was inside the merge()
operation: the argument x
here is technically a Seurat object inside a vector, rather than the object itself. Changing x
to all_objs[[1]]
, without making any changes to y
, seemed to do the trick and the samples merged in a few seconds.
Ultimately, this is on me for not reading the docs more closely to realize that x
should literally be the object itself, and not the object contained inside a named vector (which isn't the case for y
). However, I can imagine that at least a few other people may accidentally make such a mistake and not realize anything is wrong for a while; my htop
showed 100% CPU usage so I assumed the function was running normally and was simply a lot more computationally intensive than I thought.
No idea why this bug occurs, since merge.Assay
in assay.R
simply performs c(x, y)
under the hood anyways. If not fixable, would it be possible to add a warning message?
Relevant package versions: SeuratObject_4.1.3 Seurat_4.3.0 spacexr_2.2.1