From 224f62aa1e5cd118c0dcafcb5f9b4970b49dadba Mon Sep 17 00:00:00 2001 From: Torsten Seemann Date: Fri, 2 Oct 2015 15:12:50 +1000 Subject: [PATCH] Issue #27 resolved - ensure Kraken stuff is set up --- bin/nullarbor.pl | 7 ++++++- perl5/Nullarbor/Requirements.pm | 30 +++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/bin/nullarbor.pl b/bin/nullarbor.pl index 9791169..de3a330 100755 --- a/bin/nullarbor.pl +++ b/bin/nullarbor.pl @@ -19,7 +19,7 @@ use Nullarbor::IsolateSet; use Nullarbor::Logger qw(msg err); use Nullarbor::Report; -use Nullarbor::Requirements qw(require_exe require_perlmod require_version); +use Nullarbor::Requirements qw(require_exe require_perlmod require_version require_var require_file); #------------------------------------------------------------------- # constants @@ -75,6 +75,7 @@ require_exe( qw'prokka roary kraken snippy mlst abricate megahit nw_order nw_display trimal FastTree' ); require_exe( qw'fq fa afa-pairwise.pl' ); require_exe( qw'convert pandoc head cat install env' ); + require_perlmod( qw'Data::Dumper Moo SVG::Graph Bio::SeqIO File::Copy Time::Piece YAML::Tiny' ); require_version('megahit', 1.0); @@ -82,6 +83,10 @@ require_version('prokka', 1.10); require_version('roary', 3.0); +my $value = require_var('KRAKEN_DEFAULT_DB', 'kraken'); +require_file("$value/database.idx", 'kraken'); +require_file("$value/database.kdb", 'kraken'); + my $cfg; if (-r $conf_file) { my $yaml = YAML::Tiny->read( $conf_file ); diff --git a/perl5/Nullarbor/Requirements.pm b/perl5/Nullarbor/Requirements.pm index 3a9aea9..398cbfe 100644 --- a/perl5/Nullarbor/Requirements.pm +++ b/perl5/Nullarbor/Requirements.pm @@ -1,10 +1,38 @@ package Nullarbor::Requirements; use base Exporter; -@EXPORT_OK = qw(require_exe require_perlmod require_version); +@EXPORT_OK = qw(require_exe require_perlmod require_version require_var require_file); use File::Spec; use Nullarbor::Logger qw(err msg); +use strict; + +#---------------------------------------------------------------------- +sub require_var { + my($var, $reason) = @_; + $reason ||= 'nullarbor'; + my $value = $ENV{$var}; + if ($value) { + msg("Found $reason environmental variable $var=$value"); + } + else { + err("Please set $var appropriately."); + } + return $value; +} + +#---------------------------------------------------------------------- +sub require_file { + my($fname, $reason) = @_; + $reason || 'nullarbor'; + if (-r $fname) { + msg("Found file required by $reason: $fname"); + } + else { + err("Can not find file $fname required by $reason."); + } + return; +} #---------------------------------------------------------------------- sub require_version {