# HG changeset patch # User peterjc # Date 1431443907 14400 # Node ID 17051c239fdcf7fa20557961675db98b59dc373f # Parent c41aac3e45724c6b2aeb5140e03548801a506537 planemo upload for repository https://github.com/peterjc/pico_galaxy/tools/coverage_stats commit be2b63ac53fea52babdfa31feffccb948211d065 diff -r c41aac3e4572 -r 17051c239fdc tools/coverage_stats/README.rst --- a/tools/coverage_stats/README.rst Fri Nov 21 09:43:14 2014 -0500 +++ b/tools/coverage_stats/README.rst Tue May 12 11:18:27 2015 -0400 @@ -1,7 +1,7 @@ BAM coverage statistics using samtools idxstats and depth ========================================================= -This tool is copyright 2014 by Peter Cock, The James Hutton Institute +This tool is copyright 2014-2015 by Peter Cock, The James Hutton Institute (formerly SCRI, Scottish Crop Research Institute), UK. All rights reserved. See the licence text below. @@ -50,6 +50,11 @@ Version Changes ------- ---------------------------------------------------------------------- v0.0.1 - Initial public release +v0.0.2 - Cope with samtools' default depth limit using modified samtools, + see https://github.com/samtools/samtools/pull/322 +v0.0.3 - Cope with no coverage in final contigs. +v0.0.4 - Reorder XML elements (internal change only). + - Planemo for Tool Shed upload (``.shed.yml``, internal change only). ======= ====================================================================== @@ -59,22 +64,35 @@ Development is on this GitHub repository: https://github.com/peterjc/pico_galaxy/tree/master/tools/coverage_stats -For making the "Galaxy Tool Shed" http://toolshed.g2.bx.psu.edu/ tarball use -the following command from the Galaxy root folder:: +For pushing a release to the test or main "Galaxy Tool Shed", use the following +Planemo commands (which requires you have set your Tool Shed access details in +``~/.planemo.yml`` and that you have access rights on the Tool Shed):: + + $ planemo shed_upload --shed_target testtoolshed --check_diff ~/repositories/pico_galaxy/tools/coverage_stats/ + ... + +or:: - $ tar -czf coverage_stats.tar.gz tools/coverage_stats/README.rst tools/coverage_stats/coverage_stats.xml tools/coverage_stats/coverage_stats.py tools/coverage_stats/tool_dependencies.xml test-data/ex1.bam test-data/ex1.coverage_stats.tabular test-data/coverage_test.bam test-data/coverage_test.coverage_stats.tabular + $ planemo shed_upload --shed_target toolshed --check_diff ~/repositories/pico_galaxy/tools/coverage_stats/ + ... -Check this worked:: +To just build and check the tar ball, use:: - $ tar -tzf coverage_stats.tar.gz + $ planemo shed_upload --tar_only ~/repositories/pico_galaxy/tools/coverage_stats/ + ... + $ tar -tzf shed_upload.tar.gz tools/coverage_stats/README.rst tools/coverage_stats/coverage_stats.xml tools/coverage_stats/coverage_stats.py tools/coverage_stats/tool_dependencies.xml + test-data/coverage_test.bam + test-data/coverage_test.coverage_stats.tabular test-data/ex1.bam test-data/ex1.coverage_stats.tabular - test-data/coverage_test.bam - test-data/coverage_test.coverage_stats.tabular + tools/coverage_stats/README.rst + tools/coverage_stats/coverage_stats.xml + tools/coverage_stats/coverage_stats.py + tools/coverage_stats/tool_dependencies.xml Licence (MIT) diff -r c41aac3e4572 -r 17051c239fdc tools/coverage_stats/coverage_stats.py --- a/tools/coverage_stats/coverage_stats.py Fri Nov 21 09:43:14 2014 -0500 +++ b/tools/coverage_stats/coverage_stats.py Tue May 12 11:18:27 2015 -0400 @@ -17,26 +17,26 @@ 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.1") + print("BAM coverage statistics v0.0.3 [with depth hack]") cmd = "samtools 2>&1 | grep -i ^Version" sys.exit(os.system(cmd)) -def stop_err(msg, error_level=1): +def sys_exit(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") + sys_exit("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) + sys_exit("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) + sys_exit("Error: Galaxy did not index your BAM file") + sys_exit("Input BAI file not found: %s" % bai_filename) #Assign sensible names with real extensions, and setup symlinks: tmp_dir = tempfile.mkdtemp() @@ -62,15 +62,15 @@ return_code = os.system(cmd) if return_code: clean_up() - stop_err("Return code %i from command:\n%s" % (return_code, cmd)) + sys_exit("Return code %i from command:\n%s" % (return_code, cmd)) # Run samtools depth: # TODO - Parse stdout instead? -cmd = 'samtools depth "%s" > "%s"' % (bam_file, depth_filename) +cmd = 'samtools depth -d 250000 "%s" > "%s"' % (bam_file, depth_filename) return_code = os.system(cmd) if return_code: clean_up() - stop_err("Return code %i from command:\n%s" % (return_code, cmd)) + sys_exit("Return code %i from command:\n%s" % (return_code, cmd)) def load_total_coverage(depth_handle, identifier, length): """Parse some of the 'samtools depth' output for coverages. @@ -86,8 +86,13 @@ # print("%s coverage calculation, length %i, ..." % (identifier, length)) if depth_ref is None: - # Right at start of file! + # Right at start of file / new contig line = depth_handle.readline() + # Are we at the end of the file? + if not line: + # Must be at the end of the file. + # This can happen if the file contig(s) had no reads mapped + return 0, 0, 0.0 depth_ref, depth_pos, depth_reads = line.rstrip("\n").split() depth_pos = int(depth_pos) depth_reads = int(depth_reads) @@ -168,7 +173,7 @@ depth_handle.close() out_handle.close() clean_up() - stop_err("Problem with coverage for %s, expect min_cov <= mean_cov <= max_cov" + sys_exit("Problem with coverage for %s, expect min_cov <= mean_cov <= max_cov" % identifier) idxstats_handle.close() @@ -179,4 +184,4 @@ clean_up() if depth_ref is not None: - stop_err("Left over output from 'samtools depth'? %r" % depth_ref) + sys_exit("Left over output from 'samtools depth'? %r" % depth_ref) diff -r c41aac3e4572 -r 17051c239fdc tools/coverage_stats/coverage_stats.xml --- a/tools/coverage_stats/coverage_stats.xml Fri Nov 21 09:43:14 2014 -0500 +++ b/tools/coverage_stats/coverage_stats.xml Tue May 12 11:18:27 2015 -0400 @@ -1,9 +1,14 @@ - + using samtools idxstats and depth samtools samtools + + + + + coverage_stats.py --version coverage_stats.py "$input_bam" "${input_bam.metadata.bam_index}" "$out_tabular" @@ -12,11 +17,6 @@ - - - - - diff -r c41aac3e4572 -r 17051c239fdc tools/coverage_stats/tool_dependencies.xml --- a/tools/coverage_stats/tool_dependencies.xml Fri Nov 21 09:43:14 2014 -0500 +++ b/tools/coverage_stats/tool_dependencies.xml Tue May 12 11:18:27 2015 -0400 @@ -1,6 +1,6 @@ - +