I have a scRNA-seq Seurat object I've analyzed, and I noticed that for some of the clusters, there's more than one cell type.

I've created a subset which and run FindClusters again to label the cell more efficiently, and now I want to "paste" the Idents I've assigned in the subcluster to the original object.

How do I do it?

  • $\begingroup$ Hi @ShaniS this question does look like it has been answered. Please consider upvoting and/or accepting an answer $\endgroup$
    – M__
    Commented Sep 10, 2023 at 2:47

2 Answers 2


Since you haven't shared any data or code so I will show it using the example given below,

First you need to assign a specific cluster to the cells which are having another type like C_new.

cells_df <- data.frame(row.names=paste0("Cell", 1:10, sep = ""),as.vector(paste0("C",1:10,sep="")))

colnames(cells_df) <- "clusters"

cluster_new <- c("Cell6","Cell2")

cells_df$clusters <- as.character(cells_df$clusters)

for(i in 1:length(cluster_new)) {
j <- cluster_new[i] 
cells_df[j,] <- "C_new"

 Cell1       C1
 Cell2    C_new
 Cell3       C3
 Cell4       C4
 Cell5       C5
 Cell6    C_new

And if you have already assigned new clusters to the cells then you can skip the above step. Now save the new cluster belongings into the seurat object using the Idents function

Idents(seurat_obj) <- cells_df$clusters

Then you can perform the differential gene expression as follows, for example if you want to find the differentially expressed genes between cluster C7 vs C_new you can do it as follows,

FindMarkers(seurat_obj,ident.1 = "C7", ident.2 = "C_new" )

Assuming parentObj is the original seurat object, and tmp_subset is your subset, you can

new_metadata <- [email protected] 
tmp_subset_annotation <- [email protected] 

# new_metadata
AAATAAA-1   TCD4-naive

# tmp_subset_annotation
ATTCGGA-1   TCD4-naive
AAATAAA-1   TCD4-naive

new_metadata$refined_annotation <- sapply(rownames(new_metadata), 
     function(ita) ifelse(ita %in% rownames(tmp_subset_annotation),

Basically you iterate each rownames of the original object, and assign the new annotation, if the UMI matches a UMI in the subset, otherwise you keep the original annotation.

  • $\begingroup$ Hi, I am getting an error saying Error in ans[npos] <- rep(no, length.out = len)[npos] : replacement has length zero In addition: Warning message: In rep(no, length.out = len) : $\endgroup$
    – ShaniS
    Commented Jan 20, 2022 at 0:25
  • $\begingroup$ You should add the first few lines of both metadata tables (e.g. head(object@metadata)). Without seeing the data it is difficult to help. $\endgroup$
    – fra
    Commented Jan 20, 2022 at 8:31
  • $\begingroup$ I added a new question with my actual code - bioinformatics.stackexchange.com/questions/18365/… $\endgroup$
    – ShaniS
    Commented Jan 20, 2022 at 17:18
  • $\begingroup$ You should edit your original question rather than create a new thread. Especially because you are asking exactly the same thing. $\endgroup$
    – fra
    Commented Jan 20, 2022 at 20:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.