How do I subset a Seurat object using variable features?
1
1
Entering edit mode
4.0 years ago
Pratik ★ 1.1k

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 • 9.8k views
ADD COMMENT
2
Entering edit mode
4.0 years 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,]
ADD COMMENT
0
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 1758 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

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

Powered by the version 2.3.6