Tools/Run/Infernal.pm

filter: Statementstmt 21.9% 73 / 332 Branchbran 11.2% 21 / 186 Conditioncond 5.1% 4 / 78 MC/DCmcdc 0.0% 0 / 46 Subroutinesub 40.6% 13 / 32 Podpod 100% 21 / 21 totaltotal 18.9% 132 / 695 CC 131 SCAR 62.0
CC
131
Cov
16%
to_exe_string
1560.0
_run
552.0
_dump_params
272.0
CRAP 491.2
↑ Summary Tools/Run/StandAloneBlastPlus/BlastMethods.pm »
1 #
2 # You may distribute this module under the same terms as perl itself
3 #
4 # POD documentation - main docs before the code
5 #
6 # _history
7 #
8 # March 2007 - first full implementation; needs some file IO tweaking between
9 # runs but works for now
10 # April 2008 - add 0.81 parameters (may be removed in the 1.0 release)
11 #
12 # July 2009 - updated for v1.0. No longer supporting pre-1.0 Infernal
13  
14 =head1 NAME
15  
16 Bio::Tools::Run::Infernal - Wrapper for local execution of cmalign, cmbuild,
17 cmsearch, cmscore
18  
19 =head1 SYNOPSIS
20  
21 # parameters which are switches are set with any value that evals TRUE,
22 # others are set to a specific value
23  
24 my $factory = Bio::Tools::Run::Infernal->new(@params);
25  
26 # run cmalign|cmbuild|cmsearch|cmscore|cmemit directly as a wrapper method
27 # this resets the program flag if previously set
28  
29 $factory->cmsearch(@seqs); # searches Bio::PrimarySeqI's based on set cov. model
30 # saves output to optional outfile_name, returns
31 # Bio::SearchIO
32  
33 # only values which are allowed for a program are set, so one can use the same
34 # wrapper for the following...
35  
36 $factory->cmalign(@seqs); # aligns Bio::PrimarySeqI's to a set cov. model,
37 # --merge option allows two alignments generated
38 # from the same CM to be merged.
39 # output to outfile_name, returns Bio::AlignIO
40 $factory->cmscore(); # scores set cov. model against Bio::PrimarySeqI,
41 # output to outfile_name/STDOUT.
42 $factory->cmbuild($aln); # builds covariance model based on alignment
43 # CM to outfile_name or model_file (one is required
44 # here), output to STDOUT.
45 $factory->cmemit(); # emits sequence from specified cov. model;
46 # set one if no file specified. output to
47 # outfile_name, returns Bio::SeqIO or (if -a is set)
48 # Bio::AlignIO
49 $factory->cmcalibrate($file); # calibrates specified cov. model; output to
50 # STDOUT
51 $factory->cmstat($file); # summary stats for cov. model; set one if no file
52 # specified; output to STDOUT
53  
54 # run based on the setting of the program parameter
55  
56 my $factory = Bio::Tools::Run::Infernal->new(-program => 'cmsearch',
57 @params);
58 my $search = $factory->run($seq);
59  
60 # using cmsearch returns a Bio::SearchIO object
61  
62 while (my $result = $searchio->next_result){
63 while(my $hit = $result->next_hit){
64 while (my $hsp = $hit->next_hsp){
65 print join("\t", ( $r->query_name,
66 $hit->name,
67 $hsp->hit->start,
68 $hsp->hit->end,
69 $hsp->meta,
70 $hsp->score,
71 )), "\n";
72 }
73 }
74 }
75  
76 =head1 DESCRIPTION
77  
78 Wrapper module for Sean Eddy's Infernal suite of programs. The current
79 implementation runs cmsearch, cmcalibrate, cmalign, cmemit, cmbuild, cmscore,
80 and cmstat. cmsearch will return a Bio::SearchIO, cmemit a Bio::SeqIO/AlignIO,
81 and cmalign a Bio::AlignIO. All others send output to STDOUT. Optionally,
82 any program's output can be redirected to outfile_name.
83  
84 We HIGHLY suggest upgrading to Infernal 1.0. In that spirit, this wrapper now
85 supports parameters for Infernal 1.0 only; for wrapping older versions of
86 Infernal we suggest using the version of Bio::Tools::Run::Infernal that came
87 with previous versions of BioPerl-run.
88  
89 NOTE: Due to conflicts in the way Infernal parameters are now formatted vs.
90 subroutine naming in Perl (specifically the inclusion of hyphens) and due to the
91 very large number of parameters available, setting and resetting parameters via
92 set_parameters() and reset_parameters() is required. All valid parameters can
93 be set, but only ones valid for the executable set via program()/program_name()
94 are used for calling the executables, the others are silently ignored.
95  
96 =head1 FEEDBACK
97  
98 =head2 Mailing Lists
99  
100 User feedback is an integral part of the evolution of this and other
101 Bioperl modules. Send your comments and suggestions preferably to one
102 of the Bioperl mailing lists. Your participation is much appreciated.
103  
104 bioperl-l@bioperl.org - General discussion
105 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
106  
107 =head2 Support
108  
109 Please direct usage questions or support issues to the mailing list:
110  
111 I<bioperl-l@bioperl.org>
112  
113 rather than to the module maintainer directly. Many experienced and
114 reponsive experts will be able look at the problem and quickly
115 address it. Please include a thorough description of the problem
116 with code and data examples if at all possible.
117  
118 =head2 Reporting Bugs
119  
120 Report bugs to the Bioperl bug tracking system to help us keep track
121 the bugs and their resolution. Bug reports can be submitted via the
122 web:
123  
124 http://redmine.open-bio.org/projects/bioperl/
125  
126 =head1 AUTHOR - Chris Fields
127  
128 Email: cjfields-at-uiuc-dot-edu
129  
130 =head1 CONTRIBUTORS
131  
132 cjfields-at-uiuc-dot-edu
133  
134 =head1 APPENDIX
135  
136 The rest of the documentation details each of the object
137 methods. Internal methods are usually preceded with a _
138  
139 =cut
140  
141 package Bio::Tools::Run::Infernal;
142  
143 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
144 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
145 1 ▶use base qw(Bio::Root::Root Bio::Tools::Run::WrapperBase Bio::ParameterBaseI);
Subroutine BEGIN: called CC=1 SCAR=0.0
146  
147 1 ▶use Bio::SeqIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
148 1 ▶use Bio::SearchIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
149 1 ▶use Bio::AlignIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
150 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
151  
152 # yes, these are the current parameters
153 1 our %INFERNAL_PARAMS = (
154 'A' => ['switch', '-', qw(cmbuild)],
155 'E' => ['param', '-', qw(cmsearch cmstat)],
156 'F' => ['switch', '-', qw(cmbuild)],
157 'Lmax' => ['param', '--', qw(cmscore)],
158 'Lmin' => ['param', '--', qw(cmscore)],
159 'T' => ['param', '-', qw(cmsearch cmstat)],
160 'Wbeta' => ['param', '--', qw(cmbuild)],
161 'Z' => ['param', '-', qw(cmsearch cmstat)],
162 'a' => ['switch', '-', qw(cmbuild cmemit cmscore)],
163 'afile' => ['param', '--', qw(cmstat)],
164 'ahmm' => ['param', '--', qw(cmemit)],
165 'all' => ['switch', '--', qw(cmstat)],
166 'aln-hbanded' => ['switch', '--', qw(cmsearch)],
167 'aln-optacc' => ['switch', '--', qw(cmsearch)],
168 'aln2bands' => ['switch', '--', qw(cmscore cmsearch)],
169 'banddump' => ['param', '--', qw(cmalign)],
170 'begin' => ['param', '--', qw(cmemit)],
171 'beta' => ['param', '--', qw(cmalign cmscore cmsearch cmstat)],
172 'betae' => ['param', '--', qw(cmscore)],
173 'betas' => ['param', '--', qw(cmscore)],
174 'bfile' => ['param', '--', qw(cmstat)],
175 'binary' => ['switch', '--', qw(cmbuild)],
176 'bits' => ['switch', '--', qw(cmstat)],
177 'bottomonly' => ['switch', '--', qw(cmsearch)],
178 'c' => ['switch', '-', qw(cmemit)],
179 'call' => ['switch', '--', qw(cmbuild)],
180 'cdump' => ['param', '--', qw(cmbuild)],
181 'cfile' => ['param', '--', qw(cmbuild)],
182 'checkfb' => ['switch', '--', qw(cmalign)],
183 'checkpost' => ['switch', '--', qw(cmalign)],
184 'cmL' => ['param', '--', qw(cmstat)],
185 'cmaxid' => ['param', '--', qw(cmbuild)],
186 'cmtbl' => ['param', '--', qw(cmbuild)],
187 'corig' => ['switch', '--', qw(cmbuild)],
188 'ctarget' => ['param', '--', qw(cmbuild)],
189 'cyk' => ['switch', '--', qw(cmalign cmbuild cmsearch)],
190 'devhelp' => ['switch', '--', qw(cmalign cmbuild cmcalibrate cmemit cmscore cmsearch)],
191 'dlev' => ['param', '--', qw(cmalign)],
192 'dna' => ['switch', '--', qw(cmalign cmemit cmsearch)],
193 'eX' => ['param', '--', qw(cmbuild)],
194 'eent' => ['switch', '--', qw(cmbuild)],
195 'efile' => ['param', '--', qw(cmstat)],
196 'ehmmre' => ['param', '--', qw(cmbuild)],
197 'elself' => ['param', '--', qw(cmbuild)],
198 'emap' => ['param', '--', qw(cmbuild)],
199 'emit' => ['switch', '--', qw(cmscore)],
200 'end' => ['param', '--', qw(cmemit)],
201 'enone' => ['switch', '--', qw(cmbuild)],
202 'ere' => ['param', '--', qw(cmbuild)],
203 'exp' => ['param', '--', qw(cmemit)],
204 'exp-T' => ['param', '--', qw(cmcalibrate)],
205 'exp-beta' => ['param', '--', qw(cmcalibrate)],
206 'exp-cmL-glc' => ['param', '--', qw(cmcalibrate)],
207 'exp-cmL-loc' => ['param', '--', qw(cmcalibrate)],
208 'exp-ffile' => ['param', '--', qw(cmcalibrate)],
209 'exp-fract' => ['param', '--', qw(cmcalibrate)],
210 'exp-gc' => ['param', '--', qw(cmcalibrate)],
211 'exp-hfile' => ['param', '--', qw(cmcalibrate)],
212 'exp-hmmLn-glc' => ['param', '--', qw(cmcalibrate)],
213 'exp-hmmLn-loc' => ['param', '--', qw(cmcalibrate)],
214 'exp-hmmLx' => ['param', '--', qw(cmcalibrate)],
215 'exp-no-qdb' => ['switch', '--', qw(cmcalibrate)],
216 'exp-pfile' => ['param', '--', qw(cmcalibrate)],
217 'exp-qqfile' => ['param', '--', qw(cmcalibrate)],
218 'exp-random' => ['switch', '--', qw(cmcalibrate)],
219 'exp-sfile' => ['param', '--', qw(cmcalibrate)],
220 'exp-tailn-cglc' => ['param', '--', qw(cmcalibrate)],
221 'exp-tailn-cloc' => ['param', '--', qw(cmcalibrate)],
222 'exp-tailn-hglc' => ['param', '--', qw(cmcalibrate)],
223 'exp-tailn-hloc' => ['param', '--', qw(cmcalibrate)],
224 'exp-tailp' => ['param', '--', qw(cmcalibrate)],
225 'exp-tailxn' => ['param', '--', qw(cmcalibrate)],
226 'fil-E-hmm' => ['param', '--', qw(cmsearch)],
227 'fil-E-qdb' => ['param', '--', qw(cmsearch)],
228 'fil-F' => ['param', '--', qw(cmcalibrate)],
229 'fil-N' => ['param', '--', qw(cmcalibrate)],
230 'fil-Smax-hmm' => ['param', '--', qw(cmsearch)],
231 'fil-T-hmm' => ['param', '--', qw(cmsearch)],
232 'fil-T-qdb' => ['param', '--', qw(cmsearch)],
233 'fil-aln2bands' => ['switch', '--', qw(cmcalibrate)],
234 'fil-beta' => ['param', '--', qw(cmsearch)],
235 'fil-dfile' => ['param', '--', qw(cmcalibrate)],
236 'fil-gemit' => ['switch', '--', qw(cmcalibrate)],
237 'fil-no-hmm' => ['switch', '--', qw(cmsearch)],
238 'fil-no-qdb' => ['switch', '--', qw(cmsearch)],
239 'fil-nonbanded' => ['switch', '--', qw(cmcalibrate)],
240 'fil-tau' => ['param', '--', qw(cmcalibrate)],
241 'fil-xhmm' => ['param', '--', qw(cmcalibrate)],
242 'fins' => ['switch', '--', qw(cmalign cmbuild)],
243 'forecast' => ['param', '--', qw(cmcalibrate cmsearch)],
244 'forward' => ['switch', '--', qw(cmscore cmsearch)],
245 'g' => ['switch', '-', qw(cmsearch cmstat)],
246 'ga' => ['switch', '--', qw(cmsearch cmstat)],
247 'gapthresh' => ['param', '--', qw(cmalign cmbuild)],
248 'gcfile' => ['param', '--', qw(cmsearch)],
249 'ge' => ['switch', '--', qw(cmstat)],
250 'gfc' => ['switch', '--', qw(cmstat)],
251 'gfi' => ['switch', '--', qw(cmstat)],
252 'gibbs' => ['switch', '--', qw(cmbuild)],
253 'gtbl' => ['param', '--', qw(cmbuild)],
254 'gtree' => ['param', '--', qw(cmbuild)],
255 'h' => ['switch', '-', qw(cmalign cmbuild cmcalibrate cmemit cmscore cmsearch cmstat)],
256 'hbanded' => ['switch', '--', qw(cmalign cmscore cmsearch)],
257 'hmm-W' => ['param', '--', qw(cmsearch)],
258 'hmm-cW' => ['param', '--', qw(cmsearch)],
259 'hmmL' => ['param', '--', qw(cmstat)],
260 'hsafe' => ['switch', '--', qw(cmalign cmscore)],
261 'ignorant' => ['switch', '--', qw(cmbuild)],
262 'iins' => ['switch', '--', qw(cmbuild)],
263 'infile' => ['param', '--', qw(cmscore)],
264 'informat' => ['param', '--', qw(cmalign cmbuild cmsearch)],
265 'inside' => ['switch', '--', qw(cmalign cmscore cmsearch)],
266 'l' => ['switch', '-', qw(cmalign cmbuild cmemit cmscore)],
267 'lambda' => ['param', '--', qw(cmsearch)],
268 'le' => ['switch', '--', qw(cmstat)],
269 'lfc' => ['switch', '--', qw(cmstat)],
270 'lfi' => ['switch', '--', qw(cmstat)],
271 'm' => ['switch', '-', qw(cmstat)],
272 'matchonly' => ['switch', '--', qw(cmalign)],
273 'merge' => ['switch', '--', qw(cmalign)],
274 'mpi' => ['switch', '--', qw(cmalign cmcalibrate cmscore cmsearch)],
275 'mxsize' => ['param', '--', qw(cmalign cmbuild cmcalibrate cmscore cmsearch)],
276 'n' => ['param', '-', qw(cmbuild cmemit cmscore)],
277 'nc' => ['switch', '--', qw(cmsearch cmstat)],
278 'no-null3' => ['switch', '--', qw(cmalign cmcalibrate cmscore cmsearch)],
279 'no-qdb' => ['switch', '--', qw(cmsearch)],
280 'noalign' => ['switch', '--', qw(cmsearch)],
281 'nobalance' => ['switch', '--', qw(cmbuild)],
282 'nodetach' => ['switch', '--', qw(cmbuild)],
283 'nonbanded' => ['switch', '--', qw(cmalign cmbuild cmscore)],
284 'null' => ['param', '--', qw(cmbuild)],
285 'null2' => ['switch', '--', qw(cmsearch)],
286 'o' => ['param', '-', qw(cmalign cmsearch)],
287 'old' => ['switch', '--', qw(cmscore)],
288 'onepost' => ['switch', '--', qw(cmalign)],
289 'optacc' => ['switch', '--', qw(cmalign)],
290 'outfile' => ['param', '--', qw(cmscore)],
291 'p' => ['switch', '-', qw(cmalign cmsearch)],
292 'pad' => ['switch', '--', qw(cmscore)],
293 'pbegin' => ['param', '--', qw(cmalign cmcalibrate cmemit cmscore cmsearch)],
294 'pbswitch' => ['param', '--', qw(cmbuild)],
295 'pebegin' => ['switch', '--', qw(cmalign cmcalibrate cmemit cmscore cmsearch)],
296 'pend' => ['param', '--', qw(cmalign cmcalibrate cmemit cmscore cmsearch)],
297 'pfend' => ['param', '--', qw(cmalign cmcalibrate cmemit cmscore cmsearch)],
298 'prior' => ['param', '--', qw(cmbuild)],
299 'q' => ['switch', '-', qw(cmalign)],
300 'qdb' => ['switch', '--', qw(cmalign cmscore)],
301 'qdbboth' => ['switch', '--', qw(cmscore)],
302 'qdbfile' => ['param', '--', qw(cmstat)],
303 'qdbsmall' => ['switch', '--', qw(cmscore)],
304 'random' => ['switch', '--', qw(cmscore)],
305 'rdump' => ['param', '--', qw(cmbuild)],
306 'refine' => ['param', '--', qw(cmbuild)],
307 'regress' => ['param', '--', qw(cmalign cmbuild cmscore)],
308 'resonly' => ['switch', '--', qw(cmalign)],
309 'rf' => ['switch', '--', qw(cmalign cmbuild)],
310 'rna' => ['switch', '--', qw(cmalign cmemit cmsearch)],
311 'rsearch' => ['param', '--', qw(cmbuild)],
312 'rtrans' => ['switch', '--', qw(cmsearch)],
313 's' => ['param', '-', qw(cmalign cmbuild cmcalibrate cmemit cmscore)],
314 'sample' => ['switch', '--', qw(cmalign)],
315 'scoreonly' => ['switch', '--', qw(cmscore)],
316 'search' => ['switch', '--', qw(cmscore cmstat)],
317 'seqfile' => ['param', '--', qw(cmstat)],
318 'sfile' => ['param', '--', qw(cmstat)],
319 'shmm' => ['param', '--', qw(cmemit)],
320 'small' => ['switch', '--', qw(cmalign)],
321 'stall' => ['switch', '--', qw(cmalign cmscore cmsearch)],
322 'sub' => ['switch', '--', qw(cmalign cmbuild cmscore)],
323 'sums' => ['switch', '--', qw(cmalign cmsearch)],
324 'tabfile' => ['param', '--', qw(cmsearch)],
325 'tau' => ['param', '--', qw(cmalign cmbuild cmscore cmsearch)],
326 'taue' => ['param', '--', qw(cmscore)],
327 'taus' => ['param', '--', qw(cmscore)],
328 'tc' => ['switch', '--', qw(cmsearch cmstat)],
329 'tfile' => ['param', '--', qw(cmalign cmbuild cmemit cmscore)],
330 'toponly' => ['switch', '--', qw(cmsearch cmstat)],
331 'u' => ['switch', '-', qw(cmemit)],
332 'v' => ['switch', '-', qw(cmbuild cmcalibrate)],
333 'viterbi' => ['switch', '--', qw(cmalign cmscore cmsearch)],
334 'wblosum' => ['switch', '--', qw(cmbuild)],
335 'wgiven' => ['switch', '--', qw(cmbuild)],
336 'wgsc' => ['switch', '--', qw(cmbuild)],
337 'wid' => ['param', '--', qw(cmbuild)],
338 'withali' => ['param', '--', qw(cmalign)],
339 'withpknots' => ['switch', '--', qw(cmalign)],
340 'wnone' => ['switch', '--', qw(cmbuild)],
341 'wpb' => ['switch', '--', qw(cmbuild)],
342 'x' => ['switch', '-', qw(cmsearch)],
343 'xfile' => ['param', '--', qw(cmstat)],
344 );
345  
346 1 our %INFERNAL_PROGRAM = (
347 'cmalign' => "cmalign [-options] <cmfile> <sequence file>\n".
348 'cmalign [-options] --merge <cmfile> <msafile1> <msafile2>',
349 'cmbuild' => 'cmbuild [-options] <cmfile output> <alignment file>',
350 'cmcalibrate' => 'cmcalibrate [-options] <cmfile>',
351 'cmemit' => 'cmemit [-options] <cmfile> <sequence output file>',
352 'cmscore' => 'cmscore [-options] <cmfile>',
353 'cmsearch' => 'cmsearch [-options] <cmfile> <sequence file>',
354 'cmstat' => 'cmstat [-options] <cmfile>',
355 );
356  
357 # this is a simple lookup for easy validation for passed methods
358 1 our %LOCAL_PARAMS = map {$_ => 1} qw(program outfile tempfile model);
359  
360 =head2 new
361  
362 Title : new
363 Usage : my $wrapper = Bio::Tools::Run::Infernal->new(@params)
364 Function: creates a new Infernal factory
365 Returns: Bio::Tools::Run::Infernal wrapper
366 Args : list of parameters
367  
368 =cut
369  
370 1 ▶sub new {
Subroutine new: called CC=8 SCAR=23.2
Pod documented
371 1 my ($class,@args) = @_;
372 1 my $self = $class->SUPER::new(@args);
373
374 # these are specific parameters we do not want passed on to set_parameters
375 1 my ($program, $model, $validate, $q, $o1, $o2) =
376 $self->_rearrange([qw(PROGRAM
377 MODEL_FILE
378 VALIDATE_PARAMETERS
379 QUIET
380 OUTFILE_NAME
381 O)], @args);
382
383 1 ▶ if ($o1 && $o2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o1 and $o2) 0 1 1
Condition33%1/3
$o1 and $o2
!ll&&!rl&&r
100
MC/DC0%0/2
$o1 and $o2
$o1 $o2
Truth table33%1/3
A and B
A= $o1B= $o2
ABresult
0X0
100
111
384 0 $self->warn("Only assign to either -outfile_name or -o, not both;");
385 }
386 1 ▶ my $out = $o1 || $o2;
Condition33%1/3
$o1 || $o2
l!l&&r!l&&!r
001
MC/DC0%0/2
$o1 || $o2
$o1 $o2
Truth table33%1/3
A || B
A= $o1B= $o2
ABresult
1X1
011
000
387 1 $self->validate_parameters($validate);
388 1 ▶ $q && $self->quiet($q);
Branch: 1 branch
BranchTrueFalseTotal
$q and $self->quiet($q) 0 1 1
389 1 ▶ $program && $self->program($program);
Branch: 1 branch
BranchTrueFalseTotal
$program and $self->program($program) 1 0 1
390 1 ▶ $model && $self->model_file($model);
Branch: 1 branch
BranchTrueFalseTotal
$model and $self->model_file($model) 0 1 1
391 1 ▶ $out ||= '';
Condition50%1/2
$out ||= ""
l!l
01
MC/DC0%0/1
$out ||= ""
$out
Truth table50%1/2
A
A= $out
Aresult
11
00
392 1 $self->outfile_name($out);
393 1 $self->io->_initialize_io();
394 1 $self->set_parameters(@args);
395 1 return $self;
396 }
397  
398 =head2 program
399  
400 Title : program
401 Usage : $obj->program()
402 Function: Set the program called when run() is used. Synonym of
403 program_name()
404 Returns : String (program name)
405 Args : String (program name)
406 Status : Unstable (may delegate to program_name, which is the interface method)
407  
408 =cut
409  
410 2 ▶sub program {
Subroutine program: called CC=1 SCAR=0.0
Pod documented
411 2 my $self = shift;
412 2 return $self->program_name(@_);
413 }
414  
415 =head2 program_name
416  
417 Title : program_name
418 Usage : $factory>program_name()
419 Function: holds the program name
420 Returns: string
421 Args : None
422  
423 =cut
424  
425 8 ▶sub program_name {
Subroutine program_name: called CC=5 SCAR=16.1
Pod documented
426 8 my ($self) = shift;
427 8 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 7 8
428 1 my $p = shift;
429 $self->throw("Program '$p' not supported")
430 1 ▶ if !exists $INFERNAL_PROGRAM{lc $p};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Bio::Tools::Run::Infernal::INFERNAL_PROGRAM{lc $p} 0 1 1
431 1 $self->{'_program'} = lc $p;
432 # set up cache of valid parameters
433 1 ▶ while (my ($p, $data) = each %INFERNAL_PARAMS) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %Bio::Tools::Run::Infernal::INFERNAL_PARAMS) 190 1 191
434 190 my %in_exe = map {$_ => 1} @$data[2..$#{$data}];
435 190 ▶ $self->{valid_params}->{$p} = 1 if exists $in_exe{$self->{'_program'}};
Branch: 1 branch
BranchTrueFalseTotal
if exists $in_exe{$self->{"_program"}} 54 136 190
436 }
437 }
438 8 return $self->{'_program'};
439 }
440  
441 =head2 model_file
442  
443 Title : model_file
444 Usage : $obj->model_file()
445 Function: Set the model file used when run() is called.
446 Returns : String (file location of covariance model)
447 Args : String (file location of covariance model)
448  
449 =cut
450  
451 0 ▶sub model_file {
Subroutine model_file: not called CC=2 SCAR=17.9
Pod documented
452 0 my $self = shift;
453 0 ▶ return $self->{'_model_file'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
454 0 return $self->{'_model_file'};
455 }
456  
457 =head2 program_dir
458  
459 Title : program_dir
460 Usage : $factory->program_dir(@params)
461 Function: returns the program directory, obtained from ENV variable.
462 Returns: string
463 Args :
464  
465 =cut
466  
467 3 ▶sub program_dir {
Subroutine program_dir: called CC=3 SCAR=12.5
Pod documented
468 3 my ($self, $dir) = @_;
469 3 ▶ if ($dir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir) 0 3 3
470 0 $self->{_program_dir} = $dir;
471 }
472 3 ▶ return Bio::Root::IO->catfile($ENV{INFERNALDIR}) || '';
Condition50%1/2
'Bio::Root::IO'->catfile($ENV{'INFERNALDIR'}) || ''
l!l
03
MC/DC0%0/1
'Bio::Root::IO'->catfile($ENV{'INFERNALDIR'}) || ''
'Bio::Root::IO'->catfile($ENV{'INFERNALDIR'})
Truth table50%1/2
A
A= 'Bio::Root::IO'->catfile($ENV{'INFERNALDIR'})
Aresult
11
00
473 }
474  
475 =head2 version
476  
477 Title : version
478 Usage : $v = $prog->version();
479 Function: Determine the version number of the program (uses cmsearch)
480 Example :
481 Returns : float or undef
482 Args : none
483  
484 =cut
485  
486 0 ▶sub version {
Subroutine version: not called CC=5 SCAR=34.0
Pod documented
487 0 my ($self) = @_;
488 0 ▶ return unless $self->executable;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->executable 0 0 0
489 0 my $exe = $self->executable;
490 0 my $string = `$exe -h 2>&1`;
491 0 my $v;
492 0 ▶ if ($string =~ m{Infernal\s([\d.]+)}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /Infernal\s([\d.]+)/) 0 0 0
493 0 $v = $1;
494 0 ▶ $self->deprecated(-message => "Only Infernal 1.0 and above is supported.",
Branch: 1 branch
BranchTrueFalseTotal
if $v < 1 0 0 0
495 -version => 1.006001) if $v < 1;
496 }
497 0 ▶ return $self->{'_progversion'} = $v || undef;
Condition0%0/2
$v || undef
l!l
00
MC/DC0%0/1
$v || undef
$v
Truth table0%0/2
A
A= $v
Aresult
11
00
498 }
499  
500 =head2 run
501  
502 Title : run
503 Usage : $obj->run($seqFile)
504 Function: Runs Infernal and returns Bio::SearchIO
505 Returns : A Bio::SearchIO
506 Args : A Bio::PrimarySeqI or file name
507  
508 =cut
509  
510 # TODO: update to accept multiple seqs, alignments
511 0 ▶sub run {
Subroutine run: not called CC=5 SCAR=34.0
Pod documented
512 0 my ($self,@seq) = @_;
513 0 ▶ if (ref $seq[0] && $seq[0]->isa("Bio::PrimarySeqI") ){# it is an object
Branch: 2 branches
BranchTrueFalseTotal
if (ref $seq[0] and $seq[0]->isa('Bio::PrimarySeqI')) { } 0 0 0
elsif (ref $seq[0] and $seq[0]->isa('Bio::Align::AlignI')) { } 0 0 0
Condition0%0/3
ref $seq[0] and $seq[0]->isa("Bio::PrimarySeqI")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $seq[0] and $seq[0]->isa("Bio::PrimarySeqI")
ref $seq[0] $seq[0]->isa("Bio::PrimarySeqI")
Truth table0%0/3
A and B
A= ref $seq[0]B= $seq[0]->isa("Bio::PrimarySeqI")
ABresult
0X0
100
111
514 0 my $infile1 = $self->_writeSeqFile(@seq);
515 0 return $self->_run($infile1);
516 ▶ } elsif (ref $seq[0] && $seq[0]->isa("Bio::Align::AlignI") ){ # it is an object
Condition0%0/3
ref $seq[0] and $seq[0]->isa("Bio::Align::AlignI")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $seq[0] and $seq[0]->isa("Bio::Align::AlignI")
ref $seq[0] $seq[0]->isa("Bio::Align::AlignI")
Truth table0%0/3
A and B
A= ref $seq[0]B= $seq[0]->isa("Bio::Align::AlignI")
ABresult
0X0
100
111
517 0 my $infile1 = $self->_writeAlignFile(@seq);
518 0 return $self->_run($infile1);
519 } else {
520 0 return $self->_run(@seq);
521 }
522 }
523  
524 =head1 Specific program interface methods
525  
526 =head2 cmsearch
527  
528 Title : cmsearch
529 Usage : $obj->cmsearch($seqFile)
530 Function: Runs Infernal cmsearch and returns Bio::SearchIO
531 Returns : A Bio::SearchIO
532 Args : Bio::PrimarySeqI or file name
533  
534 =cut
535  
536 0 ▶sub cmsearch {
Subroutine cmsearch: not called CC=3 SCAR=24.8
Pod documented
537 0 my ($self,@seq) = @_;
538 0 $self->program('cmsearch');
539 0 ▶ if (ref $seq[0] && $seq[0]->isa("Bio::PrimarySeqI") ){# it is an object
Branch: 1 branch
BranchTrueFalseTotal
if (ref $seq[0] and $seq[0]->isa('Bio::PrimarySeqI')) { } 0 0 0
Condition0%0/3
ref $seq[0] and $seq[0]->isa("Bio::PrimarySeqI")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $seq[0] and $seq[0]->isa("Bio::PrimarySeqI")
ref $seq[0] $seq[0]->isa("Bio::PrimarySeqI")
Truth table0%0/3
A and B
A= ref $seq[0]B= $seq[0]->isa("Bio::PrimarySeqI")
ABresult
0X0
100
111
540 0 my $infile1 = $self->_writeSeqFile(@seq);
541 0 return $self->_run(-seq_files => [$infile1]);
542 } else {
543 0 return $self->_run(-seq_files => \@seq);
544 }
545 }
546  
547 =head2 cmalign
548  
549 Title : cmalign
550 Usage : $obj->cmalign($seqFile)
551 Function: Runs Infernal cmalign and returns Bio::AlignIO
552 Returns : A Bio::AlignIO
553 Args : Bio::PrimarySeqI or file name
554  
555 =cut
556  
557 0 ▶sub cmalign {
Subroutine cmalign: not called CC=6 SCAR=37.4
Pod documented
558 0 my ($self,@seq) = @_;
559 0 $self->program('cmalign');
560 0 ▶ if (ref $seq[0]) { # it is an object
Branch: 1 branch
BranchTrueFalseTotal
if (ref $seq[0]) { } 0 0 0
561 0 ▶ if ($seq[0]->isa("Bio::PrimarySeqI") ){
Branch: 2 branches
BranchTrueFalseTotal
if ($seq[0]->isa('Bio::PrimarySeqI')) { } 0 0 0
elsif ($seq[0]->isa('Bio::Align::AlignI')) { } 0 0 0
562 0 my $infile1 = $self->_writeSeqFile(@seq);
563 0 return $self->_run(-seq_files => [$infile1]);
564 } elsif ( $seq[0]->isa("Bio::Align::AlignI") ) {
565 0 ▶ if (scalar(@seq) != 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @seq != 2) 0 0 0
566 0 $self->throw("")
567 }
568 0 my $infile1 = $self->_writeAlignFile($seq[0]);
569 0 my $infile2 = $self->_writeAlignFile($seq[1]);
570 0 return $self->_run(-align_files => [$infile1, $infile2]);
571 }
572 } else {
573 # we can maybe add a check for the file extension and try to DTRT
574 0 my %params = $self->get_parameters('valid');
575 0 ▶ $params{merge} ? return $self->_run(-align_files => \@seq):
Branch: 1 branch
BranchTrueFalseTotal
$params{'merge'} ? : 0 0 0
576 return $self->_run(-seq_files => \@seq);
577 0 return $self->_run(-seq_files => \@seq);
578 }
579 }
580  
581 =head2 cmemit
582  
583 Title : cmemit
584 Usage : $obj->cmemit($modelfile)
585 Function: Runs Infernal cmemit and returns Bio::AlignIO
586 Returns : A Bio::AlignIO
587 Args : None; set model_file() to use a specific model
588  
589 =cut
590  
591 0 ▶sub cmemit {
Subroutine cmemit: not called CC=1 SCAR=6.9
Pod documented
592 0 my ($self) = shift;
593 0 $self->program('cmemit');
594 0 return $self->_run(@_);
595 }
596  
597 =head2 cmbuild
598  
599 Title : cmbuild
600 Usage : $obj->cmbuild($alignment)
601 Function: Runs Infernal cmbuild and saves covariance model
602 Returns : 1 on success (no object for covariance models)
603 Args : Bio::AlignIO with structural information (such as from Stockholm
604 format source) or alignment file name
605  
606 =cut
607  
608 0 ▶sub cmbuild {
Subroutine cmbuild: not called CC=3 SCAR=24.8
Pod documented
609 0 my ($self,@seq) = @_;
610 0 $self->program('cmbuild');
611 0 ▶ if (ref $seq[0] && $seq[0]->isa("Bio::Align::AlignI") ){# it is an object
Branch: 1 branch
BranchTrueFalseTotal
if (ref $seq[0] and $seq[0]->isa('Bio::Align::AlignI')) { } 0 0 0
Condition0%0/3
ref $seq[0] and $seq[0]->isa("Bio::Align::AlignI")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $seq[0] and $seq[0]->isa("Bio::Align::AlignI")
ref $seq[0] $seq[0]->isa("Bio::Align::AlignI")
Truth table0%0/3
A and B
A= ref $seq[0]B= $seq[0]->isa("Bio::Align::AlignI")
ABresult
0X0
100
111
612 0 my $infile1 = $self->_writeAlignFile(@seq);
613 0 return $self->_run(-align_files => [$infile1]);
614 } else {
615 0 return $self->_run(-align_files => \@seq);
616 }
617 }
618  
619 =head2 cmscore
620  
621 Title : cmscore
622 Usage : $obj->cmscore($seq)
623 Function: Runs Infernal cmscore and saves output
624 Returns : None
625 Args : None; set model_file() to use a specific model
626  
627 =cut
628  
629 0 ▶sub cmscore {
Subroutine cmscore: not called CC=1 SCAR=6.9
Pod documented
630 0 my ($self,@seq) = @_;
631 0 $self->program('cmscore');
632 0 return $self->_run();
633 }
634  
635 =head2 cmcalibrate
636  
637 Title : cmcalibrate
638 Usage : $obj->cmcalibrate('file')
639 Function: Runs Infernal calibrate on specified CM
640 Returns : None
641 Args : None; set model_file() to use a specific model
642  
643 =cut
644  
645 0 ▶sub cmcalibrate {
Subroutine cmcalibrate: not called CC=1 SCAR=6.9
Pod documented
646 0 my ($self,@seq) = @_;
647 0 $self->program('cmcalibrate');
648 0 return $self->_run();
649 }
650  
651 =head2 cmstat
652  
653 Title : cmstat
654 Usage : $obj->cmstat($seq)
655 Function: Runs Infernal cmstat and saves output
656 Returns : None
657 Args : None; set model_file() to use a specific model
658  
659 =cut
660  
661 0 ▶sub cmstat {
Subroutine cmstat: not called CC=1 SCAR=6.9
Pod documented
662 0 my ($self,@seq) = @_;
663 0 $self->program('cmstat');
664 0 return $self->_run();
665 }
666  
667 =head1 Bio::ParameterBaseI-specific methods
668  
669 These methods are part of the Bio::ParameterBaseI interface
670  
671 =cut
672  
673 =head2 set_parameters
674  
675 Title : set_parameters
676 Usage : $pobj->set_parameters(%params);
677 Function: sets the parameters listed in the hash or array
678 Returns : None
679 Args : [optional] hash or array of parameter/values. These can optionally
680 be hash or array references
681 Note : This only sets parameters; to set methods use the method name
682 =cut
683  
684 1 ▶sub set_parameters {
Subroutine set_parameters: called CC=11 SCAR=37.7
Pod documented
685 1 my $self = shift;
686 # circumvent any issues arising from passing in refs
687 0 ▶ my %args = (ref($_[0]) eq 'HASH') ? %{$_[0]} :
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' ? : 0 1 1
688 0 ▶ (ref($_[0]) eq 'ARRAY') ? @{$_[0]} :
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 1 1
689 @_;
690 # set the parameters passed in, but only ones supported for the program
691 1 my ($prog, $validate) = ($self->program, $self->validate_parameters);
692  
693 # parameter cleanup
694 1 %args = map { my $a = $_;
695 1 $a =~ s{^-}{};
696 1 lc $a => $args{$_}
697 } sort keys %args;
698
699 1 ▶ while (my ($key, $val) = each %args) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %args) 1 1 2
700 1 ▶ if (exists $INFERNAL_PARAMS{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Bio::Tools::Run::Infernal::INFERNAL_PARAMS{$key}) { } 0 1 1
701 0 my ($type, $prefix) = @{$INFERNAL_PARAMS{$key}}[0..1];
702 0 @{$self->{parameters}->{$key}} = ($type, $prefix);
703 0 ▶ unshift @{$self->{parameters}->{$key}},
Branch: 2 branches
BranchTrueFalseTotal
$type eq 'param' ? : 0 0 0
$type eq 'switch' && $val ? : 0 0 0
Condition0%0/3
$type eq "switch" and $val
!ll&&!rl&&r
000
MC/DC0%0/2
$type eq "switch" and $val
$type eq "switch" $val
Truth table0%0/3
A and B
A= $type eq "switch"B= $val
ABresult
0X0
100
111
704 $type eq 'param' ? $val :
705 $type eq 'switch' && $val ? 1 : 0;
706 0 ▶ if ($validate) {
Branch: 1 branch
BranchTrueFalseTotal
if ($validate) 0 0 0
707 0 my %in_exe = map {$_ => 1} @{$INFERNAL_PARAMS{$key}}[2..$#{$INFERNAL_PARAMS{$key}}];
708 0 ▶ $self->warn("Parameter $key not used for $prog") if !exists $in_exe{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $in_exe{$key} 0 0 0
709 }
710 } else {
711 1 ▶ $self->warn("Parameter $key does not exist") if ($validate);
Branch: 1 branch
BranchTrueFalseTotal
if $validate 0 1 1
712 }
713 }
714 }
715  
716 =head2 reset_parameters
717  
718 Title : reset_parameters
719 Usage : resets values
720 Function: resets parameters to either undef or value in passed hash
721 Returns : none
722 Args : [optional] hash of parameter-value pairs
723  
724 =cut
725  
726 0 ▶sub reset_parameters {
Subroutine reset_parameters: not called CC=2 SCAR=17.9
Pod documented
727 0 my $self = shift;
728 0 delete $self->{parameters};
729 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
730 0 $self->set_parameters(@_);
731 }
732 }
733  
734 =head2 validate_parameters
735  
736 Title : validate_parameters
737 Usage : $pobj->validate_parameters(1);
738 Function: sets a flag indicating whether to validate parameters via
739 set_parameters() or reset_parameters()
740 Returns : Bool
741 Args : [optional] value evaluating to True/False
742 Note : Optionally implemented method; up to the implementation on whether
743 to automatically validate parameters or optionally do so
744  
745 =cut
746  
747 2 ▶sub validate_parameters {
Subroutine validate_parameters: called CC=3 SCAR=11.0
Pod documented
748 2 my ($self) = shift;
749 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
750 1 ▶ $self->{validate_params} = defined $_[0] ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 0 1 1
751 }
752 2 return $self->{validate_params};
753 }
754  
755 =head2 parameters_changed
756  
757 Title : parameters_changed
758 Usage : if ($pobj->parameters_changed) {...}
759 Function: Returns boolean true (1) if parameters have changed
760 Returns : Boolean (0 or 1)
761 Args : None
762 Note : This module does not run state checks, so this always returns True
763  
764 =cut
765  
766 0 ▶sub parameters_changed { 1 }
Subroutine parameters_changed: not called CC=1 SCAR=6.9
Pod documented
767  
768 =head2 available_parameters
769  
770 Title : available_parameters
771 Usage : @params = $pobj->available_parameters()
772 Function: Returns a list of the available parameters
773 Returns : Array of parameters
774 Args : [optional] name of executable being used; defaults to returning all
775 available parameters
776  
777 =cut
778  
779 0 ▶sub available_parameters {
Subroutine available_parameters: not called CC=5 SCAR=34.0
Pod documented
780 0 my ($self, $exec) = @_;
781 0 my @params;
782 0 ▶ if ($exec) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exec) { } 0 0 0
783 0 ▶ $self->throw("$exec is not part of the Infernal package") if !exists($INFERNAL_PROGRAM{$exec});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Bio::Tools::Run::Infernal::INFERNAL_PROGRAM{$exec} 0 0 0
784 0 for my $p (sort keys %INFERNAL_PARAMS) {
785 0 ▶ if (grep { $exec eq $_ }
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$exec eq $_;} @{$Bio::Tools::Run::Infernal::INFERNAL_PARAMS{$p};}[2 .. $#{$Bio::Tools::Run::Infernal::INFERNAL_PARAMS{$p};}]) 0 0 0
786 0 @{$INFERNAL_PARAMS{$p}}[2..$#{$INFERNAL_PARAMS{$p}}])
787 {
788 0 push @params, $p;
789 }
790 }
791 } else {
792 0 @params = (sort keys %INFERNAL_PARAMS, sort keys %LOCAL_PARAMS);
793 }
794 0 return @params;
795 }
796  
797 =head2 get_parameters
798  
799 Title : get_parameters
800 Usage : %params = $pobj->get_parameters;
801 Function: Returns list of set key-value pairs, parameter => value
802 Returns : List of key-value pairs
803 Args : [optional]
804 'full' - this option returns everything associated with the parameter
805 as an array ref value; that is, not just the value but also
806 the value, type, and prefix. Default is value only.
807 'valid'- same a 'full', but only returns the grouping valid for the
808 currently set executable
809  
810 =cut
811  
812 0 ▶sub get_parameters {
Subroutine get_parameters: not called CC=6 SCAR=37.4
Pod documented
813 0 my ($self, $option) = @_;
814 0 ▶ $option ||= ''; # no option
Condition0%0/2
$option ||= ""
l!l
00
MC/DC0%0/1
$option ||= ""
$option
Truth table0%0/2
A
A= $option
Aresult
11
00
815 0 my %params;
816 0 ▶ if (exists $self->{parameters}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'parameters'}) { } 0 0 0
817 %params = (ref $option eq 'ARRAY') ? (
818 0 map {$_ => $self->{parameters}{$_}[0]}
819 0 ▶ grep { exists $self->{parameters}{$_} } @$option) :
Branch: 1 branch
BranchTrueFalseTotal
lc $option eq 'full' ? : 0 0 0
820 (lc $option eq 'full') ?
821 0 ▶ (%{$self->{parameters}}) :
Branch: 1 branch
BranchTrueFalseTotal
lc $option eq 'valid' ? : 0 0 0
822 (lc $option eq 'valid') ?
823 0 (map {$_ => $self->{parameters}{$_}}
824 0 grep { exists $self->{valid_params}->{$_} } keys %{$self->{parameters}}) :
825 0 ▶ (map {$_ => $self->{parameters}{$_}[0]} keys %{$self->{parameters}});
Branch: 1 branch
BranchTrueFalseTotal
ref $option eq 'ARRAY' ? : 0 0 0
826 } else {
827 0 %params = ();
828 }
829 0 return %params;
830 }
831  
832 =head1 to_* methods
833  
834 All to_* methods are implementation-specific
835  
836 =cut
837  
838 =head2 to_exe_string
839  
840 Title : to_exe_string
841 Usage : $string = $pobj->to_exe_string;
842 Function: Returns string (command line string in this case)
843 Returns : String
844 Args :
845  
846 =cut
847  
848 0 ▶sub to_exe_string {
Subroutine to_exe_string: not called CC=39 SCAR=73.5
Pod documented
849 0 my ($self, @passed) = @_;
850 0 my ($seqs, $aligns) = $self->_rearrange([qw(SEQ_FILES ALIGN_FILES)], @passed);
851 0 ▶ if ($seqs || $aligns) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seqs or $aligns) 0 0 0
Condition0%0/3
$seqs or $aligns
l!l&&r!l&&!r
000
MC/DC0%0/2
$seqs or $aligns
$seqs $aligns
Truth table0%0/3
A or B
A= $seqsB= $aligns
ABresult
1X1
011
000
852 0 ▶ $self->throw("Seqs or alignments must be an array reference") unless
Branch: 1 branch
BranchTrueFalseTotal
unless $seqs and ref $seqs eq "ARRAY" or $aligns and ref $aligns eq "ARRAY" 0 0 0
Condition0%0/9
$seqs and ref $seqs eq "ARRAY" or $aligns and ref $aligns eq "ARRAY"
l!l&&r!l&&!r
000
$seqs and ref $seqs eq "ARRAY"
!ll&&!rl&&r
000
$aligns and ref $aligns eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/4
$seqs and ref $seqs eq "ARRAY" or $aligns and ref $aligns eq "ARRAY"
$seqs ref $seqs eq "ARRAY" $aligns ref $aligns eq "ARRAY"
Truth table0%0/7
A and B or C and D
A= $seqsB= ref $seqs eq "ARRAY"C= $alignsD= ref $aligns eq "ARRAY"
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
853 ($seqs && ref($seqs) eq 'ARRAY') || ($aligns && ref($aligns) eq 'ARRAY' );
854 }
855
856 0 my %args = map {$_ => []} qw(switch param input redirect);
857 0 my %params = $self->get_parameters('valid');
858
859 0 my ($exe, $prog, $model, $outfile) = ($self->executable,
860 $self->program_name,
861 $self->model_file,
862 $self->outfile_name);
863
864 0 ▶ $self->throw("Executable not found") unless defined($exe);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $exe 0 0 0
865
866 0 ▶ delete $params{o} if exists $params{o};
Branch: 1 branch
BranchTrueFalseTotal
if exists $params{"o"} 0 0 0
867  
868 0 ▶ if (!defined($model) && $prog ne 'cmbuild') {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $model and $prog ne "cmbuild") 0 0 0
Condition0%0/3
not defined $model and $prog ne "cmbuild"
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $model and $prog ne "cmbuild"
not defined $model $prog ne "cmbuild"
Truth table0%0/3
not(A) and B
A= not defined $modelB= $prog ne "cmbuild"
ABresult
0X0
100
111
869 0 $self->throw("model_file() not defined")
870 }
871
872 0 ▶ $outfile ||= '';
Condition0%0/2
$outfile ||= ""
l!l
00
MC/DC0%0/1
$outfile ||= ""
$outfile
Truth table0%0/2
A
A= $outfile
Aresult
11
00
873
874 0 for my $p (sort keys %params) {
875 0 ▶ if ($params{$p}[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params{$p}[0]) 0 0 0
876 0 ▶ my $val = $params{$p}[1] eq 'param' ? ' '.$params{$p}[0] : '';
Branch: 1 branch
BranchTrueFalseTotal
$params{$p}[1] eq 'param' ? : 0 0 0
877 0 push @{$args{$params{$p}[1]}}, $params{$p}[2].$p.$val;
878 }
879 }
880
881 # TODO: not sure what happens when we pass in multiple seq or alignment
882 # filenames, may need checking
883 0 ▶ if ($prog eq 'cmscore' || $prog eq 'cmstat' || $prog eq 'cmcalibrate') {
Branch: 5 branches
BranchTrueFalseTotal
if ($prog eq 'cmscore' or $prog eq 'cmstat' or $prog eq 'cmcalibrate') { } 0 0 0
elsif ($prog eq 'cmsearch') { } 0 0 0
elsif ($prog eq 'cmalign') { } 0 0 0
elsif ($prog eq 'cmbuild') { } 0 0 0
elsif ($prog eq 'cmemit') { } 0 0 0
Condition0%0/6
$prog eq "cmscore" or $prog eq "cmstat" or $prog eq "cmcalibrate"
l!l&&r!l&&!r
000
$prog eq "cmscore" or $prog eq "cmstat"
l!l&&r!l&&!r
000
MC/DC0%0/3
$prog eq "cmscore" or $prog eq "cmstat" or $prog eq "cmcalibrate"
$prog eq "cmscore" $prog eq "cmstat" $prog eq "cmcalibrate"
Truth table0%0/4
A or B or C
A= $prog eq "cmscore"B= $prog eq "cmstat"C= $prog eq "cmcalibrate"
ABCresult
1XX1
01X1
0011
0000
884 0 ▶ push @{$args{'redirect'}}, "> $outfile" if $outfile;
Branch: 1 branch
BranchTrueFalseTotal
if $outfile 0 0 0
885 0 push @{$args{'input'}}, $model;
886 } elsif ($prog eq 'cmsearch') {
887 0 ▶ if (!defined $seqs) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $seqs) 0 0 0
888 0 $self->throw('cmsearch requires a sequence file name');
889 }
890 0 ▶ push @{$args{'param'}}, "-o $outfile" if $outfile;
Branch: 1 branch
BranchTrueFalseTotal
if $outfile 0 0 0
891 0 push @{$args{'input'}}, ($model, @$seqs);
892 } elsif ($prog eq 'cmalign') {
893 0 ▶ if ($params{'merge'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params{'merge'}) { } 0 0 0
894 0 ▶ $self->throw('cmalign with --merge option requires two alignment files') if
Branch: 1 branch
BranchTrueFalseTotal
if not defined $aligns or @$aligns < 2 0 0 0
Condition0%0/3
not defined $aligns or @$aligns < 2
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $aligns or @$aligns < 2
not defined $aligns @$aligns < 2
Truth table0%0/3
not(A) or B
A= not defined $alignsB= @$aligns < 2
ABresult
1X1
011
000
895 !defined($aligns) || @$aligns < 2;
896 0 push @{$args{'input'}}, ($model, @$aligns);
897 } else {
898 0 ▶ $self->throw('cmalign requires a sequence file') if
Branch: 1 branch
BranchTrueFalseTotal
unless defined $seqs 0 0 0
899 !defined $seqs;
900 0 push @{$args{'input'}}, ($model, @$seqs);
901 }
902 0 ▶ push @{$args{'param'}}, "-o $outfile" if $outfile;
Branch: 1 branch
BranchTrueFalseTotal
if $outfile 0 0 0
903 } elsif ($prog eq 'cmbuild') {
904 0 ▶ $self->throw('cmbuild requires one alignment file') if
Branch: 1 branch
BranchTrueFalseTotal
unless defined $aligns 0 0 0
905 !defined($aligns);
906 0 ▶ if ($model) {
Branch: 1 branch
BranchTrueFalseTotal
if ($model) { } 0 0 0
907 0 push @{$args{'input'}}, ($model, @$aligns);
908 0 ▶ push @{$args{'redirect'}}, "> $outfile" if $outfile;
Branch: 1 branch
BranchTrueFalseTotal
if $outfile 0 0 0
909 } else {
910 0 push @{$args{'input'}}, ($outfile, @$aligns);
911 }
912 } elsif ($prog eq 'cmemit') {
913 0 ▶ if (!$outfile) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $outfile) { } 0 0 0
914 0 $self->throw('cmemit requires an outfile_name; tempfile support not implemented yet');
915 } else {
916 0 push @{$args{'input'}}, ($model, ,$outfile);
917 }
918 }
919
920 # quiet!
921 0 ▶ if ($self->quiet && $prog ne 'cmsearch') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->quiet and $prog ne "cmsearch") 0 0 0
Condition0%0/3
$self->quiet and $prog ne "cmsearch"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->quiet and $prog ne "cmsearch"
$self->quiet $prog ne "cmsearch"
Truth table0%0/3
A and B
A= $self->quietB= $prog ne "cmsearch"
ABresult
0X0
100
111
922 0 ▶ if ($prog eq 'cmalign') {
Branch: 1 branch
BranchTrueFalseTotal
if ($prog eq 'cmalign') { } 0 0 0
923 0 ▶ push @{$args{switch}}, '-q' if !exists $params{q};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params{"q"} 0 0 0
924 } else {
925 0 ▶ my $null = ($^O =~ m/mswin/i) ? 'NUL' : '/dev/null';
Branch: 1 branch
BranchTrueFalseTotal
$^O =~ /mswin/i ? : 0 0 0
926 0 push @{$args{redirect}}, "> $null";
927 }
928 }
929
930 0 my $string = "$exe ".join(' ',(@{$args{switch}},
931 0 @{$args{param}},
932 0 @{$args{input}},
933 0 @{$args{redirect}}));
934  
935 0 $string;
936 }
937  
938 ############### PRIVATE ###############
939  
940 #=head2 _run
941 #
942 # Title : _run
943 # Usage : $obj->_run()
944 # Function: Internal(not to be used directly)
945 # Returns :
946 # Args :
947 #
948 #=cut
949  
950 {
951 1 my %ALLOWED = map {$_ => 1} qw(run cmsearch cmalign cmemit cmbuild
952 cmcalibrate cmstat cmscore);
953  
954 0 ▶sub _run {
Subroutine _run: not called CC=23 SCAR=63.1
955 0 my ($self)= shift;
956
957 0 my ($prog, $model, $out, $version) = ($self->program,
958 $self->model_file,
959 $self->outfile_name,
960 $self->version);
961
962 0 ▶ if (my $caller = (caller(1))[3]) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $caller = (&CORE::GLOBAL::caller(1))[3]) { } 0 0 0
963 0 $caller =~ s{.*::(\w+)$}{$1};
964 0 ▶ $self->throw("Calling _run() from disallowed method") unless exists $ALLOWED{$caller};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $ALLOWED{$caller} 0 0 0
965 } else {
966 0 $self->throw("Can't call _run directly");
967 }
968
969 # a model and a file must be defined for all but cmemit; cmemit must have a
970 # file or model defined (using $file if both are defined)
971
972 # relevant files are passed on to the string builder
973 0 my $str = $self->to_exe_string(@_);
974 0 $self->debug("Infernal command: $str\n");
975
976 0 my %has = $self->get_parameters('valid');
977
978 my $obj =
979 ($prog eq 'cmsearch') ? Bio::SearchIO->new(-format => 'infernal',
980 -version => $version,
981 -model => $model) :
982 ($prog eq 'cmalign' ) ? Bio::AlignIO->new(-format => 'stockholm') :
983 0 ▶ ($prog eq 'cmemit' && $has{a}) ? Bio::AlignIO->new(-format => 'stockholm') :
Branch: 4 branches
BranchTrueFalseTotal
$prog eq 'cmsearch' ? : 0 0 0
$prog eq 'cmalign' ? : 0 0 0
$prog eq 'cmemit' && $has{'a'} ? : 0 0 0
$prog eq 'cmemit' ? : 0 0 0
Condition0%0/3
$prog eq "cmemit" and $has{"a"}
!ll&&!rl&&r
000
MC/DC0%0/2
$prog eq "cmemit" and $has{"a"}
$prog eq "cmemit" $has{"a"}
Truth table0%0/3
A and B
A= $prog eq "cmemit"B= $has{"a"}
ABresult
0X0
100
111
984 ($prog eq 'cmemit') ? Bio::SeqIO->new(-format => 'fasta') :
985 undef;
986 0 my @args;
987 # file output
988 0 ▶ if ($out) {
Branch: 1 branch
BranchTrueFalseTotal
if ($out) { } 0 0 0
989 0 my $status = system($str);
990 0 ▶ if($status || !-e $out || -z $out ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status or not -e $out or -z $out) 0 0 0
Condition0%0/6
$status or not -e $out or -z $out
l!l&&r!l&&!r
000
$status or not -e $out
l!l&&r!l&&!r
000
MC/DC0%0/3
$status or not -e $out or -z $out
$status not -e $out -z $out
Truth table0%0/4
A or not(B) or C
A= $statusB= not -e $outC= -z $out
ABCresult
1XX1
01X1
0011
0000
991 0 ▶ my $error = ($!) ? "$! Status: $status" : "Status: $status";
Branch: 1 branch
BranchTrueFalseTotal
$! ? : 0 0 0
992 0 $self->throw( "Infernal call crashed: $error \n[command $str]\n");
993 0 return undef;
994 }
995 0 ▶ if ($obj && ref($obj)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj and ref $obj) 0 0 0
Condition0%0/3
$obj and ref $obj
!ll&&!rl&&r
000
MC/DC0%0/2
$obj and ref $obj
$obj ref $obj
Truth table0%0/3
A and B
A= $objB= ref $obj
ABresult
0X0
100
111
996 0 $obj->file($out);
997 0 @args = (-file => $out);
998 }
999 # fh-based (no outfile)
1000 } else {
1001 0 ▶ open(my $fh,"$str |") || $self->throw("Infernal call ($str) crashed: $?\n");
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "$str |" or $self->throw("Infernal call ($str) crashed: $?\n") 0 0 0
1002 0 ▶ if ($obj && ref($obj)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj and ref $obj) { } 0 0 0
Condition0%0/3
$obj and ref $obj
!ll&&!rl&&r
000
MC/DC0%0/2
$obj and ref $obj
$obj ref $obj
Truth table0%0/3
A and B
A= $objB= ref $obj
ABresult
0X0
100
111
1003 0 $obj->fh($fh);
1004 0 @args = (-fh => $fh);
1005 } else {
1006 # dump to debugging
1007 0 my $io;
1008 0 ▶ while(<$fh>) {$io .= $_;}
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
1009 0 close($fh);
1010 0 ▶ $self->debug($io) if $io;
Branch: 1 branch
BranchTrueFalseTotal
if $io 0 0 0
1011 0 return 1;
1012 }
1013 }
1014 0 ▶ $obj->_initialize_io(@args) if $obj && ref($obj);
Branch: 1 branch
BranchTrueFalseTotal
if $obj and ref $obj 0 0 0
Condition0%0/3
$obj and ref $obj
!ll&&!rl&&r
000
MC/DC0%0/2
$obj and ref $obj
$obj ref $obj
Truth table0%0/3
A and B
A= $objB= ref $obj
ABresult
0X0
100
111
1015 0 ▶ return $obj || 1;
Condition0%0/2
$obj || 1
l!l
00
MC/DC0%0/1
$obj || 1
$obj
Truth table0%0/2
A
A= $obj
Aresult
11
00
1016 }
1017  
1018 }
1019  
1020 =head2 _writeSeqFile
1021  
1022 Title : _writeSeqFile
1023 Usage : obj->_writeSeqFile($seq)
1024 Function: Internal(not to be used directly)
1025 Returns :
1026 Args :
1027  
1028 =cut
1029  
1030 1 ▶sub _writeSeqFile {
Subroutine _writeSeqFile: not called CC=2 SCAR=16.1
1031 0 my ($self,@seq) = @_;
1032 0 my ($tfh,$inputfile) = $self->io->tempfile(-dir=>$self->tempdir);
1033 0 my $in = Bio::SeqIO->new(-fh => $tfh , '-format' => 'Fasta');
1034 0 foreach my $s(@seq){
1035 0 $in->write_seq($s);
1036 }
1037 0 $in->close();
1038 0 $in = undef;
1039 0 close($tfh);
1040 0 undef $tfh;
1041 0 return $inputfile;
1042 }
1043  
1044 =head2 _writeAlignFile
1045  
1046 Title : _writeAlignFile
1047 Usage : obj->_writeAlignFile($seq)
1048 Function: Internal(not to be used directly)
1049 Returns :
1050 Args :
1051  
1052 =cut
1053  
1054 0 ▶sub _writeAlignFile{
Subroutine _writeAlignFile: not called CC=2 SCAR=17.9
1055 0 my ($self,@align) = @_;
1056 0 my ($tfh,$inputfile) = $self->io->tempfile(-dir=>$self->tempdir);
1057 0 my $in = Bio::AlignIO->new('-fh' => $tfh ,
1058 '-format' => 'stockholm');
1059 0 foreach my $s(@align){
1060 0 $in->write_aln($s);
1061 }
1062 0 $in->close();
1063 0 $in = undef;
1064 0 close($tfh);
1065 0 undef $tfh;
1066 0 return $inputfile;
1067 }
1068  
1069 # this is a private sub used to regenerate the class data structures,
1070 # dumped to STDOUT
1071  
1072 # could probably add in a description field if needed...
1073  
1074 0 ▶sub _dump_params {
Subroutine _dump_params: not called CC=16 SCAR=56.1
1075 0 my %params;
1076 my %usage;
1077 0 for my $exec (qw(cmalign cmbuild cmcalibrate cmemit cmscore cmsearch cmstat)) {
1078 0 my $output = `$exec --devhelp`;
1079 0 ▶ if ($?) {
Branch: 1 branch
BranchTrueFalseTotal
if ($?) 0 0 0
1080 0 $output = `$exec -h`;
1081 }
1082 0 my @lines = split("\n",$output);
1083
1084 0 for my $line (@lines) {
1085 0 ▶ next if $line =~ /^#/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^#/ 0 0 0
1086 0 ▶ if ($line =~ /^\s*(-{1,2})(\S+)\s+(<\S+>)?/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($line =~ /^\s*(-{1,2})(\S+)\s+(<\S+>)?/) { } 0 0 0
elsif ($line =~ /Usage:\s*(.+)$/) { } 0 0 0
1087 0 my %data;
1088 0 ▶ ($data{prefix}, my $p, $data{arg}) = ($1, $2, $3 ? 'param' : 'switch');
Branch: 1 branch
BranchTrueFalseTotal
$3 ? : 0 0 0
1089 0 ▶ if (exists $params{$p}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $params{$p}) 0 0 0
1090 0 ▶ if ($data{prefix} ne $params{$p}{prefix}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data{"prefix"} ne $params{$p}{"prefix"}) 0 0 0
1091 0 warn("$data{prefix} for $p in $exec doesn't match prefix for same parameter in ".$params{$p}{exec}[-1].":".$params{$p}{prefix});
1092 }
1093 0 ▶ if ($data{arg} ne $params{$p}{arg}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data{"arg"} ne $params{$p}{"arg"}) 0 0 0
1094 0 warn("$data{arg} for $p in $exec doesn't match arg for same parameter in ".$params{$p}{exec}[-1].":".$params{$p}{arg});
1095 }
1096 }
1097
1098 0 ▶ while (my ($key, $val) = each %data) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %data) 0 0 0
1099 0 $params{$p}->{$key} = $val;
1100 }
1101 0 push @{$params{$p}->{exec}}, $exec;
1102 } elsif ($line =~ /Usage:\s*(.+)$/) {
1103 0 push @{$usage{$exec}}, $1;
1104 } else {
1105 #print "$line\n";
1106 }
1107 }
1108 }
1109  
1110 # generate data structure
1111 0 print "our %INFERNAL_PARAMS = (\n";
1112 0 for my $k (sort keys %params) {
1113 0 printf(" %-17s => [","'$k'");
1114 0 for my $sub (qw(arg prefix exec)) {
1115 my $str = (ref($params{$k}{$sub}) eq 'ARRAY') ?
1116 0 "qw(".join(' ', @{$params{$k}{$sub}}).")" :
1117 0 ▶ "'".$params{$k}{$sub}."',";
Branch: 1 branch
BranchTrueFalseTotal
ref $params{$k}{$sub} eq 'ARRAY' ? : 0 0 0
1118 0 printf("%-10s", $str);
1119 }
1120 0 print "],\n";
1121 }
1122 0 print ");\n\n";
1123
1124 # generate usage data structure
1125 0 print "our %INFERNAL_PROGRAM = (\n";
1126 0 for my $k (sort keys %usage) {
1127 0 printf(" %-17s => [\n","'$k'");
1128 0 print ' '.join(",\n ", map {"'$_'"} @{$usage{$k}})."\n";
1129 0 print " ],\n";
1130 }
1131 0 print ");\n";
1132  
1133 }
1134  
1135 1 1;
↑ Summary Tools/Run/StandAloneBlastPlus/BlastMethods.pm »