Closed ixxmu closed 2 weeks ago
Windows系统
找到昨天的容器(我把它命名为rstudio),按下启动按钮就可以了
Linux系统
# 查看当前所有容器(可以不运行)
docker ps -a
# 启动rstudio的容器
docker start rstudio
数据预处理
初始化R环境
library(Seurat)
library(tidyverse)
library(patchwork)
library(parallel)
library(future)
library(scPRIT)
setwd("~/project/BeyondCode/CellType")
options(scprithost = "xxx.xxx.xxx.xxx", authcode = "xxxxxxxxxxxx")
options(future.globals.maxSize = 30 * 1024^3)
scRNA <- readRDS("~/project/BeyondCode/Data/sco.sub.qc.rds")
scRNA <- NormalizeData(scRNA)
scRNA <- FindVariableFeatures(scRNA)
scRNA <- ScaleData(scRNA)
scRNA <- RunPCA(scRNA, verbose = F)
ElbowPlot(scRNA, ndims = 50)
saveRDS(scRNA, file = "sco.log_pp.rds")
常规降维聚类
pcs <- 1:20
scRNA <- FindNeighbors(scRNA, reduction = "pca", dims = pcs)
scRNA <- FindClusters(scRNA, resolution = 1, cluster.name = "raw_cluster")
scRNA <- RunUMAP(scRNA, reduction = "pca", dims = pcs)
scRNA <- RunTSNE(scRNA, reduction = "pca", dims = pcs)
save(scRNA, file = "sco.log_dr.rda")
查看聚类结果与SingleR预测的细胞类型
p1 <- DimPlot(scRNA, reduction = "umap", group.by = "seurat_clusters", label = T) + NoLegend()
p2 <- DimPlot(scRNA, reduction = "umap", group.by = "SingleR", label = T) + NoLegend()
p <- p1 + p2
ggsave("unInt_SingleR_Cluster.pdf", p, width = 15, height = 7)
查看doublets预测结果
p1 <- FeaturePlot(scRNA, reduction = "umap", features = "DF.scores")
p2 <- DimPlot(scRNA, reduction = "umap", group.by = "DF.doublets") +
scale_color_manual(values = c("red","gray"))
p3 <- FeaturePlot(scRNA, reduction = "umap", features = "scr_score")
p4 <- DimPlot(scRNA, reduction = "umap", group.by = "scr_pred") +
scale_color_manual(values = c("gray","red"))
p <- (p1|p2)/(p3|p4)
ggsave("unInt_Doublets.pdf", p, width = 12, height = 9)
查看样本分组
p <- DimPlot(scRNA, reduction = "umap", group.by = c("SampleID","Group"), ncol = 2)
ggsave("unInt_Groups.pdf", p, width = 15, height = 7)
数据整合后降维聚类
# CCA整合
plan(multisession, workers = 16)
scRNA <- IntegrateLayers(
scRNA, method = CCAIntegration, k.anchor = 5,
orig.reduction = "pca", new.reduction = "cca",
verbose = FALSE)
plan(sequential)
# RPCA整合
plan(multisession, workers = 16)
scRNA <- IntegrateLayers(
scRNA, method = RPCAIntegration, k.anchor = 5,
orig.reduction = "pca", new.reduction = "rpca",
verbose = FALSE)
plan(sequential)
# Harmony整合
scRNA <- IntegrateLayers(
scRNA, method = HarmonyIntegration, lambda = 1,
orig.reduction = "pca", new.reduction = "harmony",
verbose = FALSE)
# CCA整合结果降维聚类
scRNA <- FindNeighbors(scRNA, reduction = "cca", dims = 1:30)
scRNA <- FindClusters(scRNA, resolution = 0.5, cluster.name = "cca_cluster")
scRNA <- RunUMAP(scRNA, reduction = "cca", dims = 1:30, reduction.name = "cca.umap")
# RPCA整合结果降维聚类
scRNA <- FindNeighbors(scRNA, reduction = "rpca", dims = 1:30)
scRNA <- FindClusters(scRNA, resolution = 0.5, cluster.name = "rpca_cluster")
scRNA <- RunUMAP(scRNA, reduction = "rpca", dims = 1:30, reduction.name = "rpca.umap")
# Harmony整合结果降维聚类
scRNA <- FindNeighbors(scRNA, reduction = "harmony", dims = 1:20)
scRNA <- FindClusters(scRNA, resolution = 0.5, cluster.name = "hny_cluster")
scRNA <- RunUMAP(scRNA, reduction = "harmony", dims = 1:20, reduction.name = "hny.umap")
# 保存结果
saveRDS(scRNA, file = "~/project/BeyondCode/Data/sco.int_dr.rds")
对比整合结果
# 画图展示
p1 <- DimPlot(scRNA, reduction = "umap", group.by = "raw_cluster", label = T) + NoLegend()
p2 <- DimPlot(scRNA, reduction = "cca.umap", group.by = "cca_cluster", label = T) + NoLegend()
p3 <- DimPlot(scRNA, reduction = "rpca.umap", group.by = "rpca_cluster", label = T) + NoLegend()
p4 <- DimPlot(scRNA, reduction = "hny.umap", group.by = "hny_cluster", label = T) + NoLegend()
p <- (p1+p2)/(p3+p4)
ggsave("Cluster_comparision.pdf", p, width = 12, height = 10)
p1 <- DimPlot(scRNA, reduction = "umap", group.by = "SingleR", label = T) + NoLegend()
p2 <- DimPlot(scRNA, reduction = "cca.umap", group.by = "SingleR", label = T) + NoLegend()
p3 <- DimPlot(scRNA, reduction = "rpca.umap", group.by = "SingleR", label = T) + NoLegend()
p4 <- DimPlot(scRNA, reduction = "hny.umap", group.by = "SingleR", label = T) + NoLegend()
p <- (p1+p2)/(p3+p4)
ggsave("SingleR_comparision.pdf", p, width = 12, height = 10)
聚类结果对比
细胞分布对比
SCTransform分析流程
scRNA <- readRDS("~/project/BeyondCode/Data/sco.sub.qc.rds")
scRNA <- SCTransform(scRNA)
scRNA <- RunPCA(scRNA, npcs = 30, verbose = F)
scRNA <- IntegrateLayers(
object = scRNA, k.anchor = 5,
method = RPCAIntegration,
normalization.method = "SCT",
verbose = F
)
scRNA <- FindNeighbors(scRNA, dims = 1:30, reduction = "integrated.dr")
scRNA <- FindClusters(scRNA, resolution = 0.5)
scRNA <- RunUMAP(scRNA, dims = 1:30, reduction = "integrated.dr")
save(scRNA, file = "sco.sct_rpca.rda")
分析完成后记得停止容器的运行!
提取码:eqjw
kinesin/rstudio:2.0.0镜像和scPRIT包的开发、测试非常耗费时间和精力,后续我希望可以持续提供维护和更新服务,因此计划采用收费授权的模式,具体标准如下:
200元,授权使用90天
600元,授权使用一年
授权期内如有更新免费升级,有意者添加Kinesin微信购买。
超越代码实战训练班
很多第一次分析单细胞数据的朋友,会把70%的时间耗费在代码和生信基础问题上,真正用来思考生物学问题的时间非常有限,因此产出高水平的文章相对比较困难。近几年,我深度参与了几十个单细胞、空转项目的分析,目前已有十几篇合作的署名/致谢文章发表。如果有我这么一个过来人提供分析环境和实战流程,并参与您的项目讨论,或许可以起到事半功倍的效果。如果您对此有兴趣,请阅读《超越代码》和《单细胞分析实战训练班的课程规划》了解详情!
https://mp.weixin.qq.com/s/wHFskvBIyWRp49zCGCIBmA