ards数据集合 脓毒症 jimmy学徒 优秀代码 split灵活应用

本文主要是介绍ards数据集合 脓毒症 jimmy学徒 优秀代码 split灵活应用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

GEO Accession viewer

GEO Accession viewerNCBI's Gene Expression Omnibus (GEO) is a public archive and resource for gene expression data.https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE65682

 2. 拿相应的细胞Marker进行注释再看看,其实前一个注释结果就够(T细胞Mareker) --------------------------p=DimPlot(sce,reduction = "umap",label=T )  
sce.all = sce# yT1c=c("GNLY","PTGDS","GZMB","TRDC"),
# yT2c=c("TMN1","HMGB2","TYMS")
genes_to_check =list( naive=c("CCR7","SELL","TCF7","IL7R","CD27","CD28","LEF1","S1PR1"),CD8Trm=c("XCL1","XCL2","MYADM"),NKTc=c("GNLY","GZMA"), Tfh=c("CXCR5","BCL6","ICA1","TOX","TOX2","IL6ST"),th17=c("IL17A","KLRB1","CCL20","ANKRD28","IL23R","RORC","FURIN","CCR6","CAPG","IL22"),CD8Tem=c("CXCR4","GZMH","CD44","GZMK"),Treg=c("FOXP3","IL2RA","TNFRSF18","IKZF2"),naive=c("CCR7","SELL","TCF7","IL7R","CD27","CD28"),CD8Trm=c("XCL1","XCL2","MYADM"), MAIT=c("KLRB1","ZBTB16","NCR3","RORA"),yT1c=c("GNLY","PTGDS","GZMB","TRDC"),yT2c=c("TMN1","HMGB2","TYMS"),yt=c("TRGV9","TRDV2")
)
genes_to_check = lapply(genes_to_check, str_to_title)
dup=names(table(unlist(genes_to_check)))[table(unlist(genes_to_check))>1] #取出重名的marker基因
genes_to_check = lapply(genes_to_check, function(x) x[!x %in% dup]) #取出未重名的基因
p_all_markers=DotPlot(sce.all,  group.by = "RNA_snn_res.0.8",features = genes_to_check,scale = T,assay='RNA' )+theme(axis.text.x=element_text(angle=45,hjust = 1))
p_all_markers+p
ggsave('check_cd4_and_cd8T_markers.pdf',width = 9 )

# 拆成细胞类型对应的细胞list(CyclingT、CytoticT、NaiveT)
cell_list = split(colnames(sce.all),sce.all$celltype)
cell_list#获得相应细胞类型,对应的样本ID
names(cell_list)# 4.每个celltype不同分组之间差异分析 ----
dir.create("./by_celltype")
setwd("./by_celltype/")
getwd()

