This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Rename cells in Seurat

Hello,

I've seen the relative thread of renaming cells, if for example merging Seurats from different 10x experiments which will mean some barcodes will be overlapping. The issue I'm having is that I want to save as Matrix the counts of 6 clusters. I am trying this with the code below :

rawdata <- as.matrix(GetAssayData(Stromal, slot = "counts")[, WhichCells(Stromal, idents = c("1", "2", "3", "4", "5", "6"), slot = "counts")])

this gives me the following error :

Error in intI(j, n = x@Dim[2], dn[[2]], give.dn = FALSE) : 
  no 'dimnames[[.]]': cannot use character indexing

which I assume means I have duplicate cell names. So I would need to somehow rename the cells based on their cluster? is there a way to do is?

Or alternatively if I've got it wrong, is there a way around the above error? Thanks

seurat single cell rnaseq rna-seq r

If you have a Seurat object, you do not have duplicate cell names.

Thank you. Would you happen to know what the error means?

2 answers

I think you're complicating things for yourself a bit.

# subset first
Stromal.subset <- subset(x = Stromal, idents = c("1", "2", "3", "4", "5", "6"))

# Then get counts as a matrix.
my.matrix <- as.matrix(GetAssayData(object = Stromal.subset, slot = "counts"))

Thanks for this! First part works fine and I get a Seurat object containing the clusters I want.

When I run the second command it goes through apparently alright, but I get a file that contains nothing for some reason. The file just says " num [0 , 0 ] "

Ok solved in a round about way. Not sure what the initial error is referring to. If anybody has any ideas what it was please let me know as the above I posted in the initial question use to work.

This is how I went about it for reference in case someone else runs into the same issue :

cells.use <- WhichCells(object = Stromal , ident = c("1", "2", "3", "4", "5", "6"))

expr <- GetAssayData(object = Stromal, assay = "RNA", slot = "counts")[, cells.use]
expr <- as(Class = 'matrix', object = expr)
write.csv(x = expr, file = "expression_cluster.csv", quote = FALSE)

Log in to answer this question.