comparison create_heatmap.R @ 135:fc94a1ce21eb draft

Uploaded
author greg
date Fri, 15 Dec 2017 16:48:53 -0500
parents 7d49fc24e06a
children 8d41990f4fc5
comparison
equal deleted inserted replaced
134:91db24a1384d 135:fc94a1ce21eb
1 #!/usr/bin/env Rscript 1 #!/usr/bin/env Rscript
2 2
3 suppressPackageStartupMessages(library("optparse")) 3 suppressPackageStartupMessages(library("optparse"))
4 4
5 option_list <- list( 5 option_list <- list(
6 make_option(c("-i", "--input_dir"), action="store", dest="input_dir", help="IDEAS para files directory"), 6 make_option(c("-i", "--input_dir"), action="store", dest="input_dir", help="IDEAS para files directory"),
7 make_option(c("-o", "--output_dir"), action="store", dest="output_dir", help="PDF output directory") 7 make_option(c("-o", "--output_dir"), action="store", dest="output_dir", help="PDF output directory")
8 ) 8 )
9 9
10 parser <- OptionParser(usage="%prog [options] file", option_list=option_list) 10 parser <- OptionParser(usage="%prog [options] file", option_list=option_list)
11 args <- parse_args(parser, positional_arguments=TRUE) 11 args <- parse_args(parser, positional_arguments=TRUE)
12 opt <- args$options 12 opt <- args$options
17 # by reading the .para file. 17 # by reading the .para file.
18 num_columns = dim(data_frame)[2]; 18 num_columns = dim(data_frame)[2];
19 num_rows = dim(data_frame)[1]; 19 num_rows = dim(data_frame)[1];
20 p = (sqrt(9 + 8 * (num_columns - 1)) - 3) / 2; 20 p = (sqrt(9 + 8 * (num_columns - 1)) - 3) / 2;
21 data_matrix = as.matrix(data_frame[,1+1:p] / data_frame[,1]); 21 data_matrix = as.matrix(data_frame[,1+1:p] / data_frame[,1]);
22 column_names(data_matrix) = column_names(data_frame)[1+1:p]; 22 colnames(data_matrix) = colnames(data_frame)[1+1:p];
23 marks = column_names(data_matrix); 23 marks = colnames(data_matrix);
24 row_names(data_matrix) = paste(1:num_rows, " (", round(data_frame[,1]/sum(data_frame[,1])*10000)/100, "%)", sep=""); 24 rownames(data_matrix) = paste(1:num_rows, " (", round(data_frame[,1]/sum(data_frame[,1])*10000)/100, "%)", sep="");
25 25
26 # Open the output PDF file. 26 # Open the output PDF file.
27 pdf(file=output_file_name); 27 pdf(file=output_file_name);
28 # Set graphical parameters. 28 # Set graphical parameters.
29 par(mar=c(6, 1, 1, 6)); 29 par(mar=c(6, 1, 1, 6));
33 colors = 0:100 / 100 * (min_max_vector[2] - min_max_vector[1]) + min_max_vector[1]; 33 colors = 0:100 / 100 * (min_max_vector[2] - min_max_vector[1]) + min_max_vector[1];
34 # Create the color palette. 34 # Create the color palette.
35 my_palette = colorRampPalette(c("white", "dark blue"))(n=100); 35 my_palette = colorRampPalette(c("white", "dark blue"))(n=100);
36 defpalette = palette(my_palette); 36 defpalette = palette(my_palette);
37 # Plot the heatmap for the current .para / .state combination. 37 # Plot the heatmap for the current .para / .state combination.
38 plot(NA, NA, xlim=c(0,p+0.7), ylim=c(0,l), xaxt="n", yaxt="n", xlab=NA, ylab=NA, frame.plot=F); 38 plot(NA, NA, xlim=c(0, p+0.7), ylim=c(0, num_rows), xaxt="n", yaxt="n", xlab=NA, ylab=NA, frame.plot=F);
39 axis(1, at=1:p-0.5, labels=column_names(data_matrix), las=2); 39 axis(1, at=1:p-0.5, labels=colnames(data_matrix), las=2);
40 axis(4, at=1:num_rows-0.5, labels=row_names(data_matrix), las=2); 40 axis(4, at=1:num_rows-0.5, labels=rownames(data_matrix), las=2);
41 rect(rep(1:p-1, num_rows), rep(1:num_rows, each=p), rep(1:p, num_rows), rep(1:num_rows, each=p), 41 rect(rep(1:p-1, num_rows), rep(1:num_rows, each=p), rep(1:p, num_rows), rep(1:num_rows, each=p),
42 col=round((t(data_matrix)-min_max_vector[1])/(min_max_vector[2]-min_max_vector[1])*100)); 42 col=round((t(data_matrix)-min_max_vector[1])/(min_max_vector[2]-min_max_vector[1])*100));
43 markcolor = t(col2rgb(terrain.colors(ceiling(p))[1:p])); 43 markcolor = t(col2rgb(terrain.colors(ceiling(p))[1:p]));
44 44
45 for(i in 1:length(marks)) { 45 for(i in 1:length(marks)) {