OSCR

Spatiotemporal brain transcriptomics reveal risk gene hot-spots in major neuropsychiatric disorders.

Code ↔ Paper

15 matches between paragraphs of the paper and lines of its authors' code, computed by the harvester (lexical-v1). Click a colored paragraph or line to see its counterpart.

The 15 matches
  1. [1] § Results › Spatial enrichment patterns of neuropsychiatric risk gene sets implicate disease-relevant brain regions and circuits ↔ R code for data analysis.R, lines 113–194 · score 0.92 · parietal cortex, ganglionic eminence, occipital cortex, frontal cortex, brain stem, temporal cortex
  2. [2] § Methods › Function analysis of WGCNA module genes ↔ R code for data analysis.R, lines 458–545 · score 0.83 · enriched GO terms, clusterProfiler, compareCluster, KEGG pathway, cutoff, Module genes
  3. [3] § Methods › Weighted gene co-expression network (WGCNA) analysis ↔ R code for data analysis.R, lines 188–248 · score 0.81 · soft threshold power, blockwiseModules, cut height, Pearson, TOM, network
  4. [4] § Methods › Weighted gene co-expression network (WGCNA) analysis ↔ R code for data analysis.R, lines 741–801 · score 0.81 · soft threshold power, blockwiseModules, cut height, Pearson, TOM, network
  5. [5] § Methods › Statistics and reproducibility ↔ R code for data analysis.R, lines 2–62 · score 0.80 · Mann Whitney, ComplexHeatmap, remaining genes, selected gene, expression matrix, Rank Biserial
  6. [6] § Methods › Statistics and reproducibility ↔ R code for data analysis.R, lines 2–62 · score 0.80 · Mann Whitney, ComplexHeatmap, remaining genes, selected gene, expression matrix, Rank Biserial
  7. [7] § Results › Spatial enrichment patterns of neuropsychiatric risk gene sets implicate disease-relevant brain regions and circuits ↔ R code for data analysis.R, lines 64–111 · score 0.80 · parietal cortex, ganglionic eminence, occipital cortex, frontal cortex, brain stem, temporal cortex
  8. [8] § Methods › Function analysis of WGCNA module genes ↔ R code for data analysis.R, lines 1044–1105 · score 0.75 · clusterProfiler, compareCluster, KEGG pathway, cutoff, Module genes, enriched
  9. [9] § Results › Developmental expression enrichment patterns of risk gene sets align with the peak age of onset across major neuropsychiatric disorders ↔ R code for data analysis.R, lines 64–111 · score 0.70 · peak ages, early infancy, middle adulthood, early prenatal, enrichment patterns, onset
  10. [10] § Results › Developmental expression enrichment patterns of risk gene sets align with the peak age of onset across major neuropsychiatric disorders ↔ R code for data analysis.R, lines 64–111 · score 0.70 · peak ages, early infancy, middle adulthood, early prenatal, enrichment patterns, onset
  11. [11] § Methods › Risk gene sets expression enrichment analysis in the brain spatiotemporal transcriptome › Curation of genome-wide risk genes for the 15 traits ↔ R code for data analysis.R, lines 113–186 · score 0.68 · SZes, panic disorder, SZgw, date, ANO, TS
  12. [12] § Methods › Risk gene sets expression enrichment analysis in the brain spatiotemporal transcriptome › Curation of genome-wide risk genes for the 15 traits ↔ R code for data analysis.R, lines 113–194 · score 0.66 · SZes, panic disorder, SZgw, ANO, TS, neuroticism
  13. [13] § Results › Assessing the biological relevance of risk gene expression patterns using ENIGMA brain morphometry ↔ R code for data analysis.R, lines 683–739 · score 0.57 · d_icv, amyg, caud, hippo, pal, thal
  14. [14] § Results › Spatiotemporal enrichment patterns of risk gene sets differentiate neuropsychiatric disorder subgroups ↔ R code for data analysis.R, lines 197–235 · score 0.57 · variance explained, Principal component, Scree, rank biserial, Bar, PC
  15. [15] § Results › Spatiotemporal enrichment patterns of risk gene sets differentiate neuropsychiatric disorder subgroups ↔ R code for data analysis.R, lines 237–262 · score 0.51 · panic disorder, SZgw, PC4, PC1, epilepsy, PD

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 · 1,145 lines · 41 KB · CC-BY-4.0 · 9 matches

  1. ##Mann-Whitney U test
  2. # install.packages("ggcorrplot")
  3. # BiocManager::install("ComplexHeatmap")
  4. library(gmodels)
  5. library("data.table")
  6. library("dplyr")
  7. library(ggplot2)
  8. library(ggpubr)
  9. library(effectsize)
  10. library("ComplexHeatmap")
  11. # Mann-Whitney U test based on RPKM values ------------------------------------
  12. riskgene<-read.table("riskgenes.CSV",header=TRUE,sep=",",row.names=1)
  13. str(riskgene)
  14. braingene<-read.table("expression_matrix-ave.CSV",header=TRUE,sep=",",row.names=1)
  15. str(braingene)
  16. dim(braingene)
  17. gene <- rownames(braingene)
  18. length(gene)
  19. P_values <- data.frame()
  20. W<-data.frame()
  21. r_rank_biserial<-data.frame()
  22. for (i in 1:length(riskgene))
  23. {
  24. interesting_genes <- c(riskgene[, i])
  25. interesting_genes <- interesting_genes[interesting_genes[] != ""]
  26. selected_genes <- braingene[interesting_genes,]
  27. dim(selected_genes)
  28. selected_genes <- na.omit(selected_genes)
  29. dim(selected_genes)
  30. remaining_genes <-
  31. braingene[!rownames(braingene) %in% interesting_genes,]
  32. dim(remaining_genes)
  33. remaining_genes
  34. for (j in 1:524) {
  35. mwu_test_result <-
  36. wilcox.test(selected_genes[, j],
  37. remaining_genes[, j],
  38. alternative = "greater",
  39. verbose = FALSE)
  40. EFS_result <-
  41. cliffs_delta(
  42. selected_genes[, j],
  43. remaining_genes[, j],
  44. mu = 0,
  45. alternative = "greater",
  46. verbose = F
  47. )
  48. P_values[j, i] <- mwu_test_result$p.value
  49. r_rank_biserial[j, i] <- EFS_result$r_rank_biserial
  50. }
  51. }
  52. rownames(P_values)<-c(colnames(braingene))
  53. rownames(P_values)
  54. colnames(P_values)<-c(colnames(riskgene))
  55. colnames(P_values)
  56. rownames(r_rank_biserial)<-c(colnames(braingene))
  57. colnames(r_rank_biserial)<-c(colnames(riskgene))
  58. write.csv(P_values, file="P_Value.CSV", quote = F,row.names = T)
  59. write.csv(r_rank_biserial,file="r_rank_biserial.CSV",
  60. quote=F,row.names = T)
  61. ##complexheatmap of risk gene enrichment patterns
  62. brain<-read.table("brian regions.CSV",header=TRUE,sep=",")
  63. head(brain)
  64. brain_order<-brain[order(brain$column_num),]
  65. head(brain_order)
  66. data1<-read.table("r_rank_biserial.CSV",header=TRUE,sep=",",row.names=1)
  67. data1<-data1[brain_order$sample,]
  68. head(data1)
  69. data2<- t(data1)
  70. dim(data2)
  71. data2 <- as.matrix(data2)
  72. str(data2)
  73. row_anno <-read.table("disease_Annotation_peak age onset.CSV",header=TRUE,sep=",",row.names=1,encoding = "UTF-8")
  74. dim(row_anno)
  75. str(row_anno)
  76. row_anno$peak_age_onset<-factor(row_anno$peak_age_onset,
  77. levels = c("Y4.5","Y5.5","Y8","Y9.5","Y15.5","Y19.5","Y12.8_Y24.9","Y20.5","Childhood_Y60","Y85","Y87"))
  78. col_anno <-read.table("brain_region_Annotation.CSV",header=TRUE,sep=",",row.names=1)
  79. str(col_anno)
  80. col_anno<-col_anno[,-c(2:3)]
  81. col_anno<-col_anno[brain_order$sample,]
  82. head(col_anno)
  83. col_anno$structure<-factor(col_anno$structure,
  84. levels = c("frontal_cortex","parietal_cortex","temporal_cortex","occipital_cortex","ganglionic_eminence","striatum","thalamus","limbic_system","brain_stem","cerebellum"))
  85. col_anno$dev_stage<-factor(col_anno$dev_stage,
  86. levels = c("Early_prenatal","Early_mid_prenatal","Late_mid_prenatal","Late_prenatal","Early_infancy","Late_infancy","Early_childhood","Late_childhood","Adolescence","Young_adulthood","Middle_adulthood" ))
  87. ann_colors = list(peak_age_onset = c(Y4.5 = "#CCFFCC",Y5.5="#CCFF00", Y8="#00CC99", Y9.5="#00CC00", Y15.5="#FF99FF", Y19.5="#FF33FF",
  88. Y12.8_Y24.9="#00FFFF" , Y20.5="#33CCCC", Childhood_Y60="#3366CC", Y85="#333399", Y87="#111111"),
  89. dev_stage=c(Early_prenatal="#000000",Early_mid_prenatal="#333333",Late_mid_prenatal="#666666",Late_prenatal="#888888",Early_infancy="#DDDDDD", Late_infancy="#EEEEEE", Early_childhood="#00FFCC",Late_childhood="#00CC99",Adolescence="#FFCCFF",Young_adulthood="#33CCCC",Middle_adulthood="#333399"),
  90. structure= c(frontal_cortex="#FFFF00",parietal_cortex="pink",temporal_cortex="#CCFF00",occipital_cortex="orange" , limbic_system = "#CC0000", striatum = "#00CC66", thalamus = "#00FF00",brain_stem="#CC00FF", ganglionic_eminence="blue", cerebellum = "#330066")
  91. )
  92. pdf(file = "complexheatmap-r_rank_biserial.pdf", width = 12, height = 8)
  93. pheatmap(data2, scale = "row",show_rownames = T,
  94. clustering_method="ward.D2",
  95. show_colnames = F,
  96. cluster_cols=F,cluster_rows=F,drop_levels=T,
  97. col = colorRampPalette(c("blue","white","red"))(100),
  98. annotation_col = col_anno,
  99. annotation_row = row_anno,
  100. annotation_colors = ann_colors,
  101. heatmap_legend_param = list(title = "normalized r") ,
  102. annotation_names_row = T,
  103. annotation_names_col = T ,
  104. column_title = NULL
  105. )
  106. dev.off()
  107. # # FC-other structures(without BS),pairwise t-test -----------------------------
  108. library(dplyr)
  109. library(ggplot2)
  110. library(rstatix)
  111. library(ggpubr)
  112. setwd("Major 15 disorder merged gene-RPKM-ave")
  113. data1<-read.csv("combine_r_rank_biserial-11structure-scaled-line.CSV",header=TRUE,sep=",")
  114. str(data1)
  115. data1$structure <- factor(data1$structure,
  116. levels = c("frontal_cortex", "parietal_cortex", "temporal_cortex", "occipital_cortex",
  117. "ganglionic_eminence","striatum","thalamus","amygdala","brain_stem","hippocampus","cerebellum"))
  118. data1$disorder <- factor(data1$disorder,
  119. levels = c("Neuroticism","BIP","TS", "SZes","IQ", "ASD","ADHD","ANO","PanicDisorder", "OCD","AD", "Epilepsy", "PD","MDD", "SZgw"))
  120. data1 <- data1[data1$structure != "brain_stem", ]
  121. df_summary <- data1 %>%
  122. group_by(disorder, structure) %>%
  123. summarise(
  124. mean_value = mean(r, na.rm = TRUE),
  125. sd_value = sd(r, na.rm = TRUE),
  126. se_value = sd(r, na.rm = TRUE) / sqrt(n()),
  127. n = n(),
  128. .groups =NULL
  129. )
  130. df_summary
  131. stat_res <- data1 %>%
  132. group_by(disorder) %>%
  133. pairwise_t_test(
  134. r ~ structure,
  135. ref.group = "frontal_cortex",
  136. p.adjust.method = "fdr"
  137. )
  138. stat_res
  139. stat_frontal <- stat_res %>%
  140. filter(group1 == "frontal_cortex")
  141. stat_frontal <- stat_frontal %>%
  142. mutate(stars = case_when(
  143. p.adj < 0.001 ~ "***",
  144. p.adj < 0.01 ~ "**",
  145. p.adj < 0.05 ~ "*",
  146. TRUE ~ ""
  147. ))
  148. write.csv(stat_frontal,file="stat_frontal_noBS.CSV", quote = F,row.names = F)
  149. plot_data <- df_summary %>%
  150. left_join(stat_frontal,
  151. by = c("structure" = "group2", "disorder")) %>%
  152. mutate(y_pos = mean_value + se_value + 0.02)
  153. ggplot() +
  154. # dot
  155. geom_jitter(data = data1,
  156. aes(x = structure, y = r),
  157. width = 0.15, height = 0.3,
  158. size = 0.1, alpha = 0.3, color = "black") +
  159. # bar
  160. geom_col(data = df_summary,
  161. aes(x = structure, y = mean_value, fill = structure),
  162. width = 0.7, alpha = 0.9) +
  163. # SE
  164. geom_errorbar(data = df_summary,
  165. aes(x = structure,
  166. ymin = mean_value - se_value,
  167. ymax = mean_value + se_value),
  168. width = 0.25, linewidth = 0.2) +
  169. # sig
  170. geom_text(data = plot_data,
  171. aes(x = structure, y = y_pos, label = stars),
  172. size = 3, color = "red", vjust = 0.3) +
  173. facet_grid(rows = vars(disorder), scales = "free_y") +
  174. scale_y_continuous(n.breaks =3) +
  175. theme_bw() +
  176. theme(
  177. strip.text.y = element_text(angle = 0, size =7),
  178. axis.text.x = element_text(angle = 30, size = 8,hjust = 0.9),
  179. axis.text.y = element_text(size = 5),
  180. ) +
  181. labs(y = "Mean ± SE")
  182. # ##PCA analysis -----------------------------------------------------------------
  183. library(ggplot2)
  184. library(ggrepel)
  185. data1<-read.table("r_rank_biserial_rpkm-ave.CSV",header=TRUE,sep=",",row.names=1)
  186. head(data1)
  187. data2<- scale(data1)
  188. data2<- t(data2)
  189. disor<-rownames(data2)
  190. disor
  191. mean(data2[,3])
  192. pca_result <- prcomp(data2,center=T,scale=T)
  193. pca_result
  194. summary(pca_result)
  195. pca_result$x
  196. screeplot(pca_result)
  197. plot(pca_result, type = "barplot")
  198. pca_result$x
  199. rownames(pca_result$x)
  200. var_explained <- pca_result$sdev^2 / sum(pca_result$sdev^2)
  201. df_var <- data.frame(
  202. PC = paste0("PC", 1:length(var_explained)),
  203. Variance = var_explained
  204. )
  205. var_explained
  206. df_var$PC <- factor(df_var$PC, levels = df_var$PC[order(df_var$Variance, decreasing = TRUE)])
  207. # Scree plot
  208. ggplot(df_var, aes(x = PC, y = Variance)) +
  209. geom_bar(stat = "identity") +
  210. geom_line(aes(group = 1)) +
  211. geom_point(size = 2) +
  212. ylab("Proportion of Variance Explained") +
  213. xlab("Principal Components") +
  214. theme_bw(base_size = 14) +
  215. theme(
  216. axis.text.x = element_text(angle = 45, hjust = 1)
  217. )
  218. ##disorder order
  219. disor<-rownames(pca_result$x)
  220. disor
  221. ##PCA-15 disorder dot plot
  222. pca_df <- data.frame(
  223. PC1 = pca_result$x[,1],
  224. PC4 = pca_result$x[,4]
  225. )
  226. pca_df
  227. pca_result$x
  228. write.csv(pca_result$x,file="PCA result.csv")
  229. ggplot(pca_df, aes(PC1, PC4, color =disor)) +
  230. geom_point(size = 3) +
  231. geom_text_repel(
  232. aes(label = disor),
  233. size = 3,
  234. max.overlaps = 20,
  235. box.padding = 0.5,
  236. point.padding = 0.3,
  237. min.segment.length = 0.2,
  238. segment.color = "grey50"
  239. )+
  240. scale_color_manual(values = c("IQ"="darkgrey", "ASD"="red","TS" ="firebrick", "Neuroticism"="darkgreen", "ADHD"="#FFdd22", "OCD" ="#0099FF", "ANO" = "#00CC00","PanicDisorder" ="#FF99FF", "BIP"="#FF33FF","MDD"= "orange", "SZes"="#33CCCC", "SZgw"="blue",
  241. "Epilepsy"= "#3366CC", "AD"="purple", "PD"="#111111"))+
  242. theme_bw()
  243. # ##corr::PCA component and spatiotemporal variables --------------------------------------------------
  244. library(dplyr)
  245. library(ggplot2)
  246. scaled<-read.csv("combine_r_rank_biserial-11structure-scaled.CSV",header=TRUE,sep=",")
  247. str(scaled)
  248. head(scaled)
  249. ##disorder order
  250. disor<-rownames(pca_result$x)
  251. disor
  252. scaled$structure <- factor(scaled$structure,
  253. levels = c("frontal_cortex", "parietal_cortex", "temporal_cortex", "occipital_cortex",
  254. "ganglionic_eminence","striatum","thalamus","amygdala","hippocampus","brain_stem","cerebellum"))
  255. scaled_summary <- scaled %>%
  256. group_by(structure) %>%
  257. summarise(across(disor, mean, na.rm = TRUE))
  258. scaled_summary_t<-t(scaled_summary)
  259. scaled_summary_t
  260. colnames(scaled_summary_t)
  261. colnames(scaled_summary_t) <- as.character(scaled_summary_t[1, ])
  262. scaled_summary_t
  263. scaled_summary_t <- scaled_summary_t[-1, ] # 删除第一行
  264. scaled_summary_t
  265. write.csv(scaled_summary_t,file="scaled_15disorder_structure summary.CSV",quote=F,row.names = T)
  266. scaled_summary<-read.csv("scaled_15disorder_structure summary.CSV",header=T,sep=",",row.names = 1)
  267. rownames(scaled_summary)
  268. colnames(scaled_summary)
  269. p2 <- pca_result$x[, c(1:4), drop = FALSE]
  270. df_pca_asso<-cbind(p2,scaled_summary)
  271. df_pca_asso
  272. help(rcorr)
  273. library(Hmisc)
  274. res<-rcorr(as.matrix(df_pca_asso),type="spearman")
  275. res
  276. R <- res$r
  277. P <- res$P
  278. vars <- colnames(df_pca_asso)
  279. vars
  280. library(tidyverse)
  281. n <- length(vars)
  282. upper_idx <- upper.tri(P, diag = FALSE)
  283. p_unique <- P[upper_idx]
  284. p_unique
  285. p_unique <- p_unique[!is.na(p_unique)]
  286. p_unique
  287. # FDR
  288. p_unique_fdr <- p.adjust(p_unique, method = "fdr")
  289. P_fdr <- matrix(NA, nrow = n, ncol = n)
  290. colnames(P_fdr) <- rownames(P_fdr) <- vars
  291. P_fdr[upper_idx] <- p_unique_fdr
  292. P_fdr[lower.tri(P_fdr)] <- t(P_fdr)[lower.tri(P_fdr)]
  293. diag(P_fdr) <- NA
  294. R
  295. P_fdr
  296. df_plot <- R %>%
  297. as.data.frame() %>%
  298. rownames_to_column("Var1") %>%
  299. pivot_longer(-Var1, names_to = "Var2", values_to = "cor") %>%
  300. left_join(
  301. P_fdr %>%
  302. as.data.frame() %>%
  303. rownames_to_column("Var1") %>%
  304. pivot_longer(-Var1, names_to = "Var2", values_to = "p"),
  305. by = c("Var1", "Var2")
  306. )
  307. df_plot$Var1 <- factor(df_plot$Var1, levels = vars)
  308. df_plot$Var2 <- factor(df_plot$Var2, levels = vars)
  309. df_plot
  310. ##dot plot
  311. df_plot <- df_plot %>%
  312. mutate(
  313. abs_cor = abs(cor),
  314. logp = -log10(p + 1e-10)
  315. )
  316. df_plot
  317. df_plot <- df_plot %>%
  318. mutate(
  319. p_fdr = as.vector(P_fdr[cbind(
  320. match(Var1, vars),
  321. match(Var2, vars)
  322. )]),
  323. sig = case_when(
  324. p_fdr < 0.001 ~ "***",
  325. p_fdr < 0.01 ~ "**",
  326. p_fdr < 0.05 ~ "*",
  327. TRUE ~ ""
  328. )
  329. )
  330. df_plot
  331. library(ggplot2)
  332. # bubble plot
  333. ggplot(df_plot, aes(Var1, Var2)) +
  334. geom_point(aes(size = logp,
  335. color = cor)) +
  336. geom_text(aes(label = sig), size = 4, vjust = 0.7) + # 星号标注
  337. scale_color_gradient2(low = "blue", mid = "white", high = "red", midpoint = 0,
  338. limits = range(df_plot$cor, na.rm = TRUE)) +
  339. scale_size(range = c(0, 10)) +
  340. scale_alpha(range = c(0.2, 1)) +
  341. theme_minimal()+
  342. theme(
  343. axis.text.x = element_text(angle = 45, hjust = 1),
  344. panel.grid = element_blank()
  345. ) +
  346. labs(
  347. size = "-log10(p)",
  348. color = "r",
  349. x = NULL, y = NULL,
  350. title = "Cor: PC1-4/ structures"
  351. )
  352. ## PC1 and variables
  353. library(dplyr)
  354. library(ggplot2)
  355. # ## PC and developmental stages----------------------------------------------------
  356. scaled<-read.csv("combine_r_rank_biserial-10structure-scaled.CSV",header=TRUE,sep=",")
  357. str(scaled)
  358. head(scaled)
  359. scaled$dev_stage <- factor(scaled$dev_stage,
  360. levels = c("Early_prenatal" ,"Early_mid_prenatal","Late_mid_prenatal","Late_prenatal", "Early_infancy","Late_infancy", "Early_childhood", "Late_childhood", "Adolescence",
  361. "Young_adulthood","Middle_adulthood"))
  362. ##disorder
  363. disor<-rownames(pca_result$x)
  364. disor
  365. scaled_summary <- scaled %>%
  366. group_by(dev_stage) %>%
  367. summarise(across(disor, mean, na.rm = TRUE))
  368. scaled_summary_t<-t(scaled_summary)
  369. scaled_summary_t
  370. colnames(scaled_summary_t)
  371. colnames(scaled_summary_t) <- as.character(scaled_summary_t[1, ])
  372. scaled_summary_t
  373. scaled_summary_t <- scaled_summary_t[-1, ]
  374. scaled_summary_t
  375. write.csv(scaled_summary_t,file="scaled_15disorder_dev_stage summary.CSV",quote=F,row.names = T)
  376. scaled_summary<-read.csv("scaled_15disorder_dev_stage summary.CSV",header=T,sep=",",row.names = 1)
  377. rownames(scaled_summary)
  378. colnames(scaled_summary)
  379. p2 <- pca_result$x[, c(1:4), drop = FALSE]
  380. df_pca_asso<-cbind(p2,scaled_summary)
  381. df_pca_asso
  382. library(Hmisc)
  383. res<-rcorr(as.matrix(df_pca_asso),type = "spearman")
  384. res
  385. R <- res$r
  386. P <- res$P
  387. vars <- colnames(df_pca_asso)
  388. vars
  389. library(tidyverse)
  390. n <- length(vars)
  391. upper_idx <- upper.tri(P, diag = FALSE)
  392. p_unique <- P[upper_idx]
  393. p_unique
  394. p_unique <- p_unique[!is.na(p_unique)]
  395. p_unique
  396. # FDR
  397. p_unique_fdr <- p.adjust(p_unique, method = "fdr")
  398. P_fdr <- matrix(NA, nrow = n, ncol = n)
  399. colnames(P_fdr) <- rownames(P_fdr) <- vars
  400. P_fdr[upper_idx] <- p_unique_fdr
  401. P_fdr[lower.tri(P_fdr)] <- t(P_fdr)[lower.tri(P_fdr)]
  402. diag(P_fdr) <- NA
  403. R
  404. P_fdr
  405. df_plot <- R %>%
  406. as.data.frame() %>%
  407. rownames_to_column("Var1") %>%
  408. pivot_longer(-Var1, names_to = "Var2", values_to = "cor") %>%
  409. left_join(
  410. P_fdr %>%
  411. as.data.frame() %>%
  412. rownames_to_column("Var1") %>%
  413. pivot_longer(-Var1, names_to = "Var2", values_to = "p"),
  414. by = c("Var1", "Var2")
  415. )
  416. df_plot$Var1 <- factor(df_plot$Var1, levels = vars)
  417. df_plot$Var2 <- factor(df_plot$Var2, levels = vars)
  418. df_plot
  419. df_plot <- df_plot %>%
  420. mutate(
  421. abs_cor = abs(cor),
  422. logp = -log10(p + 1e-10) # 避免 log(0)
  423. )
  424. df_plot
  425. df_plot <- df_plot %>%
  426. mutate(
  427. p_fdr = as.vector(P_fdr[cbind(
  428. match(Var1, vars),
  429. match(Var2, vars)
  430. )]),
  431. sig = case_when(
  432. p_fdr < 0.001 ~ "***",
  433. p_fdr < 0.01 ~ "**",
  434. p_fdr < 0.05 ~ "*",
  435. TRUE ~ ""
  436. )
  437. )
  438. ggplot(df_plot, aes(Var1, Var2)) +
  439. geom_point(aes(size = logp,
  440. color = cor)) +
  441. geom_text(aes(label = sig), size = 4, vjust = 0.7) + # 星号标注
  442. scale_color_gradient2(low = "blue", mid = "white", high = "red", midpoint = 0,
  443. limits = range(df_plot$cor, na.rm = TRUE)) +
  444. scale_size(range = c(0, 10)) +
  445. scale_alpha(range = c(0.2, 1)) +
  446. theme_minimal()+
  447. theme(
  448. axis.text.x = element_text(angle = 45, hjust = 1),
  449. panel.grid = element_blank()
  450. ) +
  451. labs(
  452. size = "-log10(p)",
  453. color = "r",
  454. x = NULL, y = NULL,
  455. title = "Cor: PC1-4/ dev_stage"
  456. )
  457. # ### PC and single variable ----------------------------------------------------
  458. ## PC2 and late infancy
  459. library(dplyr)
  460. library(ggplot2)
  461. scaled<-read.csv("combine_r_rank_biserial-10structure-scaled.CSV",header=TRUE,sep=",")
  462. str(scaled)
  463. head(scaled)
  464. scaled$dev_stage2 <- ifelse(scaled$dev_stage == "Late_infancy",
  465. "Late_infancy",
  466. "other")
  467. scaled$dev_stage2 <- factor(scaled$dev_stage2,
  468. levels = c("Late_infancy", "other"))
  469. summary(scaled$dev_stage2)
  470. disor<-rownames(pca_result$x)
  471. disor
  472. scaled_summary <- scaled %>%
  473. group_by(dev_stage2) %>%
  474. summarise(across(disor, mean, na.rm = TRUE))
  475. scaled_summary_t<-t(scaled_summary)
  476. scaled_summary_t
  477. colnames(scaled_summary_t)
  478. colnames(scaled_summary_t) <- as.character(scaled_summary_t[1, ])
  479. scaled_summary_t
  480. scaled_summary_t <- scaled_summary_t[-1, ]
  481. scaled_summary_t
  482. write.csv(scaled_summary_t,file="scaled_15disorder_late infancy summary.CSV",quote=F,row.names = T)
  483. scaled_summary<-read.csv("scaled_15disorder_late infancy summary.CSV",header=T,sep=",",row.names = 1)
  484. rownames(scaled_summary)
  485. colnames(scaled_summary)
  486. as.data.frame(pca_result$x[,1])
  487. df_pca_asso<-cbind(pca_result$x[,1:4],scaled_summary)
  488. df_pca_asso$PC1
  489. library(Hmisc)
  490. res<-rcorr(as.matrix(df_pca_asso))
  491. res
  492. disor
  493. ##"Cor: PC2/ Late_infancy enrichment"
  494. library(ggpubr)
  495. ggplot(data = df_pca_asso, aes(x = PC2, y =Late_infancy )) +
  496. geom_point() +
  497. geom_smooth(method = "lm", se = TRUE, color = "red") +
  498. stat_cor(method = "spearman",label.x.npc = 0.1, label.y.npc = 1.0,) +
  499. labs(title = "Cor: PC2/ Late_infancy",
  500. x = "PC2",
  501. y = "Late_infancy enrichment") +
  502. theme_minimal()+
  503. geom_text_repel(
  504. aes(label = disor),
  505. size = 3,
  506. max.overlaps = 20,
  507. box.padding = 0.5,
  508. point.padding = 0.3,
  509. min.segment.length = 0.2,
  510. segment.color = "grey50"
  511. )
  512. ## PC4 and cerebellum
  513. library(dplyr)
  514. library(ggplot2)
  515. scaled<-read.csv("combine_r_rank_biserial-11structure-scaled.CSV",header=TRUE,sep=",")
  516. str(scaled)
  517. head(scaled)
  518. scaled$structure2 <- ifelse(scaled$structure == "cerebellum",
  519. "cerebellum",
  520. "other")
  521. scaled$structure2 <- factor(scaled$structure2,
  522. levels = c("cerebellum", "other"))
  523. summary(scaled$structure2)
  524. disor<-rownames(pca_result$x)
  525. disor
  526. scaled_summary <- scaled %>%
  527. group_by(structure2) %>%
  528. summarise(across(disor, mean, na.rm = TRUE))
  529. scaled_summary_t<-t(scaled_summary)
  530. scaled_summary_t
  531. colnames(scaled_summary_t)
  532. colnames(scaled_summary_t) <- as.character(scaled_summary_t[1, ])
  533. scaled_summary_t
  534. scaled_summary_t <- scaled_summary_t[-1, ]
  535. scaled_summary_t
  536. write.csv(scaled_summary_t,file="scaled_15disorder_cerebellum summary.CSV",quote=F,row.names = T)
  537. scaled_summary<-read.csv("scaled_15disorder_cerebellum summary.CSV",header=T,sep=",",row.names = 1)
  538. rownames(scaled_summary)
  539. colnames(scaled_summary)
  540. as.data.frame(pca_result$x[,1])
  541. df_pca_asso<-cbind(pca_result$x[,1:4],scaled_summary)
  542. df_pca_asso$PC1
  543. library(Hmisc)
  544. res<-rcorr(as.matrix(df_pca_asso))
  545. res
  546. disor
  547. ##"Cor: PC4/ 和cerebellum enrichment"
  548. library(ggpubr)
  549. ggplot(data = df_pca_asso, aes(x = PC4, y =cerebellum )) +
  550. geom_point() +
  551. geom_smooth(method = "lm", se = TRUE, color = "red") +
  552. stat_cor(method = "spearman",label.x.npc = 0.2, label.y.npc = 1.0,) +
  553. labs(title = "Cor: PC4/ cerebellum enrichment",
  554. x = "PC4",
  555. y = "cerebellum enrichment") +
  556. theme_minimal()+
  557. geom_text_repel(
  558. aes(label = disor),
  559. size = 3,
  560. max.overlaps = 20,
  561. box.padding = 0.5,
  562. point.padding = 0.3,
  563. min.segment.length = 0.2,
  564. segment.color = "grey50"
  565. )
  566. # ##ENIGMA-AHBA enrichment correlations ------------------------
  567. library("data.table")
  568. library("dplyr")
  569. library(ggplot2)
  570. library(ggpubr)
  571. brainregion <-read.csv("brain_region_Annotation-6-fine.CSV",header=TRUE,sep=",")
  572. colnames(brainregion)
  573. head(brainregion)
  574. disord <-read.csv("combine_r_rank_biserial_rpkm-ave.CSV",header=TRUE,sep=",")
  575. head(disord)
  576. Disor_region_anno<-dplyr::left_join(disord,brainregion,by="X")
  577. head(Disor_region_anno)
  578. Disor_region_anno_enig <- Disor_region_anno %>%
  579. filter(!is.na(Structure_comn)) %>%
  580. group_by(Structure_comn) %>%
  581. summarise(across(all_of(colnames(Disor_region_anno)[-c(1,17:21)]), ave))
  582. Disor_region_anno_enig<- unique(Disor_region_anno_enig, fromLast = TRUE)
  583. Disor_region_anno_enig
  584. write.csv(Disor_region_anno_enig, file="Disor_region_anno.CSV", quote = F,row.names = T)
  585. # ##ASD ------------------------------------------------------------------
  586. enig_sub <-read.csv("asd_meta-analysis_case-controls_CortThick.CSV",header=TRUE,sep=",")
  587. enig_tck <-read.csv("asd_meta-analysis_case-controls_SubVol.CSV",header=TRUE,sep=",")
  588. enig<-rbind(enig_sub[,c(2:3,9)],enig_tck[,c(2:3,9)])
  589. enig$Structure<-sub('L_','',enig$Structure,ignore.case = F)
  590. enig$Structure<-sub('R_','',enig$Structure,ignore.case = F)
  591. enig$Structure<-sub('LL','Ll',enig$Structure,ignore.case = F)
  592. enig$Structure<-sub('RL','Rl',enig$Structure,ignore.case = F)
  593. enig$Structure<-sub('L','',enig$Structure,ignore.case = F)
  594. enig$Structure<-sub('R','',enig$Structure,ignore.case = F)
  595. enig
  596. enig2 <- enig %>%
  597. group_by(Structure) %>%
  598. summarise( d_icv_ave = mean(d_icv, na.rm = TRUE))
  599. print(enig2,n=40)
  600. region_enig <-read.csv("brain region-enigma.CSV",header=TRUE,sep=",")
  601. region_enig
  602. enig_comn<-dplyr::left_join(region_enig,enig2,by="Structure")
  603. enig_comn
  604. enig_merge<-dplyr::left_join(enig_comn,Disor_region_anno_enig,by="Structure_comn")
  605. str(enig_merge)
  606. enig_merge2 <- enig_merge %>%
  607. filter(!is.na(Structure_comn)) %>%
  608. group_by(Structure_comn) %>%
  609. summarise(across(all_of(colnames(enig_merge)[c(4:19)]), ave))
  610. enig_merge2<- unique(enig_merge2, fromLast = TRUE)
  611. enig_merge3<-enig_merge2 %>%
  612. filter(!is.na(d_icv_ave))
  613. ##dotplot
  614. ggplot(data = enig_merge3, aes(x = d_icv_ave, y =ASD )) +
  615. geom_point() +
  616. geom_smooth(method = "lm", se = TRUE, color = "red") +
  617. stat_cor(method = "spearman",label.x.npc = 'left', label.y.npc = "top",) +
  618. labs(title = "Correlation: brain MRI changes/ risk gene overexpression",
  619. x = "ASD_case-controls-d_icv",
  620. y = "ASD gene overexpression (rank-biserial)") +
  621. theme_minimal()+
  622. geom_text(
  623. data = subset(enig_merge3, Structure_comn %in% c("pal", "thal", "precuneus","lingual","caud", "hippo",
  624. "amyg","cuneus","put")),
  625. aes(label = Structure_comn),
  626. vjust = -0.5, # 标签垂直偏移
  627. hjust = 0.1 # 标签水平偏移
  628. )
  629. # WGCNA -----------------------------------------------------------------
  630. # BiocManager::install("WGCNA")
  631. # BiocManager::install("preprocessCore")
  632. library("WGCNA")
  633. library("glue")
  634. ## export dir
  635. outdir <- "C:/WGCNA"
  636. dir.create(file.path(outdir), showWarnings = FALSE)
  637. data1<-read.table("expression matrix_RPKM.CSV",header=TRUE,sep=",",row.names=1)
  638. dim(data1)
  639. row_sums <- rowSums(data1)
  640. sort(row_sums)[1:10]
  641. # delete very low expression genes
  642. row_sums
  643. data2 <- data1[row_sums >10, ]
  644. dim(data2)
  645. data2<-t(data2)
  646. head(data2)
  647. ## Plot a sample dendrogram
  648. setwd("C:/WGCNA")
  649. sampleTree <- hclust(dist(data2), method = "average")
  650. pdf(file = "Sample_dendrogram_rm_outlier.pdf", width = 12, height = 9)
  651. par(cex = 0.6)
  652. par(mar = c(2,5,5,1))
  653. plot(sampleTree, main = "Sample clustering to detect outliers",
  654. sub="", xlab="", cex.lab = 1.5, cex.axis = 1.5, cex.main = 2)
  655. abline(h = 100000, col = "red")
  656. dev.off()
  657. ## clust 1 contains the samples we want to keep
  658. clust <- cutreeStatic(sampleTree, cutHeight = 100000, minSize = 5)
  659. clust
  660. keepSamples <- (clust != 0)
  661. notkeepSamples <- clust[clust == 0]
  662. length(notkeepSamples)
  663. datExpr <- data2[keepSamples, ]
  664. str(datExpr)
  665. keepSamples
  666. write.csv(datExpr, file = "datExpr.csv")
  667. ## Determination of the soft-thresholding power====================================================================================
  668. powers <- c(1:20) # often 20 in practice
  669. sft <- pickSoftThreshold(datExpr, powerVector = powers, RsquaredCut = 0.85)
  670. sft
  671. pdf("Soft_Threshold.pdf")
  672. par(mfrow = c(1, 2))
  673. plot(sft$fitIndices[, 1], -sign(sft$fitIndices[, 3]) * sft$fitIndices[, 2],
  674. xlab = "Soft Threshold (power)", ylab = "SFT, signed R^2",
  675. type = "n", main = paste("Scale independence"))
  676. text(sft$fitIndices[, 1], -sign(sft$fitIndices[, 3]) * sft$fitIndices[, 2],
  677. labels = powers, col = "red")
  678. abline(h = 0.85, col = "red") ## 阈值线
  679. plot(sft$fitIndices[, 1], sft$fitIndices[, 5], type = "n",
  680. xlab = "Soft Threshold (power)", ylab = "Mean Connectivity",
  681. main = paste("Mean connectivity"))
  682. text(sft$fitIndices[, 1], sft$fitIndices[, 5],
  683. labels = powers, col = "red")
  684. dev.off()
  685. ## Obtain an appropriate soft-threshold
  686. power <- sft$powerEstimate
  687. if (is.na(power))
  688. {
  689. nSamples <- ncol(datExpr)
  690. power <- ifelse(nSamples < 20, 9, ifelse(nSamples < 30, 8, ifelse(nSamples < 40, 7, 6)))
  691. }
  692. power
  693. #Module identification====================================================================================
  694. module_detect_dir <- "C:/WGCNA"
  695. dir.create(file.path(module_detect_dir), showWarnings = FALSE)
  696. enableWGCNAThreads(nThreads = 2)
  697. str(datExpr)
  698. nGenes <- ncol(datExpr)
  699. block_thred <- 40000
  700. if(nGenes <= block_thred){
  701. net <- blockwiseModules(datExpr, corType = "pearson", maxBlockSize = 1.1 * nGenes,
  702. networkType = "unsigned", power = power, minModuleSize = 40,
  703. mergeCutHeight = 0.25, numericLabels = TRUE, saveTOMs = TRUE,
  704. pamRespectsDendro = FALSE, saveTOMFileBase = glue("{module_detect_dir}/TOM"))
  705. } else {
  706. net <- blockwiseModules(datExpr, corType = "pearson", maxBlockSize = block_thred,
  707. networkType = "unsigned", power = power, minModuleSize = 40,
  708. mergeCutHeight = 0.25, numericLabels = TRUE, saveTOMs = TRUE,
  709. pamRespectsDendro = FALSE, saveTOMFileBase = glue("{module_detect_dir}/TOM"))
  710. }
  711. moduleLables <- net$colors
  712. moduleColors <- labels2colors(moduleLables)
  713. moduleLables
  714. # #Extract the whole-genome module color table--------------------------------------
  715. str(moduleLables)
  716. head(moduleLables)
  717. genome_module<-cbind(moduleLables,moduleColors)
  718. genome_module<-as.data.frame(genome_module)
  719. factor_modules<-factor(genome_module$moduleColors)
  720. dummy_modules<-model.matrix(~factor(factor_modules)-1)
  721. str(dummy_modules)
  722. genome_module_dummy<-cbind(genome_module,dummy_modules)
  723. colnames(genome_module_dummy) <- gsub("factor\\(factor_modules\\)", "", colnames(genome_module_dummy))
  724. write.csv(genome_module_dummy, file = glue("{module_detect_dir}/genome_module_dummy.csv"), row.names = TRUE)
  725. ## save the results
  726. MEs <- net$MEs
  727. geneTree <- net$dendrograms[[1]]
  728. save(MEs, moduleLables, moduleColors, geneTree, net,
  729. file = glue("{module_detect_dir}/networkConstruction_and_modules.RData"))
  730. ## Plot the clustering tree and co-expression modules
  731. blocks <- length(unique(net$blocks))
  732. if(blocks == 1){
  733. pdf(glue("{module_detect_dir}/Gene_Cluster_Dendrogram.pdf"))
  734. plotDendroAndColors(net$dendrogram[[1]], moduleColors[net$blockGenes[[1]]],
  735. groupLabels = "Module colors", dendroLabels = FALSE,
  736. hang = 0.03, addGuide = TRUE, guideHang = 0.05)
  737. dev.off()
  738. } else {
  739. pdf(glue("{module_detect_dir}/Gene_Cluster_Dendrogram.pdf"))
  740. for (i in 1:blocks){
  741. plotDendroAndColors(net$dendrogram[[i]], moduleColors[net$blockGenes[[i]]],
  742. groupLabels = "Module colors",
  743. main = glue("Gene dendrogram and module colors in block {i}"),
  744. dendroLabels = FALSE,
  745. hang = 0.03, addGuide = TRUE, guideHang = 0.05)
  746. }
  747. dev.off()
  748. }
  749. # Co-expression network visualization
  750. dissTOM <- 1 - TOMsimilarityFromExpr(datExpr, power = power)
  751. set.seed(123)
  752. select <- sample(nGenes, size = as.numeric(400))
  753. selectTOM <- dissTOM[select, select]
  754. selectColors <- moduleColors[select]
  755. selectTree <- hclust(as.dist(selectTOM), method = "average")
  756. plotDiss = selectTOM^7
  757. diag(plotDiss) = NA
  758. pdf(glue("{outdir}/Network_heatmap_plot_selectGenes.pdf"))
  759. TOMplot(plotDiss, selectTree, selectColors, main = "Network heatmap plot, selected genes", col = heat.colors(12))
  760. dev.off()
  761. # compute module eigengenes
  762. MEs0 <- moduleEigengenes(datExpr, moduleColors)$eigengenes
  763. MEs0
  764. MEsCol <- orderMEs(MEs0)
  765. str(MEsCol)
  766. write.csv(MEsCol,file=glue("{module_detect_dir}/mescol.csv"), row.names = T, quote = FALSE)
  767. MEsCol <- read.csv(glue("{module_detect_dir}/mescol.csv"), sep=",", row.names = 1)
  768. MEsCol
  769. #=## Phenotypic data association analysis - ====================================================================================
  770. ## Read phenotypic data
  771. data1 <- read.csv("brian regions-wgcna.csv", sep=",", row.names = 1)
  772. allTraits<-data1[,1:3]
  773. str(allTraits)
  774. Sample <- rownames(datExpr)
  775. str(Sample)
  776. traitRows <- match(Sample, rownames(allTraits))
  777. traitRows
  778. datTraits <- data.frame(allTraits[traitRows, ])
  779. table(rownames(datTraits) == rownames(datExpr))
  780. dev_stage<-factor(datTraits$dev_stage)
  781. coarse_structure<-factor(datTraits$coarse_structure)
  782. dummy_dev<-model.matrix(~factor(dev_stage)-1)
  783. dummy_structure<-model.matrix(~factor(coarse_structure)-1)
  784. str(dummy_dev)
  785. str(dummy_structure)
  786. # regression analysis for 41 MEs -----------------------------------------------------
  787. library(dplyr)
  788. str(MEsCol)
  789. head(dummy_structure)
  790. MEsColall<-cbind(MEsCol,dummy_structure,dummy_dev)
  791. write.csv(MEsColall,file=glue("{module_detect_dir}/MEsColall-21Var.csv"), row.names = T, quote = FALSE)
  792. PValues<-data.frame(matrix(nrow = 18, ncol = length(MEsCol)))
  793. BS<-data.frame(matrix(nrow = 18, ncol = length(MEsCol)))
  794. str(BS)
  795. colnames(MEsCol)
  796. for (i in 1:length(MEsCol))
  797. {
  798. formula <- as.formula(paste(colnames(MEsCol)[i], "~ dummy_structure+ dummy_dev"))
  799. model <- lm(formula, data = MEsColall)
  800. summary(model)
  801. # 进行其他处理,如汇总结果等
  802. PValue<-summary(model)$ coefficients[, "Pr(>|t|)"]
  803. B<-summary(model)$coefficients[,"Estimate"]
  804. PValues[,i]<-unname(PValue)
  805. BS[,i]<-unname(B)
  806. }
  807. str(PValues)
  808. head(PValues)
  809. colnames(PValues)<-colnames(MEsCol)
  810. colnames(BS)<-colnames(MEsCol)
  811. rownames(PValues)<-names(PValue)
  812. rownames(BS)<-names(PValue)
  813. names(PValue)
  814. head(BS)
  815. tBS<-t(BS)
  816. tPValues<-t(PValues)
  817. colnames(tPValues) <- gsub("dummy_devfactor\\(dev_stage\\)", "", colnames(tPValues))
  818. colnames(tPValues) <- gsub("dummy_structurefactor\\(coarse_structure\\)", "", colnames(tPValues))
  819. colnames(tBS) <- gsub("dummy_devfactor\\(dev_stage\\)", "", colnames(tBS))
  820. colnames(tBS) <- gsub("dummy_structurefactor\\(coarse_structure\\)", "", colnames(tBS))
  821. write.csv(tBS, file = glue("{module_detect_dir}/structure—dev-covariate-regression_B-18var.CSV"),row.names = T)
  822. write.csv(tPValues, file = glue("{module_detect_dir}/structure—dev-covariate-regression_PV-18var.csv"), row.names = T, quote = FALSE)
  823. ## Select the modules with most significant spatiotemporal enrichment (at least one regression coefficient greater than 0.05).
  824. library("WGCNA")
  825. library("glue")
  826. tBS<-read.csv(glue("{module_detect_dir}/structure—dev-covariate-regression_B-18var.CSV"), check.names = FALSE, sep=",", row.names = 1)
  827. tPValues<-read.csv(glue("{module_detect_dir}/structure—dev-covariate-regression_PV-18var.CSV"), check.names = FALSE,sep=",", row.names = 1)
  828. tBS<- as.matrix(tBS)
  829. tPValues<- as.matrix(tPValues)
  830. colnames(tBS)
  831. rownames(tBS)
  832. #(Intercept)
  833. tBS2<-tBS[,c("(Intercept)","Neocortex","Striatum","Ganglionic_eminence","Amygdala",
  834. "Hippocampus","Brain_stem","Cerebellum","Early prenatal", "Early mid-prenatal", "Late mid-prenatal","Late prenatal","Early infancy","Late infancy","Early childhood","Late childhood","Adolescence","Middle adulthood")]
  835. tPValues2<-tPValues[,c("(Intercept)","Neocortex","Striatum","Ganglionic_eminence","Amygdala",
  836. "Hippocampus","Brain_stem","Cerebellum","Early prenatal", "Early mid-prenatal", "Late mid-prenatal","Late prenatal","Early infancy","Late infancy","Early childhood","Late childhood","Adolescence","Middle adulthood")]
  837. colnames(tBS2)[1] <- "Tha | Young Adult"
  838. colnames(tPValues2)[1] <- "Tha | Young Adult"
  839. head(tPValues2)
  840. ##FDR ------------------------------------------------
  841. p_adj_by_disease <- apply(tPValues2, 2, p.adjust, method = "BH")
  842. p_adj_by_disease
  843. write.csv(p_adj_by_disease, file="structure—dev-covariate-regression_PV-18var-P-41M-FDR.CSV", quote = F,row.names = T)
  844. ##module with MAX B>0.05 --------------------------------------------------
  845. threshold<-0.05
  846. threshold
  847. tBS2_sig <- tBS2[apply(tBS2, 1, max) > threshold, ]
  848. str(tBS2_sig)
  849. rownames(tBS2_sig)
  850. p_adj_fdr<-p_adj_by_disease[ rownames(tBS2_sig),]
  851. write.csv(tBS2_sig, file = glue("{module_detect_dir}/structure—dev-covariate-regression_B-18var_B大于0.05ME.CSV"),row.names = T)
  852. write.csv(p_adj_fdr, file = glue("{module_detect_dir}/structure—dev-covariate-regression_PV-18var_B大于0.05ME-fdr.csv"), row.names = T, quote = FALSE)
  853. ### textMatrix
  854. textMatrix <-signif(tBS2_sig, 1)
  855. textMatrix[abs(tBS2_sig) <= 0.05] <- ""
  856. textMatrix[p_adj_fdr >= 0.05] <- ""
  857. textMatrix
  858. dim(textMatrix) <- dim(tBS2_sig)
  859. # heatmap
  860. pdf(glue("{outdir}/Module-trait_relationship_dev_str_covari-18var-B0.05-fdr0.05.pdf"), width = 8, height =10)
  861. par(mar = c(9, 9, 3, 3),cex.main = 2)
  862. labeledHeatmap(Matrix = tBS2_sig, xLabels = colnames(tBS2_sig), yLabels = rownames(tBS2_sig),
  863. ySymbols = rownames(tBS2_sig), colorLabels = FALSE, colors = blueWhiteRed(50),
  864. cex.lab=1.0,
  865. textMatrix = textMatrix, setStdMargins = FALSE, cex.text = 0.6, zlim = c(-0.25, 0.25),
  866. main = paste("Module-trait relationships"),
  867. clustRow = TRUE,
  868. rowDendro = TRUE,
  869. verticalSeparator.x=8)
  870. dev.off()
  871. # Chi-square test between module genes and the 15 merged risk gene sets -----------------------------------------
  872. #Create a loop to batch integrate risk gene data into genome module data
  873. library("data.table")
  874. riskgene<-read.table("15 disorder_merged gene.CSV",header=TRUE,sep=",",row.names=1)
  875. str(riskgene)
  876. braingene<-fread("genome_module_dummy.CSV",header=TRUE,sep=",")
  877. braingene<-braingene[,-c(2,3)]
  878. colnames(braingene)[1]<-"gene"
  879. colnames(braingene)[2:42]<-paste("ME",colnames(braingene)[2:42],sep="")
  880. colnames(braingene)
  881. str(braingene)
  882. colname=c(colnames(riskgene))
  883. str(riskgene)
  884. dim(riskgene)
  885. dim(braingene)
  886. braingeneXrisk<-braingene
  887. for(i in 1:15){
  888. v2<-colname[i]
  889. riskgenei<-data.table(c(riskgene[,i]),"1")
  890. names(riskgenei) <- c("gene", v2)
  891. str(riskgenei)
  892. braingeneXrisk<-dplyr::left_join(braingeneXrisk,riskgenei,by="gene")
  893. }
  894. braingeneXrisk[is.na(braingeneXrisk)]<-0
  895. str(braingeneXrisk)
  896. braingeneXrisk<-braingeneXrisk[!duplicated(braingeneXrisk,by="gene"),]
  897. str(braingeneXrisk)
  898. ##Chi-square test
  899. library(gmodels)
  900. library("data.table")
  901. library("dplyr")
  902. str(braingeneXrisk)
  903. colnames(braingeneXrisk)
  904. setDT(braingeneXrisk, keep.rownames=FALSE, key=NULL, check.names=FALSE)
  905. variables<-c(colnames(braingeneXrisk))
  906. variables
  907. ncol(braingene)
  908. ncol(braingeneXrisk)
  909. p_values<-data.frame()
  910. OR<-data.frame()
  911. Risk_Positive_prop<-data.frame()
  912. imax<-ncol(braingene)
  913. imax
  914. jmax<-ncol(braingeneXrisk)-ncol(braingene)
  915. jmax
  916. c(imax+1:jmax)
  917. variables[2:ncol(braingene)]
  918. variables[ncol(braingene)+1:jmax]
  919. braingeneXrisk[[1]]
  920. for (i in 2:imax)
  921. {for (j in c(imax+1:jmax))
  922. {result<-CrossTable(braingeneXrisk[[i]], braingeneXrisk[[j]],expected = F, format = "SAS",fisher = T, prop.c = F,prop.t = F,prop.chisq = F)
  923. p_values[i-1,j-ncol(braingene)]<-result$fisher.gt$p.value
  924. OR[i-1,j-ncol(braingene)]<-result$fisher.gt$estimate[[1]]
  925. Risk_Positive_prop[i-1,j-ncol(braingene)]<-result$prop.col[2,2]
  926. }
  927. }
  928. rownames(p_values)<-c(variables[2:imax])
  929. colnames(p_values)<-c(variables[imax+1:jmax])
  930. rownames(OR)<-c(variables[2:imax])
  931. colnames(OR)<-c(variables[imax+1:jmax])
  932. rownames(Risk_Positive_prop)<-c(variables[2:imax])
  933. colnames(Risk_Positive_prop)<-c(variables[imax+1:jmax])
  934. rownames(Risk_Positive_prop)
  935. write.csv(p_values, file="P_Values-41ME.CSV", quote = F,row.names = T)
  936. write.csv(OR,file="OR-41ME.CSV", quote=F,row.names = T)
  937. ##Conduct enrichment analysis with the enrich function in the clusterProfiler package
  938. library(dplyr)
  939. library(stringr)
  940. library(rlang)
  941. library(ggplot2)
  942. require(clusterProfiler)
  943. library(clusterProfiler)
  944. library(biomaRt)
  945. library(AnnotationHub)
  946. library(AnnotationDbi)
  947. library(ggstar)
  948. library("org.Hs.eg.db")
  949. library("ggtext")
  950. # enriChKEGG---------------
  951. # KEGG analysis of significantly enriched modules---------------------------------------------------------------
  952. sig_module<-read.table("sig modules-16.CSV",header=TRUE,sep=",",row.names=1)
  953. colnames(sig_module)
  954. posi_gene_Entrez<-vector("list", ncol(sig_module))
  955. names(posi_gene_Entrez)<-colnames(sig_module)
  956. colnames(sig_module)
  957. for (j in 1:16)
  958. {
  959. posi_sig_module<-sig_module[,j]
  960. length(posi_sig_module)
  961. posi_sig_module <- posi_sig_module[!posi_sig_module==""]
  962. length(posi_sig_module)
  963. posi_sig_module
  964. entrezid_all = mapIds(x = org.Hs.eg.db,
  965. keys = posi_sig_module,
  966. keytype = "SYMBOL",
  967. column = "ENTREZID")
  968. entrezid_all
  969. entrezid_all = na.omit(entrezid_all)
  970. entrezid_all = data.frame(entrezid_all)
  971. posi_gene_Entrez[[j]]<- entrezid_all[,1]
  972. }
  973. summary(posi_gene_Entrez)
  974. save(posi_gene_Entrez, file ='KEGG_sig module gene.RData')
  975. load('KEGG_sig module gene.RData')
  976. summary(posi_gene_Entrez)
  977. ###qvalueCutoff=0.05###
  978. ###Compare multiple enrichment results using the compareCluster function in clusterProfiler
  979. KEGG_result<-compareCluster(posi_gene_Entrez, fun="enrichKEGG", organism="hsa",qvalueCutoff=0.05)
  980. table(KEGG_result@compareClusterResult$Cluster)
  981. str(KEGG_result)
  982. KEGG_result@compareClusterResult$Description<-str_replace_all(KEGG_result@compareClusterResult$Description, " - Homo sapiens \\(.*?\\)", "")
  983. str(KEGG_result@compareClusterResult$Description)
  984. KEGG_result@compareClusterResult$Log_qvalue<- -log(KEGG_result@compareClusterResult$qvalue,10)
  985. write.csv(KEGG_result,"KEGG_sig module gene-q0.05.csv")
  986. dotpl<- dotplot(KEGG_result, x="Cluster",color= "Log_qvalue",
  987. showCategory =3,
  988. by="Log_qvalue",
  989. size ="GeneRatio",
  990. font.size = 10,
  991. label_format = 30)+
  992. theme(axis.text.x = element_text(angle = 45, hjust = 1,size=8),axis.text.y = element_text(hjust = 1,size=8),plot.title = element_text(size = 10, hjust = 0.5))+
  993. labs(title="Enrichment analysis of module genes for KEGG pathways",x = '', y = '')
  994. ggsave(dotpl,filename="KEGG_sig module gene-q0.05.png", width =6, height =7,units = "in", dpi = 300, bg = "transparent")
  995. ##enrichGO--export go terms top 3significant
  996. for (j in 1:16)
  997. {
  998. summary(posi_gene_Entrez)
  999. enrichGO_result<-enrichGO(posi_gene_Entrez[[j]], OrgDb=org.Hs.eg.db, keyType = "ENTREZID", ont = "ALL",
  1000. pvalueCutoff = 0.05, pAdjustMethod = "BH", qvalueCutoff = 0.05,
  1001. minGSSize =3, maxGSSize = 500,
  1002. readable = FALSE,
  1003. pool = FALSE
  1004. )
  1005. str(enrichGO_result)
  1006. go <- enrichGO_result
  1007. str(go)
  1008. go <- go[order(go$ONTOLOGY, go$qvalue, decreasing = F),]
  1009. go_top5 <- go %>%
  1010. group_by(ONTOLOGY) %>%
  1011. slice_head(n = 3) %>%
  1012. ungroup()
  1013. go_top5 <- go_top5[order(go_top5$ONTOLOGY, go_top5$qvalue, decreasing = T),]
  1014. go_top5
  1015. go_top5$Description <- sapply(go_top5$Description, function(x) paste(strwrap(x, width = 30), collapse = "\n"))
  1016. str(go_top5)
  1017. go_top5$ShortDesc <- ifelse(nchar(go_top5$Description) > 40,
  1018. paste0(substr(go_top5$Description, 1, 37), "..."),
  1019. go_top5$Description)
  1020. go_top5$ShortDesc
  1021. go_top5$ShortDesc <- sub("acetylcholine", "Ach", go_top5$ShortDesc) # 提取首个词
  1022. barpl<-ggplot(go_top5, aes(x = reorder(ShortDesc, -qvalue),y= -log10(qvalue))) +
  1023. geom_col(aes(fill = ONTOLOGY), width = 0.5, show.legend =F) +
  1024. facet_grid(ONTOLOGY~., scale = 'free_y', space = 'free_y') +
  1025. theme(axis.text = element_text(size = 12), panel.grid = element_blank(), panel.background = element_rect(color = 'black', fill = 'transparent')) +
  1026. scale_y_continuous(expand = expansion(mult = c(0, 0.1))) +
  1027. coord_flip() +
  1028. labs(title=colnames(sig_module)[j],x = '', y = '-Log10(q)' )
  1029. ggsave(barpl,filename=paste0('enrich.go_sig module gene',colnames(sig_module)[j],'-q0.05.png'), width = 4,height=4,dpi=300, units="in", bg = "transparent")
  1030. }

