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

filter: Statementstmt 0.0% 0 / 111 Branchbran 0.0% 0 / 44 Conditioncond 0.0% 0 / 6 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 17 Podpod 0.0% 0 / 10 totaltotal 0.0% 0 / 188 CC 23 SCAR 50.7
CC
23
Cov
0%
run
342.0
new
6.0
acd
6.0
CRAP 159.9
1 #
2 # BioPerl module for Bio::Tools::Run::EMBOSSApplication
3 #
4 # Copyright Heikki Lehvaslaiho
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::EMBOSSApplication - class for EMBOSS Applications
13  
14 =head1 SYNOPSIS
15  
16 # Get an EMBOSS factory
17 use Bio::Factory::EMBOSS;
18 $f = Bio::Factory::EMBOSS -> new();
19 # Get an EMBOSS application object from the factory
20 $water = $f->program('water') || die "Program not found!\n";
21  
22 # Here is an example of running the application - water can
23 # compare 1 sequence against 1 or more sequences using Smith-Waterman.
24 # Pass a Sequence object and a reference to an array of objects.
25  
26 my $wateroutfile = 'out.water';
27 $water->run({-asequence => $seq_object,
28 -bsequence => \@seq_objects,
29 -gapopen => '10.0',
30 -gapextend => '0.5',
31 -outfile => $wateroutfile});
32  
33 # Now you might want to get the alignment
34 use Bio::AlignIO;
35 my $alnin = Bio::AlignIO->new(-format => 'emboss',
36 -file => $wateroutfile);
37  
38 while ( my $aln = $alnin->next_aln ) {
39 # process the alignment -- these will be Bio::SimpleAlign objects
40 }
41  
42 =head1 DESCRIPTION
43  
44 The EMBOSSApplication class can represent any EMBOSS program. It is
45 created by a L<Bio::Factory::EMBOSS> object.
46  
47 If you want to check command line options before sending them to the
48 program set $prog-E<gt>verbose to positive integer. The ADC
49 description of the available command line options is then parsed in
50 and compared to input.
51  
52 See also L<Bio::Factory::EMBOSS> and L<Bio::Tools::Run::EMBOSSacd>.
53  
54 =head1 FEEDBACK
55  
56 =head2 Mailing Lists
57  
58 User feedback is an integral part of the evolution of this and other
59 Bioperl modules. Send your comments and suggestions preferably to the
60 Bioperl mailing lists Your participation is much appreciated.
61  
62 bioperl-l@bioperl.org - General discussion
63 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
64  
65 =head2 Support
66  
67 Please direct usage questions or support issues to the mailing list:
68  
69 I<bioperl-l@bioperl.org>
70  
71 rather than to the module maintainer directly. Many experienced and
72 reponsive experts will be able look at the problem and quickly
73 address it. Please include a thorough description of the problem
74 with code and data examples if at all possible.
75  
76 =head2 Reporting Bugs
77  
78 Report bugs to the Bioperl bug tracking system to help us keep track
79 the bugs and their resolution. Bug reports can be submitted via the
80 web:
81  
82 http://redmine.open-bio.org/projects/bioperl/
83  
84 =head1 AUTHOR - Heikki Lehvaslaiho
85  
86 Email heikki-at-bioperl-dot-org
87  
88 =head2 CONTRIBUTORS
89  
90 Email: jason-AT-bioperl_DOT_org
91  
92 =head1 APPENDIX
93  
94 The rest of the documentation details each of the object
95 methods. Internal methods are usually preceded with a _
96  
97 =cut
98  
99 # Let the code begin...
100  
101 package Bio::Tools::Run::EMBOSSApplication;
102 use vars qw( $SEQIOLOADED $ALIGNIOLOADED );
103 use strict;
104 use Data::Dumper;
105 use Bio::Tools::Run::EMBOSSacd;
106 use base qw(Bio::Root::Root Bio::Tools::Run::WrapperBase);
107  
108 sub new {
109 my($class, $args) = @_;
110 my $self = $class->SUPER::new();
111  
112 $self->name($args->{'name'});
113 $self->verbose($args->{'verbose'});
114  
115 $self->acd if $self->verbose > 0;
116  
117 return $self;
118 }
119  
120 =head2 run
121  
122 Title : run
123 Usage : $embossapplication->run($attribute_hash)
124 Function: Runs the EMBOSS program.
125 Returns : string or creates files for now; will return objects!
126 Args : hash of input to the program
127  
128 =cut
129  
130 sub run {
131 my ($self, $input) = @_;
132 $self->io->_io_cleanup();
133 # test input
134 $self->debug( Dumper($input) );
135  
136 # parse ACD information
137 $self->acd if $self->verbose > 0;
138  
139 # collect the options into a string
140 my $option_string = '';
141 foreach my $attr (keys %{$input}) {
142 my $attr_name = substr($attr, 1) if substr($attr, 0, 1) =~ /\W/;
143  
144 my $array = 0;
145  
146 if( defined $input->{$attr} && ref($input->{$attr}) ) {
147  
148 my (@pieces);
149  
150 if( $array = (ref($input->{$attr}) =~ /array/i) ) {
151 foreach my $s ( @{$input->{$attr}} ) {
152 @pieces = @{$input->{$attr}};
153 }
154 } else {
155 @pieces = ($input->{$attr});
156 }
157 if( ! defined $pieces[0] ) {
158 # we ignore for now
159 $self->warn("specified a parameter $attr with no value");
160 $input->{$attr} = undef;
161 return;
162 } elsif( $pieces[0]->isa('Bio::PrimarySeqI') ) {
163 unless( $SEQIOLOADED ) {
164 require Bio::SeqIO;
165 $SEQIOLOADED = 1;
166 }
167 my ($tfh,$tempfile) = $self->io->tempfile(-dir => $self->tempdir);
168 my $out = Bio::SeqIO->new(-format => 'fasta',
169 -fh => $tfh);
170 foreach my $seq ( @pieces ) {
171 $out->write_seq($seq);
172 }
173 $out->close();
174 $input->{$attr} = $tempfile;
175 close($tfh);
176 undef $tfh;
177 } elsif( $pieces[0]->isa('Bio::Align::AlignI') ) {
178 unless( $ALIGNIOLOADED ) {
179 require Bio::AlignIO;
180 $ALIGNIOLOADED = 1;
181 }
182 my ($tfh,$tempfile) = $self->io->tempfile();
183 my $out = Bio::AlignIO->new(-format => 'msf',
184 -fh => $tfh);
185 foreach my $p ( @pieces ) {
186 $out->write_aln($p);
187 }
188 $input->{$attr} = $tempfile;
189 close($tfh);
190 undef $tfh;
191 }
192 }
193  
194 # check each argument against ACD
195 if ($self->verbose > 0) {
196  
197 last unless defined $self->acd; # might not have the parser
198  
199 $self->throw("Attribute [$attr] not recognized!\n")
200 unless $self->acd->qualifier($attr);
201 }
202  
203 # print out debugging info
204 $self->debug("Input attr: ". $attr_name. " => ".
205 $input->{$attr}. "\n");
206 $option_string .= " " . $attr;
207 $option_string .= " ". $input->{$attr}
208 if defined $input->{$attr};
209 }
210  
211 # check mandatory attributes against given ones
212 if ($self->verbose > 0) {
213 last unless defined $self->acd; # might not have the parser
214 # $self->acd->mandatory->print;
215 # if ($self->name eq 'water') {
216 # print Dumper($self->acd->mandatory);
217 # }
218 foreach my $attr (keys %{$self->acd->mandatory} ) {
219 last unless defined $self->acd; # might not have the parser
220 unless (defined $input->{$attr}) {
221 print "-" x 38, "\n", "MISSING MANDATORY ATTRIBUTE: $attr\n",
222 "-" x 38, "\n";
223 $self->acd->print($attr) and
224 $self->throw("Program ". $self->name.
225 " needs attribute [$attr]!\n")
226 }
227 }
228 }
229 my $runstring = join (' ', $self->name, $option_string, '-auto');
230 $self->debug( "Command line: ", $runstring, "\n");
231 return `$runstring`;
232 }
233  
234 =head2 acd
235  
236 Title : acd
237 Usage : $embossprogram->acd
238 Function: finds out all the possible qualifiers for this
239 EMBOSS application. They can be used to debug the
240 options given.
241 Throws :
242 Returns : boolean
243 Args :
244  
245 =cut
246  
247 sub acd {
248 my ($self) = @_;
249 unless ( $self->{'_acd'} ) {
250 $self->{'_acd'} =
251 Bio::Tools::Run::EMBOSSacd->new($self->name);
252 }
253 return $self->{'_acd'};
254 }
255  
256 =head2 name
257  
258 Title : name
259 Usage : $embossprogram->name
260 Function: sets/gets the name of the EMBOSS program
261 Setting is done by the EMBOSSFactory object,
262 you should only get it.
263 Throws :
264 Returns : name string
265 Args : None
266  
267 =cut
268  
269 sub name {
270 my ($self,$value) = @_;
271 if (defined $value) {
272 $self->{'_name'} = $value;
273 }
274 return $self->{'_name'};
275 }
276  
277  
278 =head2 descr
279  
280 Title : descr
281 Usage : $embossprogram->descr
282 Function: sets/gets the descr of the EMBOSS program
283 Setting is done by the EMBOSSFactory object,
284 you should only get it.
285 Throws :
286 Returns : description string
287 Args : None
288  
289 =cut
290  
291 sub descr {
292 my ($self,$value) = @_;
293 if (defined $value) {
294 $self->{'_descr'} = $value;
295 }
296 return $self->{'_descr'};
297 }
298  
299  
300 =head2 group
301  
302 Title : group
303 Usage : $embossprogram->group
304 Function: sets/gets the group of the EMBOSS program
305 Setting is done by the EMBOSSFactory object,
306 you should only get it.
307  
308 If the application is assigned into a subgroup
309 use l<subgroup> to get it.
310 Throws :
311 Returns : string, group name
312 Args : group string
313  
314 =cut
315  
316 sub group {
317 my ($self,$value) = @_;
318 if (defined $value) {
319 my ($group, $subgroup) = split ':', $value;
320 $self->{'_group'} = $group;
321 $self->{'_subgroup'} = $subgroup;
322 }
323 return $self->{'_group'};
324 }
325  
326  
327 =head2 subgroup
328  
329 Title : subgroup
330 Usage : $embossprogram->subgroup
331 Function: sets/gets the subgroup of the EMBOSS program
332 Setting is done by the EMBOSSFactory object,
333 you should only get it.
334 Throws :
335 Returns : string, subgroup name; undef if not defined
336 Args : None
337  
338 =cut
339  
340 sub subgroup {
341 my ($self) = @_;
342 return $self->{'_subgroup'};
343 }
344  
345 =head2 program_dir
346  
347 Title : program_dir
348 Usage :
349 Function: Required by WrapperBase
350 Throws :
351 Returns : Name of directory with EMBOSS programs
352 Args :
353  
354 =cut
355  
356 sub program_dir {
357 return Bio::Root::IO->catfile($ENV{EMBOSS_ACDROOT});
358 }
359  
360 =head2 program_path
361  
362 Title : program_path
363 Usage :
364 Function: Required by WrapperBase
365 Throws :
366 Returns : Full path of program
367 Args :
368  
369 =cut
370  
371 sub program_path {
372 my $self = shift;
373 my $name = $self->{_name};
374 my $dir = Bio::Root::IO->catfile($ENV{EMBOSS_ACDROOT});
375 return "$dir/$name";
376 }
377  
378 =head2 executable
379  
380 Title : executable
381 Usage :
382 Function: Required by WrapperBase
383 Throws :
384 Returns : Name of program
385 Args :
386  
387 =cut
388  
389 sub executable {
390 my $self = shift;
391 $self->{_name};
392 }
393  
394 1;