BioPerl-Run
view release on metacpan or search on metacpan
lib/Bio/Tools/Run/Phylo/Hyphy/BatchFile.pm view on Meta::CPAN
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);
( run in 0.997 second using v1.01-cache-2.11-cpan-39bf76dae61 )