加載數(shù)據(jù)
此教程演示了如何存儲(chǔ)和與 交互Seurat 中的降維信息拗盒。為了演示目的,我們將使用通過(guò)SeuratData包提供的 2,700 個(gè) PBMC 對(duì)象办陷。
library(Seurat)
library(SeuratData)
pbmc <- LoadData("pbmc3k", type = "pbmc3k.final")
探索新的降維結(jié)構(gòu)
在 Seurat v4.0 中琅轧,存儲(chǔ)和與降維信息的交互已生成并信息化到對(duì)象中。每個(gè)降維過(guò)程都作為對(duì)象存儲(chǔ)在插槽中搭伤,作為指定列表的元素只怎。可以使用[[運(yùn)算符怜俐,訪(fǎng)問(wèn)所需降維信息身堡。 例如,使用RunPCA()運(yùn)行主成分分析后拍鲤,對(duì)象[['pca']]將包含PCA的結(jié)果贴谎。 通過(guò)將新元素添加到列表中汞扎,用戶(hù)可以添加附加的和自定義的降維信息。 每個(gè)存儲(chǔ)的降維信息包含特定slot中擅这。如
- cell.embeddings:將每個(gè)細(xì)胞的坐標(biāo)存儲(chǔ)在低維空間中澈魄。
- feature.loadings:存儲(chǔ)每個(gè)基因在降維中的權(quán)重
- feature.loadings.projected:Seurat 通常計(jì)算基因子集(例如高變異基因)的降維信息,然后將該結(jié)構(gòu)投影到整個(gè)數(shù)據(jù)集(所有基因)上蕾哟。該投影的結(jié)果存儲(chǔ)在此插槽中一忱。
- stdev:每個(gè)維度的標(biāo)準(zhǔn)偏差。
- key:為基因坐標(biāo)和表達(dá)矩陣設(shè)置的列名谭确。
- jackstraw:存儲(chǔ)降維過(guò)程的結(jié)果帘营。目前僅支持PCA。
- misc:存儲(chǔ)您可能想要的任何其他信息逐哈。
要訪(fǎng)問(wèn)這些插槽芬迄,可以使用Embeddings()Loadings()Stdev()
pbmc[["pca"]]
## A dimensional reduction object with key PC_
## Number of dimensions: 50
## Projected dimensional reduction calculated: FALSE
## Jackstraw run: TRUE
## Computed using assay: RNA
head(Embeddings(pbmc, reduction = "pca")[, 1:5])
## PC_1 PC_2 PC_3 PC_4 PC_5
## AAACATACAACCAC -4.7296855 -0.5184265 -0.7623220 -2.3156790 -0.07160006
## AAACATTGAGCTAC -0.5174029 4.5918957 5.9091921 6.9118856 -1.96243034
## AAACATTGATCAGC -3.1891063 -3.4695154 -0.8313710 -2.0019985 -5.10442765
## AAACCGTGCTTCCG 12.7933021 0.1007166 0.6310221 -0.3687338 0.21838204
## AAACCGTGTATGCG -3.1288078 -6.3481412 1.2507776 3.0191026 7.84739502
## AAACGCACTGGTAC -3.1088963 0.9262125 -0.6482331 -2.3244378 -2.00526763
head(Loadings(pbmc, reduction = "pca")[, 1:5])
## PC_1 PC_2 PC_3 PC_4 PC_5
## PPBP 0.010990202 0.01148426 -0.15176092 0.10403737 0.003299077
## LYZ 0.116231706 0.01472515 -0.01280613 -0.04414540 0.049906881
## S100A9 0.115414362 0.01895146 -0.02368853 -0.05787777 0.085382309
## IGLL5 -0.007987473 0.05454239 0.04901533 0.06694722 0.004603231
## GNLY -0.015238762 -0.13375626 0.04101340 0.06912322 0.104558611
## FTL 0.118292572 0.01871142 -0.00984755 -0.01555269 0.038743505
head(Stdev(pbmc, reduction = "pca"))
## [1] 7.098420 4.495493 3.872592 3.748859 3.171755 2.545292
seurat提供 了常用的單細(xì)胞數(shù)據(jù)降維方法[RunPCA()]和 [RunTSNE()], 使用這些功能時(shí)昂秃,所有插槽都會(huì)自動(dòng)填充禀梳。
自定義降維計(jì)算
雖然沒(méi)有納入seurat,但很容易在 R 中運(yùn)行多重降維(MDS)肠骆。如果您有興趣運(yùn)行 MDS算途, 輸出將存儲(chǔ)在 Seurat 對(duì)象中:
# Before running MDS, we first calculate a distance matrix between all pairs of cells. Here we
# use a simple euclidean distance metric on all genes, using scale.data as input
d <- dist(t(GetAssayData(pbmc, slot = "scale.data")))
# Run the MDS procedure, k determines the number of dimensions
mds <- cmdscale(d = d, k = 2)
# cmdscale returns the cell embeddings, we first label the columns to ensure downstream
# consistency
colnames(mds) <- paste0("MDS_", 1:2)
# We will now store this as a custom dimensional reduction called 'mds'
pbmc[["mds"]] <- CreateDimReducObject(embeddings = mds, key = "MDS_", assay = DefaultAssay(pbmc))
# We can now use this as you would any other dimensional reduction in all downstream functions
DimPlot(pbmc, reduction = "mds", pt.size = 0.5)
image.png
# If you wold like to observe genes that are strongly correlated with the first MDS coordinate
pbmc <- ProjectDim(pbmc, reduction = "mds")
## MDS_ 1
## Positive: CST3, TYROBP, FCER1G, LST1, FTL, AIF1, FTH1, TYMP, FCN1, LYZ
## LGALS1, S100A9, CFD, CD68, SERPINA1, CTSS, IFITM3, SPI1, S100A8, LGALS2
## Negative: MALAT1, RPS27A, RPS27, RPL3, RPL23A, RPL21, RPL13A, RPS6, RPS3A, RPS3
## RPL9, LTB, RPSA, CD3D, RPS25, RPS18, PTPRCAP, RPS12, RPL30, RPL31
## MDS_ 2
## Positive: NKG7, PRF1, CST7, GZMA, GZMB, B2M, FGFBP2, CTSW, GNLY, HLA-C
## GZMH, SPON2, CD247, FCGR3A, CCL5, HLA-A, CCL4, GZMM, KLRD1, CLIC3
## Negative: RPL32, RPL18A, HLA-DRA, CD79A, RPL13, MS4A1, RPL11, TCL1A, RPS9, RPL12
## LINC00926, HLA-DQB1, HLA-DQA1, HLA-DRB1, RPL28, RPS2, S100A8, HLA-DMA, RPL8, RPLP1
# Display the results as a heatmap
DimHeatmap(pbmc, reduction = "mds", dims = 1, cells = 500, projected = TRUE, balanced = TRUE)
image.png
# Explore how the first MDS dimension is distributed across clusters
VlnPlot(pbmc, features = "MDS_1")
image.png
# See how the first MDS dimension is correlated with the first PC dimension
FeatureScatter(pbmc, feature1 = "MDS_1", feature2 = "PC_1")
image.png