Mercurial > repos > greg > ideas_genome_tracks
changeset 77:8c4549f123da draft
Uploaded
author | greg |
---|---|
date | Wed, 03 Jan 2018 13:59:17 -0500 |
parents | a3bd0cecdeb2 |
children | 55da56869a0d |
files | ideas_genome_tracks.R |
diffstat | 1 files changed, 39 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/ideas_genome_tracks.R Wed Jan 03 13:59:09 2018 -0500 +++ b/ideas_genome_tracks.R Wed Jan 03 13:59:17 2018 -0500 @@ -8,36 +8,39 @@ 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("--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("--script_dir"), action="store", dest="script_dir", help="R script source directory"), - make_option(c("--short_label"), action="store", dest="short_label", help="Hub short label"), - 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_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) args <- parse_args(parser, positional_arguments=TRUE) opt <- args$options -create_primary_html = function(output_trackhub, tracks_dir, build) { - track_files <- list.files(path=tracks_dir); +create_primary_html = function(output_trackhub, hub_dir) { + hub_dir_files <- list.files(path=hub_dir); s <- paste('<html><head></head><body>', sep="\n"); - s <- paste(s, '<h3>Contents of directory ~/myHub/', build, ' required by UCSC TrackHub</h3>\n', sep=""); + s <- paste(s, '<h3>Contents of directory ~/myHub', ' required by UCSC TrackHub</h3>\n', sep=""); s <- paste(s, '<ul>\n', sep="") - for (i in 1:length(track_files)) { - s <- paste(s, '<li><a href="', 'myHub/', build, "/", track_files[i], '">', track_files[i], '</a></li>\n', sep=""); + for (i in 1:length(hub_dir_files)) { + s <- paste(s, '<li><a href="', 'myHub/', "/", hub_dir_files[i], '">', hub_dir_files[i], '</a></li>\n', sep=""); } s <- paste(s, '</ul>\n</body>\n</html>', sep=""); cat(s, file=output_trackhub); } -create_track = function(input_dir_state, chrom_len_file, base_track_file_name) { + + +create_cells = function(input_dir_state, chrom_len_file, base_track_file_name, state_indexes, state_names, state_colors) { # Create everything needed, including the bigbed file, # to render the tracks within the UCSC track hub. state_files <- list.files(path=input_dir_state, full.names=TRUE); @@ -99,8 +102,8 @@ 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, short_label, long_label, state_indexes, 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, state_indexes, state_names, state_colors) { # Create a trackDb.txt file that includes each state. para_files <- list.files(path=input_dir_para, full.names=TRUE); ###### @@ -108,10 +111,8 @@ # are multiple .para files. See the comments in the for loop # below. data_frame <- read.table(para_files[1], comment="!", header=T); - color_hex_code <- create_heatmap(data_frame); + color_hex_code <- create_heatmap(data_frame); ###### - base_track_file_name <- paste(tracks_dir, hub_name, sep=""); - cells = create_track(input_dir_state, chrom_len_file, base_track_file_name); if (!is.null(state_indexes)) { # Split state_indexes into a list of integers. s_indexes <- c(); @@ -120,6 +121,19 @@ for (item in items) { s_indexes <- c(s_indexes, as.integer(item)); } + # Split state_names into a list of strings. + s_names <- c(); + name_str <- as.character(state_colors); + items <- strsplit(name_str, ","); + item_index <- 0; + for (item in items) { + item_index = item_index + 1; + # Handle the special string "use state index". + if (identical(item, "use state index")) { + item <- s_indexes[item_index]; + } + s_names <- c(s_names, item); + } # Split state_colors into a list of strings. s_colors <- c(); color_str <- as.character(state_colors); @@ -128,6 +142,8 @@ s_colors <- c(s_colors, item); } } + 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); track_db = NULL; for (i in 1:length(cells)) { # Get the color for the current state. @@ -147,8 +163,8 @@ track_db = c(track_db, paste("track ", hub_name, "_track_", i, sep="")); track_db = c(track_db, "type bigBed"); track_db = c(track_db, paste("bigDataUrl", big_data_url, sep=" ")); - track_db = c(track_db, paste("shortLabel", short_label, sep=" ")); - track_db = c(track_db, paste("longLabel", long_label, sep=" ")); + track_db = c(track_db, paste("shortLabel", hub_short_label, sep=" ")); + track_db = c(track_db, paste("longLabel", hub_long_label, sep=" ")); track_db = c(track_db, paste("priority", i)); track_db = c(track_db, "itemRgb on"); track_db = c(track_db, "maxItems 100000"); @@ -172,11 +188,11 @@ # Create the hub.txt output. hub_name_line <- paste("hub ", opt$hub_name, sep=""); -short_label_line <- paste("shortLabel ", opt$short_label, sep=""); -long_label_line <- paste("longLabel ", opt$long_label, sep=""); +hub_short_label_line <- paste("shortLabel ", opt$hub_short_label, sep=""); +hub_long_label_line <- paste("longLabel ", opt$hub_long_label, sep=""); genomes_txt_line <- paste("genomesFile genomes.txt", sep=""); email_line <- paste("email ", opt$email, sep=""); -contents <- paste(hub_name_line, short_label_line, long_label_line, genomes_txt_line, email_line, sep="\n"); +contents <- paste(hub_name_line, hub_short_label_line, hub_long_label_line, genomes_txt_line, email_line, sep="\n"); hub_dir <- paste(opt$output_trackhub_files_path, "/", "myHub", "/", sep=""); dir.create(hub_dir, showWarnings=FALSE); hub_file_path <- paste(hub_dir, "hub.txt", sep=""); @@ -195,12 +211,12 @@ tracks_dir <- paste(hub_dir, opt$build, "/", sep=""); dir.create(tracks_dir, showWarnings=FALSE); track_db <- create_track_db(opt$galaxy_url, opt$output_trackhub_id, opt$input_dir_para, opt$input_dir_state, opt$build, - opt$chrom_len_file, tracks_dir, opt$hub_name, opt$short_label, opt$long_label, opt$state_indexes, opt$state_colors); + opt$chrom_len_file, tracks_dir, opt$hub_name, opt$hub_short_label, opt$hub_long_label, opt$state_indexes, + opt$state_names, opt$state_colors); # Create the trackDb.txt output. track_db_file_path <- paste(tracks_dir, "trackDb.txt", sep=""); 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, hub_dir);