forked from galantelab/reboot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reboot.R
executable file
·245 lines (194 loc) · 8.88 KB
/
reboot.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#!/usr/bin/env Rscript
#Pay carefully attention to help errors. Argparse apparently bugs depending on help text size
library(argparse)
#create the top-level parser
parser = ArgumentParser()
#parser$add_argument()
subparsers = parser$add_subparsers(dest="sub_name", metavar = "<subcommand>", help = "choose only one option")
#version
parser$add_argument('-v', '--version', action='version', version='reboot 1.1.0')
#create the parser for the "regression" command
parser_reg = subparsers$add_parser('regression', help= "generates signature through multivariate cox regression")
parser_reg$add_argument("-I", "--filein", type="character", dest = "fname", metavar ='',
help="Input file name. Tab separated values (tsv) file containing genes/transcripts expression and survival data")
parser_reg$add_argument("-O", "--outprefix", type="character", dest = "out", metavar = '',
default = "reboot", help='Output file prefix (str). Default: reboot')
parser_reg$add_argument("-B","--bootstrap", type = "integer", dest = "booty", metavar = '',
default = "1",
help = "Number of iterations for bootstrap simulation (int). Default: 1")
parser_reg$add_argument("-G", "--groupsize", type="integer", dest = "nel", metavar = '',
default="10",
help="Number of genes/transcripts to be selected in each bootstrap simulation (int). Default: 10")
parser_reg$add_argument("-P", "--pcentfilter", type="character", dest = "pf", metavar = '',
default = "0.3",
help="Percentage of correlated gene/transcript pairs allowed in each iteration (double). Default: 0.3")
parser_reg$add_argument("-V", "--varfilter", type="character", dest = "var", metavar = '',
default = "0.01",
help='Minimum normalized variance (0-1) required for each gene/transcript among samples and follow up time (double). Default: 0.01')
parser_reg$add_argument("-F", "--force",
dest = "force", action="store_true",
default = "FALSE",
help="Choose -F to bypass OS and OStime filters")
#create the parser for the "survival" command
parser_sur = subparsers$add_parser('survival', help = "applies sgnature in survival analysis")
parser_sur$add_argument("-I", "--filein", type="character", dest = "fname", metavar = '',
help="Input file name. Tab separated values (tsv) file containing genes/transcripts expression and survival paramenters")
parser_sur$add_argument("-O", "--outprefix", type="character", dest = "out", metavar = '',
default = "reboot",
help='Output file prefix. Default: reboot')
parser_sur$add_argument("-M", "--multivariate",
dest = "type", action="store_true", default="FALSE",
help='If clinical variables should be included, choose -M. This option is tied with -C option')
parser_sur$add_argument("-C", "--clinical", type="character", dest = "clin_file", metavar = '',
default="",
help='Tab separated values (tsv) file containing binary categorical variables only. Required if -M option is chosen')
parser_sur$add_argument("-R", "--roc",
dest = "roc_curve", action="store_true", default="FALSE",
help='If genetic score should be categorized according to a ROC curve instead of the median, choose -R')
parser_sur$add_argument("-S", "--signature", metavar = '',
type="character", dest = "sig",
help='Tab separated values (tsv) file containing a set of genes/transcripts and corresponding cox coefficients')
parser_sur$add_argument("-V", "--varfilter", type="character", dest = "var", metavar = '',
default = "0.01",
help='Minimum normalized variance (0-1) required for follow up time (double). Default: 0.01')
parser_sur$add_argument("-F", "--force",
dest = "force", action="store_true",
default = "FALSE",
help="Choose -F to bypass OS and OStime filters")
#create the parser for the "complete" command
parser_all = subparsers$add_parser('complete', help = "generates and applies signature (integrated analysis)")
parser_all$add_argument("-I", "--filein", type="character", dest = "fname", metavar ='',
help='Input file name. Tab separated values (tsv) file containing genes/transcripts expression and survival data')
parser_all$add_argument("-O", "--outprefix", type="character", dest = "out", metavar = '',
default = "reboot", help='Output file prefix. Default: reboot')
parser_all$add_argument("-B","--bootstrap", type = "integer", dest = "booty", metavar = '',
default = "1",
help = "Number of iterations for bootstrap simulation (int). Default: 1")
parser_all$add_argument("-G", "--groupsize", type="integer", dest = "nel", metavar = '',
default="10",
help="Number of genes/transcripts to be selected in each bootstrap simulation (int). Default: 10")
parser_all$add_argument("-P", "--pcentfilter", type="character", dest = "pf", metavar = '',
default = "0.3",
help="Percentage of correlated gene/transcript pairs allowed in each iteration. Default: 0.3")
parser_all$add_argument("-V", "--varfilter", type="character", dest = "var", metavar = '',
default = "0.01",
help="Minimum normalized variance (0-1) required for each gene/transcript among samples and follow up time (double). Default: 0.01")
parser_all$add_argument("-M", "--multivariate",
dest = "type", action="store_true", default="FALSE",
help='If clinical variables should be included, choose -M. This option is tied with -C option')
parser_all$add_argument("-C", "--clinical", type="character", dest = "clin_file", metavar = '',
default="",
help='Tab separated values (tsv) file containing binary categorical variables only. Required if -M option is chosen')
parser_all$add_argument("-R", "--roc",
dest = "roc_curve", action="store_true", default=FALSE,
help='If continuous variables should be categorized according to a ROC curve instead of median, choose -R')
parser_all$add_argument("-F", "--force",
dest = "force", action="store_true",
default = "FALSE",
help="Choose -F to bypass OS and OStime filters")
args = parser$parse_args()
newargs = commandArgs(trailingOnly=TRUE)
if (length(newargs)==0){
parser$parse_args('-h')
}
if (args$sub_name=="regression"){
system(paste(
# "Rscript regression.R",
"regression.R",
"-I", args$fname,
"-O", args$out,
"-B", args$booty,
"-G", args$nel,
"-P", args$pf,
"-V", args$var,
"-F", args$force,
collapse=" "))
}
if (args$sub_name=="survival"){
logfile <- paste(args$out,".log",sep="")
if(file.exists(logfile)){
unlink(logfile)
}
#Check if clinical data is provided in case type == TRUE
if (args$type){
if (args$clin_file == ""){
cat("Insert file with clinical variables\n")
q(status=0)
}else{
system(paste(
# "Rscript survival.R",
"survival.R",
"-I", args$fname,
"-O", args$out,
"-S", args$sig,
"-M", args$type,
"-C", args$clin_file,
"-R", args$roc_curve,
"-F", args$force,
collapse=" "))
}
}else{
system(paste(
# "Rscript survival.R",
"survival.R",
"-I", args$fname,
"-O", args$out,
"-S", args$sig,
"-M", args$type,
"-R", args$roc_curve,
"-F", args$force,
collapse=" "))
}
}
if (args$sub_name=="complete"){
#Check if clinical data is provided in case type == TRUE
if(args$type){
if(args$clin_file == ""){
cat("Insert file with clinical variables\n")
q(status=0)
}
}
system(paste(
# "Rscript regression.R",
"regression.R",
"-I", args$fname,
"-O", args$out,
"-B", args$booty,
"-G", args$nel,
"-P", args$pf,
"-V", args$var,
"-F", args$force,
collapse=" "),
intern=TRUE)
assinatura <- paste(args$out,"_signature.txt",sep="")
#Check if clinical data is provided in case type == TRUE
if (args$type){
if (args$clin_file == ""){
cat("Insert file with clinical variables\n")
q(status=0)
}else{
system(paste(
# "Rscript survival.R",
"survival.R",
"-I", args$fname,
"-O", args$out,
"-S", assinatura,
"-M", args$type,
"-C", args$clin_file,
"-R", args$roc_curve,
"-F", args$force,
collapse=" "))
}
}else{
system(paste(
# "Rscript survival.R",
"survival.R",
"-I", args$fname,
"-O", args$out,
"-S", assinatura,
"-M", args$type,
"-R", args$roc_curve,
"-F", args$force,
collapse=" "))
}
}