changeset 3:7cd370b7a952 draft

v0.0.3 - More tests, fixed accidental path change in v0.0.2
author peterjc
date Thu, 18 Feb 2016 06:41:09 -0500
parents 56852ae15edd
children f7901a2a9d0c
files tools/count_roi_variants/README.rst tools/count_roi_variants/count_roi_variants.py tools/count_roi_variants/count_roi_variants.xml
diffstat 3 files changed, 16 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/tools/count_roi_variants/README.rst	Wed Feb 17 11:42:16 2016 -0500
+++ b/tools/count_roi_variants/README.rst	Thu Feb 18 06:41:09 2016 -0500
@@ -55,6 +55,7 @@
 ------- ----------------------------------------------------------------------
 v0.0.1  - Initial public release
 v0.0.2  - Cope with pipes in reference name (e.g. NCBI style FASTA naming)
+v0.0.3  - Include a functional test for using an unrecognised reference.
 ======= ======================================================================
 
 
--- a/tools/count_roi_variants/count_roi_variants.py	Wed Feb 17 11:42:16 2016 -0500
+++ b/tools/count_roi_variants/count_roi_variants.py	Thu Feb 18 06:41:09 2016 -0500
@@ -19,7 +19,7 @@
 
 if "-v" in sys.argv or "--version" in sys.argv:
     # Galaxy seems to invert the order of the two lines
-    print("BAM coverage statistics v0.0.2 (using samtools)")
+    print("BAM coverage statistics v0.0.3 (using samtools)")
     cmd = "samtools 2>&1 | grep -i ^Version"
     sys.exit(os.system(cmd))
 
@@ -165,8 +165,8 @@
 
     # Call samtools view, don't need header so no -h added.
     # Only want mapped reads, thus flag filter -F 4.
-    child = subprocess.Popen(["/mnt/galaxy/bin/samtools_1.1", "view", "-F", "4", bam_file, region],
-                             stdout=subprocess.PIPE)
+    child = subprocess.Popen(["samtools", "view", "-F", "4", bam_file, region],
+                             stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     for line in child.stdout:
         assert line[0] != "@", "Got unexpected SAM header line: %s" % line
         qname, flag, rname, pos, mapq, cigar, rnext, pnext, tlen, seq, rest = line.split("\t", 10)
@@ -186,10 +186,14 @@
         except KeyError:
             tally[roi_seq] = 1
 
+    stderr = child.stderr.read()
     child.stdout.close()
+    child.stderr.close()
     return_code = child.wait()
     if return_code:
         sys.exit("Got return code %i from samtools view" % return_code)
+    elif "specifies an unknown reference name. Continue anyway." in stderr:
+        sys.exit(stderr.strip() + "\n\nERROR: samtools did not recognise the region requested, can't count any variants.")
 
     return tally
 
--- a/tools/count_roi_variants/count_roi_variants.xml	Wed Feb 17 11:42:16 2016 -0500
+++ b/tools/count_roi_variants/count_roi_variants.xml	Thu Feb 18 06:41:09 2016 -0500
@@ -1,4 +1,4 @@
-<tool id="count_roi_variants" name="Count sequence variants in region of interest" version="0.0.2">
+<tool id="count_roi_variants" name="Count sequence variants in region of interest" version="0.0.3">
     <description>using samtools view</description>
     <requirements>
         <requirement type="binary">samtools</requirement>
@@ -59,6 +59,13 @@
                 <has_line line="Counted 3 variants from 16 reads spanning gi|187250362|ref|NC_010642.1|:1695-1725" />
             </assert_stdout>
         </test>
+        <test expect_failure="true" expect_exit_code="1">
+            <param name="input_bam" value="SRR639755_mito_pairs_vs_NC_010642_clc.bam" ftype="bam" />
+            <param name="region" value="ref:1695-1725" />
+            <assert_stderr>
+                <has_line line="ERROR: samtools did not recognise the region requested, can't count any variants." />
+            </assert_stderr>
+        </test>
     </tests>
     <help>
 **What it does**