Mercurial > repos > greg > ideas_preprocessor
comparison ideas_preprocessor.R @ 25:f7563bb242fc draft
Uploaded
| author | greg |
|---|---|
| date | Thu, 01 Feb 2018 11:22:27 -0500 |
| parents | 3651f1592f3f |
| children | 19881f817d25 |
comparison
equal
deleted
inserted
replaced
| 24:71345e154c66 | 25:f7563bb242fc |
|---|---|
| 30 ) | 30 ) |
| 31 | 31 |
| 32 parser <- OptionParser(usage="%prog [options] file", option_list=option_list) | 32 parser <- OptionParser(usage="%prog [options] file", option_list=option_list) |
| 33 args <- parse_args(parser, positional_arguments=TRUE) | 33 args <- parse_args(parser, positional_arguments=TRUE) |
| 34 opt <- args$options | 34 opt <- args$options |
| 35 | |
| 36 create_primary_html = function(output, output_files_path) { | |
| 37 files = list.files(path=output_files_path); | |
| 38 s <- paste('<html><head></head><body>', sep="\n"); | |
| 39 s <- paste(s, '<h3>Files prepared for IDEAS</h3>\n', sep=""); | |
| 40 s <- paste(s, '<ul>\n', sep=""); | |
| 41 for (i in 1:length(files)) { | |
| 42 s <- paste(s, '<li><a href="', files[i], '">', files[i], '</a></li>\n', sep=""); | |
| 43 } | |
| 44 s <- paste(s, '</ul></body></html>', sep=""); | |
| 45 cat(s, file=output); | |
| 46 } | |
| 47 | 35 |
| 48 tmp_dir = "tmp"; | 36 tmp_dir = "tmp"; |
| 49 | 37 |
| 50 # Read the ideaspre_input_config text file which has this format: | 38 # Read the ideaspre_input_config text file which has this format: |
| 51 # "cell type name" "epigenetic factor name" "file path" "file name" "datatype" | 39 # "cell type name" "epigenetic factor name" "file path" "file name" "datatype" |
| 97 to_path = paste(opt$output_files_path, ideas_input_config, sep="/"); | 85 to_path = paste(opt$output_files_path, ideas_input_config, sep="/"); |
| 98 file.rename(ideas_input_config, to_path); | 86 file.rename(ideas_input_config, to_path); |
| 99 # Archive the tmp directory. | 87 # Archive the tmp directory. |
| 100 cmd = "tar -cvf tmp.tar tmp"; | 88 cmd = "tar -cvf tmp.tar tmp"; |
| 101 system(cmd); | 89 system(cmd); |
| 90 # Compress the archive. | |
| 91 cmd = "gzip tmp.tar"; | |
| 92 system(cmd); | |
| 102 # Move the tmp archive to the output directory. | 93 # Move the tmp archive to the output directory. |
| 103 to_path = paste(opt$output_files_path, "tmp.tar", sep="/"); | 94 to_path = paste(opt$output_files_path, "tmp.tar.gz", sep="/"); |
| 104 file.rename("tmp.tar", to_path); | 95 file.rename("tmp.tar.gz", to_path); |
| 105 | 96 |
| 106 if (!is.null(opt$chrom_bed_input) && !is.null(opt$chromosome_windows)) { | 97 if (!is.null(opt$chrom_bed_input) && !is.null(opt$chromosome_windows)) { |
| 107 # Renane opt$chrom_bed_input to be chromosomes.bed | 98 # Renane opt$chrom_bed_input to be chromosomes.bed |
| 108 # and make a copy of it in the output directory. | 99 # and make a copy of it in the output directory. |
| 109 to_path = paste(opt$output_files_path, "chromosomes.bed", sep="/"); | 100 to_path = paste(opt$output_files_path, "chromosomes.bed", sep="/"); |
| 110 file.copy(opt$chrom_bed_input, to_path); | 101 file.copy(opt$chrom_bed_input, to_path); |
| 111 # Move chromosome_windows.txt to the output directory. | 102 # Move chromosome_windows.txt to the output directory. |
| 112 to_path = paste(opt$output_files_path, opt$chromosome_windows, sep="/"); | 103 to_path = paste(opt$output_files_path, opt$chromosome_windows, sep="/"); |
| 113 file.rename(opt$chromosome_windows, to_path); | 104 file.rename(opt$chromosome_windows, to_path); |
| 114 } | 105 } |
| 115 # Create the primary HTML dataset. | 106 |
| 116 create_primary_html(opt$output, opt$output_files_path); |
