141
|
1 #!/usr/bin/env Rscript
|
|
2
|
|
3 suppressPackageStartupMessages(library("optparse"))
|
|
4
|
|
5 option_list <- list(
|
145
|
6 make_option(c("--input_dir"), action="store", dest="input_dir", help="IDEAS para files directory"),
|
|
7 make_option(c("--output_dir"), action="store", dest="output_dir", help="PDF output directory"),
|
159
|
8 make_option(c("--script_dir"), action="store", dest="script_dir", help="R script source directory"),
|
|
9 make_option(c("--in_training_mode"), action="store_true", dest="in_training_mode", default=FALSE, help="Flag for training mode")
|
141
|
10 )
|
|
11
|
|
12 parser <- OptionParser(usage="%prog [options] file", option_list=option_list);
|
|
13 args <- parse_args(parser, positional_arguments=TRUE);
|
|
14 opt <- args$options;
|
|
15
|
163
|
16 heatmap_path = paste(opt$script_dir, "create_heatmap.R", sep="/");
|
143
|
17 source(heatmap_path);
|
141
|
18
|
159
|
19 if (opt$in_training_mode) {
|
163
|
20 ext = ".para0";
|
|
21 pattern = "\\.para0$";
|
162
|
22 } else {
|
163
|
23 ext = ".para";
|
|
24 pattern = "\\.para$"
|
159
|
25 }
|
163
|
26 para_files = list.files(path=opt$input_dir, pattern=pattern, full.names=TRUE);
|
141
|
27 for (i in 1:length(para_files)) {
|
163
|
28 para_file = para_files[i];
|
|
29 para_file_base_name = strsplit(para_file, split="/")[[1]][2];
|
|
30 output_file_base_name = gsub(ext, "", para_file_base_name);
|
|
31 output_file_name = paste(output_file_base_name, "state", i, "pdf", sep=".");
|
|
32 output_file_path = paste(opt$output_dir, output_file_name, sep="/");
|
|
33 data_frame = read.table(para_file, comment="!", header=T);
|
141
|
34 create_heatmap(data_frame, output_file_path);
|
|
35 }
|