Mercurial > repos > greg > ideas_genome_tracks
changeset 11:45a2f84b8247 draft
Uploaded
author | greg |
---|---|
date | Thu, 16 Nov 2017 13:20:13 -0500 |
parents | 2b484c93d20a |
children | 0f385fb474ca |
files | ideas_genome_tracks.R |
diffstat | 1 files changed, 28 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/ideas_genome_tracks.R Thu Nov 16 13:18:58 2017 -0500 +++ b/ideas_genome_tracks.R Thu Nov 16 13:20:13 2017 -0500 @@ -9,14 +9,14 @@ make_option(c("-d", "--header"), action="store", dest="header", default=NULL, help="Track header"), make_option(c("-e", "--state_name"), action="store", dest="state_name", help="State name"), make_option(c("-f", "--hub_id"), action="store", dest="hub_id", help="Not sure what this is"), + make_option(c("-g", "--email"), action="store", dest="email", help="User email address"), make_option(c("-i", "--cell_info"), action="store", dest="cell_info", default=NULL, help="Not sure what this is"), make_option(c("-n", "--hub_name"), action="store", dest="hub_name", default=NULL, help="Not sure what this is"), make_option(c("-p", "--input_dir_para"), action="store", dest="input_dir_para", help="Directory containing .para outputs from IDEAS"), make_option(c("-q", "--input_dir_state"), action="store", dest="input_dir_state", help="Directory containing .state outputs from IDEAS"), make_option(c("-u", "--output_track_db"), action="store", dest="output_track_db", help="Output track db file"), - make_option(c("-v", "--output_build"), action="store", dest="output_build", help="Output genome build file"), - make_option(c("-w", "--output_hub"), action="store", dest="output_hub", help="Output hub file"), - make_option(c("-x", "--output_hub_files_path"), action="store", dest="output_hub_files_path", help="Output hub extra files path") + make_option(c("-w", "--output_trackhub"), action="store", dest="output_trackhub", help="Output hub file"), + make_option(c("-x", "--output_trackhub_files_path"), action="store", dest="output_trackhub_files_path", help="Output hub extra files path") ) parser <- OptionParser(usage="%prog [options] file", option_list=option_list) @@ -39,7 +39,7 @@ p = x[,1] / sum(x[,1]); m = array(as.matrix(x[,1:l+1] / x[,1]), dim=c(dim(x)[1], l)); state_color <- get_state_color(m, mc); - state_color + return(state_color); } get_state_color = function(statemean, markcolor=NULL) @@ -66,7 +66,7 @@ return(rt); } -create_track = function(input_dir_state, chrom_len_file, outpref, state_color, header, state_name) { +create_track = function(input_dir_state, chrom_len_file, base_track_file_name, state_color, state_name, header) { state_files <- list.files(path=input_dir_state, full.names=TRUE); genome_size = read.table(chrom_len_file); g = NULL; @@ -108,7 +108,7 @@ g1 = NULL; options(scipen=999); tt = which(chr[2:L]!=chr[2:L-1]); - tt = c(tt,which(posst[2:L]!=posed[2:L-1])); + tt = c(tt, which(posst[2:L]!=posed[2:L-1])); tt = sort(unique(tt)); for(i in 1:n) { tstate = state[,i]; @@ -118,15 +118,18 @@ t = c(t, L); np = cbind(chr[t], posst[t0], posed[t], tstate[t]); x = cbind(np[,1:3], state_name[as.integer(np[,4])+1], 1000, ".", np[,2:3], state_color[as.numeric(np[,4])+1]); - write.table(as.matrix(x), paste(outpref, i, "bed1", sep="."), quote=F, row.names=F, col.names=F); - system(paste("bedToBigBed ", outpref, ".", i, ".bed1 ", chrom_len_file, " ", outpref, ".", i, ".bb", sep="")); - system(paste("rm ", paste(outpref, i, "bed1", sep="."))); + track_file_name_bed <- paste(base_track_file_name, i, "bed", sep=".") + track_file_name_bigbed <- paste(base_track_file_name, i, "bigbed", sep=".") + write.table(as.matrix(x), track_file_name_bed, quote=F, row.names=F, col.names=F); + system(paste("bedToBigBed ", track_file_name_bed, chrom_len_file, " ", track_file_name_bigbed)); + #system(paste("rm ", track_file_name_bed)); } return(cells); } -create_track_db = function(input_dir_state, chrom_len_file, track_file_name, state_color, header, state_name, hub_name, cell_info) { - cells = create_track(input_dir_state, chrom_len_file, track_file_name, state_color, header, state_name); +create_track_db = function(input_dir_state, chrom_len_file, header, tracks_dir, hub_id, hub_name, state_color, state_name, cell_info) { + base_track_file_name <- paste(tracks_dir, hub_id, sep=""); + cells = create_track(input_dir_state, chrom_len_file, base_track_file_name, state_color, state_name, header); if (length(cell_info) == 0) { cell_info = cbind(cells, cells, cells, "#000000"); cell_info = array(cell_info, dim=c(length(cells), 4)); @@ -150,6 +153,7 @@ track_db = c(track_db, "visibility dense"); track_db = c(track_db, ""); } + return(track_db); } if (length(opt$hub_name) == 0) { @@ -158,17 +162,22 @@ hub_name <- opt$hub_name; } -# Create the tracks output directory. -tracks_output_dir = paste("tracks_", opt$hub_id, "/", sep=""); -dir.create(tracks_output_dir, showWarnings=FALSE); - # Create the color scheme. state_color <- create_color_scheme(opt$input_dir_para); # Create the tracks. -track_db <- create_track_db(opt$input_dir_state, opt$chrom_len_file, paste(tracks_output_dir, opt$hub_id, sep=""), state_color, opt$header, opt$state_name, hub_name, opt$cell_info); +tracks_dir <- paste(opt$output_trackhub_files_path, "/tracks_", opt$hub_id, "/", sep=""); +dir.create(tracks_dir, showWarnings=FALSE); +track_db <- create_track_db(opt$input_dir_state, opt$chrom_len_file, opt$header, tracks_dir, hub_id, hub_name, state_color, opt$state_name, opt$cell_info); # Write the outputs. -write.table(track_db, opt$output_track_db, quote=F, row.names=F, col.names=F); -write.table(c(paste("genome", opt$build), opt$output_build), paste(tracks_output_dir, "genomes_", opt$hub_id, ".txt", sep=""), quote=F, row.names=F, col.names=F); -write.table(c(paste("hub", opt$hub_id), paste("shortLabel", opt$hub_id), paste("longLabel", hub_name), paste("genomesFile genomes_", opt$hub_id, ".txt", sep=""), "email yzz2 at psu.edu"), paste(opt$output_hub_files_path, "hub_", opt$hub_id, ".txt", sep=""), quote=F, row.names=F, col.names=F); +track_db_file_name <- paste(tracks_dir, "trackDb_", opt$hub_id, ".txt", sep="") +write.table(track_db, file=track_db_file_name, quote=F, row.names=F, col.names=F); + +obj_name <- c(paste("genome", opt$build), paste("trackDb trackDb_", opt$hub_id, ".txt", sep="")) +genomes_file_name <- paste(opt$output_hub_files_path, "genomes_", opt$hub_id, ".txt", sep="") +write.table(obj_name, file=genomes_file_name, quote=F, row.names=F, col.names=F); + +obj_name <- c(paste("hub", opt$hub_id), paste("shortLabel", opt$hub_id), paste("longLabel", hub_name), paste("genomesFile genomes_", opt$hub_id, ".txt", sep=""), paste("email", opt$email)) +hub_file_name <- paste(opt$output_hub_files_path, "hub_", opt$hub_id, ".txt", sep="") +write.table(obj_name, file=hub_file_name, quote=F, row.names=F, col.names=F);