R code for data analysis.R, under CC-BY-4.0 · at the source

Overview

  1. Clinical Research Center for Mental Disorders, Shanghai Pudong New Area Mental Health Center, School of Medicine, Tongji University,Shanghai, China
  2. Laboratory for Molecular Mechanisms of Brain Development, RIKEN Center for Brain Science,Wako, Japan
Institutions: Tongji University (China); RIKEN Center for Brain Science (Japan)
Journal: Communications biology, volume 9, issue 1, article 634
Dates: received 23 September 2025; accepted 31 March 2026; published online 13 May 2026
Type: Research article · Language: English
License: CC BY-NC-ND
Identifiers: DOI 10.1038/s42003-026-10045-x · PMID 42129508 · PMCID PMC13172025 · OpenAlex W4414931447
Open access: gold, a free copy (OpenAlex)
Status: code verified
Categories: genetics / omics (modality), human (organism), cellular / molecular (subfield)
Methods: Statistics, Smoothing, state filtering, decompositions, Machine learning, Preprocessing, Connectivity, Spectral & time-frequency
Keywords: Development, Disease genetics
MeSH: Brain*, Genetic Predisposition to Disease*, Mental Disorders*, Transcriptome*, Gene Expression Profiling, Genome-Wide Association Study, Humans, Neurodevelopment (* major topic)
Topic: Health, Environment, Cognitive Aging (Health, Toxicology and Mutagenesis, Environmental Science), according to OpenAlex
Funding: Key Specialty Construction Project of Shanghai Pudong Health Commission (PWZzk2022-19), Shanghai Pudong New Area Health Committee Disciplinary Leader Program (PWRd2021-06), Shanghai Pudong Science & Technology Development Foundation (PKJ2025-Y24),Open Project of the Key Laboratory of Neuropsychiatric Disorders and Developmental Genetics, Ministry of Education (2025GDND02), and the New Quality Clinical Specialty Program of High-end Medical Disciplinary Construction in Shanghai Pudong New Area (2025-PWXZ-08),JSPS KAKENHI (18F18736); National Institutes of Health grants (U01MH124619), the Funding Program by MEXT Grants-in-Aid for Scientific Research on Innovative Areas “Cell type census of adaptive neuronal circuits: biological mechanisms of structural and functional organization (Adaptive Circuit Census, ACC)” (KAKENHI 21H05240), and the Brain Mapping by Integrated Neurotechnologies for Disease Studies (Brain/MINDS) project from the Japan Agency for Medical Research and Development (JP20dm0207001) and Brain/MINDS2.0 (JP23wm0625001), and JSPS KAKENHI (18F18736)
Citations: cited by 1 paper (Europe PMC); 70 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.

