一 R包,数据准备
library(Seurat)
library(SeuratData)
"satijalab/seurat-wrappers") remotes::install_github(
remotes::install_local("./seurat-wrappers-master.zip",upgrade = F,dependencies = F)
library(SeuratWrappers)
library(ggplot2)
library(patchwork)
options(future.globals.maxSize = 1e9)
2 下载示例数据
# 下载测试数据集
#InstallData("ifnb")
install.packages('./ifnb.SeuratData_3.1.0.tar.gz', repos = NULL, type = "source")
# load in the pbmc systematic comparative analysis dataset
obj <- LoadData("ifnb")
obj <- UpdateSeuratObject(obj)
obj <- subset(obj, nFeature_RNA > 1000)
obj
An object of class Seurat
14053 features across 1254 samples within 1 assay
Active assay: RNA (14053 features, 0 variable features)
2 layers present: counts, data
二 数据整合(批次处理)
1,数据拆分
obj[["RNA"]] <- split(obj[["RNA"]], f = obj$stim)
obj
An object of class Seurat
14053 features across 1254 samples within 1 assay
Active assay: RNA (14053 features, 0 variable features)
4 layers present: counts.CTRL, counts.STIM, data.CTRL, data.STIM
obj <- NormalizeData(obj)
obj <- FindVariableFeatures(obj)
obj <- ScaleData(obj)
obj <- RunPCA(obj)
2 数据直接合并(不去批次)
obj <- FindNeighbors(obj, dims = 1:30, reduction = "pca")
obj <- FindClusters(obj, resolution = 2, cluster.name = "unintegrated_clusters")
obj <- RunUMAP(obj, dims = 1:30,
reduction = "pca",
reduction.name = "umap.unintegrated")
DimPlot(obj, reduction = "umap.unintegrated",
group.by = c("stim", "seurat_annotations"))
Anchor-based CCA integration (method=CCAIntegration) Anchor-based RPCA integration (method=RPCAIntegration) Harmony (method=HarmonyIntegration) FastMNN (method= FastMNNIntegration) scVI (method=scVIIntegration)
obj <- IntegrateLayers(
object = obj, method = CCAIntegration,
orig.reduction = "pca", new.reduction = "integrated.cca",
verbose = FALSE
)
obj <- IntegrateLayers(
object = obj, method = RPCAIntegration,
orig.reduction = "pca", new.reduction = "integrated.rpca",
verbose = FALSE
)
obj <- IntegrateLayers(
object = obj, method = HarmonyIntegration,
orig.reduction = "pca", new.reduction = "harmony",
verbose = FALSE
)
obj <- IntegrateLayers(
object = obj, method = FastMNNIntegration,
new.reduction = "integrated.mnn",
verbose = FALSE
)
obj
4,确定去批次方法
4.1 ,umap展示
obj <- FindNeighbors(obj, reduction = "integrated.cca", dims = 1:30)
obj <- FindClusters(obj, resolution = 2, cluster.name = "cca_clusters")
obj <- RunUMAP(obj, reduction = "integrated.cca",
dims = 1:30,
reduction.name = "umap.cca")
p1 <- DimPlot(
obj,
reduction = "umap.cca",
group.by = c("Method", "CellType", "cca_clusters"),
combine = FALSE, label.size = 2
)
obj <- FindNeighbors(obj, reduction = "integrated.rpca", dims = 1:30)
obj <- FindClusters(obj, resolution = 2, cluster.name = "rpca_clusters")
obj <- RunUMAP(obj, reduction = "integrated.rpca",
dims = 1:30,
reduction.name = "umap.rpca")
p2 <- DimPlot(
obj,
reduction = "umap.rpca",
group.by = c("Method", "CellType", "rpca_clusters"),
combine = FALSE, label.size = 2
)
wrap_plots(c(p1, p2), ncol = 2, byrow = F)
4.2 Marker 可视化
p1 <- VlnPlot(
obj,
features = "rna_CD8A", group.by = "unintegrated_clusters") +
NoLegend() + ggtitle("CD8A - Unintegrated Clusters")
p2 <- VlnPlot(
obj, "rna_CD8A",
group.by = "cca_clusters") +
NoLegend() + ggtitle("CD8A - CCA Clusters")
p3 <- VlnPlot(
obj, "rna_CD8A",
group.by = "rpca_clusters") +
NoLegend() + ggtitle("CD8A - RPCA Clusters")
p1 | p2 | p3
p4 <- DimPlot(obj, reduction = "umap.unintegrated", group.by = c("cca_clusters"))
p5 <- DimPlot(obj, reduction = "umap.rpca", group.by = c("cca_clusters"))
p6 <- DimPlot(obj, reduction = "umap.cca", group.by = c("cca_clusters"))
p4 | p5 | p6
三 FindMarker 分析
1,rejoin layer
obj
obj2 <- JoinLayers(obj) #仅为了区分,实际情况下使用obj即可
obj2
◆ ◆ ◆ ◆ ◆
精心整理(含图PLUS版)|R语言生信分析,可视化(R统计,ggplot2绘图,生信图形可视化汇总)
RNAseq纯生信挖掘思路分享?不,主要是送你代码!(建议收藏)