BioPerl-Run
view release on metacpan or search on metacpan
lib/Bio/Tools/Run/Primer3.pm view on Meta::CPAN
}
=head2 run()
Title : run()
Usage : $primer3->run();
Function: Run the primer3 program with the arguments that you have supplied.
Returns : A Bio::Tools::Primer3 object containing the results.
Args : None.
Note : See the Bio::Tools::Primer3 documentation for those functions.
=cut
sub run {
my($self) = @_;
my $executable = $self->executable;
my $input = $self->{'primer3_input'};
unless ($executable && -e $executable) {
$self->throw("Executable was not found. Do not know where primer3 is!") if !$executable;
$self->throw("$executable was not found. Do not know where primer3 is!");
exit(-1);
}
# note that I write this to a temp file because we need both read
# and write access to primer3, therefore,
# we can't use a simple pipe.
if ($self->{'verbose'}) {print STDERR "TRYING\n",
join "\n", @{$self->{'primer3_input'}}, "=\n"}
# make a temporary file and print the instructions to it.
my ($temphandle, $tempfile) = $self->io->tempfile;
print $temphandle join "\n", @{$self->{'primer3_input'}}, "=\n";
close($temphandle);
my $executable_command = $executable;
if ( $executable =~ m{^[^\'\"]+(.+)[^\'\"]+$} ) {
$executable_command = "\"$executable\" < \"$tempfile\"|";
}
open (RESULTS, $executable_command) || $self->throw("Can't open RESULTS");
if ($self->{'_outfilename'}) {
# I can't figure out how to use either of these to write the results out.
# neither work, what am I doing wrong or missing in the docs?
# $self->{output}=$self->_initialize_io(-file=>$self->{'outfile'});
# $self->{output}=$self->io;
# OK, for now, I will just do it myself, because I need this to
# check the parser :)
open (OUT, ">".$self->{'_outfilename'}) ||
$self->throw("Can't open ".$self->{'_outfilename'}." for writing");
}
my @results;
while (<RESULTS>) {
if ($self->{'_outfilename'}) {
# this should work, but isn't
#$self->{output}->_print($_);
print OUT $_;
}
chomp;
next if( $_ eq '='); # skip over bolderio record terminator
my ($return, $value) = split('=',$_);
$self->{'results'}->{$return} = $value;
}
close RESULTS;
# close the output file
if ($self->{'_outfilename'}) {
close OUT;
}
$self->cleanup;
# convert the results to individual results
$self->{results_obj} = Bio::Tools::Primer3->new;
$self->{results_obj}->_set_variable('results', $self->{results});
$self->{results_obj}->_set_variable('seqobject', $self->{seqobject});
# Bio::Tools::Primer3::_separate needs a hash of the primer3 arguments,
# with the arg as the key and the value as the value (surprise!).
my %input_hash = map {split '='} @{$self->{'primer3_input'}};
$self->{results_obj}->_set_variable('input_options', \%input_hash);
$self->{results_separated}= $self->{results_obj}->_separate();
return $self->{results_obj};
}
=head2 arguments()
Title : arguments()
Usage : $hashref = $primer3->arguments();
Function: Describes the options that you can set through Bio::Tools::Run::Primer3,
with a brief (one line) description of what they are and their
default values
Returns : A string (if an argument is supplied) or a reference to a hash.
Args : If supplied with an argument will return a string of its
description.
If no arguments are supplied, will return all the arguments as a
reference to a hash
Notes : Much of this is taken from the primer3 README file, and you should
read that file for a more detailed description.
=cut
sub arguments {
my ($self, $required) = @_;
unless ($self->{'input_options'}) {$self->_input_args}
if ($required) {return ${$self->{'input_options'}}{'$required'}}
else {return $self->{'input_options'}}
}
=head2 version
Title : version
Usage : $v = $prog->version();
Function: Determine the version number of the program
Example :
Returns : float or undef
Args : none
=cut
sub version {
( run in 0.966 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )