Tools/Run/Glimmer.pm

filter: Statementstmt 45.6% 53 / 116 Branchbran 17.6% 6 / 34 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 76.4% 13 / 17 Podpod 100% 5 / 5 totaltotal 44.7% 77 / 172 CC 20 SCAR 34.3
CC
20
Cov
39%
_run
90.0
run
42.0
_write_seq_file
6.0
CRAP 30.7
« Tools/Run/Phylo/FastTree.pm ↑ Summary DB/SoapEUtilities/Result.pm »
1 # BioPerl module for Bio::Tools::Run::Glimmer
2 #
3 # Please direct questions and support issues to <bioperl-l@bioperl.org>
4 #
5 # Cared for by Bioperl
6 #
7 # Copyright Bioperl, Mark Johnson <johnsonm-at-gmail-dot-com>
8 #
9 # Special thanks to Chris Fields, Sendu Bala
10 #
11 # You may distribute this module under the same terms as perl itself
12 #
13 # POD documentation - main docs before the code
14  
15 =head1 NAME
16  
17 Bio::Tools::Run::Glimmer - Wrapper for local execution of Glimmer,
18 GlimmerM and GlimmerHMM.
19  
20 =head1 SYNOPSIS
21  
22 # glimmer2
23 my $factory =
24 Bio::Tools::Run::Glimmer->new('-program' => 'glimmer3',
25 '-model' => 'model.icm');
26 # glimmer3
27 my $factory =
28 Bio::Tools::Run::Glimmer->new('-program' => 'glimmer2',
29 '-model' => 'model.icm');
30 # glimmerm
31 my $factory =
32 Bio::Tools::Run::Glimmer->new('-program' => 'glimmerm');
33  
34 # glimmerHMM
35 my $factory =
36 Bio::Tools::Run::Glimmer->new('-program' => 'glimmerHMM');
37  
38 # Pass the factory Bio::Seq objects
39 # returns a Bio::Tools::Glimmer object
40 my $glimmer = $factory->run($seq);
41 or
42 my $glimmer = $factor->run(@seq);
43  
44 =head1 DESCRIPTION
45  
46 Wrapper module for the Glimmer family of programs. Should work with
47 all currently available flavors: Glimmer, GlimmerM and GlimmerHMM.
48 However, only Glimmer 2.X and 3.X have been tested.
49  
50 Glimmer is open source and available at
51 L<http://www.cbcb.umd.edu/software/glimmer/>.
52  
53 GlimmerM is open source and available at
54 L<http://www.tigr.org/software/glimmerm/>.
55  
56 GlimmerHMM is open source and available at
57 L<http://www.cbcb.umd.edu/software/GlimmerHMM/>.
58  
59 Note that Glimmer 2.X will only process the first
60 sequence in a fasta file (if you run() more than one
61 sequence at a time, only the first will be processed).
62  
63 Note that Glimmer 3.X produces two output files. This
64 module only passes the .predict file to Bio::Tools::Glimmer.
65  
66 =head1 FEEDBACK
67  
68 =head2 Mailing Lists
69  
70 User feedback is an integral part of the evolution of this and other
71 Bioperl modules. Send your comments and suggestions preferably to one
72 of the Bioperl mailing lists. Your participation is much appreciated.
73  
74 bioperl-l@bioperl.org - General discussion
75 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
76  
77 =head2 Support
78  
79 Please direct usage questions or support issues to the mailing list:
80  
81 I<bioperl-l@bioperl.org>
82  
83 rather than to the module maintainer directly. Many experienced and
84 reponsive experts will be able look at the problem and quickly
85 address it. Please include a thorough description of the problem
86 with code and data examples if at all possible.
87  
88 =head2 Reporting Bugs
89  
90 Report bugs to the Bioperl bug tracking system to help us keep track
91 the bugs and their resolution. Bug reports can be submitted via the
92 web:
93  
94 http://redmine.open-bio.org/projects/bioperl/
95  
96 =head1 AUTHOR - Mark Johnson
97  
98 Email: johnsonm-at-gmail-dot-com
99  
100 =head1 APPENDIX
101  
102 The rest of the documentation details each of the object
103 methods. Internal methods are usually preceded with a _
104  
105 =cut
106  
107 package Bio::Tools::Run::Glimmer;
108  
109 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
110 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
111  
112 2 ▶use Bio::SeqIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
113 2 ▶use Bio::Root::Root;
Subroutine BEGIN: called CC=1 SCAR=0.0
114 2 ▶use Bio::Tools::Run::WrapperBase;
Subroutine BEGIN: called CC=1 SCAR=0.0
115 2 ▶use Bio::Tools::Glimmer;
Subroutine BEGIN: called CC=1 SCAR=0.0
116 2 ▶use English;
Subroutine BEGIN: called CC=1 SCAR=0.0
117 2 ▶use IPC::Run; # Should be okay on WIN32 (See IPC::Run Docs)
Subroutine BEGIN: called CC=1 SCAR=0.0
118  
119 2 ▶use base qw(Bio::Root::Root Bio::Tools::Run::WrapperBase);
Subroutine BEGIN: called CC=1 SCAR=0.0
120  
121 2 our @params = (qw(program model));
122  
123 2 our @glimmer2_params = (qw(C L g i o p q s t w));
124 2 our @glimmer2_switches = (qw(M X f l r));
125  
126 2 our @glimmer3_params = (qw(A C E L M P Z b g i t z));
127 2 our @glimmer3_switches = (qw(X f l o q r));
128  
129 2 our @glimmerM_params = (qw(d g t));
130 2 our @glimmerM_switches = (qw(5 3 f r s));
131  
132 2 our @glimmerHMM_params = (qw(d n p));
133 2 our @glimmerHMM_switches = (qw(f h v));
134  
135 =head2 program_name
136  
137 Title : program_name
138 Usage : $factory>program_name()
139 Function: gets/sets the program name
140 Returns: string
141 Args : string
142  
143 =cut
144  
145 12 ▶sub program_name {
Subroutine program_name: called CC=2 SCAR=7.1
Pod documented
146
147 12 my ($self, $val) = @_;
148
149 12 ▶ $self->program($val) if $val;
Branch: 1 branch
BranchTrueFalseTotal
if $val 0 12 12
150
151 12 return $self->program();
152  
153 }
154  
155 =head2 program_dir
156  
157 Title : program_dir
158 Usage : $factory->program_dir()
159 Function: gets/sets the program dir
160 Returns: string
161 Args : string
162  
163 =cut
164  
165 6 ▶sub program_dir {
Subroutine program_dir: called CC=2 SCAR=7.1
Pod documented
166
167 6 my ($self, $val) = @_;
168
169 6 ▶ $self->{'_program_dir'} = $val if $val;
Branch: 1 branch
BranchTrueFalseTotal
if $val 0 6 6
170
171 6 return $self->{'_program_dir'};
172
173 }
174  
175 =head2 model
176  
177 Title : model
178 Usage : $factory>model()
179 Function: gets/sets the name of the model (icm) file
180 Returns: string
181 Args : string
182  
183 =cut
184  
185 4 ▶sub model {
Subroutine model: called CC=2 SCAR=6.9
Pod documented
186
187 4 my ($self, $val) = @_;
188
189 4 ▶ $self->{'_model'} = $val if $val;
Branch: 1 branch
BranchTrueFalseTotal
if $val 2 2 4
190
191 4 return $self->{'_model'};
192  
193 }
194  
195 =head2 new
196  
197 Title : new
198 Usage : $glimmer->new(@params)
199 Function: creates a new Glimmer factory
200 Returns: Bio::Tools::Run::Glimmer
201 Args :
202  
203 =cut
204  
205 2 ▶sub new {
Subroutine new: called CC=3 SCAR=11.8
Pod documented
206
207 2 my ($class,@args) = @_;
208 2 my $self = $class->SUPER::new(@args);
209
210 2 $self->io->_initialize_io();
211  
212 2 $self->_set_from_args(
213 \@args,
214 -methods => [
215 @params,
216 @glimmer2_params,
217 @glimmer2_switches,
218 @glimmer3_params,
219 @glimmer3_switches,
220 @glimmerM_params,
221 @glimmerM_switches,
222 @glimmerHMM_params,
223 @glimmerHMM_switches
224 ],
225 -create => 1,
226 );
227  
228 2 ▶ unless (defined($self->program())) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->program) 0 2 2
229 0 $self->throw('Must specify program');
230 }
231  
232 2 ▶ unless (defined($self->model())) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->model) 0 2 2
233 0 $self->throw('Must specify model');
234 }
235
236 2 return $self;
237
238 }
239  
240 =head2 run
241  
242 Title : run
243 Usage : $obj->run($seq_file)
244 Function: Runs Glimmer/GlimmerM/GlimmerHMM
245 Returns : A Bio::Tools::Glimmer object
246 Args : An array of Bio::PrimarySeqI objects
247  
248 =cut
249  
250 0 ▶sub run{
Subroutine run: not called CC=6 SCAR=37.4
Pod documented
251
252 0 my ($self, @seq) = @_;
253  
254 0 ▶ unless (@seq) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@seq) 0 0 0
255 0 $self->throw("Must supply at least one Bio::PrimarySeqI");
256 }
257
258 0 foreach my $seq (@seq) {
259
260 0 ▶ unless ($seq->isa('Bio::PrimarySeqI')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($seq->isa("Bio::PrimarySeqI")) 0 0 0
261 0 $self->throw("Object does not implement Bio::PrimarySeqI");
262 }
263
264 }
265  
266 0 my $program_name = $self->program_name();
267 0 my $file_name = $self->_write_seq_file(@seq);
268  
269 0 my @run_args = ( $file_name );
270  
271 # Glimmer 2.X ignores sequences after the first in a fasta file
272 # Glimmer 3.X will process multiple sequences at once
273 0 ▶ if ($program_name eq 'glimmer2') {
Branch: 1 branch
BranchTrueFalseTotal
if ($program_name eq "glimmer2") 0 0 0
274 0 ▶ if (@seq > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@seq > 1) 0 0 0
275 0 $self->warn("Program $program_name processes one sequence at a time");
276 }
277 0 push @run_args, $seq[0]->display_id();
278 0 push @run_args, $seq[0]->length();
279 }
280
281 0 return $self->_run(@run_args);
282
283 }
284  
285 =head2 _run
286  
287 Title : _run
288 Usage : $obj->_run()
289 Function: Internal(not to be used directly)
290 Returns : An instance of Bio::Tools::Glimmer
291 Args : file name, sequence identifier (optional)
292  
293 =cut
294  
295 0 ▶sub _run {
Subroutine _run: not called CC=9 SCAR=45.0
296
297 0 my ($self, $seq_file_name, $seq_id, $seq_length) = @_;
298
299 0 my @cmd = (
300 $self->executable(),
301 $seq_file_name,
302 $self->model(),
303 split(/\s+/, $self->_setparams()),
304 );
305  
306 0 my $cmd = join(' ', @cmd);
307 0 $self->debug("Glimmer Command = $cmd");
308
309 0 my $program_name = $self->program_name();
310 0 my ($output_fh, $output_file_name, $detail_file_name);
311 0 my ($program_stdout, $program_stderr);
312
313 0 my @ipc_args = (\@cmd, \undef);
314
315 # No STDOUT option for glimmer3, it takes a
316 # 'tag' argument, and outputs tag.predict and
317 # tag.detail. It seems that tag can be a path,
318 # which is handy.
319 0 ▶ if ($program_name eq 'glimmer3') {
Branch: 1 branch
BranchTrueFalseTotal
if ($program_name eq 'glimmer3') { } 0 0 0
320
321 0 my $temp_dir = $self->tempdir();
322 0 my $glimmer3_tag = "$temp_dir/glimmer3";
323  
324 0 push @cmd, $glimmer3_tag;
325 0 $output_file_name = "$glimmer3_tag.predict";
326 0 $detail_file_name = "$glimmer3_tag.detail";
327 0 push @ipc_args, \$program_stdout, \$program_stderr;
328
329 }
330 else {
331
332 0 ($output_fh, $output_file_name) = $self->io->tempfile(-dir=>$self->tempdir());
333 0 close($output_fh);
334 0 push @ipc_args, '>', $output_file_name;
335 0 push @ipc_args, '2>', \$program_stderr;
336
337 }
338  
339 # Run the program via IPC::Run so:
340 # 1) The console doesn't get cluttered up with the program's STDERR/STDOUT
341 # 2) We don't have to embed STDERR/STDOUT redirection in $cmd
342 # 3) We don't have to deal with signal handling (IPC::Run should take care
343 # of everything automagically.
344  
345 0 eval {
346 0 ▶ IPC::Run::run(@ipc_args) || die $CHILD_ERROR;;
Branch: 1 branch
BranchTrueFalseTotal
IPC::Run::run(@ipc_args) or die $Bio::Tools::Run::Glimmer::CHILD_ERROR 0 0 0
347 };
348  
349 0 ▶ if ($EVAL_ERROR) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Bio::Tools::Run::Glimmer::EVAL_ERROR) 0 0 0
350 0 $self->throw("Glimmer call crashed: $EVAL_ERROR");
351 }
352  
353 0 ▶ $self->debug(join("\n", 'Glimmer STDOUT:', $program_stdout)) if $program_stdout;
Branch: 1 branch
BranchTrueFalseTotal
if $program_stdout 0 0 0
354 0 ▶ $self->debug(join("\n", 'Glimmer STDERR:', $program_stderr)) if $program_stderr;
Branch: 1 branch
BranchTrueFalseTotal
if $program_stderr 0 0 0
355
356 0 my %parser_args = (-file => $output_file_name);
357  
358 # Pass along $seq_id and $seq_length if they were provided
359 # (only should be for glimmer2).
360 0 ▶ if (defined($seq_id)) { $parser_args{-seqname } = $seq_id; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $seq_id) 0 0 0
361 0 ▶ if (defined($seq_length)) { $parser_args{-seqlength} = $seq_length; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $seq_length) 0 0 0
362  
363 # Pass along the name of extra output file, with handy information about
364 # sequence lengths (only produced by glimmer3)
365 0 ▶ if (defined($detail_file_name)) { $parser_args{-detail} = $detail_file_name; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $detail_file_name) 0 0 0
366
367 0 return Bio::Tools::Glimmer->new(%parser_args);
368
369 }
370  
371 0 ▶sub _setparams {
Subroutine _setparams: not called CC=1 SCAR=6.9
372  
373 0 my ($self) = @_;
374  
375 0 my $param_string = $self->SUPER::_setparams(
376 -params => [
377 @glimmer2_params,
378 @glimmer3_params,
379 @glimmerM_params,
380 @glimmerHMM_params,
381 ],
382 -switches => [
383 @glimmer2_switches,
384 @glimmer2_switches,
385 @glimmerM_switches,
386 @glimmerHMM_switches,
387 ],
388 -dash => 1
389  
390 );
391
392 # Kill leading and trailing whitespace
393 0 $param_string =~ s/^\s+//g;
394 0 $param_string =~ s/\s+$//g;
395  
396 0 return $param_string;
397  
398 }
399  
400 =head2 _write_seq_file
401  
402 Title : _write_seq_file
403 Usage : obj->_write_seq_file($seq) or obj->_write_seq_file(@seq)
404 Function: Internal(not to be used directly)
405 Returns : Name of a temp file containing program output
406 Args : One or more Bio::PrimarySeqI objects
407  
408 =cut
409  
410 0 ▶sub _write_seq_file {
Subroutine _write_seq_file: not called CC=2 SCAR=17.9
411  
412 0 my ($self, @seq) = @_;
413
414 0 my ($fh, $file_name) = $self->io->tempfile(-dir=>$self->tempdir());
415 0 my $out = Bio::SeqIO->new(-fh => $fh , '-format' => 'Fasta');
416  
417 0 foreach my $seq (@seq){
418 0 $out->write_seq($seq);
419 }
420  
421 0 close($fh);
422 0 $out->close();
423
424 0 return $file_name;
425  
426 }
427  
428 2 1;
« Tools/Run/Phylo/FastTree.pm ↑ Summary DB/SoapEUtilities/Result.pm »