Repositories

Its files are read in the Code ↔ Paper reader above, with 15 matches between paragraphs and lines of code.

liuwq2010/Neuropsychiatric-risk-gene-spatiotemporal-expression

License: MIT
State: the link answers, verified on 28 September 2026
Evidence: files inventoried
Commit: aaec55250e394a7553d4aad991fa7f86cc0f0653, 21 September 2025
Languages: R (1)
Size: 2 files, 1 script
Software Heritage: not archived
Found in: “Code availability”
Holds: license file
Not found: README, CITATION.cff, environment file, tests, continuous integration, documentation
Tools: clusterProfiler (1 file), ComplexHeatmap (1 file), data.table (1 file), easystats (1 file), ggplot2 (1 file), ggpubr (1 file), tidyverse (1 file), WGCNA (1 file)
Availability: 1 check, the latest on 28 September 2026: the link answers
  • 28 September 2026: the link answers
2 files

Zenodo 19097352

License: CC-BY-4.0
State: the link answers, verified on 28 September 2026
Evidence: files inventoried
Languages: R (1)
Size: 1 file, 1 script
Software Heritage: not checked
Found in: “Code availability”
Not found: README, license file, CITATION.cff, environment file, tests, continuous integration, documentation
Tools: clusterProfiler (1 file), ComplexHeatmap (1 file), data.table (1 file), easystats (1 file), ggplot2 (1 file), ggpubr (1 file), rstatix (1 file), tidyverse (1 file), WGCNA (1 file)
Availability: 1 check, the latest on 28 September 2026: the link answers (HTTP 200)
  • 28 September 2026: the link answers (HTTP 200)
