#! /usr/bin/perl -w =pod =head1 NAME bootstrap_lapd - Repeatedly call B for Phylip compatibility. =head1 SYNOPSIS bootstrap_lapd [+] =head1 OPTIONS The first argument, an integer, is the number of bootstrap replicates to expect in the input file. The second argument is filename where the bootstrapped sequences may be found. The rest of the line contains optional arguments to send to B. =head1 DESCRIPTION This program can only handle file in the Phylip format. The option -sd is always sent to B! =cut use strict; use integer; use Bio::AlignIO; use File::Temp qw /tempfile/; use Pod::Usage; use Pod::Text; my $lapd = 'lapd'; my $pbar = 'progressbar'; if (@ARGV < 3) { print "Wrong number of arguments!\n\n"; pod2usage(); } my $replicates = shift @ARGV; my $filename = shift @ARGV; my $outfile = shift @ARGV; my $aio = Bio::AlignIO->new(-file => $filename, -format => 'phylip'); my $count = 0; my $use_progressbar = 0; if (check_for_programs([$pbar])) { # $use_progressbar = 1; my $eta_start = $replicates / 10; if ($eta_start < 10) { $eta_start = 10; } # open(PB, "|$pbar -b $eta_start -t bootstrap_lapd -x 0 $replicates Distances") # or { # warn "Could not start '$pbar'!"; # $use_progressbar = 0; # } } unlink $outfile; while (my $aln = $aio->next_aln()) { $count++; my ($fh, $f) = tempfile(TEMPLATE => 'lapd'); my $tmpaio = Bio::AlignIO->new(-fh => $fh, -format => 'phylip'); $tmpaio->write_aln($aln); close($fh); my $cmd = "$lapd -sd " . join(' ', @ARGV) . " $f >> $outfile"; system($cmd); if ($use_progressbar) { print PB $count, "\n"; } } if ($count == 0) { print STDERR "Warning: lapd (bootstrap_lapd) could not find an alignment!\n"; exit 1; } if ($use_progressbar) { close(PB); } exit 0; # # Make sure we can run the programs needed # sub check_for_programs { my ($prog_list_ref) = @_; my @inaccessibles = (); foreach my $p (@$prog_list_ref) { if (!perl_which($p)) { push @inaccessibles, $p; } } if (@inaccessibles > 0) { return 0; } else { return 1; } } # # From sbc-staff@pdc.kth.se, avoid using 'which' or 'type' # # Returns the path to a program if it is in the path, otherwise return undef sub perl_which { my $arg = shift; my $path = $ENV{'PATH'}; my @p = split (':', $path); foreach my $i (@p) { # print STDERR "$i\n"; my $exe = "$i/$arg"; if (-x $exe) { return $exe; } } return undef; }