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