# 4.每个celltype不同分组之间差异分析 ----
dir.create("./by_celltype")
setwd("./by_celltype/")
getwd()# 利用FindAllMarkers进行差异分析---整个流程值得借鉴(针对每一种细胞类型在组别间分别进行差异分析)
# 保存每一种细胞类型的差异分析结果、对应细胞类型topMarker的Rdata、每种细胞类型top10气泡图与热图
for ( pro in names(cell_list) ) {#pro=names(cell_list)[1]sce=sce.all[,colnames(sce.all) %in% cell_list[[pro]]]sce <- CreateSeuratObject(counts = sce@assays$RNA@counts, meta.data = sce@meta.data, min.cells = 3, min.features = 200)  sce <- NormalizeData(sce)  sce = FindVariableFeatures(sce)sce = ScaleData(sce, vars.to.regress = c("nFeature_RNA","percent_mito"))Idents(sce)=sce$group #组别信息;后续用组别信息比较(赋值ident)table(Idents(sce))# 利用FindAllMarkers进行差异分析sce.markers <- FindAllMarkers(object = sce, only.pos = TRUE, logfc.threshold = 0.2,min.pct = 0.2, thresh.use = 0.2) write.csv(sce.markers,file=paste0(pro,'_sce.markers.csv'))sce.markers=sce.markers[order(sce.markers$cluster,sce.markers$avg_log2FC),]library(dplyr) top10 <- sce.markers %>% group_by(cluster) %>% top_n(10, avg_log2FC)# sce.Scale <- ScaleData(subset(sce,downsample=100),features =  unique(top10$gene)  )  sce.Scale <- ScaleData( sce ,features =  unique(top10$gene)  )  DoHeatmap(sce.Scale,features =  unique(top10$gene),# group.by = "celltype",assay = 'RNA', label = T)+scale_fill_gradientn(colors = c("white","grey","firebrick3"))ggsave(filename=paste0(pro,'_sce.markers_heatmap.pdf'),height = 8)p <- DotPlot(sce , features = unique(top10$gene)  ,assay='RNA'  )  + coord_flip()pggsave(plot=p, filename=paste0("check_top10-marker_by_",pro,"_cluster.pdf") ,height = 8)save(sce.markers,file=paste0(pro,'_sce.markers.Rdata')) }

细胞比例图library(ggsci)
ggplot(bar_per, aes(x = Var1, y = percent)) +geom_bar(aes(fill = Var2) , stat = "identity") + coord_flip() +theme(axis.ticks = element_line(linetype = "blank"),legend.position = "top",panel.grid.minor = element_line(colour = NA,linetype = "blank"), panel.background = element_rect(fill = NA),plot.background = element_rect(colour = NA)) +labs(y = "% Relative cell source", fill = NULL)+labs(x = NULL)+scale_fill_d3() #分组之间各种细胞占比ggsave("celltype_by_group_percent.pdf",units = "cm",width = 20,height = 12)
## 4.2 每种细胞类型中,各个样本所占比例 ----
bar_data <- as.data.frame(table(phe$celltype,phe$orig.ident))bar_per <- bar_data %>% group_by(Var1) %>%mutate(sum(Freq)) %>%mutate(percent = Freq / `sum(Freq)`)
bar_perwrite.csv(bar_per,file = "celltype_by_orig.ident_percent.csv")
ggplot(bar_per, aes(x = Var1, y = percent)) +geom_bar(aes(fill = Var2) , stat = "identity") + coord_flip() +theme(axis.ticks = element_line(linetype = "blank"),legend.position = "top",panel.grid.minor = element_line(colour = NA,linetype = "blank"), panel.background = element_rect(fill = NA),plot.background = element_rect(colour = NA)) +labs(y = "% Relative cell source", fill = NULL)+labs(x = NULL) ggsave("celltype_by_orig.ident_percent.pdf",units = "cm",width = 20,height = 12)

#自建函数# 自定义绘图函数,运行即可
head(phe)
plot_percent <- function(x,y){# x <- "group"# y <- "celltype"plot_data <- data.frame(table(phe[, x ],phe[, y ]))plot_data$Total <- apply(plot_data,1,function(x)sum(plot_data[plot_data$Var1 == x[1],3]))plot_data <- plot_data %>% mutate(Percentage = round(Freq/Total,3) * 100)pro <- xwrite.table(plot_data,paste0(pro,"_celltype_proportion.txt"),quote = F)th=theme(axis.text.x = element_text(angle = 45, vjust = 0.5, hjust=0.5)) library(paletteer) color <- c(paletteer_d("awtools::bpalette"),paletteer_d("awtools::a_palette"),paletteer_d("awtools::mpalette"))ratio1 <- ggplot(plot_data,aes(x = Var1,y = Percentage,fill = Var2)) +geom_bar(stat = "identity",position = "stack") +scale_fill_manual(values = color)+theme_classic() + theme(axis.title.x = element_blank()) + labs(fill = "Cluster") +th ratio1f=paste0('ratio_by_',x,'_VS_',y)h=floor(5+length(unique(plot_data[,1]))/2)w=floor(3+length(unique(plot_data[,2]))/2)ggsave(paste0('bar1_',f,'.pdf'),ratio1,height = h ,width = w ) pdf(paste0('balloonplot_',f,'.pdf'),height = 12 ,width = 20)balloonplot(table(phe[, x ],phe[, y ]))dev.off()plot_data$Total <- apply(plot_data,1,function(x)sum(plot_data[plot_data$Var1 == x[1],3]))plot_data<- plot_data %>% mutate(Percentage = round(Freq/Total,3) * 100)bar_Celltype=ggplot(plot_data,aes(x = Var1,y = Percentage,fill = Var2)) +geom_bar(stat = "identity",position = "stack") +theme_classic() + theme(axis.text.x=element_text(angle=45,hjust = 1)) + labs(fill = "Cluster")+facet_grid(~Var2,scales = "free")bar_Celltypeggsave(paste0('bar2_',f,'.pdf'),bar_Celltype,height = 8 ,width =  40) 
}## 4.3 每个分组中,不同细胞类型所占比例 ----plot_percent("group","celltype")## 4.4 每个分组中,不同细胞类型所占比例 ----
plot_percent("orig.ident","celltype")

#分组富集分析
getwd()  #"G:/linux study/hsp70_human/ref/201023国庆授课检查版/4_group"
setwd("G:/linux study/hsp70_human/ref/201023国庆授课检查版/4_group")
dir.create("../5_GO_KEGG")
setwd("../5_GO_KEGG/")
getwd()  #"G:/linux study/hsp70_human/ref/201023国庆授课检查版/5_GO_KEGG"# 对各个亚群的topMarker基因进行降维聚类分群 -----------------------------------------------## 3.1 kegg and go by cluster ----
# 只针对find的各个亚群top基因
# 现在我们选择了COSG算法if(T){# 3.all 读取数据富集分析-## 3.1 kegg and go by cluster 可视化 ----f = '../3-cell/harmony-sce.markers.Rdata' #决定了找簇与簇的显著富集的KEGG通路# 这个Rdata数据源于step3.1,针对簇利用FindAllMarker找簇的Top Marker 基因if(file.exists(f)){load(file = f)sce.markers=sce.markers[sce.markers$avg_log2FC > 0,]top1000 <- sce.markers %>% group_by(cluster) %>% top_n(1000, avg_log2FC)head(top1000) library(ggplot2)ids=bitr(top1000$gene,'SYMBOL','ENTREZID','org.Mm.eg.db')top1000=merge(top1000,ids,by.x='gene',by.y='SYMBOL')gcSample=split(top1000$ENTREZID, top1000$cluster) #分组太强大了 切割 按照组别切割splitgcSample # entrez id , compareCluster names(gcSample)xx <- compareCluster(gcSample, fun="enrichKEGG",organism="mmu")str(xx)p=dotplot(xx) p+ theme(axis.text.x = element_text(angle = 45, vjust = 0.5, hjust=0.5))ggsave('compareCluster-KEGG-top1000-cluster.pdf',width = 18,height = 8)xx <- compareCluster(gcSample, fun="enrichGO",OrgDb='org.Mm.eg.db')summary(xx)p=dotplot(xx) p+ theme(axis.text.x = element_text(angle = 90, vjust = 0, hjust=1))ggsave('compareCluster-GO-top1000-cluster.pdf',width = 15,height = 12)}}

这篇关于ards数据集合 脓毒症 jimmy学徒 优秀代码 split灵活应用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/566583

相关文章

使用Python和PaddleOCR实现图文识别的代码和步骤

《使用Python和PaddleOCR实现图文识别的代码和步骤》在当今数字化时代,图文识别技术的应用越来越广泛,如文档数字化、信息提取等,PaddleOCR是百度开源的一款强大的OCR工具包,它集成了... 目录一、引言二、环境准备2.1 安装 python2.2 安装 PaddlePaddle2.3 安装

Python datetime 模块概述及应用场景

《Pythondatetime模块概述及应用场景》Python的datetime模块是标准库中用于处理日期和时间的核心模块,本文给大家介绍Pythondatetime模块概述及应用场景,感兴趣的朋... 目录一、python datetime 模块概述二、datetime 模块核心类解析三、日期时间格式化与

SpringBoot中四种AOP实战应用场景及代码实现

《SpringBoot中四种AOP实战应用场景及代码实现》面向切面编程(AOP)是Spring框架的核心功能之一,它通过预编译和运行期动态代理实现程序功能的统一维护,在SpringBoot应用中,AO... 目录引言场景一:日志记录与性能监控业务需求实现方案使用示例扩展:MDC实现请求跟踪场景二:权限控制与

Java注解之超越Javadoc的元数据利器详解

《Java注解之超越Javadoc的元数据利器详解》本文将深入探讨Java注解的定义、类型、内置注解、自定义注解、保留策略、实际应用场景及最佳实践,无论是初学者还是资深开发者,都能通过本文了解如何利用... 目录什么是注解?注解的类型内置注编程解自定义注解注解的保留策略实际用例最佳实践总结在 Java 编程

一文教你Python如何快速精准抓取网页数据

《一文教你Python如何快速精准抓取网页数据》这篇文章主要为大家详细介绍了如何利用Python实现快速精准抓取网页数据,文中的示例代码简洁易懂,具有一定的借鉴价值,有需要的小伙伴可以了解下... 目录1. 准备工作2. 基础爬虫实现3. 高级功能扩展3.1 抓取文章详情3.2 保存数据到文件4. 完整示例

使用Java将各种数据写入Excel表格的操作示例

《使用Java将各种数据写入Excel表格的操作示例》在数据处理与管理领域,Excel凭借其强大的功能和广泛的应用,成为了数据存储与展示的重要工具,在Java开发过程中,常常需要将不同类型的数据,本文... 目录前言安装免费Java库1. 写入文本、或数值到 Excel单元格2. 写入数组到 Excel表格

python处理带有时区的日期和时间数据

《python处理带有时区的日期和时间数据》这篇文章主要为大家详细介绍了如何在Python中使用pytz库处理时区信息,包括获取当前UTC时间,转换为特定时区等,有需要的小伙伴可以参考一下... 目录时区基本信息python datetime使用timezonepandas处理时区数据知识延展时区基本信息

Qt实现网络数据解析的方法总结

《Qt实现网络数据解析的方法总结》在Qt中解析网络数据通常涉及接收原始字节流,并将其转换为有意义的应用层数据,这篇文章为大家介绍了详细步骤和示例,感兴趣的小伙伴可以了解下... 目录1. 网络数据接收2. 缓冲区管理(处理粘包/拆包)3. 常见数据格式解析3.1 jsON解析3.2 XML解析3.3 自定义

SpringMVC 通过ajax 前后端数据交互的实现方法

《SpringMVC通过ajax前后端数据交互的实现方法》:本文主要介绍SpringMVC通过ajax前后端数据交互的实现方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价... 在前端的开发过程中,经常在html页面通过AJAX进行前后端数据的交互,SpringMVC的controll

Pandas统计每行数据中的空值的方法示例

《Pandas统计每行数据中的空值的方法示例》处理缺失数据(NaN值)是一个非常常见的问题,本文主要介绍了Pandas统计每行数据中的空值的方法示例,具有一定的参考价值,感兴趣的可以了解一下... 目录什么是空值?为什么要统计空值?准备工作创建示例数据统计每行空值数量进一步分析www.chinasem.cn处