10X单细胞转录组数据分析记录

建立Seurat对象

library(dplyr)
library(Seurat)
library(patchwork)
library(SingleR)
library(celldex)
library(pheatmap)


# 加载单细胞数据集(三个文件:barcodes.tsv.gz  features.tsv.gz  matrix.mtx.gz)
pbmc.data <- Read10X(data.dir = "outs/filtered_feature_bc_matrix")
# 使用未标准化的原始数据初始化Seurat对象
pbmc <- CreateSeuratObject(counts = pbmc.data, project = "treat", min.cells = 3, min.features = 200)
pbmc
#An object of class Seurat
#28782 features across 10689 samples within 1 assay
#Active assay: RNA (28782 features, 0 variable features)

Read10x函数可以直接读取cellRanger处理过的10x单细胞测序数据文件,返回表达矩阵,该矩阵中的值表示在每个细胞(列)中检测到的每个特征(行)的数量。
CreateSeuratObject从Read10x读取的原始数据创建Seurat对象。
参数说明:

  • counts : 一个类似表达矩阵的对象,其中包含非标准化的数据,单元格为列,要素为行,或者是一个派生对象
  • project : Seurat对象的项目名称
  • min.cells : 至少细胞数量中检测到了基因
  • min.features : 至少检测到基因表达数的细胞。

数据QC 与细胞过滤

pbmc[["percent.mt"]] <- PercentageFeatureSet(pbmc, pattern = "^MT-")
pbmc[["percent.ribo"]] <- PercentageFeatureSet(pbmc, pattern = "^RPL|^RPS")
violin <- VlnPlot(pbmc, features = c("nFeature_RNA", "nCount_RNA", "percent.mt", "percent.ribo"), pt.size = 0.01,ncol = 4) + theme(axis.title.x=element_blank(), axis.text.x=element_blank(), axis.ticks.x=element_blank())
ggsave("QC/vlnplot_before_qc.png", plot = violin, width = 12, height = 6) 
FeatureScatter.png
plot1 <- FeatureScatter(pbmc, feature1 = "nCount_RNA", feature2 = "percent.mt")
plot2 <- FeatureScatter(pbmc, feature1 = "nCount_RNA", feature2 = "nFeature_RNA")
pdf("FeatureScatter.pdf")
plot1 + plot2
dev.off()
FeatureScatter.png
pbmc <- subset(pbmc, subset = nFeature_RNA > 200 & nFeature_RNA < 6000 & percent.mt < 10 & percent.ribo < 20)
pbmc
#An object of class Seurat
#28782 features across 8285 samples within 1 assay
#Active assay: RNA (28782 features, 0 variable features)

Normalizing the data

#Normalized values are stored in pbmc[["RNA"]]@data.
pbmc <- NormalizeData(pbmc, normalization.method = "LogNormalize", scale.factor = 10000)

Identification of highly variable features (feature selection)

pbmc <- FindVariableFeatures(pbmc, selection.method = "vst", nfeatures = 2000)
# Identify the 10 most highly variable genes
top10 <- head(VariableFeatures(pbmc), 10)
# plot variable features with and without labels
plot1 <- VariableFeaturePlot(pbmc)
plot2 <- LabelPoints(plot = plot1, points = top10, repel = TRUE)
pdf("VariableFeature.pdf")
plot1 / plot2
dev.off()
VariableFeature.png

Scaling the data

Next, we apply a linear transformation (‘scaling’) that is a standard pre-processing step prior to dimensional reduction techniques like PCA. The `[ScaleData()] function:

  • Shifts the expression of each gene, so that the mean expression across cells is 0
  • Scales the expression of each gene, so that the variance across cells is 1
    • This step gives equal weight in downstream analyses, so that highly-expressed genes do not dominate
  • The results of this are stored in pbmc[["RNA"]]@scale.data
all.genes <- rownames(pbmc)
pbmc <- ScaleData(pbmc, features = all.genes)

Perform linear dimensional reduction

Next we perform PCA on the scaled data. By default, only the previously determined variable features are used as input, but can be defined using features argument if you wish to choose a different subset.

pbmc <- RunPCA(pbmc, features = VariableFeatures(object = pbmc))
pdf("PCA.pdf")
VizDimLoadings(pbmc, dims = 1:4, reduction = "pca")
DimPlot(pbmc, reduction = "pca")
DimHeatmap(pbmc, dims = 1:15, cells = 500, balanced = TRUE)
dev.off()
PCA-0.png
PCA-1.png

PCA-2.png

Determine the ‘dimensionality’ of the dataset

To overcome the extensive technical noise in any single feature for scRNA-seq data, Seurat clusters cells based on their PCA scores, with each PC essentially representing a ‘metafeature’ that combines information across a correlated feature set.

pbmc <- JackStraw(pbmc, num.replicate = 100)
pbmc <- ScoreJackStraw(pbmc, dims = 1:20)
pdf("dimensionality.pdf")
ElbowPlot(pbmc)
JackStrawPlot(pbmc, dims = 1:20)
dev.off()
dimensionality-0.png
dimensionality-1.png

Cluster the cells

pbmc <- FindNeighbors(pbmc, dims = 1:18)
pbmc <- FindClusters(pbmc, resolution = 0.5)
pbmc <- RunUMAP(pbmc, dims = 1:18)
pdf("cluster_umap.pdf")
DimPlot(pbmc, reduction = "umap")
saveRDS(pbmc, file = "pbmc_tutorial.rds")
dev.off()
cluster_umap.png

Finding differentially expressed features (cluster biomarkers)

pbmc.markers <- FindAllMarkers(pbmc, only.pos = TRUE, min.pct = 0.25, logfc.threshold = 0.25)
pbmc.markers %>% group_by(cluster) %>% slice_max(n = 2, order_by = avg_log2FC)
pbmc.markers %>% group_by(cluster) %>% top_n(n = 5, wt = avg_log2FC) -> top5
pdf("DoHeatmap.pdf")
DoHeatmap(pbmc, features = top5$gene) + NoLegend()
dev.off()
DoHeatmap.png

Assigning cell type identity to clusters

#load(file="DATABASE/CellTypeAnno/celldex_hpca.RData")
hpca.ref <- HumanPrimaryCellAtlasData()
pred <- SingleR(test = pbmc@assays$RNA@data, ref = hpca.ref, labels = hpca.ref$label.main,  clusters = pbmc@active.ident)


table(pred$labels)
pdf("cell_type.pdf")
plotScoreHeatmap(pred)
plotDeltaDistribution(pred, ncol = 3)
new.cluster.ids <- pred$labels
names(new.cluster.ids) <- levels(pbmc)
UMAPPlot(object = pbmc, pt.size = 0.5, label = TRUE)
dev.off()
cell_type-0.png
cell_type-1.png
cell_type-2.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 213,616评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,020评论 3 387
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 159,078评论 0 349
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,040评论 1 285
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,154评论 6 385
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,265评论 1 292
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,298评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,072评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,491评论 1 306
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,795评论 2 328
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,970评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,654评论 4 337
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,272评论 3 318
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,985评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,223评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,815评论 2 365
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,852评论 2 351

推荐阅读更多精彩内容