Mercurial > repos > greg > ideas
changeset 121:755d4a3754d2 draft
Uploaded
author | greg |
---|---|
date | Fri, 17 Nov 2017 13:13:37 -0500 |
parents | cfa683d96cae |
children | 7229e52fa8e1 |
files | create_heatmap.R |
diffstat | 1 files changed, 15 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/create_heatmap.R Fri Nov 17 13:13:27 2017 -0500 +++ b/create_heatmap.R Fri Nov 17 13:13:37 2017 -0500 @@ -3,8 +3,8 @@ suppressPackageStartupMessages(library("optparse")) option_list <- list( - make_option(c("-i", "--input"), action="store", dest="input", help="IDEAS para file"), - make_option(c("-o", "--output"), action="store", dest="output", help="Output PDF file") + make_option(c("-i", "--input_dir"), action="store", dest="input_dir", help="IDEAS para files directory"), + make_option(c("-o", "--output_dir"), action="store", dest="output_dir", help="PDF output directory") ) parser <- OptionParser(usage="%prog [options] file", option_list=option_list) @@ -38,7 +38,7 @@ return(rt); } -create_heatmap<-function(data_frame, statecolor=NULL, markcolor=NULL, cols=c("white","dark blue")) { +create_heatmap<-function(data_frame, output_file_name, statecolor=NULL, markcolor=NULL, cols=c("white","dark blue")) { k = dim(data_frame)[2]; l = dim(data_frame)[1]; p = (sqrt(9 + 8 * (k - 1)) - 3) / 2; @@ -46,10 +46,10 @@ colnames(data_matrix) = colnames(data_frame)[1+1:p]; marks = colnames(data_matrix); rownames(data_matrix) = paste(1:l," (", round(data_frame[,1] / sum(data_frame[,1]) * 10000) / 100, "%)", sep=""); - pdf(file=opt$output); - par(mar=c(6,1,1,6)); + pdf(file=output_file_name); + par(mar=c(6, 1, 1, 6)); rg = range(data_matrix); - colors = 0:100/100*(rg[2]-rg[1])+rg[1]; + colors = 0:100 / 100 * (rg[2] - rg[1]) + rg[1]; my_palette = colorRampPalette(cols)(n=100); defpalette = palette(my_palette); @@ -110,6 +110,12 @@ dev.off(); } -# Read the input. -data_frame <- read.table(opt$input, comment="!", header=T); -create_heatmap(data_frame); +# Read the inputs. +para_files <- list.files(path=input_dir, pattern="*.para", full.names=TRUE); +for (i in 1:length(para_files) { + para_file <- para_files[i]; + para_file_base_name <- strsplit(para_file, ".para", fixed=TRUE)[1]; + output_file_name <- paste(opt$output_dir, "/", para_file_base_name, ".pdf", sep=""); + data_frame <- read.table(para_file, comment="!", header=T); + create_heatmap(data_frame, output_file_name); +}