<p>You can access data within the Seurat object using <code>GetAssayData</code>, and extract a list of cell names for the cluster you're interested in using <code>WhichCells</code>:</p>

<pre><code>library(Seurat)

cells.use &lt;- WhichCells(object = pbmc_small, ident = 1)
expr &lt;- GetAssayData(object = pbmc_small, assay.type = "RNA", slot = "data")[, cells.use]
expr &lt;- as(Class = 'matrix', object = expr)
write.csv(x = expr, file = "expression_cluster1.csv", quote = FALSE)
</code></pre>

CC BY-SA 4.0
2019-02-22T05:35:58.760Z
Hi TimStuart, thank you for your advice, and it works well in the RStudio. But when I use this script in cypress it shows the error "Error in as(Class = "matrix", object = expr), could not find function "as"
Execution halted". Do you know how to solve this problem?
hua
CC BY-SA 4.0
2019-02-22T14:11:16.937Z
I don't know what cypress is, but if you're running it in a script you'll need to load the methods and utils libraries
TimStuart
CC BY-SA 4.0
2019-02-22T16:25:20.543Z
Hi TimStuart, thank you for your reply, and if it is possible could you please tell my what kind of the utils libraries that I should load?
hua
CC BY-SA 4.0
2019-02-22T17:24:52.367Z
`library(methods); library(utils)`
TimStuart
CC BY-SA 4.0
2019-10-02T22:16:19.413Z
Hi TimStuart, nowadays thank you for the Seurat's update, we can analysis several samples together. And I would like to know whether we can obtain the specific sample's specific cluster gene expression profile by using the same code "cells.use <- WhichCells(object = pbmc_small, ident = 1)
expr <- GetAssayData(object = pbmc_small, assay.type = "RNA", slot = "data")[, cells.use]
expr <- as(Class = 'matrix', object = expr)
write.csv(x = expr, file = "expression_cluster1.csv", quote = FALSE)"?
hua
CC BY-SA 4.0
2019-02-19T14:50:51.793Z
2019-02-19T14:50:51.793Z
TimStuart
<p>I was using Seurat to analysis single-cell RNA Seq. And I was interested in only one cluster by using the Seurat. Does anyone know how to achieve the cluster's data(.csv file) by using Seurat or any other method that can do this function? Thank you!</p>

CC BY-SA 4.0
2019-02-18T23:13:17.230Z
A cluster may contain different types of data. Do you want the specific cells, expression for each cell, average expression, cluster markers, etc.?
burger
CC BY-SA 4.0
2019-02-19T03:23:13.307Z
Yes even a cluster contain different types of data. I still  want to obtain that cluster's data including its each cell and gene expression for further analysis.
hua
CC BY-SA 4.0
2019-02-19T10:12:19.633Z
I think that the Seurat tutorials had some information about this. Did you read them? Have you tried something?
llrs
<seurat><single-cell>
how to obtain only one cluster's data (.csv file) in Seurat
# how to obtain only one cluster's data (.csv file) in Seurat

(Asked by: username_0 on 2019-02-18)

I was using Seurat to analysis single-cell RNA Seq. And I was interested in only one cluster by using the Seurat. Does anyone know how to achieve the cluster's data(.csv file) by using Seurat or any other method that can do this function? Thank you!

**Tags:** seurat, single-cell
> **Comments:**
> **username_1**: A cluster may contain different types of data. Do you want the specific cells, expression for each cell, average expression, cluster markers, etc.?  
> **username_0**: Yes even a cluster contain different types of data. I still  want to obtain that cluster's data including its each cell and gene expression for further analysis.  
> **username_2**: I think that the Seurat tutorials had some information about this. Did you read them? Have you tried something?  

---

## 1 answers

### Answer by username_3 on 2019-02-19. Score: 1 | Accepted answer

You can access data within the Seurat object using GetAssayData, and extract a list of cell names for the cluster you're interested in using WhichCells:
library(Seurat)

cells.use <- WhichCells(object = pbmc_small, ident = 1)
expr <- GetAssayData(object = pbmc_small, assay.type = "RNA", slot = "data")[, cells.use]
expr <- as(Class = 'matrix', object = expr)
write.csv(x = expr, file = "expression_cluster1.csv", quote = FALSE)

> **Comments:**
> **username_0**: Hi TimStuart, thank you for your advice, and it works well in the RStudio. But when I use this script in cypress it shows the error "Error in as(Class = "matrix", object = expr), could not find function "as" Execution halted". Do you know how to solve this problem?  
> **username_3**: I don't know what cypress is, but if you're running it in a script you'll need to load the methods and utils libraries  
> **username_0**: Hi TimStuart, thank you for your reply, and if it is possible could you please tell my what kind of the utils libraries that I should load?  
> **username_3**: `library(methods); library(utils)`  
> **username_0**: Hi TimStuart, nowadays thank you for the Seurat's update, we can analysis several samples together. And I would like to know whether we can obtain the specific sample's specific cluster gene expression profile by using the same code "cells.use <- WhichCells(object = pbmc_small, ident = 1) expr <- GetAssayData(object = pbmc_small, assay.type = "RNA", slot = "data")[, cells.use] expr <- as(Class = 'matrix', object = expr) write.csv(x = expr, file = "expression_cluster1.csv", quote = FALSE)"?  

---

