lib/Bio/Roary/External/CheckTools.pm

filter: Statementstmt 79.7% 55 / 69 Branchbran 50.0% 12 / 24 Conditioncond 50.0% 6 / 12 MC/DCmcdc 50.0% 4 / 8 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 4 totaltotal 68.2% 86 / 126 CC 20 SCAR 29.6
CC
20
Cov
70%
check_tool
38.4
check_all_tools
4.7
which_tool_exec
3.0
CRAP 19.3
« lib/Bio/Roary/External/GeneAlignmentFromNucleotides.pm ↑ Summary lib/Bio/Roary/ContigsToGeneIDsFromGFF.pm »
1 package Bio::Roary::External::CheckTools;
2 2 $Bio::Roary::External::CheckTools::VERSION = '3.13.0';
3 # ABSTRACT: Check external executables are available and are the correct version
4  
5  
6 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Log::Log4perl qw(:easy);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 has 'logger' => ( is => 'ro', lazy => 1, builder => '_build_logger' );
10  
11 1 ▶sub _build_logger {
Subroutine _build_logger: called CC=1 SCAR=0.0
12 1 my ($self) = @_;
13 1 Log::Log4perl->easy_init($DEBUG);
14 1 my $logger = get_logger();
15 1 return $logger;
16 }
17  
18 2 my $BIDEC = '(\d+\.\d+)'; # pattern of NN.NN for versions that can be compared
19  
20 2 my %tools = (
21 'parallel' => {
22 GETVER => "parallel --version | grep '^GNU parallel 2'",
23 REGEXP => qr/GNU parallel (\d+)/,
24 MINVER => "20130422",
25 NEEDED => 1,
26 },
27 'blastp' => {
28 GETVER => "blastp -version",
29 REGEXP => qr/blastp:\s+(\d+\.\d+\.\d+)/,
30 NEEDED => 1,
31 },
32 'makeblastdb' => {
33 GETVER => "makeblastdb -version",
34 REGEXP => qr/makeblastdb:\s+(\d+\.\d+\.\d+)/,
35 NEEDED => 1,
36 },
37 'mcl' => {
38 GETVER => "mcl --version | head -n 1",
39 REGEXP => qr/(\d+\-\d+)/,
40 NEEDED => 1,
41 },
42 'bedtools' => {
43 GETVER => "bedtools --version",
44 REGEXP => qr/bedtools v($BIDEC)/,
45 MINVER => "2.1",
46 NEEDED => 1,
47 },
48 'mafft' => {
49 GETVER => "mafft --version < /dev/null 2>&1",
50 REGEXP => qr/(\d+\.\d+)/,
51 NEEDED => 1,
52 },
53 'kraken' => {
54 GETVER => "kraken -v | head -n 1",
55 REGEXP => qr/(\d+\.\d+\.*\d*.*)/,
56 NEEDED => 0,
57 },
58 'kraken-report' => {
59 GETVER => "kraken-report -v | head -n 1",
60 REGEXP => qr/(\d+\.\d+\.*\d*.*)/,
61 NEEDED => 0,
62 },
63 'Rscript' => {
64 GETVER => "Rscript --version 2>&1 | head -n 1",
65 REGEXP => qr/R scripting front-end version ($BIDEC)/,
66 MINVER => "3",
67 NEEDED => 0,
68 },
69 'prank' => {
70 GETVER => "prank | grep -m 1 ^prank",
71 REGEXP => qr/prank v.(\d+)/,
72 NEEDED => 0,
73 },
74  
75 # now just the standard unix tools we need
76 'grep' => { NEEDED => 1 },
77 'sed' => { NEEDED => 1 },
78 'awk' => { NEEDED => 1 },
79
80 );
81  
82 2 my %cdhit_tools = (
83 'cdhit' => {
84 GETVER => "cdhit -h | grep 'CD-HIT version'",
85 REGEXP => qr/version\s+($BIDEC)/i,
86 MINVER => "4.6",
87 },
88 'cd-hit' => {
89 GETVER => "cd-hit -h | grep 'CD-HIT version'",
90 REGEXP => qr/version\s+($BIDEC)i/,
91 MINVER => "4.6",
92 }
93 );
94  
95 2 my %fasttree_tools = (
96 'fasttree' => {
97 GETVER => "fasttree 2>&1 | head -n 1",
98 REGEXP => qr/Usage for FastTree version ($BIDEC)/,
99 },
100 'FastTree' => {
101 GETVER => "FastTree 2>&1 | head -n 1",
102 REGEXP => qr/Usage for FastTree version ($BIDEC)/,
103 }
104 );
105  
106 2 ▶sub which_tool_exec {
Subroutine which_tool_exec: called CC=3 SCAR=11.0
Pod undocumented
107 2 my ( $self, $alt_tools ) = @_;
108 2 for my $toolname ( sort keys %{$alt_tools} ) {
109 4 my $fp = $self->find_exe($toolname);
110 4 ▶ return $toolname if $fp;
Branch: 1 branch
BranchTrueFalseTotal
if $fp 0 4 4
111 }
112 2 $self->logger->error( "Required tool missing. Can't find one of " . join( '/', keys %{$alt_tools} ) . " in your \$PATH." );
113 2 return undef;
114 }
115  
116 23 ▶sub check_tool {
Subroutine check_tool: called CC=13 SCAR=36.5
Pod undocumented
117 23 my ( $self, $toolname ) = @_;
118 23 my $t = $tools{$toolname};
119 23 my $fp = $self->find_exe($toolname);
120 23 ▶ $self->logger->error("ERROR: Can't find required '$toolname' in your \$PATH") if !$fp and $t->{NEEDED};
Branch: 1 branch
BranchTrueFalseTotal
if not $fp and $t->{"NEEDED"} 12 11 23
Condition100%3/3
not $fp and $t->{"NEEDED"}
!ll&&!rl&&r
6512
MC/DC100%2/2
not $fp and $t->{"NEEDED"}
not $fp $t->{"NEEDED"}
Truth table100%3/3
not(A) and B
A= not $fpB= $t->{"NEEDED"}
ABresult
0X0
100
111
121 23 ▶ $self->logger->error("Optional tool '$toolname' not found in your \$PATH") if !$fp and !$t->{NEEDED};
Branch: 1 branch
BranchTrueFalseTotal
unless $fp or $t->{"NEEDED"} 5 18 23
Condition100%3/3
$fp or $t->{"NEEDED"}
l!l&&r!l&&!r
6125
MC/DC100%2/2
$fp or $t->{"NEEDED"}
$fp $t->{"NEEDED"}
Truth table100%3/3
A or B
A= $fpB= $t->{"NEEDED"}
ABresult
1X1
011
000
122  
123 23 ▶ if ($fp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fp) 6 17 23
124 6 $t->{HAVE} = $fp;
125 6 $self->logger->warn("Looking for '$toolname' - found $fp");
126 6 ▶ if ( $t->{GETVER} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->{"GETVER"}) 0 6 6
127 0 my ($s) = qx($t->{GETVER});
128 0 ▶ if ( defined $s ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) { } 0 0 0
129 0 $s =~ $t->{REGEXP};
130 0 ▶ $t->{VERSION} = $1 if defined $1;
Branch: 1 branch
BranchTrueFalseTotal
if defined $1 0 0 0
131 0 $self->logger->warn("Determined $toolname version is $t->{VERSION}");
132 0 ▶ if ( defined $t->{MINVER} and $t->{VERSION} < $t->{MINVER} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $t->{"MINVER"} and $t->{"VERSION"} < $t->{"MINVER"}) 0 0 0
Condition0%0/3
defined $t->{"MINVER"} and $t->{"VERSION"} < $t->{"MINVER"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $t->{"MINVER"} and $t->{"VERSION"} < $t->{"MINVER"}
defined $t->{"MINVER"} $t->{"VERSION"} < $t->{"MINVER"}
Truth table0%0/3
A and B
A= defined $t->{"MINVER"}B= $t->{"VERSION"} < $t->{"MINVER"}
ABresult
0X0
100
111
133 0 $self->logger->error("Roary needs $toolname $t->{MINVER} or higher. Please upgrade and try again.");
134 }
135 0 ▶ if ( defined $t->{MAXVER} and $t->{VERSION} > $t->{MAXVER} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $t->{"MAXVER"} and $t->{"VERSION"} > $t->{"MAXVER"}) 0 0 0
Condition0%0/3
defined $t->{"MAXVER"} and $t->{"VERSION"} > $t->{"MAXVER"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $t->{"MAXVER"} and $t->{"VERSION"} > $t->{"MAXVER"}
defined $t->{"MAXVER"} $t->{"VERSION"} > $t->{"MAXVER"}
Truth table0%0/3
A and B
A= defined $t->{"MAXVER"}B= $t->{"VERSION"} > $t->{"MAXVER"}
ABresult
0X0
100
111
136 0 $self->logger->error(
137 "Roary needs a version of $toolname between $t->{MINVER} and $t->{MAXVER}. Please downgrade and try again.");
138 }
139 }
140 else {
141 0 $self->logger->error( "Could not determine version of $toolname - please install version ", $t->{MINVER}, " or higher" )
142 ; # FIXME: or less <= MAXVER if given
143 }
144 }
145 }
146 }
147  
148 1 ▶sub check_all_tools {
Subroutine check_all_tools: called CC=4 SCAR=15.5
Pod undocumented
149 1 my ($self) = @_;
150 1 $ENV{"GREP_OPTIONS"} = ''; # --colour => version grep fails (Issue #117)
151 1 for my $toolname ( sort keys %tools ) {
152 13 $self->check_tool($toolname);
153 }
154
155 1 my $cdhit = $self->which_tool_exec( \%cdhit_tools );
156 1 ▶ if ($cdhit) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cdhit) 0 1 1
157 0 $tools{$cdhit} = $cdhit_tools{$cdhit};
158 0 $self->check_tool($cdhit);
159 }
160  
161 1 my $fasttree = $self->which_tool_exec( \%fasttree_tools );
162 1 ▶ if ($fasttree) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fasttree) 0 1 1
163 0 $tools{$fasttree} = $fasttree_tools{$fasttree};
164 0 $self->check_tool($fasttree);
165 }
166  
167 1 return $self;
168 }
169  
170 27 ▶sub find_exe {
Subroutine find_exe: called CC=3 SCAR=11.0
Pod undocumented
171 27 my ( $self, $bin ) = @_;
172 27 for my $dir ( File::Spec->path ) {
173 258 my $exe = File::Spec->catfile( $dir, $bin );
174 258 ▶ return $exe if -x $exe;
Branch: 1 branch
BranchTrueFalseTotal
if -x $exe 6 252 258
175 }
176 21 return;
177 }
178  
179 2 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
180 2 __PACKAGE__->meta->make_immutable;
181  
182 2 1;
183  
184 __END__
« lib/Bio/Roary/External/GeneAlignmentFromNucleotides.pm ↑ Summary lib/Bio/Roary/ContigsToGeneIDsFromGFF.pm »