annotate ReactomePA.R @ 1:66cd0f5b8c36 draft default tip

Uploaded
author mora-lab
date Thu, 20 May 2021 08:39:40 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
1 ###############################################################################
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
2 #title: Reactome Pathway enrich Analysis of a gene set
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
3 #author: xiaowei
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
4 # time: Mar.31 2021
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
5 ###############################################################################
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
6
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
7
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
8 #####################
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
9 #Input argument for this function
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
10 #####################
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
11 # title
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
12 # Reactome Pathway enrich Analysis of a gene set
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
13
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
14 # description
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
15 #Input a vector of all different expression gene and Output the enriched Significant Reactome Pathways
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
16
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
17 # basic input:
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
18 # genelist, g, 1, character, an csv file contained all different expression genes with entrez gene id, and has one column as DEgenes
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
19
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
20 # Optional:
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
21 # pvalueCutoff , p , 1, numeric , Cutoff value of p-value,
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
22 # organism , o , 1, character, one of 'human', 'rat', 'mouse', 'celegans', 'yeast', 'zebrafish' and 'fly',
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
23 # pAdjustMethod , w , 1, character, one of 'holm', 'hochberg', 'hommel', 'bonferroni', 'BH', 'BY', 'fdr', 'none',
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
24 # minGSSize , i , 1, integer , minimal size of genes annotated by Ontology term for testing,
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
25 # maxGSSize , a , 1, integer , maximal size of each geneSet for analyzing,
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
26 # convertId , c , 0, logical , whether papping gene ID to gene Name,
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
27
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
28
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
29 # OUT:
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
30 # sigP, s, 1, character, output csv file name
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
31
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
32 ##############################################################################
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
33 #Input argument
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
34 ###############################################################################
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
35 #args <- commandArgs(trailingOnly = TRUE)
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
36
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
37 spec <- matrix(c("genelist", "g", 1, "character", "an csv file contained all different expression genes with entrez gene id",
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
38 "pvalueCutoff", "p", 1, "numeric", "Cutoff value of p-value",
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
39 "organism", "o", 1, "character", "one of 'human', 'rat', 'mouse', 'celegans', 'yeast', 'zebrafish' and 'fly'",
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
40 "pAdjustMethod","w", 1, "character", "one of 'holm', 'hochberg', 'hommel', 'bonferroni', 'BH', 'BY', 'fdr', 'none'",
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
41 "minGSSize", "i",1, "integer", "minimal size of genes annotated by Ontology term for testing",
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
42 "maxGSSize", "a",1, "integer", "maximal size of each geneSet for analyzing",
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
43 "convertId", "c",0, "logical", "whether papping gene ID to gene Name",
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
44 "sigP", "s", 1, "character", "output csv file name"),
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
45 byrow = TRUE, ncol = 5)
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
46
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
47
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
48 if (!requireNamespace("getopt", quietly = TRUE))
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
49 install.packages("getopt")
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
50
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
51
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
52 opt <- getopt::getopt(spec)
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
53
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
54 #-------整理输入的参数----------------
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
55 de <- opt$genelist
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
56 if(is.null(opt$pvalueCutoff)){
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
57 pvalueCutoff = 0.05
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
58 }else{
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
59 pvalueCutoff <- opt$pvalueCutoff
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
60 }
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
61
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
62 if(is.null(opt$organism)){
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
63 organism <- "human"
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
64 }else{
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
65 organism <- opt$organism
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
66 }
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
67
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
68 if(is.null(opt$pAdjustMethod)){
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
69 pAdjustMethod <- "BH"
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
70 }else{
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
71 pAdjustMethod <- opt$pAdjustMethod
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
72 }
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
73
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
74 if(is.null(opt$minGSSize)){
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
75 minGSSize <- 10
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
76 }else{
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
77 minGSSize <- opt$minGSSize
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
78 }
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
79
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
80 if(is.null(opt$maxGSSize)){
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
81 maxGSSize <- 500
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
82 }else{
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
83 maxGSSize <- opt$maxGSSize
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
84 }
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
85
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
86
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
87 if(is.null(opt$convertId)){
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
88 convertId <- FALSE
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
89 }else{
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
90 convertId <- opt$convertId
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
91 }
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
92
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
93 if(is.null(opt$sigP)){
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
94 opt$sigP <- "Significant_Reactome_Pathway_result.csv"
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
95 }
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
96
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
97 ###############################################################################
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
98 #运行代码
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
99 ###############################################################################
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
100 de <- read.csv(de)
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
101 de <- de$DEgenes
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
102
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
103 suppressPackageStartupMessages(
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
104 if (!requireNamespace("ReactomePA", quietly = TRUE)){
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
105 if (!requireNamespace("BiocManager", quietly = TRUE))
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
106 install.packages("BiocManager")
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
107 BiocManager::install("ReactomePA")
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
108 })
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
109
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
110 #suppressPackageStartupMessages(library(ReactomePA))
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
111
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
112 #Pathway Enrichment Analysis of a gene set
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
113 result_sigP <- ReactomePA::enrichPathway(gene=de, #entrez id 的基因 向量
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
114 pvalueCutoff= pvalueCutoff, #p值阈值
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
115 organism = organism, #有机体是"human"、"rat"、"mouse"、"celegans"、"yeast"、"zebrafish"、"fly"其中一个
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
116 pAdjustMethod = pAdjustMethod, #"holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none" 其中一个
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
117 #unverse, #背景基因
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
118 minGSSize = minGSSize, #检验本体术语时,限制最少基因个数
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
119 maxGSSize = maxGSSize, #分析基因集时,限制最大基因个数
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
120 readable=convertId) #是否将geneID映射到基因名称
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
121
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
122 result_sigP <- as.data.frame(result_sigP)
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
123
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
124
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
125
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
126 ###############################################################################
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
127 #输出
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
128 ###############################################################################
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
129 write.csv(result_sigP, file = opt$sigP, row.names = FALSE)
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
130
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
131
66cd0f5b8c36 Uploaded
mora-lab
parents:
diff changeset
132