changeset 18:bcb74072d3a6 draft

Added snippy-core tool
author simon-gladman
date Thu, 09 Jun 2016 03:55:50 -0400
parents 2fbf00cd46ca
children d1719f16caa3
files macros.xml snippy-core.xml snippy_core_wrapper.pl
diffstat 3 files changed, 132 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/macros.xml	Wed Jun 08 23:46:47 2016 -0400
+++ b/macros.xml	Thu Jun 09 03:55:50 2016 -0400
@@ -1,7 +1,7 @@
 <macros>
     <xml name="requirements">
         <requirements>
-        <requirement type="package">package_snippy_3_0</requirement>
+            <requirement type="package" version="3.0">snippy</requirement>
             <yield/>
         </requirements>
     </xml>
@@ -12,7 +12,12 @@
     </xml>
     <xml name="citations">
         <citations>
+          <citation type="bibtex">@UNPUBLISHED{Seemann2013,
+            author = "Seemann T",
+            title = "snippy: fast bacterial variant calling from NGS reads",
+            year = "2015",
+            note = "https://github.com/tseemann/snippy"}</citation>
             <yield />
         </citations>
     </xml>
-</macros>
\ No newline at end of file
+</macros>
--- a/snippy-core.xml	Wed Jun 08 23:46:47 2016 -0400
+++ b/snippy-core.xml	Thu Jun 09 03:55:50 2016 -0400
@@ -1,31 +1,66 @@
 <tool id="snippy-core" name="snippy-core" version="0.1.0">
-    <macros>
-        <import>macros.xml</import>
-    </macros>
-    <expand macro="requirements" />
-    <expand macro="stdio" />
-    <command><![CDATA[
-        TODO: Fill in command template.
+
+  <requirements>
+      <requirement type="package" version="3.0">snippy</requirement>
+  </requirements>
+  <stdio>
+      <exit_code range="1:" />
+  </stdio>
+
+    <command interpreter=perl><![CDATA[
+
+        snippy_core_wrapper.pl
+        $is_reference
+        --mincov $mincov
+        --indirs '${" ".join(map(str, $indirs))}'
+
     ]]></command>
+
     <inputs>
+      <param name="indirs" type="data" multiple="true" format="bgzip" label="Snippy input zipped dirs" help="Select all the snippy inputs for alignment" />
+      <param name="is_reference" type="boolean" checked="true" truevalue="--noref" falsevalue="" label="Exclude reference" help="Don't include the reference file in the alignment." />
+      <param name="mincov" type="float" value="10.0" min="1" label="Minimum coverage" help="Minimum depth of coverage to consider core (default '10')" />
     </inputs>
+
     <outputs>
+      <data format="fasta" name="alignment_fasta" label="${tool.name} on ${on_string} core alignment fasta" from_work_dir="core.aln" />
+      <data format="tabular" name="alignment_table" label="${tool.name} on ${on_string} core alignment table" from_work_dir="core.tab" />
+      <data format="txt" name="alignment_summary" label="${tool.name} on ${on_string} core alignment summary" from_work_dir="core.txt" />
     </outputs>
+
     <help><![CDATA[
-        Synopsis:
+Synopsis:
   Combine multiple Snippy folders into a core SNP alignment
+
 Usage:
   ../../snippy/bin/snippy-core [options] [--noref] snippyDir1/ snippyDir2/ snippyDir3/ ...
+
 Options:
+
   --help!         This help.
+
   --quiet!        No output to stderr (default '0').
+
   --verbose!      Verbose output (default '0').
+
   --inprefix=s    Preferred input prefix of Snippy files (default 'snps').
+
   --prefix=s      Output file prefix (default 'core').
+
   --noref!        Exclude reference (default '0').
+
   --mincov=i      Minimum depth of coverage to consider core (default '10').
+
   --aformat=s     Output alignment format: nexus fasta phylip maf clustalw ... (default 'fasta').
 
     ]]></help>
-    <expand macro="citations" />
-</tool>
\ No newline at end of file
+
+  <citations>
+    <citation type="bibtex">@UNPUBLISHED{Seemann2013,
+      author = "Seemann T",
+      title = "snippy: fast bacterial variant calling from NGS reads",
+      year = "2015",
+      note = "https://github.com/tseemann/snippy"}</citation>
+  </citations>
+
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/snippy_core_wrapper.pl	Thu Jun 09 03:55:50 2016 -0400
@@ -0,0 +1,80 @@
+#!/usr/bin/env perl
+
+#--------------------------------------
+#
+#        snippy_core_wrapper.pl
+#
+# This is an intermediary script between snippy-core.xml and snippy-core
+# It:
+#   - Copys the supplied zipped snippy output files to the working dir
+#   - Untars them to their datafile name
+#   - Builds the snippy-core command and captures the stdout and stderr to files
+#   - Runs the snippy-core command
+#
+#--------------------------------------
+
+use warnings;
+use strict;
+use File::Copy;
+use File::Basename;
+
+my(@Options, $indirs, $mincov, $noref);
+setOptions();
+
+my @list_of_dirs = split /\s+/, $indirs;
+
+#The list of final directories to be passed to snippy-core will be stored here.
+my @snippy_outs;
+
+foreach my $d (@list_of_dirs){
+  #print STDERR "$d\n";
+  my $bn = basename($d);
+  my ($name, $dir, $ext) = fileparse($d, '\..*');
+  copy($d, $bn);
+  #print STDERR "$d, $bn, $name, $dir, $ext\n";
+  `tar -xf $bn`;
+  move("./out", "./$name");
+  unlink($bn);
+  push @snippy_outs, $name;
+}
+
+my $commandline = "snippy-core ";
+
+$commandline .= "--noref " if $noref;
+$commandline .= "--mincov $mincov " if $mincov;
+$commandline .= join(" ", @snippy_outs);
+print STDERR "snippy-core commandline: $commandline\n";
+
+my $ok = system($commandline);
+
+#----------------------------------------------------------------------
+# Option setting routines
+
+sub setOptions {
+  use Getopt::Long;
+
+  @Options = (
+    {OPT=>"help",    VAR=>\&usage,             DESC=>"This help"},
+    {OPT=>"mincov=f",  VAR=>\$mincov, DEFAULT=>'10.0', DESC=>"The minimum coverage to consider."},
+    {OPT=>"noref!", VAR=>\$noref, DEFAULT=>0, DESC=>"Don't include the reference in the alignment."},
+    {OPT=>"indirs=s", VAR=>\$indirs, DEFAULT=>"", DESC=>"A whitespace delimited list of the snippy output zipped dirs."},
+  );
+
+  &GetOptions(map {$_->{OPT}, $_->{VAR}} @Options) || usage();
+
+  # Now setup default values.
+  foreach (@Options) {
+    if (defined($_->{DEFAULT}) && !defined(${$_->{VAR}})) {
+      ${$_->{VAR}} = $_->{DEFAULT};
+    }
+  }
+}
+
+sub usage {
+  print "Usage: $0 [options] -i inputfile > ... \n";
+  foreach (@Options) {
+    printf "  --%-13s %s%s.\n",$_->{OPT},$_->{DESC},
+           defined($_->{DEFAULT}) ? " (default '$_->{DEFAULT}')" : "";
+  }
+  exit(1);
+}