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
|
143
|
16 heatmap_path <- paste(opt$script_dir, "create_heatmap.R", sep="/");
|
|
17 source(heatmap_path);
|
141
|
18
|
159
|
19 if (opt$in_training_mode) {
|
|
20 ext <- ".para";
|
|
21 para_files <- list.files(path=opt$input_dir, pattern="\\.para$", full.names=TRUE);
|
|
22 } else {
|
|
23 ext <- ".para0";
|
|
24 para_files <- list.files(path=opt$input_dir, pattern="\\.para0$", full.names=TRUE);
|
|
25 }
|
141
|
26 for (i in 1:length(para_files)) {
|
|
27 para_file <- para_files[i];
|
|
28 para_file_base_name <- strsplit(para_file, split="/")[[1]][2];
|
159
|
29 output_file_base_name <- gsub(ext, "", para_file_base_name);
|
141
|
30 output_file_name <- paste(output_file_base_name, "state", i, "pdf", sep=".");
|
|
31 output_file_path <- paste(opt$output_dir, output_file_name, sep="/");
|
|
32 data_frame <- read.table(para_file, comment="!", header=T);
|
|
33 create_heatmap(data_frame, output_file_path);
|
|
34 }
|