blib/lib/Bio/Tools/Run/Phylo/Hyphy/SLAC.pm

filter: Statementstmt 58.1% 61 / 105 Branchbran 44.0% 22 / 50 Conditioncond 16.6% 2 / 12 MC/DCmcdc 14.2% 1 / 7 Subroutinesub 84.6% 11 / 13 Podpod 100% 4 / 4 totaltotal 52.8% 101 / 191 CC 32 SCAR 42.8
CC
32
Cov
51%
run
210.0
set_default_parameters
12.0
new
10.7
CRAP 72.1
« blib/lib/Bio/Tools/Run/Phylo/Hyphy/FEL.pm ↑ Summary blib/lib/Bio/Tools/Run/Alignment/Kalign.pm »
1 # $Id$
2 #
3 # BioPerl module for Bio::Tools::Run::Phylo::Hyphy::SLAC
4 #
5 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 #
7 # Cared for by Albert Vilella <avilella-at-gmail-dot-com>
8 #
9 # Copyright Albert Vilella
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::Phylo::Hyphy::SLAC - Wrapper around the Hyphy SLAC analysis
18  
19 =head1 SYNOPSIS
20  
21 use Bio::Tools::Run::Phylo::Hyphy::SLAC;
22 use Bio::AlignIO;
23 use Bio::TreeIO;
24  
25 my $alignio = Bio::AlignIO->new(-format => 'fasta',
26 -file => 't/data/hyphy1.fasta');
27  
28 my $aln = $alignio->next_aln;
29  
30 my $treeio = Bio::TreeIO->new(
31 -format => 'newick', -file => 't/data/hyphy1.tree');
32  
33 my $slac = Bio::Tools::Run::Phylo::Hyphy::SLAC->new();
34 $slac->alignment($aln);
35 $slac->tree($tree);
36 my ($rc,$results) = $slac->run();
37  
38  
39 =head1 DESCRIPTION
40  
41 This is a wrapper around the SLAC analysis of HyPhy ([Hy]pothesis
42 Testing Using [Phy]logenies) package of Sergei Kosakowsky Pond,
43 Spencer V. Muse, Simon D.W. Frost and Art Poon. See
44 http://www.hyphy.org for more information.
45  
46 =head1 FEEDBACK
47  
48 =head2 Mailing Lists
49  
50 User feedback is an integral part of the evolution of this and other
51 Bioperl modules. Send your comments and suggestions preferably to
52 the Bioperl mailing list. Your participation is much appreciated.
53  
54 bioperl-l@bioperl.org - General discussion
55 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
56  
57 =head2 Support
58  
59 Please direct usage questions or support issues to the mailing list:
60  
61 I<bioperl-l@bioperl.org>
62  
63 rather than to the module maintainer directly. Many experienced and
64 reponsive experts will be able look at the problem and quickly
65 address it. Please include a thorough description of the problem
66 with code and data examples if at all possible.
67  
68 =head2 Reporting Bugs
69  
70 Report bugs to the Bioperl bug tracking system to help us keep track
71 of the bugs and their resolution. Bug reports can be submitted via the
72 web:
73  
74 http://redmine.open-bio.org/projects/bioperl/
75  
76 =head1 AUTHOR - Albert Vilella
77  
78 Email avilella-at-gmail-dot-com
79  
80 =head1 CONTRIBUTORS
81  
82 Additional contributors names and emails here
83  
84 =head1 APPENDIX
85  
86 The rest of the documentation details each of the object methods.
87 Internal methods are usually preceded with a _
88  
89 =cut
90  
91  
92 # Let the code begin...
93  
94  
95 package Bio::Tools::Run::Phylo::Hyphy::SLAC;
96 1 ▶use vars qw(@ISA @VALIDVALUES $PROGRAMNAME $PROGRAM);
Subroutine BEGIN: called CC=1 SCAR=0.0
97 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
98 1 ▶use Bio::Root::Root;
Subroutine BEGIN: called CC=1 SCAR=0.0
99 1 ▶use Bio::AlignIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
100 1 ▶use Bio::TreeIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
101 1 ▶use Bio::Tools::Run::Phylo::Hyphy::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
102 1 ▶use Bio::Tools::Run::WrapperBase;
Subroutine BEGIN: called CC=1 SCAR=0.0
103  
104 1 @ISA = qw(Bio::Tools::Run::Phylo::Hyphy::Base);
105  
106 =head2 Default Values
107  
108 Valid and default values for SLAC are listed below. The default
109 values are always the first one listed. These descriptions are
110 essentially lifted from the python wrapper or provided by the author.
111  
112 INCOMPLETE DOCUMENTATION OF ALL METHODS
113  
114 =cut
115  
116 BEGIN {
117 1 ▶ @VALIDVALUES =
Subroutine BEGIN: called CC=1 SCAR=0.0
118 (
119 {'geneticCode' => [ "Universal","VertebratemtDNA","YeastmtDNA","Mold/ProtozoanmtDNA",
120 "InvertebratemtDNA","CiliateNuclear","EchinodermmtDNA","EuplotidNuclear",
121 "Alt.YeastNuclear","AscidianmtDNA","FlatwormmtDNA","BlepharismaNuclear"]},
122 {'New/Restore' => [ "New Analysis", "Restore"]},
123 {'tempalnfile' => undef }, # aln file goes here
124 {'Model Options' => [ { "Custom" => '010010' },
125 { "Default" => undef } ]
126 },
127 {'temptreefile' => undef }, # tree file goes here
128 {'Model Fit Results' => [ '/dev/null'] }, # this will not work under Windows
129 {'dN/dS bias parameter' => [ { "Estimate dN/dS only" => undef },
130 { "Neutral" => undef },
131 { "Estimate" => undef },
132 { "Estimate + CI" => undef },
133 { "User" => '3' } ] },
134 {'Ancestor Counting' => [ 'Single Ancestor Counting','Weighted Ancestor Counting',
135 'Sample Ancestal States','Process Sampled Ancestal States',
136 'One rate FEL','Two rate FEL','Rate Distribution',
137 'Full site-by-site LRT','Multirate FEL'] },
138 {'SLAC Options' => ['Full tree','Tips vs Internals'] },
139 {'Treatment of Ambiguities' => ['Resolved','Averaged'] },
140 {'Test Statistic' => ['Approximate','Simulated Null'] },
141 {'Significance level' => '0.05' },
142 {'Output options' => 'Export to File' }, #we force a tsv file here
143 {'outfile' => undef }, # outfile goes here
144 {'Rate class estimator' => [ 'Skip','Count'] },
145 );
146 }
147  
148 =head2 new
149  
150 Title : new
151 Usage : my $obj = Bio::Tools::Run::Phylo::Hyphy::SLAC->new();
152 Function: Builds a new Bio::Tools::Run::Phylo::Hyphy::SLAC object
153 Returns : Bio::Tools::Run::Phylo::Hyphy::SLAC
154 Args : -alignment => the Bio::Align::AlignI object
155 -save_tempfiles => boolean to save the generated tempfiles and
156 NOT cleanup after onesself (default FALSE)
157 -tree => the Bio::Tree::TreeI object
158 -params => a hashref of parameters (all passed to set_parameter)
159 -executable => where the hyphy executable resides
160  
161 See also: L<Bio::Tree::TreeI>, L<Bio::Align::AlignI>
162  
163 =cut
164  
165 sub new {
166 1 ▶ my($class,@args) = @_;
Subroutine new: called CC=7 SCAR=23.7
Pod documented
167  
168 1 my $self = $class->SUPER::new(@args);
169 1 my ($aln, $tree, $st, $params, $exe,
170 $ubl) = $self->_rearrange([qw(ALIGNMENT TREE SAVE_TEMPFILES
171 PARAMS EXECUTABLE)],
172 @args);
173 1 ▶ defined $aln && $self->alignment($aln);
Branch: 1 branch
BranchTrueFalseTotal
defined $aln and $self->alignment($aln) 0 1 1
174 1 ▶ defined $tree && $self->tree($tree);
Branch: 1 branch
BranchTrueFalseTotal
defined $tree and $self->tree($tree) 0 1 1
175 1 ▶ defined $st && $self->save_tempfiles($st);
Branch: 1 branch
BranchTrueFalseTotal
defined $st and $self->save_tempfiles($st) 0 1 1
176 1 ▶ defined $exe && $self->executable($exe);
Branch: 1 branch
BranchTrueFalseTotal
defined $exe and $self->executable($exe) 0 1 1
177 1 $self->set_default_parameters();
178 1 ▶ if( defined $params ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params) 0 1 1
179 0 ▶ if( ref($params) !~ /HASH/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref($params) =~ /HASH/i) { } 0 0 0
180 0 $self->warn("Must provide a valid hash ref for parameter -FLAGS");
181 } else {
182 0 map { $self->set_parameter($_, $$params{$_}) } keys %$params;
183 }
184 }
185  
186 1 return $self;
187 }
188  
189  
190 =head2 run
191  
192 Title : run
193 Usage : my ($rc,$results) = $slac->run($aln);
194 Function: run the slac analysis using the default or updated parameters
195 the alignment parameter must have been set
196 Returns : Return code, hash
197 Args : L<Bio::Align::AlignI> object,
198 L<Bio::Tree::TreeI> object [optional]
199  
200  
201 =cut
202  
203 sub run {
204 0 ▶ my ($self,$aln,$tree) = @_;
Subroutine run: not called CC=14 SCAR=53.5
Pod documented
205  
206 0 ▶ $self->prepare($aln,$tree) unless (defined($self->{'_prepared'}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_prepared"} 0 0 0
207 0 my ($rc,$results) = (1);
208 {
209 0 my $commandstring;
210 my $exit_status;
211 0 my $tempdir = $self->tempdir;
212 0 my $slacexe = $self->executable();
213 0 ▶ $self->throw("unable to find or run executable for 'HYPHY'") unless $slacexe && -e $slacexe && -x _;
Branch: 1 branch
BranchTrueFalseTotal
unless $slacexe and -e $slacexe and -x _ 0 0 0
Condition0%0/6
$slacexe and -e $slacexe and -x _
!ll&&!rl&&r
000
$slacexe and -e $slacexe
!ll&&!rl&&r
000
MC/DC0%0/3
$slacexe and -e $slacexe and -x _
$slacexe -e $slacexe -x _
Truth table0%0/4
A and B and C
A= $slacexeB= -e $slacexeC= -x _
ABCresult
0XX0
10X0
1100
1111
214 0 $commandstring = $slacexe . " BASEPATH=" . $self->program_dir . " " . $self->{'_wrapper'};
215 0 ▶ open(RUN, "$commandstring |") or $self->throw("Cannot open exe $slacexe");
Branch: 1 branch
BranchTrueFalseTotal
open RUN, "$commandstring |" or $self->throw("Cannot open exe $slacexe") 0 0 0
216 0 my @output = <RUN>;
217 0 $exit_status = close(RUN);
218 0 $self->error_string(join('',@output));
219 0 ▶ if( (grep { /\berr(or)?: /io } @output) || !$exit_status) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {/\berr(or)?: /io;} @output or not $exit_status) 0 0 0
Condition0%0/3
grep {/\berr(or)?: /io;} @output or not $exit_status
l!l&&r!l&&!r
000
MC/DC0%0/2
grep {/\berr(or)?: /io;} @output or not $exit_status
grep {/\berr(or)?: /io;} @output not $exit_status
Truth table0%0/3
A or not(B)
A= grep {/\berr(or)?: /io;} @outputB= not $exit_status
ABresult
1X1
011
000
220 0 $self->warn("There was an error - see error_string for the program output");
221 0 $rc = 0;
222 }
223 0 my $outfile = $self->outfile_name;
224 0 eval {
225 0 ▶ open(OUTFILE, "$outfile") or $self->throw("cannot open $outfile for reading");
Branch: 1 branch
BranchTrueFalseTotal
open OUTFILE, "$outfile" or $self->throw("cannot open $outfile for reading") 0 0 0
226 0 my $readed_header = 0;
227 0 my @elems;
228 0 ▶ while (<OUTFILE>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline OUTFILE)) 0 0 0
229 0 ▶ if ($readed_header) {
Branch: 1 branch
BranchTrueFalseTotal
if ($readed_header) { } 0 0 0
230 # FEL results are tsv
231 0 my @values = split("\t",$_);
232 0 for my $i (0 .. (scalar(@values)-1)) {
233 0 $elems[$i] =~ s/\n//g;
234 0 push @{$results->{$elems[$i]}}, $values[$i];
235 }
236 } else {
237 0 @elems = split("\t",$_);
238 0 $readed_header = 1;
239 }
240 }
241 };
242 0 ▶ if( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
243 0 $self->warn($self->error_string);
244 }
245 }
246 0 ▶ unless ( $self->save_tempfiles ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->save_tempfiles) 0 0 0
247 0 unlink($self->{'_wrapper'});
248 0 $self->cleanup();
249 }
250 0 return ($rc,$results);
251 }
252  
253 =head2 create_wrapper
254  
255 Title : create_wrapper
256 Usage : $self->create_wrapper
257 Function: It will create the wrapper file that interfaces with the analysis bf file
258 Example :
259 Returns :
260 Args :
261  
262  
263 =cut
264  
265 sub create_wrapper {
266 0 ▶ my $self = shift;
Subroutine create_wrapper: not called CC=1 SCAR=6.9
Pod documented
267  
268 0 my $batchfile = 'QuickSelectionDetection.bf';
269 0 $self->SUPER::create_wrapper($batchfile);
270 }
271  
272 =head2 set_default_parameters
273  
274 Title : set_default_parameters
275 Usage : $hyphy->set_default_parameters(0);
276 Function: (Re)set the default parameters from the defaults
277 (the first value in each array in the
278 %VALIDVALUES class variable)
279 Returns : none
280 Args : boolean: keep existing parameter values
281  
282  
283 =cut
284  
285 sub set_default_parameters {
286 1 ▶ my ($self,$keepold) = @_;
Subroutine set_default_parameters: called CC=12 SCAR=24.9
Pod documented
287 1 ▶ $keepold = 0 unless defined $keepold;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $keepold 1 0 1
288 1 foreach my $elem (@VALIDVALUES) {
289 15 my ($param,$val) = each %$elem;
290 # skip if we want to keep old values and it is already set
291 15 ▶ if (ref($val)=~/ARRAY/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($val) =~ /ARRAY/i) 10 5 15
292 10 ▶ unless (ref($val->[0])=~/HASH/i) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($val->[0]) =~ /HASH/i) { } 2 8 10
293 8 push @{ $self->{'_orderedparams'} }, {$param, $val->[0]};
294 } else {
295 2 $val = $val->[0];
296 }
297 }
298 15 ▶ if ( ref($val) =~ /HASH/i ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref($val) =~ /HASH/i) { } 2 13 15
elsif (not ref($val) =~ /HASH/i || ref($val) =~ /ARRAY/i) { } 5 8 13
299 2 my $prevparam;
300 2 ▶ while (defined($val)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) 3 1 4
301 3 ▶ last unless (ref($val) =~ /HASH/i);
Branch: 1 branch
BranchTrueFalseTotal
unless ref($val) =~ /HASH/i 1 2 3
302 2 ▶ last unless (defined($param));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $param 0 2 2
303 2 $prevparam = $param;
304 2 ($param,$val) = each %{$val};
305 2 push @{ $self->{'_orderedparams'} }, {$prevparam, $param};
306 2 ▶ push @{ $self->{'_orderedparams'} }, {$param, $val} if (defined($val));
Branch: 1 branch
BranchTrueFalseTotal
if defined $val 1 1 2
307 }
308 ▶ } elsif (ref($val) !~ /HASH/i && ref($val) !~ /ARRAY/i) {
Condition66%2/3
ref($val) =~ /HASH/i || ref($val) =~ /ARRAY/i
l!l&&r!l&&!r
085
MC/DC50%1/2
ref($val) =~ /HASH/i || ref($val) =~ /ARRAY/i
ref($val) =~ /HASH/i ref($val) =~ /ARRAY/i
Truth table66%2/3
A || B
A= ref($val) =~ /HASH/iB= ref($val) =~ /ARRAY/i
ABresult
1X1
011
000
309 5 push @{ $self->{'_orderedparams'} }, {$param, $val};
310 }
311 }
312 }
313  
314 =head1 Bio::Tools::Run::Phylo::Hyphy::Base methods
315  
316 =head2 program_name
317  
318 Title : program_name
319 Usage : $factory->program_name()
320 Function: holds the program name
321 Returns: string
322 Args : None
323  
324 =cut
325  
326 =head2 program_dir
327  
328 Title : program_dir
329 Usage : ->program_dir()
330 Function: returns the program directory, obtained from ENV variable.
331 Returns: string
332 Args :
333  
334 =cut
335  
336 =head2 prepare
337  
338 Title : prepare
339 Usage : my $rundir = $slac->prepare($aln);
340 Function: prepare the slac analysis using the default or updated parameters
341 the alignment parameter must have been set
342 Returns : value of rundir
343 Args : L<Bio::Align::AlignI> object,
344 L<Bio::Tree::TreeI> object [optional]
345  
346 =cut
347  
348  
349 =head2 error_string
350  
351 Title : error_string
352 Usage : $obj->error_string($newval)
353 Function: Where the output from the last analysus run is stored.
354 Returns : value of error_string
355 Args : newvalue (optional)
356  
357  
358 =cut
359  
360  
361 =head2 alignment
362  
363 Title : alignment
364 Usage : $slac->align($aln);
365 Function: Get/Set the L<Bio::Align::AlignI> object
366 Returns : L<Bio::Align::AlignI> object
367 Args : [optional] L<Bio::Align::AlignI>
368 Comment : We could potentially add support for running directly on a file
369 but we shall keep it simple
370 See also: L<Bio::SimpleAlign>
371  
372 =cut
373  
374  
375 =head2 tree
376  
377 Title : tree
378 Usage : $slac->tree($tree, %params);
379 Function: Get/Set the L<Bio::Tree::TreeI> object
380 Returns : L<Bio::Tree::TreeI>
381 Args : [optional] $tree => L<Bio::Tree::TreeI>,
382 [optional] %parameters => hash of tree-specific parameters:
383  
384 Comment : We could potentially add support for running directly on a file
385 but we shall keep it simple
386 See also: L<Bio::Tree::Tree>
387  
388 =cut
389  
390 =head2 get_parameters
391  
392 Title : get_parameters
393 Usage : my %params = $self->get_parameters();
394 Function: returns the list of parameters as a hash
395 Returns : associative array keyed on parameter names
396 Args : none
397  
398  
399 =cut
400  
401 =head2 set_parameter
402  
403 Title : set_parameter
404 Usage : $slac->set_parameter($param,$val);
405 Function: Sets a slac parameter, will be validated against
406 the valid values as set in the %VALIDVALUES class variable.
407 The checks can be ignored if one turns off param checks like this:
408 $slac->no_param_checks(1)
409 Returns : boolean if set was success, if verbose is set to -1
410 then no warning will be reported
411 Args : $param => name of the parameter
412 $value => value to set the parameter to
413 See also: L<no_param_checks()>
414  
415 =cut
416  
417 =head2 set_default_parameters
418  
419 Title : set_default_parameters
420 Usage : $slac->set_default_parameters(0);
421 Function: (Re)set the default parameters from the defaults
422 (the first value in each array in the
423 %VALIDVALUES class variable)
424 Returns : none
425 Args : boolean: keep existing parameter values
426  
427  
428 =cut
429  
430 =head2 update_ordered_parameters
431  
432 Title : update_ordered_parameters
433 Usage : $slac->update_ordered_parameters(0);
434 Function: (Re)set the default parameters from the defaults
435 (the first value in each array in the
436 %VALIDVALUES class variable)
437 Returns : none
438 Args : boolean: keep existing parameter values
439  
440  
441 =cut
442  
443 =head1 Bio::Tools::Run::WrapperBase methods
444  
445 =cut
446  
447  
448 =head2 save_tempfiles
449  
450 Title : save_tempfiles
451 Usage : $obj->save_tempfiles($newval)
452 Function:
453 Returns : value of save_tempfiles
454 Args : newvalue (optional)
455  
456  
457 =cut
458  
459 =head2 tempdir
460  
461 Title : tempdir
462 Usage : my $tmpdir = $self->tempdir();
463 Function: Retrieve a temporary directory name (which is created)
464 Returns : string which is the name of the temporary directory
465 Args : none
466  
467  
468 =cut
469  
470 =head2 cleanup
471  
472 Title : cleanup
473 Usage : $slac->cleanup();
474 Function: Will cleanup the tempdir directory after a run
475 Returns : none
476 Args : none
477  
478  
479 =cut
480  
481 =head2 io
482  
483 Title : io
484 Usage : $obj->io($newval)
485 Function: Gets a L<Bio::Root::IO> object
486 Returns : L<Bio::Root::IO>
487 Args : none
488  
489  
490 =cut
491  
492 sub DESTROY {
493 1 ▶ my $self= shift;
Subroutine DESTROY: called CC=2 SCAR=7.0
494 1 ▶ unless ( $self->save_tempfiles ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->save_tempfiles) 1 0 1
495 1 $self->cleanup();
496 }
497 1 $self->SUPER::DESTROY();
498 }
499  
500 1 1;
« blib/lib/Bio/Tools/Run/Phylo/Hyphy/FEL.pm ↑ Summary blib/lib/Bio/Tools/Run/Alignment/Kalign.pm »