# how to obtain only one cluster's data (.csv file) in Seurat

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!

• A cluster may contain different types of data. Do you want the specific cells, expression for each cell, average expression, cluster markers, etc.? Feb 18 '19 at 23:13
• 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
Feb 19 '19 at 3:23
– llrs
Feb 19 '19 at 10:12

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)

• 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
Feb 22 '19 at 5:35
• 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 Feb 22 '19 at 14:11
• 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
Feb 22 '19 at 16:25
• library(methods); library(utils) Feb 22 '19 at 17:24
• 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
Oct 2 '19 at 22:16