Rename cells in Seurat
2
1
Entering edit mode
4.4 years ago
V ▴ 380

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 • 6.4k views
ADD COMMENT
1
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY
1
Entering edit mode
4.4 years ago

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"))
ADD COMMENT
0
Entering edit mode

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 ] "

ADD REPLY
1
Entering edit mode
4.4 years ago
V ▴ 380

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)
ADD COMMENT

Login before adding your answer.

Traffic: 2611 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6