How do I subset a Seurat object using variable features?
Entering edit mode
10 months ago
Pratik Mehta ▴ 590

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 =, 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 • 2.3k views
Entering edit mode
10 months ago

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,]
Entering edit mode

Beautiful! Thank you.

Just had to stick an as such:

seurat_df <-[var_genes,]

and I am good to go!

Thank you very much again @bioinformatics2020!

Very Respectfully, Pratik


Login before adding your answer.

Traffic: 2666 users visited in the last hour
Help About
Access RSS

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

Powered by the version 2.3.6