diff ideas_preprocessor.R @ 22:3651f1592f3f draft

Uploaded
author greg
date Wed, 31 Jan 2018 14:13:11 -0500
parents 99102499271a
children f7563bb242fc
line wrap: on
line diff
--- a/ideas_preprocessor.R	Wed Jan 31 08:22:43 2018 -0500
+++ b/ideas_preprocessor.R	Wed Jan 31 14:13:11 2018 -0500
@@ -45,6 +45,8 @@
     cat(s, file=output);
 }
 
+tmp_dir = "tmp";
+
 # Read the ideaspre_input_config text file which has this format:
 # "cell type name" "epigenetic factor name" "file path" "file name" "datatype"
 ideaspre_input_config = as.matrix(read.table(opt$ideaspre_input_config));
@@ -71,9 +73,10 @@
             bigwig_file_name = file_path;
         }
         bed_file_name = paste(file_name, "bed", sep=".");
-        cmd = paste("bigWigAverageOverBed", bigwig_file_name, opt$chrom_bed_input, "stdout | cut -f5 >", bed_file_name);
+        bed_file_path = paste("tmp", bed_file_name, sep="/");
+        cmd = paste("bigWigAverageOverBed", bigwig_file_name, opt$chrom_bed_input, "stdout | cut -f5 >", bed_file_path);
         system(cmd);
-        cmd = paste("gzip -f", bed_file_name);
+        cmd = paste("gzip -f", bed_file_path);
         system(cmd);
     }
 }
@@ -81,8 +84,10 @@
 # Create file1.txt.
 cmd = paste("cut -d' '", opt$ideaspre_input_config, "-f1,2 > file1.txt", sep=" ");
 system(cmd);
-# Compress the bed files and create file2.txt.
-cmd = "ls *.bed.gz > file2.txt";
+# Compress the bed files in the tmp directory.
+tmp_gzipped_files = paste(tmp_dir, "*.bed.gz", sep="/");
+# Create file2.txt.
+cmd = paste("ls", tmp_gzipped_files, "> file2.txt", sep=" ");
 system(cmd);
 # Create IDEAS_input_config.txt  with the format required by IDEAS.
 ideas_input_config = "IDEAS_input_config.txt"
@@ -91,7 +96,13 @@
 # Move IDEAS_input_config.txt to the output directory.
 to_path = paste(opt$output_files_path, ideas_input_config, sep="/");
 file.rename(ideas_input_config, to_path);
-# Handle optional chrom_bed_input.txt and chromosomes.bed files.
+# Archive the tmp directory.
+cmd = "tar -cvf tmp.tar tmp";
+system(cmd);
+# Move the tmp archive to the output directory.
+to_path = paste(opt$output_files_path, "tmp.tar", sep="/");
+file.rename("tmp.tar", to_path);
+
 if (!is.null(opt$chrom_bed_input) && !is.null(opt$chromosome_windows)) {
     # Renane opt$chrom_bed_input to be chromosomes.bed
     # and make a copy of it in the output directory.