单细胞分析专题单细胞学习单细胞

scRNA基础分析-2:降维与聚类

2020-08-25  本文已影响0人  小贝学生信

scRNA基础分析-1:安装包、导入数据、过滤质控 - 简书
scRNA基础分析-2:降维与聚类 - 简书
scRNA基础分析-3:鉴定细胞类型 - 简书
scRNA基础分析-4:细胞亚类再聚类、注释 - 简书
scRNA基础分析-5:伪时间分析 - 简书
scRNA基础分析-6:富集分析 - 简书

library(Seurat)
library(tidyverse)
library(patchwork)
rm(list=ls())
scRNA <- readRDS("scRNA.rds")

1、首先选择2000个(默认)表达值变化大的基因代表细胞转录谱

scRNA <- FindVariableFeatures(scRNA, selection.method = "vst", nfeatures = 2000) 
top10 <- head(VariableFeatures(scRNA), 10) 
top10
# [1] "GNLY"   "IGLC2"  "S100A9" "IGLC3"  "FCGR3A" "S100A8" "CDKN1C"
# [8] "GZMB"   "ITM2C"  "LYZ" 
plot1 <- VariableFeaturePlot(scRNA) 
LabelPoints(plot = plot1, points = top10, repel = TRUE, size=2.5) 
#如下图,横坐标是某基因在所有细胞中的平均表达值,纵坐标是此基因的方差;红点即为高变基因(2000个)
1-1
补充:细胞周期相关基因
#细胞周期有关基因
head(c(cc.genes$s.genes,cc.genes$g2m.genes))
# [1] "MCM5" "PCNA" "TYMS" "FEN1" "MCM2" "MCM4"

#查看我们选择的高变基因中有哪些细胞周期相关基因
CaseMatch(c(cc.genes$s.genes,cc.genes$g2m.genes),VariableFeatures(scRNA))
g2m_genes = cc.genes$g2m.genes
g2m_genes = CaseMatch(search = g2m_genes, match = rownames(scRNA))
s_genes = cc.genes$s.genes
s_genes = CaseMatch(search = s_genes, match = rownames(scRNA))
scRNA <- CellCycleScoring(object=scRNA,  g2m.features=g2m_genes,  s.features=s_genes)
head(scRNA@meta.data)
1-2
scRNAa <- RunPCA(scRNA, features = c(s_genes, g2m_genes))
DimPlot(scRNA, reduction = "pca", group.by = "Phase")
#如下图结果,细胞周期基因对细胞聚类的影响不大,不需要去除。

# 如需去除,代码如下
# scRNAb <- ScaleData(scRNA, vars.to.regress = c("S.Score", "G2M.Score"), features = rownames(scRNA))
1-3

2、PCA降维(线性降维)

scRNA <- RunPCA(scRNA, features = VariableFeatures(scRNA)) 
plot1 <- DimPlot(scRNA, reduction = "pca", group.by="orig.ident")
#(左图)根据主成分1和2的值将细胞在平面上展示出来
plot2 <- ElbowPlot(scRNA, ndims=20, reduction="pca") 
#(右图)展示前20个主成分的解释量
plot1+plot2

3、非线性降维(tSNE或UMAP)

先聚类cluster
pc.num=1:18
scRNA <- FindNeighbors(scRNA, dims = pc.num) 
# dims参数,需要指定哪些pc轴用于分析;这里利用上面的分析,选择18
scRNA <- FindClusters(scRNA, resolution = 0.5)
# resolution参数,需要指定0.1-0.9之间的一个数值,用于决定clusters的相对数量;
#数值越大,cluters越多。
table(scRNA@meta.data$seurat_clusters) #分成了0-9,共10个cluster
#  0   1   2   3   4   5   6   7   8   9 
#296 184 120 119  70  55  53  50  44  22 
tSNE
scRNA = RunTSNE(scRNA, dims = pc.num)
embed_tsne <- Embeddings(scRNA, 'tsne')
plot1 = DimPlot(scRNA, reduction = "tsne") 
3-1
UMAP
scRNA <- RunUMAP(scRNA, dims = pc.num)
embed_umap <- Embeddings(scRNA, 'umap')
plot2 = DimPlot(scRNA, reduction = "umap")
3-2
plotc <- plot1+plot2+ plot_layout(guides = 'collect')
saveRDS(scRNA, file="scRNA.rds")
上一篇 下一篇

猜你喜欢

热点阅读