Mercurial > repos > greg > ideas_preprocessor
comparison ideas_preprocessor.R @ 9:0cf23f33d13d draft
Uploaded
| author | greg |
|---|---|
| date | Wed, 24 Jan 2018 10:16:11 -0500 |
| parents | 92bb33490bb4 |
| children | f45e461b0557 |
comparison
equal
deleted
inserted
replaced
| 8:860b59cae5df | 9:0cf23f33d13d |
|---|---|
| 1 (.venv) [galaxy@IDEAS ideas_preprocessor]$ cat ideas_preprocessor.R | |
| 1 #!/usr/bin/env Rscript | 2 #!/usr/bin/env Rscript |
| 2 | 3 |
| 3 suppressPackageStartupMessages(library("data.table")) | 4 suppressPackageStartupMessages(library("data.table")) |
| 4 suppressPackageStartupMessages(library("optparse")) | 5 suppressPackageStartupMessages(library("optparse")) |
| 5 | 6 |
| 6 option_list <- list( | 7 option_list <- list( |
| 7 make_option(c("--chrom_bed_input"), action="store", dest="chrom_bed_input", defaul=NULL, help="Chromosome windows positions file"), | 8 make_option(c("--bed_input"), action="store", dest="bed_input", defaul=NULL, help="Chromosome windows positions file"), |
| 8 make_option(c("--exclude_input"), action="store", dest="exclude_input", defaul=NULL, help="File(s) containing regions to exclude"), | 9 make_option(c("--exclude_input"), action="store", dest="exclude_input", defaul=NULL, help="File(s) containing regions to exclude"), |
| 9 make_option(c("--bychr"), action="store_true", dest="bychr", defaul=FALSE, help="Separate files by chromosome"), | 10 make_option(c("--bychr"), action="store_true", dest="bychr", defaul=FALSE, help="Separate files by chromosome"), |
| 10 make_option(c("--chrom_len_file"), action="store", dest="chrom_len_file", default=NULL, help="Chromosome lengths file"), | 11 make_option(c("--chrom_len_file"), action="store", dest="chrom_len_file", default=NULL, help="Chromosome lengths file"), |
| 11 make_option(c("--ideas_input_config"), action="store", dest="ideas_input_config", help="Preprocessing output config file"), | 12 make_option(c("--ideas_input_config"), action="store", dest="ideas_input_config", help="Preprocessing output config file"), |
| 12 make_option(c("--ideaspre_input_config"), action="store", dest="ideaspre_input_config", help="Preprocessing input config file"), | 13 make_option(c("--ideaspre_input_config"), action="store", dest="ideaspre_input_config", help="Preprocessing input config file"), |
| 57 } else { | 58 } else { |
| 58 bigwig_file_name = file_path; | 59 bigwig_file_name = file_path; |
| 59 } | 60 } |
| 60 bed_file_name = paste(file_name, "bed", sep="."); | 61 bed_file_name = paste(file_name, "bed", sep="."); |
| 61 bed_file_path = paste("tmp", bed_file_name, sep="/"); | 62 bed_file_path = paste("tmp", bed_file_name, sep="/"); |
| 62 cmd = paste("bigWigAverageOverBed", bigwig_file_name, opt$chrom_bed_input, "stdout | cut -f5 >", bed_file_path); | 63 cmd = paste("bigWigAverageOverBed", bigwig_file_name, opt$bed_input, "stdout | cut -f5 >", bed_file_path); |
| 63 system(cmd); | 64 system(cmd); |
| 64 cmd = paste("gzip -f", bed_file_path); | 65 cmd = paste("gzip -f", bed_file_path); |
| 65 system(cmd); | 66 system(cmd); |
| 66 } | 67 } |
| 67 | 68 |
| 68 # Create temporary file1.txt. | 69 # Create file1.txt. |
| 69 cmd = paste("cut -d' '", opt$ideaspre_input_config, "-f1,2 > file1.txt", sep=" "); | 70 cmd = paste("cut -d' '", opt$ideaspre_input_config, "-f1,2 > file1.txt", sep=" "); |
| 70 system(cmd); | 71 system(cmd); |
| 71 # Compress the bed files in the tmp directory. | 72 # Compress the bed files in the tmp directory. |
| 72 tmp_gzipped_files = paste(tmp_dir, "*.bed.gz", sep="/"); | 73 tmp_gzipped_files = paste(tmp_dir, "*.bed.gz", sep="/"); |
| 73 # Create temporary file2.txt. | 74 # Create file2.txt. |
| 74 cmd = paste("ls", tmp_gzipped_files, "> file2.txt", sep=" "); | 75 cmd = paste("ls", tmp_gzipped_files, "> file2.txt", sep=" "); |
| 75 system(cmd); | 76 system(cmd); |
| 76 # Create IDEAS_input_config.txt with the format required by IDEAS. | 77 # Create the ideas_input_config with the format required by IDEAS. |
| 77 cmd = paste("paste -d' ' file1.txt file2.txt >", opt$ideas_input_config, sep=" "); | 78 cmd = paste("paste -d' ' file1.txt file2.txt >", opt$ideas_input_config, sep=" "); |
| 78 system(cmd); | 79 system(cmd); |
| 79 # Move IDEAS_input_config.txt to the output directory. | 80 # Move the ideas_input_config to the output directory. |
| 80 to_path = paste(opt$output_files_path, opt$ideas_input_config, sep="/"); | 81 to_path = paste(opt$output_files_path, opt$ideas_input_config, sep="/"); |
| 81 file.rename(opt$ideas_input_config, to_path); | 82 file.rename(opt$ideas_input_config, to_path); |
| 82 # Move all compressed bed files in the tmp | 83 # Move the compressed bed files in the tmp |
| 83 # directory to the output tmp directory. | 84 # directory to the output tmp directory. |
| 84 tmp_files = list.files(path=tmp_dir); | 85 tmp_files = list.files(path=tmp_dir); |
| 85 for (i in 1:length(tmp_files)) { | 86 for (i in 1:length(tmp_files)) { |
| 86 from_path = paste(tmp_dir, tmp_files[i], sep="/"); | 87 from_path = paste(tmp_dir, tmp_files[i], sep="/"); |
| 87 to_path = paste(output_tmp_dir, tmp_files[i], sep="/"); | 88 to_path = paste(output_tmp_dir, tmp_files[i], sep="/"); |
| 88 file.rename(from_path, to_path); | 89 file.rename(from_path, to_path); |
| 89 } | 90 } |
| 90 if (!is.null(opt$chrom_bed_input) && !is.null(opt$chromosome_windows)) { | 91 if (!is.null(opt$chromosome_windows)) { |
| 91 # Rename chrom_bed_input to chromosomes.txt | 92 # Move the chromosome_windows to the output directory. |
| 92 # and move it to the output directory. | |
| 93 to_path = paste(opt$output_files_path, "chromosomes.bed", sep="/"); | |
| 94 file.rename(opt$chrom_bed_input, to_path) | |
| 95 # Move chromosome_windows.txt to the output directory. | |
| 96 to_path = paste(opt$output_files_path, opt$chromosome_windows, sep="/"); | 93 to_path = paste(opt$output_files_path, opt$chromosome_windows, sep="/"); |
| 97 file.rename(opt$chromosome_windows, to_path); | 94 file.rename(opt$chromosome_windows, to_path); |
| 98 } | 95 } |
| 99 # Create the primary HTML dataset. | 96 # Create the primary HTML dataset. |
| 100 create_primary_html(opt$output, opt$output_hid, opt$output_files_path); | 97 create_primary_html(opt$output, opt$output_hid, opt$output_files_path); |
