Bio::EnsEMBL::Analysis
Programs
Toolbar
Package variables
No package variables defined.
Included modules
Synopsis
No synopsis!
Description
Programs is used to check at compile time for the
presence of executables which will be called from your
script. Arguments passed via the use statement
can be just the program name, or an absolute or
relative path to the program. Tildes are expanded
correctly (not using "glob"). Failure to find any
one program is fatal, and a list of all failures is
printed, along with the host''s name.
If you want to check for a program during run time,
the import funtion can be called directly, as shown above.
The paths to each program found are stored in the
%Program_Paths hash, which is keyed on the original
arguments passed.
Methods
_follow | No description | Code |
_go_home | No description | Code |
_is_prog | No description | Code |
import | No description | Code |
Methods description
None available.
Methods code
sub _follow
{ my( $H, $path ) = @_;
if ( ! $path and $path ne '0' ) {
return 1;
} elsif (chdir($path)) {
$H->[1] = 0;
return 1;
} else {
return;
} } |
sub _go_home
{ my( $H ) = @_;
if ($H->[1] == 0) {
if (chdir( $H->[0] )) {
$H->[1] = 1;
} else {
confess "Can't go home to [ ", $H->[0], ' ]';
}
}
}
1;
__END__ } |
sub _is_prog
{ my( $h, $path, $prog ) = @_;
unless ($prog) {
($path, $prog) = $path =~ m|(.*?)([^/]+)$|; }
if (-l "$path$prog") {
_follow( $h, $path ) or return;
unless (-x readlink($prog)) {
confess "Can't read link '$path$prog' : $!";
}
my $link = $prog;
$path = cwd() or confess "Can't determine cwd";
return "$path/$prog";
} elsif (-f _ and -x _) {
_follow( $h, $path ) or return;
$path = cwd() or confess "Can't determine cwd";
return "$path/$prog";
} else {
return;
}
}
} |
sub import
{ my $pkg = shift;
foreach (@_) {
$Program_Paths{ $_ } = 0;
}
my( $home, @PATH, @missing );
$home = cwd() or die "Can't save cwd";
my $H = [ $home, 1 ];
@PATH = split /:/, $ENV{'PATH'};
foreach (@PATH) {
s|/?$|/|; }
foreach my $program (keys %Program_Paths) {
if ($program =~ m|/|) { _go_home( $H ); my $path = $program;
$path =~ s{^~([^/]*)}{ $1 ? (getpwnam($1))[7] : (getpwuid($>))[7] }e;
if (my $real = _is_prog( $H, $path )) {
$Program_Paths{ $program } = $real;
}
}
else {
foreach my $path (@PATH) {
_go_home( $H );
if (my $real = _is_prog( $H, $path, $program )) {
$Program_Paths{ $program } = $real;
last;
}
}
}
}
_go_home( $H );
foreach my $program (keys %Program_Paths) {
push( @missing, $program ) unless $Program_Paths{ $program };
}
if (@missing) {
throw("Unable to locate the following programs as '". (getpwuid($<))[0]. "' on host '". hostname(). "' :\t".
join ( " --> " , @missing )) ;
}
}
} |
General documentation
Copyright (c) 1999-2009 The European Bioinformatics Institute and
Genome Research Limited. All rights reserved.
This software is distributed under a modified Apache license.
For license details, please see
/info/about/code_licence.html
use Bio::EnsEMBL::Analysis::Programs qw( efetch getz est2genome
/usr/local/bin/this_one
~me/some/path/my_prog
~/../jane/bin/her_prog );
# Can also do at run time
Bio::EnsEMBL::Analysis::Programs->import( $someProg );
$path_to_prog = $Bio::EnsEMBL::Analysis::Programs::Program_Paths{ $prog };
If the executable is in the root directory, then it''s found
path will appear as "//prog" in %Program_Paths, not "/prog".