Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #10 from bioperl/daisieh-adding_batchfile

merging adding_batchfile
  • Loading branch information...
commit 4c3ab7cc561eaf9fb96399533de5f9e25b20d5e7 2 parents b51440c + 6adb913
@daisieh daisieh authored
View
440 lib/Bio/Tools/Run/Phylo/Hyphy/Base.pm
@@ -75,14 +75,12 @@ Internal methods are usually preceded with a _
package Bio::Tools::Run::Phylo::Hyphy::Base;
-use vars qw(@ISA @VALIDVALUES $PROGRAMNAME $PROGRAM);
use strict;
use Bio::Root::Root;
use Bio::AlignIO;
use Bio::TreeIO;
use Bio::Tools::Run::WrapperBase;
-
-@ISA = qw(Bio::Root::Root Bio::Tools::Run::WrapperBase);
+use base qw(Bio::Root::Root Bio::Tools::Run::WrapperBase);
=head2 Default Values
@@ -90,15 +88,16 @@ Valid and default values are listed below. The default
values are always the first one listed. These descriptions are
essentially lifted from the python wrapper or provided by the author.
-INCOMPLETE DOCUMENTATION OF ALL METHODS
-
=cut
+our $PROGRAMNAME = 'HYPHYMP';
+our $PROGRAM;
+
+
BEGIN {
- $PROGRAMNAME = 'HYPHYMP' . ($^O =~ /mswin/i ?'.exe':'');
- if( defined $ENV{'HYPHYDIR'} ) {
- $PROGRAM = Bio::Root::IO->catfile($ENV{'HYPHYDIR'},$PROGRAMNAME). ($^O =~ /mswin/i ?'.exe':'');;
- }
+ if( defined $ENV{'HYPHYDIR'} ) {
+ $PROGRAM = Bio::Root::IO->catfile($ENV{'HYPHYDIR'},$PROGRAMNAME). ($^O =~ /mswin/i ?'.exe':'');;
+ }
}
=head2 program_name
@@ -112,7 +111,22 @@ BEGIN {
=cut
sub program_name {
- return 'HYPHYMP';
+ return $PROGRAMNAME;
+}
+
+=head2 valid_values
+
+ Title : valid_values
+ Usage : $factory->valid_values()
+ Function: returns the possible parameters
+ Returns: an array holding all possible parameters (this needs to be specified per child class).
+ Returns an empty array in the base class.
+ Args : None
+
+=cut
+
+sub valid_values {
+ return ();
}
=head2 program_dir
@@ -126,7 +140,7 @@ sub program_name {
=cut
sub program_dir {
- return Bio::Root::IO->catfile($ENV{HYPHYDIR}) if $ENV{HYPHYDIR};
+ return Bio::Root::IO->catfile($ENV{HYPHYDIR}) if $ENV{HYPHYDIR};
}
@@ -149,7 +163,6 @@ See also: L<Bio::Tree::TreeI>, L<Bio::Align::AlignI>
sub new {
my($class,@args) = @_;
-
my $self = $class->SUPER::new(@args);
my $versionstring = $self->version();
@@ -165,56 +178,48 @@ sub new {
the alignment parameter must have been set
Returns : value of rundir
Args : L<Bio::Align::AlignI> object,
- L<Bio::Tree::TreeI> object [optional]
+ L<Bio::Tree::TreeI> object [optional]
=cut
sub prepare {
my ($self,$aln,$tree) = @_;
- unless ( $self->save_tempfiles ) {
- # brush so we don't get plaque buildup ;)
- $self->cleanup();
- }
$tree = $self->tree unless $tree;
$aln = $self->alignment unless $aln;
if( ! $aln ) {
- $self->warn("must have supplied a valid alignment file in order to run hyphy");
- return 0;
+ $self->warn("must have supplied a valid alignment file in order to run hyphy");
+ return 0;
}
my ($tempdir) = $self->tempdir();
my ($tempseqFH,$tempalnfile);
if( ! ref($aln) && -e $aln ) {
- $tempalnfile = $aln;
+ $tempalnfile = $aln;
} else {
- ($tempseqFH,$tempalnfile) = $self->io->tempfile
- ('-dir' => $tempdir,
- UNLINK => ($self->save_tempfiles ? 0 : 1));
- $aln->set_displayname_flat(1);
- my $alnout = Bio::AlignIO->new('-format' => 'fasta',
- '-fh' => $tempseqFH);
-
- $alnout->write_aln($aln);
- $alnout->close();
- undef $alnout;
- close($tempseqFH);
+ ($tempseqFH,$tempalnfile) = $self->io->tempfile('-dir' => $tempdir, UNLINK => ($self->save_tempfiles ? 0 : 1));
+ $aln->set_displayname_flat(1);
+ my $alnout = Bio::AlignIO->new('-format' => 'fasta', '-fh' => $tempseqFH);
+ $alnout->write_aln($aln);
+ $alnout->close();
+ undef $alnout;
+ close($tempseqFH);
}
$self->{'_params'}{'tempalnfile'} = $tempalnfile;
- my $outfile = $self->outfile_name || "$tempdir/results.tsv";
- $self->{'_params'}{'outfile'} = $outfile;
-
+ # setting a new temp file to hold the run output for debugging
+ $self->{'run_output'} = "$tempdir/run_output";
+ my $outfile = $self->outfile_name;
+ if ($outfile eq "") {
+ $outfile = "$tempdir/results.out";
+ $self->outfile_name($outfile);
+ }
my ($temptreeFH,$temptreefile);
if( ! ref($tree) && -e $tree ) {
- $temptreefile = $tree;
+ $temptreefile = $tree;
} else {
- ($temptreeFH,$temptreefile) = $self->io->tempfile
- ('-dir' => $tempdir,
- UNLINK => ($self->save_tempfiles ? 0 : 1));
-
- my $treeout = Bio::TreeIO->new('-format' => 'newick',
- '-fh' => $temptreeFH);
- $treeout->write_tree($tree);
- $treeout->close();
- close($temptreeFH);
+ ($temptreeFH,$temptreefile) = $self->io->tempfile('-dir' => $tempdir, UNLINK => ($self->save_tempfiles ? 0 : 1));
+ my $treeout = Bio::TreeIO->new('-format' => 'newick', '-fh' => $temptreeFH);
+ $treeout->write_tree($tree);
+ $treeout->close();
+ close($temptreeFH);
}
$self->{'_params'}{'temptreefile'} = $temptreefile;
$self->create_wrapper;
@@ -236,8 +241,8 @@ sub prepare {
=cut
sub create_wrapper {
+ my $redirect = "stdinRedirect";
my ($self,$batchfile) = @_;
-
my $tempdir = $self->tempdir;
$self->update_ordered_parameters;
@@ -247,32 +252,98 @@ sub create_wrapper {
my $version = $1;
my $wrapper = "$tempdir/wrapper.bf";
- open(WRAPPER, ">$wrapper") or $self->throw("cannot open $wrapper for writing");
+ open(WRAPPER, ">", $wrapper) or $self->throw("cannot open $wrapper for writing");
- print WRAPPER "stdinRedirect"," = ", "\{", "\};", "\n\n";
+ print WRAPPER qq{$redirect = {};\n\n};
my $counter = sprintf("%02d", 0);
- foreach my $elem (@{ $self->{'_updatedorderedparams'} }) {
- my ($param,$val) = each %$elem;
- print WRAPPER 'stdinRedirect ["';
- print WRAPPER "$counter";
- print WRAPPER '"] = "';
- print WRAPPER "$val";
- print WRAPPER '"',";\n";
- $counter = sprintf("%02d",$counter+1);
+ foreach my $elem (@{ $self->{'_orderedparams'} }) {
+ my ($param,$val) = each %$elem;
+ if ($val eq "") {
+ $val = "$tempdir/$param"; # any undefined parameters must be temporary output files.
+ }
+ print WRAPPER qq{$redirect ["$counter"] = "$val";\n};
+ $counter = sprintf("%02d",$counter+1);
}
- # not exactly sure what version of HYPHY caused this change,
- # but Github source changes suggest that it was sometime
- # after version 0.9920060501 was required.
- if ($version >= 0.9920060501) {
- print WRAPPER qq{\nExecuteAFile (HYPHY_LIB_DIRECTORY + "TemplateBatchFiles" + DIRECTORY_SEPARATOR + "$batchfile", stdinRedirect);\n};
+ # This next line is for BatchFile:
+ if ((ref ($self)) =~ m/BatchFile/) {
+ print WRAPPER "\nExecuteAFile ($batchfile, $redirect);\n";
} else {
- print WRAPPER qq{\nExecuteAFile (HYPHY_BASE_DIRECTORY + "TemplateBatchFiles" + DIRECTORY_SEPARATOR + "$batchfile", stdinRedirect);\n};
+ # Not exactly sure what version of HYPHY caused this change,
+ # but Github source changes suggest that it was sometime
+ # after version 0.9920060501 was required.
+ $batchfile =~ s/"//g; # remove any extra quotes in the batchfile name.
+ if ($version >= 0.9920060501) {
+ print WRAPPER qq{\nExecuteAFile (HYPHY_LIB_DIRECTORY + "TemplateBatchFiles" + DIRECTORY_SEPARATOR + "$batchfile", stdinRedirect);\n};
+ } else {
+ print WRAPPER qq{\nExecuteAFile (HYPHY_BASE_DIRECTORY + "TemplateBatchFiles" + DIRECTORY_SEPARATOR + "$batchfile", stdinRedirect);\n};
+ }
}
+
close(WRAPPER);
$self->{'_wrapper'} = $wrapper;
}
+=head2 run
+
+ Title : run
+ Usage : my ($rc,$results) = $BatchFile->run();
+ Function: run the Hyphy analysis using the specified batchfile and its ordered parameters
+ Returns : Return code, Hash
+ Args : none
+
+
+=cut
+
+sub run {
+ my ($self) = @_;
+
+ my $aln = $self->alignment;
+ my $tree = $self->tree;
+ unless (defined($self->{'_prepared'})) {
+ $self->prepare($aln,$tree);
+ }
+ my $rc = 1;
+ my $results = "";
+ my $commandstring;
+ my $exe = $self->executable();
+ unless ($exe && -e $exe && -x _) {
+ $self->throw("unable to find or run executable for 'HYPHY'");
+ }
+
+ #runs the HYPHY command
+ $commandstring = $exe . " BASEPATH=" . $self->program_dir . " " . $self->{'_wrapper'};
+ my $pid = open(RUN, "-|", "$commandstring") or $self->throw("Cannot open exe $exe");
+ my $waiting = waitpid $pid,0;
+ # waitpid will leave a nonzero error in $? if the HYPHY command crashes, so we should bail gracefully.
+ my $error = $? & 127;
+ if ($error != 0) {
+ $self->throw("Error: " . $self->program_name . " ($waiting) quit unexpectedly with signal $error");
+ }
+ #otherwise, return the results and exit with 1 so that the parent knows we were successful.
+ while (my $line = <RUN>) {
+ $results .= "$line";
+ }
+ close(RUN);
+ # process the errors from $? and set the error values.
+ $rc = $? >> 8;
+ if (($results =~ m/error/i) || ($rc == 0)) { # either the child process had an error, or HYPHY put one in the output.
+ $rc = 0;
+ $self->warn($self->program_name . " reported error $rc - see error_string for the program output");
+ $results =~ m/(error.+)/is;
+ $self->error_string($1);
+ }
+
+ # put these run results into the temp run output file:
+ open (OUT, ">", $self->{'run_output'});
+ print OUT $results;
+ close OUT;
+
+ return ($rc,$results);
+}
+
+
+
=head2 error_string
Title : error_string
@@ -296,10 +367,9 @@ sub error_string {
=head2 alignment
Title : alignment
- Usage : $hyphy->align($aln);
+ Usage : $hyphy->alignment($aln);
Function: Get/Set the L<Bio::Align::AlignI> object
Returns : L<Bio::Align::AlignI> object
- Args : [optional] L<Bio::Align::AlignI>
Comment : We could potentially add support for running directly on a file
but we shall keep it simple
See also: L<Bio::SimpleAlign>
@@ -310,26 +380,25 @@ sub alignment {
my ($self,$aln) = @_;
if( defined $aln ) {
- if( -e $aln ) {
- $self->{'_alignment'} = $aln;
- } elsif( !ref($aln) || ! $aln->isa('Bio::Align::AlignI') ) {
- $self->warn("Must specify a valid Bio::Align::AlignI object to the alignment function not $aln");
- return undef;
- } else {
- $self->{'_alignment'} = $aln;
- }
+ if( -e $aln ) {
+ $self->{'_alignment'} = $aln;
+ } elsif( !ref($aln) || !$aln->isa('Bio::Align::AlignI') ) {
+ $self->warn("Must specify a valid Bio::Align::AlignI object to alignment(): you specified a " . ref($aln));
+ return;
+ } else {
+ $self->{'_alignment'} = $aln;
+ }
}
- return $self->{'_alignment'};
+ return $self->{'_alignment'};
}
=head2 tree
Title : tree
- Usage : $hyphy->tree($tree, %params);
+ Usage : $hyphy->tree($tree);
Function: Get/Set the L<Bio::Tree::TreeI> object
Returns : L<Bio::Tree::TreeI>
Args : [optional] $tree => L<Bio::Tree::TreeI>,
- [optional] %parameters => hash of tree-specific parameters:
Comment : We could potentially add support for running directly on a file
but we shall keep it simple
@@ -340,10 +409,12 @@ sub alignment {
sub tree {
my ($self, $tree, %params) = @_;
if( defined $tree ) {
- if( ! ref($tree) || ! $tree->isa('Bio::Tree::TreeI') ) {
- $self->warn("Must specify a valid Bio::Tree::TreeI object to the alignment function");
- }
- $self->{'_tree'} = $tree;
+ if( !ref($tree) || !$tree->isa('Bio::Tree::TreeI') ) {
+ $self->warn("Must specify a valid Bio::Tree::TreeI object to tree(): you specified a " . ref($tree));
+ return;
+ } else {
+ $self->{'_tree'} = $tree;
+ }
}
return $self->{'_tree'};
}
@@ -362,7 +433,7 @@ sub tree {
sub get_parameters {
my ($self) = @_;
# we're returning a copy of this
- return @{ $self->{'_hyphyparams'} };
+ return %{ $self->{'_params'} };
}
@@ -371,7 +442,7 @@ sub get_parameters {
Title : set_parameter
Usage : $hyphy->set_parameter($param,$val);
Function: Sets a hyphy parameter, will be validated against
- the valid values as set in the %VALIDVALUES class variable.
+ the valid values.
The checks can be ignored if one turns off param checks like this:
$hyphy->no_param_checks(1)
Returns : boolean if set was success, if verbose is set to -1
@@ -386,84 +457,79 @@ sub get_parameters {
sub set_parameter {
my ($self,$param,$value) = @_;
-
# FIXME - add validparams checking
- $self->{'_hyphyparams'}{$param} = $value;
+ $self->{'_params'}{$param} = $value;
return 1;
}
-=head2 update_ordered_parameters
+=head2 set_default_parameters
- Title : update_ordered_parameters
- Usage : $hyphy->update_ordered_parameters(0);
+ Title : set_default_parameters
+ Usage : $obj->set_default_parameters();
Function: (Re)set the default parameters from the defaults
- (the first value in each array in the
- %VALIDVALUES class variable)
+ (the first value in each array in the valid_values() array)
Returns : none
- Args : boolean: keep existing parameter values
-
-
-=cut
-
-sub update_ordered_parameters {
- my ($self,$keepold) = @_;
- $keepold = 0 unless defined $keepold;
- foreach my $elem (@{$self->{'_orderedparams'}}) {
- my ($param,$val) = each %$elem;
- my $composite_param = $param;
- # skip if we want to keep old values and it is already set
- if (ref($param) =~ /ARRAY/i ) {
- push @{ $self->{'_updatedorderedsparams'} }, {$param, $self->{_params}{$param} || $val};
- } elsif ( ref($val) =~ /HASH/i ) {
- while (defined($val)) {
- last unless (ref($val) =~ /HASH/i);
- my ($param,$val) = each %{$val};
- $composite_param .= $param;
- }
- push @{ $self->{'_updatedorderedparams'} }, {$param, $self->{_params}{$composite_param} || $val};
- } else {
- push @{ $self->{'_updatedorderedparams'} }, {$param, $self->{_params}{$param} || $val};
- }
- }
-}
-
+ Args : none
-=head1 Bio::Tools::Run::WrapperBase methods
=cut
-=head2 no_param_checks
-
- Title : no_param_checks
- Usage : $obj->no_param_checks($newval)
- Function: Boolean flag as to whether or not we should
- trust the sanity checks for parameter values
- Returns : value of no_param_checks
- Args : newvalue (optional)
-
-=cut
-
-sub no_param_checks {
- my ($self,$value) = @_;
- if( defined $value) {
- $self->{'no_param_checks'} = $value;
+sub set_default_parameters {
+ my ($self) = @_;
+ my @validvals = $self->valid_values();
+ foreach my $elem (@validvals) {
+ keys %$elem; #reset hash iterator
+ my ($param,$val) = each %$elem;
+ if (ref($val)=~/ARRAY/i ) {
+ unless (ref($val->[0])=~/HASH/i) {
+ push @{ $self->{'_orderedparams'} }, {$param, $val->[0]};
+ } else {
+ $val = $val->[0];
+ }
+ }
+ if ( ref($val) =~ /HASH/i ) {
+ my $prevparam;
+ while (defined($val)) {
+ last unless (ref($val) =~ /HASH/i);
+ last unless (defined($param));
+ $prevparam = $param;
+ ($param,$val) = each %{$val};
+ push @{ $self->{'_orderedparams'} }, {$prevparam, $param};
+ push @{ $self->{'_orderedparams'} }, {$param, $val} if (defined($val));
+ }
+ } elsif (ref($val) !~ /HASH/i && ref($val) !~ /ARRAY/i) {
+ push @{ $self->{'_orderedparams'} }, {$param, $val};
+ }
}
- return $self->{'no_param_checks'};
}
-=head2 save_tempfiles
+=head2 update_ordered_parameters
- Title : save_tempfiles
- Usage : $obj->save_tempfiles($newval)
- Function:
- Returns : value of save_tempfiles
- Args : newvalue (optional)
+ Title : update_ordered_parameters
+ Usage : $hyphy->update_ordered_parameters(0);
+ Function: (Re)set the default parameters from the defaults
+ (the first value in each array in the
+ %VALIDVALUES class variable)
+ Returns : none
+ Args : boolean: keep existing parameter values
=cut
+sub update_ordered_parameters {
+ my ($self) = @_;
+ for (my $i=0; $i < scalar(@{$self->{'_orderedparams'}}); $i++) {
+ my ($param,$val) = each %{$self->{'_orderedparams'}[$i]};
+ if (exists $self->{'_params'}{$param}) {
+ $self->{'_orderedparams'}[$i] = {$param, $self->{'_params'}{$param}};
+ } else {
+ $self->{'_orderedparams'}[$i] = {$param, $val};
+ }
+ }
+}
+
=head2 outfile_name
Title : outfile_name
@@ -477,55 +543,13 @@ sub no_param_checks {
=cut
sub outfile_name {
- my $self = shift;
- if( @_ ) {
- return $self->{'_params'}->{'outfile'} = shift @_;
- }
- return $self->{'_params'}->{'outfile'};
+ my $self = shift;
+ if( @_ ) {
+ return $self->{'_params'}->{'outfile'} = shift @_;
+ }
+ return $self->{'_params'}->{'outfile'};
}
-=head2 no_param_checks
-
- Title : no_param_checks
- Usage : $obj->no_param_checks($newval)
- Function: Boolean flag as to whether or not we should
- trust the sanity checks for parameter values
- Returns : value of no_param_checks
- Args : newvalue (optional)
-
-
-=cut
-
-# sub no_param_checks {
-# my ($self,$value) = @_;
-# if( defined $value) {
-# $self->{'no_param_checks'} = $value;
-# }
-# return $self->{'no_param_checks'};
-# }
-
-=head2 tempdir
-
- Title : tempdir
- Usage : my $tmpdir = $self->tempdir();
- Function: Retrieve a temporary directory name (which is created)
- Returns : string which is the name of the temporary directory
- Args : none
-
-
-=cut
-
-=head2 cleanup
-
- Title : cleanup
- Usage : $hyphy->cleanup();
- Function: Will cleanup the tempdir directory after a run
- Returns : none
- Args : none
-
-
-=cut
-
=head2 version
Title : version
@@ -540,28 +564,60 @@ sub outfile_name {
sub version {
my $self = shift;
my $tempdir = $self->tempdir;
- my $wrapper = "$tempdir/version.bf";
- open(WRAPPER, ">$wrapper") or $self->throw("cannot open $wrapper for writing");
+ if (defined $self->{'_version'}) {
+ return $self->{'_version'};
+ }
+ # if it's not already defined, write out a small batchfile to return the version string, then clean up.
+ my $versionbf = "$tempdir/version.bf";
+ open(WRAPPER, ">", $versionbf) or $self->throw("cannot open $versionbf for writing");
print WRAPPER qq{GetString (versionString, HYPHY_VERSION, 2);\nfprintf (stdout, versionString);};
close(WRAPPER);
my $exe = $self->executable();
unless ($exe && -e $exe && -x _) {
$self->throw("unable to find or run executable for 'HYPHY'");
}
- my $commandstring = $exe . " BASEPATH=" . $self->program_dir . " " . $wrapper;
+ my $commandstring = $exe . " BASEPATH=" . $self->program_dir . " " . $versionbf;
open(RUN, "$commandstring |") or $self->throw("Cannot open exe $exe");
my $output = <RUN>;
close(RUN);
+ unlink $versionbf;
$self->{'_version'} = $output;
return $output;
}
-sub DESTROY {
- my $self= shift;
- unless ( $self->save_tempfiles ) {
- $self->cleanup();
+=head2 hyphy_lib_dir
+
+ Title : hyphy_lib_dir
+ Usage : $obj->hyphy_lib_dir()
+ Function: Returns the HYPHY_LIB_DIRECTORY from HYPHY
+ Returns : string
+ Args : none
+
+
+=cut
+
+sub hyphy_lib_dir {
+ my $self = shift;
+ if (defined $self->{'_hyphylibdir'}) {
+ return $self->{'_hyphylibdir'};
+ }
+ # if it's not already defined, write out a small batchfile to return the version string, then clean up.
+ my $hyphylibdirbf = $self->io->catfile($self->tempdir,"hyphylibdir.bf");
+ open(WRAPPER, ">", $hyphylibdirbf) or $self->throw("cannot open $hyphylibdirbf for writing");
+ print WRAPPER qq{fprintf (stdout, HYPHY_LIB_DIRECTORY);};
+ close(WRAPPER);
+ my $exe = $self->executable();
+ unless ($exe && -e $exe && -x _) {
+ $self->throw("unable to find or run executable for 'HYPHY'");
}
- $self->SUPER::DESTROY();
+ my $commandstring = $exe . " BASEPATH=" . $self->program_dir . " " . $hyphylibdirbf;
+ open(RUN, "$commandstring |") or $self->throw("Cannot open exe $exe");
+ my $output = <RUN>;
+ close(RUN);
+ unlink $hyphylibdirbf;
+ $self->{'_hyphylibdir'} = $output;
+ return $output;
}
+
1;
View
320 lib/Bio/Tools/Run/Phylo/Hyphy/BatchFile.pm
@@ -0,0 +1,320 @@
+=head1 NAME
+
+Bio::Tools::Run::Phylo::Hyphy::BatchFile - Wrapper for custom execution of Hyphy batch files
+
+=head1 SYNOPSIS
+
+my $aln = Bio::Align::AlignI->new();
+my $treeio = Bio::TreeIO->new(-format => "nexus", -file => "$tree_file");
+my $tree = $treeio->next_tree();
+my $bf_exec = Bio::Tools::Run::Phylo::Hyphy::BatchFile->new(-params => {'bf' => "hyphybatchfile.bf", 'order' => ["Universal", "Custom", $aln, "001001", $tree]});
+$bf_exec->set_parameter('3', "012012");
+my ($rc,$parser) = $bf_exec->run();
+
+=head1 DESCRIPTION
+
+This module creates a generic interface to processing of HBL files in HyPhy ([Hy]pothesis
+Testing Using [Phy]logenies), a package by Sergei Kosakowsky Pond,
+Spencer V. Muse, Simon D.W. Frost and Art Poon. See
+http://www.hyphy.org for more information.
+
+Instances of this module require only a link to the batch file and an ordered list of
+parameters, as described in the HyPhy documentation "SelectionAnalyses.pdf."
+
+
+=head1 FEEDBACK
+
+=head2 Mailing Lists
+
+User feedback is an integral part of the evolution of this and other
+Bioperl modules. Send your comments and suggestions preferably to
+the Bioperl mailing list. Your participation is much appreciated.
+
+ bioperl-l@bioperl.org - General discussion
+ http://bioperl.org/wiki/Mailing_lists - About the mailing lists
+
+=head2 Support
+
+Please direct usage questions or support issues to the mailing list:
+
+I<bioperl-l@bioperl.org>
+
+rather than to the module maintainer directly. Many experienced and
+reponsive experts will be able look at the problem and quickly
+address it. Please include a thorough description of the problem
+with code and data examples if at all possible.
+
+=head2 Reporting Bugs
+
+Report bugs to the Bioperl bug tracking system to help us keep track
+of the bugs and their resolution. Bug reports can be submitted via the
+web:
+
+ http://redmine.open-bio.org/projects/bioperl/
+
+=head1 AUTHOR - Daisie Huang
+
+Email daisieh@zoology.ubc.ca
+
+=head1 CONTRIBUTORS
+
+Additional contributors names and emails here
+
+=cut
+
+package Bio::Tools::Run::Phylo::Hyphy::BatchFile;
+use strict;
+use Bio::Root::Root;
+use Bio::AlignIO;
+use Bio::TreeIO;
+use Bio::Tools::Run::Phylo::Hyphy::Base;
+use Bio::Tools::Run::WrapperBase;
+
+use base qw(Bio::Root::Root Bio::Tools::Run::Phylo::Hyphy::Base);
+
+=head2 valid_values
+
+ Title : valid_values
+ Usage : $factory->valid_values()
+ Function: returns the possible parameters
+ Returns: an array holding all possible parameters. The default
+values are always the first one listed. These descriptions are
+essentially lifted from the python wrapper or provided by the author.
+ Args : None
+
+=cut
+
+
+sub valid_values {
+ return (
+ {'geneticCode' => [ "Universal","VertebratemtDNA","YeastmtDNA","Mold/ProtozoanmtDNA",
+ "InvertebratemtDNA","CiliateNuclear","EchinodermmtDNA","EuplotidNuclear",
+ "Alt.YeastNuclear","AscidianmtDNA","FlatwormmtDNA","BlepharismaNuclear"]},
+ {'tempalnfile' => undef }, # aln file goes here
+ {'temptreefile' => undef }, # tree file goes here
+ );
+}
+
+=head2 new
+
+ Title : new
+ Usage : my $obj = Bio::Tools::Run::Phylo::Hyphy::BatchFile->new();
+ Function: Builds a new Bio::Tools::Run::Phylo::Hyphy::BatchFile object
+ Returns : Bio::Tools::Run::Phylo::Hyphy::BatchFile
+ Args : -alignment => the Bio::Align::AlignI object
+ -save_tempfiles => boolean to save the generated tempfiles and
+ NOT cleanup after onesself (default FALSE)
+ -tree => the Bio::Tree::TreeI object
+ -params => a hashref of parameters (all passed to set_parameter)
+ this hashref should include 'bf' => custombatchfile.bf
+ 'order' => [array of ordered parameters]
+ -executable => where the hyphy executable resides
+
+See also: L<Bio::Tree::TreeI>, L<Bio::Align::AlignI>
+
+=cut
+
+sub new {
+ my($class,@args) = @_;
+
+ my $self = $class->SUPER::new(@args);
+ my ($aln, $tree, $st, $params, $exe) = $self->_rearrange([qw(ALIGNMENT TREE SAVE_TEMPFILES PARAMS EXECUTABLE)], @args);
+ defined $aln && $self->alignment($aln);
+ defined $tree && $self->tree($tree);
+ defined $st && $self->save_tempfiles($st);
+ defined $exe && $self->executable($exe);
+
+ $self->set_default_parameters();
+ if( defined $params ) {
+ if( ref($params) !~ /HASH/i ) {
+ $self->warn("Must provide a valid hash ref for parameter -FLAGS");
+ } else {
+ map { $self->set_parameter($_, $$params{$_}) } keys %$params;
+ }
+ }
+ return $self;
+}
+
+=head2 update_ordered_parameters
+
+ Title : update_ordered_parameters
+ Usage : $BatchFile->update_ordered_parameters();
+ Function: updates all of the parameters needed for the ordered input redirect in HBL.
+ Returns : nothing
+ Args : none
+
+=cut
+
+sub update_ordered_parameters {
+ my ($self) = @_;
+ unless (defined ($self->{'_params'}{'order'})) {
+ $self->throw("No ordered parameters for HYPHY were defined.");
+ }
+ for (my $i=0; $i< scalar @{$self->{'_params'}{'order'}}; $i++) {
+ my $item = @{$self->{'_params'}{'order'}}[$i];
+ #FIXME: update_ordered_parameters should be more flexible. It should be able to tell what type of object $item is and, if necessary, create a temp file for it.
+ if (ref ($item) =~ m/Bio::SimpleAlign/) {
+ $item = $self->{'_params'}{'tempalnfile'};
+ } elsif (ref ($item) =~ m/Bio::Tree::Tree/) {
+ $item = $self->{'_params'}{'temptreefile'};
+ }
+ $self->{'_orderedparams'}[$i] = {$i, $item};
+ }
+ $self->SUPER::update_ordered_parameters();
+}
+
+=head2 run
+
+ Title : run
+ Usage : my ($rc,$results) = $BatchFile->run();
+ Function: run the Hyphy analysis using the specified batchfile and its ordered parameters
+ Returns : Return code, Hash
+ Args : none
+
+
+=cut
+
+sub run {
+ my $self = shift;
+ my ($rc, $results) = $self->SUPER::run();
+ my $outfile = $self->outfile_name();
+ open(OUTFILE, ">", $outfile) or $self->throw("cannot open $outfile for writing");
+ print OUTFILE $results;
+ close(OUTFILE);
+ return ($rc,$results);
+}
+
+
+=head2 create_wrapper
+
+ Title : create_wrapper
+ Usage : $self->create_wrapper
+ Function: Creates the wrapper file for the batchfile specified in the hash, saves it to the hash as '_wrapper'.
+ Returns : nothing
+ Args : none
+
+
+=cut
+
+sub create_wrapper {
+ my $self = shift;
+ my $batchfile = $self->batchfile;
+ unless (defined($batchfile)) {
+ $self->throw("No batchfile specified, couldn't create wrapper.");
+ }
+
+ unless (-f $batchfile) {
+ # check to see if maybe this batchfile is a template batchfile
+ my $new_bf = $self->io->catfile($self->hyphy_lib_dir,"TemplateBatchFiles",$batchfile);
+ $new_bf =~ s/\"//g;
+ if (-f $new_bf) {
+ $self->batchfile($new_bf);
+ } else {
+ $self->throw ("Specified batchfile $batchfile not found.");
+ return;
+ }
+ }
+ $self->SUPER::create_wrapper('"' . $self->batchfile . '"');
+}
+
+=head2 set_parameter
+
+Title : set_parameter
+Usage : $hyphy->set_parameter($param,$val);
+Function: Sets the named parameter $param to $val if it is a non-numeric parameter
+ If $param is a number, sets the corresponding value of the ordered redirect array (starts from 1).
+Returns : boolean if set was successful
+Args : $param => name of the parameter
+ $value => value to set the parameter to
+
+=cut
+
+
+sub set_parameter {
+ my ($self,$param,$value) = @_;
+ if ($param =~ /\d+/) {
+ $self->{'_params'}{'order'}[$param-1] = $value;
+ } else {
+ $self->{'_params'}{$param} = $value;
+ }
+ return 1;
+}
+
+=head2 batchfile
+
+Title : batchfile
+Usage : $hyphy->batchfile($bf_name);
+Function: Gets/sets the batchfile that is run by $hyphy.
+Returns : The batchfile path.
+Args : $bf_name => path of new batchfile
+
+=cut
+
+sub batchfile {
+ my ($self,$bf) = @_;
+ if (defined $bf) {
+ $self->set_parameter('bf', $bf);
+ }
+
+ if ($self->{'_params'}{'bf'}) {
+ return $self->{'_params'}{'bf'};
+ } else {
+ $self->warn ("Batchfile was requested but no batchfile was found.");
+ }
+ return;
+}
+
+=head2 make_batchfile_with_contents
+
+Title : make_batchfile_with_contents
+Usage : $hyphy->make_batchfile_with_contents($bf_string);
+Function: Creates a temporary file with the specified string of contents for the batchfile.
+Returns : The batchfile path.
+Args : $bf_string => contents for the batchfile
+
+=cut
+
+sub make_batchfile_with_contents {
+ my ($self,$bf_string) = @_;
+ my $temp_bf = $self->io->catfile($self->tempdir,"temp.bf");
+ open (BF, ">", $temp_bf) or $self->throw("cannot open $temp_bf for writing");
+ print BF "$bf_string\n";
+ close BF;
+ return $self->batchfile($temp_bf);
+}
+
+
+=head2 set_default_parameters
+
+ Title : set_default_parameters
+ Usage : $BatchFile->set_default_parameters(0);
+ Function: (Re)set the default parameters from the defaults
+ (the first value in each array in the
+ valid_values)
+ Returns : none
+ Args : boolean: keep existing parameter values
+
+
+=cut
+
+sub set_default_parameters {
+ my ($self,$keepold) = @_;
+ unless (defined $keepold) {
+ $keepold = 0;
+ }
+ my @validvals = $self->valid_values();
+ for (my $i=0; $i< scalar (@validvals); $i++) {
+ my $elem = @validvals[$i];
+ keys %$elem; #reset hash iterator
+ my ($param,$val) = each %$elem;
+ # skip if we want to keep old values and it is already set
+ if (ref($val)=~/ARRAY/i ) {
+ $self->{'_orderedparams'}[$i] = {$param, $val->[0]};
+ } else {
+ $self->{'_orderedparams'}[$i] = {$param, $val};
+ }
+ #FIXME: for alignment and treefile, this should default to the ones in params.
+ }
+}
+
+1;
View
252 lib/Bio/Tools/Run/Phylo/Hyphy/FEL.pm
@@ -2,7 +2,7 @@
#
# BioPerl module for Bio::Tools::Run::Phylo::Hyphy::FEL
#
-# Please direct questions and support issues to <bioperl-l@bioperl.org>
+# Please direct questions and support issues to <bioperl-l@bioperl.org>
#
# Cared for by Albert Vilella <avilella-at-gmail-dot-com>
#
@@ -56,15 +56,15 @@ the Bioperl mailing list. Your participation is much appreciated.
bioperl-l@bioperl.org - General discussion
http://bioperl.org/wiki/Mailing_lists - About the mailing lists
-=head2 Support
+=head2 Support
Please direct usage questions or support issues to the mailing list:
I<bioperl-l@bioperl.org>
-rather than to the module maintainer directly. Many experienced and
-reponsive experts will be able look at the problem and quickly
-address it. Please include a thorough description of the problem
+rather than to the module maintainer directly. Many experienced and
+reponsive experts will be able look at the problem and quickly
+address it. Please include a thorough description of the problem
with code and data examples if at all possible.
=head2 Reporting Bugs
@@ -95,7 +95,6 @@ Internal methods are usually preceded with a _
package Bio::Tools::Run::Phylo::Hyphy::FEL;
-use vars qw(@ISA @VALIDVALUES $PROGRAMNAME $PROGRAM);
use strict;
use Bio::Root::Root;
use Bio::AlignIO;
@@ -103,7 +102,7 @@ use Bio::TreeIO;
use Bio::Tools::Run::Phylo::Hyphy::Base;
use Bio::Tools::Run::WrapperBase;
-@ISA = qw(Bio::Tools::Run::Phylo::Hyphy::Base);
+use base qw(Bio::Root::Root Bio::Tools::Run::Phylo::Hyphy::Base);
=head2 Default Values
@@ -115,8 +114,21 @@ INCOMPLETE DOCUMENTATION OF ALL METHODS
=cut
-BEGIN {
- @VALIDVALUES =
+=head2 valid_values
+
+ Title : valid_values
+ Usage : $factory->valid_values()
+ Function: returns the possible parameters
+ Returns: an array holding all possible parameters. The default
+values are always the first one listed. These descriptions are
+essentially lifted from the python wrapper or provided by the author.
+ Args : None
+
+=cut
+
+
+sub valid_values {
+ return
(
{'geneticCode' => [ "Universal","VertebratemtDNA","YeastmtDNA","Mold/ProtozoanmtDNA",
"InvertebratemtDNA","CiliateNuclear","EchinodermmtDNA","EuplotidNuclear",
@@ -124,7 +136,7 @@ BEGIN {
{'New/Restore' => [ "New Analysis", "Restore"]},
{'tempalnfile' => undef }, # aln file goes here
{'Model Options' => [ { "Custom" => '010010' },
- { "Default" => undef } ]
+ { "Default" => undef } ]
},
{'temptreefile' => undef }, # tree file goes here
{'Model Fit Results' => [ '/dev/null'] }, # this will not work under Windows
@@ -143,31 +155,12 @@ BEGIN {
);
}
-=head2 program_name
-
- Title : program_name
- Usage : $factory->program_name()
- Function: holds the program name
- Returns: string
- Args : None
-
-=cut
-
-=head2 program_dir
-
- Title : program_dir
- Usage : ->program_dir()
- Function: returns the program directory, obtained from ENV variable.
- Returns: string
- Args :
-
-=cut
=head2 new
Title : new
Usage : my $obj = Bio::Tools::Run::Phylo::Hyphy::FEL->new();
- Function: Builds a new Bio::Tools::Run::Phylo::Hyphy::FEL object
+ Function: Builds a new Bio::Tools::Run::Phylo::Hyphy::FEL object
Returns : Bio::Tools::Run::Phylo::Hyphy::FEL
Args : -alignment => the Bio::Align::AlignI object
-save_tempfiles => boolean to save the generated tempfiles and
@@ -184,8 +177,8 @@ sub new {
my($class,@args) = @_;
my $self = $class->SUPER::new(@args);
- my ($aln, $tree, $st, $params, $exe,
- $ubl) = $self->_rearrange([qw(ALIGNMENT TREE SAVE_TEMPFILES
+ my ($aln, $tree, $st, $params, $exe,
+ $ubl) = $self->_rearrange([qw(ALIGNMENT TREE SAVE_TEMPFILES
PARAMS EXECUTABLE)],
@args);
defined $aln && $self->alignment($aln);
@@ -195,7 +188,7 @@ sub new {
$self->set_default_parameters();
if( defined $params ) {
- if( ref($params) !~ /HASH/i ) {
+ if( ref($params) !~ /HASH/i ) {
$self->warn("Must provide a valid hash ref for parameter -FLAGS");
} else {
map { $self->set_parameter($_, $$params{$_}) } keys %$params;
@@ -219,53 +212,27 @@ sub new {
=cut
sub run {
- my ($self,$aln,$tree) = @_;
-
- $self->prepare($aln,$tree) unless (defined($self->{'_prepared'}));
- my ($rc,$results) = (1);
- {
- my $commandstring;
- my $exit_status;
- my $tempdir = $self->tempdir;
- my $felexe = $self->executable();
- $self->throw("unable to find or run executable for 'HYPHY'") unless $felexe && -e $felexe && -x _;
- $commandstring = $felexe . " BASEPATH=" . $self->program_dir . " " . $self->{'_wrapper'};
- open(RUN, "$commandstring |") or $self->throw("Cannot open exe $felexe");
- my @output = <RUN>;
- $exit_status = close(RUN);
- $self->error_string(join('',@output));
- if( (grep { /\berr(or)?: /io } @output) || !$exit_status) {
- $self->warn("There was an error - see error_string for the program output");
- $rc = 0;
- }
- my $outfile = $self->outfile_name;
- eval {
- open(OUTFILE, "$outfile") or $self->throw("cannot open $outfile for reading");
- my $readed_header = 0;
- my @elems;
- while (<OUTFILE>) {
- if ($readed_header) {
- # FEL results are csv
- my @values = split("\,",$_);
- for my $i (0 .. (scalar(@values)-1)) {
- $elems[$i] =~ s/\n//g;
- push @{$results->{$elems[$i]}}, $values[$i];
- }
- } else {
- @elems = split("\,",$_);
- $readed_header = 1;
- }
+ my $self = shift;
+ my ($rc, $run_results) = $self->SUPER::run();
+ my $results ={};
+ my $outfile = $self->outfile_name();
+ open(OUTFILE, "$outfile") or $self->throw("cannot open $outfile for reading");
+ my $readed_header = 0;
+ my @elems;
+ while (<OUTFILE>) {
+ if ($readed_header) {
+ # FEL results are csv
+ my @values = split("\,",$_);
+ for my $i (0 .. (scalar(@values)-1)) {
+ $elems[$i] =~ s/\n//g;
+ push @{$results->{$elems[$i]}}, $values[$i];
}
- };
- if( $@ ) {
- $self->warn($self->error_string);
- }
- }
- unless ( $self->save_tempfiles ) {
- unlink($self->{'_wrapper'});
- $self->cleanup();
- }
- return ($rc,$results);
+ } else {
+ @elems = split("\,",$_);
+ $readed_header = 1;
+ }
+ }
+ return ($rc, $results);
}
@@ -275,7 +242,7 @@ sub run {
Usage : $self->create_wrapper
Function: It will create the wrapper file that interfaces with the analysis bf file
Example :
- Returns :
+ Returns :
Args :
@@ -284,132 +251,9 @@ sub run {
sub create_wrapper {
my $self = shift;
- my $batchfile = 'QuickSelectionDetection.bf';
+ my $batchfile = "QuickSelectionDetection.bf";
$self->SUPER::create_wrapper($batchfile);
}
-=head2 error_string
-
- Title : error_string
- Usage : $obj->error_string($newval)
- Function: Where the output from the last analysus run is stored.
- Returns : value of error_string
- Args : newvalue (optional)
-
-
-=cut
-
-=head2 set_default_parameters
-
- Title : set_default_parameters
- Usage : $fel->set_default_parameters(0);
- Function: (Re)set the default parameters from the defaults
- (the first value in each array in the
- %VALIDVALUES class variable)
- Returns : none
- Args : boolean: keep existing parameter values
-
-
-=cut
-
-sub set_default_parameters {
- my ($self,$keepold) = @_;
- $keepold = 0 unless defined $keepold;
- foreach my $elem (@VALIDVALUES) {
- my ($param,$val) = each %$elem;
- # skip if we want to keep old values and it is already set
- if (ref($val)=~/ARRAY/i ) {
- unless (ref($val->[0])=~/HASH/i) {
- push @{ $self->{'_orderedparams'} }, {$param, $val->[0]};
- } else {
- $val = $val->[0];
- }
- }
- if ( ref($val) =~ /HASH/i ) {
- my $prevparam;
- while (defined($val)) {
- last unless (ref($val) =~ /HASH/i);
- last unless (defined($param));
- $prevparam = $param;
- ($param,$val) = each %{$val};
- push @{ $self->{'_orderedparams'} }, {$prevparam, $param};
- push @{ $self->{'_orderedparams'} }, {$param, $val} if (defined($val));
- }
- } elsif (ref($val) !~ /HASH/i && ref($val) !~ /ARRAY/i) {
- push @{ $self->{'_orderedparams'} }, {$param, $val};
- }
- }
-}
-
-
-=head1 Bio::Tools::Run::WrapperBase methods
-
-=cut
-
-=head2 no_param_checks
-
- Title : no_param_checks
- Usage : $obj->no_param_checks($newval)
- Function: Boolean flag as to whether or not we should
- trust the sanity checks for parameter values
- Returns : value of no_param_checks
- Args : newvalue (optional)
-
-
-=cut
-
-
-=head2 save_tempfiles
-
- Title : save_tempfiles
- Usage : $obj->save_tempfiles($newval)
- Function:
- Returns : value of save_tempfiles
- Args : newvalue (optional)
-
-
-=cut
-
-=head2 tempdir
-
- Title : tempdir
- Usage : my $tmpdir = $self->tempdir();
- Function: Retrieve a temporary directory name (which is created)
- Returns : string which is the name of the temporary directory
- Args : none
-
-
-=cut
-
-=head2 cleanup
-
- Title : cleanup
- Usage : $fel->cleanup();
- Function: Will cleanup the tempdir directory after a run
- Returns : none
- Args : none
-
-
-=cut
-
-=head2 io
-
- Title : io
- Usage : $obj->io($newval)
- Function: Gets a L<Bio::Root::IO> object
- Returns : L<Bio::Root::IO>
- Args : none
-
-
-=cut
-
-sub DESTROY {
- my $self= shift;
- unless ( $self->save_tempfiles ) {
- $self->cleanup();
- }
- $self->SUPER::DESTROY();
-}
-
1;
View
220 lib/Bio/Tools/Run/Phylo/Hyphy/Modeltest.pm
@@ -2,7 +2,7 @@
#
# BioPerl module for Bio::Tools::Run::Phylo::Hyphy::Modeltest
#
-# Please direct questions and support issues to <bioperl-l@bioperl.org>
+# Please direct questions and support issues to <bioperl-l@bioperl.org>
#
# Cared for by Albert Vilella <avilella-at-gmail-dot-com>
#
@@ -42,7 +42,7 @@ Spencer V. Muse, Simon D.W. Frost and Art Poon. See
http://www.hyphy.org for more information.
This module will generate the correct list of options for interfacing
-with TemplateBatchFiles/Ghostrides/Modeltestwrapper.bf.
+with TemplateBatchFiles/Modeltest.bf.
=head1 FEEDBACK
@@ -55,15 +55,15 @@ the Bioperl mailing list. Your participation is much appreciated.
bioperl-l@bioperl.org - General discussion
http://bioperl.org/wiki/Mailing_lists - About the mailing lists
-=head2 Support
+=head2 Support
Please direct usage questions or support issues to the mailing list:
I<bioperl-l@bioperl.org>
-rather than to the module maintainer directly. Many experienced and
-reponsive experts will be able look at the problem and quickly
-address it. Please include a thorough description of the problem
+rather than to the module maintainer directly. Many experienced and
+reponsive experts will be able look at the problem and quickly
+address it. Please include a thorough description of the problem
with code and data examples if at all possible.
=head2 Reporting Bugs
@@ -94,7 +94,7 @@ Internal methods are usually preceded with a _
package Bio::Tools::Run::Phylo::Hyphy::Modeltest;
-use vars qw(@ISA @VALIDVALUES $PROGRAMNAME $PROGRAM);
+use vars qw(@ISA);
use strict;
use Bio::Root::Root;
use Bio::AlignIO;
@@ -102,7 +102,7 @@ use Bio::TreeIO;
use Bio::Tools::Run::Phylo::Hyphy::Base;
use Bio::Tools::Run::WrapperBase;
-@ISA = qw(Bio::Root::Root Bio::Tools::Run::Phylo::Hyphy::Base);
+use base qw(Bio::Root::Root Bio::Tools::Run::Phylo::Hyphy::Base);
=head2 Default Values
@@ -110,34 +110,41 @@ Valid and default values for Modeltest are listed below. The default
values are always the first one listed. These descriptions are
essentially lifted from the python wrapper or provided by the author.
-INCOMPLETE DOCUMENTATION OF ALL METHODS
+=cut
+
+=head2 valid_values
+
+ Title : valid_values
+ Usage : $factory->valid_values()
+ Function: returns the possible parameters
+ Returns: an array holding all possible parameters. The default
+values are always the first one listed. These descriptions are
+essentially lifted from the python wrapper or provided by the author.
+ Args : None
=cut
-BEGIN {
- $PROGRAMNAME = 'HYPHYMP' . ($^O =~ /mswin/i ?'.exe':'');
- if( defined $ENV{'HYPHYDIR'} ) {
- $PROGRAM = Bio::Root::IO->catfile($ENV{'HYPHYDIR'},$PROGRAMNAME). ($^O =~ /mswin/i ?'.exe':'');;
- }
- @VALIDVALUES =
+sub valid_values {
+ return
(
{'tempalnfile' => undef }, # aln file goes here
{'temptreefile' => undef }, # tree file goes here
{'Number of Rate Classes' => [ '4' ] },
- {'Model Selection Method' => [ 'Both',
- 'Hierarchical Test',
+ {'Model Selection Method' => [ 'Both',
+ 'Hierarchical Test',
'AIC Test'] },
{'Model rejection level' => '0.05' },
+ {'hieoutfile' => undef },
+ {'aicoutfile' => undef }
);
}
-
=head2 new
Title : new
Usage : my $obj = Bio::Tools::Run::Phylo::Hyphy::Modeltest->new();
- Function: Builds a new Bio::Tools::Run::Phylo::Hyphy::Modeltest object
+ Function: Builds a new Bio::Tools::Run::Phylo::Hyphy::Modeltest object
Returns : Bio::Tools::Run::Phylo::Hyphy::Modeltest
Args : -alignment => the Bio::Align::AlignI object
-save_tempfiles => boolean to save the generated tempfiles and
@@ -154,8 +161,8 @@ sub new {
my($class,@args) = @_;
my $self = $class->SUPER::new(@args);
- my ($aln, $tree, $st, $params, $exe,
- $ubl) = $self->_rearrange([qw(ALIGNMENT TREE SAVE_TEMPFILES
+ my ($aln, $tree, $st, $params, $exe,
+ $ubl) = $self->_rearrange([qw(ALIGNMENT TREE SAVE_TEMPFILES
PARAMS EXECUTABLE)],
@args);
defined $aln && $self->alignment($aln);
@@ -165,7 +172,7 @@ sub new {
$self->set_default_parameters();
if( defined $params ) {
- if( ref($params) !~ /HASH/i ) {
+ if( ref($params) !~ /HASH/i ) {
$self->warn("Must provide a valid hash ref for parameter -FLAGS");
} else {
map { $self->set_parameter($_, $$params{$_}) } keys %$params;
@@ -181,52 +188,36 @@ sub new {
Usage : my ($rc,$results) = $modeltest->run($aln);
Function: run the modeltest analysis using the default or updated parameters
the alignment parameter must have been set
- Returns : Return code, Hash
+ Returns : Return code, hash containing the "Hierarchical Testing" and "AIC" results, both as hashes.
Args : L<Bio::Align::AlignI> object,
L<Bio::Tree::TreeI> object [optional]
-
=cut
sub run {
- my ($self,$aln,$tree) = @_;
-
- $self->prepare($aln,$tree) unless (defined($self->{'_prepared'}));
- my ($rc,$results) = (1);
- {
- my $commandstring;
- my $exit_status;
- my $tempdir = $self->tempdir;
- my $modeltestexe = $self->executable();
- $self->throw("unable to find or run executable for 'HYPHY'") unless $modeltestexe && -e $modeltestexe && -x _;
- $commandstring = $modeltestexe . " BASEPATH=" . $self->program_dir . " " . $self->{'_wrapper'};
- open(RUN, "$commandstring |") or $self->throw("Cannot open exe $modeltestexe");
- my @output = <RUN>;
- $exit_status = close(RUN);
- $self->error_string(join('',@output));
- if( (grep { /\berr(or)?: /io } @output) || !$exit_status) {
- $self->warn("There was an error - see error_string for the program output");
- $rc = 0;
- }
- my $outfile = $self->outfile_name;
- eval {
- open(OUTFILE, ">$outfile") or $self->throw("cannot open $outfile for writing");
- # FIXME -- needs output parsing -- ask hyphy to clean that up into a tsv?
- foreach my $output (@output) {
- print OUTFILE $output;
- $results .= sprintf($output);
- }
- close(OUTFILE);
- };
- if( $@ ) {
- $self->warn($self->error_string);
- }
- }
- unless ( $self->save_tempfiles ) {
- unlink($self->{'_wrapper'});
- $self->cleanup();
- }
- return ($rc,$results);
+ my $self = shift;
+ my ($rc, $run_results) = $self->SUPER::run();
+ my $results = {};
+ my @run_result_array = split (/\n/, $run_results);
+ my $line = shift @run_result_array;
+ my $current_model = "error"; # if this stays "error" when you're trying to add results for a model, something's wrong.
+ while (defined $line) {
+ if ($line =~ m/Hierarchical Testing based model \((.*)\)/) {
+ $current_model = "Hierarchical Testing";
+ $results->{$current_model}{'model_name'} = $1;
+ } elsif ($line =~ m/AIC based model \((.*)\)/) {
+ $current_model = "AIC";
+ $results->{$current_model}{'model_name'} = $1;
+ } elsif ($line =~ m/Model String:(\d+)/) {
+ $results->{$current_model}{'model_string'} = $1;
+ } elsif ($line =~ m/Model Options: (.+)/) {
+ $results->{$current_model}{'model_options'} = $1;
+ } elsif ($line =~ m/Equilibrium Frequencies Option: (.+)/) {
+ $results->{$current_model}{'eq_freq_option'} = $1;
+ }
+ $line = shift @run_result_array;
+ }
+ return ($rc,$results);
}
@@ -236,7 +227,7 @@ sub run {
Usage : $self->create_wrapper
Function: It will create the wrapper file that interfaces with the analysis bf file
Example :
- Returns :
+ Returns :
Args :
@@ -245,109 +236,8 @@ sub run {
sub create_wrapper {
my $self = shift;
- my $batchfile = 'ModelTest.bf';
+ my $batchfile = "ModelTest.bf";
$self->SUPER::create_wrapper($batchfile);
}
-
-=head2 set_default_parameters
-
- Title : set_default_parameters
- Usage : $modeltest->set_default_parameters(0);
- Function: (Re)set the default parameters from the defaults
- (the first value in each array in the
- %VALIDVALUES class variable)
- Returns : none
- Args : boolean: keep existing parameter values
-
-
-=cut
-
-sub set_default_parameters {
- my ($self,$keepold) = @_;
- $keepold = 0 unless defined $keepold;
- foreach my $elem (@VALIDVALUES) {
- my ($param,$val) = each %$elem;
- # skip if we want to keep old values and it is already set
- if (ref($val)=~/ARRAY/i ) {
- unless (ref($val->[0])=~/HASH/i) {
- push @{ $self->{'_orderedparams'} }, {$param, $val->[0]};
- } else {
- $val = $val->[0];
- }
- }
- if ( ref($val) =~ /HASH/i ) {
- my $prevparam;
- while (defined($val)) {
- last unless (ref($val) =~ /HASH/i);
- last unless (defined($param));
- $prevparam = $param;
- ($param,$val) = each %{$val};
- push @{ $self->{'_orderedparams'} }, {$prevparam, $param};
- push @{ $self->{'_orderedparams'} }, {$param, $val} if (defined($val));
- }
- } elsif (ref($val) !~ /HASH/i && ref($val) !~ /ARRAY/i) {
- push @{ $self->{'_orderedparams'} }, {$param, $val};
- }
- }
-}
-
-
-=head1 Bio::Tools::Run::WrapperBase methods
-
-=cut
-
-=head2 save_tempfiles
-
- Title : save_tempfiles
- Usage : $obj->save_tempfiles($newval)
- Function:
- Returns : value of save_tempfiles
- Args : newvalue (optional)
-
-
-=cut
-
-
-=head2 tempdir
-
- Title : tempdir
- Usage : my $tmpdir = $self->tempdir();
- Function: Retrieve a temporary directory name (which is created)
- Returns : string which is the name of the temporary directory
- Args : none
-
-
-=cut
-
-=head2 cleanup
-
- Title : cleanup
- Usage : $modeltest->cleanup();
- Function: Will cleanup the tempdir directory after a run
- Returns : none
- Args : none
-
-
-=cut
-
-=head2 io
-
- Title : io
- Usage : $obj->io($newval)
- Function: Gets a L<Bio::Root::IO> object
- Returns : L<Bio::Root::IO>
- Args : none
-
-
-=cut
-
-sub DESTROY {
- my $self= shift;
- unless ( $self->save_tempfiles ) {
- $self->cleanup();
- }
- $self->SUPER::DESTROY();
-}
-
1;
View
212 lib/Bio/Tools/Run/Phylo/Hyphy/REL.pm
@@ -23,7 +23,7 @@ Bio::Tools::Run::Phylo::Hyphy::REL - Wrapper around the Hyphy REL analysis
use Bio::TreeIO;
my $alignio = Bio::AlignIO->new(-format => 'fasta',
- -file => 't/data/hyphy1.fasta');
+ -file => 't/data/hyphy1.fasta');
my $aln = $alignio->next_aln;
@@ -95,7 +95,6 @@ Internal methods are usually preceded with a _
package Bio::Tools::Run::Phylo::Hyphy::REL;
-use vars qw(@ISA @VALIDVALUES $PROGRAMNAME $PROGRAM);
use strict;
use Bio::Root::Root;
use Bio::AlignIO;
@@ -103,20 +102,23 @@ use Bio::TreeIO;
use Bio::Tools::Run::Phylo::Hyphy::Base;
use Bio::Tools::Run::WrapperBase;
-@ISA = qw(Bio::Root::Root Bio::Tools::Run::Phylo::Hyphy::Base);
+use base qw(Bio::Root::Root Bio::Tools::Run::Phylo::Hyphy::Base);
-=head2 Default Values
-Valid and default values for REL are listed below. The default
+=head2 valid_values
+
+ Title : valid_values
+ Usage : $factory->valid_values()
+ Function: returns the possible parameters
+ Returns: an array holding all possible parameters. The default
values are always the first one listed. These descriptions are
essentially lifted from the python wrapper or provided by the author.
-
-INCOMPLETE DOCUMENTATION OF ALL METHODS
+ Args : None
=cut
-BEGIN {
- @VALIDVALUES =
+sub valid_values {
+ return
(
{'geneticCode' => [ "Universal","VertebratemtDNA","YeastmtDNA","Mold/ProtozoanmtDNA",
"InvertebratemtDNA","CiliateNuclear","EchinodermmtDNA","EuplotidNuclear",
@@ -124,7 +126,7 @@ BEGIN {
{'tempalnfile' => undef }, # aln file goes here
{'temptreefile' => undef }, # tree file goes here
{'Model' => [ "Null for Test 1", "Null for Test 2", "Alternative"]},
- {'temptsvfile' => undef } # site-by-site conditional probabilities go to this file
+ {'outfile' => undef } # site-by-site conditional probabilities go to this file
);
}
@@ -146,8 +148,7 @@ See also: L<Bio::Tree::TreeI>, L<Bio::Align::AlignI>
=cut
sub new {
- my($class,@args) = @_;
-
+ my($class,@args) = @_;
my $self = $class->SUPER::new(@args);
my ($aln, $tree, $st, $params, $exe,
$ubl) = $self->_rearrange([qw(ALIGNMENT TREE SAVE_TEMPFILES PARAMS EXECUTABLE)], @args);
@@ -156,19 +157,15 @@ sub new {
defined $st && $self->save_tempfiles($st);
defined $exe && $self->executable($exe);
- my $tsvfile = $self->tempdir() . "/results.tsv";
- $self->{'_params'}{'temptsvfile'} = $tsvfile;
-
-
$self->set_default_parameters();
if( defined $params ) {
if( ref($params) !~ /HASH/i ) {
$self->warn("Must provide a valid hash ref for parameter -FLAGS");
} else {
- map { $self->set_parameter($_, $$params{$_}) } keys %$params;
+ map { $self->set_parameter($_, $$params{$_}) } keys %$params;
}
- }
- return $self;
+ }
+ return $self;
}
@@ -180,53 +177,35 @@ sub new {
the alignment parameter must have been set
Returns : Return code, Hash
Args : L<Bio::Align::AlignI> object,
- L<Bio::Tree::TreeI> object [optional]
+ L<Bio::Tree::TreeI> object [optional]
=cut
sub run {
- my ($self,$aln,$tree) = @_;
-
- $self->prepare($aln,$tree) unless (defined($self->{'_prepared'}));
- my ($rc,$results) = (1);
- {
- my $commandstring;
- my $exit_status;
- my $tempdir = $self->tempdir;
-
- my $relexe = $self->executable();
- $self->throw("unable to find or run executable for 'HYPHY'") unless $relexe && -e $relexe && -x _;
- $commandstring = $relexe . " BASEPATH=" . $self->program_dir . " " . $self->{'_wrapper'};
- open(RUN, "$commandstring |") or $self->throw("Cannot open exe $relexe");
- my @output = <RUN>;
- $exit_status = close(RUN);
- $self->error_string(join('',@output));
- if( (grep { /\berr(or)?: /io } @output) || !$exit_status) {
- $self->warn("There was an error - see error_string for the program output");
- $rc = 0;
- }
- my $outfile = $self->outfile_name;
- eval {
- open(OUTFILE, ">$outfile") or $self->throw("cannot open $outfile for writing");
- foreach my $output (@output) {
- print OUTFILE $output;
- $results .= sprintf($output);
- }
- close(OUTFILE);
- };
- if( $@ ) {
- $self->warn($self->error_string);
- }
- }
- unless ( $self->save_tempfiles ) {
- unlink($self->{'_wrapper'});
- $self->cleanup();
- }
- return ($rc,$results);
+ my $self = shift;
+ my ($rc,$run_results) = $self->SUPER::run();
+ my $results = {};
+ my $outfile = $self->outfile_name();
+ open(OUTFILE, "$outfile") or $self->throw("cannot open $outfile for reading");
+ my $readed_header = 0;
+ my @elems;
+ while (<OUTFILE>) {
+ if ($readed_header) {
+ # REL results are csv
+ my @values = split("\,",$_);
+ for my $i (0 .. (scalar(@values)-1)) {
+ $elems[$i] =~ s/\n//g;
+ push @{$results->{$elems[$i]}}, $values[$i];
+ }
+ } else {
+ @elems = split("\,",$_);
+ $readed_header = 1;
+ }
+ }
+ return ($rc,$results);
}
-
=head2 create_wrapper
Title : create_wrapper
@@ -242,121 +221,8 @@ sub run {
sub create_wrapper {
my $self = shift;
- my $batchfile = 'YangNielsenBranchSite2005.bf';
+ my $batchfile = "YangNielsenBranchSite2005.bf";
$self->SUPER::create_wrapper($batchfile);
}
-
-=head2 set_default_parameters
-
- Title : set_default_parameters
- Usage : $rel->set_default_parameters(0);
- Function: (Re)set the default parameters from the defaults
- (the first value in each array in the
- %VALIDVALUES class variable)
- Returns : none
- Args : boolean: keep existing parameter values
-
-
-=cut
-
-sub set_default_parameters {
- my ($self,$keepold) = @_;
- $keepold = 0 unless defined $keepold;
- foreach my $elem (@VALIDVALUES) {
- keys %$elem; #reset hash iterator
- my ($param,$val) = each %$elem;
- # skip if we want to keep old values and it is already set
- if (ref($val)=~/ARRAY/i ) {
- unless (ref($val->[0])=~/HASH/i) {
- push @{ $self->{'_orderedparams'} }, {$param, $val->[0]};
- } else {
- $val = $val->[0];
- }
- }
- if ( ref($val) =~ /HASH/i ) {
- my $prevparam;
- while (defined($val)) {
- last unless (ref($val) =~ /HASH/i);
- last unless (defined($param));
- $prevparam = $param;
- ($param,$val) = each %{$val};
- push @{ $self->{'_orderedparams'} }, {$prevparam, $param};
- push @{ $self->{'_orderedparams'} }, {$param, $val} if (defined($val));
- }
- } elsif (ref($val) !~ /HASH/i && ref($val) !~ /ARRAY/i) {
- push @{ $self->{'_orderedparams'} }, {$param, $val};
- }
- }
-}
-
-
-=head1 Bio::Tools::Run::WrapperBase methods
-
-=cut
-
-=head2 no_param_checks
-
- Title : no_param_checks
- Usage : $obj->no_param_checks($newval)
- Function: Boolean flag as to whether or not we should
- trust the sanity checks for parameter values
- Returns : value of no_param_checks
- Args : newvalue (optional)
-
-
-=cut
-
-=head2 save_tempfiles
-
- Title : save_tempfiles
- Usage : $obj->save_tempfiles($newval)
- Function:
- Returns : value of save_tempfiles
- Args : newvalue (optional)
-
-
-=cut
-
-=head2 tempdir
-
- Title : tempdir
- Usage : my $tmpdir = $self->tempdir();
- Function: Retrieve a temporary directory name (which is created)
- Returns : string which is the name of the temporary directory
- Args : none
-
-
-=cut
-
-=head2 cleanup
-
- Title : cleanup
- Usage : $rel->cleanup();
- Function: Will cleanup the tempdir directory after a run
- Returns : none
- Args : none
-
-
-=cut
-
-=head2 io
-
- Title : io
- Usage : $obj->io($newval)
- Function: Gets a L<Bio::Root::IO> object
- Returns : L<Bio::Root::IO>
- Args : none
-
-
-=cut
-
-sub DESTROY {
- my $self= shift;
- unless ( $self->save_tempfiles ) {
- $self->cleanup();
- }
- $self->SUPER::DESTROY();
-}
-
1;
View
342 lib/Bio/Tools/Run/Phylo/Hyphy/SLAC.pm
@@ -2,7 +2,7 @@
#
# BioPerl module for Bio::Tools::Run::Phylo::Hyphy::SLAC
#
-# Please direct questions and support issues to <bioperl-l@bioperl.org>
+# Please direct questions and support issues to <bioperl-l@bioperl.org>
#
# Cared for by Albert Vilella <avilella-at-gmail-dot-com>
#
@@ -54,15 +54,15 @@ the Bioperl mailing list. Your participation is much appreciated.
bioperl-l@bioperl.org - General discussion
http://bioperl.org/wiki/Mailing_lists - About the mailing lists
-=head2 Support
+=head2 Support
Please direct usage questions or support issues to the mailing list:
I<bioperl-l@bioperl.org>
-rather than to the module maintainer directly. Many experienced and
-reponsive experts will be able look at the problem and quickly
-address it. Please include a thorough description of the problem
+rather than to the module maintainer directly. Many experienced and
+reponsive experts will be able look at the problem and quickly
+address it. Please include a thorough description of the problem
with code and data examples if at all possible.
=head2 Reporting Bugs
@@ -93,7 +93,6 @@ Internal methods are usually preceded with a _
package Bio::Tools::Run::Phylo::Hyphy::SLAC;
-use vars qw(@ISA @VALIDVALUES $PROGRAMNAME $PROGRAM);
use strict;
use Bio::Root::Root;
use Bio::AlignIO;
@@ -101,7 +100,7 @@ use Bio::TreeIO;
use Bio::Tools::Run::Phylo::Hyphy::Base;
use Bio::Tools::Run::WrapperBase;
-@ISA = qw(Bio::Tools::Run::Phylo::Hyphy::Base);
+use base qw(Bio::Root::Root Bio::Tools::Run::Phylo::Hyphy::Base);
=head2 Default Values
@@ -113,16 +112,30 @@ INCOMPLETE DOCUMENTATION OF ALL METHODS
=cut
-BEGIN {
- @VALIDVALUES =
- (
+=head2 valid_values
+
+ Title : valid_values
+ Usage : $factory->valid_values()
+ Function: returns the possible parameters
+ Returns: an array holding all possible parameters. The default
+values are always the first one listed. These descriptions are
+essentially lifted from the python wrapper or provided by the author.
+ Args : None
+
+=cut
+
+
+
+sub valid_values {
+ return
+ (
{'geneticCode' => [ "Universal","VertebratemtDNA","YeastmtDNA","Mold/ProtozoanmtDNA",
"InvertebratemtDNA","CiliateNuclear","EchinodermmtDNA","EuplotidNuclear",
"Alt.YeastNuclear","AscidianmtDNA","FlatwormmtDNA","BlepharismaNuclear"]},
{'New/Restore' => [ "New Analysis", "Restore"]},
{'tempalnfile' => undef }, # aln file goes here
{'Model Options' => [ { "Custom" => '010010' },
- { "Default" => undef } ]
+ { "Default" => undef } ]
},
{'temptreefile' => undef }, # tree file goes here
{'Model Fit Results' => [ '/dev/null'] }, # this will not work under Windows
@@ -145,11 +158,12 @@ BEGIN {
);
}
+
=head2 new
Title : new
Usage : my $obj = Bio::Tools::Run::Phylo::Hyphy::SLAC->new();
- Function: Builds a new Bio::Tools::Run::Phylo::Hyphy::SLAC object
+ Function: Builds a new Bio::Tools::Run::Phylo::Hyphy::SLAC object
Returns : Bio::Tools::Run::Phylo::Hyphy::SLAC
Args : -alignment => the Bio::Align::AlignI object
-save_tempfiles => boolean to save the generated tempfiles and
@@ -166,8 +180,9 @@ sub new {
my($class,@args) = @_;
my $self = $class->SUPER::new(@args);
- my ($aln, $tree, $st, $params, $exe,
- $ubl) = $self->_rearrange([qw(ALIGNMENT TREE SAVE_TEMPFILES
+
+ my ($aln, $tree, $st, $params, $exe,
+ $ubl) = $self->_rearrange([qw(ALIGNMENT TREE SAVE_TEMPFILES
PARAMS EXECUTABLE)],
@args);
defined $aln && $self->alignment($aln);
@@ -176,13 +191,12 @@ sub new {
defined $exe && $self->executable($exe);
$self->set_default_parameters();
if( defined $params ) {
- if( ref($params) !~ /HASH/i ) {
+ if( ref($params) !~ /HASH/i ) {
$self->warn("Must provide a valid hash ref for parameter -FLAGS");
} else {
map { $self->set_parameter($_, $$params{$_}) } keys %$params;
}
}
-
return $self;
}
@@ -201,53 +215,27 @@ sub new {
=cut
sub run {
- my ($self,$aln,$tree) = @_;
-
- $self->prepare($aln,$tree) unless (defined($self->{'_prepared'}));
- my ($rc,$results) = (1);
- {
- my $commandstring;
- my $exit_status;
- my $tempdir = $self->tempdir;
- my $slacexe = $self->executable();
- $self->throw("unable to find or run executable for 'HYPHY'") unless $slacexe && -e $slacexe && -x _;
- $commandstring = $slacexe . " BASEPATH=" . $self->program_dir . " " . $self->{'_wrapper'};
- open(RUN, "$commandstring |") or $self->throw("Cannot open exe $slacexe");
- my @output = <RUN>;
- $exit_status = close(RUN);
- $self->error_string(join('',@output));
- if( (grep { /\berr(or)?: /io } @output) || !$exit_status) {
- $self->warn("There was an error - see error_string for the program output");
- $rc = 0;
- }
- my $outfile = $self->outfile_name;
- eval {
- open(OUTFILE, "$outfile") or $self->throw("cannot open $outfile for reading");
- my $readed_header = 0;
- my @elems;
- while (<OUTFILE>) {
- if ($readed_header) {
- # FEL results are tsv
- my @values = split("\t",$_);
- for my $i (0 .. (scalar(@values)-1)) {
- $elems[$i] =~ s/\n//g;
- push @{$results->{$elems[$i]}}, $values[$i];
- }
- } else {
- @elems = split("\t",$_);
- $readed_header = 1;
- }
+ my $self = shift;
+ my $results = {};
+ my ($rc, $run_output) = $self->SUPER::run();
+ my $outfile = $self->outfile_name();
+ open(OUTFILE, "$outfile") or $self->throw("cannot open $outfile for reading");
+ my $readed_header = 0;
+ my @elems;
+ while (my $line = <OUTFILE>) {
+ if ($readed_header) {
+ # SLAC results are tsv
+ my @values = split("\t",$line);
+ for my $i (0 .. (scalar(@values)-1)) {
+ $elems[$i] =~ s/\n//g;
+ push @{$results->{$elems[$i]}}, $values[$i];
}
- };
- if( $@ ) {
- $self->warn($self->error_string);
+ } else {
+ @elems = split("\t",$line);
+ $readed_header = 1;
}
- }
- unless ( $self->save_tempfiles ) {
- unlink($self->{'_wrapper'});
- $self->cleanup();
- }
- return ($rc,$results);
+ }
+ return ($rc, $results);
}
=head2 create_wrapper
@@ -256,7 +244,7 @@ sub run {
Usage : $self->create_wrapper
Function: It will create the wrapper file that interfaces with the analysis bf file
Example :
- Returns :
+ Returns :
Args :
@@ -265,236 +253,8 @@ sub run {
sub create_wrapper {
my $self = shift;
- my $batchfile = 'QuickSelectionDetection.bf';
+ my $batchfile = "QuickSelectionDetection.bf";
$self->SUPER::create_wrapper($batchfile);
}
-=head2 set_default_parameters
-
- Title : set_default_parameters
- Usage : $hyphy->set_default_parameters(0);
- Function: (Re)set the default parameters from the defaults
- (the first value in each array in the
- %VALIDVALUES class variable)
- Returns : none
- Args : boolean: keep existing parameter values
-
-
-=cut
-
-sub set_default_parameters {
- my ($self,$keepold) = @_;
- $keepold = 0 unless defined $keepold;
- foreach my $elem (@VALIDVALUES) {
- my ($param,$val) = each %$elem;
- # skip if we want to keep old values and it is already set
- if (ref($val)=~/ARRAY/i ) {
- unless (ref($val->[0])=~/HASH/i) {
- push @{ $self->{'_orderedparams'} }, {$param, $val->[0]};
- } else {
- $val = $val->[0];
- }
- }
- if ( ref($val) =~ /HASH/i ) {
- my $prevparam;
- while (defined($val)) {
- last unless (ref($val) =~ /HASH/i);
- last unless (defined($param));
- $prevparam = $param;
- ($param,$val) = each %{$val};
- push @{ $self->{'_orderedparams'} }, {$prevparam, $param};
- push @{ $self->{'_orderedparams'} }, {$param, $val} if (defined($val));
- }
- } elsif (ref($val) !~ /HASH/i && ref($val) !~ /ARRAY/i) {
- push @{ $self->{'_orderedparams'} }, {$param, $val};
- }
- }
-}
-
-=head1 Bio::Tools::Run::Phylo::Hyphy::Base methods
-
-=head2 program_name
-
- Title : program_name
- Usage : $factory->program_name()
- Function: holds the program name
- Returns: string
- Args : None
-
-=cut
-
-=head2 program_dir
-
- Title : program_dir
- Usage : ->program_dir()
- Function: returns the program directory, obtained from ENV variable.
- Returns: string
- Args :
-
-=cut
-
-=head2 prepare
-
- Title : prepare
- Usage : my $rundir = $slac->prepare($aln);
- Function: prepare the slac analysis using the default or updated parameters
- the alignment parameter must have been set
- Returns : value of rundir
- Args : L<Bio::Align::AlignI> object,
- L<Bio::Tree::TreeI> object [optional]
-
-=cut
-
-
-=head2 error_string
-
- Title : error_string
- Usage : $obj->error_string($newval)
- Function: Where the output from the last analysus run is stored.
- Returns : value of error_string
- Args : newvalue (optional)
-
-
-=cut
-
-
-=head2 alignment
-
- Title : alignment
- Usage : $slac->align($aln);
- Function: Get/Set the L<Bio::Align::AlignI> object
- Returns : L<Bio::Align::AlignI> object
- Args : [optional] L<Bio::Align::AlignI>
- Comment : We could potentially add support for running directly on a file
- but we shall keep it simple
- See also: L<Bio::SimpleAlign>
-
-=cut
-
-
-=head2 tree
-
- Title : tree
- Usage : $slac->tree($tree, %params);
- Function: Get/Set the L<Bio::Tree::TreeI> object
- Returns : L<Bio::Tree::TreeI>
- Args : [optional] $tree => L<Bio::Tree::TreeI>,
- [optional] %parameters => hash of tree-specific parameters:
-
- Comment : We could potentially add support for running directly on a file
- but we shall keep it simple
- See also: L<Bio::Tree::Tree>
-
-=cut
-
-=head2 get_parameters
-
- Title : get_parameters
- Usage : my %params = $self->get_parameters();
- Function: returns the list of parameters as a hash
- Returns : associative array keyed on parameter names
- Args : none
-
-
-=cut
-
-=head2 set_parameter
-
- Title : set_parameter
- Usage : $slac->set_parameter($param,$val);
- Function: Sets a slac parameter, will be validated against
- the valid values as set in the %VALIDVALUES class variable.
- The checks can be ignored if one turns off param checks like this:
- $slac->no_param_checks(1)
- Returns : boolean if set was success, if verbose is set to -1
- then no warning will be reported
- Args : $param => name of the parameter
- $value => value to set the parameter to
- See also: L<no_param_checks()>
-
-=cut
-
-=head2 set_default_parameters
-
- Title : set_default_parameters
- Usage : $slac->set_default_parameters(0);
- Function: (Re)set the default parameters from the defaults
- (the first value in each array in the
- %VALIDVALUES class variable)
- Returns : none
- Args : boolean: keep existing parameter values
-
-
-=cut
-
-=head2 update_ordered_parameters
-
- Title : update_ordered_parameters
- Usage : $slac->update_ordered_parameters(0);
- Function: (Re)set the default parameters from the defaults
- (the first value in each array in the
- %VALIDVALUES class variable)
- Returns : none
- Args : boolean: keep existing parameter values
-
-
-=cut
-
-=head1 Bio::Tools::Run::WrapperBase methods
-
-=cut
-
-
-=head2 save_tempfiles
-
- Title : save_tempfiles
- Usage : $obj->save_tempfiles($newval)
- Function:
- Returns : value of save_tempfiles
- Args : newvalue (optional)
-
-
-=cut
-
-=head2 tempdir
-
- Title : tempdir
- Usage : my $tmpdir = $self->tempdir();
- Function: Retrieve a temporary directory name (which is created)
- Returns : string which is the name of the temporary directory
- Args : none
-
-
-=cut
-
-=head2 cleanup
-
- Title : cleanup
- Usage : $slac->cleanup();
- Function: Will cleanup the tempdir directory after a run
- Returns : none
- Args : none
-
-
-=cut
-
-=head2 io
-
- Title : io
- Usage : $obj->io($newval)
- Function: Gets a L<Bio::Root::IO> object
- Returns : L<Bio::Root::IO>
- Args : none
-
-
-=cut
-
-sub DESTROY {
- my $self= shift;
- unless ( $self->save_tempfiles ) {
- $self->cleanup();
- }
- $self->SUPER::DESTROY();
-}
-
1;
View
46 t/Hyphy.t
@@ -7,19 +7,21 @@ use strict;
BEGIN {
use Bio::Root::Test;
- test_begin(-tests => 8, -requires_module =>'IO::String');
+ test_begin(-tests => 10, -requires_module =>'IO::String');
use_ok('Bio::Tools::Run::Phylo::Hyphy::SLAC');
use_ok('Bio::Tools::Run::Phylo::Hyphy::FEL');
use_ok('Bio::Tools::Run::Phylo::Hyphy::REL');