This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How do I subset a Seurat object using variable features?

So I was struggling with this: Creating a dendrogram with a large dataset (20,000 by 20,000 gene-gene correlation matrix): Is there a way to use multiple processors (parallelize) to create a heatmap for a large dataset?

Now I think I found a good solution, taking a "meaningful" sample of the dataset, and then create a dendrogram-heatmap of the gene-gene correlation matrix generated from the sample.

I have got this far:

cluster3.seurat.obj <- CreateSeuratObject(counts = cluster3.raw.data, project = "cluster3", min.cells = 3, min.features = 200)

cluster3.seurat.obj <- NormalizeData(cluster3.seurat.obj, normalization.method = "LogNormalize", scale.factor = 10000)
cluster3.seurat.obj <- FindVariableFeatures(cluster3.seurat.obj, selection.method = "vst", nfeatures = 2000)

Now I am wondering, how do I extract a data frame or matrix of this Seurat object with the built in function or would I have to do it in a "homemade"-R-way?

I'm hoping it's something as simple as doing this:

cluster3.cells.variable.features <- as.matrix(GetAssayData(cluster3.seurat.obj, slot = "data")[, WhichCells(cluster3.seurat.obj)][, FetchData(cluster3.seurat.obj, var.features)])

I was playing around with it, but couldn't get it...

Any help would be appreciated.

Very Respectfully, Pratik

seurat rna-seq scrna-seq r

1 answer

You just want a matrix of counts of the variable features?

var_genes <- VariableFeatures(cluster3.seurat.obj)
seurat_df <- GetAssayData(cluster3.seurat.obj)[var_genes,]

Beautiful! Thank you.

Just had to stick an as.data.frame as such:

seurat_df <- as.data.frame(GetAssayData(cluster3.seurat.obj))[var_genes,]

and I am good to go!

Thank you very much again @bioinformatics2020!

Very Respectfully, Pratik

Log in to answer this question.