changeset 45:fbc520a3d0e2 draft

Uploaded
author greg
date Thu, 14 Dec 2017 10:01:20 -0500
parents fa8dc7f00b43
children 1290764e2750
files ideas_genome_tracks.R
diffstat 1 files changed, 17 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/ideas_genome_tracks.R	Thu Dec 14 09:58:35 2017 -0500
+++ b/ideas_genome_tracks.R	Thu Dec 14 10:01:20 2017 -0500
@@ -5,18 +5,18 @@
 suppressPackageStartupMessages(library("viridislite"))
 
 option_list <- list(
-            make_option(c("--build"), action="store", dest="build", help="Genome build"),
-            make_option(c("--chrom_len_file"), action="store", dest="chrom_len_file", help="Chromosome length file"),
-            make_option(c("--email"),  action="store", dest="email", help="User email address"),
-            make_option(c("--galaxy_url"),  action="store", dest="galaxy_url", help="Galaxy instance base URL"),
-            make_option(c("--hub_name"),  action="store", dest="hub_name", default=NULL, help="Hub name without spaces"),
-            make_option(c("--input_dir_para"), action="store", dest="input_dir_para", help="Directory containing .para outputs from IDEAS"),
-            make_option(c("--input_dir_state"), action="store", dest="input_dir_state", help="Directory containing .state outputs from IDEAS"),
-            make_option(c("--long_label"), action="store", dest="long_label", help="Hub long label"),
-            make_option(c("--output_trackhub"),  action="store", dest="output_trackhub", help="Output hub file"),
-            make_option(c("--output_trackhub_files_path"),  action="store", dest="output_trackhub_files_path", help="Output hub extra files path"),
-            make_option(c("--output_trackhub_id"),  action="store", dest="output_trackhub_id", help="Encoded output_trackhub dataset id"),
-            make_option(c("--short_label"), action="store", dest="short_label", help="Hub short label")
+        make_option(c("--build"), action="store", dest="build", help="Genome build"),
+        make_option(c("--chrom_len_file"), action="store", dest="chrom_len_file", help="Chromosome length file"),
+        make_option(c("--email"),  action="store", dest="email", help="User email address"),
+        make_option(c("--galaxy_url"),  action="store", dest="galaxy_url", help="Galaxy instance base URL"),
+        make_option(c("--hub_name"),  action="store", dest="hub_name", default=NULL, help="Hub name without spaces"),
+        make_option(c("--input_dir_para"), action="store", dest="input_dir_para", help="Directory containing .para outputs from IDEAS"),
+        make_option(c("--input_dir_state"), action="store", dest="input_dir_state", help="Directory containing .state outputs from IDEAS"),
+        make_option(c("--long_label"), action="store", dest="long_label", help="Hub long label"),
+        make_option(c("--output_trackhub"),  action="store", dest="output_trackhub", help="Output hub file"),
+        make_option(c("--output_trackhub_files_path"),  action="store", dest="output_trackhub_files_path", help="Output hub extra files path"),
+        make_option(c("--output_trackhub_id"),  action="store", dest="output_trackhub_id", help="Encoded output_trackhub dataset id"),
+        make_option(c("--short_label"), action="store", dest="short_label", help="Hub short label")
 )
 
 parser <- OptionParser(usage="%prog [options] file", option_list=option_list)
@@ -37,6 +37,7 @@
 
 create_track = function(input_dir_para, input_dir_state, chrom_len_file, base_track_file_name) {
     para_files <- list.files(path=input_dir_para, full.names=TRUE);
+    cat("para_files: ", para_files, "\n");
     state_files <- list.files(path=input_dir_state, full.names=TRUE);
     genome_size = read.table(chrom_len_file);
     g = NULL;
@@ -75,8 +76,9 @@
     tt = which(chr[2:L]!=chr[2:L-1]);
     tt = c(tt, which(posst[2:L]!=posed[2:L-1]));
     tt = sort(unique(tt));
+    state_color <- get_state_color(para_files[1])
     for(i in 1:n) {
-        state_color <- get_state_color(para_files[i])
+        cat("i: ", i, "\n");
         tstate = state[,i];
         t = c(tt, which(tstate[2:L]!=tstate[2:L-1]));
         t = sort(unique(t));
@@ -165,7 +167,7 @@
 }
 
 get_state_color <- function(para_file, cols=c("white", "dark blue")) {
-    x = read.table(parafile, comment.char="#", header=T);
+    x = read.table(para_file, comment="!", header=T);
     k = dim(x)[2];
     l = dim(x)[1];
     p = (sqrt(9+8*(k-1))-3)/2;
@@ -176,12 +178,6 @@
     par(mar=c(6,1,1,6));
     rg = range(m);
     colors = 0:100/100*(rg[2]-rg[1])+rg[1];
-    my_palette = colorRampPalette(cols)(n=100);
-    defpalette = palette(my_palette);
-    plot(NA,NA,xlim=c(0,p+0.7),ylim=c(0,l),xaxt="n",yaxt="n",xlab=NA,ylab=NA,frame.plot=F);
-    axis(1,at=1:p-0.5,labels=colnames(m),las=2);
-    axis(4,at=1:l-0.5,labels=rownames(m),las=2);
-    rect(rep(1:p-1,l),rep(1:l-1,each=p),rep(1:p,l),rep(1:l,each=p),col=round((t(m)-rg[1])/(rg[2]-rg[1])*100));
     markcolor = t(col2rgb(terrain.colors(ceiling(p))[1:p]));
     for(i in 1:length(marks)) {
         if (regexpr("h3k4me3",tolower(marks[i]))>0) {
@@ -228,8 +224,6 @@
         }
     }
     statecolor = get_rgb(m, markcolor)[,];
-    rect(rep(p+0.2,l),1:l-0.8,rep(p+0.8,l),1:l-0.2,col=statecolor[,2]);
-    palette(defpalette);
     return(statecolor);
 }
 
@@ -267,4 +261,4 @@
 write.table(track_db, file=track_db_file_path, quote=F, row.names=F, col.names=F);
 
 # Create the primary HTML dataset.
-create_primary_html(opt$output_trackhub, tracks_dir, opt$build);
+create_primary_html(opt$output_trackhub, tracks_dir, opt$build);
\ No newline at end of file