-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_reactome_fig.R
90 lines (74 loc) · 2.1 KB
/
gen_reactome_fig.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env Rscript
library(pathfindR)
library("optparse")
# pan <- Sys.getenv("RSTUDIO_PANDOC")
# Sys.setenv(RSTUDIO_PANDOC=pan)
# print(paste0("Set RSTUDIO_PANDOC variable to: ", pan))
option_list = list(
make_option(c("-i", "--gene_lst"), type="character", default=NULL,
help="gene list path", metavar="character"),
make_option(c("-o", "--out"), type="character", default=NULL,
help="output dir", metavar="character")
);
opt_parser = OptionParser(option_list=option_list);
opt = parse_args(opt_parser);
if (is.null(opt$gene_lst)){
print_help(opt_parser)
stop("Input file to gene list must be specified.n", call.=FALSE)
}
if (is.null(opt$out)){
print_help(opt_parser)
stop("Output directory must be specified.n", call.=FALSE)
}
f=opt$gene_lst
o=opt$out
if (file.exists(o)){
stop("Output directory already exists. Please delete before running.n", call.=FALSE)
}
g_list= read.csv(
f,
header = TRUE,
sep="\t",
na.strings = "",
stringsAsFactors=FALSE
)
gsets_list <- get_gene_sets_list(
source = "Reactome",
species = "Homo sapiens"
)
# out=paste(o,"/out",sep='')
output_df <- run_pathfindR(
g_list,
output_dir = o,
# gene_sets = "Reactome",
custom_genes = gsets_list$gene_sets,
custom_descriptions = gsets_list$descriptions,
min_gset_size = 5,
max_gset_size = 500,
n_processes = 4,
#pin_name_path = "STRING"
pin_name_path = "Biogrid"
)
output_df_clustered <- cluster_enriched_terms(output_df, plot_dend = FALSE, plot_clusters_graph = FALSE)
# plotting only selected clusters for better visualization
selected_clusters <- subset(output_df_clustered[output_df_clustered$Status == "Representative", ], Cluster %in% 1:10)
# output png enrichment chart
out=paste(o,"/enrichment_chart.png",sep='')
png(
filename = out,
res = 250,
width = 8,
height = 4,
units = "in"
)
plot(enrichment_chart(selected_clusters, plot_by_cluster = TRUE))
dev.off()
# output png enrichment chart
out=paste(o,"/enrichment_chart.svg",sep='')
svg(
filename = out,
width = 8,
height = 4
)
plot(enrichment_chart(selected_clusters, plot_by_cluster = TRUE))
dev.off()