Question: Rename cells in Seurat
1
gravatar for V
4 months ago by
V200
UK/London
V200 wrote:

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

ADD COMMENTlink modified 4 months ago • written 4 months ago by V200
1

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

ADD REPLYlink written 4 months ago by igor9.9k

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

ADD REPLYlink written 4 months ago by V200
1
gravatar for jared.andrews07
4 months ago by
jared.andrews075.3k
St. Louis, MO
jared.andrews075.3k wrote:

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 COMMENTlink written 4 months ago by jared.andrews075.3k

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 REPLYlink written 4 months ago by V200
1
gravatar for V
4 months ago by
V200
UK/London
V200 wrote:

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 COMMENTlink written 4 months ago by V200
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1347 users visited in the last hour