Hi, so I have aggregated samples in one barcode file which the end of each cell is denoted by "-1" for sample 1, "-2" for sample 2, and so on. I'm trying to create separate objects out of the suffixed barcodes, but I can't find a way to do it. I've also tried adding metadata by adding a separate column by the sample name and then reading it again, but I keep getting the error: "Error in .rowNamesDF<-(x, value = value) : invalid 'row.names' length" at the 4th line of code.
rownames = colnames(gd)
write.csv(rownames,"gddata.csv")
condition.only.metadata <- read.csv(file = "gddata.csv", header = FALSE)
rownames(condition.only.metadata) = rownames([email protected])
gd <- AddMetaData(object = gd, metadata = condition.only.metadata, colnames = "condition")
I've also tried
gd.matrix <- gerd@assays[["RNA"]]@counts
colnames(gd.matrix) <- paste0(colnames(gd), "-6")
nodctrl3 <- CreateSeuratObject(gd.matrix)
But I quickly realized that this code adds additional suffixes at the end of each cell, instead of actually filtering based on the suffix and creating a separate object.
Is there a better way to do this?
Hi,
When you read into Seurat as single object does the orig.ident column in your metadata not match the barcode suffixes? It should normally. Then you can just subset using:
object_sample01 <- subset(object_all, subset = orig.ident == "1")
Alternatively, you could filter the input csv file first before creating Seurat object.
Best,
Sam
I figured out the problem (one of my columns was unlabelled) but I ran into more issues. However I managed to figure them out. Thank you so much for your help!
You can extract sample number from rownames and put it into the separate column of meta.data file like this:
[email protected]$samples <- sub('.*-', '', rownames(gd))
Then subset aacording to sample number:
Idents(gd) <- 'samples'
Sample1 <- subset(gd, idents = '1')
Most helpful comment
You can extract sample number from rownames and put it into the separate column of meta.data file like this:
[email protected]$samples <- sub('.*-', '', rownames(gd))
Then subset aacording to sample number:
Idents(gd) <- 'samples'
Sample1 <- subset(gd, idents = '1')