annotate chipenrich.R @ 4:7ed46473bb8f draft default tip

Uploaded
author mora-lab
date Sun, 13 Jun 2021 06:34:17 +0000
parents 63ec097240bf
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
1 ###############################################################################
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
2 # title: chipenrich
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
3 # author: Xiaowei
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
4 # time: Mar.31 2021
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
5 ###############################################################################
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
6
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
7 spec <- matrix(c("input_peaks", "P",1, "character", "peaks file",
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
8 "input_genome","G",1, "character", "genome",
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
9 "input_locusdef","L",1,"character", "locusdef",
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
10 "input_mappability","Map",0, "logical", "mappability",
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
11 "input_qc_plot","Q",0, "logical", "qc_plot",
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
12 "input_method","M",1,"character", "method",
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
13 "input_geneset","GS",1,"character", "geneset_category",
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
14 "input_minSize","Min",1,"integer","minSize",
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
15 "input_maxSize","Max",1,"integer", "maxSize",
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
16 "input_randomization","random",1,"character","randomization",
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
17 "input_reglocation","reg",1,"character","reglocation",
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
18 "input_num_peak_threshould","threshould",1,"numeric", "peak_threshould",
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
19 "output_peaks","out_peaks",1,"character","output_peaks",
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
20 "output_peaks_per_gene","out_ppg",1,"character","peaks per gene",
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
21 "output_enrich_results","out_er",1,"character", "enrich result",
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
22 "output_qc_plot", "out_qc", 1,"character","output_qc_plot"
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
23 ),byrow = TRUE, ncol = 5)
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
24
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
25 opt <- getopt::getopt(spec)
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
26
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
27
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
28 #----------------------------------------------------------------
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
29
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
30 input_peaks <- read.csv(opt$input_peaks,header = TRUE)
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
31 input_genome = opt$input_genome
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
32 input_locusdef = opt$input_locusdef
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
33
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
34 if (!is.null(opt$input_mappability)){
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
35 input_mappability = 24 #根据表格来填写
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
36 }else{
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
37 input_mappability = NULL #supported_read_lengths()
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
38 }
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
39
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
40 if(!is.null(opt$input_qc_plot)){
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
41 input_qc_plot = opt$input_qc_plot
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
42 input_output_name = "x"
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
43 }else{
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
44 input_qc_plot = FALSE
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
45 input_output_name = NULL
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
46 }
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
47
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
48
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
49 if (!is.null(opt$input_method)){input_method = opt$input_method}else{input_method ="chipenrich"}
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
50 if(!is.null(opt$input_geneset)){input_geneset = strsplit(opt$input_geneset, split = ",")[[1]]}else{input_geneset = NULL}
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
51 if(!is.null(opt$input_minSize)){input_minSize = opt$input_minSize}else{input_minSize = 15}
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
52 if(!is.null(opt$input_maxSize)){input_maxSize = opt$input_maxSize}else{input_maxSize = 2000}
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
53 if(!is.null(opt$input_randomization) & opt$input_randomization != "NULL"){input_randomization = opt$input_randomization}else{input_randomization = NULL}
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
54 input_core = parallel::detectCores()
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
55 if(!is.null(opt$input_reglocation)){input_reglocation = opt$input_reglocation}else{input_reglocation = "tss"} #proxReg
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
56 #chipenrich、hybridenrich
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
57 if(!is.null(opt$input_num_peak_threshould)){input_num_peak_threshould = opt$input_num_peak_threshould}else{input_num_peak_threshould = 1}
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
58 #================================================================
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
59 #run codes
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
60 #================================================================
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
61 suppressPackageStartupMessages(library(chipenrich))
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
62 ## ---- chipenrich----------------------------------------
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
63 if (input_method == "chipenrich"){
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
64 results = chipenrich(peaks = input_peaks, genome = input_genome, genesets = input_geneset,
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
65 locusdef = input_locusdef, qc_plots = FALSE, out_name = input_output_name,
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
66 mappability = input_mappability,
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
67 min_geneset_size = input_minSize,
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
68 max_geneset_size = input_maxSize,
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
69 randomization = input_randomization,
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
70 num_peak_threshold = input_num_peak_threshould,
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
71 n_cores = input_core)
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
72 }
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
73
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
74
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
75 ## ----polyenrich----------------------------------------
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
76 if (input_method == "polyenrich"){
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
77 results = polyenrich(peaks = input_peaks, genome = input_genome, genesets = input_geneset,
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
78 method = 'polyenrich',
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
79 locusdef = input_locusdef, qc_plots = FALSE, out_name = input_output_name,
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
80 mappability = input_mappability,
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
81 min_geneset_size = input_minSize,
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
82 max_geneset_size = input_maxSize,
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
83 randomization = input_randomization,
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
84 n_cores = input_core)
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
85 }
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
86
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
87 ## ----hybridenrich----------------------------------------
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
88 if (input_method == "hybridenrich"){
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
89 results = hybridenrich(peaks = input_peaks, genome = input_genome, genesets = input_geneset,
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
90 locusdef = input_locusdef, qc_plots = FALSE, out_name = input_output_name,
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
91 mappability = input_mappability,
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
92 min_geneset_size = input_minSize,
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
93 max_geneset_size = input_maxSize,
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
94 randomization = input_randomization,
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
95 num_peak_threshold = input_num_peak_threshould,
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
96 n_cores = input_core)
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
97 }
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
98
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
99 ## ----proxReg----------------------------------------
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
100 if (input_method == "proxReg"){
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
101 results = proxReg(peaks = input_peaks, reglocation = input_reglocation,
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
102 genome = input_genome, genesets=input_geneset,
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
103 min_geneset_size = input_minSize,
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
104 max_geneset_size = input_maxSize,
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
105 randomization = input_randomization,
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
106 out_name=input_output_name,
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
107 n_cores = input_core)
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
108 }
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
109
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
110 ## ----broadenrich----------------------------------------peaks_H3K4me3_GM12878---
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
111 if (input_method == "broadenrich"){
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
112 results = broadenrich(peaks = input_peaks, genome = input_genome, genesets = input_geneset,
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
113 locusdef = input_locusdef, qc_plots = FALSE, out_name = input_output_name,
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
114 mappability = input_mappability,
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
115 min_geneset_size = input_minSize,
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
116 max_geneset_size = input_maxSize,
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
117 randomization = input_randomization,
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
118 n_cores = input_core)
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
119 }
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
120
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
121 #===============================================================================
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
122 # 输出
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
123 #===============================================================================
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
124 output_peaks = opt$output_peaks
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
125 output_peaks_per_gene = opt$output_peaks_per_gene
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
126 output_enrich_result = opt$output_enrich_results
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
127
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
128 if (!is.null(output_peaks)){
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
129 write.csv(results$peaks, file = output_peaks)
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
130 }
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
131
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
132 if (!is.null(output_peaks_per_gene)){
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
133 if (input_method != "proxReg"){
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
134 write.csv(results$peaks_per_gene, file = output_peaks_per_gene)
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
135 }
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
136 }
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
137
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
138 if (!is.null(output_enrich_result)){
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
139 write.csv(results$results, file = output_enrich_result)
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
140 }
63ec097240bf Uploaded
mora-lab
parents:
diff changeset
141