[Bioperl-guts-l] [16533] bioperl-dev/branches/blastplus-dev-branch/lib/Bio/Tools/Run: bl2seq added, other tweaks
Mark Allen Jensen
maj at dev.open-bio.org
Fri Dec 18 22:01:32 EST 2009
Revision: 16533
Author: maj
Date: 2009-12-18 22:01:32 -0500 (Fri, 18 Dec 2009)
Log Message:
-----------
bl2seq added, other tweaks
Modified Paths:
--------------
bioperl-dev/branches/blastplus-dev-branch/lib/Bio/Tools/Run/StandAloneBlastPlus/BlastMethods.pm
bioperl-dev/branches/blastplus-dev-branch/lib/Bio/Tools/Run/StandAloneBlastPlus.pm
Modified: bioperl-dev/branches/blastplus-dev-branch/lib/Bio/Tools/Run/StandAloneBlastPlus/BlastMethods.pm
===================================================================
--- bioperl-dev/branches/blastplus-dev-branch/lib/Bio/Tools/Run/StandAloneBlastPlus/BlastMethods.pm 2009-12-18 22:46:13 UTC (rev 16532)
+++ bioperl-dev/branches/blastplus-dev-branch/lib/Bio/Tools/Run/StandAloneBlastPlus/BlastMethods.pm 2009-12-19 03:01:32 UTC (rev 16533)
@@ -22,8 +22,47 @@
=head1 DESCRIPTION
-This module provides the BLAST methods (blastn, blastp, psiblast, etc.) to the L<Bio::Tools::Run::StandAloneBlastPlus> object.
+This module provides the BLAST methods (blastn, blastp, psiblast,
+etc.) to the L<Bio::Tools::Run::StandAloneBlastPlus> object.
+=head1 USAGE
+
+This POD describes the use of BLAST methods against a
+L<Bio::Tools::Run::StandAloneBlastPlus> factory object. The object
+itself has extensive facilities for creating, formatting, and masking
+BLAST databases; please refer to
+L<Bio::Tools::Run::StandAloneBlastPlus> POD for these details
+
+Given a C<StandAloneBlastPlus> factory, such as
+
+ $fac = Bio::Tools::Run::StandAloneBlastPlus->new(
+ -db_name => 'testdb'
+ );
+
+you can run the desired BLAST method directly from the factory object,
+against the database currently attached to the factory (in the
+example, C<testdb>). C<-query> is a required argument:
+
+ $result = $fac->blastn( -query => 'query_seqs.fas' );
+
+Here, C<$result> is a L<Bio::Search::Result::BlastResult> object.
+
+The blast output file can be named explicitly:
+
+ $result = $fac->blastn( -query => 'query_seqs.fas',
+ -outfile => 'query.bls' );
+
+
+
+
+=head2 Return values
+
+
+
+=head1 SEE ALSO
+
+L<Bio::Tools::Run::StandAloneBlastPlus>, L<Bio::Tools::Run::BlastPlus>
+
=head1 FEEDBACK
=head2 Mailing Lists
@@ -82,20 +121,44 @@
use lib '../../../..';
use Bio::Tools::Run::BlastPlus;
use File::Temp;
+use File::Copy;
our @BlastMethods = qw( blastp blastn blastx tblastn tblastx
psiblast rpsblast rpstblastn );
+
+
+=head2 run()
+
+ Title : run
+ Usage :
+ Function: Query the attached database using a specified blast
+ method
+ Returns : Bio::Search::Result::BlastResult object
+ Args : key => value:
+ -method => $method [blastp|blastn|blastx|tblastx|tblastn|
+ rpsblast|psiblast|rpstblastn]
+ -query => $query_sequences (a fasta file name or BioPerl sequence
+ object or sequence collection object)
+ -outfile => $blast_report_file (optional: default creates a tempfile)
+ -outformat => $format_code (integer in [0..10], see blast+ docs)
+ -method_args => [ -key1 => $value1, ... ] (additional arguments
+ for the given method)
+
+=cut
+
sub run {
my $self = shift;
my @args = @_;
- my ($method, $query, $outfile, $method_args) = $self->_rearrange( [qw(
+ my ($method, $query, $outfile, $outformat, $method_args) = $self->_rearrange( [qw(
METHOD
QUERY
OUTFILE
+ OUTFORMAT
METHOD_ARGS
)], @args);
my $ret;
+ my (%blast_args, %usr_args);
unless ($method) {
$self->throw("Blast run: method not specified, use -method");
@@ -110,7 +173,13 @@
$fh->close;
$self->_register_temp_for_cleanup($outfile);
}
- my %usr_args;
+ if ($outformat) {
+ unless ($outformat =~ /^[0-9]{1,2}$/) {
+ $self->throw("Blast run: output format code should be integer 0-10");
+ }
+ $blast_args{'-outfmt'} = $outformat;
+ }
+
if ($method_args) {
$self->throw("Blast run: method arguments must be name => value pairs") unless !(@$method_args % 2);
%usr_args = @$method_args;
@@ -129,7 +198,6 @@
}
}
- my %blast_args;
$blast_args{-db} = $self->db;
$blast_args{-query} = $self->_fastize($query);
$blast_args{-out} = $outfile;
@@ -137,17 +205,27 @@
if (%usr_args) {
$blast_args{$_} = $usr_args{$_} for keys %usr_args;
}
-
+ # override for bl2seq;
+ if ($blast_args{'-db'} && $blast_args{'-subject'}) {
+ delete $blast_args{'-db'};
+ }
$self->factory->set_parameters( %blast_args );
$self->factory->no_throw_on_crash( $self->no_throw_on_crash );
my $status = $self->_run;
return $status unless $status;
+ # kludge to demodernize the bl2seq output
+ if ($blast_args{'-subject'}) {
+ unless (_demodernize($outfile)) {
+ $self->throw("Ack! demodernization failed!");
+ }
+ }
+
# if here, success
for ($method) {
m/^[t]?blast[npx]/ && do {
- $ret = Bio::SearchIO->new(-file => $outfile,
- -format => 'blast');
+ $ret = Bio::SearchIO->new(-file => $outfile);
+
$self->{_blastout} = $outfile;
$ret = $ret->next_result;
last;
@@ -161,4 +239,69 @@
}
+
+=head2 bl2seq()
+
+ Title : bl2seq
+ Usage :
+ Function: emulate bl2seq using blast+ programs
+ Returns : Bio::Search::Result::BlastResult object
+ Args : key => value
+ -method => $blast_method [blastn|blastp|blastx|
+ tblastn|tblastx]
+ -query => $query (fasta file or BioPerl sequence object
+ -subject => $subject (fasta file or BioPerl sequence object)
+ -outfile => $blast_report_file
+ -method_args => [ $key1 => $value1, ... ] (additional method
+ parameters)
+
+=cut
+
+sub bl2seq {
+ my $self = shift;
+ my @args = @_;
+ my ($method, $query, $subject, $outfile, $outformat, $method_args) = $self->_rearrange( [qw(
+ METHOD
+ QUERY
+ SUBJECT
+ OUTFILE
+ OUTFORMAT
+ METHOD_ARGS
+ )], @args);
+
+ unless ($method) {
+ $self->throw("bl2seq: blast method not specified, use -method");
+ }
+ unless ($query) {
+ $self->throw("bl2seq: query data required, use -query");
+ }
+ unless ($subject) {
+ $self->throw("bl2seq: subject data required, use -subject");
+ }
+ $subject = $self->_fastize($subject);
+
+ my @run_args;
+ if ($method_args) {
+ @run_args = @$method_args;
+ }
+ return $self->run( -method => $method,
+ -query => $query,
+ -outfile => $outfile,
+ -outformat => $outformat,
+ -method_args => [ @run_args, '-subject' => $subject ]
+ );
+
+}
+
+sub _demodernize {
+ my $file = shift;
+ my $tf = File::Temp->new();
+ open (my $f, $file);
+ while (<$f>) {
+ s/^Subject=\s+/>/;
+ print $tf $_;
+ }
+ $tf->close;
+ copy($tf->filename, $file);
+}
1;
Modified: bioperl-dev/branches/blastplus-dev-branch/lib/Bio/Tools/Run/StandAloneBlastPlus.pm
===================================================================
--- bioperl-dev/branches/blastplus-dev-branch/lib/Bio/Tools/Run/StandAloneBlastPlus.pm 2009-12-18 22:46:13 UTC (rev 16532)
+++ bioperl-dev/branches/blastplus-dev-branch/lib/Bio/Tools/Run/StandAloneBlastPlus.pm 2009-12-19 03:01:32 UTC (rev 16533)
@@ -321,7 +321,8 @@
=item
-You can check whether a given basename points to a properly formatted BLAST database by doing
+You can check whether a given basename points to a properly formatted
+BLAST database by doing
$is_good = $fac->check_db('putative_db');
@@ -1110,6 +1111,9 @@
elsif ($data->isa('Bio::Align::AlignI')) {
$fasio->write_seq($_) for $data->each_seq;
}
+ elsif ($data->isa('Bio::Seq') || $data->isa('Bio::PrimarySeq')) {
+ $fasio->write_seq($data);
+ }
else {
$self->throw("Can't handle sequence container object ".
"of type '".ref($data)."'");
@@ -1210,15 +1214,15 @@
my $method = $AUTOLOAD;
$method =~ s/.*:://;
my @ret;
+ if (grep /^$method$/, @Bio::Tools::Run::StandAloneBlastPlus::BlastMethods) {
+ return $self->run( -method => $method, @args );
+ }
if ($self->factory and $self->factory->can($method)) { # factory method
return $self->factory->$method(@args);
}
if ($self->db_info and grep /^$method$/, keys %{$self->db_info}) {
return $self->db_info->{$method};
}
- if (grep /^$method$/, @Bio::Tools::Run::StandAloneBlastPlus::BlastMethods) {
- return $self->run( -method => $method, @args );
- }
# else, fail
$self->throw("Can't locate method '$method' in class ".ref($self));
More information about the Bioperl-guts-l
mailing list