Ischemic stroke triggers brain-wide synaptic remodeling within four hours.
The 1 match
- [1] § Methods › Quantification and statistical analysis › Statistic analysis of proteomic and transcriptomic data. ↔ Dream_Synaptosome_DE_code.R, lines 43–91 · score 0.76 · linear mixed models, Rattus norvegicus, Salmon, Dream, variancePartition, gene
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,237 lines · 53 KB · CC-BY-4.0 · 1 match
- library(tximeta)
- library(DESeq2)
- library(tidyverse)
- library(readr)
- library(apeglm)
- library(ashr)
- library (EnhancedVolcano)
- library(gprofiler2)
- library(dplyr)
- library(IHW)
- library("variancePartition")
- library(edgeR)
- library(tximport)
- library(patchwork)
- library(cowplot)
- ################################################################################
- #################################################################### Synaptosome
- pathSyn <- "/BMK_DATA_20230515093157_1_synaptosome/transcripts_quant"
- directoryIDSyn <- c("BE096-02T0001_good_quant", "BE096-02T0002_good_quant", "BE096-02T0003_good_quant",
- "BE096-02T0004_good_quant", "BE096-02T0005_good_quant", "BE096-02T0006_good_quant",
- "BE096-02T0007_good_quant", "BE096-02T0008_good_quant", "BE096-02T0009_good_quant",
- "BE096-02T0010_good_quant", "BE096-02T0011_good_quant", "BE096-02T0012_good_quant")
- filesSyn <- file.path(pathSyn, directoryIDSyn, "quant.sf")
- files <- c(filesSyn)
- file.exists(files)
- rep <- c("CA1", "CA2", "CA3", "4z1", "4z2", "4z3", "4c1", "4c2", "4c3", "4p1", "4p2", "4p3")
- region <- c("CA", "CA", "CA", "4z", "4z", "4z", "4c", "4c", "4c", "4p", "4p", "4p")
- data <- c("synaptosome","synaptosome","synaptosome","synaptosome","synaptosome","synaptosome","synaptosome","synaptosome","synaptosome","synaptosome","synaptosome","synaptosome")
- rat <- c("1", "2", "3", "4", "5", "6", "4", "5", "6", "4", "5", "6")
- condition <- c("control", "control", "control", "stroke", "stroke","stroke","stroke", "stroke", "stroke","stroke","stroke", "stroke")
- coldata_syn <- data.frame(files, data=rep, names=rep, region=region,rat = rat, condition=condition, stringsAsFactors=FALSE)
- coldata_syn$region <- as.factor(coldata_syn$region)
- coldata_syn$data <- as.factor(coldata_syn$data)
- coldata_syn$names <- as.factor(coldata_syn$names)
- coldata_syn$rat <- as.factor(coldata_syn$rat)
- coldata_syn$condition <- as.factor(coldata_syn$condition)
- # Build taxome file
- indexDir <- file.path("/Resources/Salmon_indexes/Rattus_norvegicus/salmon_index")
- fastaFTP <- c("/Resources/Salmon_indexes/Rattus_norvegicus")
- gtfPath <- file.path("/Resources/Rattus_norvegicus.mRatBN7.2.111.gtf.gz")
- makeLinkedTxome(indexDir=indexDir,
- source="LocalEnsembl",
- organism="Rattus norvegicus",
- release="111",
- genome="mRatBN7.2",
- fasta=fastaFTP,
- gtf=gtfPath,
- write=FALSE)
- # Syn
- se_syn <- tximeta(coldata_syn)
- edb <- retrieveDb(se_syn)
- k <- keys(edb, keytype = "TXNAME")
- tx2gene <- AnnotationDbi::select(edb, k, "GENEID", "TXNAME")
- txi <- tximport(files, type = "salmon", tx2gene = tx2gene, countsFromAbundance = "lengthScaledTPM", ignoreTxVersion = T)
- y <- DGEList(txi$counts)
- design <- model.matrix(~region, data = coldata_syn)
- isexpr <- filterByExpr(y, design)
- y <- y[isexpr, ]
- y <- calcNormFactors(y)
- param <- SnowParam(4, "SOCK", progressbar = TRUE)
- form <- ~ region
- # estimate weights using linear mixed model of dream
- vobjDream <- voomWithDreamWeights(y, form, coldata_syn, BPPARAM = param)
- write_tsv(as.data.frame(vobjDream$E) %>%
- mutate(gene = rownames(vobjDream$E)) %>%
- rename( CA1 = Sample1, CA2 = Sample2, CA3 = Sample3, "4z1" = Sample4,
- "4z2" = Sample5, "4z3" = Sample6, "4c1" = Sample7, "4c2" = Sample8,
- "4c3" = Sample9, "4p1" = Sample10, "4p2" = Sample11, "4p3" = Sample12),
- file = "q/VariancePartitioning/Syn_voomWithDreamWeights-normalised.txt")
- fitmm <- dream(vobjDream, form, coldata_syn, ddf = "Kenward-Roger")
- fitmm <- eBayes(fitmm)
- L <- makeContrastsDream(form, coldata_syn,
- contrasts = c(
- compare4c_4z = "region4c - region4z",
- compare4c_4p = "region4c - region4p",
- compare4z_4p = "region4z - region4p"))
- # fit dream model with contrasts
- fit <- dream(vobjDream, form, coldata_syn, L)
- fit <- eBayes(fit)
- compare4c_4z = topTable(fit, coef = "compare4c_4z", number = 47000)
- compare4c_4z$input = rownames(compare4c_4z)
- compare4c_4zGenes = gprofiler2::gconvert(rownames(compare4c_4z), organism = "rnorvegicus")
- compare4c_4z = left_join(compare4c_4z, compare4c_4zGenes, by = "input")
- compare4c_4p = topTable(fit, coef = "compare4c_4p", number = 47000)
- compare4c_4p$input = rownames(compare4c_4p)
- compare4c_4pGenes = gprofiler2::gconvert(rownames(compare4c_4p), organism = "rnorvegicus")
- compare4c_4p = left_join(compare4c_4p, compare4c_4pGenes, by = "input")
- compare4z_4p = topTable(fit, coef = "compare4z_4p", number = 47000)
- compare4z_4p$input = rownames(compare4z_4p)
- compare4z_4pGenes = gprofiler2::gconvert(rownames(compare4z_4p), organism = "rnorvegicus")
- compare4z_4p = left_join(compare4z_4p, compare4z_4pGenes, by = "input")
- volcano_res1 = EnhancedVolcano(compare4z_4p,
- lab = compare4z_4p$name,
- x = 'logFC',
- y = 'adj.P.Val',
- pCutoff = 0.05,
- FCcutoff = 1,
- xlim = c(-11, 11),
- ylim = c(0, 6),
- pointSize = 1.5,
- labSize = 3,
- title = '4z vs 4p in Syn',
- # subtitle = 'Differential expression',
- # caption = 'FC cutoff, 1; p-value cutoff, 10e-4',
- legendPosition = "right",
- legendLabSize = 14,
- col = c('grey30', '#E9E9E9', "#0072B2", '#D55E00'),
- colAlpha = 0.5,
- #drawConnectors = TRUE,
- hline = c(10e-8),
- widthConnectors = 0.5)
- volcano_res2 = EnhancedVolcano(compare4c_4z,
- lab = compare4c_4z$name,
- x = 'logFC',
- y = 'adj.P.Val',
- pCutoff = 0.05,
- FCcutoff = 1,
- xlim = c(-11, 11),
- ylim = c(0, 6),
- pointSize = 1.5,
- labSize = 3,
- title = '4c vs 4z in Syn',
- # subtitle = 'Differential expression',
- # caption = 'FC cutoff, 1; p-value cutoff, 10e-4',
- legendPosition = "right",
- legendLabSize = 14,
- col = c('grey30', '#E9E9E9', "#0072B2", '#D55E00'),
- colAlpha = 0.5,
- #drawConnectors = TRUE,
- hline = c(10e-8),
- widthConnectors = 0.5)
- volcano_res3 = EnhancedVolcano(compare4c_4p,
- lab = compare4c_4p$name,
- x = 'logFC',
- y = 'adj.P.Val',
- pCutoff = 0.05,
- FCcutoff = 1,
- xlim = c(-11, 11),
- ylim = c(0, 6),
- pointSize = 1.5,
- labSize = 3,
- title = '4c vs 4p in Syn',
- # subtitle = 'Differential expression',
- # caption = 'FC cutoff, 1; p-value cutoff, 10e-4',
- legendPosition = "right",
- legendLabSize = 14,
- col = c('grey30', '#E9E9E9', "#0072B2", '#D55E00'),
- colAlpha = 0.5,
- #drawConnectors = TRUE,
- hline = c(10e-8),
- widthConnectors = 0.5)
- down_genes_compare4z_4p <- compare4z_4p %>% filter(adj.P.Val <= 0.05 & (logFC < (-1)))
- up_genes_compare4z_4p <- compare4z_4p %>% filter(adj.P.Val <= 0.05 & (logFC > 1))
- gost_down_genes_compare4z_4p = gprofiler2::gost(down_genes_compare4z_4p$name, organism = "rnorvegicus")
- gost_up_genes_compare4z_4p = gprofiler2::gost(up_genes_compare4z_4p$name, organism = "rnorvegicus")
- down_genes_compare4c_4z <- compare4c_4z %>% filter(adj.P.Val <= 0.05 & (logFC < (-1)))
- up_genes_compare4c_4z <- compare4c_4z %>% filter(adj.P.Val <= 0.05 & (logFC > 1))
- gost_down_genes_compare4c_4z = gprofiler2::gost(down_genes_compare4c_4z$name, organism = "rnorvegicus")
- gost_up_genes_compare4c_4z = gprofiler2::gost(up_genes_compare4c_4z$name, organism = "rnorvegicus")
- down_genes_compare4c_4p <- compare4c_4p %>% filter(adj.P.Val <= 0.05 & (logFC < (-1)))
- up_genes_compare4c_4p <- compare4c_4p %>% filter(adj.P.Val <= 0.05 & (logFC > 1))
- gost_down_genes_compare4c_4p = gprofiler2::gost(down_genes_compare4c_4p$name, organism = "rnorvegicus")
- gost_up_genes_compare4c_4p = gprofiler2::gost(up_genes_compare4c_4p$name, organism = "rnorvegicus")
- ############ Each versus CA
- compare4c_CA = topTable(fit, coef = "region4c", number = 47000)
- compare4c_CA$input = rownames(compare4c_CA)
- compare4c_CAGenes = gprofiler2::gconvert(rownames(compare4c_CA), organism = "rnorvegicus")
- compare4c_CA = left_join(compare4c_CA, compare4c_CAGenes, by = "input")
- compare4p_CA = topTable(fit, coef = "region4p", number = 47000)
- compare4p_CA$input = rownames(compare4p_CA)
- compare4p_CAGenes <- gprofiler2::gconvert(rownames(compare4p_CA), organism = "rnorvegicus")
- compare4p_CA = left_join(compare4p_CA, compare4p_CAGenes, by = "input")
- compare4z_CA = topTable(fit, coef = "region4z", number = 47000)
- compare4z_CA$input = rownames(compare4z_CA)
- compare4z_CAGenes = gprofiler2::gconvert(rownames(compare4z_CA), organism = "rnorvegicus")
- compare4z_CA = left_join(compare4z_CA, compare4z_CAGenes, by = "input")
- volcano_res4 = EnhancedVolcano(compare4z_CA,
- lab = compare4z_CA$name,
- x = 'logFC',
- y = 'adj.P.Val',
- pCutoff = 0.05,
- FCcutoff = 1,
- xlim = c(-11, 11),
- ylim = c(0, 6),
- pointSize = 1.5,
- labSize = 3,
- title = '4z vs CA in Synaptosome',
- # subtitle = 'Differential expression',
- # caption = 'FC cutoff, 1; p-value cutoff, 10e-4',
- legendPosition = "right",
- legendLabSize = 14,
- col = c('grey30', '#E9E9E9', "#0072B2", '#D55E00'),
- colAlpha = 0.5,
- #drawConnectors = TRUE,
- hline = c(10e-8),
- widthConnectors = 0.5)
- volcano_res5 = EnhancedVolcano(compare4c_CA,
- lab = compare4c_CA$name,
- x = 'logFC',
- y = 'adj.P.Val',
- pCutoff = 0.05,
- FCcutoff = 1,
- xlim = c(-11, 11),
- ylim = c(0, 6),
- pointSize = 1.5,
- labSize = 3,
- title = '4c vs CA in Synaptosome',
- # subtitle = 'Differential expression',
- # caption = 'FC cutoff, 1; p-value cutoff, 10e-4',
- legendPosition = "right",
- legendLabSize = 14,
- col = c('grey30', '#E9E9E9', "#0072B2", '#D55E00'),
- colAlpha = 0.5,
- #drawConnectors = TRUE,
- hline = c(10e-8),
- widthConnectors = 0.5)
- volcano_res6 = EnhancedVolcano(compare4p_CA,
- lab = compare4p_CA$name,
- x = 'logFC',
- y = 'adj.P.Val',
- pCutoff = 0.05,
- FCcutoff = 1,
- xlim = c(-11, 11),
- ylim = c(0, 6),
- pointSize = 1.5,
- labSize = 3,
- title = '4p vs CA in Synaptosome',
- # subtitle = 'Differential expression',
- # caption = 'FC cutoff, 1; p-value cutoff, 10e-4',
- legendPosition = "right",
- legendLabSize = 14,
- col = c('grey30', '#E9E9E9', "#0072B2", '#D55E00'),
- colAlpha = 0.5,
- #drawConnectors = TRUE,
- hline = c(10e-8),
- widthConnectors = 0.5)
- # Filter significant genes in 4z vs CA
- up_genes_compare4z_CA <- compare4z_CA %>% filter(adj.P.Val <= 0.05 & (logFC > 1))
- down_genes_compare4z_CA <- compare4z_CA %>% filter(adj.P.Val <= 0.05 & (logFC < (-1)))
- gost_up_genes_compare4z_CA = gprofiler2::gost(up_genes_compare4z_CA$name, organism = "rnorvegicus", evcodes = T)
- gost_down_genes_compare4z_CA = gprofiler2::gost(down_genes_compare4z_CA$name, organism = "rnorvegicus", evcodes = T)
- gost_up_genes_compare4z_CA = gprofiler2::gost(up_genes_compare4z_CA$name, organism = "rnorvegicus")
- # Filter significant genes in 4c vs CA
- up_genes_compare4c_CA <- compare4c_CA %>% filter(adj.P.Val <= 0.05 & (logFC > 1))
- down_genes_compare4c_CA <- compare4c_CA %>% filter(adj.P.Val <= 0.05 & (logFC < (-1)))
- gost_up_genes_compare4c_CA = gprofiler2::gost(up_genes_compare4c_CA$name, organism = "rnorvegicus")
- gost_down_genes_compare4c_CA = gprofiler2::gost(down_genes_compare4c_CA$name, organism = "rnorvegicus")
- x = as.data.frame(up_genes_compare4c_CA$name)
- compare4c_CA_gost = gostplot(gost_down_genes_compare4c_CA, interactive = F)
- compare4c_CA_publ = publish_gostplot(compare4c_CA_gost)
- compare4c_CA_table = publish_gosttable(gost_down_genes_compare4c_CA, highlight_terms = gost_down_genes_compare4c_CA$result[c(1:20),],
- use_colors = TRUE,
- show_columns = c("source", "term_name", "term_size", "intersection_size"),
- filename = NULL)
- gost_up_genes_compare4c_CA = gprofiler2::gost(up_genes_compare4c_CA$name, organism = "rnorvegicus")
- compare4c_CA_up_gost = gostplot(gost_up_genes_compare4c_CA, interactive = F)
- compare4c_CA_up_publ = publish_gostplot(compare4c_CA_up_gost)
- compare4c_CA_up_table = publish_gosttable(gost_up_genes_compare4c_CA, highlight_terms = gost_up_genes_compare4c_CA$result[c(1:20),],
- use_colors = TRUE,
- show_columns = c("source", "term_name", "term_size", "intersection_size"),
- filename = NULL) +
- labs(title = "Upregulated genes 4c versus CA")
- # Filter significant genes in 4p vs CA
- up_genes_compare4p_CA <- compare4p_CA %>% filter(adj.P.Val <= 0.05 & (logFC > 1))
- down_genes_compare4p_CA <- compare4p_CA %>% filter(adj.P.Val <= 0.05 & (logFC < (-1)))
- gost_up_genes_compare4p_CA = gprofiler2::gost(up_genes_compare4p_CA$name, organism = "rnorvegicus", evcodes = T)
- gost_down_genes_compare4p_CA = gprofiler2::gost(down_genes_compare4p_CA$name, organism = "rnorvegicus", evcodes = T)
- x = as.data.frame(up_genes_compare4p_CA$name)
- compare4p_CA_gost = gostplot(gost_down_genes_compare4p_CA, interactive = F)
- compare4p_CA_publ = publish_gostplot(compare4p_CA_gost)
- compare4p_CA_table = publish_gosttable(gost_down_genes_compare4p_CA, highlight_terms = gost_down_genes_compare4p_CA$result[c(1:20),],
- use_colors = TRUE,
- show_columns = c("source", "term_name", "term_size", "intersection_size"),
- filename = NULL)
- gost_up_genes_compare4p_CA = gprofiler2::gost(up_genes_compare4p_CA$name, organism = "rnorvegicus")
- compare4p_CA_up_gost = gostplot(gost_up_genes_compare4p_CA, interactive = F)
- compare4p_CA_up_publ = publish_gostplot(compare4p_CA_up_gost)
- compare4p_CA_up_table = publish_gosttable(gost_up_genes_compare4p_CA, highlight_terms = gost_up_genes_compare4p_CA$result[c(1:20),],
- use_colors = TRUE,
- show_columns = c("source", "term_name", "term_size", "intersection_size"),
- filename = NULL) +
- labs(title = "Upregulated genes 4p versus CA")
- ################################################################################
- ########## Plot to file
- #file_path <- "/VariancePartitioning/VariancePartition_Syn.pdf"
- pdf(file_path, width = 14, height = 12)
- plot(pca$x, cex = 4.0, col = c("#2f4f4f",
- "#228b22",
- "#7f0000",
- "#00008b"), pch = 18)
- legend(
- "topright",
- bty = "n",
- c("CA", "4z", "4c","4p"),
- fill = c("#2f4f4f",
- "#228b22",
- "#7f0000",
- "#00008b"),
- cex = 3.0)
- plot(tree)
- plotVarPart(vp)
- plotContrasts(L)
- plotPercentBars(vp[1:100, ])
- heatmap(syn_matrix)
- volcano_res1
- compare4z_4p_publ
- cat("Downreg in 4z versus 4p")
- compare4z_4p_table
- volcano_res2
- compare4c_4z_publ
- cat("Downreg in 4c versus 4z")
- compare4c_4z_table
- volcano_res3
- compare4c_4p_publ
- cat("Downreg in 4c versus 4p")
- compare4c_4p_table
- volcano_res4
- compare4z_CA_publ
- cat("Downreg in 4z versus CA")
- compare4z_CA_table
- cat("Upreg in 4z versus CA")
- compare4z_CA_up_publ
- compare4z_CA_up_table
- volcano_res5
- compare4c_CA_publ
- cat("Downreg in 4c versus CA")
- compare4c_CA_table
- cat("Upreg in 4c versus CA")
- compare4c_CA_up_publ
- compare4c_CA_up_table
- volcano_res6
- compare4p_CA_publ
- cat("Downreg in 4p versus CA")
- compare4p_CA_table
- cat("Upreg in 4p versus CA")
- compare4p_CA_up_publ
- compare4p_CA_up_table
- dev.off()
- ################################################################################
- ###################### Gene set enrichment analysis ############################
- library(GSVA)
- library(fgsea)
- library(GSEABase)
- library(readxl)
- library(dendextend)
- library(gplots)
- # Path to your Excel file with genes of interest
- xlsx_file <- "/Other_resources/mmc2.xlsx"
- # Add novel genes (Synapsed enriched novel)
- xlsx_file2 <- "/Other_resources/mmc2.xlsx"
- xlsx_file3 <- "/Other_resources/GeneSets_Synaptic_Presynaptic.xlsx"
- # Read the first/second sheet of the Excel file, and convert names
- # to match the expression matrix
- df = read_excel(xlsx_file, sheet = 1) %>% dplyr::select(GeneName, SynapseType)
- df2 = read_excel(xlsx_file, sheet = 2) %>% dplyr::select("hgnc symbol") %>%
- mutate(SynapseType = "Oostrum2023_novel") %>% rename(GeneName = "hgnc symbol")
- df3 = read_excel(xlsx_file3, sheet = 1) %>% pivot_longer(cols = c(Presynaptic, Postsynaptic),
- names_to = "SynapseType", values_to = "GeneName")
- df = rbind(df, df2, df3)
- df_ens = gprofiler2::gconvert(df$GeneName, organism = "rnorvegicus")
- df = left_join(df, df_ens, by = c("GeneName"="input")) %>% dplyr::select(target, SynapseType) %>% unique()
- # Define gene sets
- gene_set <- list()
- # Loop through unique entries in SynapseType
- unique_entries <- unique(df$SynapseType)
- for(entry in unique_entries) {
- # Extract values from GeneName corresponding to current SynapseType
- values <- df$target[df$SynapseType == entry]
- # Assign values to the list with name as current SynapseType
- gene_set[[entry]] <- values
- }
- # Convert to GeneSetCollection
- gene_set_list <- lapply(names(gene_set), function(x) GeneSet(setName = x, geneIds = gene_set[[x]]))
- ################################################################################
- gsc <- GeneSetCollection(gene_set_list)
- ################################################################################
- # Perform GSVA on voomWithDream normaalized counts (log2-counts per million (logCPM))
- colnames(vobjDream$E) = rep
- vobjDream_E = as.data.frame(vobjDream$E)
- vobjDream_E$genes = rownames(vobjDream_E)
- converted = gprofiler2::gconvert(rownames(vobjDream_E), organism = "rnorvegicus")
- vobjDream_E = left_join(vobjDream_E, converted, by = c("genes" = "input"))
- vobjDream_E = vobjDream_E[,c("name","CA1","CA2","CA3","4z1","4z2","4z3","4c1",
- "4c2","4c3","4p1","4p2","4p3")]
- vobjDream_E2 = as.matrix(vobjDream_E[,2:13])
- rownames(vobjDream_E2) = vobjDream_E$name
- vobjDream_E = as.data.frame(vobjDream$E)
- ################################################################################
- unique_genes_Oostrum23 <- unique(unlist(gene_set))
- unique_genes_Oostrum23_symbols = gprofiler2::gconvert(unique_genes_Oostrum23, organism = "rnorvegicus")
- Oostrum23_geneExpr = vobjDream_E2[rownames(vobjDream_E2) %in% unique_genes_Oostrum23_symbols$name,]
- ################################################################################
- gsva_res <- gsva(vobjDream$E, gsc, method = "gsva", kcdf = "Poisson", mx.diff = TRUE, verbose = FALSE)
- # Create design matrix
- design <- model.matrix(~ region, data = coldata_syn)
- # fit dream model with contrasts
- fit2 <- dream(gsva_res, form, coldata_syn, L)
- fit2 <- eBayes(fit2)
- # Get differential analysis results
- results4p_CA <- topTable(fit2, coef="region4p", adjust.method="BH", number=Inf)
- results4c_CA <- topTable(fit2, coef="region4c", adjust.method="BH", number=Inf)
- results4z_CA <- topTable(fit2, coef="region4z", adjust.method="BH", number=Inf)
- pca2 = prcomp(gsva_res)
- pca3 = prcomp(t(gsva_res))
- pca4 = prcomp(t(Oostrum23_geneExpr))
- ################################################################################
- ########## Correlation between terms
- # Filter gene sets to include only genes present in the gene expression matrix
- gene_sets <- lapply(gene_set, function(genes) {
- genes[genes %in% rownames(vobjDream_E)]
- })
- # Aggregate expression values for each gene set
- aggregate_expression <- sapply(gene_sets, function(genes) {
- if (length(genes) > 0) {
- colMeans(vobjDream_E[genes, , drop = FALSE])
- } else {
- rep(NA, ncol(vobjDream_E)) # Handle gene sets with no genes present in the data
- }
- })
- # Remove any columns with NA values (gene sets with no genes present in the data)
- aggregate_expression <- aggregate_expression[, colSums(is.na(aggregate_expression)) == 0]
- # Compute the correlation matrix for the aggregated expression values of the gene sets
- correlation_matrix <- cor(aggregate_expression)
- # Print the correlation matrix
- print(correlation_matrix)
- ################################################################################
- ########## Plot to file
- file_path <- "/GeneSet_Enrichments/Heaatmap_GeneSetOostrum2023_and_fromOleg_Syn.pdf"
- pdf(file_path, width = 18, height = 12)
- library(RColorBrewer)
- # Define color palette for heatmap
- colorLegend <- c("#0072B2", "#D55E00", "#CC79A7","#F0E442")
- #0072B2 (blue)
- #CC79A7 (pinky purple)
- #D55E00 (orange)
- #F0E442 (yellow)
- names(colorLegend) <- c("CA", "4z", "4c", "4p")
- sample.color.map <- colorLegend[coldata_syn$region]
- coldata_syn$rep <- rep
- names(sample.color.map) <- coldata_syn$rep
- sample.color.map["4z1"] = "#D55E00"
- sample.color.map["4z2"] = "#D55E00"
- sample.color.map["4z3"] = "#D55E00"
- sample.color.map["4p1"] = "#F0E442"
- sample.color.map["4p2"] = "#F0E442"
- sample.color.map["4p3"] = "#F0E442"
- sample.color.map["4c1"] = "#CC79A7"
- sample.color.map["4c2"] = "#CC79A7"
- sample.color.map["4c3"] = "#CC79A7"
- heatmap_colors <- colorRampPalette(c("lightblue", "white", "#FF457D"))(n = 1000)
- # Cluster the samples and gene terms
- geneSetClustering <- hclust(dist(gsva_res, method = "euclidean"), method = "complete")
- sampleClustering <- hclust(dist(t(gsva_res), method = "euclidean"), method = "complete")
- # Convert hclust objects to dendrograms
- geneSetDendrogram <- as.dendrogram(geneSetClustering)
- sampleDendrogram <- as.dendrogram(sampleClustering)
- sampleDendrogram <- rotate(sampleDendrogram, order = c("4p3", "4p1", "4p2",
- "4c2", "4c1", "4c3",
- "CA1", "CA2", "CA3",
- "4z2", "4z3", "4z1"))
- # Function to rotate a specific branch of a dendrogram given a path
- rotate_branch <- function(dend, path) {
- if (length(path) == 0) return(rev(dend))
- if (is.leaf(dend)) return(dend)
- branch_index <- path[1]
- dend[[branch_index]] <- rotate_branch(dend[[branch_index]], path[-1])
- dend
- }
- # Path to the [[2]][[2]][[1]] branch
- branch_path <- c(2, 2, 1)
- # Sample dendrogram (for demonstration purposes)
- # Create a sample dendrogram if needed
- # sampleDendrogram <- as.dendrogram(hclust(dist(USArrests), "ave"))
- # Rotate the specified branch
- sampleDendrogram <- rotate_branch(sampleDendrogram, branch_path)
- # Create heatmap with adjusted parameters
- heatmap(as.matrix(gsva_res),
- ColSideColors = sample.color.map,
- xlab = " ",
- ylab = " ",
- margins = c(5, 5),
- labRow = gsub("_", " ", rownames(gsva_res)), # Remove only "_"
- labCol = colnames(gsva_res),
- scale = "row",
- Colv = sampleDendrogram,
- Rowv = geneSetDendrogram,
- col = heatmap_colors,
- cexRow = 0.8, # 2 for gene set enrichment but 0.8 for cell type enrichment
- cexCol = 2,
- cex.lab = 2)
- # Add legend for heatmap colors
- min_value <- as.numeric(min(gsva_res))
- max_value <- as.numeric(max(gsva_res))
- mid_value <- (min_value + max_value) / 2
- min_value <- round(min_value, 3)
- max_value <- round(max_value, 3)
- mid_value <- round(mid_value, 3)
- # Create legend labels
- legend_labels <- c(min_value, mid_value, max_value)
- # Add legend for regions/reps
- legend("topleft", legend = names(colorLegend), fill = colorLegend, title = "Sections", cex = 1.5, bty = "n", inset = 0.05)
- # Legend plot for values
- legend("left", legend = legend_labels, fill = colorRampPalette(c("lightblue", "white", "#FF457D"))(n = 3), title = "Enrichment values", cex = 1.5, bty = "n", inset = 0.05)
- ################################################################################
- ########################## Samples PCA based on gene set/term enrichment scoring
- pca_data <- as.data.frame(pca3$x)
- pca_data$sample <- rownames(pca_data)
- # Assign colors to samples
- pca_data$color <- c("#0072B2","#0072B2","#0072B2", # blue
- "#D55E00","#D55E00","#D55E00", #orange
- "#CC79A7","#CC79A7","#CC79A7", #pinky purple
- "#F0E442","#F0E442","#F0E442") #yellow
- custom_colors <- c("#0072B2", "#CC79A7","#D55E00", "#F0E442")
- # Plot the PCA
- ggplot(pca_data, aes(x = PC1, y = PC2, label = sample, color = color)) +
- geom_point(size = 5) + # Adjust point size
- geom_text(vjust = 1.5, hjust = 1.5, size = 5) + # Adjust font size
- labs(title = "PCA of Gene Set Enrichment Scores (Samples)",
- x = "Principal Component 1",
- y = "Principal Component 2") +
- scale_color_manual(values = custom_colors) +
- theme_minimal() +
- theme(aspect.ratio = 1, # Make the plot square
- plot.title = element_text(size = 16), # Adjust title font size
- axis.title = element_text(size = 14), # Adjust axis titles font size
- axis.text = element_text(size = 12), # Adjust axis text font size
- legend.position = "none") # Remove legend
- ################################################################################
- ##################### Terms
- pca_data2 <- as.data.frame(pca2$x)
- pca_data2$sample <- rownames(pca_data2)
- base_colors <- brewer.pal(8, "Set1") # Use "Set1" for a vibrant color set
- custom_colors2 <- colorRampPalette(base_colors)(18)
- # Create a named vector for custom colors
- names(custom_colors2) <- rownames(pca_data2)
- # Plot the PCA
- ggplot(pca_data2, aes(x = PC1, y = PC2, label = sample, color = sample)) +
- geom_point(size = 5) + # Adjust point size
- geom_text_repel(aes(label = sample), size = 5, nudge_x = 0.05, direction = "y", hjust = 0) + # Adjust text label position
- labs(title = "PCA of Gene Set Enrichment Scores",
- x = "Principal Component 1",
- y = "Principal Component 2") +
- scale_color_manual(values = custom_colors2) +
- theme_minimal() +
- theme(aspect.ratio = 1, # Make the plot square
- plot.title = element_text(size = 16), # Adjust title font size
- axis.title = element_text(size = 14), # Adjust axis titles font size
- axis.text = element_text(size = 12), # Adjust axis text font size
- legend.position = "none") # Remove legend
- ################################################################################
- ############################ Gene expression fo teh genes in the terms/gene sets
- pca_data4 <- as.data.frame(pca4$x)
- pca_data4$sample <- rownames(pca_data4)
- # Assign colors to samples
- pca_data4$color <- c("#0072B2","#0072B2","#0072B2", # blue
- "#D55E00","#D55E00","#D55E00", #orange
- "#CC79A7","#CC79A7","#CC79A7", #pinky purple
- "#F0E442","#F0E442","#F0E442") #yellow
- custom_colors4 <- c("#0072B2","#0072B2","#0072B2", # blue
- "#D55E00","#D55E00","#D55E00", #orange
- "#CC79A7","#CC79A7","#CC79A7", #pinky purple
- "#F0E442","#F0E442","#F0E442") #yellow
- names(custom_colors4) <- pca_data4$sample
- # Plot the PCA
- ggplot(pca_data4, aes(x = PC1, y = PC2, label = sample, color = sample)) +
- geom_point(size = 5) + # Adjust point size
- geom_text_repel(aes(label = sample), size = 5, nudge_x = 0.05, direction = "y", hjust = 0) + # Adjust text label position
- labs(title = "PCA of Gene Set Expression",
- x = "Principal Component 1",
- y = "Principal Component 2") +
- scale_color_manual(values = custom_colors4) +
- theme_minimal() +
- theme(aspect.ratio = 1, # Make the plot square
- plot.title = element_text(size = 16), # Adjust title font size
- axis.title = element_text(size = 14), # Adjust axis titles font size
- axis.text = element_text(size = 12), # Adjust axis text font size
- legend.position = "none") # Remove legend
- heatmap.2(Oostrum23_geneExpr,
- trace = "none",
- col = heatmap_colors,
- margins = c(10, 10),
- key = TRUE,
- keysize = 1,
- density.info = "none",
- dendrogram = "none",
- main = "Heatmap of Gene Sets Gene Expression",
- Colv = FALSE,
- Rowv = FALSE)
- # Same thing as above, different format:
- heatmap(Oostrum23_geneExpr,
- col = heatmap_colors, Colv = NULL, Rowv = NULL)
- # Add legend for heatmap colors
- min_value <- as.numeric(min(Oostrum23_geneExpr))
- max_value <- as.numeric(max(Oostrum23_geneExpr))
- mid_value <- (min_value + max_value) / 2
- min_value <- round(min_value, 3)
- max_value <- round(max_value, 3)
- mid_value <- round(mid_value, 3)
- # Create legend labels
- legend_labels <- c(min_value, mid_value, max_value)
- # Legend plot for values
- legend("left", legend = legend_labels,
- fill = colorRampPalette(c("lightblue", "white", "#FF457D"))(n = 3),
- title = expression("Log"[2]*"CPM values"),
- cex = 1.5, bty = "n", inset = 0.05)
- ################## Correlation of terms expression
- # Define your color palette
- colorLegend <- c("#0072B2", "#D55E00", "#CC79A7", "#F0E442")
- names(colorLegend) <- c("CA", "4z", "4c", "4p")
- # Generate heatmap colors
- heatmap_colors <- colorRampPalette(c("lightblue", "white", "#FF457D"))(n = 1000)
- # Define the color breaks for the heatmap
- breaks <- seq(min(correlation_matrix, na.rm = TRUE), max(correlation_matrix, na.rm = TRUE), length.out = length(heatmap_colors) + 1)
- # Create the heatmap
- heatmap.2(
- correlation_matrix,
- col = heatmap_colors,
- breaks = breaks,
- trace = "none",
- margins = c(20, 20),
- main = "Correlation Matrix of Gene Sets (expression aggregated across samples)",
- key = TRUE,
- keysize = 1.5,
- dendrogram = "none",
- Colv = FALSE,
- Rowv = FALSE
- )
- ###################
- correlation_matrix2 = cor(t(gsva_res))
- # Plot the correlation heatmap
- heatmap.2(correlation_matrix2,
- trace = "none",
- col = bluered(256),
- margins = c(8, 8),
- main = "Correlation Matrix of Gene Sets (enrichment scoring)",
- density.info = "none")
- ###################
- # Ensure your gene sets contain only genes present in the gene expression matrix
- gene_sets <- lapply(gene_set, function(genes) {
- genes[genes %in% rownames(vobjDream_E)]
- })
- # Initialize a matrix to store average expressions per gene set per sample
- avg_expression_matrix <- matrix(NA, nrow = length(gene_sets), ncol = ncol(vobjDream_E))
- rownames(avg_expression_matrix) <- names(gene_sets)
- colnames(avg_expression_matrix) <- colnames(vobjDream_E)
- # Calculate the average expression for each gene set per sample
- for (i in seq_along(gene_sets)) {
- genes <- gene_sets[[i]]
- if (length(genes) > 0) {
- avg_expression_matrix[i, ] <- colMeans(vobjDream_E[genes, , drop = FALSE])
- }
- }
- # Compute the correlation matrix for the averaged expression values per sample
- correlation_matrix <- cor(t(avg_expression_matrix), use = "complete.obs")
- # Print the correlation matrix
- print(correlation_matrix)
- # Plot the correlation matrix as a heatmap
- heatmap.2(correlation_matrix,
- trace = "none",
- col = colorRampPalette(brewer.pal(9, "Blues"))(256),
- margins = c(8, 8),
- main = "Correlation Matrix of Gene Sets (gene expression average per sample)",
- density.info = "none",
- key.title = "Correlation",
- key.xlab = "Correlation",
- cexRow = 0.7,
- cexCol = 0.7)
- dev.off()
- ############## Plotting main figure 4p vs CA
- # Define colorblind-friendly colors manually
- PCA_colors <- c("#000000", # Black (for CA)
- "#000000", # Black (for CA)
- "#000000", # Black (for CA)
- "#D55E00", # Orange (for 4z)
- "#D55E00", # Orange (for 4z)
- "#D55E00", # Orange (for 4z)
- "#0072B2", # Sky Blue (for 4c)
- "#0072B2", # Sky Blue (for 4c)
- "#0072B2", # Sky Blue (for 4c)
- "#CC79A7", # Magenta (for 4p)
- "#CC79A7", # Magenta (for 4p)
- "#CC79A7") # Magenta (for 4p)
- pca_all = prcomp(t(syn_matrix))
- pca_data_all <- as.data.frame(pca_all$x)
- pca_data_all$sample <- rownames(pca_data_all)
- names(PCA_colors) <- pca_data_all$sample
- # Plot the PCA
- PCA_4p_CA_1 = ggplot(pca_data_all, aes(x = PC1, y = PC2, label = sample, color = sample)) +
- geom_point(size = 10) + # Adjust point size
- geom_text_repel(aes(label = sample), size = 15, nudge_x = 0.05, direction = "y", hjust = 0) + # Adjust text label position
- labs(x = "Principal Component 1",
- y = "Principal Component 2") +
- scale_color_manual(values = PCA_colors) +
- theme_minimal() +
- theme(
- aspect.ratio = 1, # Make the plot square
- plot.title = element_text(size = 35), # Adjust title font size
- axis.title = element_text(size = 40), # Adjust axis titles font size
- axis.text = element_text(size = 35), # Adjust axis text font size
- legend.position = "none", # Remove legend
- panel.grid.major = element_line(color = "grey90"), # Adjust major grid lines
- panel.grid.minor = element_line(color = "grey60"), # Adjust minor grid lines
- panel.border = element_rect(color = "black", fill = NA, size = 1) # Add a black border around the plot
- )
- pdf("/VariancePartitioning/4p_vs_CA_PCA_VariancePartition_Syn.pdf",
- width = 13.5, height = 12.5, bg = "transparent")
- print(PCA_4p_CA_1)
- dev.off() # Close the device
- volcano_syn_4p_CA = EnhancedVolcano(compare4p_CA,
- lab = compare4p_CA$name,
- subtitle = NULL,
- x = 'logFC',
- y = 'adj.P.Val',
- pCutoff = 0.05,
- FCcutoff = 1,
- xlim = c(-9, 11),
- ylim = c(0, 6),
- pointSize = 1.5,
- axisLabSize = 35,
- labSize = 10,
- title = NULL,
- legendPosition = "top",
- legendLabSize = 35,
- legendLabels = c("NS", expression(Log[2] ~ FC), "p-value", expression("p-value" ~ and
- ~ log[2] ~ FC)),
- col = c('grey30', '#E9E9E9', "#0072B2", '#D55E00'),
- colAlpha = 0.7,
- #drawConnectors = TRUE,
- widthConnectors = 0.5)
- pdf("/VariancePartitioning/4p_vs_CA_Volcano_VariancePartition_Syn.pdf",
- width = 17.5, height = 13.5, bg = "transparent")
- print(volcano_syn_4p_CA)
- dev.off() # Close the device
- #Prepare the data frame for up genes
- Syn_4p_CA_up_genes <- gost_up_genes_compare4p_CA$result %>%
- filter(source %in% c("GO:BP", "GO:CC", "GO:MF", "KEGG")) %>%
- mutate(Ratio = intersection_size / term_size) %>%
- group_by(source) %>%
- slice_min(p_value, n = 7) %>%
- ungroup() %>%
- mutate(term_name = factor(term_name, levels = unique(term_name))) # Maintain original order
- # Plot for down genes GO
- Bubble_4p_CA_1 <- ggplot(Syn_4p_CA_up_genes, aes(x = Ratio, y = term_name)) +
- geom_point(aes(size = intersection_size, color = -log10(p_value)), alpha = 0.7) +
- scale_color_gradient(
- low = "#0072B2",
- high = "#D55E00",
- breaks = c(min(-log10(Syn_4p_CA_up_genes$p_value)),
- max(-log10(Syn_4p_CA_up_genes$p_value))),
- labels = c(
- paste0(round(min(-log10(Syn_4p_CA_up_genes$p_value)), 2)),
- paste0(round(max(-log10(Syn_4p_CA_up_genes$p_value)), 2))
- )
- ) + # Color based on p-value with custom breaks
- scale_size(range = c(5, 10)) + # Adjust bubble sizes
- labs(size = "Intersection Size\n", color = "-log10(p-value)\n", y = NULL) + # Axis and legend labels
- theme_minimal() + # Clean theme
- theme(
- axis.text.y = element_text(size = 35), # Adjust y-axis text size
- axis.text.x = element_text(size = 30, hjust = 1), # Adjust x-axis text size and angle
- axis.title.x = element_text(size = 35), # Adjust x-axis title size
- legend.title = element_text(size = 30), # Font size of legend title
- legend.text = element_text(size = 25),
- legend.spacing.y = unit(2, "cm") # Increase spacing between legend title and text
- )
- pdf("/VariancePartitioning/4p_vs_CA_BubbleUp_VariancePartition_Syn.pdf",
- width = 22.5, height = 13.5, bg = "transparent")
- print(Bubble_4p_CA_1)
- dev.off() # Close the device
- # Apply the updated code for down genes without text wrapping < sorta better
- Syn_4p_CA_down_genes <- gost_down_genes_compare4p_CA$result %>%
- filter(source %in% c("GO:BP", "GO:CC", "GO:MF", "KEGG")) %>%
- mutate(Ratio = intersection_size / term_size) %>%
- group_by(source) %>%
- slice_min(p_value, n = 7) %>%
- ungroup() %>%
- mutate(term_name = factor(term_name, levels = unique(term_name))) # Maintain original order
- # Plot for down genes GO
- Bubble_4p_CA_2 <- ggplot(Syn_4p_CA_down_genes, aes(x = Ratio, y = term_name)) +
- geom_point(aes(size = intersection_size, color = -log10(p_value)), alpha = 0.7) +
- scale_color_gradient(
- low = "#0072B2",
- high = "#D55E00",
- breaks = c(min(-log10(Syn_4p_CA_down_genes$p_value)),
- max(-log10(Syn_4p_CA_down_genes$p_value))),
- labels = c(
- paste0(round(min(-log10(Syn_4p_CA_down_genes$p_value)), 2)),
- paste0(round(max(-log10(Syn_4p_CA_down_genes$p_value)), 2))
- )
- ) + # Color based on p-value with custom breaks
- scale_size(range = c(5, 10)) + # Adjust bubble sizes
- labs(size = "Intersection Size\n", color = "-log10(p-value)\n", y = NULL) + # Axis and legend labels
- theme_minimal() + # Clean theme
- theme(
- axis.text.y = element_text(size = 35), # Adjust y-axis text size
- axis.text.x = element_text(size = 30, hjust = 1), # Adjust x-axis text size and angle
- axis.title.x = element_text(size = 35), # Adjust x-axis title size
- legend.title = element_text(size = 30), # Font size of legend title
- legend.text = element_text(size = 25),
- legend.spacing.y = unit(2, "cm") # Increase spacing between legend title and text
- )
- pdf("/VariancePartitioning/4p_vs_CA_BubbleDown_VariancePartition_Syn.pdf",
- width = 22.5, height = 13.5, bg = "transparent")
- print(Bubble_4p_CA_2)
- dev.off() # Close the device
- # Create bubble plot of gene set enrichments
- gsva_res2 <- as.data.frame(gsva_res)
- # Convert row names to a column
- gsva_res2 <- gsva_res2 %>%
- tibble::rownames_to_column(var = "geneset")
- # Convert matrix to long format and add value column
- long_data <- gsva_res2 %>%
- pivot_longer(
- cols = -geneset, # Exclude the geneset column from pivoting
- names_to = "replicate",
- values_to = "enrichment_score"
- ) %>%
- filter(!is.na(enrichment_score)) %>% # Remove NA values if any
- mutate(value = enrichment_score, # Example: scaling enrichment score
- label = sprintf("%.2f", value)) # Format values to 2 decimal places
- # Create heatmap of gene set enrichments
- Genesets_4p_CA_heatmap = ggplot(long_data, aes(x = replicate, y = geneset, fill = enrichment_score)) +
- geom_tile(color = "white") + # Create heatmap tiles with white borders between cells
- scale_fill_gradient2(low = "#0072B2", mid = "white", high = "#D55E00", midpoint = 0, limits = c(min(long_data$enrichment_score), max(long_data$enrichment_score))) + # Color gradient with white midpoint
- geom_text(aes(label = label), color = "white", size = 10, vjust = 0.5, fontface = "bold") + # Add text labels inside tiles
- labs(
- x = "Replicates",
- y = "Gene Sets",
- fill = "GSVA\nEnrichment Score" # Use newline character (\n) to split the legend title
- ) +
- theme_minimal() + # Use minimal theme for a clean look
- theme(
- axis.text.x = element_text(size = 25), # Increase x-axis text size
- axis.text.y = element_text(size = 35), # Increase y-axis text size
- axis.title.x = element_text(size = 35), # Increase x-axis title size
- axis.title.y = element_text(size = 35), # Increase y-axis title size
- plot.title = element_text(size = 25, face = "bold"), # Increase plot title size and make it bold
- legend.title = element_text(size = 30), # Font size of legend title
- legend.text = element_text(size = 30),
- legend.position = "right" # Position the legend on the right
- )
- pdf("/VariancePartitioning/4p_vs_CA_GeneSetsGSVAHeatmap_VariancePartition_Syn.pdf",
- width = 24, height = 16, bg = "transparent")
- #print(Genesets_4p_CA)
- print(Genesets_4p_CA_heatmap)
- dev.off() # Close the device
- ################################################################################
- ############## Plotting supplementary figure 4z vs CA
- volcano_syn_4z_CA = EnhancedVolcano(compare4z_CA,
- lab = compare4z_CA$name,
- subtitle = NULL,
- x = 'logFC',
- y = 'adj.P.Val',
- pCutoff = 0.05,
- FCcutoff = 1,
- xlim = c(-9, 11),
- ylim = c(0, 6),
- pointSize = 1.5,
- axisLabSize = 35,
- labSize = 10,
- title = NULL,
- legendPosition = "top",
- legendLabSize = 35,
- legendLabels = c("NS", expression(Log[2] ~ FC), "p-value", expression("p-value" ~ and
- ~ log[2] ~ FC)),
- col = c('grey30', '#E9E9E9', "#0072B2", '#D55E00'),
- colAlpha = 0.7,
- drawConnectors = TRUE,
- arrowheads = FALSE,
- max.overlaps = 15,
- widthConnectors = 0.5)
- pdf("/VariancePartitioning/4z_vs_CA_Volcano_VariancePartition_Syn.pdf",
- width = 17.5, height = 13.5, bg = "transparent")
- print(volcano_syn_4z_CA)
- dev.off() # Close the device
- # Apply the updated code for up genes with additional filtering and calculations
- Syn_4z_CA_up_genes <- gost_up_genes_compare4z_CA$result %>%
- filter(source %in% c("GO:BP", "GO:CC", "GO:MF", "KEGG")) %>%
- mutate(Ratio = intersection_size / term_size) %>%
- group_by(source) %>%
- slice_min(p_value, n = 12) %>%
- ungroup() %>%
- mutate(term_name = factor(term_name, levels = unique(term_name))) # Maintain original order
- # Plot for down genes GO
- Bubble_4z_CA_1 <- ggplot(Syn_4z_CA_up_genes, aes(x = Ratio, y = term_name)) +
- geom_point(aes(size = intersection_size, color = -log10(p_value)), alpha = 0.7) +
- scale_color_gradient(
- low = "#0072B2",
- high = "#D55E00",
- breaks = c(min(-log10(Syn_4z_CA_up_genes$p_value)),
- max(-log10(Syn_4z_CA_up_genes$p_value))),
- labels = c(
- paste0(round(min(-log10(Syn_4z_CA_up_genes$p_value)), 2)),
- paste0(round(max(-log10(Syn_4z_CA_up_genes$p_value)), 2))
- )
- ) + # Color based on p-value with custom breaks
- scale_size(range = c(5, 10)) + # Adjust bubble sizes
- labs(size = "Intersection Size\n", color = "-log10(p-value)\n", y = NULL) + # Axis and legend labels
- theme_minimal() + # Clean theme
- theme(
- axis.text.y = element_text(size = 35), # Adjust y-axis text size
- axis.text.x = element_text(size = 30, hjust = 1), # Adjust x-axis text size and angle
- axis.title.x = element_text(size = 35), # Adjust x-axis title size
- legend.title = element_text(size = 30), # Font size of legend title
- legend.text = element_text(size = 25),
- legend.spacing.y = unit(2, "cm") # Increase spacing between legend title and text
- )
- pdf("/VariancePartitioning/4z_vs_CA_BubbleUp_VariancePartition_Syn.pdf",
- width = 22.5, height = 13.5, bg = "transparent")
- print(Bubble_4z_CA_1)
- dev.off() # Close the device
- # Apply the updated code for down genes without text wrapping
- Syn_4z_CA_down_genes <- gost_down_genes_compare4z_CA$result %>%
- filter(source %in% c("GO:BP", "GO:CC", "GO:MF", "KEGG")) %>%
- mutate(Ratio = intersection_size / term_size) %>%
- group_by(source) %>%
- slice_min(p_value, n = 7) %>%
- ungroup() %>%
- mutate(term_name = factor(term_name, levels = unique(term_name))) # Maintain original order
- # Plot for down genes GO
- Bubble_4z_CA_2 <- ggplot(Syn_4z_CA_down_genes, aes(x = Ratio, y = term_name)) +
- geom_point(aes(size = intersection_size, color = -log10(p_value)), alpha = 0.7) +
- scale_color_gradient(
- low = "#0072B2",
- high = "#D55E00",
- breaks = c(min(-log10(Syn_4z_CA_down_genes$p_value)),
- max(-log10(Syn_4z_CA_down_genes$p_value))),
- labels = c(
- paste0(round(min(-log10(Syn_4z_CA_down_genes$p_value)), 2)),
- paste0(round(max(-log10(Syn_4z_CA_down_genes$p_value)), 2))
- )
- ) + # Color based on p-value with custom breaks
- scale_size(range = c(5, 10)) + # Adjust bubble sizes
- labs(size = "Intersection Size\n", color = "-log10(p-value)\n", y = NULL) + # Axis and legend labels
- theme_minimal() + # Clean theme
- theme(
- axis.text.y = element_text(size = 35), # Adjust y-axis text size
- axis.text.x = element_text(size = 30, hjust = 1), # Adjust x-axis text size and angle
- axis.title.x = element_text(size = 35), # Adjust x-axis title size
- legend.title = element_text(size = 30), # Font size of legend title
- legend.text = element_text(size = 25),
- legend.spacing.y = unit(2, "cm") # Increase spacing between legend title and text
- )
- pdf("/VariancePartitioning/4z_vs_CA_BubbleDown_VariancePartition_Syn.pdf",
- width = 22.5, height = 10, bg = "transparent")
- print(Bubble_4z_CA_2) # Print the plot to the PNG device
- dev.off() # Close the device
- ################################################################################
- ############## Plotting supplementary figure 4c vs CA
- volcano_syn_4c_CA = EnhancedVolcano(compare4c_CA,
- lab = compare4c_CA$name,
- subtitle = NULL,
- x = 'logFC',
- y = 'adj.P.Val',
- pCutoff = 0.05,
- FCcutoff = 1,
- xlim = c(-9, 11),
- ylim = c(0, 6),
- pointSize = 1.5,
- axisLabSize = 35,
- labSize = 10,
- title = NULL,
- legendPosition = "top",
- legendLabSize = 35,
- legendLabels = c("NS", expression(Log[2] ~ FC), "p-value", expression("p-value" ~ and
- ~ log[2] ~ FC)),
- col = c('grey30', '#E9E9E9', "#0072B2", '#D55E00'),
- colAlpha = 0.7,
- #drawConnectors = TRUE,
- widthConnectors = 0.5)
- pdf("/VariancePartitioning/4c_vs_CA_Volcano_VariancePartition_Syn.pdf",
- width = 17.5, height = 13.5, bg = "transparent")
- print(volcano_syn_4c_CA) # Print the plot to the PNG device
- dev.off() # Close the device
- # Apply the updated code for up genes with additional filtering and calculations
- Syn_4c_CA_up_genes <- gost_up_genes_compare4c_CA$result %>%
- filter(source %in% c("GO:BP", "GO:CC", "GO:MF", "KEGG")) %>%
- mutate(Ratio = intersection_size / term_size) %>%
- group_by(source) %>%
- slice_min(p_value, n = 7) %>%
- ungroup() %>%
- mutate(term_name = factor(term_name, levels = unique(term_name))) # Maintain original order
- # Plot for down genes GO
- Bubble_4c_CA_1 <- ggplot(Syn_4c_CA_up_genes, aes(x = Ratio, y = term_name)) +
- geom_point(aes(size = intersection_size, color = -log10(p_value)), alpha = 0.7) +
- scale_color_gradient(
- low = "#0072B2",
- high = "#D55E00",
- breaks = c(min(-log10(Syn_4c_CA_up_genes$p_value)),
- max(-log10(Syn_4c_CA_up_genes$p_value))),
- labels = c(
- paste0(round(min(-log10(Syn_4c_CA_up_genes$p_value)), 2)),
- paste0(round(max(-log10(Syn_4c_CA_up_genes$p_value)), 2))
- )
- ) + # Color based on p-value with custom breaks
- scale_size(range = c(5, 10)) + # Adjust bubble sizes
- labs(size = "Intersection Size\n", color = "-log10(p-value)\n", y = NULL) + # Axis and legend labels
- theme_minimal() + # Clean theme
- theme(
- axis.text.y = element_text(size = 35), # Adjust y-axis text size
- axis.text.x = element_text(size = 30, hjust = 1), # Adjust x-axis text size and angle
- axis.title.x = element_text(size = 35), # Adjust x-axis title size
- legend.title = element_text(size = 30), # Font size of legend title
- legend.text = element_text(size = 25),
- legend.spacing.y = unit(2, "cm") # Increase spacing between legend title and text
- )
- pdf("/VariancePartitioning/4c_vs_CA_BubbleUp_VariancePartition_Syn.pdf",
- width = 22.5, height = 13.5, bg = "transparent")
- print(Bubble_4c_CA_1)
- dev.off() # Close the device
- # Apply the updated code for down genes without text wrapping
- Syn_4c_CA_down_genes <- gost_down_genes_compare4c_CA$result %>%
- filter(source %in% c("GO:BP", "GO:CC", "GO:MF", "KEGG")) %>%
- mutate(Ratio = intersection_size / term_size) %>%
- group_by(source) %>%
- slice_min(p_value, n = 7) %>%
- ungroup() %>%
- mutate(term_name = factor(term_name, levels = unique(term_name))) # Maintain original order
- # Plot for down genes GO
- Bubble_4c_CA_2 <- ggplot(Syn_4c_CA_down_genes, aes(x = Ratio, y = term_name)) +
- geom_point(aes(size = intersection_size, color = -log10(p_value)), alpha = 0.7) +
- scale_color_gradient(
- low = "#0072B2",
- high = "#D55E00",
- breaks = c(min(-log10(Syn_4c_CA_down_genes$p_value)),
- max(-log10(Syn_4c_CA_down_genes$p_value))),
- labels = c(
- paste0(round(min(-log10(Syn_4c_CA_down_genes$p_value)), 2)),
- paste0(round(max(-log10(Syn_4c_CA_down_genes$p_value)), 2))
- )
- ) + # Color based on p-value with custom breaks
- scale_size(range = c(5, 10)) + # Adjust bubble sizes
- labs(size = "Intersection Size\n", color = "-log10(p-value)\n", y = NULL) + # Axis and legend labels
- theme_minimal() + # Clean theme
- theme(
- axis.text.y = element_text(size = 35), # Adjust y-axis text size
- axis.text.x = element_text(size = 30, hjust = 1), # Adjust x-axis text size and angle
- axis.title.x = element_text(size = 35), # Adjust x-axis title size
- legend.title = element_text(size = 30), # Font size of legend title
- legend.text = element_text(size = 25),
- legend.spacing.y = unit(2, "cm") # Increase spacing between legend title and text
- )
- pdf("/VariancePartitioning/4c_vs_CA_BubbleDown_VariancePartition_Syn.pdf",
- width = 22.5, height = 13.5, bg = "transparent")
- print(Bubble_4c_CA_2)
- dev.off() # Close the device
Dream_Synaptosome_DE_code.R, under CC-BY-4.0 · at the source
Overview
- Institute of Neuroregeneration and Neurorehabilitation, Qingdao University, Qingdao, Shandong, China
- MRC Laboratory of Medical Sciences, London, United Kingdom
- Institute of Clinical Sciences, Imperial College, London, United Kingdom
- Department of Neurobiology, School of Basic Medical Sciences, National Institute on Drug Dependence, Peking University, Beijing, China
- Faculty of Life and Health, Shenzhen University of Advanced Technology, Shenzhen, Guangdong, China
- Department of Psychological Medicine, Institute of Psychiatry, Psychology & Neuroscience, King’s College London, London, United Kingdom
Abstract
Physiological mechanisms of the key hyperacute (0–24 hours) stage of stroke are poorly understood, hampering the development of new therapies. Synaptic plasticity has been strongly implicated in early stages of neurodegenerative and neurodevelopmental disorders, yet its relevance in early stroke remains unclear. Here, we describe the emergence of distinct region-specific forms of synaptic remodeling following middle cerebral artery occlusion in rats, arising within the critical 4-hour period. Synapses within the severely ischemic core region were rapidly lost, while those in the mildly ischemic penumbra, albeit largely structurally intact, were functionally diminished. In contrast, the contralateral cortex exhibited increased synaptic staining and synaptic vesicle cycling. Systemic pharmacological blockade of NMDA-type glutamate receptors abolished contralateral synaptic increase and exacerbated synaptic decline in the penumbra. Proteomic and transcriptomic analyses showed that cross-brain synaptic plasticity is independent of local gene expression and revealed metabolic rearrangement and synaptic downregulation in the penumbra. These findings identify brain-wide synaptic rebalancing as a potential mechanism for rapid functional compensation in hyperacute stroke, highlighting the extent of brain response to acute perturbation.
Reproduced under the paper's license (CC BY), from the paper cited above.
Repository
Its files are read in the Code ↔ Paper reader above, with 1 match between paragraphs and lines of code.
Zenodo 17987265
Availability: 1 check, the latest on 30 September 2026: the link answers (HTTP 200)
- 30 September 2026: the link answers (HTTP 200)
1 file
- Dream_Synaptosome_DE_cod
e.R , R, 1,237 lines, 1 match
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;
- 1 match 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
Data links
- ncbi.nlm.nih.gov/
geo , NCBI; found in “Data Availability”
Data Availability
All relevant data are contained within the paper and its Supporting information files, or freely available online. Proteomics data were analyzed by Oe Biotech using a proprietary pipeline. Mass spectrometry proteomics data is available at ProteomeXchange (https://
Reproduced under the paper's license (CC BY), from the paper cited above.
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, 30 September 2026: the first record
Recorded: type, language, journal, volume, issue, pages, dates, 8 authors, 13 MeSH terms, 3 funders, 113 references.
Cite
This paper
Chen, H., Wei, Y., Ruje, L., Du, F., Feng, Z., Wan, Q., Spivakov, M., & Glebov, O. O. (2026). Ischemic stroke triggers brain-wide synaptic remodeling within four hours. PLoS biology, 24(3), e3003608. https://
BibTeX
@article{chen2026ischemi
author = {Chen, Huanhuan and Wei, Ye and Ruje, Luminiţa and Du, Fusheng and Feng, Zhendong and Wan, Qi and Spivakov, Mikhail and Glebov, Oleg O.},
title = {{Ischemic stroke triggers brain-wide synaptic remodeling within four hours}},
journal = {PLoS biology},
year = {2026},
month = mar,
volume = {24},
number = {3},
pages = {e3003608},
publisher = {PLOS},
issn = {1544-9173},
doi = {10.1371/
url = {https://
pmid = {41770794},
pmcid = {PMC12981561}
}
RIS
TY - JOUR
AU - Chen, Huanhuan
AU - Wei, Ye
AU - Ruje, Luminiţa
AU - Du, Fusheng
AU - Feng, Zhendong
AU - Wan, Qi
AU - Spivakov, Mikhail
AU - Glebov, Oleg O.
TI - Ischemic stroke triggers brain-wide synaptic remodeling within four hours
T2 - PLoS biology
J2 - PLoS Biol
PY - 2026
DA - 2026/
VL - 24
IS - 3
SP - e3003608
SN - 1544-9173
PB - PLOS
DO - 10.1371/
UR - https://
LA - en
ER -
CSL-JSON
{
"id": "10.1371/
"type": "article-journal",
"title": "Ischemic stroke triggers brain-wide synaptic remodeling within four hours",
"container-title": "PLoS biology",
"author": [
{
"family": "Chen",
"given": "Huanhuan"
},
{
"family": "Wei",
"given": "Ye"
},
{
"family": "Ruje",
"given": "Luminiţa"
},
{
"family": "Du",
"given": "Fusheng"
},
{
"family": "Feng",
"given": "Zhendong"
},
{
"family": "Wan",
"given": "Qi"
},
{
"family": "Spivakov",
"given": "Mikhail"
},
{
"family": "Glebov",
"given": "Oleg O."
}
],
"container-title-short":
"volume": "24",
"issue": "3",
"page": "e3003608",
"DOI": "10.1371/
"PMID": "41770794",
"PMCID": "PMC12981561",
"ISSN": "1544-9173",
"publisher": "PLOS",
"URL": "https://
"language": "en",
"issued": {
"date-parts": [
[
2026,
3,
2
]
]
}
}
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.1016/j.celrep.2026.117500 [code]
- Spatio-molecular gene expression reflects dorsal anterior cingulate cortex structure and function in the human brain.Journal: Cell reportsIn common: edgeR, cowplot, patchwork, 1 other tool, histology / microscopy, genetics / omics, cellular / molecular, 2 references
- [2] doi:10.1016/j.xcrm.2026.102766 [code]
- A longitudinal single-cell and spatial multiomic atlas of pediatric high-grade glioma.Journal: Cell reports. MedicineIn common: edgeR, DESeq2, cowplot, 2 other tools, genetics / omics, cellular / molecular, 1 reference
- [3] doi:10.1002/advs.202521254 [code]
- Persistently Increased Expression of PKMzeta and Unbiased Gene Expression Profiles Identify Hippocampal Molecular Traces of a Long-Term Active Place Avoidance Memory and "Shadow" Proteins.Journal: Advanced science (Weinheim, Baden-Wurttemberg, Germany)In common: DESeq2, cowplot, tidyverse, rat, histology / microscopy, genetics / omics, 1 other category, 2 references
- [4] doi:10.1186/s12974-026-03885-1 [code]
- Shared transcriptomic signatures in perilesional and contralesional cortex after ischemic stroke.Journal: Journal of neuroinflammationIn common: cowplot, tidyverse, stroke, genetics / omics, cellular / molecular, 3 references
- [5] doi:10.1002/imt2.70163 [code]
- Spatial multi-omics unveils sphingolipid metabolic reprogramming within the retinal pathological niche.Journal: iMetaIn common: edgeR, DESeq2, cowplot, 2 other tools, genetics / omics, cellular / molecular
- [6] doi:10.3389/fnmol.2026.1844705 [code]
- Risperidone regulates the expression of schizophrenia-related genes in the forebrain of adult male mice.Journal: Frontiers in molecular neuroscienceIn common: edgeR, DESeq2, cowplot, 2 other tools, genetics / omics, cellular / molecular
- [7] doi:10.1038/s41467-026-73305-8 [code]
- Comparative analysis of the cellular landscape in mammalian striatum.Journal: Nature communicationsIn common: edgeR, DESeq2, cowplot, 2 other tools, genetics / omics, cellular / molecular
- [8] doi:10.1038/s41593-026-02300-5 [code]
- Integrated single-cell and spatial transcriptomic profiling in ALS uncovers peripheral-to-central immune infiltration and reprogramming.Journal: Nature neuroscienceIn common: edgeR, DESeq2, cowplot, 2 other tools, genetics / omics, cellular / molecular
- [9] doi:10.1016/j.celrep.2026.117073 [code]
- Single-cell epigenomics uncovers heterochromatin instability and transcription factor dysfunction during mouse brain aging.Journal: Cell reportsIn common: edgeR, DESeq2, cowplot, 2 other tools, genetics / omics, cellular / molecular
- [10] doi:10.1038/s41467-026-70232-6 [code]
- Gene expression dynamics of human and mouse craniofacial development at the single-cell level.Journal: Nature communicationsIn common: edgeR, DESeq2, cowplot, 2 other tools, genetics / omics, cellular / molecular
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.
Claim this paper
Correct its record
Say what each link of this record is, remove the ones that are not the paper's, add the ones that are missing. The correction becomes a new version of the record, in its Versions section.
Validate its tracing map
You validate the map as this page shows it: 1 repository of the authors' code, each at its verified commit and with its license, 1 script, and 1 match between paragraphs and code (see the Code and Map sections). It then receives a DOI on Zenodo, with you (your ORCID iD) and OSCR as its creators; the code itself is not deposited.
The map's fingerprint: sha256:95172318525666f2…
Add the badge to its README
The badge links the code to this page. Copy one of these into the README of the paper's code: only you decide where it goes, and nothing is changed for you.
Markdown
[.
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.
