OSCR

Gut microbial metabolic disorder in depression: insights from computational modeling and mediation analysis.

Code ↔ Paper

The paper beside its authors' code: matches between them have not been computed for this paper yet.

Paper

Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC

The paper is loaded when this pane is shown.

The authors' code

R · 2,141 lines · 89 KB · no license

  1. rm(list = ls())
  2. library(Maaslin2)
  3. library(MicrobiotaProcess)
  4. library(tidyverse)
  5. library(compositions)
  6. library(pheatmap)
  7. library(phyloseq)
  8. library(ggalluvial)
  9. library(dplyr)
  10. library(qvalue)
  11. library(gridExtra)
  12. library(ggsignif)
  13. library(ggpubr)
  14. library(data.table)
  15. library(ggplot2)
  16. library(ggExtra)
  17. library(ggtext)
  18. library(vegan)
  19. library(caret)
  20. library(data.table)
  21. library(ggtext)
  22. library(ggbreak)
  23. meta_D<-read.table('D:/microbiome/micom/202404/paper/data/meta_Depression.txt',sep = '\t',header = T)
  24. meta_H<-read.table('D:/microbiome/micom/202404/paper/data/meta_healthy.txt',sep = '\t',header = T)
  25. colnames(meta_H)[8]<-'disease'
  26. colnames(meta_D)[8]<-'disease'
  27. meta_H$disease<-'Healthy'
  28. meta_D$disease<-'Depression'
  29. age<-rbind(meta_H[,c(6,8),drop=F],meta_D[,c(6,8),drop=F])
  30. p1<-ggplot(age, aes(x = Host.age, fill = disease)) +
  31. geom_density(alpha = 0.5) +
  32. labs(x = "Age(Before matching)") +
  33. theme_minimal() +
  34. scale_fill_manual(values=c('Depression'='#E7B800', 'Healthy'='#00AFBB'))+
  35. ggtitle('C')+
  36. theme(legend.position = 'none')+
  37. theme(plot.title = element_text(face = 'bold'))+
  38. theme(axis.text.y = element_blank(),
  39. axis.title = element_blank(),
  40. panel.grid = element_blank())
  41. p1##p.val:6.265e-15
  42. BMI<-rbind(meta_H[,c(7,8),drop=F],meta_D[,c(7,8),drop=F])
  43. p2<-ggplot(BMI, aes(x = BMI, fill = disease)) +
  44. geom_density(alpha = 0.5) +
  45. labs(x = "BMI(Before matching)") +
  46. theme_minimal() +
  47. scale_fill_manual(values=c('Depression'='#E7B800', 'Healthy'='#00AFBB'))+
  48. xlim(c(0,55))+
  49. ggtitle('E')+
  50. theme(plot.title = element_text(face = 'bold'))+
  51. theme(legend.position = 'none')+
  52. theme(axis.text.y = element_blank(),
  53. axis.title = element_blank(),
  54. panel.grid = element_blank())
  55. p2##p.val:0.4529
  56. meta_H<-read.csv('D:/microbiome/micom/202404/paper/data/1-1/meta_H_used.csv',row.names = 1)
  57. meta_D<-read.csv('D:/microbiome/micom/202404/paper/data/1-1/meta_D_used.csv',row.names = 1)
  58. colnames(meta_H)[5]<-'disease'
  59. colnames(meta_D)[5]<-'disease'
  60. meta_H$disease<-'Healthy'
  61. meta_D$disease<-'Depression'
  62. age<-rbind(meta_H[,c(3,5),drop=F],meta_D[,c(3,5),drop=F])
  63. p3<-ggplot(age, aes(x = Host.age, fill = disease)) +
  64. geom_density(alpha = 0.5) +
  65. labs(x = "Age(After matching)") +
  66. theme_minimal() +
  67. scale_fill_manual(values=c('Depression'='#E7B800', 'Healthy'='#00AFBB'))+
  68. ggtitle('D')+
  69. theme(plot.title = element_text(face = 'bold'))+
  70. theme(legend.position = 'none')+
  71. theme(axis.text.y = element_blank(),
  72. axis.title = element_blank(),
  73. panel.grid = element_blank())
  74. p3##p.val:0.5574
  75. BMI<-rbind(meta_H[,c(4,5),drop=F],meta_D[,c(4,5),drop=F])
  76. p4<-ggplot(BMI, aes(x = BMI, fill = disease)) +
  77. geom_density(alpha = 0.5) +
  78. labs(x = "BMI(After matching)") +
  79. theme_minimal() +
  80. scale_fill_manual(values=c('Depression'='#E7B800', 'Healthy'='#00AFBB'))+
  81. ggtitle('F')+
  82. theme(plot.title = element_text(face = 'bold'))+
  83. theme(axis.text.y = element_blank(),
  84. axis.title = element_blank(),
  85. panel.grid = element_blank())
  86. p4##p.val:0.8053
  87. pdf(file = 'D:/microbiome/micom/202404/paper/figures/fig1.pdf',width = 15,height = 5.82)
  88. grid.arrange(p1, p3,p2,p4,nrow = 1)
  89. dev.off()
  90. abundance_D<-read.csv('D:/microbiome/micom/202404/paper/data/1-1/depression_genus.csv',row.names = 1)
  91. abundance_D<-abundance_D[match(rownames(meta_D),colnames(abundance_D))]
  92. temp<-abundance_D
  93. temp[temp!=0]<-1
  94. abundance_D<-abundance_D[which(rowSums(temp)>ncol(abundance_D)*0.1)%>%as.numeric(),]
  95. abundance_H<-read.csv('D:/microbiome/micom/202404/paper/data/1-1/healthy_genus.csv',row.names = 1)
  96. abundance_H<-abundance_H[match(rownames(meta_H),colnames(abundance_H))]
  97. temp<-abundance_H
  98. temp[temp!=0]<-1
  99. #abundance_H<-abundance_H[which(rowSums(temp)>ncol(abundance_H)*0.1)%>%as.numeric(),]
  100. abundance<-merge(abundance_D,abundance_H,by = "row.names",all = TRUE)
  101. abundance[is.na(abundance)]<-0
  102. rownames(abundance)<-abundance$Row.names
  103. abundance$Row.names<-NULL
  104. #abundance_clr<-t(abundance/100)%>%clr()%>%as.matrix()%>%t()
  105. meta<-rbind(meta_D,meta_H)
  106. files<-list.files('D:/microbiome/micom/genus_models/genus_models/')
  107. for(i in 1:length(files)){
  108. files[i]<-substr(files[i],1,nchar(files[i])-4)
  109. }
  110. abundance1<-abundance_H[files,]
  111. abundance1<-na.omit(abundance1)
  112. colSums(abundance1)%>%hist()
  113. ##########alpha
  114. OTU<-phyloseq::otu_table(abundance,taxa_are_rows = T)
  115. meta1<-phyloseq::sample_data(meta)
  116. physeq<-phyloseq(OTU,meta1)
  117. mpse<-as.MPSE(physeq)
  118. mpse@assays@data@listData[["Abundance"]]<-mpse@assays@data@listData[["Abundance"]]*1e10
  119. mpse %<>%
  120. mp_decostand(.abundance=Abundance)
  121. cols<-c('Depression'='#E7B800', 'Healthy'='#00AFBB')
  122. mpse %<>% mp_cal_alpha(.abundance = Abundance,force = T)
  123. p5 <- mpse %>%
  124. mp_plot_alpha(
  125. .alpha = c(Observe, Shannon,Chao1,Simpson, Pielou),
  126. .group = disease,
  127. ) +
  128. scale_fill_manual(values=cols) +
  129. scale_color_manual(values=cols) +
  130. theme(
  131. legend.position="none",
  132. strip.background = element_rect(colour=NA, fill="grey")
  133. )+
  134. ggtitle('A')+
  135. theme(plot.title = element_text(face = 'bold'))
  136. p5
  137. ##########anosim
  138. mpse %>%
  139. mp_anosim(.abundance=Abundance, .group=disease, action="get")
  140. mpse %<>% mp_cal_dist(.abundance=hellinger, distmethod="bray")
  141. p6 <- mpse %>% mp_plot_dist(.distmethod = bray, .group = disease, group.test=TRUE, textsize=2)+
  142. ggtitle('C')+
  143. theme(plot.title = element_text(face = 'bold'))
  144. p6
  145. ##########pcoa
  146. dist_bray <- phyloseq::distance(physeq, method = "bray")
  147. pcoa <- ordinate(physeq, method = "PCoA", distance = dist_bray)
  148. pcoa_df <- data.frame(pcoa$vectors)
  149. pcoa_df$SampleID <- rownames(pcoa_df)
  150. sample_data<-cbind(rownames(meta),meta$disease)%>%as.data.frame()
  151. colnames(sample_data)<-c('SampleID','disease')
  152. rownames(sample_data)<-sample_data$SampleID
  153. pcoa_df <- merge(pcoa_df, sample_data, by.x = "SampleID", by.y = "SampleID")
  154. p7<-ggplot(pcoa_df, aes(x = Axis.1, y = Axis.2, color = disease)) +
  155. geom_point(alpha = 0.4) +
  156. labs(
  157. x = paste0("PCOA1 (", round(pcoa[["values"]][["Eigenvalues"]][1], 2), "%)"),
  158. y = paste0("PCOA2 (", round(pcoa[["values"]][["Eigenvalues"]][2], 2), "%)"),
  159. color = "label"
  160. ) +
  161. theme_minimal()+
  162. theme(legend.position = 'none')+
  163. stat_ellipse(aes(color = disease),type = "t", level = 0.95)+
  164. scale_color_manual(values=c('Depression'='#E7B800', 'Healthy'='#00AFBB'))+
  165. annotate("text", x = -0.3, y = -0.3, label = "ANOSIM R: 0.007962
  166. P: 0.004")+
  167. ggtitle('B')+
  168. theme(plot.title = element_text(face = 'bold'))
  169. p7
  170. p7<-ggMarginal(p7, type = "boxplot", margins = "both", size = 5, groupColour = TRUE, groupFill = TRUE)
  171. p7
  172. #abundance1<-t(abundance)%>%as.data.frame()
  173. #env<-cbind(meta$Host.age,meta$BMI)%>%as.data.frame()
  174. #colnames(env)<-c('Age','BMI')
  175. #rownames(env)<-rownames(abundance1)
  176. #cca <- cca(abundance1 ~ ., data = env)
  177. #cca_summary<-summary(cca)
  178. #cca_df<-cca_summary$sites%>%as.data.frame()
  179. #cca_df$disease<-meta$disease[match(rownames(cca_df),rownames(meta))]
  180. #scores <- as.data.frame(scores(cca)$biplot)
  181. #p7<-ggplot(cca_df, aes(x = CCA1, y = CCA2, color = disease)) +
  182. # geom_point(alpha = 0.4) +
  183. # geom_segment(data = scores, aes(x = 0, xend = CCA1*20, y = 0, yend = CCA2*20),
  184. # arrow = arrow(length = unit(0.2, "cm")), color = "red")+
  185. # labs(
  186. # x = paste0("CCA1 (", round(cca$CCA$eig[1] * 100, 2), "%)"),
  187. # y = paste0("CCA2 (", round(cca$CCA$eig[2] * 100, 2), "%)"),
  188. # color = "label"
  189. # ) +
  190. # theme_minimal()+
  191. # theme(legend.position = 'none')+
  192. # stat_ellipse(aes(color = disease),type = "t", level = 0.95)+
  193. # scale_color_manual(values=c('Depression'='#E7B800', 'Healthy'='#00AFBB'))+
  194. # annotate("text", x = -10, y = -20, label = "ANOSIM R: 0.007962
  195. # P: 0.004")+
  196. # ggtitle('B')
  197. #p7<-ggMarginal(p7, type = "boxplot", margins = "both", size = 5, groupColour = TRUE, groupFill = TRUE)
  198. #p7
  199. pdf(file = 'D:/microbiome/micom/202404/paper/figures/fig2_1.pdf',width = 15,height = 4)
  200. grid.arrange(p5,p7,ncol=2)
  201. dev.off()
  202. #########
  203. #top5_D<-rownames(abundance_D)[order(rowSums(abundance_D),decreasing = T)[1:5]]
  204. #df_D<-rowSums(abundance_D[top5_D,])%>%as.data.frame()
  205. #colnames(df_D)<-'Depression'
  206. #df_D<-rbind(df_D,abundance_D[-order(rowSums(abundance_D),decreasing = T)[1:5],]%>%rowSums()%>%sum())
  207. #rownames(df_D)[6]<-'Others'
  208. #top5_H<-rownames(abundance_H)[order(rowSums(abundance_H),decreasing = T)[1:5]]
  209. #df_H<-rowSums(abundance_H[top5_H,])%>%as.data.frame()
  210. #colnames(df_H)<-'Healthy'
  211. #df_H<-rbind(df_H,abundance_H[-order(rowSums(abundance_H),decreasing = T)[1:5],]%>%rowSums()%>%sum())
  212. #rownames(df_H)[6]<-'Others'
  213. #df<-merge(df_D,df_H,by = "row.names",all = TRUE)
  214. #rownames(df)<-df$Row.names
  215. #df$Row.names<-NULL
  216. #df[is.na(df)]<-0
  217. #df$genus<-rownames(df)
  218. #temp<-colSums(df[,1:2])%>%as.numeric()
  219. #df[,1]<-df[,1]/temp[1]
  220. #df[,2]<-df[,2]/temp[2]
  221. #data_long <- df %>%
  222. # tidyr::gather(key = "group", value = "value", -genus)
  223. #data_alluvial <- data_long %>%
  224. # dplyr::mutate(flow = rep(1:length(unique(data_long$genus)),2))
  225. #desired_order<-c('Healthy','Depression')
  226. #colnames(data_alluvial)[1]<-'Genus'
  227. #p8<-ggplot(data_alluvial, aes(x = group, y = value, fill = Genus, stratum = Genus, alluvium = flow)) +
  228. # geom_stratum(width = 0.4) +
  229. # geom_flow(stat = "alluvium", lode.guidance = "forward", aes.flow = "backward") +
  230. # theme_minimal() +
  231. # labs(x = "", y = "abundance") +
  232. # scale_fill_brewer(type = "qual", palette = "Set3") +
  233. # scale_x_discrete(limits=desired_order)+
  234. # theme(legend.text=element_text(face="italic"))+
  235. # ggtitle('D')+
  236. # theme(plot.title = element_text(face = 'bold'))
  237. #p8
  238. ############Wilcoxon signed rank test
  239. abundance_D<-abundance[,match(rownames(meta_D),colnames(abundance))]
  240. abundance_H<-abundance[,match(rownames(meta_H),colnames(abundance))]
  241. res<-matrix(0,nrow(abundance),2)%>%as.data.frame()
  242. rownames(res)<-rownames(abundance)
  243. colnames(res)<-c('p.val','fdr')
  244. for(i in 1:nrow(abundance)){
  245. res[i,1]<-wilcox.test(abundance_D[i,]%>%as.numeric(),abundance_H[i,]%>%as.numeric(),paired = T)$p.val
  246. }
  247. res[,2]<-p.adjust(res[,1],method = 'BH')
  248. diff_top50<-rownames(res)[order(res[,2],decreasing = F)[1:50]]
  249. diff_top50
  250. diff<-rownames(res)[which(res[,2]<0.05)]
  251. #diff1<-rownames(res)[which(res[,2]>1e-5&res[,2]<0.05)]
  252. #diff1
  253. #exp<-abundance_clr[diff_top50,]
  254. #label<-meta[,5,drop=F]
  255. #ann_colors = list(disease=c(Healthy="#00AFBB",Depression="#E7B800"))
  256. #col <- c(colorRampPalette(c("#4DBBD5FF", "white"))(abs(min(exp))*100),
  257. # colorRampPalette('white')(1),
  258. # colorRampPalette(c("white", "#F39B7FFF"))(max(exp)*100))
  259. #p9<-pheatmap(exp,show_colnames = F,show_rownames = T,
  260. # annotation_col = label,
  261. # annotation_colors = ann_colors,
  262. # color = col,
  263. # cluster_cols = F,
  264. # fontfamily="serif")
  265. #p9
  266. #pdf(file = 'diff_genus.pdf',width = 8,height = 15)
  267. #pheatmap(exp,show_colnames = F,show_rownames = T,
  268. # annotation_col = label,
  269. # annotation_colors = ann_colors,
  270. # color = col,
  271. # cluster_cols = F,
  272. # fontfamily="serif")
  273. #dev.off()
  274. #diff<-rownames(res)[which(res[,2]<0.005)]
  275. #a<-c('Bifidobacterium','Blautia','Ruminococcus','Oscillibacter','Faecalibacterium','Corprococcus','Alistipes','Dialister')
  276. #intersect(a,diff)
  277. #diff_abundance<-abundance[diff,]
  278. #top5_abundance<-rowSums(diff_abundance)%>%as.data.frame()
  279. #top5_genus<-diff_abundance[rownames(top5_abundance)[order(top5_abundance[,1],decreasing = T)[1:5]],]
  280. #top5_genus<-t(top5_genus)%>%as.data.frame()
  281. #top5_genus$id<-rownames(top5_genus)
  282. #top5_genus<-pivot_longer(top5_genus,
  283. # cols = -id,
  284. # names_to = "Genus",
  285. # values_to = "Relative Abundance"
  286. #)
  287. #top5_genus$label<-meta$disease[match(top5_genus$id,rownames(meta))]
  288. #p10<-ggplot(top5_genus, aes(x = `Relative Abundance`, y = Genus, fill = label)) +
  289. # geom_boxplot(outlier.shape = NA) +
  290. # theme_minimal() +
  291. # scale_fill_manual(values=c('Depression'='#E7B800', 'Healthy'='#00AFBB'))+
  292. # theme(axis.text.y = element_text(face = "italic"))+
  293. # ggtitle('C')
  294. #p10
  295. #pdf(file = 'D:/microbiome/micom/202404/paper/figures/fig2.pdf',width = 12,height = 10)
  296. #grid.arrange(arrangeGrob(p5, p7,ncol=2),p10, nrow = 2)
  297. #dev.off()
  298. #exp1<-abundance_clr[diff1,]
  299. #col <- c(colorRampPalette(c("#4DBBD5FF", "white"))(abs(min(exp1))*100),
  300. # colorRampPalette('white')(1),
  301. # colorRampPalette(c("white", "#F39B7FFF"))(max(exp1)*100))
  302. #p5<-pheatmap(exp1,show_colnames = F,show_rownames = F,
  303. # annotation_col = label,
  304. # annotation_colors = ann_colors,
  305. # color = col)
  306. ##########Maaslin2
  307. #meta_D1<-meta_D
  308. #meta_D1$disease[1:100]<-'Healthy'
  309. #fit_data = Maaslin2(input_data = t(abundance_D),
  310. # input_metadata = meta_D1,
  311. # min_prevalence = 0,
  312. # normalization = "NONE",
  313. # max_significance = 1,
  314. # output = "D:/microbiome/micom/202404/paper/result/1-1/Maaslin2_result/Depression",
  315. # fixed_effects = c("Host.age",'BMI'))
  316. #
  317. #meta_H1<-meta_H
  318. #meta_H1$disease[1:100]<-'Depression'
  319. #fit_data = Maaslin2(input_data = t(abundance_H),
  320. # input_metadata = meta_H1,
  321. # min_prevalence = 0,
  322. # normalization = "NONE",
  323. # max_significance = 1,
  324. # output = "D:/microbiome/micom/202404/paper/result/1-1/Maaslin2_result/Healthy",
  325. # fixed_effects = c("Host.age",'BMI'))
  326. ############
  327. #coef_D<-read.table('D:/microbiome/micom/202404/paper/result/1-1/Maaslin2_result/Depression/all_results.tsv',header = T)
  328. #coef_H<-read.table('D:/microbiome/micom/202404/paper/result/1-1/Maaslin2_result/Healthy/all_results.tsv',header = T)
  329. #coef_D<-coef_D[which(coef_D$metadata=='Host.age'),]
  330. #coef_H<-coef_H[which(coef_H$metadata=='Host.age'),]
  331. #coef_D<-coef_D[match(intersect(coef_D$feature,coef_H$feature),coef_D$feature),]
  332. #coef_H<-coef_H[match(intersect(coef_D$feature,coef_H$feature),coef_H$feature),]
  333. #coef<-cbind(coef_D$coef,coef_H$coef)%>%as.data.frame()
  334. #colnames(coef)<-c('Depression','Healthy')
  335. #rownames(coef)<-coef_D$feature
  336. #coef$index<-abs(coef[,1]-coef[,2])
  337. #genus<-c('Ruminococcus','Lactonifactor')
  338. ######
  339. #a<-cor(t(abundance_D),meta_D$Host.age)
  340. #b<-cor(t(abundance_H),meta_H$Host.age)
  341. ###########
  342. Reactionabundance<-read.csv('D:/microbiome/micom/202404/paper/result/1-1/Results/ReactionAbundance.csv',row.names = 1)
  343. #Reactionpresence<-Reactionabundance
  344. #Reactionpresence[Reactionpresence!=0]<-1
  345. #Subsystemabundance<-read.csv('D:/microbiome/micom/202404/paper/result/1-1/Results/SubsystemAbundance.csv',row.names = 1)
  346. #Subsystempresence<-Subsystemabundance
  347. #Subsystempresence[Subsystempresence!=0]<-1
  348. #genuspresence<-abundance
  349. #genuspresence[genuspresence!=0]<-1
  350. #df<-rbind(genuspresence,Reactionpresence,Subsystempresence)
  351. #df<-t(df)
  352. #label_col<-c(rep('Genus',nrow(genuspresence)),
  353. # rep('Reactions',nrow(Reactionpresence)),
  354. # rep('Subsystem',nrow(Subsystempresence)))%>%as.data.frame()
  355. #colnames(label_col)<-'label'
  356. #rownames(label_col)<-colnames(df)
  357. #label_row<-meta[,5,drop=F]
  358. #col <-c("white", "#4DBBD5FF")
  359. #p11<-pheatmap(df,show_colnames = F,show_rownames = F,
  360. # annotation_row = label_row,
  361. # annotation_col = label_col,
  362. # annotation_colors = ann_colors,
  363. # color = col,
  364. # cluster_rows = F,
  365. # cluster_cols = F,
  366. # legend = F)
  367. #p11
  368. ########Wilcoxon signed rank test (Reaction)
  369. res_reaction<-matrix(0,nrow(Reactionabundance),2)
  370. colnames(res_reaction)<-c('p.val','fdr')
  371. rownames(res_reaction)<-rownames(Reactionabundance)
  372. Reactionabundance_D<-Reactionabundance[,match(rownames(meta_D),colnames(Reactionabundance))]
  373. Reactionabundance_H<-Reactionabundance[,match(rownames(meta_H),colnames(Reactionabundance))]
  374. for(i in 1:nrow(Reactionabundance)){
  375. print(i)
  376. res_reaction[i,1]<-wilcox.test(Reactionabundance_D[i,]%>%as.numeric(),Reactionabundance_H[i,]%>%as.numeric(),paired = T)$p.val
  377. }
  378. res_reaction[,2]<-p.adjust(res_reaction[,1],method = 'BH')
  379. diff_reaction<-rownames(res_reaction)[which(res_reaction[,2]<0.05)]
  380. diff_reaction
  381. df<-t(Reactionabundance[rownames(res_reaction)[order(res_reaction[,1],decreasing = F)[1:20]],,drop=F])%>%as.data.frame()
  382. df$label<-meta$disease[match(rownames(df),rownames(meta))]
  383. df1<-pivot_longer(df,
  384. cols = -label,
  385. names_to = "reaction",
  386. values_to = "value"
  387. )
  388. p12<-ggplot(df1, aes(x = value, y = reaction, fill = label)) +
  389. geom_boxplot(outlier.shape = NA) +
  390. theme_minimal() +
  391. scale_x_break(c(0.1,0.99), scales = 0.5,ticklabels=c(0.99,0.995,1))+
  392. scale_fill_manual(values=c('Depression'='#E7B800', 'Healthy'='#00AFBB'))+
  393. scale_x_continuous(labels = function(x) sprintf("%.2f", x))+
  394. ggtitle('D')+
  395. theme(plot.title = element_text(face = 'bold'))
  396. p12
  397. #pdf(file = 'diff_reactions.pdf',width = 8,height = 15)
  398. #pheatmap(exp,show_colnames = F,show_rownames = T,
  399. # annotation_col = label,
  400. # annotation_colors = ann_colors,
  401. # color = col,
  402. # cluster_cols = F)
  403. #dev.off()
  404. ########Wilcoxon signed rank test (Subsystem)
  405. #res_Subsystem<-matrix(0,nrow(Subsystemabundance),2)
  406. #colnames(res_Subsystem)<-c('p.val','fdr')
  407. #rownames(res_Subsystem)<-rownames(Subsystemabundance)
  408. #Subsystemabundance_D<-Subsystemabundance[,match(rownames(meta_D),colnames(Subsystemabundance))]
  409. #Subsystemabundance_H<-Subsystemabundance[,match(rownames(meta_H),colnames(Subsystemabundance))]
  410. #for(i in 1:nrow(Subsystemabundance)){
  411. # print(i)
  412. # res_Subsystem[i,1]<-wilcox.test(Subsystemabundance_D[i,]%>%as.numeric(),Subsystemabundance_H[i,]%>%as.numeric(),paired = T)$p.val
  413. #}
  414. #res_Subsystem[,2]<-p.adjust(res_Subsystem[,1],method = 'BH')
  415. #diff_Subsystem<-rownames(res_Subsystem)[which(res_Subsystem[,1]<0.05)]
  416. #diff_Subsystem
  417. #exp<-Subsystemabundance[diff_Subsystem,]
  418. #col <- c(colorRampPalette('white')(1),
  419. # colorRampPalette(c("white", "#F39B7FFF"))(max(exp)*100))
  420. #p13<-pheatmap(exp,show_colnames = F,show_rownames = T,
  421. # annotation_col = label_row,
  422. # annotation_colors = ann_colors,
  423. # color = col,
  424. # cluster_cols = F)
  425. #p13
  426. ############alpha/beta(reaction)
  427. temp<-colSums(Reactionabundance)%>%as.numeric()
  428. for(i in 1:ncol(Reactionabundance)){
  429. Reactionabundance[,i]<-Reactionabundance[,i]/temp[i]
  430. }
  431. OTU<-phyloseq::otu_table(Reactionabundance,taxa_are_rows = T)
  432. #rownames(meta)<-meta$sampleid
  433. meta1<-phyloseq::sample_data(meta)
  434. physeq<-phyloseq(OTU,meta1)
  435. mpse<-as.MPSE(physeq)
  436. mpse@assays@data@listData[["Abundance"]]<-mpse@assays@data@listData[["Abundance"]]*1e20
  437. mpse %<>%
  438. mp_decostand(.abundance=Abundance)
  439. cols<-c('Depression'='#E7B800', 'Healthy'='#00AFBB')
  440. mpse %<>% mp_cal_alpha(.abundance = Abundance,force = T)
  441. p14 <- mpse %>%
  442. mp_plot_alpha(
  443. .alpha = c(Observe, Shannon,Chao1,Simpson, Pielou),
  444. .group = disease,
  445. ) +
  446. scale_fill_manual(values=cols) +
  447. scale_color_manual(values=cols) +
  448. theme(
  449. legend.position="none",
  450. strip.background = element_rect(colour=NA, fill="grey")
  451. )+
  452. ggtitle('A')+
  453. theme(plot.title = element_text(face = 'bold'))
  454. mpse %>%
  455. mp_anosim(.abundance=Abundance, .group=disease, action="get")
  456. p14
  457. dist_bray <- phyloseq::distance(physeq, method = "bray")
  458. pcoa <- ordinate(physeq, method = "PCoA", distance = dist_bray)
  459. pcoa_df <- data.frame(pcoa$vectors)
  460. pcoa_df$SampleID <- rownames(pcoa_df)
  461. sample_data<-cbind(rownames(meta),meta$disease)%>%as.data.frame()
  462. colnames(sample_data)<-c('SampleID','disease')
  463. rownames(sample_data)<-sample_data$SampleID
  464. pcoa_df <- merge(pcoa_df, sample_data, by.x = "SampleID", by.y = "SampleID")
  465. p15<-ggplot(pcoa_df, aes(x = Axis.1, y = Axis.2, color = disease)) +
  466. geom_point(alpha = 0.4) +
  467. labs(
  468. x = paste0("PCOA1 (", round(pcoa[["values"]][["Eigenvalues"]][1], 2), "%)"),
  469. y = paste0("PCOA2 (", round(pcoa[["values"]][["Eigenvalues"]][2], 2), "%)"),
  470. color = "label"
  471. ) +
  472. theme_minimal()+
  473. theme(legend.position = 'none')+
  474. stat_ellipse(aes(color = disease),type = "t", level = 0.95)+
  475. scale_color_manual(values=c('Depression'='#E7B800', 'Healthy'='#00AFBB'))+
  476. annotate("text", x = -0.1, y = -0.2, label = "ANOSIM R: -0.0003651
  477. P: 0.493")+
  478. ggtitle('B')+
  479. theme(plot.title = element_text(face = 'bold'))
  480. p15
  481. p15<-ggMarginal(p15, type = "boxplot", margins = "both", size = 5, groupColour = TRUE, groupFill = TRUE)
  482. p15
  483. #abundance1<-t(Reactionabundance)%>%as.data.frame()
  484. #env<-cbind(meta$Host.age,meta$BMI)%>%as.data.frame()
  485. #colnames(env)<-c('Age','BMI')
  486. #rownames(env)<-rownames(abundance1)
  487. #cca <- cca(abundance1 ~ ., data = env)
  488. #cca_summary<-summary(cca)
  489. #cca_df<-cca_summary$sites%>%as.data.frame()
  490. #cca_df$disease<-meta$disease[match(rownames(cca_df),rownames(meta))]
  491. #scores <- as.data.frame(scores(cca)$biplot)
  492. #p15<-ggplot(cca_df, aes(x = CCA1, y = CCA2, color = disease)) +
  493. # geom_point(alpha = 0.4) +
  494. # geom_segment(data = scores, aes(x = 0, xend = CCA1*20, y = 0, yend = CCA2*20),
  495. # arrow = arrow(length = unit(0.2, "cm")), color = "red")+
  496. # labs(
  497. # x = paste0("CCA1 (", round(cca$CCA$eig[1] * 100, 2), "%)"),
  498. # y = paste0("CCA2 (", round(cca$CCA$eig[2] * 100, 2), "%)"),
  499. # color = "label"
  500. # ) +
  501. # theme_minimal()+
  502. # theme(legend.position = 'none')+
  503. # stat_ellipse(aes(color = disease),type = "t", level = 0.95)+
  504. # scale_color_manual(values=c('Depression'='#E7B800', 'Healthy'='#00AFBB'))+
  505. # annotate("text", x = -10, y = -20, label = "ANOSIM R: 0.007962
  506. # P: 0.004")+
  507. # ggtitle('B')
  508. #p15<-ggMarginal(p15, type = "boxplot", margins = "both", size = 5, groupColour = TRUE, groupFill = TRUE)
  509. #p15
  510. #########
  511. fc_reaction<-rowMeans(Reactionabundance_D)/rowMeans(Reactionabundance_H)%>%as.data.frame()
  512. res_reaction<-cbind(res_reaction,fc_reaction)
  513. colnames(res_reaction)[3]<-'log2fc'
  514. res_reaction[which(res_reaction$log2fc!=0),3]<-log2(res_reaction[which(res_reaction$log2fc!=0),3])
  515. res_reaction$`-log10p.val`<-(-log10(res_reaction$p.val))
  516. cut_off_log2FC<-1
  517. cut_off_p<-0.05
  518. res_reaction$sig<-ifelse(res_reaction$p.val < cut_off_p &
  519. abs(res_reaction$log2fc) >= cut_off_log2FC,
  520. ifelse(res_reaction$log2fc > cut_off_log2FC ,'Up','Down'),'No significance')
  521. p16<-ggplot(res_reaction, aes(x =log2fc, y=`-log10p.val`,colour = sig)) +
  522. geom_point(alpha=0.65, size=2) +
  523. scale_color_manual(values=c("#546de5", "#d2dae2","#ff4757")) +
  524. geom_vline(xintercept=c(-cut_off_log2FC,cut_off_log2FC),lty=4,col="black",lwd=0.8) +
  525. geom_hline(yintercept = -log10(cut_off_p), lty=4,col="black",lwd=0.8) +
  526. labs(x="log2FC", y="-log10(p.val)") +
  527. theme_bw() +
  528. theme(plot.title = element_text(hjust = 0),
  529. legend.position="right",
  530. legend.title = element_blank()
  531. )+
  532. ggtitle('C')+
  533. theme(plot.title = element_text(face = 'bold'))
  534. p16
  535. ############alpha/beta(Subsystemabundance)
  536. #temp<-colSums(Subsystemabundance)%>%as.numeric()
  537. #for(i in 1:ncol(Subsystemabundance)){
  538. # Subsystemabundance[,i]<-Subsystemabundance[,i]/temp[i]
  539. #}
  540. #OTU<-phyloseq::otu_table(Subsystemabundance,taxa_are_rows = T)
  541. #meta1<-phyloseq::sample_data(meta)
  542. #physeq<-phyloseq(OTU,meta1)
  543. #mpse<-as.MPSE(physeq)
  544. #mpse@assays@data@listData[["Abundance"]]<-mpse@assays@data@listData[["Abundance"]]*1e20
  545. #mpse %<>%
  546. # mp_decostand(.abundance=Abundance)
  547. #cols<-c('Depression'='#E7B800', 'Healthy'='#00AFBB')
  548. #mpse %<>% mp_cal_alpha(.abundance = Abundance,force = T)
  549. #p16 <- mpse %>%
  550. # mp_plot_alpha(
  551. # .alpha = c(Observe, Shannon,Chao1,Simpson, Pielou),
  552. # .group = disease,
  553. # ) +
  554. # scale_fill_manual(values=cols) +
  555. # scale_color_manual(values=cols) +
  556. # theme(
  557. # legend.position="none",
  558. # strip.background = element_rect(colour=NA, fill="grey")
  559. # )
  560. #p16
  561. #dist_bray <- phyloseq::distance(physeq, method = "bray")
  562. #pcoa <- ordinate(physeq, method = "PCoA", distance = dist_bray)
  563. #pcoa_df <- data.frame(pcoa$vectors)
  564. #pcoa_df$SampleID <- rownames(pcoa_df)
  565. #sample_data<-cbind(rownames(meta),meta$disease)%>%as.data.frame()
  566. #colnames(sample_data)<-c('SampleID','disease')
  567. #rownames(sample_data)<-sample_data$SampleID
  568. #pcoa_df <- merge(pcoa_df, sample_data, by.x = "SampleID", by.y = "SampleID")
  569. #p17<-ggplot(pcoa_df, aes(x = Axis.1, y = Axis.2, color = disease)) +
  570. # geom_point(size = 2) +
  571. # labs(x = paste0("PCoA1 (", round(pcoa$values$Relative_eig[1] * 100, 2), "%)"),
  572. # y = paste0("PCoA2 (", round(pcoa$values$Relative_eig[2] * 100, 2), "%)")) +
  573. # theme_minimal() +
  574. # stat_ellipse(aes(color = disease),type = "t", level = 0.95) +
  575. # scale_color_manual(values=c('Depression'='#E7B800', 'Healthy'='#00AFBB'))
  576. #p17<-ggMarginal(p17, type = "boxplot", margins = "both", size = 5, groupColour = TRUE, groupFill = TRUE)
  577. #p17
  578. ###############
  579. #abundance_H<-read.csv('D:/microbiome/micom/202404/paper/data/1-1/healthy_genus.csv',row.names = 1)
  580. #files<-list.files('D:/microbiome/micom/genus_models/genus_models')
  581. #for(i in 1:length(files)){
  582. # files[i]<-substr(files[i],1,nchar(files[i])-4)
  583. #}
  584. #abundance_H<-abundance_H[intersect(rownames(abundance_H),files),]
  585. #sampleids<-list.files('D:/microbiome/micom/202404/paper/result/1-1/FBA_result/healthy')
  586. #for(i in 1:length(sampleids)){
  587. # sampleids[i]<-substr(sampleids[i],1,nchar(sampleids[i])-4)
  588. #}
  589. #for(sampleid in sampleids){
  590. # print(sampleid)
  591. # flux_file<-paste0('D:/microbiome/micom/202404/paper/result/1-1/FBA_result/healthy/',sampleid,'.csv')
  592. # flux<-read.csv(flux_file,row.names = 1)
  593. # flux<-flux[which(flux[,1]!=0),,drop=F]
  594. # temp<-abundance_H[,match(colnames(flux),colnames(abundance_H)),drop=F]
  595. # temp<-temp[which(temp[,1]!=0),,drop=F]
  596. # flux$genus<-0
  597. # flux$metabolite<-0
  598. # for(i in 1:nrow(temp)){
  599. # temp1<-grep(rownames(temp)[i],rownames(flux))
  600. # flux[temp1,2]<-rownames(temp)[i]
  601. # }
  602. # for(i in 1:nrow(flux)){
  603. # if(flux$genus[i]!='0'){
  604. # flux$metabolite[i]<-substr(rownames(flux)[i],nchar(flux$genus[i])+1,nchar(rownames(flux)[i]))
  605. # }else{
  606. # flux$metabolite[i]<-rownames(flux)[i]
  607. # }
  608. # }
  609. # flux$genus[which(flux$genus=='0')]<-'thylakoid'
  610. # metabolite<-unique(flux$metabolite)
  611. # genus<-unique(flux$genus)
  612. # temp3<-matrix(0,length(metabolite),1)%>%as.data.frame()
  613. # rownames(temp3)<-metabolite
  614. # temp_a<-abundance_H[,sampleid,drop=F]
  615. # temp_a<-temp_a/colSums(temp_a)
  616. # for(i in 1:length(genus)){
  617. # if(genus[i]!='thylakoid'){
  618. # flux[which(flux$genus==genus[i]),1]<-flux[which(flux$genus==genus[i]),1]*temp_a[genus[i],]
  619. # }
  620. # }
  621. # for(i in 1:length(metabolite)){
  622. # temp3[i,1]<-flux[which(flux$metabolite==metabolite[i]),1]%>%sum()
  623. # }
  624. # colnames(temp3)<-sampleid
  625. # output_file<-paste0('D:/microbiome/micom/202404/paper/result/1-1//FBA_result_p/healthy/',sampleid,'.csv')
  626. # write.csv(temp3,output_file)
  627. #}
  628. #temp4<-read.csv(paste0('D:/microbiome/micom/202404/paper/result/1-1/FBA_result_p/healthy/',sampleids[1],'.csv'),row.names = 1)
  629. #temp5<-read.csv(paste0('D:/microbiome/micom/202404/paper/result/1-1/FBA_result_p/healthy/',sampleids[2],'.csv'),row.names = 1)
  630. #merged_df <- merge(temp4, temp5, by = "row.names", all = TRUE)
  631. #merged_df[is.na(merged_df)] <- 0
  632. #rownames(merged_df) <- merged_df$Row.names
  633. #merged_df$Row.names <- NULL
  634. #for(i in 3:length(sampleids)){
  635. # print(i)
  636. # temp6<-read.csv(paste0('D:/microbiome/micom/202404/paper/result/1-1/FBA_result_p/healthy/',sampleids[i],'.csv'),row.names = 1)
  637. # merged_df <- merge(merged_df, temp6, by = "row.names", all = TRUE)
  638. # merged_df[is.na(merged_df)] <- 0
  639. # rownames(merged_df) <- merged_df$Row.names
  640. # merged_df$Row.names <- NULL
  641. #}
  642. #write.csv(merged_df,'D:/microbiome/micom/202404/paper/result/1-1/metabolite_H.csv')
  643. ########
  644. #abundance_D<-read.csv('D:/microbiome/micom/202404/paper/data/1-1/depression_genus.csv',row.names = 1)
  645. #files<-list.files('D:/microbiome/micom/genus_models/genus_models')
  646. #for(i in 1:length(files)){
  647. # files[i]<-substr(files[i],1,nchar(files[i])-4)
  648. #}
  649. #abundance_D<-abundance_D[intersect(rownames(abundance_D),files),]
  650. #sampleids<-list.files('D:/microbiome/micom/202404/paper/result/1-1/FBA_result/depression')
  651. #for(i in 1:length(sampleids)){
  652. # sampleids[i]<-substr(sampleids[i],1,nchar(sampleids[i])-4)
  653. #}
  654. #for(sampleid in sampleids){
  655. # print(sampleid)
  656. # flux_file<-paste0('D:/microbiome/micom/202404/paper/result/1-1/FBA_result/depression/',sampleid,'.csv')
  657. # flux<-read.csv(flux_file,row.names = 1)
  658. # flux<-flux[which(flux[,1]!=0),,drop=F]
  659. # temp<-abundance_D[,match(colnames(flux),colnames(abundance_D)),drop=F]
  660. # temp<-temp[which(temp[,1]!=0),,drop=F]
  661. # flux$genus<-0
  662. # flux$metabolite<-0
  663. # for(i in 1:nrow(temp)){
  664. # temp1<-grep(rownames(temp)[i],rownames(flux))
  665. # flux[temp1,2]<-rownames(temp)[i]
  666. # }
  667. # for(i in 1:nrow(flux)){
  668. # if(flux$genus[i]!='0'){
  669. # flux$metabolite[i]<-substr(rownames(flux)[i],nchar(flux$genus[i])+1,nchar(rownames(flux)[i]))
  670. # }else{
  671. # flux$metabolite[i]<-rownames(flux)[i]
  672. # }
  673. # }
  674. # flux$genus[which(flux$genus=='0')]<-'thylakoid'
  675. # metabolite<-unique(flux$metabolite)
  676. # genus<-unique(flux$genus)
  677. # temp3<-matrix(0,length(metabolite),1)%>%as.data.frame()
  678. # rownames(temp3)<-metabolite
  679. # temp_a<-abundance_D[,sampleid,drop=F]
  680. # temp_a<-temp_a/colSums(temp_a)
  681. # for(i in 1:length(genus)){
  682. # if(genus[i]!='thylakoid'){
  683. # flux[which(flux$genus==genus[i]),1]<-flux[which(flux$genus==genus[i]),1]*temp_a[genus[i],]
  684. # }
  685. # }
  686. # for(i in 1:length(metabolite)){
  687. # temp3[i,1]<-flux[which(flux$metabolite==metabolite[i]),1]%>%sum()
  688. # }
  689. # colnames(temp3)<-sampleid
  690. # output_file<-paste0('D:/microbiome/micom/202404/paper/result/1-1//FBA_result_p/depression/',sampleid,'.csv')
  691. # write.csv(temp3,output_file)
  692. #}
  693. #
  694. #temp4<-read.csv(paste0('D:/microbiome/micom/202404/paper/result/1-1/FBA_result_p/depression/',sampleids[1],'.csv'),row.names = 1)
  695. #temp5<-read.csv(paste0('D:/microbiome/micom/202404/paper/result/1-1/FBA_result_p/depression/',sampleids[2],'.csv'),row.names = 1)
  696. #merged_df <- merge(temp4, temp5, by = "row.names", all = TRUE)
  697. #merged_df[is.na(merged_df)] <- 0
  698. #rownames(merged_df) <- merged_df$Row.names
  699. #merged_df$Row.names <- NULL
  700. #for(i in 3:length(sampleids)){
  701. # print(i)
  702. # temp6<-read.csv(paste0('D:/microbiome/micom/202404/paper/result/1-1/FBA_result_p/depression/',sampleids[i],'.csv'),row.names = 1)
  703. # merged_df <- merge(merged_df, temp6, by = "row.names", all = TRUE)
  704. # merged_df[is.na(merged_df)] <- 0
  705. # rownames(merged_df) <- merged_df$Row.names
  706. # merged_df$Row.names <- NULL
  707. #}
  708. #write.csv(merged_df,'D:/microbiome/micom/202404/paper/result/1-1/metabolite_D.csv')
  709. ########
  710. metabolite_D<-read.csv('D:/microbiome/micom/202404/paper/result/1-1/metabolite_D.csv',row.names = 1)
  711. metabolite_H<-read.csv('D:/microbiome/micom/202404/paper/result/1-1/metabolite_H.csv',row.names = 1)
  712. metabolite_D<-metabolite_D[intersect(rownames(metabolite_D),rownames(metabolite_H)),]
  713. metabolite_H<-metabolite_H[intersect(rownames(metabolite_D),rownames(metabolite_H)),]
  714. metabolite_D<-metabolite_D[,match(rownames(meta_D),colnames(metabolite_D))]
  715. metabolite_H<-metabolite_H[,match(rownames(meta_H),colnames(metabolite_H))]
  716. metabolite<-cbind(metabolite_D,metabolite_H)
  717. meta_D<-read.table('D:/microbiome/micom/202404/paper/data/meta_Depression.txt',sep = '\t',header = T)
  718. meta_H<-read.table('D:/microbiome/micom/202404/paper/data/meta_healthy.txt',sep = '\t',header = T)
  719. colnames(meta_H)[8]<-'disease'
  720. colnames(meta_D)[8]<-'disease'
  721. meta_H$disease<-'Healthy'
  722. meta_D$disease<-'Depression'
  723. meta<-rbind(meta_D,meta_H)
  724. res_metabolite<-matrix(0,nrow(metabolite_D),2)%>%as.data.frame()
  725. rownames(res_metabolite)<-rownames(metabolite_D)
  726. colnames(res_metabolite)<-c('p.val','fdr')
  727. for(i in 1:nrow(metabolite_D)){
  728. print(i)
  729. res_metabolite[i,1]<-wilcox.test(metabolite_D[i,]%>%as.numeric(),metabolite_H[i,]%>%as.numeric(),paired = T)$p.val
  730. }
  731. res_metabolite[,2]<-p.adjust(res_metabolite[,1],method = 'BH')
  732. diff_metabolite<-rownames(res_metabolite)[which(res_metabolite[,2]<0.05)]
  733. diff_metabolite
  734. df<-t(metabolite[rownames(res_metabolite)[which(res_metabolite[,2]<0.05)],,drop=F])%>%as.data.frame()
  735. df<-scale(df,scale = T,center = T)%>%as.data.frame()
  736. metabolite_all<-fread('D:/microbiome/micom/202404/paper/data/MetaboliteDatabase.txt')%>%as.data.frame()
  737. compartment<-c()
  738. for(i in 1:ncol(df)){
  739. compartment<-c(compartment,substr(colnames(df)[i],nchar(colnames(df)[i])-2,nchar(colnames(df)[i])))
  740. }
  741. name<-c()
  742. for(i in 1:ncol(df)){
  743. name<-c(name,substr(colnames(df)[i],1,nchar(colnames(df)[i])-3))
  744. }
  745. name1<-metabolite_all[match(name,metabolite_all[,1]),2]
  746. name1<-paste0(name1,compartment)
  747. colnames(df)<-name1
  748. df$label<-meta$disease[match(rownames(df),meta$Run.ID)]
  749. df1<-pivot_longer(df,
  750. cols = -label,
  751. names_to = "metabolite",
  752. values_to = "flux"
  753. )
  754. #p<-list()
  755. #for(i in 1:(ncol(df)-1)){
  756. # print(i)
  757. # temp<-df1[which(df1$metabolite==colnames(df)[i]),]
  758. # p[[i]]<-ggplot(temp, aes(x = label, y = flux, fill = label)) +
  759. # geom_boxplot(outlier.shape = NA) +
  760. # theme_minimal() +
  761. # scale_fill_manual(values=c('Depression'='#E7B800', 'Healthy'='#00AFBB'))+
  762. # coord_cartesian(ylim=c(quantile(temp$flux,0.1),quantile(temp$flux,0.9)+0.2))+
  763. #
  764. # ggtitle(colnames(df)[i])
  765. #}
  766. p18<-ggplot(df1, aes(x = flux, y = metabolite, fill = label)) +
  767. geom_boxplot(outlier.alpha=0.2) +
  768. theme_minimal() +
  769. scale_fill_manual(values=c('Depression'='#E7B800', 'Healthy'='#00AFBB'))+
  770. #xlim(c(-5,5))+
  771. labs(x='flux\n mmol/[gDW h](scaled)',y='')+
  772. theme(axis.text.y = element_text(size = 12),
  773. axis.title.y = element_text(size = 12),
  774. axis.text.x = element_text(size = 12),
  775. axis.title.x = element_text(size = 12),
  776. legend.title = element_blank(),
  777. legend.position = 'right',
  778. plot.title = element_text(hjust = -2.5,face = 'bold'))+
  779. ggtitle('A')
  780. p18
  781. ###############
  782. allmetabolite<-fread('D:/microbiome/micom/202404/paper/data/MetaboliteDatabase.txt')%>%as.data.frame()
  783. diff_metabolite<-strsplit(diff_metabolite,'\\[')%>%unlist
  784. diff_metabolite<-diff_metabolite[-grep('\\]',diff_metabolite)]%>%unique
  785. id<-allmetabolite$V6[match(diff_metabolite,allmetabolite$V1)]
  786. id<-id[id!='']
  787. id
  788. write.table(id,'D:/microbiome/micom/202404/paper/result/1-1/keggid_diff.txt',quote = F,sep = '\t',row.names = F,col.names = F)
  789. stitch<-fread('D:/microbiome/micom/202404/paper/result/1-1/stitch_interactions (1).tsv')%>%as.data.frame()
  790. protein<-c(stitch$`#node1`,
  791. stitch$node2)
  792. names(protein)<-c(stitch$node1_external_id,stitch$node2_external_id)
  793. protein<-protein[grep('ENSP',names(protein))]
  794. protein<-unique(protein)
  795. write.table(protein,'D:/microbiome/micom/202404/paper/result/1-1/protein.txt',quote = F,sep = '\t',row.names = F,col.names = F)
  796. protein<-read.table('D:/microbiome/micom/202404/paper/result/1-1/protein.txt',sep='\t')
  797. gene_list<-protein$V1
  798. library(httr)
  799. library(jsonlite)
  800. library(stringr)
  801. get_uniprot_id <- function(gene) {
  802. url <- paste0("https://rest.uniprot.org/uniprotkb/search?query=gene_exact:",
  803. gene, "+AND+organism_id:9606+AND+reviewed:true&format=json&size=1")
  804. res <- GET(url)
  805. if (res$status_code != 200) return(NA)
  806. data <- fromJSON(content(res, "text", encoding = "UTF-8"))
  807. if (length(data$results) == 0) return(NA)
  808. return(data[["results"]][["primaryAccession"]])
  809. }
  810. get_fasta <- function(uniprot_id) {
  811. url <- paste0("https://rest.uniprot.org/uniprotkb/", uniprot_id, ".fasta")
  812. res <- GET(url)
  813. if (res$status_code != 200) return(NULL)
  814. return(content(res, "text", encoding = "UTF-8"))
  815. }
  816. fasta_all <- ""
  817. for (gene in gene_list) {
  818. cat("Processing:", gene, "\n")
  819. uid <- get_uniprot_id(gene)
  820. if (is.na(uid)) {
  821. warning(paste("No UniProt ID found for", gene))
  822. next
  823. }
  824. fasta_seq <- get_fasta(uid)
  825. if (is.null(fasta_seq)) {
  826. warning(paste("Failed to retrieve FASTA for", uid))
  827. next
  828. }
  829. fasta_all <- paste0(fasta_all, fasta_seq, "\n")
  830. }
  831. # 5. ?????? FASTA ??????
  832. writeLines(fasta_all, "output_sequences.fasta")
  833. ##############
  834. #metabolite_used_D<-metabolite_D[diff_metabolite,]%>%t()%>%as.data.frame()
  835. #metabolite_used_H<-metabolite_H[diff_metabolite,]%>%t()%>%as.data.frame()
  836. #metabolite_used_D$label<-'Depression'
  837. #metabolite_used_H$label<-'Healthy'
  838. #set.seed(123)
  839. #temp<-sample(1:nrow(metabolite_used_D),0.7*nrow(metabolite_used_D))
  840. #train_D<-metabolite_used_D[temp,]
  841. #train_H<-metabolite_used_H[temp,]
  842. #data_train<-rbind(train_D,train_H)
  843. #test_D<-metabolite_used_D[-temp,]
  844. #test_H<-metabolite_used_H[-temp,]
  845. #data_test<-rbind(test_D,test_H)
  846. #train_index <- createFolds(data_train$label, k = 10)
  847. #randomForestFit <- data_train %>% train(label ~ .,
  848. # method = "rf",
  849. # data = .,
  850. # tuneLength = 5,
  851. # trControl = trainControl(method = "cv", indexOut = train_index))
  852. #randomForestFit
  853. #pr_rf<-predict(randomForestFit,data_test,type = 'prob')
  854. #library(pROC)
  855. #roc_curve<-roc(data_test$label,pr_rf[,1])
  856. #plot(roc_curve)
  857. #sp.obj <- ci.sp(roc_curve, sensitivities=seq(0, 1, .01), boot.n=100)
  858. #plot(sp.obj, type="shape", col="#5bd1d7")
  859. #text(0,0.5,paste0("AUC:",round(roc_curve[["auc"]],4)))
  860. #pdf(file = 'diff_metabolite.pdf',width = 10,height = 5)
  861. #ggplot(df1, aes(x = metabolite, y = value, fill = label)) +
  862. # geom_boxplot() +
  863. # theme_minimal() +
  864. # scale_fill_manual(values=c('Depression'='#E7B800', 'Healthy'='#00AFBB'))
  865. #dev.off()
  866. #######34dhphe[e]
  867. #sampleids<-list.files('D:/microbiome/micom/202404/paper/result/1-1/FBA_result/depression')
  868. #for(i in 1:length(sampleids)){
  869. # sampleids[i]<-substr(sampleids[i],1,nchar(sampleids[i])-4)
  870. #}
  871. #temp7<-read.csv(paste0('D:/microbiome/micom/202404/paper/result/1-1/FBA_result/depression/',sampleids[1],'.csv'),row.names = 1)
  872. #temp7<-temp7[grep('34dhphe\\[e\\]',rownames(temp7)),,drop=F]
  873. #temp8<-read.csv(paste0('D:/microbiome/micom/202404/paper/result/1-1/FBA_result/depression/',sampleids[2],'.csv'),row.names = 1)
  874. #temp8<-temp8[grep('34dhphe\\[e\\]',rownames(temp8)),,drop=F]
  875. #
  876. #merged_df <- merge(temp7, temp8, by = "row.names", all = TRUE)
  877. #merged_df[is.na(merged_df)] <- 0
  878. #rownames(merged_df) <- merged_df$Row.names
  879. #merged_df$Row.names <- NULL
  880. #for(i in 3:length(sampleids)){
  881. # print(i)
  882. # temp9<-read.csv(paste0('D:/microbiome/micom/202404/paper/result/1-1/FBA_result/depression/',sampleids[i],'.csv'),row.names = 1)
  883. # temp9<-temp9[grep('34dhphe\\[e\\]',rownames(temp9)),,drop=F]
  884. # merged_df <- merge(merged_df, temp9, by = "row.names", all = TRUE)
  885. # merged_df[is.na(merged_df)] <- 0
  886. # rownames(merged_df) <- merged_df$Row.names
  887. # merged_df$Row.names <- NULL
  888. #}
  889. #write.csv(merged_df,'D:/microbiome/micom/202404/paper/result/1-1/34dhphe[e]_D.csv')
  890. #######
  891. #L_Dopa_D<-read.csv('D:/microbiome/micom/202404/paper/result/1-1/34dhphe[e]_D.csv',row.names = 1)
  892. #L_Dopa_H<-read.csv('D:/microbiome/micom/202404/paper/result/1-1/34dhphe[e]_H.csv',row.names = 1)
  893. #for(i in 1:nrow(L_Dopa_D)){
  894. # rownames(L_Dopa_D)[i]<-substr(rownames(L_Dopa_D)[i],1,nchar(rownames(L_Dopa_D)[i])-10)
  895. #}
  896. #for(i in 1:nrow(L_Dopa_H)){
  897. # rownames(L_Dopa_H)[i]<-substr(rownames(L_Dopa_H)[i],1,nchar(rownames(L_Dopa_H)[i])-10)
  898. #}
  899. #L_Dopa_H<-abs(L_Dopa_H)
  900. #L_Dopa_D<-abs(L_Dopa_D)
  901. #top20_D<-rownames(L_Dopa_D)[order(rowSums(L_Dopa_D),decreasing = T)[1:20]]
  902. #df_D<-rowSums(L_Dopa_D[top20_D,])%>%as.data.frame()
  903. #colnames(df_D)<-'Depression'
  904. #df_D<-rbind(df_D,L_Dopa_D[-order(rowSums(L_Dopa_D),decreasing = T)[1:20],]%>%rowSums()%>%sum())
  905. #rownames(df_D)[21]<-'Others'
  906. #top20_H<-rownames(L_Dopa_H)[order(rowSums(L_Dopa_H),decreasing = T)[1:20]]
  907. #df_H<-rowSums(L_Dopa_H[top20_H,])%>%as.data.frame()
  908. #colnames(df_H)<-'Healthy'
  909. #df_H<-rbind(df_H,L_Dopa_H[-order(rowSums(L_Dopa_H),decreasing = T)[1:20],]%>%rowSums()%>%sum())
  910. #rownames(df_H)[21]<-'Others'
  911. #df<-merge(df_D,df_H,by = "row.names",all = TRUE)
  912. #rownames(df)<-df$Row.names
  913. #df$Row.names<-NULL
  914. #df[is.na(df)]<-0
  915. #df$genus<-rownames(df)
  916. ##temp<-colSums(df[,1:2])%>%as.numeric()
  917. ##df[,1]<-df[,1]/temp[1]
  918. ##df[,2]<-df[,2]/temp[2]
  919. #data_long <- df %>%
  920. # tidyr::gather(key = "group", value = "value", -genus)
  921. #data_alluvial <- data_long %>%
  922. # dplyr::mutate(flow = rep(1:length(unique(data_long$genus)),2))
  923. #desired_order<-c('Healthy','Depression')
  924. #col<-rgb(runif(21), runif(21), runif(21))
  925. #p19<-ggplot(data_alluvial, aes(x = group, y = value, fill = genus, stratum = genus, alluvium = flow)) +
  926. # geom_stratum(width = 0.4) +
  927. # geom_flow(stat = "alluvium", lode.guidance = "forward", aes.flow = "backward") +
  928. # theme_minimal() +
  929. # labs(x = "", y = "L-Dopa[e]") +
  930. # scale_x_discrete(limits=desired_order)+
  931. # ggtitle('B')
  932. #p19
  933. #
  934. #
  935. #tmao_D<-read.csv('D:/microbiome/micom/202404/paper/result/1-1/tmao[e]_D.csv',row.names = 1)
  936. #tmao_H<-read.csv('D:/microbiome/micom/202404/paper/result/1-1/tmao[e]_H.csv',row.names = 1)
  937. #for(i in 1:nrow(tmao_D)){
  938. # rownames(tmao_D)[i]<-substr(rownames(tmao_D)[i],1,nchar(rownames(tmao_D)[i])-7)
  939. #}
  940. #for(i in 1:nrow(tmao_H)){
  941. # rownames(tmao_H)[i]<-substr(rownames(tmao_H)[i],1,nchar(rownames(tmao_H)[i])-7)
  942. #}
  943. #tmao_H<-abs(tmao_H)
  944. #tmao_D<-abs(tmao_D)
  945. #top20_D<-rownames(tmao_D)[order(rowSums(tmao_D),decreasing = T)[1:20]]
  946. #df_D<-rowSums(tmao_D[top20_D,])%>%as.data.frame()
  947. #colnames(df_D)<-'Depression'
  948. #df_D<-rbind(df_D,tmao_D[-order(rowSums(tmao_D),decreasing = T)[1:20],]%>%rowSums()%>%sum())
  949. #rownames(df_D)[21]<-'Others'
  950. #top20_H<-rownames(tmao_H)[order(rowSums(tmao_H),decreasing = T)[1:20]]
  951. #df_H<-rowSums(tmao_H[top20_H,])%>%as.data.frame()
  952. #colnames(df_H)<-'Healthy'
  953. #df_H<-rbind(df_H,tmao_H[-order(rowSums(tmao_H),decreasing = T)[1:20],]%>%rowSums()%>%sum())
  954. #rownames(df_H)[21]<-'Others'
  955. #df<-merge(df_D,df_H,by = "row.names",all = TRUE)
  956. #rownames(df)<-df$Row.names
  957. #df$Row.names<-NULL
  958. #df[is.na(df)]<-0
  959. #df$genus<-rownames(df)
  960. ##temp<-colSums(df[,1:2])%>%as.numeric()
  961. ##df[,1]<-df[,1]/temp[1]
  962. ##df[,2]<-df[,2]/temp[2]
  963. #data_long <- df %>%
  964. # tidyr::gather(key = "group", value = "value", -genus)
  965. #data_alluvial <- data_long %>%
  966. # dplyr::mutate(flow = rep(1:length(unique(data_long$genus)),2))
  967. #desired_order<-c('Healthy','Depression')
  968. #col<-rgb(runif(22), runif(22), runif(22))
  969. #p20<-ggplot(data_alluvial, aes(x = group, y = value, fill = genus, stratum = genus, alluvium = flow)) +
  970. # geom_stratum(width = 0.4) +
  971. # geom_flow(stat = "alluvium", lode.guidance = "forward", aes.flow = "backward") +
  972. # theme_minimal() +
  973. # labs(x = "", y = "Trimethylamine N-oxide[e]") +
  974. # scale_x_discrete(limits=desired_order)+
  975. # ggtitle('C')
  976. #p20
  977. #
  978. #pdf(file = 'D:/microbiome/micom/202404/paper/figures/fig4.pdf',width = 10,height = 7)
  979. #grid.arrange(p18,arrangeGrob(p19, p20,ncol=2), nrow = 2)
  980. #dev.off()
  981. #
  982. ########
  983. #L_Dopa_D<-read.csv('D:/microbiome/micom/202404/paper/result/1-1/34dhphe[e]_D.csv',row.names = 1)
  984. #L_Dopa_H<-read.csv('D:/microbiome/micom/202404/paper/result/1-1/34dhphe[e]_H.csv',row.names = 1)
  985. #L_Dopa <- merge(L_Dopa_D, L_Dopa_H, by = "row.names", all = TRUE)
  986. #L_Dopa[is.na(L_Dopa)] <- 0
  987. #rownames(L_Dopa) <- L_Dopa$Row.names
  988. #L_Dopa$Row.names <- NULL
  989. #for(i in 1:nrow(L_Dopa)){
  990. # rownames(L_Dopa)[i]<-substr(rownames(L_Dopa)[i],1,nchar(rownames(L_Dopa)[i])-10)
  991. #}
  992. #L_Dopa_D<-L_Dopa[,match(colnames(L_Dopa_D),colnames(L_Dopa))]
  993. #L_Dopa_H<-L_Dopa[,match(colnames(L_Dopa_H),colnames(L_Dopa))]
  994. #res_L_Dopa<-matrix(0,nrow(L_Dopa),2)%>%as.data.frame()
  995. #rownames(res_L_Dopa)<-rownames(L_Dopa)
  996. #colnames(res_L_Dopa)<-c('p.val','fdr')
  997. #for(i in 1:nrow(L_Dopa_D)){
  998. # res_L_Dopa[i,1]<-wilcox.test(L_Dopa_D[i,]%>%as.numeric(),L_Dopa_H[i,]%>%as.numeric(),paired = T)$p.val
  999. #}
  1000. #res_L_Dopa[,2]<-p.adjust(res_L_Dopa[,1],method = 'BH')
  1001. #diff_L_Dopa<-rownames(res_L_Dopa)[which(res_L_Dopa[,2]<0.1)]
  1002. #setdiff(diff_L_Dopa,diff)
  1003. ##########
  1004. #tmao_D<-read.csv('D:/microbiome/micom/202404/paper/result/1-1/tmao[e]_D.csv',row.names = 1)
  1005. #tmao_H<-read.csv('D:/microbiome/micom/202404/paper/result/1-1/tmao[e]_H.csv',row.names = 1)
  1006. #tmao <- merge(tmao_D, tmao_H, by = "row.names", all = TRUE)
  1007. #tmao[is.na(tmao)] <- 0
  1008. #rownames(tmao) <- tmao$Row.names
  1009. #tmao$Row.names <- NULL
  1010. #for(i in 1:nrow(tmao)){
  1011. # rownames(tmao)[i]<-substr(rownames(tmao)[i],1,nchar(rownames(tmao)[i])-7)
  1012. #}
  1013. #tmao_D<-tmao[,match(colnames(tmao_D),colnames(tmao))]
  1014. #tmao_H<-tmao[,match(colnames(tmao_H),colnames(tmao))]
  1015. #res_tmao<-matrix(0,nrow(tmao),2)%>%as.data.frame()
  1016. #rownames(res_tmao)<-rownames(tmao)
  1017. #colnames(res_tmao)<-c('p.val','fdr')
  1018. #for(i in 1:nrow(tmao_D)){
  1019. # res_tmao[i,1]<-wilcox.test(tmao_D[i,]%>%as.numeric(),tmao_H[i,]%>%as.numeric(),paired = T)$p.val
  1020. #}
  1021. #res_tmao[,2]<-p.adjust(res_tmao[,1],method = 'BH')
  1022. #diff_tmao<-rownames(res_tmao)[which(res_tmao[,1]<0.05)]
  1023. #setdiff(diff_tmao,diff)
  1024. #######FEA
  1025. reaction_all<-read.csv('D:/microbiome/micom/202404/paper/data/ReactionDatabase.csv',row.names = 1)
  1026. reaction_used<-reaction_all[match(rownames(res_reaction),rownames(reaction_all)),,drop=F]
  1027. diff_reaction_used<-reaction_all[match(diff_reaction,rownames(reaction_all)),,drop=F]
  1028. reaction_used<-na.omit(reaction_used)
  1029. reaction_used$Subsystem[which(reaction_used$Subsystem=='')]<-'Other'
  1030. Subsystem_list <- split(rownames(reaction_used), reaction_used$Subsystem)
  1031. all_reactions<-rownames(reaction_used)
  1032. selected_reactions<-rownames(diff_reaction_used)
  1033. res_FEA <- data.frame(
  1034. Subsystem = character(),
  1035. PValue = numeric(),
  1036. stringsAsFactors = FALSE
  1037. )
  1038. N <- length(all_reactions)
  1039. M <- length(selected_reactions)
  1040. for (Subsystem in names(Subsystem_list)) {
  1041. K <- length(Subsystem_list[[Subsystem]])
  1042. x <- sum(selected_reactions %in% Subsystem_list[[Subsystem]])
  1043. p_value <- phyper(x - 1, K, N - K, M, lower.tail = FALSE)
  1044. res_FEA <- rbind(res_FEA, data.frame(Subsystem = Subsystem, PValue = p_value))
  1045. }
  1046. res_FEA <- res_FEA %>%
  1047. mutate(AdjustedPValue = p.adjust(PValue, method = "BH")) %>%
  1048. arrange(AdjustedPValue)
  1049. res_FEA_sig<-res_FEA[which(res_FEA$AdjustedPValue<0.05),]
  1050. index<-match(res_FEA_sig$Subsystem,names(Subsystem_list))
  1051. ratio<-c()
  1052. for(i in 1:length(index)){
  1053. ratio<-c(ratio,length(which(diff_reaction_used$Subsystem==names(Subsystem_list)[[index[i]]]))/length(Subsystem_list[[index[i]]]))
  1054. }
  1055. res_FEA_sig$neg_log_padj <- -log10(res_FEA_sig$AdjustedPValue)
  1056. res_FEA_sig$ratio<-ratio
  1057. p21<-ggplot(res_FEA_sig, aes(x = ratio, y = Subsystem, size = neg_log_padj, color = AdjustedPValue)) +
  1058. geom_point(alpha = 0.7) +
  1059. scale_size_continuous(name = "-log10(p.adjust)") +
  1060. scale_color_gradient(low = "#4DBBD5FF", high = "#F39B7FFF", name = "fdr") +
  1061. labs(title = "",
  1062. x = "Reaction Ratio",
  1063. y = "Subsystem") +
  1064. theme_minimal()+
  1065. theme(axis.text.y = element_text(size = 12),
  1066. axis.text.x = element_text(size = 12),
  1067. plot.title = element_text(hjust = -1.05,face = 'bold'))+
  1068. guides(color = guide_legend(ncol = 2),
  1069. size = guide_legend(ncol = 2))+
  1070. ggtitle('E')
  1071. p21
  1072. a<-ggplot()+theme_minimal()
  1073. pdf(file = 'D:/microbiome/micom/202404/paper/figures/fig3_12.pdf',width = 16,height = 14)
  1074. grid.arrange(arrangeGrob(p14, p15,nrow=2),arrangeGrob(p16,a,p21,nrow=3,heights = c(0.3,0.4,0.3)), ncol = 2)
  1075. dev.off()
  1076. pdf(file = 'D:/microbiome/micom/202404/paper/figures/p12.pdf',width = 9,height = 6)
  1077. p12
  1078. dev.off()
  1079. ##########
  1080. #metabolite_D<-read.csv('D:/microbiome/micom/202404/paper/result/1-1/metabolite_D.csv',row.names = 1)
  1081. #metabolite_H<-read.csv('D:/microbiome/micom/202404/paper/result/1-1/metabolite_H.csv',row.names = 1)
  1082. #merged_df <- merge(metabolite_D, metabolite_H, by = "row.names", all = TRUE)
  1083. #merged_df[is.na(merged_df)] <- 0
  1084. #rownames(merged_df) <- merged_df$Row.names
  1085. #merged_df$Row.names <- NULL
  1086. #merged_df<-abs(merged_df)
  1087. #OTU<-phyloseq::otu_table(merged_df,taxa_are_rows = T)
  1088. #meta1<-phyloseq::sample_data(meta)
  1089. #physeq<-phyloseq(OTU,meta1)
  1090. #mpse<-as.MPSE(physeq)
  1091. #mpse@assays@data@listData[["Abundance"]]<-mpse@assays@data@listData[["Abundance"]]*1e10
  1092. #mpse %<>%
  1093. # mp_decostand(.abundance=Abundance)
  1094. #cols<-c('Depression'='#E7B800', 'Healthy'='#00AFBB')
  1095. #mpse %<>% mp_cal_alpha(.abundance = Abundance,force = T)
  1096. #p22 <- mpse %>%
  1097. # mp_plot_alpha(
  1098. # .alpha = c(Observe, Shannon,Chao1,Simpson, Pielou),
  1099. # .group = disease,
  1100. # ) +
  1101. # scale_fill_manual(values=cols) +
  1102. # scale_color_manual(values=cols) +
  1103. # theme(
  1104. # legend.position="none",
  1105. # strip.background = element_rect(colour=NA, fill="grey")
  1106. # )+
  1107. # ggtitle('A')
  1108. #p22
  1109. ###########anosim
  1110. #
  1111. ###########pcoa
  1112. #dist_bray <- phyloseq::distance(physeq, method = 'bray')
  1113. #pcoa <- ordinate(physeq, method = "PCoA", distance = dist_bray)
  1114. #pcoa_df <- data.frame(pcoa$vectors)
  1115. #pcoa_df$SampleID <- rownames(pcoa_df)
  1116. #sample_data<-cbind(rownames(meta),meta$disease)%>%as.data.frame()
  1117. #colnames(sample_data)<-c('SampleID','disease')
  1118. #rownames(sample_data)<-sample_data$SampleID
  1119. #pcoa_df <- merge(pcoa_df, sample_data, by.x = "SampleID", by.y = "SampleID")
  1120. #pcoa_df$age<-meta$Host.age[match(pcoa_df$SampleID,rownames(meta))]
  1121. #pcoa_df$BMI<-meta$BMI[match(pcoa_df$SampleID,rownames(meta))]
  1122. #pcoa_df$age[which(pcoa_df$age>=0&pcoa_df$age<=20)]<-'0-20'
  1123. #pcoa_df$age[which(pcoa_df$age>20&pcoa_df$age<=40)]<-'20-40'
  1124. #pcoa_df$age[which(pcoa_df$age>40&pcoa_df$age<=60)]<-'40-60'
  1125. #pcoa_df$age[which(pcoa_df$age>60&pcoa_df$age<=80)]<-'60-80'
  1126. #p23<-ggplot(pcoa_df, aes(x = Axis.1, y = Axis.2, color = disease, shape = age, size = BMI)) +
  1127. # geom_point(alpha = 0.4) +
  1128. # labs(
  1129. # x = paste0("PCoA1 (", round(pcoa$values$Relative_eig[1] * 100, 2), "%)"),
  1130. # y = paste0("PCoA2 (", round(pcoa$values$Relative_eig[2] * 100, 2), "%)"),
  1131. # color = "label",
  1132. # shape = "Age",
  1133. # size = "BMI"
  1134. # ) +
  1135. # theme_minimal()+
  1136. # scale_color_manual(values=c('Depression'='#E7B800', 'Healthy'='#00AFBB'))+
  1137. # annotate("text", x = 0.4, y = -0.4, label = "ANOSIM R: 0.007962
  1138. # P: 0.004")+
  1139. # ggtitle('B')
  1140. #p23<-ggMarginal(p23, type = "boxplot", margins = "both", size = 5, groupColour = TRUE, groupFill = TRUE)
  1141. #p23
  1142. ########
  1143. #a<-res[rownames(res_L_Dopa),]
  1144. #a<-na.omit(a)
  1145. #b<-res_L_Dopa[match(rownames(a),rownames(res_L_Dopa)),]
  1146. #aa<-cbind(a[,1],b[1])
  1147. #colnames(aa)<-c('p.val1','p.val2')
  1148. #write.csv(aa,'D:/microbiome/micom/202404/paper/result/1-1/res_genus-ldopa.csv')
  1149. #
  1150. #a<-res[rownames(res_tmao),]
  1151. #a<-na.omit(a)
  1152. #b<-res_tmao[match(rownames(a),rownames(res_tmao)),]
  1153. #aa<-cbind(a[,1],b[1])
  1154. #colnames(aa)<-c('p.val1','p.val2')
  1155. #write.csv(aa,'D:/microbiome/micom/202404/paper/result/1-1/res_genus-tmao.csv')
  1156. ########
  1157. metabolites<-c('15dap\\[e\\]','34dhphe\\[c\\]','3c3hmp\\[c\\]','5dglcn\\[c\\]','acACP\\[c\\]',
  1158. 'C02528\\[c\\]','cinnm\\[c\\]','cu2\\[e\\]',
  1159. 'gdpddman\\[c\\]','gdpfuc\\[c\\]','idon_L\\[c\\]')
  1160. #for(i in 1:length(metabolites)){
  1161. # print(i)
  1162. # sampleids_D<-list.files('D:/microbiome/micom/202404/paper/result/1-1/FBA_result/depression')
  1163. # for(j in 1:length(sampleids_D)){
  1164. # sampleids_D[j]<-substr(sampleids_D[j],1,nchar(sampleids_D[j])-4)
  1165. # }
  1166. # temp7<-read.csv(paste0('D:/microbiome/micom/202404/paper/result/1-1/FBA_result/depression/',sampleids_D[1],'.csv'),row.names = 1)
  1167. # temp7<-temp7[grep(metabolites[i],rownames(temp7)),,drop=F]
  1168. # temp8<-read.csv(paste0('D:/microbiome/micom/202404/paper/result/1-1/FBA_result/depression/',sampleids_D[2],'.csv'),row.names = 1)
  1169. # temp8<-temp8[grep(metabolites[i],rownames(temp8)),,drop=F]
  1170. #
  1171. # merged_df <- merge(temp7, temp8, by = "row.names", all = TRUE)
  1172. # merged_df[is.na(merged_df)] <- 0
  1173. # rownames(merged_df) <- merged_df$Row.names
  1174. # merged_df$Row.names <- NULL
  1175. # for(k in 3:length(sampleids_D)){
  1176. # temp9<-read.csv(paste0('D:/microbiome/micom/202404/paper/result/1-1/FBA_result/depression/',sampleids_D[k],'.csv'),row.names = 1)
  1177. # temp9<-temp9[grep(metabolites[i],rownames(temp9)),,drop=F]
  1178. # merged_df <- merge(merged_df, temp9, by = "row.names", all = TRUE)
  1179. # merged_df[is.na(merged_df)] <- 0
  1180. # rownames(merged_df) <- merged_df$Row.names
  1181. # merged_df$Row.names <- NULL
  1182. # }
  1183. # write.csv(merged_df,paste0('D:/microbiome/micom/202404/paper/result/1-1/',substr(metabolites[i],1,nchar(metabolites[i])-5),'_D.csv'))
  1184. #
  1185. #
  1186. # sampleids_H<-list.files('D:/microbiome/micom/202404/paper/result/1-1/FBA_result/healthy')
  1187. # for(j1 in 1:length(sampleids_H)){
  1188. # sampleids_H[j1]<-substr(sampleids_H[j1],1,nchar(sampleids_H[j1])-4)
  1189. # }
  1190. # temp7<-read.csv(paste0('D:/microbiome/micom/202404/paper/result/1-1/FBA_result/healthy/',sampleids_H[1],'.csv'),row.names = 1)
  1191. # temp7<-temp7[grep(metabolites[i],rownames(temp7)),,drop=F]
  1192. # temp8<-read.csv(paste0('D:/microbiome/micom/202404/paper/result/1-1/FBA_result/healthy/',sampleids_H[2],'.csv'),row.names = 1)
  1193. # temp8<-temp8[grep(metabolites[i],rownames(temp8)),,drop=F]
  1194. #
  1195. # merged_df <- merge(temp7, temp8, by = "row.names", all = TRUE)
  1196. # merged_df[is.na(merged_df)] <- 0
  1197. # rownames(merged_df) <- merged_df$Row.names
  1198. # merged_df$Row.names <- NULL
  1199. # for(k1 in 3:length(sampleids_H)){
  1200. # temp9<-read.csv(paste0('D:/microbiome/micom/202404/paper/result/1-1/FBA_result/healthy/',sampleids_H[k1],'.csv'),row.names = 1)
  1201. # temp9<-temp9[grep(metabolites[i],rownames(temp9)),,drop=F]
  1202. # merged_df <- merge(merged_df, temp9, by = "row.names", all = TRUE)
  1203. # merged_df[is.na(merged_df)] <- 0
  1204. # rownames(merged_df) <- merged_df$Row.names
  1205. # merged_df$Row.names <- NULL
  1206. # }
  1207. # write.csv(merged_df,paste0('D:/microbiome/micom/202404/paper/result/1-1/',substr(metabolites[i],1,nchar(metabolites[i])-5),'_H.csv'))
  1208. #}
  1209. #########
  1210. i<-1
  1211. temp_D<-read.csv(paste0('D:/microbiome/micom/202404/paper/result/1-1/',substr(metabolites[i],1,nchar(metabolites[i])-5),'_D.csv'),row.names = 1)
  1212. temp_H<-read.csv(paste0('D:/microbiome/micom/202404/paper/result/1-1/',substr(metabolites[i],1,nchar(metabolites[i])-5),'_H.csv'),row.names = 1)
  1213. meta_H<-read.csv('D:/microbiome/micom/202404/paper/data/1-1/meta_H_used.csv',row.names = 1)
  1214. meta_D<-read.csv('D:/microbiome/micom/202404/paper/data/1-1/meta_D_used.csv',row.names = 1)
  1215. colnames(meta_H)[5]<-'disease'
  1216. colnames(meta_D)[5]<-'disease'
  1217. meta_H$disease<-'Healthy'
  1218. meta_D$disease<-'Depression'
  1219. meta<-rbind(meta_D,meta_H)
  1220. for(j in 1:nrow(temp_D)){
  1221. rownames(temp_D)[j]<-substr(rownames(temp_D)[j],1,nchar(rownames(temp_D)[j])-(nchar(metabolites[i])-2))
  1222. }
  1223. for(j in 1:nrow(temp_H)){
  1224. rownames(temp_H)[j]<-substr(rownames(temp_H)[j],1,nchar(rownames(temp_H)[j])-(nchar(metabolites[i])-2))
  1225. }
  1226. temp <- merge(temp_D, temp_H, by = "row.names", all = TRUE)
  1227. temp[is.na(temp)] <- 0
  1228. rownames(temp) <- temp$Row.names
  1229. temp$Row.names <- NULL
  1230. temp<-t(temp)%>%as.data.frame()
  1231. temp<-temp[,-which(colSums(temp)==0)]
  1232. temp$sampleid<-rownames(temp)
  1233. df1<-pivot_longer(temp,
  1234. cols = -sampleid,
  1235. names_to = "genus",
  1236. values_to = "flux"
  1237. )
  1238. df1$metabolite<-substr(metabolites[i],1,nchar(metabolites[i])-5)
  1239. df1$label<-meta$disease[match(df1$sampleid,rownames(meta))]
  1240. for(i in 2:length(metabolites)){
  1241. print(i)
  1242. temp_D<-read.csv(paste0('D:/microbiome/micom/202404/paper/result/1-1/',substr(metabolites[i],1,nchar(metabolites[i])-5),'_D.csv'),row.names = 1)
  1243. temp_H<-read.csv(paste0('D:/microbiome/micom/202404/paper/result/1-1/',substr(metabolites[i],1,nchar(metabolites[i])-5),'_H.csv'),row.names = 1)
  1244. for(j in 1:nrow(temp_D)){
  1245. rownames(temp_D)[j]<-substr(rownames(temp_D)[j],1,nchar(rownames(temp_D)[j])-(nchar(metabolites[i])-2))
  1246. }
  1247. for(j in 1:nrow(temp_H)){
  1248. rownames(temp_H)[j]<-substr(rownames(temp_H)[j],1,nchar(rownames(temp_H)[j])-(nchar(metabolites[i])-2))
  1249. }
  1250. temp <- merge(temp_D, temp_H, by = "row.names", all = TRUE)
  1251. temp[is.na(temp)] <- 0
  1252. rownames(temp) <- temp$Row.names
  1253. temp$Row.names <- NULL
  1254. temp<-t(temp)%>%as.data.frame()
  1255. temp<-temp[,-which(colSums(temp)==0)]
  1256. temp$sampleid<-rownames(temp)
  1257. df3<-pivot_longer(temp,
  1258. cols = -sampleid,
  1259. names_to = "genus",
  1260. values_to = "flux"
  1261. )
  1262. df3$metabolite<-substr(metabolites[i],1,nchar(metabolites[i])-5)
  1263. df3$label<-meta$disease[match(df3$sampleid,rownames(meta))]
  1264. df1<-rbind(df1,df3)
  1265. }
  1266. #pdf(file = 'test.pdf',width = 10,height = 1200)
  1267. #ggplot(df1, aes(x = label, y = flux, fill = label)) +
  1268. # geom_boxplot(outlier.shape = NA) +
  1269. # theme(axis.text.x = element_blank(), # ihxh=4ff,f g->
  1270. # axis.ticks.x = element_blank())+
  1271. # stat_compare_means(comparisons = list(c("Depression", "Healthy")),label.y = 1.5)+
  1272. # scale_fill_manual(values=c('Depression'='#E7B800', 'Healthy'='#00AFBB'))+
  1273. # coord_cartesian(ylim = c(-1, 1))+
  1274. # facet_grid(genus ~ metabolite)
  1275. #dev.off()
  1276. #write.csv(df1,'data.csv')
  1277. #########
  1278. #diff<-read.csv('D:/microbiome/micom/202404/paper/result/1-1/diff_taxon.csv',header = F)%>%as.character()
  1279. library(tidyverse)
  1280. library(RColorBrewer)
  1281. library(effsize)
  1282. #df1$flux<-scale(df1$flux,scale = T,center = T)
  1283. metabolite_used<-unique(df1$metabolite)
  1284. metabolite_all<-fread('D:/microbiome/micom/202404/paper/data/MetaboliteDatabase.txt')%>%as.data.frame()
  1285. metabolite_used1<-metabolite_all[match(metabolite_used,metabolite_all[,1]),2]
  1286. df1$label<-meta$disease[match(df1$sampleid,rownames(meta))]
  1287. meta<-df1[!duplicated(df1$sampleid),c(1,5)]
  1288. res_all<-data.frame()
  1289. for(i in 1:length(metabolite_used)){
  1290. print(i)
  1291. temp_m<-df1[df1$metabolite==metabolite_used[i],]
  1292. con<-meta$sampleid[meta$label=="Healthy"]
  1293. ds<-meta$sampleid[meta$label=="Depression"]
  1294. m1<-df1[df1$metabolite==metabolite_used[i],]
  1295. mat1<-pivot_wider(m1[,1:3],names_from = sampleid,values_from = flux)
  1296. mat1<-column_to_rownames(mat1,var = "genus")
  1297. mat1<-mat1[,meta$sampleid]
  1298. fc1<-rowMeans(mat1[,ds])/rowMeans(mat1[,con])
  1299. p1<-c()
  1300. cliff_delta<-c()
  1301. a<-c()
  1302. for (j in 1:nrow(mat1)) {
  1303. ptmp<-wilcox.test(as.numeric(mat1[j,ds]),as.numeric(mat1[j,con]),paired = T)$p.val
  1304. cliff_delta_temp<-cliff.delta(as.numeric(mat1[j,ds]),as.numeric(mat1[j,con]))$estimate
  1305. p1<-c(p1,ptmp)
  1306. cliff_delta<-c(cliff_delta,cliff_delta_temp)
  1307. }
  1308. res1<-data.frame(genus=rownames(mat1),fc=fc1,p=p1,metabolite=metabolite_used1[i],cliff_delta=cliff_delta,a=rowMeans(mat1[,ds]))
  1309. res_all<-rbind(res_all,res1)
  1310. }
  1311. res_all$sig<-'no'
  1312. res_all$sig[which(res_all$p<0.05)]<-'yes'
  1313. res_all1<-res_all[res_all$sig=='yes',]
  1314. #setdiff(res_all1$genus%>%unique(),diff_top50)
  1315. cu_genus<-res_all1$genus[which(res_all1$metabolite=='Cu2+')]
  1316. res_all2<-res_all1[which(res_all1$metabolite!='Cu2+'),]
  1317. res_cu<-res_all1[which(res_all1$metabolite=='Cu2+'),]
  1318. res_all2$a[res_all2$a>0]<-'export'
  1319. res_all2$a[res_all2$a<0]<-'import'
  1320. colnames(res_all2)[6]<-'direction'
  1321. res_all2 <- res_all2 %>%
  1322. mutate(significance = case_when(
  1323. p < 0.001 ~ "***",
  1324. p < 0.01 ~ "**",
  1325. p < 0.05 ~ "*",
  1326. TRUE ~ ""
  1327. ))
  1328. p22<-ggplot2::ggplot()+
  1329. geom_point(data = res_all2,
  1330. aes(x = genus, y = metabolite,size = fc,color = significance,shape=direction))+
  1331. theme_minimal()+
  1332. #scale_fill_manual(c('*'='red','**'='green'))+
  1333. theme(axis.text.x = element_text(angle = 90,size = 12,face = "italic"),
  1334. axis.title.x = element_text(size = 12),
  1335. axis.text.y = element_text(size = 12),
  1336. legend.position = 'left',
  1337. plot.title = element_text(hjust = -2,face = 'bold'))+
  1338. scale_y_discrete(position = 'right')+
  1339. labs(x='',y='')+
  1340. guides(color = guide_legend(ncol = 1),
  1341. size = guide_legend(ncol = 2)) +
  1342. scale_x_discrete(labels = function(y) {
  1343. ifelse(y %in% setdiff(res_all2$genus%>%unique(),diff),
  1344. paste0("<span style='color:red;'>", y, "</span>"),
  1345. y)
  1346. })+
  1347. scale_shape_manual(values = c("export" = 24, "import" = 25))+
  1348. theme(axis.text.x=element_markdown())+
  1349. ggtitle('B')
  1350. p22
  1351. pdf(file = 'D:/microbiome/micom/202404/paper/figures/fig4.pdf',width = 15,height = 12)
  1352. grid.arrange(p18,p22, ncol = 2)
  1353. dev.off()
  1354. #ggsave("dotp.pdf",height = 15,width = 6,limitsize = FALSE)
  1355. ######
  1356. i<-8
  1357. cu_D<-read.csv(paste0('D:/microbiome/micom/202404/paper/result/1-1/',substr(metabolites[i],1,nchar(metabolites[i])-5),'_D.csv'),row.names = 1)
  1358. cu_H<-read.csv(paste0('D:/microbiome/micom/202404/paper/result/1-1/',substr(metabolites[i],1,nchar(metabolites[i])-5),'_H.csv'),row.names = 1)
  1359. taxon<-read.csv('D:/microbiome/micom/202404/paper/data/taxa.csv')
  1360. for(j in 1:nrow(cu_D)){
  1361. rownames(cu_D)[j]<-substr(rownames(cu_D)[j],1,nchar(rownames(cu_D)[j])-(nchar(metabolites[i])-2))
  1362. }
  1363. for(j in 1:nrow(cu_H)){
  1364. rownames(cu_H)[j]<-substr(rownames(cu_H)[j],1,nchar(rownames(cu_H)[j])-(nchar(metabolites[i])-2))
  1365. }
  1366. cu <- merge(cu_D, cu_H, by = "row.names", all = TRUE)
  1367. cu[is.na(cu)] <- 0
  1368. rownames(cu) <- cu$Row.names
  1369. cu$Row.names <- NULL
  1370. cu_data<-cu
  1371. cu<-t(cu)%>%as.data.frame()
  1372. cu<-cu[,-which(colSums(cu)==0)]
  1373. cu<-abs(cu)
  1374. for(i in 1:nrow(cu)){
  1375. cu[i,]<-cu[i,]/rowSums(cu)[i]
  1376. }
  1377. cu$sampleid<-rownames(cu)
  1378. df<-pivot_longer(cu,
  1379. cols = -sampleid,
  1380. names_to = "genus",
  1381. values_to = "flux"
  1382. )
  1383. df$phyla<-taxon$p__[match(df$genus,taxon$g__)]
  1384. df$flux<-abs(df$flux)
  1385. df$flux<-log2(df$flux+1)
  1386. df$metabolic<-'Cu2+'
  1387. df$group<-meta$disease[match(df$sampleid,rownames(meta))]
  1388. set.seed(1)
  1389. col<-rgb(runif(length(unique(df$phyla))),runif(length(unique(df$phyla))),runif(length(unique(df$phyla))))
  1390. names(col)<-unique(df$phyla)
  1391. ggplot(df, aes(x = sampleid, y = flux, fill = phyla)) +
  1392. geom_bar(stat = "identity") +
  1393. scale_fill_manual(values = col)+
  1394. theme(axis.text.x = element_blank(),
  1395. axis.ticks.x = element_blank(),
  1396. panel.grid = element_blank(),
  1397. strip.text = element_text(size = 12))+
  1398. facet_grid(group~.,scales = "free_x",as.table = F)
  1399. #######
  1400. p_phyla<-list()
  1401. p_genus<-list()
  1402. meta_H<-read.csv('D:/microbiome/micom/202404/paper/data/1-1/meta_H_used.csv',row.names = 1)
  1403. meta_D<-read.csv('D:/microbiome/micom/202404/paper/data/1-1/meta_D_used.csv',row.names = 1)
  1404. colnames(meta_H)[5]<-'disease'
  1405. colnames(meta_D)[5]<-'disease'
  1406. meta_H$disease<-'Healthy'
  1407. meta_D$disease<-'Depression'
  1408. meta<-rbind(meta_D,meta_H)
  1409. i=8
  1410. for(i in 1:length(metabolites)){
  1411. cu_D<-read.csv(paste0('D:/microbiome/micom/202404/paper/result/1-1/',substr(metabolites[i],1,nchar(metabolites[i])-5),'_D.csv'),row.names = 1)
  1412. cu_H<-read.csv(paste0('D:/microbiome/micom/202404/paper/result/1-1/',substr(metabolites[i],1,nchar(metabolites[i])-5),'_H.csv'),row.names = 1)
  1413. cu_D<-cu_D[,-which(colnames(cu_H)=='ERR1090035')]
  1414. cu_H<-cu_H[,-which(colnames(cu_H)=='ERR1090035')]
  1415. taxon<-read.csv('D:/microbiome/micom/202404/paper/data/taxa.csv')
  1416. for(j in 1:nrow(cu_D)){
  1417. rownames(cu_D)[j]<-substr(rownames(cu_D)[j],1,nchar(rownames(cu_D)[j])-(nchar(metabolites[i])-2))
  1418. }
  1419. for(j in 1:nrow(cu_H)){
  1420. rownames(cu_H)[j]<-substr(rownames(cu_H)[j],1,nchar(rownames(cu_H)[j])-(nchar(metabolites[i])-2))
  1421. }
  1422. cu <- merge(cu_D, cu_H, by = "row.names", all = TRUE)
  1423. cu[is.na(cu)] <- 0
  1424. rownames(cu) <- cu$Row.names
  1425. cu$Row.names <- NULL
  1426. cu<-t(cu)%>%as.data.frame()
  1427. cu<-cu[,-which(colSums(cu)==0)]
  1428. cu$sampleid<-rownames(cu)
  1429. df<-pivot_longer(cu,
  1430. cols = -sampleid,
  1431. names_to = "genus",
  1432. values_to = "flux"
  1433. )
  1434. df$phyla<-taxon$p__[match(df$genus,taxon$g__)]
  1435. df$flux<-abs(df$flux)
  1436. df$flux<-log2(df$flux+1)
  1437. df$metabolic<-metabolites[i]
  1438. set.seed(1)
  1439. col<-rgb(runif(length(unique(df$phyla))),runif(length(unique(df$phyla))),runif(length(unique(df$phyla))))
  1440. names(col)<-unique(df$phyla)
  1441. col_genus<-rgb(runif(length(unique(df$genus))),runif(length(unique(df$genus))),runif(length(unique(df$genus))))
  1442. names(col_genus)<-unique(df$genus)
  1443. p_genus[[i]]<-ggplot(df, aes(x = sampleid, y = flux, fill = genus)) +
  1444. geom_bar(stat = "identity") +
  1445. scale_fill_manual(values = col_genus)+
  1446. theme(axis.text.x = element_blank(),
  1447. axis.ticks.x = element_blank(),
  1448. panel.grid = element_blank(),
  1449. strip.text = element_text(size = 12),
  1450. legend.position = 'none')+
  1451. facet_wrap(~ metabolic)
  1452. }
  1453. for(i in 1:length(metabolites)){
  1454. cu_D<-read.csv(paste0('D:/microbiome/micom/202404/paper/result/1-1/',substr(metabolites[i],1,nchar(metabolites[i])-5),'_D.csv'),row.names = 1)
  1455. cu_H<-read.csv(paste0('D:/microbiome/micom/202404/paper/result/1-1/',substr(metabolites[i],1,nchar(metabolites[i])-5),'_H.csv'),row.names = 1)
  1456. cu_D<-cu_D[,-which(colnames(cu_H)=='ERR1090035')]
  1457. cu_H<-cu_H[,-which(colnames(cu_H)=='ERR1090035')]
  1458. taxon<-read.csv('D:/microbiome/micom/202404/paper/data/taxa.csv')
  1459. for(j in 1:nrow(cu_D)){
  1460. rownames(cu_D)[j]<-substr(rownames(cu_D)[j],1,nchar(rownames(cu_D)[j])-(nchar(metabolites[i])-2))
  1461. }
  1462. for(j in 1:nrow(cu_H)){
  1463. rownames(cu_H)[j]<-substr(rownames(cu_H)[j],1,nchar(rownames(cu_H)[j])-(nchar(metabolites[i])-2))
  1464. }
  1465. cu <- merge(cu_D, cu_H, by = "row.names", all = TRUE)
  1466. cu[is.na(cu)] <- 0
  1467. rownames(cu) <- cu$Row.names
  1468. cu$Row.names <- NULL
  1469. cu<-t(cu)%>%as.data.frame()
  1470. cu<-cu[,-which(colSums(cu)==0)]
  1471. cu$sampleid<-rownames(cu)
  1472. df<-pivot_longer(cu,
  1473. cols = -sampleid,
  1474. names_to = "genus",
  1475. values_to = "flux"
  1476. )
  1477. df$phyla<-taxon$p__[match(df$genus,taxon$g__)]
  1478. df$flux<-abs(df$flux)
  1479. df$flux<-log2(df$flux+1)
  1480. df$metabolic<-metabolites[i]
  1481. Firm<-df[which(df$phyla=='Proteobacteria'),]
  1482. Firm_summarized <- Firm %>%
  1483. group_by(sampleid) %>%
  1484. summarize(
  1485. flux = sum(flux),
  1486. )
  1487. set.seed(1)
  1488. col_phyla<-rgb(runif(length(unique(df$phyla))),runif(length(unique(df$phyla))),runif(length(unique(df$phyla))))
  1489. names(col_phyla)<-unique(df$phyla)
  1490. col_phyla<-c(col_phyla,'#E7B800','#00AFBB')
  1491. names(col_phyla)[19:20]<-c('Depression','Healthy')
  1492. col_genus<-rgb(runif(length(unique(df$genus))),runif(length(unique(df$genus))),runif(length(unique(df$genus))))
  1493. names(col_genus)<-unique(df$genus)
  1494. Firm_summarized_D<-Firm_summarized[match(rownames(meta)[which(meta$disease=='Depression')],Firm_summarized$sampleid),]
  1495. Firm_summarized_H<-Firm_summarized[match(rownames(meta)[which(meta$disease=='Healthy')],Firm_summarized$sampleid),]
  1496. levels<-c(Firm_summarized_D$sampleid[order(Firm_summarized_D$flux)],rownames(meta_H)[match(Firm_summarized_D$sampleid[order(Firm_summarized_D$flux)],rownames(meta_D))])
  1497. ##df$sampleid<-factor(df$sampleid,levels = Firm_summarized$sampleid[order(Firm_summarized$flux)])
  1498. df$sampleid<-factor(df$sampleid,levels = levels)
  1499. df$label<-meta$disease[match(df$sampleid,rownames(meta))]
  1500. df<-na.omit(df)
  1501. #tile_data <- df %>%
  1502. # mutate(xmin = as.numeric(factor(sampleid)) - 0.5,
  1503. # xmax = as.numeric(factor(sampleid)) + 0.5,
  1504. # ymin = -1,
  1505. # ymax = -0.5)
  1506. p_phyla[[i]]<-ggplot(df, aes(x = sampleid, y = flux, fill = phyla)) +
  1507. geom_bar(stat = "identity") +
  1508. theme(axis.text.x = element_blank(),
  1509. axis.ticks.x = element_blank(),
  1510. panel.grid = element_blank(),
  1511. strip.text = element_text(size = 12)) +
  1512. scale_fill_manual(values = col_phyla)+
  1513. facet_wrap(~ label, scales = "free_x", ncol = 1)
  1514. }
  1515. p25<-ggplot(df, aes(x = sampleid, y = flux, fill = phyla)) +
  1516. geom_bar(stat = "identity") +
  1517. theme(axis.text.x = element_blank(),
  1518. axis.ticks.x = element_blank(),
  1519. panel.grid = element_blank(),
  1520. strip.text = element_text(size = 12),
  1521. plot.title = element_text(face = 'bold')) +
  1522. scale_fill_manual(values = col_phyla)+
  1523. labs(y='flux\n mmol/[gDW h](scaled)',x='Sample id')+
  1524. facet_wrap(~ label, scales = "free_x", ncol = 1)+
  1525. ggtitle('D')
  1526. p25
  1527. ########
  1528. cu_data$genus<-rownames(cu_data)
  1529. cu_data<-pivot_longer(cu_data,
  1530. cols = -genus,
  1531. names_to = "sampleid",
  1532. values_to = "flux"
  1533. )
  1534. cu_data$label<-meta$label[match(cu_data$sampleid,meta$sampleid)]
  1535. p<-list()
  1536. for(i in 1:length(cu_genus)){
  1537. temp<-cu_data[which(cu_data$genus==cu_genus[i]),]
  1538. p[[i]]<-ggplot(temp, aes(x = label, y = flux, fill = label)) +
  1539. geom_violin() +
  1540. labs( x = "", y = '') +
  1541. facet_wrap(~ genus)+
  1542. stat_compare_means(aes(group = label),label = "p.signif",label.x = 1.5) +
  1543. theme(axis.text.x = element_blank(),
  1544. strip.text = element_text(size=14),
  1545. panel.grid.major = element_blank(),
  1546. panel.grid.minor = element_blank(),
  1547. axis.line.x = element_blank(),
  1548. axis.ticks.x = element_blank(),
  1549. axis.text.y = element_blank(),
  1550. axis.ticks.y = element_blank(),
  1551. plot.margin = unit(c(0.01, 0.01, 0.01, 0.01), "cm"),#top, right, bottom, and left
  1552. legend.position = 'none')+
  1553. scale_fill_manual(values=c('Depression'='#E7B800', 'Healthy'='#00AFBB'))
  1554. }
  1555. pdf(file = 'D:/microbiome/micom/202404/paper/figures/fig6.pdf',width = 36,height = 20)
  1556. grid.arrange(arrangeGrob(p[[1]],p[[2]],p[[3]],p[[4]],p[[5]],p[[6]],p[[7]],p[[8]],p[[9]],ncol=9),
  1557. arrangeGrob(p[[10]],p[[11]],p[[12]],p[[13]],p[[14]],p[[15]],p[[16]],p[[17]],p[[18]],ncol=9),
  1558. arrangeGrob(p[[19]],p[[20]],p[[21]],p[[22]],p[[23]],p[[24]],p[[25]],p[[26]],p[[27]],ncol=9),
  1559. arrangeGrob(p[[28]],p[[29]],p[[30]],p[[31]],p[[32]],p[[33]],p[[34]],p[[35]],p[[36]],ncol=9),
  1560. arrangeGrob(p[[37]],p[[38]],p[[39]],p[[40]],p[[41]],p[[42]],p[[43]],p[[44]],p[[45]],ncol=9),
  1561. nrow = 5)
  1562. dev.off()
  1563. #########
  1564. Firm<-df[which(df$phyla=='Firmicutes'),]
  1565. Firm_summarized <- Firm %>%
  1566. group_by(sampleid) %>%
  1567. summarize(
  1568. flux = sum(flux),
  1569. )
  1570. ########
  1571. i=8
  1572. cu_D<-read.csv(paste0('D:/microbiome/micom/202404/paper/result/1-1/',substr(metabolites[i],1,nchar(metabolites[i])-5),'_D.csv'),row.names = 1)
  1573. cu_H<-read.csv(paste0('D:/microbiome/micom/202404/paper/result/1-1/',substr(metabolites[i],1,nchar(metabolites[i])-5),'_H.csv'),row.names = 1)
  1574. cu <- merge(cu_D, cu_H, by = "row.names", all = TRUE)
  1575. cu[is.na(cu)] <- 0
  1576. rownames(cu) <- cu$Row.names
  1577. cu$Row.names <- NULL
  1578. cu<-t(cu)%>%as.data.frame()
  1579. cu<-cu[,-which(colSums(cu)==0)]
  1580. cu<-abs(cu)
  1581. for(i in 1:ncol(cu)){
  1582. colnames(cu)[i]<-substr(colnames(cu)[i],1,nchar(colnames(cu)[i])-6)
  1583. }
  1584. cu<-cu[,match(cu_genus,colnames(cu))]
  1585. cu$group<-meta$disease[match(rownames(cu),rownames(meta))]
  1586. cu<-cbind(cu[,ncol(cu)],cu[,-ncol(cu)])
  1587. colnames(cu)[1]<-'label'
  1588. cu_D<-cu[which(cu$label=='Depression'),]
  1589. cu_H<-cu[which(cu$label=='Healthy'),]
  1590. temp1<-colMeans(cu_D[,-1])
  1591. temp2<-colMeans(cu_H[,-1])
  1592. temp<-rbind(temp1,temp2)%>%as.data.frame()
  1593. temp$label<-c('Depression','Healthy')
  1594. temp<-cbind(temp[,ncol(temp)],temp[,-ncol(temp)])
  1595. p23<-ggradar(temp,
  1596. grid.line.width = 0,
  1597. axis.label.size= 0,
  1598. group.line.width = 0.2,
  1599. group.point.size = 0.2,
  1600. plot.extent.x.sf = 1.6,
  1601. background.circle.colour = 'white',
  1602. grid.label.size = 0,
  1603. grid.min = 0,
  1604. grid.mid = 0.2,
  1605. grid.max = 0.3,
  1606. group.colours = c('#E7B800','#00AFBB'),
  1607. background.circle.transparency = 0,
  1608. legend.position = 'none')
  1609. p23
  1610. p24<-ggplot()+theme_minimal()
  1611. pdf(file = 'D:/microbiome/micom/202404/paper/figures/fig4_12.pdf',width = 15,height = 18)
  1612. grid.arrange(arrangeGrob(p18,arrangeGrob(p22,p24,nrow = 2),ncol=2),p25,nrow=2)
  1613. dev.off()
  1614. pdf(file = 'D:/microbiome/micom/202404/paper/figures/cu_radar.pdf',width = 7,height = 4)
  1615. p23
  1616. dev.off()
  1617. ###########
  1618. library(mediation)
  1619. data<-rbind(abundance,metabolite)
  1620. data<-t(data)%>%as.data.frame()
  1621. for(i in 1:ncol(data)){
  1622. colnames(data)[i]<-paste0('f_',colnames(data)[i])
  1623. }
  1624. data$group<-meta$disease[match(rownames(data),rownames(meta))]
  1625. data$gender<-meta$Sex[match(rownames(data),rownames(meta))]
  1626. data$age<-meta$Host.age[match(rownames(data),rownames(meta))]
  1627. data$BMI<-meta$BMI[match(rownames(data),rownames(meta))]
  1628. genusnames<-diff
  1629. metabolitenames<-diff_metabolite
  1630. data$group<-(as.factor(data$group)%>%as.numeric()-1)
  1631. colnames(data)<-gsub("\\[|\\]","_",colnames(data))
  1632. f1<-paste0('group','~','f_',genusnames[i])
  1633. f1<-as.formula(f1)
  1634. Y1<-glm(f1,data=data,family = binomial("probit"))
  1635. f2<-paste0('group','~','f_',metabolitenames[j],'+gender+BMI+age')
  1636. f2<-as.formula(f2)
  1637. Y2<-lm(f2,data=data)
  1638. ############
  1639. library(mediation)
  1640. data_a<-abundance[diff,]
  1641. data_m<-metabolite[diff_metabolite,]
  1642. data<-rbind(data_a,data_m)
  1643. data<-t(data)%>%as.data.frame()
  1644. allfeatures<-colnames(data)
  1645. for(i in 1:ncol(data)){
  1646. colnames(data)[i]<-paste0('features',i)
  1647. }
  1648. data$group<-meta$disease[match(rownames(data),rownames(meta))]
  1649. data$gender<-meta$Sex[match(rownames(data),rownames(meta))]
  1650. data$age<-meta$Host.age[match(rownames(data),rownames(meta))]
  1651. data$BMI<-meta$BMI[match(rownames(data),rownames(meta))]
  1652. data$group<-(as.factor(data$group)%>%as.numeric()-1)
  1653. result_mediate<-c()
  1654. for(i in 1:nrow(data_a)){
  1655. print(i)
  1656. for(j in (nrow(data_a)+1):(ncol(data)-4)){
  1657. print(j)
  1658. f1<-paste0('features',j,'~','features',i,'+gender+BMI+age')
  1659. f1<-as.formula(f1)
  1660. Y1<-lm(f1,data=data)
  1661. f2<-paste0('group','~','features',i,'+','features',j,'+gender+BMI+age')
  1662. f2<-as.formula(f2)
  1663. Y2<-glm(f2,data=data,family = binomial("probit"))
  1664. r_causal2 <- mediate(Y1, Y2, treat=paste0('features',i), mediator=paste0('features',j), covariates=c('gender','BMI','age'), boot=TRUE, sims=1000)
  1665. res_temp<-c(paste0('features',i),paste0('features',j),
  1666. r_causal2$d1.p,r_causal2$d0.p,
  1667. r_causal2$d1,r_causal2$d0)
  1668. result_mediate <- append(result_mediate, list(res_temp))
  1669. }
  1670. }
  1671. features1<-c()
  1672. features2<-c()
  1673. res_m<-c()
  1674. for(i in 1:length(result_mediate)){
  1675. if(result_mediate[[i]][3]%>%as.numeric()<0.001&
  1676. result_mediate[[i]][4]%>%as.numeric()<0.001){
  1677. features1<-append(features1,allfeatures[match(result_mediate[[i]][1],colnames(data))])
  1678. features2<-append(features2,allfeatures[match(result_mediate[[i]][2],colnames(data))])
  1679. temp<-c(allfeatures[match(result_mediate[[i]][1],colnames(data))],
  1680. allfeatures[match(result_mediate[[i]][2],colnames(data))],
  1681. result_mediate[[i]][3]%>%as.numeric())%>%t()%>%as.data.frame()
  1682. res_m<-rbind(res_m,temp)
  1683. }
  1684. }
  1685. features1<-c()
  1686. features2<-c()
  1687. for(i in 1:length(result_mediate)){
  1688. if(result_mediate[[i]][3]%>%as.numeric()<0.001&
  1689. result_mediate[[i]][4]%>%as.numeric()<0.001){
  1690. features1<-append(features1,result_mediate[[i]][1])
  1691. features2<-append(features2,result_mediate[[i]][2])
  1692. }
  1693. }
  1694. colnames(res_m)<-c('genus','metabolites','p.val')
  1695. res_m[,3]<-as.numeric(res_m[,3])
  1696. res_m1<-res_m
  1697. #########
  1698. res_m1<-read.csv('D:/microbiome/micom/202404/paper/result/1-1/res_m2.csv',row.names = 1)
  1699. features1<-res_m1$genus
  1700. features2<-res_m1$metabolites
  1701. features1<-match(features1,allfeatures)
  1702. features1<-paste0('features',features1)
  1703. features2<-match(features2,allfeatures)
  1704. features2<-paste0('features',features2)
  1705. result_mediate1<-c()
  1706. for(i in 1:nrow(res_m1)){
  1707. print(i)
  1708. f0<-paste0('group','~',features1[i],'+gender+BMI+age')#d8-d; ei~h*ei+f77fe g4
  1709. f0<-as.formula(f0)
  1710. Y0<-glm(f0,data=data,family = binomial("probit"))
  1711. f1<-paste0(features2[i],'~',features1[i],'+gender+BMI+age')#d8-d; ei~h*ei+f77fe g4
  1712. f1<-as.formula(f1)
  1713. Y1<-lm(f1,data=data)
  1714. print(summary(Y1))
  1715. f2<-paste0('group','~',features1[i],'+',features2[i],'+gender+BMI+age')#e ei~h*ei+d8-d; ei+f77fe g4
  1716. f2<-as.formula(f2)
  1717. Y2<-glm(f2,data=data,family = binomial("probit"))
  1718. r_causal2 <- mediate(Y1, Y2, treat=features1[i], mediator=features2[i], covariates=c('gender','BMI','age'), boot=TRUE, sims=1000)
  1719. model_summary<-summary(r_causal2)
  1720. res_temp<-c(features1[i],
  1721. features2[i],
  1722. r_causal2$d.avg,
  1723. r_causal2$d.avg.p,
  1724. r_causal2$z0.p,
  1725. r_causal2$z1.p,
  1726. r_causal2$z.avg,
  1727. r_causal2$z.avg.p,
  1728. Y1$coefficients[2]%>%as.numeric(),
  1729. Y2$coefficients[2]%>%as.numeric(),
  1730. Y2$coefficients[3]%>%as.numeric(),
  1731. r_causal2$n.avg,
  1732. Y0$coefficients[2]
  1733. )
  1734. result_mediate1 <- append(result_mediate1, list(res_temp))
  1735. }
  1736. features1<-c()
  1737. features2<-c()
  1738. d.avg<-c()
  1739. z.avg<-c()
  1740. coefficientsy1<-c()
  1741. coefficientsy2<-c()
  1742. coefficientsy3<-c()
  1743. d.avg.p<-c()
  1744. z.avg.p<-c()
  1745. n.avg<-c()
  1746. res_m2<-c()
  1747. for(i in 1:length(result_mediate1)){
  1748. if(result_mediate1[[i]][8]%>%as.numeric()<0.01&result_mediate1[[i]][4]%>%as.numeric()<0.01){
  1749. print(i)
  1750. features1<-result_mediate1[[i]][1]
  1751. features2<-result_mediate1[[i]][2]
  1752. d.avg<-result_mediate1[[i]][3]
  1753. z.avg<-result_mediate1[[i]][7]
  1754. d.avg.p<-result_mediate1[[i]][4]
  1755. z.avg.p<-result_mediate1[[i]][8]
  1756. coefficientsy1<-result_mediate1[[i]][9]
  1757. coefficientsy2<-result_mediate1[[i]][10]
  1758. coefficientsy3<-result_mediate1[[i]][13]
  1759. n.avg<-result_mediate1[[i]][12]
  1760. temp<-c(allfeatures[match(features1,colnames(data))],
  1761. allfeatures[match(features2,colnames(data))],
  1762. coefficientsy1,
  1763. coefficientsy2,
  1764. coefficientsy3,
  1765. d.avg.p,
  1766. z.avg.p,
  1767. d.avg,
  1768. z.avg,
  1769. n.avg)%>%t()%>%as.data.frame()
  1770. colnames(temp)<-c('genus','metabolites','coefficients1','coefficients2','coefficients3','d.avg.p','z.avg.p','d.avg','z.avg','n.avg')
  1771. res_m2<-rbind(res_m2,temp)
  1772. }
  1773. }
  1774. res_m2<-res_m2[res_m2$n.avg%>%as.numeric()>0.1,]
  1775. result_mediate2<-c()
  1776. for(i in 1:nrow(res_m1)){
  1777. print(i)
  1778. f1<-paste0('group','~',features1[i],'+gender+BMI+age')
  1779. f1<-as.formula(f1)
  1780. Y1<-glm(f1,data=data,family = binomial("probit"))
  1781. f2<-paste0(features2[i],'~',features1[i],'+','group','+gender+BMI+age')
  1782. f2<-as.formula(f2)
  1783. Y2<-lm(f2,data=data)
  1784. r_causal2 <- mediate(Y1, Y2, treat=features1[i], mediator=features2[i], covariates=c('gender','BMI','age'), boot=TRUE, sims=1000)
  1785. res_temp<-c(features1[i],
  1786. features2[i],
  1787. r_causal2$d.avg,
  1788. r_causal2$d.avg.p,
  1789. r_causal2$z0.p,
  1790. r_causal2$z1.p,
  1791. r_causal2$z.avg,
  1792. r_causal2$z.avg.p,
  1793. #r_causal2$n.avg.p
  1794. Y1$coefficients[2]%>%as.numeric(),
  1795. Y2$coefficients[3]%>%as.numeric())
  1796. result_mediate2 <- append(result_mediate2, list(res_temp))
  1797. }
  1798. res_m3<-c()
  1799. for(i in 1:length(result_mediate2)){
  1800. print(i)
  1801. features1<-result_mediate2[[i]][1]
  1802. features2<-result_mediate2[[i]][2]
  1803. #d.avg<-result_mediate2[[i]][3]
  1804. #z.avg<-result_mediate2[[i]][7]
  1805. d.avg.p<-result_mediate2[[i]][4]
  1806. #z.avg.p<-result_mediate2[[i]][8]
  1807. #coefficientsy1<-result_mediate2[[i]][9]
  1808. #coefficientsy2<-result_mediate2[[i]][10]
  1809. #coefficientsy3<-result_mediate2[[i]][13]
  1810. #n.avg<-result_mediate2[[i]][12]
  1811. temp<-c(allfeatures[match(features1,colnames(data))],
  1812. allfeatures[match(features2,colnames(data))],
  1813. #coefficientsy1,
  1814. #coefficientsy2,
  1815. #coefficientsy3,
  1816. d.avg.p
  1817. #z.avg.p,
  1818. #d.avg,
  1819. #z.avg,
  1820. #n.avg)
  1821. )%>%t()%>%as.data.frame()
  1822. colnames(temp)<-c('genus','metabolites','d.avg.p')
  1823. res_m3<-rbind(res_m3,temp)
  1824. }
  1825. write.csv(res_m2,'D:/microbiome/micom/202404/paper/result/1-1/res_m2.csv')
  1826. #########
  1827. library(igraph)
  1828. library(ggraph)
  1829. metabolite<-unique(res_m1$metabolites)
  1830. nodetype<-data.frame(nodes=c(unique(res_m1$genus),
  1831. unique(res_m1$metabolites),
  1832. "Depression"),
  1833. type=c(rep(c("Independent","Mediator","Dependent"),
  1834. c(length(unique(res_m1$genus)),length(unique(res_m1$metabolites)),1))))
  1835. res_m1<-rbind(res_m1,data.frame(genus=metabolite,metabolites="Depression",p.val=0))
  1836. graph<-graph_from_data_frame(res_m1,vertices = nodetype)
  1837. pos<-nodetype
  1838. pos$x<-c(seq(0.1,0.1*length(unique(res_m1$genus)),0.1),seq(0.2,0.2*length(unique(res_m1$metabolites)),0.2),1.2)
  1839. pos$y<-c(rep(0.8,23),rep(0.5,11),0.2)
  1840. p26<-ggraph(graph,
  1841. layout = "manual",
  1842. x = pos$x,
  1843. y = pos$y) +
  1844. geom_edge_link0(width=1,arrow = arrow(length = unit(3, 'mm'), type = "closed"),alpha=0.5) +
  1845. geom_node_point(aes(fill = type), shape = 21, size = 6,alpha=0.5) +
  1846. #scale_color_manual(values = c("Independent"="orangered4","Mediator"="orchid4","Dependent"="red")) +
  1847. scale_fill_manual(values = c("Independent"="orangered4","Mediator"="orchid4","Dependent"="red")) +
  1848. #scale_edge_colour_gradientn(
  1849. # colors = c("aquamarine3","grey90"),
  1850. # #limits = c(0, 0.28),
  1851. # space = "Lab",
  1852. # na.value = "grey50")+
  1853. guides(fill = guide_legend(ncol = 1))+
  1854. theme_graph(base_family = "sans")+#theme(legend.box = 'horizontal',
  1855. # legend.box.just = 'top')+
  1856. theme(plot.title = element_text(hjust = -0.065,vjust = 0.25),title = element_text(size = 12))+
  1857. geom_node_text(aes(label = pos$nodes), size = 5, vjust = ifelse(1:35 <= 23, -0.5, 1),
  1858. angle = ifelse(1:35 <= 23, 45, 0),hjust = ifelse(1:35 <= 23, 0, 0.5))+
  1859. expand_limits(y=c(0.2,1.2),x=c(0,2.6))
  1860. #p26<-p26+ggtitle('E')
  1861. p26
  1862. pdf(file = 'D:/microbiome/micom/202404/paper/figures/fig4_9.pdf',width = 15,height = 25)
  1863. grid.arrange(arrangeGrob(p18,arrangeGrob(p22,p24,nrow = 2),ncol=2),p25,nrow=2)
  1864. dev.off()
  1865. ################
  1866. meta_H<-read.csv('D:/microbiome/micom/202404/paper/data/1-1/meta_H_used.csv',row.names = 1)
  1867. meta_D<-read.csv('D:/microbiome/micom/202404/paper/data/1-1/meta_D_used.csv',row.names = 1)
  1868. colnames(meta_H)[5]<-'disease'
  1869. colnames(meta_D)[5]<-'disease'
  1870. meta_H$disease<-'Healthy'
  1871. meta_D$disease<-'Depression'
  1872. meta<-rbind(meta_D,meta_H)
  1873. abundance_D<-read.csv('D:/microbiome/micom/202404/paper/data/1-1/depression_genus.csv',row.names = 1)
  1874. abundance_D<-abundance_D[match(rownames(meta_D),colnames(abundance_D))]
  1875. temp<-abundance_D
  1876. temp[temp!=0]<-1
  1877. abundance_D<-abundance_D[which(rowSums(temp)>ncol(abundance_D)*0.1)%>%as.numeric(),]
  1878. abundance_H<-read.csv('D:/microbiome/micom/202404/paper/data/1-1/healthy_genus.csv',row.names = 1)
  1879. abundance_H<-abundance_H[match(rownames(meta_H),colnames(abundance_H))]
  1880. temp<-abundance_H
  1881. temp[temp!=0]<-1
  1882. #abundance_H<-abundance_H[which(rowSums(temp)>ncol(abundance_H)*0.1)%>%as.numeric(),]
  1883. abundance<-merge(abundance_D,abundance_H,by = "row.names",all = TRUE)
  1884. abundance[is.na(abundance)]<-0
  1885. rownames(abundance)<-abundance$Row.names
  1886. abundance$Row.names<-NULL
  1887. abundance_D<-read.csv('D:/microbiome/micom/202404/paper/data/1-1/depression_genus.csv',row.names = 1)
  1888. abundance_D<-abundance_D[match(rownames(meta_D),colnames(abundance_D))]
  1889. temp<-abundance_D
  1890. temp[temp!=0]<-1
  1891. abundance_D<-abundance_D[which(rowSums(temp)>ncol(abundance_D)*0.1)%>%as.numeric(),]
  1892. abundance_H<-read.csv('D:/microbiome/micom/202404/paper/data/1-1/healthy_genus.csv',row.names = 1)
  1893. abundance_H<-abundance_H[match(rownames(meta_H),colnames(abundance_H))]
  1894. temp<-abundance_H
  1895. temp[temp!=0]<-1
  1896. #abundance_H<-abundance_H[which(rowSums(temp)>ncol(abundance_H)*0.1)%>%as.numeric(),]
  1897. abundance<-merge(abundance_D,abundance_H,by = "row.names",all = TRUE)
  1898. abundance[is.na(abundance)]<-0
  1899. rownames(abundance)<-abundance$Row.names
  1900. abundance$Row.names<-NULL
  1901. files <- list.files('D:/microbiome/micom/202404/paper/result/1-1/FBA_result/depression/', full.names = TRUE)
  1902. df_list <- vector("list", length(files))
  1903. for(i in seq_along(files)){
  1904. print(i)
  1905. sampleid <- tools::file_path_sans_ext(basename(files[i]))
  1906. temp_m <- read.csv(files[i], row.names = 1)
  1907. colnames(temp_m) <- 'flux'
  1908. temp_m$sampleid <- sampleid
  1909. temp_m$genus <- NA
  1910. temp_m$metabolite <- NA
  1911. temp_a <- abundance[which(abundance[, sampleid, drop = FALSE] > 0), , drop = FALSE]
  1912. genus <- rownames(temp_a)
  1913. for(gen in genus){
  1914. indices <- grep(gen, rownames(temp_m))
  1915. if(length(indices) > 0){
  1916. temp_m$genus[indices] <- gen
  1917. temp_m$metabolite[indices] <- substr(rownames(temp_m)[indices], nchar(gen) + 1, nchar(rownames(temp_m)[indices]))
  1918. }
  1919. }
  1920. df_list[[i]] <- temp_m
  1921. }
  1922. df_depression <- do.call(rbind, df_list)
  1923. ##########
  1924. taxon<-read.csv('D:/microbiome/micom/202404/paper/data/taxa.csv')
  1925. tsnedata<-read.csv('D:/microbiome/micom/202404/paper/result/1-1/tsne_data.csv',row.names = 1)
  1926. tsnedata$group<-meta$disease[match(tsnedata$sampleid,rownames(meta))]
  1927. #tsnedata<-tsnedata[tsnedata$genus%in%diff,]
  1928. tsnedata$phyla<-taxon$p__[match(tsnedata$genus,taxon$g__)]
  1929. ggplot(tsnedata, aes(x = TSNE.1, y = TSNE.2,color=genus, shape = group)) +
  1930. geom_point(size = 1,alpha=0.6) +
  1931. theme_minimal() +
  1932. theme(legend.position = 'none')
  1933. ##########
  1934. mes<-read.csv('D:/microbiome/micom/202404/paper/result/1-1/mes.csv',row.names = 1)
  1935. mes$group<-meta$disease[match(mes$sampleid,rownames(meta))]
  1936. mes_diff<-mes[mes$metabolite%in%diff_metabolite,]
  1937. mes_diff<-mes_diff[mes_diff$MES>0,]
  1938. mes<-mes[mes$MES>0,]
  1939. ggplot(mes_diff,aes(x=MES,fill=group))+
  1940. geom_density(alpha=0.6)+
  1941. theme_minimal()+
  1942. theme(panel.grid = element_blank(),
  1943. axis.line = element_line(),
  1944. axis.ticks = element_line())+
  1945. scale_fill_manual(values=c('Depression'='#E7B800', 'Healthy'='#00AFBB'))+
  1946. xlim(c(0,6))
  1947. metabolite_D_diff<-metabolite_D[diff_metabolite,]
  1948. metabolite_H_diff<-metabolite_H[diff_metabolite,]
  1949. rowMeans(metabolite_D_diff)/rowMeans(metabolite_H_diff)
  1950. ###########
  1951. all_genus<-unique(tsnedata$genus)
  1952. res_tsne<-c()
  1953. for(i in 1:length(all_genus)){
  1954. print(i)
  1955. tsne1_d<-tsnedata_d$TSNE.1[which(tsnedata_d$genus==all_genus[i])]
  1956. tsne1_h<-tsnedata_h$TSNE.1[which(tsnedata_h$genus==all_genus[i])]
  1957. freq_d<-length(tsne1_d)
  1958. freq_h<-length(tsne1_h)
  1959. if(freq_d>0&freq_h>0){
  1960. print(shapiro.test(tsne1_d)$p.val)
  1961. print(shapiro.test(tsne1_h)$p.val)
  1962. temp<-c(t.test(tsne1_d,tsne1_h)$p.val,freq_d,freq_h)%>%as.data.frame()
  1963. }else{
  1964. temp<-c(NA,freq_d,freq_h)%>%as.data.frame()
  1965. }
  1966. temp<-t(temp)%>%as.data.frame()
  1967. colnames(temp)<-c('p.val','freq_d','freq_h')
  1968. rownames(temp)<-all_genus[i]
  1969. res_tsne<-rbind(res_tsne,temp)
  1970. }
  1971. res_tsne$p.adj<-NA
  1972. res_tsne$p.adj<-p.adjust(res_tsne$p.val,method = 'BH')
  1973. ######
  1974. taxon<-read.csv('D:/microbiome/micom/202404/paper/data/taxa.csv')
  1975. meta_H<-read.csv('D:/microbiome/micom/202404/paper/data/1-1/meta_H_used.csv',row.names = 1)
  1976. meta_D<-read.csv('D:/microbiome/micom/202404/paper/data/1-1/meta_D_used.csv',row.names = 1)
  1977. colnames(meta_H)[5]<-'disease'
  1978. colnames(meta_D)[5]<-'disease'
  1979. meta_H$disease<-'Healthy'
  1980. meta_D$disease<-'Depression'
  1981. meta<-rbind(meta_D,meta_H)
  1982. abundance_D<-read.csv('D:/microbiome/micom/202404/paper/data/1-1/depression_genus.csv',row.names = 1)
  1983. abundance_D<-abundance_D[match(rownames(meta_D),colnames(abundance_D))]
  1984. temp<-abundance_D
  1985. temp[temp!=0]<-1
  1986. #abundance_D<-abundance_D[which(rowSums(temp)>ncol(abundance_D)*0.1)%>%as.numeric(),]
  1987. abundance_H<-read.csv('D:/microbiome/micom/202404/paper/data/1-1/healthy_genus.csv',row.names = 1)
  1988. abundance_H<-abundance_H[match(rownames(meta_H),colnames(abundance_H))]
  1989. temp<-abundance_H
  1990. temp[temp!=0]<-1
  1991. #abundance_H<-abundance_H[which(rowSums(temp)>ncol(abundance_H)*0.1)%>%as.numeric(),]
  1992. abundance<-merge(abundance_D,abundance_H,by = "row.names",all = TRUE)
  1993. abundance[is.na(abundance)]<-0
  1994. rownames(abundance)<-abundance$Row.names
  1995. abundance$Row.names<-NULL
  1996. abundance$phyla<-taxon$p__[match(rownames(abundance),taxon$g__)]
  1997. abundance<-na.omit(abundance)
  1998. Firm<-colSums(abundance[abundance$phyla=='Firmicutes',1:ncol(abundance)-1])
  1999. Bact<-colSums(abundance[abundance$phyla=='Bacteroidetes',1:ncol(abundance)-1])
  2000. F_B<-(Firm/Bact)%>%as.data.frame()
  2001. colnames(F_B)<-'Firmicutes/Bacteroidetes'
  2002. F_B$group<-meta$disease[match(rownames(F_B),rownames(meta))]
  2003. ggplot(F_B,aes(x=group,y=`Firmicutes/Bacteroidetes`,))+
  2004. geom_boxplot()+
  2005. ylim(c(0,10))
  2006. abundance$phyla<-NULL
  2007. shannon<-diversity(t(abundance))%>%as.data.frame()
  2008. simpson<-diversity(t(abundance),index = 'simpson')%>%as.data.frame()
  2009. abundance[abundance<0.01]<-0
  2010. temp<-abundance
  2011. temp$phyla<-NULL
  2012. temp[temp!=0]<-1
  2013. temp1<-rowSums(temp)
  2014. abundance<-abundance[rownames(temp)[temp1>53],]
  2015. abundance1<-rbind(abundance,shannon,simpson)
  2016. a<-colSums(abundance)
  2017. b<-colSums(abundance[,1:ncol(abundance)-1])
  2018. (a-b)%>%sort()%>%plot()
  2019. (a-b)%>%sort()%>%hist()
  2020. #t.test(F_B$`Firmicutes/Bacteroidetes`[F_B$group=='Depression'],
  2021. # F_B$`Firmicutes/Bacteroidetes`[F_B$group=='Healthy'],paired = T)
  2022. #####
  2023. abundance1<-t(abundance1)%>%as.data.frame()
  2024. abundance1$`F/B`<-F_B$`Firmicutes/Bacteroidetes`
  2025. exchange_mat<-read.csv('D:/xy/20250108/exchanges_mat.csv',row.names = 1)
  2026. topo<-read.csv('D:/microbiome/Depression/topolog.csv',row.names = 1)
  2027. id<-intersect(rownames(abundance1),rownames(topo))
  2028. abundance1<-abundance1[id,]
  2029. exchange_mat<-exchange_mat[id,]
  2030. topo<-topo[id,]
  2031. shannon<-shannon[id,]
  2032. simpson<-simpson[id,]
  2033. data<-cbind(#abundance1,
  2034. exchange_mat,
  2035. topo
  2036. )
  2037. #data<-cbind(shannon,simpson,exchange_mat,topo)
  2038. data$group<-meta$disease[match(rownames(data),rownames(meta))]
  2039. data$Disease.name<-NULL
  2040. data_split <- createDataPartition(data$group, p = .70, list = FALSE)
  2041. training_data <- data[ data_split,]
  2042. testing_data <- data[-data_split,]
  2043. train_index <- createFolds(training_data$group, k = 10)
  2044. randomForestFit <- training_data %>% train(group ~ .,
  2045. method = "rf",
  2046. data = .,
  2047. tuneLength = 5,
  2048. trControl = trainControl(method = "cv", indexOut = train_index))
  2049. randomForestFit
  2050. pr_rf<-predict(randomForestFit,testing_data)
  2051. confusionMatrix(pr_rf,reference = testing_data$group%>%as.factor())
  2052. pr_rf<-predict(randomForestFit,testing_data,type = 'prob')
  2053. library(pROC)
  2054. roc_curve<-roc(testing_data$group,pr_rf[,1])
  2055. plot(roc_curve)
  2056. sp.obj <- ci.sp(roc_curve, sensitivities=seq(0, 1, .01), boot.n=100)
  2057. plot(sp.obj, type="shape", col="#5bd1d7")
  2058. text(0,0.5,paste0("AUC:",round(roc_curve[["auc"]],4)))
  2059. varImp(randomForestFit)

code1.R at commit ffa78a5, no license · at the source

Overview

Authors: Yuchen Zhang1, Wenkai Lai2, Meiling Wang1, Shirong Lai2, Qing Liu2, Qi Luo1, Zheng Chen3, Da Zhao4, Ziwei Wang5, Fenglong Yang1,6,7
  1. Department of Bioinformatics, School of Medical Technology and Engineering, Fujian Medical University, Fuzhou, 350122 China
  2. School of Medical Imaging, Fujian Medical University, Fuzhou, 350122 China
  3. College of Life Science, Jiangxi Normal University, Jiangxi, 330000 China
  4. School of Information Engineering, Fujian Key Lab of Agriculture IOT Application, Sanming University, Sanming, Fujian 365004 China
  5. Biomedical Sciences College & Shandong Medicinal Biotechnology Centre, Shandong First Medical University & Shandong Academy of Medical Sciences, Ji’nan, 250117 China
  6. Fujian Key Laboratory of Medical Bioinformatics, Institute of Precision Medicine, Fujian Medical University, Fuzhou, 350122 China
  7. Key Laboratory of Gastrointestinal Cancer, Fujian Medical University, Ministry of Education, Fuzhou, 350122 China
Journal: BMC microbiology, volume 26, issue 1, article 494
Dates: received 30 June 2025; accepted 19 March 2026; published online 14 April 2026
Type: Research article · Language: English
License: CC BY-NC-ND
Identifiers: DOI 10.1186/s12866-026-04991-z · PMID 41975251 · PMCID PMC13203000 · OpenAlex W7154123733
Open access: gold, a free copy (OpenAlex)
Status: code verified
Categories: computational modeling (no new data) (modality), human (organism), depression (population)
Methods: Statistics, Machine learning
Keywords: Depression, Gut-brain axis, Metabolic modeling, Flux balance analysis, Causal mediation analysis, Potential Biomarkers
MeSH: Depression*, Gastrointestinal Microbiome*, Bacteria, Butyrates, Computer Simulation, Humans, Mediation Analysis, Metabolic Networks and Pathways (* major topic)
Topic: Gut microbiota and health (Molecular Biology, Biochemistry, Genetics and Molecular Biology), according to OpenAlex
Funding: Joint Funds for the innovation of Science and Technology, Fujian province (2022J05055); National Natural Science Foundation of China (62102065,62272321); Science and Technology Plan Project of Taizhou (24ywa61); Fujian Medical University Research Foundation of Talented Scholars (XRCZX2022003)
Citations: cited by 1 paper (Europe PMC); 52 references in the paper

Abstract

The abstract is not reproduced here: the paper's license (CC BY-NC-ND) does not allow it. Read it in the paper, at the publisher or on Europe PMC.

Repository

Its files are read in the Code ↔ Paper reader above.

zyc134/Depression

License: none: the authors keep all their rights
State: the link answers, verified on 29 September 2026
Evidence: files inventoried
Commit: ffa78a5d917ce028fc0075615f78eff493a1d632, 4 September 2025
Languages: R (1)
Size: 4 files, 1 script
Software Heritage: not archived
Found in: “Data availability”
Not found: README, license file, CITATION.cff, environment file, tests, continuous integration, documentation
Tools: caret (1 file), data.table (1 file), ggplot2 (1 file), ggpubr (1 file), igraph (1 file), pheatmap (1 file), pROC (1 file), tidyverse (1 file)
Availability: 1 check, the latest on 29 September 2026: the link answers
  • 29 September 2026: the link answers
1 file

The paper's code and data availability statement is in the Data section.

Tracing map

Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.

What the map holds:

  • 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 1 script, each with its path and the digest of its content;
  • no match between paragraphs and code yet;
  • neither the text of the paper nor the code itself.

Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.

Data

No dataset and no data link were found in the paper.

Code and data availability statement

The paper has a code and data availability statement. Its license (CC BY-NC-ND) does not allow reproducing it here; in short, from what the harvester recognized in it:

Read it in the paper: doi.org/10.1186/s12866-026-04991-z.

Versions

The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.

Version 1, 29 September 2026: the first record

Recorded: type, language, journal, volume, issue, pages, dates, 10 authors, 6 keywords, 8 MeSH terms, 4 funders, 48 references.

Cite

This paper

Zhang, Y., Lai, W., Wang, M., Lai, S., Liu, Q., Luo, Q., Chen, Z., Zhao, D., Wang, Z., & Yang, F. (2026). Gut microbial metabolic disorder in depression: insights from computational modeling and mediation analysis. BMC microbiology, 26(1), 494. https://doi.org/10.1186/s12866-026-04991-z

BibTeX

@article{zhang2026gut,
author = {Zhang, Yuchen and Lai, Wenkai and Wang, Meiling and Lai, Shirong and Liu, Qing and Luo, Qi and Chen, Zheng and Zhao, Da and Wang, Ziwei and Yang, Fenglong},
title = {{Gut microbial metabolic disorder in depression: insights from computational modeling and mediation analysis}},
journal = {BMC microbiology},
year = {2026},
month = apr,
volume = {26},
number = {1},
pages = {494},
publisher = {BMC},
issn = {1471-2180},
doi = {10.1186/s12866-026-04991-z},
url = {https://doi.org/10.1186/s12866-026-04991-z},
pmid = {41975251},
pmcid = {PMC13203000}
}

RIS

TY - JOUR
AU - Zhang, Yuchen
AU - Lai, Wenkai
AU - Wang, Meiling
AU - Lai, Shirong
AU - Liu, Qing
AU - Luo, Qi
AU - Chen, Zheng
AU - Zhao, Da
AU - Wang, Ziwei
AU - Yang, Fenglong
TI - Gut microbial metabolic disorder in depression: insights from computational modeling and mediation analysis
T2 - BMC microbiology
J2 - BMC Microbiol
PY - 2026
DA - 2026/04/14
VL - 26
IS - 1
SP - 494
SN - 1471-2180
PB - BMC
DO - 10.1186/s12866-026-04991-z
UR - https://doi.org/10.1186/s12866-026-04991-z
LA - en
ER -

CSL-JSON

{
"id": "10.1186/s12866-026-04991-z",
"type": "article-journal",
"title": "Gut microbial metabolic disorder in depression: insights from computational modeling and mediation analysis",
"container-title": "BMC microbiology",
"author": [
{
"family": "Zhang",
"given": "Yuchen"
},
{
"family": "Lai",
"given": "Wenkai"
},
{
"family": "Wang",
"given": "Meiling"
},
{
"family": "Lai",
"given": "Shirong"
},
{
"family": "Liu",
"given": "Qing"
},
{
"family": "Luo",
"given": "Qi"
},
{
"family": "Chen",
"given": "Zheng"
},
{
"family": "Zhao",
"given": "Da"
},
{
"family": "Wang",
"given": "Ziwei"
},
{
"family": "Yang",
"given": "Fenglong"
}
],
"container-title-short": "BMC Microbiol",
"volume": "26",
"issue": "1",
"page": "494",
"DOI": "10.1186/s12866-026-04991-z",
"PMID": "41975251",
"PMCID": "PMC13203000",
"ISSN": "1471-2180",
"publisher": "BMC",
"URL": "https://doi.org/10.1186/s12866-026-04991-z",
"language": "en",
"issued": {
"date-parts": [
[
2026,
4,
14
]
]
}
}

The tracing map gets a citation of its own once an author has validated it and it has a DOI.

Similar papers

The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.

[1] doi:10.3390/ijms27104466 [code]
Uncovering the Key Circuit FOSL2/FOS/EGR3/EGR1, Contributing to the Hyperexcitability of Excitatory Neurons in the Epileptic Temporal Cortex and Hippocampus.
Journal: International journal of molecular sciences
In common: pROC, caret, igraph, 5 other tools
[2] doi:10.1038/s41467-026-77170-3 [code]
DNA methylation profiling identifies long-range epigenetic silencing of clustered protocadherins as a key determinant of meningioma progression.
Journal: Nature communications
In common: pROC, caret, pheatmap, 4 other tools
[3] doi:10.3390/ijms27156925 [code]
XGBoost-SHAP Interpretable Modeling Identifies and Validates an Eight-Gene Biomarker for Hepatic Encephalopathy Risk Prediction in Cirrhosis.
Journal: International journal of molecular sciences
In common: pROC, caret, pheatmap, 4 other tools
[4] doi:10.7717/peerj.21426 [code]
Integrated transcriptomic identification and validation reveal key autophagy-associated biomarkers in sleep deprivation.
Journal: PeerJ
In common: pROC, caret, pheatmap, 4 other tools
[5] doi:10.1093/bioinformatics/btag592 [code]
Network-based stratification of allele-specific expression reveals patient subgroups in Huntington's disease.
Journal: Bioinformatics (Oxford, England)
In common: pROC, igraph, pheatmap, 4 other tools
[6] doi:10.1016/j.xcrm.2026.102766 [code]
A longitudinal single-cell and spatial multiomic atlas of pediatric high-grade glioma.
Journal: Cell reports. Medicine
In common: pROC, igraph, pheatmap, 4 other tools
[7] doi:10.1016/j.isci.2026.115657 [code]
Integration of machine learning to develop a disulfidptosis model for predicting glioma prognosis, immunotherapy response, and drug.
Journal: iScience
In common: pROC, igraph, pheatmap, 4 other tools
[8] doi:10.1038/s42003-026-10957-8 [code]
Brain defence by the extracellular matrix protein Cochlin.
Journal: Communications biology
In common: caret, igraph, pheatmap, 4 other tools
[9] doi:10.1038/s41586-026-10735-w [code]
Distributed control circuits across a brain-and-cord connectome.
Journal: Nature
In common: caret, igraph, pheatmap, 4 other tools
[10] doi:10.1038/s41597-026-06971-4 [code]
Human neuronal differentiation under Aβ exposure: a single-cell transcriptomic and epigenomic dataset.
Journal: Scientific data
In common: pROC, caret, igraph, 3 other tools

Contribute

The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.

Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.

Request its removal

To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).

Discussion, reproductions, activity

Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.

Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.

Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.