#复习seurat流程rm(list = ls())library(Seurat)library(SeuratData)library(ggplot2)library(patchwork)library(dplyr)# Load the PBMC dataset# https://cf.10xgenomics.com/samples/cell/pbmc3k/pbmc3k_filtered_gene_bc_matrices.tar.gzpbmc.data <- Read10X(data.dir = "filtered_gene_bc_matrices/hg19/")# Initialize the Seurat object with the raw (non-normalized data).pbmc <- CreateSeuratObject(counts = pbmc.data, project = "pbmc3k", min.cells = 3, min.features = 200)pbmcpbmc[["percent.mt"]] <- PercentageFeatureSet(pbmc, pattern = "^MT-") #计算属于给定特性集的所有计数的百分比#将QC度量可视化为小提琴图VlnPlot(pbmc, features = c("nFeature_RNA", "nCount_RNA", "percent.mt"), ncol = 3)#FeatureScatter通常用于可视化特征-特征关系,但也可以用于对象计算的任何内容,例如对象元数据的列,PC分数等。plot1 <- FeatureScatter(pbmc, feature1 = "nCount_RNA", feature2 = "percent.mt") #单细胞数据的散点图plot2 <- FeatureScatter(pbmc, feature1 = "nCount_RNA", feature2 = "nFeature_RNA") #单细胞数据的散点图plot1 + plot2pbmc <- subset(pbmc, subset = nFeature_RNA > 200 & nFeature_RNA < 2500 & percent.mt < 5)pbmc <- NormalizeData(pbmc, normalization.method = "LogNormalize", scale.factor = 1e4) pbmc <- FindVariableFeatures(pbmc, selection.method = 'vst', nfeatures = 2000)#找出10个最易突变的基因top10 <- head(VariableFeatures(pbmc), 10)#绘制带有或不带有标签的变量特征plot1 <- VariableFeaturePlot(pbmc)plot2 <- LabelPoints(plot = plot1, points = top10, repel = TRUE)plot1 + plot2pbmc <- ScaleData(pbmc, vars.to.regress = "percent.mt")pbmc <- RunPCA(pbmc, features = VariableFeatures(object = pbmc)) pbmc <- FindNeighbors(pbmc, dims = 1:10)pbmc <- FindClusters(pbmc, resolution = 0.5)#查看前5个单元格的集群idhead(Idents(pbmc), 5)table(pbmc$seurat_clusters) pbmc <- RunUMAP(pbmc, dims = 1:10)#可以设置' label = TRUE '或使用LabelClusters功能来帮助标记单个集群DimPlot(pbmc, reduction = 'umap')VlnPlot(pbmc, features = c("MS4A1", "CD79A")) FeaturePlot(pbmc, features = c("MS4A1", "GNLY", "CD3E", "CD14", "FCER1A", "FCGR3A", "LYZ", "PPBP", "CD8A"))new.cluster.ids <- c("Naive CD4 T", "CD14+ Mono", "Memory CD4 T", "B", "CD8 T", "FCGR3A+ Mono", "NK", "DC", "Platelet")names(new.cluster.ids) <- levels(pbmc)pbmc <- RenameIdents(pbmc, new.cluster.ids)DimPlot(pbmc, reduction = 'umap', label = TRUE, pt.size = 0.5) + NoLegend()VlnPlot(pbmc, features = c("MS4A1", "CD79A")) FeaturePlot(pbmc, features = c("MS4A1", "CD79A"))RidgePlot(pbmc, features = c("MS4A1", "CD79A"), ncol = 1)features= c('IL7R', 'CCR7','CD14', 'LYZ', 'IL7R', 'S100A4',"MS4A1", "CD8A",'FOXP3', 'FCGR3A', 'MS4A7', 'GNLY', 'NKG7', 'FCER1A', 'CST3','PPBP')DotPlot(pbmc, features = unique(features)) + RotatedAxis()DoHeatmap(subset(pbmc ), features = features, size = 3)DoHeatmap(subset(pbmc, downsample = 100), features = features, size = 3)save(pbmc,file = 'basic.sce.pbmc.Rdata')
