I'm working with single-cell RNA-seq data in R using the Seurat package, and I need to align the cell order between two Seurat objects (seurat_obj1
and seurat_obj2
) so that their cell barcodes are in the same order.
I have tried
# Find common cells
common_cells <- intersect(colnames(seurat_obj1), colnames(seurat_obj2))
seurat_obj1 <- seurat_obj1[, common_cells]
seurat_obj2 <- seurat_obj2[, common_cells]
length(colnames(seurat_obj1)) == length(colnames(seurat_obj2))
TRUE
all(colnames(seurat_obj1) == colnames(seurat_obj2))
FALSE
Can you validate that there are even colnames present?
Yeah, I have printed
colnames(seurat_obj1)
andcolnames(seurat_obj2)
, It's ok, I dont know why when I choose cells byseurat_obj1[, common_cells]
, its seems only choose cells but not order bycommon_cells