~ubuntu-branches/ubuntu/raring/bioperl/raring

« back to all changes in this revision

Viewing changes to Bio/Tools/Run/StandAloneBlast.pm

  • Committer: Bazaar Package Importer
  • Author(s): Charles Plessy
  • Date: 2008-03-18 14:44:57 UTC
  • mfrom: (4 hardy)
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: james.westby@ubuntu.com-20080318144457-1jjoztrvqwf0gruk
* debian/control:
  - Removed MIA Matt Hope (dopey) from the Uploaders field.
    Thank you for your work, Matt. I hope you are doing well.
  - Downgraded some recommended package to the 'Suggests' priority,
    according to the following discussion on Upstream's mail list.
    http://bioperl.org/pipermail/bioperl-l/2008-March/027379.html
    (Closes: #448890)
* debian/copyright converted to machine-readable format.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# $Id: StandAloneBlast.pm,v 1.36 2003/10/28 22:11:50 jason Exp $
2
 
#
3
 
# BioPerl module for Bio::Tools::StandAloneBlast
4
 
#
5
 
# Cared for by Peter Schattner
 
1
# $Id: StandAloneBlast.pm,v 1.63.4.1 2006/10/02 23:10:36 sendu Exp $
 
2
#
 
3
# BioPerl module for Bio::Tools::Run::StandAloneBlast
6
4
#
7
5
# Copyright Peter Schattner
8
6
#
12
10
 
13
11
=head1 NAME
14
12
 
15
 
Bio::Tools::Run::StandAloneBlast - Object for the local execution of the
16
 
NCBI Blast program suite (blastall, blastpgp, bl2seq). There is experimental
17
 
support for WU-Blast.
 
13
Bio::Tools::Run::StandAloneBlast - Object for the local execution 
 
14
of the NCBI BLAST program suite (blastall, blastpgp, bl2seq). 
 
15
There is experimental support for WU-Blast and NCBI rpsblast.
18
16
 
19
17
=head1 SYNOPSIS
20
18
 
21
19
 # Local-blast "factory object" creation and blast-parameter
22
20
 # initialization:
23
21
 
24
 
 @params = ('database' => 'swissprot','outfile' => 'blast1.out', 
25
 
            '_READMETHOD' => 'Blast');
26
 
 
 
22
 @params = (-database => 'swissprot',-outfile => 'blast1.out');
27
23
 $factory = Bio::Tools::Run::StandAloneBlast->new(@params);
28
24
 
29
25
 # Blast a sequence against a database:
30
26
 
31
 
 $str = Bio::SeqIO->new(-file=>'t/amino.fa' , '-format' => 'Fasta' );
 
27
 $str = Bio::SeqIO->new(-file=>'t/amino.fa', -format => 'Fasta');
32
28
 $input = $str->next_seq();
33
29
 $input2 = $str->next_seq();
34
30
 $blast_report = $factory->blastall($input);
42
38
 
43
39
 # Use blast to align 2 sequences against each other:
44
40
 
45
 
 $factory = Bio::Tools::Run::StandAloneBlast->new('outfile' => 'bl2seq.out');
 
41
 $factory = Bio::Tools::Run::StandAloneBlast->new(-outfile => 'bl2seq.out');
46
42
 $factory->bl2seq($input, $input2);
47
43
 
48
 
  #experimental support for WU-Blast 2.0
49
 
  my $factory= Bio::Tools::Run::StandAloneBlast->new('program'=>"wublastp",
50
 
                                                     'database'=>"swissprot",
51
 
                                                     'E'=>1e-20); 
52
 
  my $blast_report = $factory->wublast($seq);
53
 
 
54
 
 # Various additional options and input formats are available.  See
55
 
 # the DESCRIPTION section for details.
 
44
 # Experimental support for WU-Blast 2.0
 
45
 
 
46
 my $factory = Bio::Tools::Run::StandAloneBlast->new(-program =>"wublastp",
 
47
                                                     -database =>"swissprot",
 
48
                                                     -e => 1e-20); 
 
49
 my $blast_report = $factory->wublast($seq);
 
50
 
 
51
 # Experimental support for NCBI rpsblast
 
52
 
 
53
 my $factory = Bio::Tools::Run::StandAloneBlast->new(-db => 'CDD/Cog', 
 
54
                                                     -expect => 0.001);
 
55
 $factory->F('T'); # turn on SEG filtering of query sequence
 
56
 my $blast_report = $factory->rpsblast($seq);
 
57
 
 
58
 # Various additional options and input formats are available,
 
59
 # see the DESCRIPTION section for details.
56
60
 
57
61
=head1 DESCRIPTION
58
62
 
62
66
BLAST, please see the BLAST documentation which accompanies the BLAST
63
67
distribution. BLAST is available from ftp://ncbi.nlm.nih.gov/blast/.
64
68
 
65
 
(A source of confusion in documenting a BLAST interface is that the
 
69
A source of confusion in documenting a BLAST interface is that the
66
70
term "program" is used in - at least - three different ways in the
67
71
BLAST documentation.  In this DESCRIPTION, "program" will refer to the
68
 
BLAST routine set by BLAST's C<-p> parameter that can be set to blastn,
 
72
BLAST routine set by the BLAST C<-p> parameter that can be set to blastn,
69
73
blastp, tblastx etc.  We will use the term Blast "executable" to refer
70
74
to the various different executable files that may be called - ie
71
75
blastall, blastpgp or bl2seq.  In addition, there are several BLAST
72
 
capabilities (which are also referred to as "programs") and are
 
76
capabilities, which are also referred to as "programs", and are
73
77
implemented by using specific combinations of BLAST executables,
74
78
programs and parameters.  They will be referred by their specific
75
 
names - eg PSIBLAST and PHIBLAST. )
76
 
 
77
 
StandAloneBlast has been tested so far only under Linux. I expect
78
 
that it should also work under other Unix systems. However, since the
79
 
module is implemented using (unix) system calls, modification may be
80
 
necessary before StandAloneBlast would work under non-Unix
81
 
operating systems (eg Windows, MacOS).  Before running
82
 
StandAloneBlast it is necessary: to install BLAST on your system,
83
 
to edit set the environmental variable $BLASTDIR or your $PATH
84
 
variable to point to the BLAST directory, and to ensure that users
85
 
have execute privileges for the BLAST program.  If the databases
86
 
which will be searched by BLAST are located in the data subdirectory
87
 
of the blast program directory (the default installation location),
88
 
StandAloneBlast will find them; however, if the database files are
89
 
located in any other location, environmental variable $BLASTDATADIR
90
 
will need to be set to point to that directory.
 
79
names - eg PSIBLAST and PHIBLAST.
 
80
 
 
81
Before running StandAloneBlast it is necessary: to install BLAST 
 
82
on your system, to edit set the environmental variable $BLASTDIR 
 
83
or your $PATH variable to point to the BLAST directory, and to 
 
84
ensure that users have execute privileges for the BLAST program.  
 
85
 
 
86
If the databases which will be searched by BLAST are located in the 
 
87
data subdirectory of the blast program directory (the default 
 
88
installation location), StandAloneBlast will find them; however, 
 
89
if the database files are located in any other location, environmental 
 
90
variable $BLASTDATADIR will need to be set to point to that directory.
91
91
 
92
92
The use of the StandAloneBlast module is as follows: Initially, a
93
93
local blast "factory object" is created. The constructor may be passed
94
94
an optional array of (non-default) parameters to be used by the
95
95
factory, eg:
96
96
 
97
 
 @params = ('program' => 'blastn', 'database' => 'ecoli.nt');
 
97
 @params = (-program => 'blastn', -database => 'ecoli.nt');
98
98
 $factory = Bio::Tools::Run::StandAloneBlast->new(@params);
99
99
 
100
100
Any parameters not explicitly set will remain as the defaults of the
109
109
parameter/switch being set/read is valid.  Except where specifically
110
110
noted, StandAloneBlast uses the same single-letter, case-sensitive
111
111
parameter names as the actual blast program.  Currently no checks are
112
 
included to verify that parameters are of the proper type (eg string
 
112
included to verify that parameters are of the proper type (e.g. string
113
113
or numeric) or that their values are within the proper range.
114
114
 
115
115
As an example, to change the value of the Blast parameter 'e' ('e' is
116
116
the parameter for expectation-value cutoff) 
117
117
 
118
 
 $expectvalue = 0.01;
119
 
 $factory->e($expectvalue);
 
118
  $expectvalue = 0.01;
 
119
  $factory->e($expectvalue);
120
120
 
121
121
Note that for improved script readibility one can modify the name of
122
122
the BLAST parameters as desired as long as the initial letter (and
123
 
case) of the parameter are preserved, eg
124
 
$factory-E<gt>expectvalue($expectvalue); Unfortunately, some of the BLAST
125
 
parameters are not the single letter one might expect (eg "iteration
126
 
round" in blastpgp is 'j'). Again one can check by using (eg)
127
 
 
128
 
 > blastpgp - .
 
123
case) of the parameter are preserved, e.g.:
 
124
 
 
125
  $factory->expectvalue($expectvalue);
 
126
 
 
127
Unfortunately, some of the BLAST parameters are not the single 
 
128
letter one might expect (eg "iteration round" in blastpgp is 'j'). 
 
129
Again one can check by using, for example:
 
130
 
 
131
  > blastpgp - .
129
132
 
130
133
Once the factory has been created and the appropriate parameters set,
131
 
 one can call one of the supported blast executables.  The input
132
 
 sequence(s) to these executables may be fasta file(s) as described in
133
 
 the BLAST documentation.
 
134
one can call one of the supported blast executables.  The input
 
135
sequence(s) to these executables may be fasta file(s) as described in
 
136
the BLAST documentation.
134
137
 
135
 
 $inputfilename = 't/testquery.fa';
136
 
 $blast_report = $factory->blastall($inputfilename);
 
138
  $inputfilename = 't/testquery.fa';
 
139
  $blast_report = $factory->blastall($inputfilename);
137
140
 
138
141
In addition, sequence input may be in the form of either a Bio::Seq
139
 
 object or or an array of Bio::Seq objects, eg
 
142
object or or an array of Bio::Seq objects, e.g.:
140
143
 
141
 
 $input = Bio::Seq->new(-id=>"test query",-seq=>"ACTACCCTTTAAATCAGTGGGGG");
142
 
 $blast_report = $factory->blastall($input);
 
144
  $input = Bio::Seq->new(-id => "test query",
 
145
                         -seq => "ACTACCCTTTAAATCAGTGGGGG");
 
146
  $blast_report = $factory->blastall($input);
143
147
 
144
148
For blastall and non-psiblast blastpgp runs, report object is either a
145
 
BPlite.pm or Bio::SearchIO object, selected by the user with the
146
 
parameter _READMETHOD.  (The leading underscore is needed to
 
149
L<Bio::Tools::BPlite> or L<Bio::SearchIO> object, selected by the user 
 
150
with the parameter _READMETHOD.  The leading underscore is needed to
147
151
distinguish this option from options which are passed to the BLAST
148
 
executable.) The default parser is Bio::SearchIO::blast.  For
149
 
(multiple iteration) psiblast and bl2seq runs the report is
150
 
automatically parsed by the BPpsilite.pm and BPbl2seq.pm parsers
151
 
respectively, since neither Blast.pm nor BPlite can parse these
152
 
reports. In any case, the "raw" blast report is also available. The
153
 
filename is set by the in the 'outfile' parameter and has the default
154
 
value of "blastreport.out".
 
152
executable. The default parser is Bio::SearchIO::blast.  If BPlite
 
153
method is selected, L<Bio::Tools::BPlite> objects will be returned for
 
154
standard blast and L<Bio::Tools::BPpsilite> for a multiple-iteration
 
155
blasts, and a L<Bio::Tools::BPbl2seq> for bl2seq.  In any case, the "raw"
 
156
blast report is also available. The filename is set by the in the
 
157
'outfile' parameter and has the default value of "blastreport.out".
 
158
The BPlite method is only provided to support legacy code since
 
159
the BPlite modules are no longer maintained - do not use BPlite
 
160
since these modules will be removed eventually.
155
161
 
156
 
For psiblast execution in BLAST's "jumpstart" mode, the program must
 
162
For psiblast execution in the BLAST "jumpstart" mode, the program must
157
163
be passed (in addition to the query sequence itself) an alignment
158
164
containing the query sequence (in the form of a SimpleAlign object) as
159
165
well as a "mask" specifying at what residues position-specific scoring
164
170
locations where (PSSMs) are to be used and a "0" at all other
165
171
locations. So for example:
166
172
 
167
 
 $str = Bio::AlignIO->new(-file=> "cysprot.msf", '-format' => 'msf'  );
168
 
 $aln = $str->next_aln();
169
 
 $len = $aln->length_aln();
170
 
 $mask =   '1' x $len;  # simple case where PSSM's to be used at all residues
171
 
 $report = $factory->blastpgp("cysprot1.fa", $aln, $mask);
 
173
  $str = Bio::AlignIO->new(-file => "cysprot.msf", 
 
174
                           -format => 'msf');
 
175
  $aln = $str->next_aln();
 
176
  $len = $aln->length_aln();
 
177
  $mask = '1' x $len;
 
178
  # simple case where PSSM's to be used at all residues
 
179
  $report = $factory->blastpgp("cysprot1.fa", $aln, $mask);
172
180
 
173
181
For bl2seq execution, StandAloneBlast.pm can be combined with
174
182
AlignIO.pm to directly produce a SimpleAlign object from the alignment
175
183
of the two sequences produced by bl2seq as in:
176
184
 
177
 
 #Get 2 sequences
178
 
 $str = Bio::SeqIO->new(-file=>'t/amino.fa' , '-format' => 'Fasta', );
179
 
 my $seq3 = $str->next_seq();
180
 
 my $seq4 = $str->next_seq();
181
 
 
182
 
 # Run bl2seq on them
183
 
 $factory = Bio::Tools::Run::StandAloneBlast->new('outfile' => 'bl2seq.out');
184
 
 my $bl2seq_report = $factory->bl2seq($seq3, $seq4);
185
 
 
186
 
 # Use AlignIO.pm to create a SimpleAlign object from the bl2seq report
187
 
 $str = Bio::AlignIO->new(-file=> 'bl2seq.out','-format' => 'bl2seq');
188
 
 $aln = $str->next_aln();
 
185
  # Get 2 sequences
 
186
  $str = Bio::SeqIO->new(-file=>'t/amino.fa' , -format => 'Fasta');
 
187
  my $seq3 = $str->next_seq();
 
188
  my $seq4 = $str->next_seq();
 
189
 
 
190
  # Run bl2seq on them
 
191
  $factory = Bio::Tools::Run::StandAloneBlast->new(-program => 'blastp',
 
192
                                                   -outfile => 'bl2seq.out');
 
193
  my $bl2seq_report = $factory->bl2seq($seq3, $seq4);
 
194
 
 
195
  # Use AlignIO.pm to create a SimpleAlign object from the bl2seq report
 
196
  $str = Bio::AlignIO->new(-file=> 'bl2seq.out',-format => 'bl2seq');
 
197
  $aln = $str->next_aln();
189
198
 
190
199
For more examples of syntax and use of Blast.pm, the user is
191
200
encouraged to run the scripts standaloneblast.pl in the bioperl
192
 
/examples directory and StandAloneBlast.t in the bioperl /t directory.
193
 
 
194
 
Note: There is a similar (but older) perl object interface offered by
195
 
nhgri. The nhgri module only supports blastall and does not support
196
 
blastpgp, psiblast, phiblast, bl2seq etc.  This module can be found at
197
 
http://genome.nhgri.nih.gov/blastall/.
198
 
 
199
 
=head1 DEVELOPERS NOTES
200
 
 
201
 
B<STILL TO BE WRITTEN>
202
 
 
203
 
Note: This module is still under development.  If you would like that a
204
 
specific BLAST feature be added to this perl interface, let me know.
 
201
examples/tools directory and StandAloneBlast.t in the bioperl t/ 
 
202
directory.
205
203
 
206
204
=head1 FEEDBACK
207
205
 
211
209
Bioperl modules. Send your comments and suggestions preferably to one
212
210
of the Bioperl mailing lists.  Your participation is much appreciated.
213
211
 
214
 
  bioperl-l@bioperl.org               - General discussion
215
 
  http://bio.perl.org/MailList.html   - About the mailing lists
 
212
  bioperl-l@bioperl.org                  - General discussion
 
213
  http://bioperl.org/wiki/Mailing_lists  - About the mailing lists
216
214
 
217
215
=head2 Reporting Bugs
218
216
 
219
217
Report bugs to the Bioperl bug tracking system to help us keep track
220
 
the bugs and their resolution.  Bug reports can be submitted via email
221
 
or the web:
 
218
the bugs and their resolution.  Bug reports can be submitted via 
 
219
the web:
222
220
 
223
 
  bioperl-bugs@bio.perl.org
224
 
  http://bio.perl.org/bioperl-bugs/
 
221
  http://bugzilla.open-bio.org/
225
222
 
226
223
=head1 AUTHOR -  Peter Schattner
227
224
 
228
 
Email schattner@alum.mit.edu
 
225
Email schattner at alum.mit.edu
 
226
 
 
227
=head1 MAINTAINER - Torsten Seemann
 
228
 
 
229
Email torsten at infotech.monash.edu.au
229
230
 
230
231
=head1 APPENDIX
231
232
 
236
237
 
237
238
package Bio::Tools::Run::StandAloneBlast;
238
239
 
239
 
use vars qw($AUTOLOAD @ISA $PROGRAMDIR  $DATADIR $BLASTTYPE
240
 
            @BLASTALL_PARAMS @BLASTPGP_PARAMS @WUBLAST_PARAMS @WUBLAST_SWITCH
241
 
            @BL2SEQ_PARAMS @OTHER_PARAMS %OK_FIELD 
242
 
            $DEFAULTREADMETHOD
 
240
use vars qw($AUTOLOAD $PROGRAMDIR  $DATADIR $BLASTTYPE
 
241
            @BLASTALL_PARAMS @BLASTPGP_PARAMS @WUBLAST_PARAMS 
 
242
                 @WUBLAST_SWITCH @RPSBLAST_PARAMS @BL2SEQ_PARAMS 
 
243
       @OTHER_PARAMS %OK_FIELD $DEFAULTREADMETHOD
243
244
            );
 
245
                 
244
246
use strict;
245
 
use Bio::Root::Root;
 
247
 
246
248
use Bio::Root::IO;
247
249
use Bio::Seq;
248
250
use Bio::SeqIO;
249
251
use Bio::Tools::BPbl2seq;
250
252
use Bio::Tools::BPpsilite;
251
253
use Bio::SearchIO;
252
 
use Bio::Tools::Run::WrapperBase;
253
 
use Bio::Factory::ApplicationFactoryI;
254
 
 
255
 
BEGIN {      
256
 
 
257
 
     @BLASTALL_PARAMS = qw( p d i e m o F G E X I q r v b f g Q
258
 
                            D a O J M W z K L Y S T l U y Z);
259
 
     @BLASTPGP_PARAMS = qw(d i A f e m o y P F G E X N g S H a I h c
260
 
                           j J Z O M v b C R W z K L Y p k T Q B l U);
261
 
     @BL2SEQ_PARAMS = qw(i j p g o d a G E X W M q r F e S T m);
262
 
     $DEFAULTREADMETHOD = 'BLAST';
263
 
     $BLASTTYPE = 'ncbi';
264
 
     @WUBLAST_PARAMS = qw( E S E2 S2 W T X M Y Z L K H V  B
265
 
                          matrix Q R filter wordmask filter maskextra 
266
 
                          hitdist wink ctxfactor gapE gapS gapE2 gapS2 gapW gapX olf golf 
267
 
                          olmax golmax gapdecayrate topcomboN topcomboE sumstatsmethod 
268
 
                          hspsepqmax hspsepsmax gapsepqmax gapsepsmax altscore hspmax gspmax 
269
 
                          qoffset nwstart nwlen qrecmin qrecmax 
270
 
                          dbrecmin dbrecmax vdbdescmax dbchunks sort_by_pvalue 
271
 
                          cpus putenv getenv progress o database input);
272
 
    @WUBLAST_SWITCH = qw(kap sump poissonp lcfilter lcmask echofilter stats nogap gapall pingpong 
273
 
                         nosegs postsw span2 span1 span prune consistency 
274
 
                         links ucdb gi noseqs qtype qres sort_by_pvalue sort_by_count 
275
 
                         sort_by_highscore sort_by_totalscore sort_by_subjectlength
276
 
                         mmio nonnegok novalidctxok shortqueryok notes warnings errors endputenv 
277
 
                         getenv endgetenv abortonerror abortonfatal); 
278
 
 
279
 
# Non BLAST parameters start with underscore to differentiate them
280
 
# from BLAST parameters
281
 
     @OTHER_PARAMS = qw(_READMETHOD);
282
 
 
283
 
# _READMETHOD = 'BPlite' (default) or 'Blast'
284
 
# my @other_switches = qw(QUIET);
285
 
 
286
 
 
287
 
# Authorize attribute fields
288
 
     foreach my $attr (@BLASTALL_PARAMS,  @BLASTPGP_PARAMS, 
289
 
                       @BL2SEQ_PARAMS, @OTHER_PARAMS ,@WUBLAST_PARAMS, @WUBLAST_SWITCH )
 
254
use File::Spec;
 
255
 
 
256
use base qw(Bio::Root::Root Bio::Tools::Run::WrapperBase Bio::Factory::ApplicationFactoryI);
 
257
 
 
258
BEGIN {
 
259
        @BLASTALL_PARAMS = qw(A B C D E F G I J K L M O P Q R S T U V W X Y Z a b d e f g i l m n o p q r s t v w y z);
 
260
        @BLASTPGP_PARAMS = qw(A B C E F G H I J K L M N O P Q R S T U W X Y Z a b c d e f h i j k l m o p q s t u v y z);
 
261
        @RPSBLAST_PARAMS = qw(F I J L N O P T U V X Y Z a b d e i l m o p v y z);
 
262
        @BL2SEQ_PARAMS = qw(A D E F G I J M S T U V W X Y a d e g i j m o p q r t);
 
263
        $DEFAULTREADMETHOD = 'BLAST';
 
264
        $BLASTTYPE = 'ncbi';
 
265
        @WUBLAST_PARAMS = 
 
266
          qw( E S E2 S2 W T X M Y Z L K H V  B
 
267
     matrix Q R filter wordmask filter maskextra 
 
268
     hitdist wink ctxfactor gapE gapS gapE2 gapS2 gapW gapX olf golf 
 
269
     olmax golmax gapdecayrate topcomboN topcomboE sumstatsmethod 
 
270
     hspsepqmax hspsepsmax gapsepqmax gapsepsmax altscore hspmax gspmax 
 
271
     qoffset nwstart nwlen qrecmin qrecmax 
 
272
     dbrecmin dbrecmax vdbdescmax dbchunks sort_by_pvalue 
 
273
     cpus putenv getenv progress o database input);
 
274
        @WUBLAST_SWITCH = 
 
275
     qw(kap sump poissonp lcfilter lcmask echofilter stats nogap 
 
276
     gapall pingpong 
 
277
     nosegs postsw span2 span1 span prune consistency 
 
278
     links ucdb gi noseqs qtype qres sort_by_pvalue sort_by_count 
 
279
     sort_by_highscore sort_by_totalscore sort_by_subjectlength
 
280
     mmio nonnegok novalidctxok shortqueryok notes warnings 
 
281
     errors endputenv 
 
282
     getenv endgetenv abortonerror abortonfatal); 
 
283
 
 
284
        # Non BLAST parameters start with underscore to differentiate them
 
285
        # from BLAST parameters
 
286
        @OTHER_PARAMS = qw(_READMETHOD);
 
287
 
 
288
        # my @other_switches = qw(QUIET);
 
289
 
 
290
        # Authorize attribute fields
 
291
        foreach my $attr (@BLASTALL_PARAMS, @BLASTPGP_PARAMS, @RPSBLAST_PARAMS,
 
292
                                                        @BL2SEQ_PARAMS, @OTHER_PARAMS ,@WUBLAST_PARAMS, 
 
293
                     @WUBLAST_SWITCH )
290
294
     { $OK_FIELD{$attr}++; }
291
295
 
292
 
# You will need to enable Blast to find the Blast program. This can be done
293
 
# in (at least) two different ways:
294
 
#  1. define an environmental variable blastDIR:
295
 
#       export BLASTDIR=/home/peter/blast   or
296
 
#  2. include a definition of an environmental variable BLASTDIR in every script that will
297
 
#     use StandAloneBlast.pm.
298
 
#       BEGIN {$ENV{BLASTDIR} = '/home/peter/blast/'; }
299
 
     $PROGRAMDIR = $BLASTTYPE eq 'ncbi' ? $ENV{'BLASTDIR'}: $ENV{'WUBLASTIDR'};
300
 
     
301
 
# If local BLAST databases are not stored in the standard
302
 
# /data directory, the variable BLASTDATADIR will need to be set explicitly 
303
 
     $DATADIR =  $ENV{'BLASTDATADIR'} || $ENV{'BLASTDB'} || '';
 
296
        # You will need to enable Blast to find the Blast program.  
 
297
        # This can be done in at least two different ways:
 
298
        #  1. define an environmental variable blastDIR:
 
299
        #       export BLASTDIR=/home/peter/blast   or
 
300
        #  2. include a definition of an environmental variable 
 
301
        # BLASTDIR in every script that will use StandAloneBlast.pm.
 
302
 
 
303
        $PROGRAMDIR = $BLASTTYPE eq 'ncbi' ? $ENV{'BLASTDIR'}: $ENV{'WUBLASTDIR'};
 
304
 
 
305
        # If local BLAST databases are not stored in the standard
 
306
        # /data directory, the variable BLASTDATADIR will need to be 
 
307
        # set explicitly 
 
308
        $DATADIR =  $ENV{'BLASTDATADIR'} || $ENV{'BLASTDB'} || '';
304
309
}
305
310
 
306
 
@ISA = qw(Bio::Root::Root 
307
 
          Bio::Tools::Run::WrapperBase 
308
 
          Bio::Factory::ApplicationFactoryI);
309
311
 
310
312
=head1 BLAST parameters
311
313
 
324
326
        The database specified must first be formatted with formatdb.
325
327
        Multiple database names (bracketed by quotations) will be accepted.
326
328
        An example would be -d "nr est"
327
 
  -i  Query File [File In]   Set by StandAloneBlast.pm from script.
 
329
   -i  Query File [File In]   Set by StandAloneBlast.pm from script.
328
330
    default = stdin. The query should be in FASTA format.  If multiple FASTA entries are in the input
329
331
        file, all queries will be searched.
330
332
  -e  Expectation value (E) [Real] default = 10.0
342
344
  -B  Multiple alignment file for PSI-BLAST "jump start mode"  Optional
343
345
  -Q  Output File for PSI-BLAST Matrix in ASCII [File Out]  Optional
344
346
 
 
347
=head2 E<lt>rpsblastE<gt>
 
348
 
 
349
  -d  Database [String] default = (none - you must specify a database)
 
350
        The database specified must first be formatted with formatdb.
 
351
        Multiple database names (bracketed by quotations) will be accepted.
 
352
        An example would be -d "Cog Smart"
 
353
   -i  Query File [File In]   Set by StandAloneBlast.pm from script.
 
354
    default = stdin. The query should be in FASTA format.  If multiple FASTA entries are in the input
 
355
        file, all queries will be searched.
 
356
  -e  Expectation value (E) [Real] default = 10.0
 
357
  -o  BLAST report Output File [File Out]  Optional,
 
358
        default = ./blastreport.out ; set by StandAloneBlast.pm         
 
359
 
345
360
=head2 Bl2seq
346
361
 
347
362
  -i  First sequence [File In]
373
388
    my ($caller, @args) = @_;
374
389
    # chained new
375
390
    my $self = $caller->SUPER::new(@args);
376
 
 
 
391
 
377
392
    # to facilitiate tempfile cleanup
378
393
    my ($tfh,$tempfile) = $self->io->tempfile();
379
394
    close($tfh); # we don't want the filehandle, just a temporary name
380
395
    $self->o($tempfile) unless $self->o;
381
396
    $self->_READMETHOD($DEFAULTREADMETHOD);
382
397
    while (@args)  {
383
 
            my $attr =   shift @args;
 
398
        my $attr =   shift @args;
384
399
        my $value =  shift @args;
385
400
        next if( $attr eq '-verbose');
 
401
        # we allow both 'attr' and '-attr' options on the new() call
 
402
        $attr =~ s/^-//;
386
403
        # the workaround to deal with initializing
387
 
      if($attr =~/^\s*program\s*$|^p$/){
388
 
        if($value =~/^wu*/){
389
 
          $BLASTTYPE="wublast";
390
 
        }
391
 
        $attr = 'p';
392
 
      }
393
 
      if($attr =~/outfile/){
394
 
        $attr = 'o';
395
 
      }
396
 
    
397
 
        $self->$attr($value);
 
404
        if($attr =~/^\s*program\s*$|^p$/){
 
405
            if($value =~/^wu*/){
 
406
                $BLASTTYPE="wublast";
 
407
            }
 
408
            $attr = 'p';
 
409
        }
 
410
        if($attr =~/outfile/){
 
411
            $attr = 'o';
 
412
        }
 
413
 
 
414
        $self->$attr($value);
398
415
    }
399
416
    return $self;
400
417
}
401
418
 
 
419
=head2 quiet
 
420
 
 
421
 Title   : quiet
 
422
 Usage   : $obj->quiet($newval)
 
423
 Function: 
 
424
 Example : 
 
425
 Returns : value of quiet (a scalar)
 
426
 Args    : on set, new value (a scalar or undef, optional)
 
427
 
 
428
 
 
429
=cut
 
430
 
 
431
sub quiet{
 
432
    my $self = shift;
 
433
    return $self->{'_quiet'} = shift if @_;
 
434
    return $self->{'_quiet'};
 
435
}
 
436
 
402
437
sub AUTOLOAD {
403
438
    my $self = shift;
404
439
    my $attr = $AUTOLOAD;
410
445
    # parameter and should be truncated to its first letter only
411
446
    $attr = ($attr_letter eq '_') ? $attr : $attr_letter;
412
447
    $self->throw("Unallowed parameter: $attr !") unless $OK_FIELD{$attr};
413
 
#    $self->throw("Unallowed parameter: $attr !") unless $ok_field{$attr_letter};
414
448
    $self->{$attr_letter} = shift if @_;
415
449
    return $self->{$attr_letter};
416
450
}
431
465
 
432
466
sub executable {
433
467
   my ($self, $exename, $exe,$warn) = @_;
434
 
   $exename = 'blastall' unless (defined $exename || $BLASTTYPE ne'ncbi');
 
468
   $exename = 'blastall' unless (defined $exename || $BLASTTYPE ne 'ncbi');
435
469
 
436
470
   if( defined $exe && -x $exe ) {
437
471
     $self->{'_pathtoexe'}->{$exename} = $exe;
479
513
 
480
514
 Title   : program_dir
481
515
 Usage   : my $dir = $factory->program_dir();
482
 
 Function: Abstract get method for dir of program. To be implemented
483
 
           by wrapper.
 
516
 Function: Abstract get method for dir of program. 
484
517
 Returns : string representing program directory 
485
518
 Args    : none 
486
519
 
508
541
                                      -seq=>"ACTACCCTTTAAATCAGTGGGGG");
509
542
               $blast_report = $factory->blastall($input);
510
543
        or 
511
 
              $seq_array_ref = \@seq_array;  # where @seq_array is an array of Bio::Seq objects
 
544
              $seq_array_ref = \@seq_array;  
 
545
         # where @seq_array is an array of Bio::Seq objects
512
546
              $blast_report = $factory->blastall(\@seq_array);
513
 
 Returns :  Reference to a Blast object or BPlite object 
 
547
 Returns : Reference to a Blast object or BPlite object 
514
548
           containing the blast report.
515
549
 Args    : Name of a file or Bio::Seq object or an array of 
516
550
           Bio::Seq object containing the query sequence(s). 
577
611
               $input = Bio::Seq->new(-id=>"test query",
578
612
                                      -seq=>"ACTADDEEQQPPTCADEEQQQVVGG");
579
613
               $blast_report = $factory->blastpgp ($input);
580
 
        or 
581
 
              $seq_array_ref = \@seq_array;  # where @seq_array is an array of Bio::Seq objects
 
614
        or
 
615
              $seq_array_ref = \@seq_array;  
 
616
         # where @seq_array is an array of Bio::Seq objects
582
617
              $blast_report = $factory-> blastpgp(\@seq_array);
583
 
 Returns : Reference to a Blast object or BPlite object containing 
584
 
           the blast report.
 
618
 Returns : Reference to a Bio::SearchIO object or BPlite object 
 
619
           containing the blast report (BPlite only if you specify 
 
620
           _READMETHOD=> 'BPlite')
585
621
 Args    : Name of a file or Bio::Seq object. In psiblast jumpstart 
586
622
           mode two additional arguments are required: a SimpleAlign 
587
623
           object one of whose elements is the query and a "mask" to 
593
629
           (or to an array of Seq objects).  If argument is string, 
594
630
           throws exception if file corresponding to string name can 
595
631
           not be found.
596
 
 Returns : Reference to either a BPlite.pm, Blast.pm or BPpsilite.pm  
597
 
           object containing the blast report.
 
632
 Returns : Reference to Bio::SearchIO object 
 
633
           or Bio::Tools::BPpsilite if you specify 
 
634
           _READMETHOD => 'BPlite' object containing the blast report.
598
635
 
599
636
=cut
600
637
 
603
640
    my $executable = 'blastpgp';
604
641
    my $input1 = shift;
605
642
    my $input2 = shift;
606
 
    my $mask = shift;           # used by blastpgp's -B option to specify which residues are position aligned
 
643
         # used by blastpgp's -B option to specify which 
 
644
         # residues are position aligned
 
645
    my $mask = shift;
607
646
 
608
647
    my  ($infilename1, $infilename2 )  = $self->_setinput($executable, 
609
648
                                                          $input1, $input2, 
617
656
    my $blast_report = &_generic_local_blast($self, $executable, $input1, $input2);
618
657
}
619
658
 
 
659
=head2  rpsblast
 
660
 
 
661
 Title   : rpsblast
 
662
 Usage   :  $blast_report = $factory->rpsblast('t/testquery.fa');
 
663
        or
 
664
               $input = Bio::Seq->new(-id=>"test query",
 
665
                                      -seq=>"MVVLCRADDEEQQPPTCADEEQQQVVGG");
 
666
               $blast_report = $factory->rpsblast($input);
 
667
        or
 
668
              $seq_array_ref = \@seq_array;  
 
669
         # where @seq_array is an array of Bio::Seq objects
 
670
              $blast_report = $factory->rpsblast(\@seq_array);
 
671
 Args    : Name of a file or Bio::Seq object or an array of 
 
672
           Bio::Seq object containing the query sequence(s). 
 
673
           Throws an exception if argument is not either a string 
 
674
           (eg a filename) or a reference to a Bio::Seq object 
 
675
           (or to an array of Seq objects).  If argument is string, 
 
676
           throws exception if file corresponding to string name can 
 
677
           not be found.
 
678
 Returns : Reference to a Bio::SearchIO object or BPlite object 
 
679
           containing the blast report (BPlite only if you specify 
 
680
           _READMETHOD=> 'BPlite')
 
681
 
 
682
=cut
 
683
 
 
684
sub rpsblast {
 
685
    my ($self, $input1) = @_;
 
686
        
 
687
    my $executable = 'rpsblast';
 
688
 
 
689
    # Create input file pointer
 
690
    my $infilename1 = $self->_setinput($executable, $input1);
 
691
    if (! $infilename1) { 
 
692
           $self->throw(" $input1 ($infilename1) not Bio::Seq object or array of Bio::Seq objects or file name!");
 
693
         }
 
694
    $self->i($infilename1);     # set file name of sequence to be blasted to inputfilename1 (-i param of blastall)
 
695
    
 
696
         # Run like a standard NCBI blast from this point
 
697
    my $blast_report = _generic_local_blast($self, $executable);
 
698
}
 
699
 
620
700
=head2   bl2seq
621
701
 
622
702
 Title   : bl2seq
623
 
 Usage   : $factory-> blastpgp('t/seq1.fa', 't/seq2.fa');
 
703
 Usage   : $factory-> bl2seq('t/seq1.fa', 't/seq2.fa');
624
704
        or
625
705
          $input1 = Bio::Seq->new(-id=>"test query1",
626
706
                                  -seq=>"ACTADDEEQQPPTCADEEQQQVVGG");
632
712
           sequences to be aligned by bl2seq.
633
713
 
634
714
           Throws an exception if argument is not either a pair of 
635
 
           strings (eg filenames) or  references to Bio::Seq objects.  
 
715
           strings (eg filenames) or references to Bio::Seq objects.  
636
716
           If arguments are strings, throws exception if files 
637
717
           corresponding to string names can not be found.
638
718
 
663
743
=head2  _generic_local_blast
664
744
 
665
745
 Title   : _generic_local_blast
666
 
 Usage   :  internal function not called directly
667
 
 Returns :  Blast or BPlite object
668
 
 Args    :   Reference to calling object and name of BLAST executable 
 
746
 Usage   : internal function not called directly
 
747
 Returns : Bio::SearchIO or Bio::Tools::BPlite object
 
748
 Args    : Reference to calling object and name of BLAST executable 
669
749
 
670
750
=cut
671
751
 
708
788
 Usage   :  Internal function, not to be called directly        
709
789
 Function:   makes actual system call to Blast program
710
790
 Example :
711
 
 Returns : Report object in the appropriate format (BPlite, 
712
 
           BPpsilite, Blast, or BPbl2seq)
 
791
 Returns : Report object in the appropriate format (Bio::SearchIO)
 
792
           or if BPlite is requested: Bio::Tools::BPlite, 
 
793
           Bio::Tools::BPpsilite,or Bio::Tools::BPbl2seq)
713
794
 Args    : Reference to calling object, name of BLAST executable, 
714
795
           and parameter string for executable 
715
796
 
716
797
=cut
717
798
 
718
799
sub _runblast {
719
 
    my ($self,$executable,$param_string) = @_;
720
 
    my ($blast_obj,$exe);
721
 
    if( ! ($exe = $self->executable($executable)) ) {
722
 
        $self->warn("cannot find path to $executable");
723
 
        return undef;    
724
 
    }
725
 
    my $commandstring = $exe. $param_string;
726
 
   
727
 
    # next line for debugging
728
 
    $self->debug( "$commandstring \n");
729
 
 
730
 
    my $status = system($commandstring);
731
 
 
732
 
    $self->throw("$executable call crashed: $? $commandstring\n")  unless ($status==0) ;
733
 
    my $outfile = $self->o() ;  # get outputfilename
734
 
    my $signif = $self->e()  || 1e-5  ; 
735
 
 
736
 
# set significance cutoff to set expectation value or default value
737
 
# (may want to make this value vary for different executables)
738
 
 
739
 
# If running bl2seq or psiblast (blastpgp with multiple iterations),
740
 
# the specific parsers for these programs must be used (ie BPbl2seq or
741
 
# BPpsilite).  Otherwise either the Blast parser or the BPlite
742
 
# parsers can be selected.
743
 
 
744
 
    if ($self->_READMETHOD =~ /^(Blast|SearchIO)/i )  {
745
 
        $blast_obj = Bio::SearchIO->new(-file=>$outfile,
746
 
                                        -format => 'blast' )  ;
747
 
    } elsif( $self->_READMETHOD =~ /BPlite/i ) {
748
 
        if ($executable =~ /bl2seq/i)  {
749
 
            # Added program info so BPbl2seq can compute strand info
750
 
            $blast_obj = Bio::Tools::BPbl2seq->new(-file => $outfile,
751
 
                                                   -REPORT_TYPE => $self->p );
752
 
        } elsif ($executable =~ /blastpgp/i && defined $self->j() && 
753
 
                 $self->j() > 1)  {
754
 
            $self->debug( "using psilite parser\n");
755
 
            $blast_obj = Bio::Tools::BPpsilite->new(-file => $outfile);
756
 
        } elsif( $executable =~ /blastall/i ) { 
757
 
            $blast_obj = Bio::Tools::BPlite->new(-file=>$outfile);
758
 
        } else { 
759
 
            $self->warn("Unrecognized executable $executable");
760
 
        }
761
 
    } else {
762
 
        $self->warn("Unrecognized readmethod ".$self->_READMETHOD);
763
 
    }
764
 
 
765
 
    return $blast_obj;
 
800
        my ($self,$executable,$param_string) = @_;
 
801
        my ($blast_obj,$exe);
 
802
        if( ! ($exe = $self->executable($executable)) ) {
 
803
                $self->warn("cannot find path to $executable");
 
804
                return;
 
805
        }
 
806
        my $commandstring = $exe. $param_string;
 
807
 
 
808
        # next line for debugging
 
809
        $self->debug( "$commandstring \n");
 
810
 
 
811
        my $status = system($commandstring);
 
812
 
 
813
        $self->throw("$executable call crashed: $? $commandstring\n")  
 
814
          unless ($status==0) ;
 
815
        my $outfile = $self->o() ;      # get outputfilename
 
816
        my $signif = $self->e()  || 1e-5  ; 
 
817
 
 
818
        # set significance cutoff to set expectation value or default value
 
819
        # (may want to make this value vary for different executables)
 
820
 
 
821
        # If running bl2seq or psiblast (blastpgp with multiple iterations),
 
822
        # the specific parsers for these programs must be used (ie BPbl2seq or
 
823
        # BPpsilite).  Otherwise either the Blast parser or the BPlite
 
824
        # parsers can be selected.
 
825
 
 
826
        if ($self->_READMETHOD =~ /^(Blast|SearchIO)/i )  {
 
827
                $blast_obj = Bio::SearchIO->new(-file=>$outfile,
 
828
                                                                                                  -format => 'blast' )  ;
 
829
        } elsif( $self->_READMETHOD =~ /BPlite/i ) {
 
830
                if ($executable =~ /bl2seq/i)  {
 
831
                        # Added program info so BPbl2seq can compute strand info
 
832
                        $blast_obj = Bio::Tools::BPbl2seq->new(-file => $outfile,
 
833
                                                                                                                                -REPORT_TYPE => $self->p );
 
834
                } elsif ($executable =~ /blastpgp/i && defined $self->j() && 
 
835
                                        $self->j() > 1)  {
 
836
                        $self->debug( "using psilite parser\n");
 
837
                        $blast_obj = Bio::Tools::BPpsilite->new(-file => $outfile);
 
838
                } elsif( $executable =~ /blastall|rpsblast/i) { 
 
839
                        $blast_obj = Bio::Tools::BPlite->new(-file=>$outfile);
 
840
                } else { 
 
841
                        $self->warn("Unrecognized executable $executable");
 
842
                }
 
843
        } else {
 
844
                $self->warn("Unrecognized readmethod ".$self->_READMETHOD);
 
845
        }
 
846
 
 
847
        return $blast_obj;
766
848
}
767
849
 
768
850
=head2  _runwublast
778
860
=cut
779
861
 
780
862
sub _runwublast {
781
 
    my ($self,$executable,$param_string) = @_;
782
 
    my ($blast_obj,$exe);
783
 
    if( ! ($exe = $self->executable($self->p))){
784
 
        $self->warn("cannot find path to $executable");
785
 
        return undef;    
786
 
    }
787
 
    my $commandstring = $exe.  " ".$param_string;
788
 
   
789
 
    # next line for debugging
790
 
    $self->debug( "$commandstring \n");
791
 
 
792
 
    my $status = system($commandstring);
793
 
 
794
 
    $self->throw("$executable call crashed: $? $commandstring\n")  unless ($status==0) ;
795
 
    my $outfile = $self->o() ;  # get outputfilename
796
 
          $blast_obj = Bio::SearchIO->new(-file=>$outfile,
 
863
        my ($self,$executable,$param_string) = @_;
 
864
        my ($blast_obj,$exe);
 
865
        if( ! ($exe = $self->executable($self->p))){
 
866
            $self->warn("cannot find path to $executable");
 
867
            return;
 
868
        }
 
869
        my $commandstring = $exe.  " ".$param_string;
 
870
 
 
871
        # next line for debugging
 
872
        $self->debug( "$commandstring \n");
 
873
 
 
874
        my $status = system($commandstring);
 
875
 
 
876
        $self->throw("$executable call crashed: $? $commandstring\n")  
 
877
          unless ($status==0) ;
 
878
        my $outfile = $self->o() ;      # get outputfilename
 
879
        $blast_obj = Bio::SearchIO->new(-file=>$outfile,
797
880
                                                                -format => 'blast') ;
798
 
    return $blast_obj;
 
881
        return $blast_obj;
799
882
}
800
883
 
801
884
=head2  _setinput
810
893
=cut
811
894
 
812
895
sub _setinput {
813
 
    my ($self, $executable, $input1, $input2) = @_;
814
 
    my ($seq, $temp, $infilename1, $infilename2,$fh ) ;
815
 
#  If $input1 is not a reference it better be the name of a file with
816
 
#  the sequence/ alignment data...
817
 
    $self->io->_io_cleanup();
 
896
        my ($self, $executable, $input1, $input2) = @_;
 
897
        my ($seq, $temp, $infilename1, $infilename2,$fh ) ;
 
898
        #  If $input1 is not a reference it better be the name of a file with
 
899
        #  the sequence/ alignment data...
 
900
        $self->io->_io_cleanup();
818
901
 
819
 
  SWITCH:  {
 
902
 SWITCH:  {
820
903
      unless (ref $input1) {
821
 
          $infilename1 = (-e $input1) ? $input1 : 0 ;
822
 
          last SWITCH; 
 
904
                        $infilename1 = (-e $input1) ? $input1 : 0 ;
 
905
                        last SWITCH; 
823
906
      }
824
 
#  $input may be an array of BioSeq objects...
 
907
                #  $input may be an array of BioSeq objects...
825
908
      if (ref($input1) =~ /ARRAY/i ) {
826
 
          ($fh,$infilename1) = $self->io->tempfile();
827
 
          $temp =  Bio::SeqIO->new(-fh=> $fh, 
828
 
                                   '-format' => 'fasta');
829
 
          foreach $seq (@$input1) {
830
 
              unless ($seq->isa("Bio::PrimarySeqI")) {return 0;}
831
 
              $seq->display_id($seq->display_id);
832
 
              $temp->write_seq($seq);
833
 
          }
834
 
          close $fh;
835
 
          $fh = undef;
836
 
          last SWITCH;
 
909
                        ($fh,$infilename1) = $self->io->tempfile();
 
910
                        $temp =  Bio::SeqIO->new(-fh=> $fh, 
 
911
                                                                                         -format => 'fasta');
 
912
                        foreach $seq (@$input1) {
 
913
                                unless ($seq->isa("Bio::PrimarySeqI")) {return 0;}
 
914
                                $seq->display_id($seq->display_id);
 
915
                                $temp->write_seq($seq);
 
916
                        }
 
917
                        close $fh;
 
918
                        $fh = undef;
 
919
                        last SWITCH;
837
920
      }
838
 
#  $input may be a single BioSeq object...
 
921
                #  $input may be a single BioSeq object...
839
922
      elsif ($input1->isa("Bio::PrimarySeqI")) {
840
 
          ($fh,$infilename1) = $self->io->tempfile();
841
 
 
842
 
# just in case $input1 is taken from an alignment and has spaces (ie
843
 
# deletions) indicated within it, we have to remove them - otherwise
844
 
# the BLAST programs will be unhappy
845
 
 
846
 
          my $seq_string =  $input1->seq();
847
 
          $seq_string =~ s/\W+//g; # get rid of spaces in sequence
848
 
          $input1->seq($seq_string);
849
 
          $temp =  Bio::SeqIO->new(-fh=> $fh, '-format' => 'fasta');
850
 
          $temp->write_seq($input1);
851
 
          close $fh;
852
 
          undef $fh;
853
 
          last SWITCH;
 
923
                        ($fh,$infilename1) = $self->io->tempfile();
 
924
 
 
925
                        # just in case $input1 is taken from an alignment and has spaces (ie
 
926
                        # deletions) indicated within it, we have to remove them - otherwise
 
927
                        # the BLAST programs will be unhappy
 
928
 
 
929
                        my $seq_string =  $input1->seq();
 
930
                        $seq_string =~ s/\W+//g; # get rid of spaces in sequence
 
931
                        $input1->seq($seq_string);
 
932
                        $temp =  Bio::SeqIO->new(-fh=> $fh, '-format' => 'fasta');
 
933
                        $temp->write_seq($input1);
 
934
                        close $fh;
 
935
                        undef $fh;
 
936
                        last SWITCH;
854
937
      }
855
938
      $infilename1 = 0;         # Set error flag if you get here
856
 
  }                             # End SWITCH
857
 
    unless ($input2) { return $infilename1; }
858
 
  SWITCH2:  {
 
939
        }                               # End SWITCH
 
940
        unless ($input2) { return $infilename1; }
 
941
 SWITCH2:  {
859
942
      unless (ref $input2) {
860
 
          $infilename2 =   (-e $input2) ? $input2 : 0 ;
861
 
          last SWITCH2; 
 
943
                        $infilename2 =   (-e $input2) ? $input2 : 0 ;
 
944
                        last SWITCH2; 
862
945
      }
863
946
      if ($input2->isa("Bio::PrimarySeqI")  && $executable  eq 'bl2seq' ) {
864
 
          ($fh,$infilename2) = $self->io->tempfile();
 
947
                        ($fh,$infilename2) = $self->io->tempfile();
865
948
 
866
 
          $temp =  Bio::SeqIO->new(-fh=> $fh, '-format' => 'Fasta');
867
 
          $temp->write_seq($input2);
868
 
          close $fh;
869
 
          undef $fh;      
870
 
          last SWITCH2;
 
949
                        $temp =  Bio::SeqIO->new(-fh=> $fh, '-format' => 'Fasta');
 
950
                        $temp->write_seq($input2);
 
951
                        close $fh;
 
952
                        undef $fh;
 
953
                        last SWITCH2;
871
954
      }
872
 
# Option for using psiblast's pre-alignment "jumpstart" feature
 
955
                # Option for using psiblast's pre-alignment "jumpstart" feature
873
956
      elsif ($input2->isa("Bio::SimpleAlign")  && 
874
 
             $executable  eq 'blastpgp' ) {
875
 
           # a bit of a lie since it won't be a fasta file
 
957
                                 $executable  eq 'blastpgp' ) {
 
958
                        # a bit of a lie since it won't be a fasta file
876
959
          ($fh,$infilename2) = $self->io->tempfile(); 
877
960
 
878
 
# first we retrieve the "mask" that determines which residues should
879
 
# by scored according to their position and which should be scored
880
 
# using the non-position-specific matrices
 
961
          # first we retrieve the "mask" that determines which residues should
 
962
          # by scored according to their position and which should be scored
 
963
          # using the non-position-specific matrices
881
964
 
882
965
          my @mask = split("", shift ); #  get mask
883
966
 
884
 
# then we have to convert all the residues in every sequence to upper
885
 
# case at the positions that we want psiblast to use position specific
886
 
# scoring
 
967
          # then we have to convert all the residues in every sequence to upper
 
968
          # case at the positions that we want psiblast to use position specific
 
969
          # scoring
887
970
 
888
971
          foreach $seq ( $input2->each_seq() ) {
889
 
              my @seqstringlist = split("",$seq->seq());
890
 
              for (my $i = 0; $i < scalar(@mask); $i++) {
891
 
                  unless ( $seqstringlist[$i] =~ /[a-zA-Z]/ ) {next}
892
 
                  $seqstringlist[$i] = $mask[$i] ? uc $seqstringlist[$i]: lc $seqstringlist[$i] ;
893
 
              }
894
 
              my $newseqstring = join("", @seqstringlist);
895
 
              $seq->seq($newseqstring);
 
972
                  my @seqstringlist = split("",$seq->seq());
 
973
                  for (my $i = 0; $i < scalar(@mask); $i++) {
 
974
                          unless ( $seqstringlist[$i] =~ /[a-zA-Z]/ ) {next}
 
975
                          $seqstringlist[$i] = $mask[$i] ? uc $seqstringlist[$i]: lc $seqstringlist[$i] ;
 
976
                  }
 
977
                  my $newseqstring = join("", @seqstringlist);
 
978
                  $seq->seq($newseqstring);
896
979
          }
897
 
          #  Now we need to write out the alignment to a file 
898
 
          # in the "psi format" which psiblast is expecting
 
980
          #  Now we need to write out the alignment to a file 
 
981
          # in the "psi format" which psiblast is expecting
899
982
          $input2->map_chars('\.','-');
900
983
          $temp =  Bio::AlignIO->new(-fh=> $fh, '-format' => 'psi');
901
984
          $temp->write_aln($input2);
902
985
          close $fh;
903
986
          undef $fh;
904
987
          last SWITCH2;
905
 
      }
 
988
  }
906
989
      $infilename2 = 0;         # Set error flag if you get here
907
 
  }                             # End SWITCH2
908
 
    return ($infilename1, $infilename2);
 
990
        }                               # End SWITCH2
 
991
        return ($infilename1, $infilename2);
909
992
}
910
993
 
911
994
=head2  _setparams
923
1006
    my ($self,$executable) = @_;
924
1007
    my ($attr, $value, @execparams);
925
1008
 
926
 
    if ($executable eq 'blastall') {@execparams = @BLASTALL_PARAMS; }
927
 
    if ($executable eq 'blastpgp') {@execparams = @BLASTPGP_PARAMS; }
928
 
    if ($executable eq 'bl2seq')   {@execparams = @BL2SEQ_PARAMS; }
929
 
    if($executable eq 'wublast')   {@execparams = @WUBLAST_PARAMS; }
 
1009
    if    ($executable eq 'blastall') { @execparams = @BLASTALL_PARAMS; }
 
1010
    elsif ($executable eq 'blastpgp') { @execparams = @BLASTPGP_PARAMS; }
 
1011
    elsif ($executable eq 'rpsblast') { @execparams = @RPSBLAST_PARAMS; }
 
1012
    elsif ($executable eq 'bl2seq'  ) { @execparams = @BL2SEQ_PARAMS;   }
 
1013
    elsif ($executable eq 'wublast' ) { @execparams = @WUBLAST_PARAMS;  }
930
1014
 
931
1015
    my $param_string = "";
932
1016
    for $attr ( @execparams ) {
933
 
            $value = $self->$attr();
934
 
        next unless (defined $value);
935
 
      # Need to prepend datadirectory to database name
936
 
      if($executable eq 'wublast'){
937
 
        next if $attr =~ /database|^d$/;
938
 
        next if $attr =~ /input|^i$/;
939
 
        $attr = 'o' if ($attr =~/outfile/);
940
 
      }
 
1017
        $value = $self->$attr();
 
1018
        next unless (defined $value);
 
1019
        # Need to prepend datadirectory to database name
 
1020
        if ($executable eq 'wublast') {
 
1021
          next if $attr =~ /database|^d$/;
 
1022
          next if $attr =~ /input|^i$/;
 
1023
          $attr = 'o' if ($attr =~/outfile/);
 
1024
        }
941
1025
 
942
1026
        if ($attr  eq 'd' && ($executable ne 'bl2seq')) { 
943
 
# This is added so that you can specify a DB with a full path
944
 
          if (! (-e $value.".nin" || -e $value.".pin")){ 
945
 
      my @dbs = split(/ /, $value);
946
 
      for (my $i = 0; $i < scalar(@dbs); $i++) {
947
 
        $dbs[$i] = File::Spec->catdir($DATADIR, $dbs[$i]);
948
 
      }
949
 
      $value = '"'.join(" ", @dbs).'"';
950
 
    }
 
1027
            my @dbs = split(/ /, $value);
 
1028
            for (my $i = 0; $i < scalar(@dbs); $i++) {
 
1029
                # moved the test for full path db to work with multiple databases
 
1030
                if (! (-e $dbs[$i].".nin" || -e $dbs[$i].".pin") &&
 
1031
                    ! (-e $dbs[$i].".nal" || -e $dbs[$i].".pal") ) {
 
1032
                    $dbs[$i] = File::Spec->catdir($DATADIR, $dbs[$i]);
 
1033
                }
 
1034
                $value = '"'.join(" ", @dbs).'"';
 
1035
            }
951
1036
        }
952
1037
# put params in format expected by Blast
953
1038
        $attr  = '-'. $attr ;       
954
1039
        $param_string .= " $attr  $value ";
955
1040
    }
956
1041
 
957
 
    if ($self->quiet()) { $param_string .= '  2>/dev/null';}
958
 
    if($executable eq 'wublast'){
959
 
        foreach my $attr(@WUBLAST_SWITCH){
 
1042
    if ($self->quiet()) { 
 
1043
      $param_string .= '  2> '.File::Spec->devnull;
 
1044
    }
 
1045
    if ($executable eq 'wublast') {
 
1046
        foreach my $attr (@WUBLAST_SWITCH) {
960
1047
            my $value = $self->$attr();
961
1048
            next unless (defined $value);
962
1049
            my $attr_key = ' -'.(lc $attr);
1033
1120
 
1034
1121
 Title   : io
1035
1122
 Usage   : $obj->io($newval)
1036
 
 Function:  Gets a L<Bio::Root::IO> object
1037
 
 Returns : L<Bio::Root::IO>
 
1123
 Function:  Gets a Bio::Root::IO object
 
1124
 Returns : Bio::Root::IO
1038
1125
 Args    : none
1039
1126
 
1040
1127
 
1041
1128
=cut
1042
1129
 
1043
1130
1;
 
1131
 
1044
1132
__END__