blib/lib/Bio/Tools/Run/StandAloneWUBlast.pm untested

filter: Statementstmt 0.0% 0 / 68 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 21 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 115 CC 7 SCAR 22.9
CC
7
Cov
0%
_setparams
20.0
_runwublast
12.0
new
6.0
CRAP 9.9
1 #
2 # BioPerl module for Bio::Tools::Run::StandAloneBlast
3 #
4 # Copyright Peter Schattner
5 #
6 # You may distribute this module under the same terms as perl itself
7  
8 # POD documentation - main docs before the code
9  
10 =head1 NAME
11  
12 Bio::Tools::Run::StandAloneWUBlast - Object for the local execution
13 of WU-Blast.
14  
15 =head1 SYNOPSIS
16  
17 # Do not use directly; use Bio::Tools::Run::StandAloneBlast
18  
19 =head1 DESCRIPTION
20  
21 See Bio::Tools::Run::StandAloneBlast
22  
23 =head1 FEEDBACK
24  
25 =head2 Mailing Lists
26  
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.
30  
31 bioperl-l@bioperl.org - General discussion
32 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
33  
34 =head2 Support
35  
36 Please direct usage questions or support issues to the mailing list:
37  
38 I<bioperl-l@bioperl.org>
39  
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.
44  
45 =head2 Reporting Bugs
46  
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:
50  
51 https://github.com/bioperl/bioperl-live/issues
52  
53 =head1 AUTHOR - Peter Schattner
54  
55 Email schattner at alum.mit.edu
56  
57 =head1 MAINTAINER - Torsten Seemann
58  
59 Email torsten at infotech.monash.edu.au
60  
61 =head1 CONTRIBUTORS
62  
63 Sendu Bala bix@sendu.me.uk (reimplementation)
64  
65 =head1 APPENDIX
66  
67 The rest of the documentation details each of the object
68 methods. Internal methods are usually preceded with a _
69  
70 =cut
71  
72 package Bio::Tools::Run::StandAloneWUBlast;
73  
74 use strict;
75  
76 use base qw(Bio::Tools::Run::StandAloneBlast);
77  
78 our $AUTOLOAD;
79 our $DEFAULTREADMETHOD = 'BLAST';
80  
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;
85  
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);
103  
104 our @OTHER_PARAMS = qw(_READMETHOD);
105  
106  
107 =head2 new
108  
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
116  
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.
120  
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
129  
130 =cut
131  
132 sub new {
133 my ($caller, @args) = @_;
134 my $self = $caller->SUPER::new(@args);
135
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);
142
143 my ($tfh, $tempfile) = $self->io->tempfile();
144 my $outfile = $self->o || $self->outfile || $tempfile;
145 $self->o($outfile);
146 close($tfh);
147
148 $self->_READMETHOD($DEFAULTREADMETHOD) unless $self->_READMETHOD;
149
150 return $self;
151 }
152  
153 # We let get/setter method names be case-insensitve
154 sub AUTOLOAD {
155 my $self = shift;
156 my $attr = $AUTOLOAD;
157 $attr =~ s/.*:://;
158
159 my $orig = $attr;
160
161 $attr = lc($attr);
162
163 $self->can($attr) || $self->throw("Unallowed parameter: $orig !");
164
165 return $self->$attr(@_);
166 }
167  
168 =head2 wublast
169  
170 Title : wublast
171 Usage : $blast_report = $factory->wublast('t/testquery.fa');
172 or
173 $input = Bio::Seq->new(-id=>"test query",
174 -seq=>"ACTACCCTTTAAATCAGTGGGGG");
175 $blast_report = $factory->wublast($input);
176 or
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.
187  
188 =cut
189  
190 sub wublast {
191 my ($self, $input1) = @_;
192 $self->io->_io_cleanup();
193 my $executable = 'wublast';
194
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);
198
199 my $blast_report = $self->_generic_local_wublast($executable);
200 }
201  
202 =head2 _generic_local_wublast
203  
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
208  
209 =cut
210  
211 sub _generic_local_wublast {
212 my $self = shift;
213 my $executable = shift;
214
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;
218
219 # run Blast
220 my $blast_report = $self->_runwublast($executable, $param_string);
221 }
222  
223 =head2 _runwublast
224  
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
232  
233 =cut
234  
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;
241 }
242
243 # Use double quotes if executable path have empty spaces
244 if ($exe =~ m/ /) {
245 $exe = "\"$exe\"";
246 }
247 my $commandstring = $exe.$param_string;
248
249 $self->debug("$commandstring\n");
250 system($commandstring) && $self->throw("$executable call crashed: $? | $! | $commandstring\n");
251
252 # get outputfilename
253 my $outfile = $self->o();
254 $blast_obj = Bio::SearchIO->new(-file => $outfile, -format => 'blast');
255
256 return $blast_obj;
257 }
258  
259 =head2 _setparams
260  
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
267  
268 =cut
269  
270 sub _setparams {
271 my ($self, $executable) = @_;
272 my ($attr, $value, @execparams);
273
274 @execparams = @WUBLAST_PARAMS;
275
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');
279
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/);
285
286 my $param_string = $self->SUPER::_setparams(-params => [@execparams],
287 -switches => \@WUBLAST_SWITCH,
288 -dash => 1);
289
290 $self->o($tmp) if ($tmp && $^O !~ /^MSWin/);
291
292 if ($self->quiet()) {
293 $param_string .= ' 2> '.File::Spec->devnull;
294 }
295
296 return $param_string;
297 }
298  
299 1;