|
18
|
1 #!/usr/bin/env perl
|
|
|
2
|
|
|
3 #--------------------------------------
|
|
|
4 #
|
|
|
5 # snippy_core_wrapper.pl
|
|
|
6 #
|
|
|
7 # This is an intermediary script between snippy-core.xml and snippy-core
|
|
|
8 # It:
|
|
|
9 # - Copys the supplied zipped snippy output files to the working dir
|
|
|
10 # - Untars them to their datafile name
|
|
|
11 # - Builds the snippy-core command and captures the stdout and stderr to files
|
|
|
12 # - Runs the snippy-core command
|
|
|
13 #
|
|
|
14 #--------------------------------------
|
|
|
15
|
|
|
16 use warnings;
|
|
|
17 use strict;
|
|
|
18 use File::Copy;
|
|
|
19 use File::Basename;
|
|
|
20
|
|
|
21 my(@Options, $indirs, $mincov, $noref);
|
|
|
22 setOptions();
|
|
|
23
|
|
|
24 my @list_of_dirs = split /\s+/, $indirs;
|
|
|
25
|
|
|
26 #The list of final directories to be passed to snippy-core will be stored here.
|
|
|
27 my @snippy_outs;
|
|
|
28
|
|
|
29 foreach my $d (@list_of_dirs){
|
|
|
30 #print STDERR "$d\n";
|
|
|
31 my $bn = basename($d);
|
|
|
32 my ($name, $dir, $ext) = fileparse($d, '\..*');
|
|
|
33 copy($d, $bn);
|
|
|
34 #print STDERR "$d, $bn, $name, $dir, $ext\n";
|
|
|
35 `tar -xf $bn`;
|
|
|
36 move("./out", "./$name");
|
|
|
37 unlink($bn);
|
|
|
38 push @snippy_outs, $name;
|
|
|
39 }
|
|
|
40
|
|
|
41 my $commandline = "snippy-core ";
|
|
|
42
|
|
|
43 $commandline .= "--noref " if $noref;
|
|
|
44 $commandline .= "--mincov $mincov " if $mincov;
|
|
|
45 $commandline .= join(" ", @snippy_outs);
|
|
|
46 print STDERR "snippy-core commandline: $commandline\n";
|
|
|
47
|
|
|
48 my $ok = system($commandline);
|
|
|
49
|
|
|
50 #----------------------------------------------------------------------
|
|
|
51 # Option setting routines
|
|
|
52
|
|
|
53 sub setOptions {
|
|
|
54 use Getopt::Long;
|
|
|
55
|
|
|
56 @Options = (
|
|
|
57 {OPT=>"help", VAR=>\&usage, DESC=>"This help"},
|
|
22
|
58 {OPT=>"mincov=i", VAR=>\$mincov, DEFAULT=>'10.0', DESC=>"The minimum coverage to consider."},
|
|
18
|
59 {OPT=>"noref!", VAR=>\$noref, DEFAULT=>0, DESC=>"Don't include the reference in the alignment."},
|
|
|
60 {OPT=>"indirs=s", VAR=>\$indirs, DEFAULT=>"", DESC=>"A whitespace delimited list of the snippy output zipped dirs."},
|
|
|
61 );
|
|
|
62
|
|
|
63 &GetOptions(map {$_->{OPT}, $_->{VAR}} @Options) || usage();
|
|
|
64
|
|
|
65 # Now setup default values.
|
|
|
66 foreach (@Options) {
|
|
|
67 if (defined($_->{DEFAULT}) && !defined(${$_->{VAR}})) {
|
|
|
68 ${$_->{VAR}} = $_->{DEFAULT};
|
|
|
69 }
|
|
|
70 }
|
|
|
71 }
|
|
|
72
|
|
|
73 sub usage {
|
|
|
74 print "Usage: $0 [options] -i inputfile > ... \n";
|
|
|
75 foreach (@Options) {
|
|
|
76 printf " --%-13s %s%s.\n",$_->{OPT},$_->{DESC},
|
|
|
77 defined($_->{DEFAULT}) ? " (default '$_->{DEFAULT}')" : "";
|
|
|
78 }
|
|
|
79 exit(1);
|
|
|
80 }
|