不积跬步无以至千里
安装R语言,工欲善其事,必先利其器,作为生信小白,安装R语言也走了不少弯路,要注意R语言和RStudio是搭配安装的哦
详情见网址“https://blog.csdn.net/beauty0522/article/details/82560024”
Seurat
Seurat发展史“https://www.jianshu.com/p/3fed86a6792c”
安装Seurat
install.packages("Seurat")
小白先不管,跟着大神把该安装的包和数据都安装了,总会有用到的那一天,请注意:一串安装代码来了
install.packages("devtools", dependencies=T)
install.packages("BiocManager", dependencies=T)
install.packages("tidyverse", dependencies=T)
#使用BiocManager安装分析包
BiocManager::install(c("SingleR","monocle", "DESeq2"),ask = F,update = F)
BiocManager::install(c("clusterProfiler","DOSE","pheatmap"),ask = F,update = F)
BiocManager::install(c("org.Hs.eg.db","org.Mm.eg.db","org.Rn.eg.db"),ask = F,update = F)
devtools::install_github('satijalab/seurat-data')
SeuratData::InstallData("pbmc3k")
终于该安装的包安装完了,接下来就是要用这些包去完成本周的KPI,绘制热图和点图。
运行Seurat
运行脚本和笔记
rm(list=ls()) #清空环境变量
ls() #查看环境变量,具体的环境变量在RStudio右上角框的“Environment”中也可查看
pbmc3k.SeuratData::pbmc3k.final -> vpdata #将pbmc3k的数据赋值到vpdata
vpdata #查看vpdata,就可以知道vpdata中内容
UMAPPlot(vpdata) #绘制UMAP图
UMAPPlot(vpdata)+NoLegend() #绘制没有图注的UMAP图
grep('TRPV',rownames(vpdata),value = T) #查看TRPV基因在不在vpdata中
library(ggplot2) # 加载ggplot2函数
FeaturePlot(vpdata,features = 'TRPV2') #绘制TRPV2基因的featureplot图
FeaturePlot(vpdata,features = 'TRPV2') +theme(panel.grid =element_blank()) +
theme(axis.text.y = element_blank()) +
theme(axis.ticks.y = element_blank()) +
theme(axis.ticks.y = element_blank()) +
theme(axis.line.y = element_blank()) +
labs(y = "") +
theme(axis.line.x = element_line(size=1, colour = "black")) # 对featureplot图的处理,去除了Y轴,且利用了ggplot2中的theme函数
?FeaturePlot #若有代码的疑问,直接?可在RStudio右下框查看具体用法
FeaturePlot(vpdata,features = c('CD8A','CD4','CD8B'),ncol = 3,raster = T) +NoLegend() #绘制3个基因的featureplot图
vpdata$stim <- sample(c("rep1", "rep2"), size = ncol(vpdata), replace = TRUE)
levels(Idents(vpdata))
FindMarkers(vpdata,ident.1 = 'rep1',ident.2 = 'rep2',group.by = 'stim')
subset(vpdata,idents = c('FCGR3A+ Mono','DC')) ->subvpdata
p1<- VlnPlot(subvpdata,features = c('IRF9'), split.by = 'stim', pt.size = 0,
split.plot = TRUE,combine = FALSE, log = TRUE)
p1[[1]]+ ggplot2::theme(legend.position='bottom') #双小提琴图
mk <- FindAllMarkers(vpdata) #寻找差异基因
library(tidyverse) #加载tidyverse函数
mk %>% group_by(cluster) %>% top_n(10,wt = avg_log2FC) -> top10g #
vpdata <- ScaleData(vpdata,features = top10g$gene) #
DoHeatmap(vpdata,features = top10g$gene) +
scale_fill_gradientn(colors = c("blue", "white", "red")) #小提琴图已出(颜色修饰)
pbmc3k <- pbmc3k.final <- vpdata
Idents(pbmc3k.final) <- as.vector(pbmc3k.final[['seurat_annotations',drop=T]])
# 直接指定某一列作为 Idents
Idents(pbmc3k, which(is.na(Idents(pbmc3k)))) <- "Unknown"
Bcellmarks <- c("CD19","CD79A","CD79B","MS4A1")
HLAmarks <- c("HLA-DQA1", "HLA-DQB1", "HLA-DRB3")
Monomarks <- c("CD14","VCAN","FCN1")
Tcellmarks <- c("CD3D","CD3E","CD3G","IL7R","TRAC","TRGC2","TRDC", "CD8A", "CD8B", "CD4")
DCmarks <- c(HLAmarks,"CLEC10A","CLEC9A")
platelet <- c("GP9","PF4")
features <- list("B cell" = Bcellmarks, "T cell" = Tcellmarks, "DC" = DCmarks, "Monocyte" = Monomarks, "Platelet" = platelet)
DotPlot(object = pbmc3k.final,
cols = c("lightgrey", "red"),
features=features,
cluster.idents=T) +
theme(axis.text.x = element_text(angle = 90))
?DotPlot
展示热图和点图