3 See the NOTICE file distributed with
this work
for additional information
4 regarding copyright ownership.
6 Licensed under the Apache License, Version 2.0 (the
"License");
7 you may not use
this file except in compliance with the License.
8 You may obtain a copy of the License at
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an
"AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License
for the specific language governing permissions and
16 limitations under the License.
23 Please email comments or questions to the
public Ensembl
24 developers list at <http:
26 Questions may also be sent to the Ensembl help desk at
31 package Bio::EnsEMBL::Analysis::Programs;
33 use vars qw( %Program_Paths );
42 #print STDERR "importing: $_\n";
43 $Program_Paths{ $_ } = 0;
45 my( $home, @PATH, @missing );
47 $home = cwd() or die
"Can't save cwd";
50 @PATH = split /:/, $ENV{
'PATH'};
52 s|/?$|/|; # Append / to each path
55 # For each program, check there is an executable
56 foreach my $program (keys %Program_Paths) {
59 if ($program =~ m|/|) {
63 $path =~ s{^~([^/]*)}{ $1 ? (getpwnam($1))[7]
64 : (getpwuid($>))[7] }e;
65 if (my $real = _is_prog( $H, $path )) {
66 $Program_Paths{ $program } = $real;
69 # Or search through all paths
71 foreach my $path (@PATH) {
73 if (my $real = _is_prog( $H, $path, $program )) {
74 $Program_Paths{ $program } = $real;
80 _go_home( $H ); # Return to home directory
82 # Make a list of all missing programs
83 foreach my $program (keys %Program_Paths) {
84 push( @missing, $program ) unless $Program_Paths{ $program };
87 # Give informative death message if programs weren't found
89 throw(
"Unable to locate the following programs as '". (getpwuid($<))[0].
"' on host '". hostname().
"' :\t".
90 join (
" --> " , @missing )) ;
94 # Recursive function which follows links, or tests final destination
96 my( $h, $path, $prog ) = @_;
98 # Need to split path if $prog not provided
100 ($path, $prog) = $path =~ m|(.*?)([^/]+)$|;
103 if (-l
"$path$prog") {
105 _follow( $h, $path ) or
return;
106 unless (-x readlink($prog)) {
107 confess
"Can't read link '$path$prog' : $!";
110 $path = cwd() or confess
"Can't determine cwd";
111 return "$path/$prog";
112 } elsif (-f _ and -x _) {
114 _follow( $h, $path ) or
return;
115 $path = cwd() or confess
"Can't determine cwd";
116 return "$path/$prog";
118 # Not a link or an executable plain file
123 # To avoid unnecessary chdir'ing
125 my( $H, $path ) = @_;
127 # Chdir without arguments goes to home dir.
128 # Can't use defined in test since $path may contain
129 # a real null string.
130 if ( ! $path and $path ne
'0' ) {
132 } elsif (chdir($path)) {
142 # Go home unless we're already there
144 if (chdir( $H->[0] )) {
147 confess
"Can't go home to [ ", $H->[0],
' ]';
161 /usr/local/bin/this_one
162 ~me/some/path/my_prog
163 ~/../jane/bin/her_prog );
165 # Can also do at run time
168 $path_to_prog = $Bio::EnsEMBL::Analysis::Programs::Program_Paths{ $prog };
172 B<Programs> is used to check at compile time
for the
173 presence of executables which will be called from your
174 script. Arguments passed via the use statement
175 can be just the program name, or an absolute or
176 relative path to the program. Tildes are expanded
177 correctly (I<not>
using "glob"). Failure to find any
178 one program is fatal, and a list of all failures is
179 printed, along with the host
''s name.
181 If you want to check
for a program during
run time,
182 the
import funtion can be called directly, as shown above.
184 The paths to each program found are stored in the
185 B<%Program_Paths> hash, which is keyed on the original
190 If the executable is in the root directory, then it
''s found
191 path will appear as
"//prog" in %Program_Paths, not
"/prog".
195 B<James Gilbert> Email jgrg@sanger.ac.uk