~ubuntu-branches/ubuntu/oneiric/bioperl/oneiric

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Charles Plessy
  • Date: 2009-03-10 07:19:11 UTC
  • mfrom: (3.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090310071911-ever3si2bbzx1iks
Tags: 1.6.0-2
* Removed patch system (not used):
  - removed instuctions in debian/rules;
  - removed quilt from Build-Depends in debian/control.
* Re-enabled tests:
  - uncommented test command in debian/rules;
  - uncommented previously missing build-dependencies in debian/control.
  - Re-enabled tests and uncommented build-dependencies accordingly.
* Removed libmodule-build-perl and libtest-harness-perl from
  Build-Depends-Indep (provided by perl-modules).
* Better cleaning of empty directories using find -type d -empty -delete
  instead of rmdir in debian/rules (LP: #324001).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# $Id: StandAloneWUBlast.pm 15383 2009-01-16 16:45:08Z cjfields $
 
2
#
 
3
# BioPerl module for Bio::Tools::Run::StandAloneBlast
 
4
#
 
5
# Copyright Peter Schattner
 
6
#
 
7
# You may distribute this module under the same terms as perl itself
 
8
 
 
9
# POD documentation - main docs before the code
 
10
 
 
11
=head1 NAME
 
12
 
 
13
Bio::Tools::Run::StandAloneWUBlast - Object for the local execution 
 
14
of WU-Blast.
 
15
 
 
16
=head1 SYNOPSIS
 
17
 
 
18
 # Do not use directly; use Bio::Tools::Run::StandAloneBlast
 
19
 
 
20
=head1 DESCRIPTION
 
21
 
 
22
See Bio::Tools::Run::StandAloneBlast
 
23
 
 
24
=head1 FEEDBACK
 
25
 
 
26
=head2 Mailing Lists
 
27
 
 
28
User feedback is an integral part of the evolution of this and other
 
29
Bioperl modules. Send your comments and suggestions preferably to one
 
30
of the Bioperl mailing lists.  Your participation is much appreciated.
 
31
 
 
32
  bioperl-l@bioperl.org                  - General discussion
 
33
  http://bioperl.org/wiki/Mailing_lists  - About the mailing lists
 
34
 
 
35
=head2 Reporting Bugs
 
36
 
 
37
Report bugs to the Bioperl bug tracking system to help us keep track
 
38
the bugs and their resolution.  Bug reports can be submitted via 
 
39
the web:
 
40
 
 
41
  http://bugzilla.open-bio.org/
 
42
 
 
43
=head1 AUTHOR - Peter Schattner
 
44
 
 
45
Email schattner at alum.mit.edu
 
46
 
 
47
=head1 MAINTAINER - Torsten Seemann
 
48
 
 
49
Email torsten at infotech.monash.edu.au
 
50
 
 
51
=head1 CONTRIBUTORS
 
52
 
 
53
Sendu Bala  bix@sendu.me.uk (reimplementation)
 
54
 
 
55
=head1 APPENDIX
 
56
 
 
57
The rest of the documentation details each of the object
 
58
methods. Internal methods are usually preceded with a _
 
59
 
 
60
=cut
 
61
 
 
62
package Bio::Tools::Run::StandAloneWUBlast;
 
63
 
 
64
use strict;
 
65
 
 
66
use base qw(Bio::Tools::Run::StandAloneBlast);
 
67
 
 
68
our $AUTOLOAD;
 
69
our $DEFAULTREADMETHOD = 'BLAST';
 
70
 
 
71
# If local BLAST databases are not stored in the standard
 
72
# /data directory, the variable BLASTDATADIR will need to be 
 
73
# set explicitly 
 
74
our $DATADIR = $Bio::Tools::Run::StandAloneBlast::DATADIR;
 
75
 
 
76
our %GENERAL_PARAMS  = (i => 'input',
 
77
                        o => 'outfile',
 
78
                        p => 'program',
 
79
                        d => 'database');
 
80
our @WUBLAST_PARAMS  = qw(e s e2 s2 w t x m y z l k h v b q r
 
81
    matrix filter wordmask filter maskextra  hitdist wink ctxfactor gape
 
82
    gaps gape2 gaps2 gapw gapx olf golf  olmax golmax gapdecayrate
 
83
    topcombon topcomboe sumstatsmethod hspsepqmax hspsepsmax gapsepqmax
 
84
    gapsepsmax altscore hspmax gspmax qoffset nwstart nwlen qrecmin qrecmax 
 
85
    dbrecmin dbrecmax vdbdescmax dbchunks sort_by_pvalue  cpus putenv
 
86
    getenv progress);
 
87
our @WUBLAST_SWITCH = qw(kap sump poissonp lcfilter lcmask echofilter
 
88
    stats nogap gapall pingpong nosegs postsw span2 span1 span prune
 
89
    consistency links ucdb gi noseqs qtype qres sort_by_pvalue
 
90
    sort_by_count sort_by_highscore sort_by_totalscore
 
91
    sort_by_subjectlength mmio nonnegok novalidctxok shortqueryok notes
 
92
    warnings errors endputenv getenv endgetenv abortonerror abortonfatal);
 
93
 
 
94
our @OTHER_PARAMS = qw(_READMETHOD);
 
95
 
 
96
 
 
97
=head2 new
 
98
 
 
99
 Title   : new
 
100
 Usage   : my $obj = Bio::Tools::Run::StandAloneBlast->new();
 
101
 Function: Builds a newBio::Tools::Run::StandAloneBlast object 
 
102
 Returns : Bio::Tools::Run::StandAloneBlast
 
103
 Args    : -quiet => boolean # make program execution quiet
 
104
           -_READMETHOD => 'BLAST' (default, synonym 'SearchIO') || 'blast_pull'
 
105
                           # the parsing method, case insensitive
 
106
 
 
107
Essentially all BLAST parameters can be set via StandAloneBlast.pm.
 
108
Some of the most commonly used parameters are listed below. All
 
109
parameters have defaults and are optional except for -p.
 
110
 
 
111
  -p Program Name [String] 
 
112
        Input should be one of "wublastp", "wublastn", "wublastx", 
 
113
        "wutblastn", or "wutblastx".
 
114
  -d  Database [String] default = nr
 
115
        The database specified must first be formatted with xdformat.
 
116
  -E  Expectation value (E) [Real] default = 10.0
 
117
  -o  BLAST report Output File [File Out]  Optional,
 
118
            default = ./blastreport.out ; set by StandAloneBlast.pm             
 
119
 
 
120
=cut
 
121
 
 
122
sub new {
 
123
    my ($caller, @args) = @_;
 
124
    my $self = $caller->SUPER::new(@args);
 
125
    
 
126
    $self->_set_from_args(\@args, -methods => {(map { $_ => $GENERAL_PARAMS{$_} } keys %GENERAL_PARAMS),
 
127
                                               (map { $_ => $_ } (@OTHER_PARAMS,
 
128
                                                                  @WUBLAST_PARAMS,
 
129
                                                                  @WUBLAST_SWITCH))},
 
130
                                  -create => 1,
 
131
                                  -force => 1);
 
132
    
 
133
    my ($tfh, $tempfile) = $self->io->tempfile();
 
134
    my $outfile = $self->o || $self->outfile || $tempfile;
 
135
    $self->o($outfile);
 
136
    close($tfh);
 
137
    
 
138
    $self->_READMETHOD($DEFAULTREADMETHOD) unless $self->_READMETHOD;
 
139
    
 
140
    return $self;
 
141
}
 
142
 
 
143
# We let get/setter method names be case-insensitve
 
144
sub AUTOLOAD {
 
145
    my $self = shift;
 
146
    my $attr = $AUTOLOAD;
 
147
    $attr =~ s/.*:://;
 
148
    
 
149
    my $orig = $attr;
 
150
    
 
151
    $attr = lc($attr);
 
152
    
 
153
    $self->can($attr) || $self->throw("Unallowed parameter: $orig !");
 
154
    
 
155
    return $self->$attr(@_);
 
156
}
 
157
 
 
158
=head2  wublast
 
159
 
 
160
 Title   : wublast
 
161
 Usage   :  $blast_report = $factory->wublast('t/testquery.fa');
 
162
        or
 
163
               $input = Bio::Seq->new(-id=>"test query",
 
164
                                      -seq=>"ACTACCCTTTAAATCAGTGGGGG");
 
165
               $blast_report = $factory->wublast($input);
 
166
        or 
 
167
              $seq_array_ref = \@seq_array;  # where @seq_array is an array of Bio::Seq objects
 
168
              $blast_report = $factory->wublast(\@seq_array);
 
169
 Returns :  Reference to a Blast object 
 
170
 Args    : Name of a file or Bio::Seq object or an array of 
 
171
           Bio::Seq object containing the query sequence(s). 
 
172
           Throws an exception if argument is not either a string 
 
173
           (eg a filename) or a reference to a Bio::Seq object 
 
174
           (or to an array of Seq objects).  If argument is string, 
 
175
           throws exception if file corresponding to string name can 
 
176
           not be found.
 
177
 
 
178
=cut
 
179
 
 
180
sub wublast {
 
181
    my ($self, $input1) = @_;
 
182
    $self->io->_io_cleanup();
 
183
    my $executable = 'wublast';
 
184
    
 
185
    # Create input file pointer
 
186
    my $infilename1 = $self->_setinput($executable, $input1) || $self->throw("$input1 not Bio::Seq object or array of Bio::Seq objects or file name!");
 
187
    $self->i($infilename1);
 
188
    
 
189
    my $blast_report = $self->_generic_local_wublast($executable);
 
190
}
 
191
 
 
192
=head2  _generic_local_wublast
 
193
 
 
194
 Title   : _generic_local_wublast
 
195
 Usage   :  internal function not called directly
 
196
 Returns :  Blast object
 
197
 Args    :   Reference to calling object and name of BLAST executable 
 
198
 
 
199
=cut
 
200
 
 
201
sub _generic_local_wublast {
 
202
    my $self = shift;
 
203
    my $executable = shift;
 
204
    
 
205
    # Create parameter string to pass to Blast program
 
206
    my $param_string = $self->_setparams($executable);
 
207
    $param_string = " ".$self->database." ".$self->input." ".$param_string;
 
208
    
 
209
    # run Blast
 
210
    my $blast_report = $self->_runwublast($executable, $param_string);
 
211
}
 
212
 
 
213
=head2  _runwublast
 
214
 
 
215
 Title   :  _runwublast
 
216
 Usage   :  Internal function, not to be called directly        
 
217
 Function:   makes actual system call to WU-Blast program
 
218
 Example :
 
219
 Returns : Report Blast object
 
220
 Args    : Reference to calling object, name of BLAST executable, 
 
221
           and parameter string for executable 
 
222
 
 
223
=cut
 
224
 
 
225
sub _runwublast {
 
226
        my ($self, $executable, $param_string) = @_;
 
227
        my ($blast_obj, $exe);
 
228
        if (! ($exe = $self->executable($self->p))){
 
229
        $self->warn("cannot find path to $executable");
 
230
        return;
 
231
        }
 
232
    
 
233
        my $commandstring = $exe.$param_string;
 
234
    
 
235
        $self->debug("$commandstring\n");
 
236
        system($commandstring) && $self->throw("$executable call crashed: $? | $! | $commandstring\n");
 
237
    
 
238
    # get outputfilename
 
239
        my $outfile = $self->o();       
 
240
        $blast_obj = Bio::SearchIO->new(-file => $outfile, -format => 'blast');
 
241
    
 
242
        return $blast_obj;
 
243
}
 
244
 
 
245
=head2  _setparams
 
246
 
 
247
 Title   : _setparams
 
248
 Usage   : Internal function, not to be called directly 
 
249
 Function: Create parameter inputs for Blast program
 
250
 Example :
 
251
 Returns : parameter string to be passed to Blast 
 
252
 Args    : Reference to calling object and name of BLAST executable
 
253
 
 
254
=cut
 
255
 
 
256
sub _setparams {
 
257
    my ($self, $executable) = @_;
 
258
    my ($attr, $value, @execparams);
 
259
    
 
260
    @execparams = @WUBLAST_PARAMS;
 
261
    
 
262
    # of the general params, wublast only takes outfile at
 
263
    # this stage (we add in program, input and database manually elsewhere)
 
264
    push(@execparams, 'o');
 
265
    
 
266
    # workaround for problems with shell metacharacters [bug 2707]
 
267
    # simply quoting does not always work!
 
268
    # Fixed so Windows files are not quotemeta'd
 
269
    my $tmp = $self->o;
 
270
    $self->o(quotemeta($tmp)) if ($tmp && $^O !~ /^MSWin/);
 
271
    
 
272
    my $param_string = $self->SUPER::_setparams(-params => [@execparams],
 
273
                                                -switches => \@WUBLAST_SWITCH,
 
274
                                                -dash => 1);
 
275
    
 
276
    $self->o($tmp) if ($tmp && $^O !~ /^MSWin/);
 
277
    
 
278
    if ($self->quiet()) { 
 
279
        $param_string .= ' 2> '.File::Spec->devnull;
 
280
    }
 
281
    
 
282
    return $param_string;
 
283
}
 
284
 
 
285
1;