rm(list=ls())
library(clusterProfiler)
library(ReactomePA)
library(rrvgo)
library(enrichplot)
library(ggplot2)
library(msigdbr)
organism ="org.Hs.eg.db"
library(organism, character.only = TRUE)
library(glue)
library(mulea)
library(tidyverse)
library(AnnotationDbi)
library(scales)
setwd("C:/Users/dmodos/OneDrive - Imperial College London/Gandalf_projekt_v1_clearing/Paper/Molecular_systems_biology_reresubmission/Figures/Figure_2_folder/Figure2c")
outcome_cd <- read.csv("cd_only_ppi10rnd.txt", sep="\t", row.names = 1)
head(outcome_cd)
selected_outcome_cd <- outcome_cd[outcome_cd$Z_Count>0,]
```{r}
reactome_ontology <- read_gmt("ReactomePathways.gmt")
reactome_ontology <- reactome_ontology %>%
rename(ontology_id = "ontology_id",
ontology_name = "ontology_name",
list_of_values = "list_of_values")
head(reactome_ontology)
reactome_ontology_filtered <- filter_ontology(gmt = reactome_ontology,
min_nr_of_elements = 5,
max_nr_of_elements = 500)
op <- read.csv("OmniPath_27_10_2021_directed.ncol", sep=" ", header = FALSE, row.names = NULL)
head(op)
gene_ontology_filtered <- filter_ontology(gmt = gene_ontology,
min_nr_of_elements = 5,
max_nr_of_elements = 500)
bg <- unique(c(op$V1,op$V2))
commonly_afffected_genes_cd <- selected_outcome_cd[selected_outcome_cd$Z_Count>100,]
dim(commonly_afffected_genes_cd)
commonly_afffected_cd_genes_symbols <- mapIds(org.Hs.eg.db, keys = row.names(commonly_afffected_genes_cd),
column = "SYMBOL", keytype = "UNIPROT", multiVals = "first")
ora_model <- ora(gmt = reactome_ontology_filtered,
# Test set variable
element_names = commonly_afffected_cd_genes_symbols,
# Background set variable
background_element_names = bg_symbols,
# p-value adjustment method
p_value_adjustment_method = "eFDR",
# Number of permutations
number_of_permutations = 10000,
# Number of processor threads to use
nthreads = 2,
# Setting a random seed for reproducibility
random_seed = 42)
bg_symbols <- mapIds(org.Hs.eg.db, keys = bg, column = "SYMBOL", keytype = "UNIPROT", multiVals = "first")
ora_model <- ora(gmt = reactome_ontology_filtered,
# Test set variable
element_names = commonly_afffected_cd_genes_symbols,
# Background set variable
background_element_names = bg_symbols,
# p-value adjustment method
p_value_adjustment_method = "eFDR",
# Number of permutations
number_of_permutations = 10000,
# Number of processor threads to use
nthreads = 2,
# Setting a random seed for reproducibility
random_seed = 42)
reactome_results_cd_ppi <- run_test(ora_model)
reactome_results_cd_ppi$GeneRatio <- reactome_results_cd_ppi$nr_common_with_tested_elements / length(commonly_afffected_cd_genes_symbols)
sig_results_cd_ppi <- reactome_results_cd_ppi %>%
# Rows where the eFDR < 0.05
filter(eFDR < 0.1) %>%
# Arrange the rows by the gene ratio for plotting
arrange(desc(GeneRatio))
sig_results_cd_ppi$ontology_id <- factor(sig_results_cd_ppi$ontology_id,
levels = sig_results_cd_ppi[order(sig_results_cd_ppi$GeneRatio, decreasing = FALSE), "ontology_id"])
sig_results_cd_ppi
sig_results_cd_ppi$formed_id <- gsub("_", " ", sig_results_cd_ppi$ontology_id)
sig_results_cd_ppi$formed_id <- factor(sig_results_cd_ppi$formed_id,
levels = sig_results_cd_ppi[order(sig_results_cd_ppi$GeneRatio,
decreasing = FALSE), "formed_id"])
sig_results_cd_ppi$eFDR = sig_results_cd_ppi$eFDR +10^-12
dotplot_reactome_cd_ppi <- ggplot(sig_results_cd_ppi[1:20,], aes(x=GeneRatio, y=formed_id)) +
geom_point(aes(size=nr_common_with_tested_elements, colour=eFDR)) +
scale_y_discrete(labels = label_wrap(50)) +
scale_color_continuous(low="red", high="blue",
limits=c(10^-5, 0.1),
trans = "log10", name="Emprical FDR")
dotplot_reactome_cd_ppi <- dotplot_reactome_cd_ppi +
scale_size(limits = c(2,20), range = c(2,15), name = "Number of genes") +
xlim(0, 0.23) +
xlab("Gene Ratio") +
ylab("Reactome pathways") +
theme_light() +
theme(rect=element_rect(fill="white")) +
theme(panel.background = element_rect(fill = "white")) +
theme(plot.background = element_rect(fill = "white")) +
theme(plot.background = element_rect(colour = "white"))+
theme(axis.title.x = element_text(colour = "black", size = 10)) +
theme(axis.title.y = element_text(colour = "black", size = 10)) +
theme(axis.text = element_text(color= "black", size = 10)) +
theme(axis.line = element_line(color = "black")) +
theme(legend.background = element_rect(fill ="white")) +
theme(legend.text = element_text(color="black", size = 10)) +
theme(legend.title = element_text(color= "black", size = 10))
dotplot_reactome_cd_ppi <- dotplot_reactome_cd_ppi +
scale_size(limits = c(2,20), range = c(2,15), name = "Number of genes") +
xlim(0, 0.23) +
xlab("Gene Ratio") +
ylab("Reactome pathways") +
theme_light() +
theme(rect=element_rect(fill="white")) +
theme(panel.background = element_rect(fill = "white")) +
theme(plot.background = element_rect(fill = "white")) +
theme(plot.background = element_rect(colour = "white"))+
theme(axis.title.x = element_text(colour = "black", size = 10)) +
theme(axis.title.y = element_text(colour = "black", size = 10)) +
theme(axis.text = element_text(color= "black", size = 10)) +
theme(axis.line = element_line(color = "black")) +
theme(legend.background = element_rect(fill ="white")) +
theme(legend.text = element_text(color="black", size = 10)) +
theme(legend.title = element_text(color= "black", size = 10))
```
dotplot_reactome_cd_ppi
png("Fig3c.png",width=8, height=8, units="in", res=600)
dotplot_reactome_cd_ppi
dev.off()
rm(list=ls())
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install("clusterProfiler")
library(clusterProfiler)
library(ReactomePA)
library(rrvgo)
library(enrichplot)
library(ggplot2)
library(msigdbr)
organism ="org.Hs.eg.db"
library(organism, character.only = TRUE)
library(glue)
library(mulea)
library(tidyverse)
library(AnnotationDbi)
library(scales)
outcome_cd <- read.csv("cd_only_ppi10rnd.txt", sep="\t", row.names = 1)
head(outcome_cd)
selected_outcome_cd <- outcome_cd[outcome_cd$Z_Count>0,]
histogramplot_cd <- ggplot(selected_outcome_cd, aes(x=Z_Count)) +
geom_histogram(colour="white", fill="orange", binwidth = 50)+
ylab("Number of individual proteins") + xlab("Number of patients") +
geom_vline(aes(xintercept=100),
color="black", linetype="dashed", size=1) +
scale_x_continuous(breaks=seq(0,1400,200)) + theme_light()
theme(panel.background = element_rect(fill = "black")) +
theme(plot.background = element_rect(fill = "white", colour = "white")) +
theme(axis.title.x = element_text(colour = "black", size = 10)) +
theme(axis.title.y = element_text(colour = "black", size = 10)) +
theme(axis.text = element_text(color= "black", size = 10)) +
theme(axis.line = element_line(color = "black")) +
theme(panel.grid.minor = element_blank())
histogramplot_cd
png(file=glue("Figure_2b.png"),width=8, height=4, units="in", res=600)
histogramplot_cd
dev.off()
