Mercurial > repos > greg > ideas
changeset 141:a976dd6fcd1b draft
Uploaded
author | greg |
---|---|
date | Wed, 20 Dec 2017 11:24:23 -0500 |
parents | 17e8829bbae2 |
children | 8cfcf32c4282 |
files | create_heatmap.R create_heatmaps.R ideas.xml test-data/genomic_windows.bed |
diffstat | 4 files changed, 87 insertions(+), 80 deletions(-) [+] |
line wrap: on
line diff
--- a/create_heatmap.R Tue Dec 19 12:29:29 2017 -0500 +++ b/create_heatmap.R Wed Dec 20 11:24:23 2017 -0500 @@ -1,17 +1,6 @@ #!/usr/bin/env Rscript -suppressPackageStartupMessages(library("optparse")) - -option_list <- list( - 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) -args <- parse_args(parser, positional_arguments=TRUE) -opt <- args$options - -create_heatmap<-function(data_frame, output_file_name) { +create_heatmap<-function(data_frame, output_file_name=NULL) { # Plot a heatmap for a .para / .state combination # based on the received data_frame which was created # by reading the .para file. @@ -22,8 +11,10 @@ colnames(data_matrix) = colnames(data_frame)[1+1:p]; histone_marks = colnames(data_matrix); rownames(data_matrix) = paste(1:num_rows-1, " (", round(data_frame[,1]/sum(data_frame[,1])*10000)/100, "%)", sep=""); - # Open the output PDF file. - pdf(file=output_file_name); + if (!is.null(output_file_name)) { + # Open the output PDF file. + pdf(file=output_file_name); + } # Set graphical parameters. par(mar=c(6, 1, 1, 6)); # Create a vector containing the minimum and maximum values in data_matrix. @@ -87,15 +78,18 @@ } rect(rep(p+0.2, num_rows), 1:num_rows-0.8, rep(p+0.8, num_rows), 1:num_rows-0.2, col=state_color); palette(defpalette); - dev.off(); + if (!is.null(output_file_name)) { + dev.off(); + } + return(state_color); } get_state_color <- function(data_matrix, histone_mark_color) { range_vector = apply(data_matrix, 1, range); mm = NULL; for(i in 1:dim(data_matrix)[1]) { - range_val1 = range_vector[1, i] + 1e-10 - range_val2 = range_vector[2, i] + range_val1 = range_vector[1, i] + 1e-10; + range_val2 = range_vector[2, i]; mm = rbind(mm, (data_matrix[i,] - range_val1) / (range_val2 - range_val1)); } mm = mm^5; @@ -113,15 +107,3 @@ rt = cbind(rt, h); return(rt); } - -# Read the inputs. -para_files <- list.files(path=opt$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, split="/")[[1]][2] - output_file_base_name <- gsub(".para", "", para_file_base_name) - output_file_name <- paste(output_file_base_name, "state", i, "pdf", sep=".") - output_file_path <- paste(opt$output_dir, output_file_name, sep="/"); - data_frame <- read.table(para_file, comment="!", header=T); - create_heatmap(data_frame, output_file_path); -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/create_heatmaps.R Wed Dec 20 11:24:23 2017 -0500 @@ -0,0 +1,25 @@ +#!/usr/bin/env Rscript + +suppressPackageStartupMessages(library("optparse")) + +option_list <- list( + 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); +args <- parse_args(parser, positional_arguments=TRUE); +opt <- args$options; + +source("create_heatmap.R"); + +para_files <- list.files(path=opt$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, split="/")[[1]][2]; + output_file_base_name <- gsub(".para", "", para_file_base_name); + output_file_name <- paste(output_file_base_name, "state", i, "pdf", sep="."); + output_file_path <- paste(opt$output_dir, output_file_name, sep="/"); + data_frame <- read.table(para_file, comment="!", header=T); + create_heatmap(data_frame, output_file_path); +}
--- a/ideas.xml Tue Dec 19 12:29:29 2017 -0500 +++ b/ideas.xml Wed Dec 20 11:24:23 2017 -0500 @@ -182,7 +182,7 @@ && mv ./*.profile '$output_txt_dir' && mv ./*.state '$output_txt_dir' #if str($output_heatmaps) == "yes": - && Rscript '$__tool_directory__/create_heatmap.R' + && Rscript '$__tool_directory__/create_heatmaps.R' -i '$output_txt_dir' -o '$output_pdf_dir' #end if
--- a/test-data/genomic_windows.bed Tue Dec 19 12:29:29 2017 -0500 +++ b/test-data/genomic_windows.bed Wed Dec 20 11:24:23 2017 -0500 @@ -1,50 +1,50 @@ -chr1 21819600 21819800 R100001 -chr1 21819800 21820000 R100002 -chr1 21820000 21820200 R100003 -chr1 21820200 21820400 R100004 -chr1 21820400 21820600 R100005 -chr1 21820600 21820800 R100006 -chr1 21820800 21821000 R100007 -chr1 21821000 21821200 R100008 -chr1 21821200 21821400 R100009 -chr1 21821400 21821600 R100010 -chr1 21821600 21821800 R100011 -chr1 21821800 21822000 R100012 -chr1 21822000 21822200 R100013 -chr1 21822200 21822400 R100014 -chr1 21822400 21822600 R100015 -chr1 21822600 21822800 R100016 -chr1 21822800 21823000 R100017 -chr1 21823000 21823200 R100018 -chr1 21823200 21823400 R100019 -chr1 21823400 21823600 R100020 -chr1 21823600 21823800 R100021 -chr1 21823800 21824000 R100022 -chr1 21824000 21824200 R100023 -chr1 21824200 21824400 R100024 -chr1 21824400 21824600 R100025 -chr1 21824600 21824800 R100026 -chr1 21824800 21825000 R100027 -chr1 21825000 21825200 R100028 -chr1 21825200 21825400 R100029 -chr1 21825400 21825600 R100030 -chr1 21825600 21825800 R100031 -chr1 21825800 21826000 R100032 -chr1 21826000 21826200 R100033 -chr1 21826200 21826400 R100034 -chr1 21826400 21826600 R100035 -chr1 21826600 21826800 R100036 -chr1 21826800 21827000 R100037 -chr1 21827000 21827200 R100038 -chr1 21827200 21827400 R100039 -chr1 21827400 21827600 R100040 -chr1 21827600 21827800 R100041 -chr1 21827800 21828000 R100042 -chr1 21828000 21828200 R100043 -chr1 21828200 21828400 R100044 -chr1 21828400 21828600 R100045 -chr1 21829000 21829200 R100046 -chr1 21829400 21829600 R100047 -chr1 21829600 21829800 R100048 -chr1 21829800 21830000 R100049 -chr1 21830000 21830200 R100050 +chr1 21819600 21819800 R100001 +chr1 21819800 21820000 R100002 +chr1 21820000 21820200 R100003 +chr1 21820200 21820400 R100004 +chr1 21820400 21820600 R100005 +chr1 21820600 21820800 R100006 +chr1 21820800 21821000 R100007 +chr1 21821000 21821200 R100008 +chr1 21821200 21821400 R100009 +chr1 21821400 21821600 R100010 +chr1 21821600 21821800 R100011 +chr1 21821800 21822000 R100012 +chr1 21822000 21822200 R100013 +chr1 21822200 21822400 R100014 +chr1 21822400 21822600 R100015 +chr1 21822600 21822800 R100016 +chr1 21822800 21823000 R100017 +chr1 21823000 21823200 R100018 +chr1 21823200 21823400 R100019 +chr1 21823400 21823600 R100020 +chr1 21823600 21823800 R100021 +chr1 21823800 21824000 R100022 +chr1 21824000 21824200 R100023 +chr1 21824200 21824400 R100024 +chr1 21824400 21824600 R100025 +chr1 21824600 21824800 R100026 +chr1 21824800 21825000 R100027 +chr1 21825000 21825200 R100028 +chr1 21825200 21825400 R100029 +chr1 21825400 21825600 R100030 +chr1 21825600 21825800 R100031 +chr1 21825800 21826000 R100032 +chr1 21826000 21826200 R100033 +chr1 21826200 21826400 R100034 +chr1 21826400 21826600 R100035 +chr1 21826600 21826800 R100036 +chr1 21826800 21827000 R100037 +chr1 21827000 21827200 R100038 +chr1 21827200 21827400 R100039 +chr1 21827400 21827600 R100040 +chr1 21827600 21827800 R100041 +chr1 21827800 21828000 R100042 +chr1 21828000 21828200 R100043 +chr1 21828200 21828400 R100044 +chr1 21828400 21828600 R100045 +chr1 21829000 21829200 R100046 +chr1 21829400 21829600 R100047 +chr1 21829600 21829800 R100048 +chr1 21829800 21830000 R100049 +chr1 21830000 21830200 R100050