1 file
At the source:

Code availability statement

The paper has a code 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.1038/s42003-026-10045-x.

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:

  • 2 repositories of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 2 scripts, each with its path and the digest of its content;
  • 15 matches between paragraphs of the paper and lines of the code (method lexical-v1);
  • 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.

Data availability statement

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

  • no repository, dataset or request procedure was recognized in it

Read it in the paper: doi.org/10.1038/s42003-026-10045-x.

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, 28 September 2026: the first record

Recorded: type, language, journal, volume, issue, pages, dates, 2 authors, 2 keywords, 8 MeSH terms, 2 funders, 67 references.

Cite

This paper

Liu, W., & Shimogori, T. (2026). Spatiotemporal brain transcriptomics reveal risk gene hot-spots in major neuropsychiatric disorders. Communications biology, 9(1), 634. https://doi.org/10.1038/s42003-026-10045-x

BibTeX

@article{liu2026spatiotemporal,
author = {Liu, Weiqing and Shimogori, Tomomi},
title = {{Spatiotemporal brain transcriptomics reveal risk gene hot-spots in major neuropsychiatric disorders}},
journal = {Communications biology},
year = {2026},
month = may,
volume = {9},
number = {1},
pages = {634},
publisher = {Nature Publishing Group},
issn = {2399-3642},
doi = {10.1038/s42003-026-10045-x},
url = {https://doi.org/10.1038/s42003-026-10045-x},
pmid = {42129508},
pmcid = {PMC13172025}
}

RIS

TY - JOUR
AU - Liu, Weiqing
AU - Shimogori, Tomomi
TI - Spatiotemporal brain transcriptomics reveal risk gene hot-spots in major neuropsychiatric disorders
T2 - Communications biology
J2 - Commun Biol
PY - 2026
DA - 2026/05/13
VL - 9
IS - 1
SP - 634
SN - 2399-3642
PB - Nature Publishing Group
DO - 10.1038/s42003-026-10045-x
UR - https://doi.org/10.1038/s42003-026-10045-x
LA - en
ER -

CSL-JSON

{
"id": "10.1038/s42003-026-10045-x",
"type": "article-journal",
"title": "Spatiotemporal brain transcriptomics reveal risk gene hot-spots in major neuropsychiatric disorders",
"container-title": "Communications biology",
"author": [
{
"family": "Liu",
"given": "Weiqing"
},
{
"family": "Shimogori",
"given": "Tomomi"
}
],
"container-title-short": "Commun Biol",
"volume": "9",
"issue": "1",
"page": "634",
"DOI": "10.1038/s42003-026-10045-x",
"PMID": "42129508",
"PMCID": "PMC13172025",
"ISSN": "2399-3642",
"publisher": "Nature Publishing Group",
"URL": "https://doi.org/10.1038/s42003-026-10045-x",
"language": "en",
"issued": {
"date-parts": [
[
2026,
5,
13
]
]
}
}

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.1371/journal.pcbi.1014422 [code]
Deciphering cell type-specific causal genetic effects on brain imaging-derived phenotypes and disorders with single-cell Mendelian randomization.
Journal: PLoS computational biology
In common: clusterProfiler, data.table, ggplot2, 1 other tool, genetics / omics, cellular / molecular, 10 references
[2] doi:10.1038/s41593-026-02247-7 [code]
Transcriptomic and phenotypic convergence of neurodevelopmental disorder risk genes in vitro and in vivo.
Journal: Nature neuroscience
In common: genetics / omics, cellular / molecular, 13 references
[3] doi:10.1038/s41380-026-03497-4 [code]
Transcriptome-informed brain cartography of polygenic risk and association with brain structure in major psychiatric disorders.
Journal: Molecular psychiatry
In common: clusterProfiler, ComplexHeatmap, ggplot2, 1 other tool, genetics / omics, cellular / molecular, 8 references
[4] doi:10.1016/j.celrep.2026.117500 [code]
Spatio-molecular gene expression reflects dorsal anterior cingulate cortex structure and function in the human brain.
Journal: Cell reports
In common: easystats, ComplexHeatmap, ggpubr, 2 other tools, genetics / omics, cellular / molecular, 7 references
[5] doi:10.1111/adb.70179 [code]
Transcriptional Response to Chronic Long-Access Fentanyl Self-Administration in Rat Habenula and Amygdala.
Journal: Addiction biology
In common: rstatix, clusterProfiler, ComplexHeatmap, 3 other tools, genetics / omics, cellular / molecular, 3 references
[6] doi:10.1038/s41467-026-71542-5 [code]
Astrocyte fatty acid metabolism as a driver of risk for major depressive disorder.
Journal: Nature communications
In common: WGCNA, data.table, ggplot2, 1 other tool, genetics / omics, cellular / molecular, 5 references
[7] doi:10.1038/s41467-026-72598-z [code]
Functional impact of genetic background on variable expressivity in neurodevelopmental disorders.
Journal: Nature communications
In common: WGCNA, clusterProfiler, ComplexHeatmap, 4 other tools, 2 references
[8] doi:10.1038/s41467-026-75193-4 [code]
Multi-ancestry gene expression models amplify transcriptome-wide association study discovery and validation.
Journal: Nature communications
In common: ComplexHeatmap, ggpubr, data.table, 2 other tools, genetics / omics, cellular / molecular, 4 references
[9] 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: WGCNA, rstatix, clusterProfiler, 5 other tools, genetics / omics
[10] doi:10.1016/j.xhgg.2026.100652 [code]
CRISPR-engineered deletion of POGZ alters transcription factor binding at promoters of genes involved in synaptic signaling.
Journal: HGG advances
In common: WGCNA, ggpubr, data.table, 2 other tools, cellular / molecular, 4 references

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.