This file is indexed.

/usr/share/perl5/Bio/Tools/Run/StandAloneBlastPlus/BlastMethods.pm is in libbio-perl-run-perl 1.6.9-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
# $Id$
#
# BioPerl module for Bio::Tools::Run::StandAloneBlastPlus::BlastMethods
#
# Please direct questions and support issues to <bioperl-l@bioperl.org>
#
# Cared for by Mark A. Jensen <maj -at- fortinbras -dot- us>
#
# Copyright Mark A. Jensen
#
# You may distribute this module under the same terms as perl itself

# POD documentation - main docs before the code

=head1 NAME

Bio::Tools::Run::StandAloneBlastPlus::BlastMethods - Provides BLAST methods to StandAloneBlastPlus

=head1 SYNOPSIS

 # create a factory:
 $fac = Bio::Tools::Run::StandAloneBlastPlus->new(
    -db_name => 'testdb'
 );
 # get your results
 $result = $fac->blastn( -query => 'query_seqs.fas',
                         -outfile => 'query.bls',
                         -method_args => [ '-num_alignments' => 10 ,

 $result = $fac->tblastx( -query => $an_alignment_object,
                          -outfile => 'query.bls',
                          -outformat => 7 );
 # do a bl2seq
 $fac->bl2seq( -method => 'blastp',
               -query => $seq_object_1,
               -subject => $seq_object_2 );

=head1 DESCRIPTION

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.

Other details:

=over

=item * The blast output file can be named explicitly:

 $result = $fac->blastn( -query => 'query_seqs.fas',
                         -outfile => 'query.bls' );

=item * The output format can be specified:

 $result = $fac->blastn( -query => 'query_seqs.fas',
                         -outfile => 'query.bls',
                         -outformat => 7 ); #tabular

=item * Additional arguments to the method can be specified:

 $result = $fac->blastn( -query => 'query_seqs.fas',
                         -outfile => 'query.bls',
                         -method_args => [ '-num_alignments' => 10 ,
                                           '-evalue' => 100 ]);

=item * To get the name of the blast output file, do 

 $file = $fac->blast_out;

=item * To clean up the temp files (you must do this explicitly):

 $fac->cleanup;

=back

=head2 bl2seq()

Running C<bl2seq> is similar, but both C<-query> and C<-subject> are
required, and the attached database is ignored. The blast method must
be specified explicitly with the C<-method> parameter:

 $fac->bl2seq( -method => 'blastp',
               -query => $seq_object_1,
               -subject => $seq_object_2 );

Other parameters ( C<-method_args>, C<-outfile>, and C<-outformat> ) are valid. 

=head2 Return values

The return value is always a L<Bio::Search::Result::BlastResult>
object on success, undef on failure.

=head1 SEE ALSO

L<Bio::Tools::Run::StandAloneBlastPlus>, L<Bio::Tools::Run::BlastPlus>

=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:

L<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 - Mark A. Jensen

Email maj -at- fortinbras -dot- us

Describe contact details here

=head1 CONTRIBUTORS

Additional contributors names and emails here

=head1 APPENDIX

The rest of the documentation details each of the object methods.
Internal methods are usually preceded with a _

=cut

# Let the code begin...

# note: providing methods directly to the namespace...
package Bio::Tools::Run::StandAloneBlastPlus;
use strict;
use warnings;

use Bio::SearchIO;
use lib '../../../..';
use Bio::Tools::Run::BlastPlus;
use File::Temp;
use File::Copy;
use File::Spec;
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, $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");
    }
    unless ($query) {
	$self->throw("Blast run: query data required, use -query");
    }
    unless ($outfile) { # create a tempfile name
	my $fh = File::Temp->new(TEMPLATE => 'BLOXXXXX',
				 DIR => $self->db_dir,
				 UNLINK => 0);
	$outfile = $fh->filename;
	$fh->close;
	$self->_register_temp_for_cleanup($outfile);
    }
    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;
    }
    # make db if necessary
    $self->make_db unless $self->check_db or $self->is_remote or $usr_args{'-subject'} or $usr_args{'-SUBJECT'}; # no db nec if this is bl2seq...
    $self->{_factory} = Bio::Tools::Run::BlastPlus->new( -command => $method );
    if (%usr_args) {
	my @avail_parms = $self->factory->available_parameters('all');
	while ( my( $key, $value ) = each %usr_args ) {
	    $key =~ s/^-//;
	    unless (grep /^$key$/, @avail_parms) {
		$self->throw("Blast run: parameter '$key' is not available for method '$method'");
	    }
	}
    }

    # remove a leading ./ on remote databases. Something adds that in the
    # factory, easier to remove here.
    my $db = $self->db_path;
    if ($self->is_remote) {
        $db =~ s#^\./##;
    }
    $blast_args{-db} = $db;
    $blast_args{-query} = $self->_fastize($query);
    $blast_args{-out} = $outfile;
    # user arg override
    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|psi|rps|rpst)?blast[npx]?/ && do { 
	    $ret = Bio::SearchIO->new(-file => $outfile);

	    $self->{_blastout} = $outfile;
	    $self->{_results} = $ret;
	    $ret = $ret->next_result;
	    last;
	};
	do {
	    1; # huh?
	};
    }
    
    return $ret;
}

=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 ]
	);

}

=head2 next_result()

 Title   : next_result
 Usage   : $result = $fac->next_result;
 Function: get the next BLAST result
 Returns : Bio::Search::Result::BlastResult object
 Args    : none

=cut

sub next_result() {
    my $self = shift;
    return unless $self->{_results};
    return $self->{_results}->next_result;
}

=head2 rewind_results()

 Title   : rewind_results
 Usage   : $fac->rewind_results;
 Function: rewind BLAST results
 Returns : true on success
 Args    : 

=cut

sub rewind_results {
    my $self = shift;
    return unless $self->blast_out;
    $self->{_results} = Bio::SearchIO->new( -file => $self->blast_out );
    return 1;
}


=head2 blast_out()

 Title   : blast_out
 Usage   : $file = $fac->blast_out
 Function: get the filename of the blast report file
 Returns : scalar string
 Args    : none

=cut

sub blast_out { shift->{_blastout} }

# =head2 _demodernize()

#  Title   : _demodernize
#  Usage   : 
#  Function: Ha! Wouldn't you like to know!
#  Returns : 
#  Args    : 

# =cut

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;