# HG changeset patch # User peterjc # Date 1384968453 18000 # Node ID d4412c04d7b13f33f543283dd168d5d64c65534b Uploaded v0.0.1 (as tested previously on the Test Tool Shed) diff -r 000000000000 -r d4412c04d7b1 test-data/ex1.bam Binary file test-data/ex1.bam has changed diff -r 000000000000 -r d4412c04d7b1 test-data/ex1.idxstats.tabular --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/ex1.idxstats.tabular Wed Nov 20 12:27:33 2013 -0500 @@ -0,0 +1,3 @@ +chr1 1575 1446 18 +chr2 1584 1789 17 +* 0 0 0 diff -r 000000000000 -r d4412c04d7b1 tools/samtools_idxstats/README.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/samtools_idxstats/README.rst Wed Nov 20 12:27:33 2013 -0500 @@ -0,0 +1,100 @@ +Galaxy wrapper for samtools idxstats +==================================== + +This wrapper is copyright 2013 by Peter Cock, The James Hutton Institute +(formerly SCRI, Scottish Crop Research Institute), UK. All rights reserved. +See the licence text below. + +This is a wrapper for part of the command line samtools suite, v0.1.19 + +This wrapper is available from the Galaxy Tool Shed at: +http://toolshed.g2.bx.psu.edu/view/peterjc/samtools_idxstats + + +Automated Installation +====================== + +This should be straightforward, Galaxy should automatically download and install +samtools 0.1.19 if required. + + +Manual Installation +=================== + +This expects samtools to be on the $PATH, and was tested using v0.1.19. + +To install the wrapper copy or move the following files under the Galaxy tools +folder, e.g. in a ``tools/samtools_idxstats`` folder: + +* samtools_idxstats.xml (the Galaxy tool definition) +* samtools_idxstats.py (the Python wrapper script) +* README.rst (this file) + +You will also need to modify the ``tools_conf.xml`` file to tell Galaxy to offer +the tool. Just add the line, perhaps under the NGS tools section:: + + + +If you wish to run the unit tests, also add this to tools_conf.xml.sample +and move/copy the test-data files under Galaxy's test-data folder. Then:: + + $ ./run_functional_tests.sh -id samtools_idxstats + +That's it. + + +History +======= + +======= ====================================================================== +Version Changes +------- ---------------------------------------------------------------------- +v0.0.1 - Initial public release +======= ====================================================================== + + +Developers +========== + +Development is one this GitHub repository: +https://github.com/peterjc/pico_galaxy/tree/master/tools/samtools_idxstats + +For making the "Galaxy Tool Shed" http://toolshed.g2.bx.psu.edu/ tarball use +the following command from the Galaxy root folder:: + + $ tar -czf samtools_idxstats.tar.gz tools/samtools_idxstats/README.rst tools/samtools_idxstats/samtools_idxstats.xml tools/samtools_idxstats/samtools_idxstats.py tools/samtools_idxstats/tool_dependencies.xml test-data/ex1.bam test-data/ex1.idxstats.tabular + +Check this worked:: + + $ tar -tzf samtools_idxstats.tar.gz + tools/samtools_idxstats/README.rst + tools/samtools_idxstats/samtools_idxstats.xml + tools/samtools_idxstats/samtools_idxstats.py + tools/samtools_idxstats/tool_dependencies.xml + test-data/ex1.bam + test-data/ex1.idxstats.tabular + + +Licence (MIT) +============= + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +NOTE: This is the licence for the Galaxy Wrapper only. +samtools is available and licenced separately. diff -r 000000000000 -r d4412c04d7b1 tools/samtools_idxstats/samtools_idxstats.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/samtools_idxstats/samtools_idxstats.py Wed Nov 20 12:27:33 2013 -0500 @@ -0,0 +1,61 @@ +#!/usr/bin/env python +"""Wrapper for "samtools idxstats" for use in Galaxy. + +This script takes exactly three command line arguments: + * Input BAM filename + * Input BAI filename (via Galaxy metadata) + * Output tabular filename + +This messes about with the filenames to make samtools happy, then +runs "samtools idxstats" and captures the output to the desired +tabular file. +""" +import sys +import os +import subprocess +import tempfile + +if "-v" in sys.argv or "--version" in sys.argv: + #Galaxy seems to invert the order of the two lines + print "(Galaxy wrapper v0.0.1)" + cmd = "samtools 2>&1 | grep -i ^Version" + sys.exit(os.system(cmd)) + +def stop_err(msg, error_level=1): + """Print error message to stdout and quit with given error level.""" + sys.stderr.write("%s\n" % msg) + sys.exit(error_level) + +if len(sys.argv) != 4: + stop_err("Require three arguments: BAM, BAI, tabular filenames") + +bam_filename, bai_filename, tabular_filename = sys.argv[1:] + +if not os.path.isfile(bam_filename): + stop_err("Input BAM file not found: %s" % bam_filename) +if not os.path.isfile(bai_filename): + if bai_filename == "None": + stop_err("Error: Galaxy did not index your BAM file") + stop_err("Input BAI file not found: %s" % bai_filename) + +#Assign sensible names with real extensions, and setup symlinks: +tmp_dir = tempfile.mkdtemp() +bam_file = os.path.join(tmp_dir, "temp.bam") +bai_file = os.path.join(tmp_dir, "temp.bam.bai") +os.symlink(os.path.abspath(bam_filename), bam_file) +os.symlink(os.path.abspath(bai_filename), bai_file) +assert os.path.isfile(bam_file), bam_file +assert os.path.isfile(bai_file), bai_file +assert os.path.isfile(bam_file + ".bai"), bam_file + +#Run samtools idxstats: +cmd = "samtools idxstats %s > %s" % (bam_file, tabular_filename) +return_code = os.system(cmd) + +#Remove the temp symlinks: +os.remove(bam_file) +os.remove(bai_file) +os.rmdir(tmp_dir) + +if return_code: + stop_err("Return code %i from command:\n%s" % (return_code, cmd)) diff -r 000000000000 -r d4412c04d7b1 tools/samtools_idxstats/samtools_idxstats.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/samtools_idxstats/samtools_idxstats.xml Wed Nov 20 12:27:33 2013 -0500 @@ -0,0 +1,76 @@ + + samtools idxstats + + samtools + samtools + + samtools_idxstats.py --version + samtools_idxstats.py "$input_bam" "${input_bam.metadata.bam_index}" "$out_tabular" + + + + + + + + + + + + + + + + + + +**What it does** + +This tool runs the ``samtools idxstats`` command in the SAMtools toolkit. + +Input is a sorted and indexed BAM file, the output is tabular with +four columns (one row per reference sequence plus a final line for +unmapped reads): + +====== ================================================================================= +Column Description +------ --------------------------------------------------------------------------------- + 1 Reference sequence identifier + 2 Reference sequence length + 3 Number of mapped reads + 4 Number of placed but unmapped reads (typically unmapped partners of mapped reads) +====== ================================================================================= + +Example output from a *de novo* assembly: + +========== ====== ====== ===== +contig_1 170035 98397 0 +contig_2 403835 199564 0 +contig_3 553102 288189 0 +... ... ... ... +contig_603 653 50 0 +contig_604 214 6 0 +\* 0 0 50320 +========== ====== ====== ===== + +In this example there were 604 contigs, each with one line in the output table, +plus the final row (labelled with an asterisk) representing 50320 unmapped reads. +In this BAM file, the final column was otherwise zero. + + +**Citation** + +If you use this Galaxy tool in work leading to a scientific publication please +cite: + +Heng Li et al (2009). The Sequence Alignment/Map format and SAMtools. +Bioinformatics 25(16), 2078-9. +http://dx.doi.org/10.1093/bioinformatics/btp352 + +Peter J.A. Cock (2013), Galaxy wrapper for the samtools idxstats command +http://toolshed.g2.bx.psu.edu/view/peterjc/samtools_idxstats + +This wrapper is available to install into other Galaxy Instances via the Galaxy +Tool Shed at http://toolshed.g2.bx.psu.edu/view/peterjc/samtools_idxstats + + diff -r 000000000000 -r d4412c04d7b1 tools/samtools_idxstats/tool_dependencies.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/samtools_idxstats/tool_dependencies.xml Wed Nov 20 12:27:33 2013 -0500 @@ -0,0 +1,6 @@ + + + + + +