Mercurial > repos > greg > ideas_genome_tracks
changeset 87:60ce288eb52f draft
Uploaded
author | greg |
---|---|
date | Fri, 05 Jan 2018 13:56:36 -0500 |
parents | 3e19f09ca68d |
children | 3e9e8a7bcba6 |
files | ideas_genome_tracks.R |
diffstat | 1 files changed, 98 insertions(+), 45 deletions(-) [+] |
line wrap: on
line diff
--- a/ideas_genome_tracks.R Fri Jan 05 13:54:44 2018 -0500 +++ b/ideas_genome_tracks.R Fri Jan 05 13:56:36 2018 -0500 @@ -4,22 +4,22 @@ suppressPackageStartupMessages(library("optparse")) 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_long_label"), action="store", dest="hub_long_label", help="Hub long label"), - make_option(c("--hub_name"), action="store", dest="hub_name", default=NULL, help="Hub name without spaces"), - make_option(c("--hub_short_label"), action="store", dest="hub_short_label", help="Hub short label"), - 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("--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("--script_dir"), action="store", dest="script_dir", help="R script source directory"), - make_option(c("--state_colors"), action="store", dest="state_colors", default=NULL, help="List of state colors"), - make_option(c("--state_indexes"), action="store", dest="state_indexes", default=NULL, help="List of state indexes"), - make_option(c("--state_names"), action="store", dest="state_names", default=NULL, help="List of state names") + 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_long_label"), action="store", dest="hub_long_label", help="Hub long label"), + make_option(c("--hub_name"), action="store", dest="hub_name", default=NULL, help="Hub name without spaces"), + make_option(c("--hub_short_label"), action="store", dest="hub_short_label", help="Hub short label"), + 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("--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("--script_dir"), action="store", dest="script_dir", help="R script source directory"), + make_option(c("--state_colors"), action="store", dest="state_colors", default=NULL, help="List of state colors"), + make_option(c("--state_indexes"), action="store", dest="state_indexes", default=NULL, help="List of state indexes"), + make_option(c("--state_names"), action="store", dest="state_names", default=NULL, help="List of state names") ) parser <- OptionParser(usage="%prog [options] file", option_list=option_list) @@ -88,6 +88,7 @@ t0 = c(0, t) + 1; t = c(t, L); np = cbind(chr[t], posst[t0], posed[t], tstate[t]); + #cat("JJJJJJJ as.numeric(np[,4]: ", as.numeric(np[,4]), "\n"); track_file_name_bed_unsorted <- get_track_file_name(base_track_file_name, i, "bed_unsorted"); track_file_name_bed <- get_track_file_name(base_track_file_name, i, "bed"); track_file_name_bigbed <- get_track_file_name(base_track_file_name, i, "bigbed"); @@ -103,52 +104,84 @@ return(cells); } -create_track_db = function(galaxy_url, encoded_dataset_id, input_dir_para, input_dir_state, build, chrom_len_file, - tracks_dir, hub_name, hub_short_label, hub_long_label, state_indexes, state_names, state_colors) { +create_track_db = function(galaxy_url, encoded_dataset_id, input_dir_para, input_dir_state, build, chrom_len_file, tracks_dir, + hub_name, hub_short_label, hub_long_label, specified_state_indexes, specified_state_names, specified_state_colors) { # Create a trackDb.txt file that includes each state. - s_indexes = c(); - s_names = c(); - s_colors = c(); - # Generate the default state colors. + #cat("\n\n\n\n\nXXXXXXXXXXXXXXXX Entered create_track_db\n"); + #cat("specified_state_indexes: ", specified_state_indexes, "\n"); + #cat("specified_state_names: ", specified_state_names, "\n"); + #cat("specified_state_colors: ", specified_state_colors, "\n"); + state_names = c(); + state_colors = list(); + # Generate the default state names and colors. + # IDEAS state indexes are zero based. index = 0; para_files = list.files(path=input_dir_para, full.names=TRUE); + #cat("para_files: ", toString(para_files), "\n\n\n"); for (para_file in para_files) { + #cat("para_file: ", para_file, "\n"); + # Append the default state name. + state_names = c(state_names, toString(index)); + #cat("\n", index,index,index,index, "state_names: ", state_names, "\n"); + # Append the default color codes vector. data_frame = read.table(para_file, comment="!", header=T); - color_hex_code = create_heatmap(data_frame); - s_indexes = c(s_indexes, index); - s_names = c(s_names, toString(index)); - s_colors = c(s_colors, color_hex_code); + # Here specified_state_colors will look something like this: + # 248,239,0 254,153,95 255,255,255 245,245,0 #F8EF00 #FE995F #FFFFFF #F5F500 + state_color_codes_vector = create_heatmap(data_frame); + #cat("state_color_codes_vector: ", state_color_codes_vector, "\n"); + #cat("typeof(state_color_codes_vector): ", typeof(state_color_codes_vector), "\n"); + #cat("length(state_color_codes_vector): ", length(state_color_codes_vector), "\n"); + state_colors[[index + 1]] = state_color_codes_vector; + #cat("\n", index,index,index,index, "state_colors: ", state_colors, "\n"); index = index + 1; } - if (!is.null(state_indexes)) { + #cat("\n\nBBBBBBBB default state_names: ", state_names, "\n"); + #cat("BBBBBBBB default typeof(state_names): ", typeof(state_names), "\n"); + #cat("BBBBBBBB default length(state_names): ", length(state_names), "\n"); + #cat("BBBBBBBB default state_colors: ", toString(state_colors), "\n"); + #cat("BBBBBBBB default length(state_colors): ", length(state_colors), "\n\n\n"); + if (!is.null(specified_state_indexes)) { # Replace default name with specified name and default # color with specified color for each selected state. - # Split state_indexes into a list of strings. - index_str = as.character(state_indexes); - state_index_items = strsplit(index_str, ","); - # Split state_names into a list of strings. - name_str = as.character(state_names); - state_name_items = strsplit(name_str, ","); - # Split state_colors into a list of strings. - color_str = as.character(state_colors); - state_color_items = strsplit(color_str, ","); + # Split specified_state_indexes into a list of strings. + index_str = as.character(specified_state_indexes); + specified_state_index_items = strsplit(index_str, ",")[[1]]; + # Split specified_state_names into a list of strings. + name_str = as.character(specified_state_names); + specified_state_name_items = strsplit(name_str, ",")[[1]]; + # Split specified_state_colors into a list of strings. + color_str = as.character(specified_state_colors); + specified_state_color_items = strsplit(color_str, ",")[[1]]; # Replace default names and colors. - specified_item_index = 1; - for (state_index_item in state_index_items) { - specified_index = as.integer(state_index_item); + loop_index = 1; + for (specified_state_index_item in specified_state_index_items) { + #cat("specified_state_index_item: ", specified_state_index_item, "\n"); + specified_index = as.integer(specified_state_index_item); + #cat("specified_index: ", specified_index, "\n"); # Replace default name with specified name. - specified_name = state_name_items[specified_item_index]; + specified_name = specified_state_name_items[loop_index]; # Handle the special string "use state index". if (identical(specified_name, "use state index")) { - specified_name = state_index_item; + specified_name = specified_state_index_item; } - s_names[specified_index] = specified_name; + #cat("specified_name: ", specified_name, "\n"); + #cat("state_names: ", state_names, "\n"); + #state_names[specified_index] = specified_name; + state_names = replace(state_names, state_names==specified_index, specified_name); + #cat("state_names: ", state_names, "\n"); # Replace default color with specified color. - s_colors[specified_index] = state_color_items[specified_item_index]; + #cat("specified_state_color_items[specified_item_index]: ", specified_state_color_items[specified_item_index], "\n"); + # FixMe: replacing default state colors is not yet working. + #state_colors[specified_index] = specified_state_color_items[loop_index]; + #cat("state_colors: ", toString(state_colors), "\n"); + loop_index = loop_index + 1; } } + #cat("\n\nCCCCCC reset state_names: ", state_names, "\n"); + #cat("CCCCCC reset state_colors: ", toString(state_colors), "\n"); + #cat("CCCCCC reset length(state_colors): ", length(state_colors), "\n\n\n"); base_track_file_name <- paste(tracks_dir, hub_name, sep=""); - cells = create_cells(input_dir_state, chrom_len_file, base_track_file_name, s_indexes, s_names, s_colors); + cells = create_cells(input_dir_state, chrom_len_file, base_track_file_name, state_indexes, state_names, state_colors); cell_info = cbind(cells, cells, cells, "#000000"); cell_info = array(cell_info, dim=c(length(cells), 4)); cell_info = as.matrix(cell_info); @@ -160,7 +193,27 @@ } ii = ii[1]; # Get the color for the current state. - color <- paste(c(col2rgb(s_colors[i])), collapse=","); + color_vector = state_colors[i]; + #cat("color_vector: ", toString(color_vector), "\n"); + # We are handling hte hub label color setting here. + # FixMe: Color selection is currently very confusing. I think we may + # need to add another color selector for the hub label. The current + # approach is to apply the specified color for the state to the hub label + # if the list of specified_state_index_items contains the value of i - 1 + # since state indexes are zero based. + #cat("specified_state_index_items: ", specified_state_index_items, "\n"); + #cat("length(specified_state_index_items): ", length(specified_state_index_items), "\n"); + state_index = i - 1; + #cat("state_index: ", state_index, "\n"); + if (state_index %in% specified_state_index_items) { + specified_state_color = specified_state_color_items[[i]]; + #cat("specified_state_color: ", specified_state_color, "\n"); + color = paste(c(col2rgb(specified_state_color)), collapse=","); + #cat("color 1: ", color, "\n"); + } else { + color = paste(c(col2rgb("#FFFFFF")), collapse=",") + #cat("color 2: ", color, "\n"); + } # Get the bigDataUrl. big_data_url <- get_big_data_url(galaxy_url, encoded_dataset_id, tracks_dir, i, build); # trackDb.txt track hub entry.