changeset 18:4e85d68a2347 draft

Version 2.1.0-6: add sorting step in bigWig generation, and explicitly terminate tool on error from MACS2.
author pjbriggs
date Wed, 22 Mar 2017 11:24:52 -0400
parents f346287fe52c
children 51303ba3fbbe
files README.rst macs21_wrapper.py macs21_wrapper.xml tool_dependencies.xml
diffstat 4 files changed, 31 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/README.rst	Tue Jul 26 09:54:21 2016 -0400
+++ b/README.rst	Wed Mar 22 11:24:52 2017 -0400
@@ -59,6 +59,8 @@
 ========== ======================================================================
 Version    Changes
 ---------- ----------------------------------------------------------------------
+2.1.0-6    - Add bedSort step into bigWig file generation; terminate with error
+             when MACS finishes with non-zero exit code.
 2.1.0-5    - User must explicitly specify the format for the inputs (to allow
              for paired-end data)
 2.1.0-4    - Remove 'bdgcmp' functionality.
--- a/macs21_wrapper.py	Tue Jul 26 09:54:21 2016 -0400
+++ b/macs21_wrapper.py	Wed Mar 22 11:24:52 2017 -0400
@@ -61,7 +61,8 @@
 
     $ fetchChromSizes.sh mm9 > mm9.chrom.sizes
     $ bedClip treat.bedgraph mm9.chrom.sizes treat.clipped
-    $ bedGraphToBigWig treat.clipped mm9.chrom.sizes treat.bw
+    $ bedSort treat.clipped treat.clipped.sorted
+    $ bedGraphToBigWig treat.clipped.sorted mm9.chrom.sizes treat.bw
 
     Get the binaries from
     http://hgdownload.cse.ucsc.edu/admin/exe/linux.x86_64/
@@ -111,8 +112,20 @@
     if not os.path.exists(treat_clipped):
         sys.stderr.write("Failed to create clipped bed file\n")
         sys.exit(1)
+    # Run bedSort
+    treat_clipped_sorted = "%s.sorted" % os.path.basename(treat_clipped)
+    cmd = "bedSort %s %s" % (treat_clipped,treat_clipped_sorted)
+    print "Running %s" % cmd
+    proc = subprocess.Popen(args=cmd,shell=True,cwd=working_dir)
+    proc.wait()
+    # Check that sorted file exists
+    treat_clipped_sorted = os.path.join(working_dir,treat_clipped_sorted)
+    if not os.path.exists(treat_clipped_sorted):
+        sys.stderr.write("Failed to create sorted clipped bed file\n")
+        sys.exit(1)
     # Run bedGraphToBigWig
-    cmd = "bedGraphToBigWig %s %s %s" % (treat_clipped,chrom_sizes,
+    cmd = "bedGraphToBigWig %s %s %s" % (treat_clipped_sorted,
+                                         chrom_sizes,
                                          bigwig_file)
     print "Running %s" % cmd
     proc = subprocess.Popen(args=cmd,shell=True,cwd=working_dir)
@@ -206,6 +219,10 @@
     proc = subprocess.Popen(args=cmdline,shell=True,cwd=working_dir,
                             stderr=open(stderr_filen,'wb'))
     proc.wait()
+    exit_code = proc.returncode
+    if exit_code != 0:
+        sys.stderr.write(open(stderr_filen,'rb').read())
+        sys.exit(exit_code)
     
     # Run R script to create PDF from model script
     if os.path.exists(os.path.join(working_dir,"%s_model.r" % experiment_name)):
--- a/macs21_wrapper.xml	Tue Jul 26 09:54:21 2016 -0400
+++ b/macs21_wrapper.xml	Wed Mar 22 11:24:52 2017 -0400
@@ -1,11 +1,11 @@
-<tool id="macs2_1_peakcalling" name="MACS2.1.0" version="2.1.0-5">
+<tool id="macs2_1_peakcalling" name="MACS2.1.0" version="2.1.0-6">
   <description>Model-based Analysis of ChIP-Seq: peak calling</description>
   <requirements>
     <requirement type="package" version="2.7">python</requirement>
     <requirement type="package" version="1.9">numpy</requirement>
     <requirement type="package" version="2.1.0.20140616">macs2</requirement>
     <requirement type="package" version="3.1.2">R</requirement>
-    <requirement type="package" version="1.0">ucsc_tools_for_macs21</requirement>
+    <requirement type="package" version="2.0">ucsc_tools_for_macs21</requirement>
   </requirements>
   <version_command>macs2 --version</version_command>
   <command interpreter="python">
--- a/tool_dependencies.xml	Tue Jul 26 09:54:21 2016 -0400
+++ b/tool_dependencies.xml	Wed Mar 22 11:24:52 2017 -0400
@@ -8,7 +8,7 @@
     <repository changeset_revision="1ca39eb16186" name="package_r_3_1_2" owner="iuc" prior_installation_required="True" toolshed="https://testtoolshed.g2.bx.psu.edu" />
   </package>
   <!-- Subset of UCSC tools -->
-  <package name="ucsc_tools_for_macs21" version="1.0">
+  <package name="ucsc_tools_for_macs21" version="2.0">
       <install version="1.0">
             <actions>
 	      <!-- fetchChromSizes -->
@@ -25,6 +25,13 @@
               <action type="chmod">
                 <file mode="755">$INSTALL_DIR/bedClip</file>
               </action>
+	      <!-- bedSort -->
+              <action type="download_binary">
+                <url_template architecture="x86_64" os="linux">http://hgdownload.cse.ucsc.edu/admin/exe/linux.x86_64/bedSort</url_template>
+              </action>
+              <action type="chmod">
+                <file mode="755">$INSTALL_DIR/bedSort</file>
+              </action>
 	      <!-- bedGraphToBigWig -->
               <action type="download_binary">
                 <url_template architecture="x86_64" os="linux">http://hgdownload.cse.ucsc.edu/admin/exe/linux.x86_64/bedGraphToBigWig</url_template>