I am analyzing six single-cell RNA-seq datasets with Seurat package.
These 6 datasets were acquired through each different 10X running, then combined with batch effect-corrected via Seurat function "FindIntegrationAnchors". Meanwhile, among the 6 datasets, data 1, 2, 3 and 4 are "untreated" group, while data 5 and 6 belongs to "treated" group. I merged all the 6 datasets together with batch-corrected, but I also need to compare features of "untreated" vs "treated".
How can I group data 1,2,3 and 4 into "untreated group", and data 5 and 6 into "treated group", and then perform downstream analysis?
Thanks.
One quick and dirty way to do this, is to add the information before merging the Seurat objects:
...
so_samples[[1]]@meta.data$treatment <- "control"
so_samples[[2]]@meta.data$treatment <- "control"
so_samples[[3]]@meta.data$treatment <- "control"
so_samples[[4]]@meta.data$treatment <- "control"
so_samples[[5]]@meta.data$treatment <- "treated"
so_samples[[6]]@meta.data$treatment <- "treated"
...
anchors <- FindIntegrationAnchors(object.list = so_samples, dims = 1:20)
so_all_samples <- IntegrateData(anchorset = anchors, dims = 1:20)
In general, it would be better to load such meta data from a file and join it to the seurat object without such error-prone copy-paste code. Also note that it is in general a bad idea to modify R S4 objects (those where you can access elements with @
) like this, but the functions provided to modify Seurat objects provided by the Seurat package are so cumbersome to use that I doubt they will ever change the underlying data structure.