I have a single-cell multi-omic Seurat object that contains RNA, cell-surface-protein(ADT) assays and metadata. I subsetted the object based on ADT levels of interest. I want to add metadata to annotate these subsets specifically within the original object.
What I tried does not work:
data[subset]
gives the error:
Error in as.character.default(x) :
no method for coercing this S4 class to a vector
Or data@assays$ADT[subset]
Error in GetAssayData(object = x)[i, j, ..., drop = FALSE] :
invalid or not-yet-implemented 'Matrix' subsetting
Or data@meta.data[subset] OR data@meta.data[[subset]]
Error in `[.default`(data@meta.data, subset) :
invalid subscript type 'S4'
Any help would be appreciated, thank you.
UPDATE: It works using the approach:
# add annotation to each subset
subset1@meta.data$newLabel<-"subset1"
subset2@meta.data$newLabel<-"subset2"
subset3@meta.data$newLabel<-"subset3"
subset4@meta.data$newLabel<-"subset4"
# function that merges the metadata of the subsets
multiannot<-function(x)
{
CellsName<-NULL
for(i in 1: length(x))
{
CellsNameInt <- subset(x[[i]]@meta.data, select = c("newLabel"))
if(is.null(CellsName)==F)
CellsName <-rbind(CellsName,CellsNameInt) else
CellsName <- CellsNameInt
}
return(CellsName)
}
# call the function using a vector that contains the subsets
metadatanew<-multiannot(c(subset1,subset2,subset3,subset4))
# add the metadata to the original object
data<-AddMetaData(data, metadatanew)