Mercurial > repos > greg > ideas2
comparison create_heatmaps.R @ 0:b785bcfe5cd0 draft default tip
Uploaded
author | greg |
---|---|
date | Mon, 12 Feb 2018 09:52:26 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:b785bcfe5cd0 |
---|---|
1 #!/usr/bin/env Rscript | |
2 | |
3 suppressPackageStartupMessages(library("optparse")) | |
4 | |
5 option_list <- list( | |
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"), | |
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") | |
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 | |
16 heatmap_path = paste(opt$script_dir, "create_heatmap.R", sep="/"); | |
17 source(heatmap_path); | |
18 | |
19 if (opt$in_training_mode) { | |
20 ext = ".para0"; | |
21 pattern = "\\.para0$"; | |
22 } else { | |
23 ext = ".para"; | |
24 pattern = "\\.para$" | |
25 } | |
26 para_files = list.files(path=opt$input_dir, pattern=pattern, full.names=TRUE); | |
27 for (i in 1:length(para_files)) { | |
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); | |
34 create_heatmap(data_frame, output_file_path); | |
35 } |