Mercurial > repos > dereeper > roary_plots
comparison Roary/lib/Bio/Roary/External/CheckTools.pm @ 0:c47a5f61bc9f draft
Uploaded
author | dereeper |
---|---|
date | Fri, 14 May 2021 20:27:06 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c47a5f61bc9f |
---|---|
1 package Bio::Roary::External::CheckTools; | |
2 | |
3 # ABSTRACT: Check external executables are available and are the correct version | |
4 | |
5 =head1 SYNOPSIS | |
6 Functionality borrowed from PROKKA by Torsten Seemann. | |
7 Check external executables are available and are the correct version | |
8 | |
9 use Bio::Roary::External::CheckTools; | |
10 | |
11 my $obj = Bio::Roary::External::CheckTools->new(); | |
12 $obj->check_all_tools; | |
13 | |
14 =cut | |
15 | |
16 use Moose; | |
17 use File::Spec; | |
18 use Log::Log4perl qw(:easy); | |
19 has 'logger' => ( is => 'ro', lazy => 1, builder => '_build_logger' ); | |
20 | |
21 sub _build_logger { | |
22 my ($self) = @_; | |
23 Log::Log4perl->easy_init($DEBUG); | |
24 my $logger = get_logger(); | |
25 return $logger; | |
26 } | |
27 | |
28 my $BIDEC = '(\d+\.\d+)'; # pattern of NN.NN for versions that can be compared | |
29 | |
30 my %tools = ( | |
31 'parallel' => { | |
32 GETVER => "parallel --version | grep '^GNU parallel 2'", | |
33 REGEXP => qr/GNU parallel (\d+)/, | |
34 MINVER => "20130422", | |
35 NEEDED => 1, | |
36 }, | |
37 'blastp' => { | |
38 GETVER => "blastp -version", | |
39 REGEXP => qr/blastp:\s+(\d+\.\d+\.\d+)/, | |
40 NEEDED => 1, | |
41 }, | |
42 'makeblastdb' => { | |
43 GETVER => "makeblastdb -version", | |
44 REGEXP => qr/makeblastdb:\s+(\d+\.\d+\.\d+)/, | |
45 NEEDED => 1, | |
46 }, | |
47 'mcl' => { | |
48 GETVER => "mcl --version | head -n 1", | |
49 REGEXP => qr/(\d+\-\d+)/, | |
50 NEEDED => 1, | |
51 }, | |
52 'bedtools' => { | |
53 GETVER => "bedtools --version", | |
54 REGEXP => qr/bedtools v($BIDEC)/, | |
55 MINVER => "2.1", | |
56 NEEDED => 1, | |
57 }, | |
58 'mafft' => { | |
59 GETVER => "mafft --version < /dev/null 2>&1", | |
60 REGEXP => qr/(\d+\.\d+)/, | |
61 NEEDED => 1, | |
62 }, | |
63 'kraken' => { | |
64 GETVER => "kraken -v | head -n 1", | |
65 REGEXP => qr/(\d+\.\d+\.*\d*.*)/, | |
66 NEEDED => 0, | |
67 }, | |
68 'kraken-report' => { | |
69 GETVER => "kraken-report -v | head -n 1", | |
70 REGEXP => qr/(\d+\.\d+\.*\d*.*)/, | |
71 NEEDED => 0, | |
72 }, | |
73 'Rscript' => { | |
74 GETVER => "Rscript --version 2>&1 | head -n 1", | |
75 REGEXP => qr/R scripting front-end version ($BIDEC)/, | |
76 MINVER => "3", | |
77 NEEDED => 0, | |
78 }, | |
79 'prank' => { | |
80 GETVER => "prank | grep -m 1 ^prank", | |
81 REGEXP => qr/prank v.(\d+)/, | |
82 NEEDED => 0, | |
83 }, | |
84 | |
85 # now just the standard unix tools we need | |
86 'grep' => { NEEDED => 1 }, | |
87 'sed' => { NEEDED => 1 }, | |
88 'awk' => { NEEDED => 1 }, | |
89 | |
90 ); | |
91 | |
92 my %cdhit_tools = ( | |
93 'cdhit' => { | |
94 GETVER => "cdhit -h | grep 'CD-HIT version'", | |
95 REGEXP => qr/version\s+($BIDEC)/i, | |
96 MINVER => "4.6", | |
97 }, | |
98 'cd-hit' => { | |
99 GETVER => "cd-hit -h | grep 'CD-HIT version'", | |
100 REGEXP => qr/version\s+($BIDEC)/i, | |
101 MINVER => "4.6", | |
102 } | |
103 ); | |
104 | |
105 my %fasttree_tools = ( | |
106 'fasttree' => { | |
107 GETVER => "fasttree 2>&1 | head -n 1", | |
108 REGEXP => qr/Usage for FastTree version ($BIDEC)/, | |
109 }, | |
110 'FastTree' => { | |
111 GETVER => "FastTree 2>&1 | head -n 1", | |
112 REGEXP => qr/Usage for FastTree version ($BIDEC)/, | |
113 } | |
114 ); | |
115 | |
116 sub which_tool_exec { | |
117 my ( $self, $alt_tools ) = @_; | |
118 for my $toolname ( sort keys %{$alt_tools} ) { | |
119 my $fp = $self->find_exe($toolname); | |
120 return $toolname if $fp; | |
121 } | |
122 $self->logger->error( "Required tool missing. Can't find one of " . join( '/', keys %{$alt_tools} ) . " in your \$PATH." ); | |
123 return undef; | |
124 } | |
125 | |
126 sub check_tool { | |
127 my ( $self, $toolname ) = @_; | |
128 my $t = $tools{$toolname}; | |
129 my $fp = $self->find_exe($toolname); | |
130 $self->logger->error("ERROR: Can't find required '$toolname' in your \$PATH") if !$fp and $t->{NEEDED}; | |
131 $self->logger->error("Optional tool '$toolname' not found in your \$PATH") if !$fp and !$t->{NEEDED}; | |
132 | |
133 if ($fp) { | |
134 $t->{HAVE} = $fp; | |
135 $self->logger->warn("Looking for '$toolname' - found $fp"); | |
136 if ( $t->{GETVER} ) { | |
137 my ($s) = qx($t->{GETVER}); | |
138 if ( defined $s ) { | |
139 $s =~ $t->{REGEXP}; | |
140 $t->{VERSION} = $1 if defined $1; | |
141 $self->logger->warn("Determined $toolname version is $t->{VERSION}"); | |
142 if ( defined $t->{MINVER} and $t->{VERSION} < $t->{MINVER} ) { | |
143 $self->logger->error("Roary needs $toolname $t->{MINVER} or higher. Please upgrade and try again."); | |
144 } | |
145 if ( defined $t->{MAXVER} and $t->{VERSION} > $t->{MAXVER} ) { | |
146 $self->logger->error( | |
147 "Roary needs a version of $toolname between $t->{MINVER} and $t->{MAXVER}. Please downgrade and try again."); | |
148 } | |
149 } | |
150 else { | |
151 $self->logger->error( "Could not determine version of $toolname - please install version ", $t->{MINVER}, " or higher" ) | |
152 ; # FIXME: or less <= MAXVER if given | |
153 } | |
154 } | |
155 } | |
156 } | |
157 | |
158 sub check_all_tools { | |
159 my ($self) = @_; | |
160 $ENV{"GREP_OPTIONS"} = ''; # --colour => version grep fails (Issue #117) | |
161 for my $toolname ( sort keys %tools ) { | |
162 $self->check_tool($toolname); | |
163 } | |
164 | |
165 my $cdhit = $self->which_tool_exec( \%cdhit_tools ); | |
166 if ($cdhit) { | |
167 $tools{$cdhit} = $cdhit_tools{$cdhit}; | |
168 $self->check_tool($cdhit); | |
169 } | |
170 | |
171 my $fasttree = $self->which_tool_exec( \%fasttree_tools ); | |
172 if ($fasttree) { | |
173 $tools{$fasttree} = $fasttree_tools{$fasttree}; | |
174 $self->check_tool($fasttree); | |
175 } | |
176 | |
177 return $self; | |
178 } | |
179 | |
180 sub find_exe { | |
181 my ( $self, $bin ) = @_; | |
182 for my $dir ( File::Spec->path ) { | |
183 my $exe = File::Spec->catfile( $dir, $bin ); | |
184 return $exe if -x $exe; | |
185 } | |
186 return; | |
187 } | |
188 | |
189 no Moose; | |
190 __PACKAGE__->meta->make_immutable; | |
191 | |
192 1; |