Closed jenli3 closed 3 years ago
Thanks so much for the suggestion! STdeconvolve essentially just needs a matrix of nonnegative integer gene counts for each spatial pixel. If the spatial data was stored as a Seurat object it could be accessed via seuratobj@assays$RNA@counts
. So it should be reasonable to take a Seurat object as input.
Dear Jen,
As Brendan noted, you should be able to extract your filtered gene counts matrix from the Seurat S4 object via something like:
counts <- seuratobj@assays$RNA@counts
Optionally if you want to compare spatial pixel clustering with pixel deconvolution, you can also extract the spatial pixels clusters from the Seurat S4 object via something like:
annot <- seuratobj@meta.data$seurat_clusters
Given the filtered gene counts matrix counts
and the corresponding spatial positional coordinations pos
, you would then be able to run STdeconvolve
as shown in the tutorials:
## feature select for genes
corpus <- restrictCorpus(counts, removeAbove=1.0, removeBelow = 0.05)
## choose optimal number of cell-types
ldas <- fitLDA(t(as.matrix(corpus)), Ks = seq(2, 9, by = 1))
## get best model results
optLDA <- optimalModel(models = ldas, opt = "min")
results <- getBetaTheta(optLDA, t(as.matrix(corpus)))
deconProp <- results$theta
deconGexp <- results$beta*1000
## visualize deconvolved cell-type proportions
vizAllTopics(deconProp, pos,
groups = annot,
group_cols = rainbow(length(levels(annot))),
r=0.4)
Please feel free to let us know if you are still experiencing any challenges.
Stay healthy and safe, Jean
Thank you Brendan and Jean I've finally had a chance to try it out - a very useful tool!
Hi, I'm wondering if there is a way for to integrate STdeconvolve with STUtility/Seurat? I have already performed filtering and clustering using these with a saved s4 object (example below)
_Formal class 'Seurat' [package "SeuratObject"] with 13 slots ..@ assays :List of 2 .. ..$ RNA:Formal class 'Assay' [package "SeuratObject"] with 8 slots .. ..$ SCT:Formal class 'SCTAssay' [package "Seurat"] with 9 slots ..@ meta.data :'data.frame': 11714 obs. of 22 variables: .. ..$ orig.ident : Factor w/ 1 level "SeuratProject": 1 1 1 1 1 1 1 1 1 1 ... .. ..$ nCount_RNA : num [1:11714] 4083 3920 8126 8507 4338 ... .. ..$ nFeature_RNA : int [1:11714] 1429 1466 2578 2524 1752 1650 3310 4130 2476 2823 ... .. ..$ slide : chr [1:11714] "D17" "D17" "D17" "D17" ... .. ..$ treatment : chr [1:11714] "PBS" "PBS" "PBS" "PBS" ... .. ..$ id : int [1:11714] 27 29 31 33 35 37 39 41 43 45 ... .. ..$ labels : chr [1:11714] "Default" "Default" "Default" "Default" ... .. ..$ sample_id : chr [1:11714] "section_1" "section_1" "section_1" "section_1" ... .. ..$ slide1 : Factor w/ 6 levels "D17","D19","D54",..: 1 1 1 1 1 1 1 1 1 1 ... .. ..$ percent.mito : num [1:11714] 29.5 27.6 21.7 21.7 20.1 ... .. ..$ percent.ribo : num [1:11714] 8.55 8.55 9.61 10.09 9.84 ... .. ..$ nCount_SCT : num [1:11714] 11606 11413 11185 11262 11202 ... .. ..$ nFeature_SCT : int [1:11714] 1991 2066 2589 2533 2202 2120 3310 3857 2486 2823 ... .. ..$ SCT_snn_res.0.1: Factor w/ 3 levels "0","1","2": 1 1 1 1 1 1 1 1 1 1 ... .. ..$ SCT_snn_res.0.2: Factor w/ 8 levels "0","1","2","3",..: 1 1 1 1 1 1 1 6 1 1 ... .. ..$ SCT_snn_res.0.3: Factor w/ 10 levels "0","1","2","3",..: 1 1 5 5 1 5 5 7 5 5 ... .. ..$ SCT_snn_res.0.4: Factor w/ 11 levels "0","1","2","3",..: 1 1 3 3 1 3 3 6 3 3 ... .. ..$ SCT_snn_res.0.6: Factor w/ 13 levels "0","1","2","3",..: 1 1 2 2 1 2 2 5 2 2 ... .. ..$ SCT_snn_res.0.8: Factor w/ 16 levels "0","1","2","3",..: 1 1 3 7 1 7 3 9 7 3 ... .. ..$ SCT_snn_res.1 : Factor w/ 18 levels "0","1","2","3",..: 1 1 2 16 1 16 2 4 16 2 ... .. ..$ SCT_snn_res.1.2: Factor w/ 21 levels "0","1","2","3",..: 1 1 2 7 1 7 2 21 7 2 ... .. ..$ seurat_clusters: Factor w/ 8 levels "0","1","2","3",..: 1 1 1 1 1 1 1 6 1 1 ... ..@ active.assay: chr "SCT" ..@ active.ident: Factor w/ 8 levels "0","1","2","3",..: 1 1 1 1 1 1 1 6 1 1 ... .. ..- attr(*, "names")= chr [1:11714] "CTGCACCTGGAACCGC-1_1" "GTTCTTCCCTCGATGT-1_1" "AACGATAGAAGGGCCG-1_1" "AGGCCCATTGTACAGG-1_1" ... ..@ graphs :List of 2 .. ..$ SCT_nn :Formal class 'Graph' [package "SeuratObject"] with 7 slots .. ..$ SCT_snn:Formal class 'Graph' [package "SeuratObject"] with 7 slots ..@ neighbors : list() ..@ reductions :List of 4 .. ..$ pca :Formal class 'DimReduc' [package "SeuratObject"] with 9 slots .. ..$ tsne :Formal class 'DimReduc' [package "SeuratObject"] with 9 slots .. ..$ umap :Formal class 'DimReduc' [package "SeuratObject"] with 9 slots .. ..$ umap.3d:Formal class 'DimReduc' [package "SeuratObject"] with 9 slots ..@ images : list() ..@ project.name: chr "SeuratProject" ..@ misc : list() ..@ version :Classes 'package_version', 'numericversion' hidden list of 1 .. ..$ : int [1:3] 4 0 2 ..@ commands :List of 6 .. ..$ SCTransform.RNA :Formal class 'SeuratCommand' [package "SeuratObject"] with 5 slots .. ..$ RunPCA.SCT :Formal class 'SeuratCommand' [package "SeuratObject"] with 5 slots .. ..$ FindNeighbors.SCT.pca:Formal class 'SeuratCommand' [package "SeuratObject"] with 5 slots .. ..$ FindClusters :Formal class 'SeuratCommand' [package "SeuratObject"] with 5 slots .. ..$ RunTSNE :Formal class 'SeuratCommand' [package "SeuratObject"] with 5 slots .. ..$ RunUMAP.SCT.pca :Formal class 'SeuratCommand' [package "SeuratObject"] with 5 slots ..@ tools :List of 1 .. ..$ Staffli:Formal class 'Staffli' [package "STutility"] with 12 slots