blib/lib/Bio/Tools/Run/Phylo/SLR.pm

filter: Statementstmt 26.5% 57 / 215 Branchbran 14.5% 16 / 110 Conditioncond 4.1% 1 / 24 MC/DCmcdc 0.0% 0 / 15 Subroutinesub 62.5% 15 / 24 Podpod 100% 13 / 13 totaltotal 25.4% 102 / 401 CC 68 SCAR 49.2
CC
68
Cov
21%
run
380.0
prepare
272.0
set_parameter
56.0
CRAP 136.6
« blib/lib/Bio/Tools/Run/Eponine.pm ↑ Summary blib/lib/Bio/Tools/Run/Alignment/Muscle.pm »
1 # $Id$
2 #
3 # BioPerl module for Bio::Tools::Run::Phylo::SLR
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::SLR - Wrapper around the SLR program
18  
19 =head1 SYNOPSIS
20  
21 use Bio::Tools::Run::Phylo::SLR;
22 use Bio::AlignIO;
23 use Bio::TreeIO;
24 use Bio::SimpleAlign;
25  
26 my $alignio = Bio::AlignIO->new
27 (-format => 'fasta',
28 -file => 't/data/219877.cdna.fasta');
29  
30 my $aln = $alignio->next_aln;
31  
32 my $treeio = Bio::TreeIO->new
33 (-format => 'newick', -file => 't/data/219877.tree');
34  
35 my $tree = $treeio->next_tree;
36  
37 my $slr = Bio::Tools::Run::Phylo::SLR->new();
38 $slr->alignment($aln);
39 $slr->tree($tree);
40 # $rc = 1 for success, 0 for errors
41 my ($rc,$results) = $slr->run();
42  
43 my $positive_sites = $results->{'positive'};
44  
45 print "# Site\tNeutral\tOptimal\tOmega\t",
46 "lower\tupper\tLRT_Stat\tPval\tAdj.Pval\tResult\tNote\n";
47 foreach my $positive_site (@$positive_sites) {
48 print
49 $positive_site->[0], "\t",
50 $positive_site->[1], "\t",
51 $positive_site->[2], "\t",
52 $positive_site->[3], "\t",
53 $positive_site->[4], "\t",
54 $positive_site->[5], "\t",
55 $positive_site->[6], "\t",
56 $positive_site->[7], "\t",
57 $positive_site->[8], "\t",
58 "positive\n";
59 }
60  
61 =head1 DESCRIPTION
62  
63 This is a wrapper around the SLR program. See
64 http://www.ebi.ac.uk/goldman/SLR/ for more information.
65  
66 This module is more about generating the proper ctl file and
67 will run the program in a separate temporary directory to avoid
68 creating temp files all over the place.
69  
70 =head1 FEEDBACK
71  
72 =head2 Mailing Lists
73  
74 User feedback is an integral part of the evolution of this and other
75 Bioperl modules. Send your comments and suggestions preferably to
76 the Bioperl mailing list. Your participation is much appreciated.
77  
78 bioperl-l@bioperl.org - General discussion
79 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
80  
81 =head2 Support
82  
83 Please direct usage questions or support issues to the mailing list:
84  
85 I<bioperl-l@bioperl.org>
86  
87 rather than to the module maintainer directly. Many experienced and
88 reponsive experts will be able look at the problem and quickly
89 address it. Please include a thorough description of the problem
90 with code and data examples if at all possible.
91  
92 =head2 Reporting Bugs
93  
94 Report bugs to the Bioperl bug tracking system to help us keep track
95 of the bugs and their resolution. Bug reports can be submitted via the
96 web:
97  
98 http://redmine.open-bio.org/projects/bioperl/
99  
100 =head1 AUTHOR - Albert Vilella
101  
102 Email avilella-at-gmail-dot-com
103  
104 =head1 CONTRIBUTORS
105  
106 Additional contributors names and emails here
107  
108 =head1 APPENDIX
109  
110 The rest of the documentation details each of the object methods.
111 Internal methods are usually preceded with a _
112  
113 =cut
114  
115  
116 #' keep my emacs happy
117 # Let the code begin...
118  
119  
120 package Bio::Tools::Run::Phylo::SLR;
121 1 ▶use vars qw(@ISA %VALIDVALUES $MINNAMELEN $PROGRAMNAME $PROGRAM);
Subroutine BEGIN: called CC=1 SCAR=0.0
122 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
123 1 ▶use Bio::Root::Root;
Subroutine BEGIN: called CC=1 SCAR=0.0
124 1 ▶use Bio::AlignIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
125 1 ▶use Bio::TreeIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
126 1 ▶use Bio::SimpleAlign;
Subroutine BEGIN: called CC=1 SCAR=0.0
127 1 ▶use Bio::Tools::Run::WrapperBase;
Subroutine BEGIN: called CC=1 SCAR=0.0
128 1 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
129 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
130  
131 1 @ISA = qw(Bio::Root::Root Bio::Tools::Run::WrapperBase);
132  
133 =head2 Default Values
134  
135 INCOMPLETE DOCUMENTATION OF ALL METHODS
136  
137 seqfile [incodon]
138 File from which to read alignment of codon sequences. The file
139 should be in PAML format.
140  
141 treefile [intree]
142 File from which tree should be read. The tree should be in Nexus
143 format
144  
145 outfile [slr.res]
146 File to which results are written. If the file already exists, it will
147 be overwritten.
148  
149 reoptimise [1]
150 Should the branch lengths, omega and kappa be reoptimized?
151 0 - no
152 1 - yes.
153  
154 kappa [2.0]
155 Value for kappa. If 'reoptimise' is specified, the value
156 given will be used as am initial estimate,
157  
158 omega [0.1]
159 Value for omega (dN/dS). If 'reoptimise' is specified, the value
160 given will be used as an initial estimate.
161  
162 codonf [0]
163 How codon frequencies are estimated:
164 0: F61/F60 Estimates used are the empirical frequencies from the
165 data.
166 1: F3x4 The frequencies of nucleotides at each codon position
167 are estimated from the data and then multiplied together to get the
168 frequency of observing a given codon. The frequency of stop codons is
169 set to zero, and all other frequencies scaled appropriately.
170 2: F1x4 Nucleotide frequencies are estimated from the data
171 (not taking into account at which position in the codon it occurs).
172 The nucleotide frequencies are multiplied together to get the frequency
173 of observing and then corrected for stop codons.
174  
175 freqtype [0]
176 How codon frequencies are incorporated into the substitution matrix.
177 0: q_{ij} = pi_{j} s_{ij}
178 1: q_{ij} = \sqrt(pi_j/pi_i) s_{ij}
179 2: q_{ij} = \pi_{n} s_{ij}, where n is the nucleotide that the
180 subsitution is to.
181 3: q_{ij} = s_{ij} / pi_i
182 Option 0 is the tradition method of incorporating equilibrium frequencies
183 into subsitution matrices (Felsenstein 1981; Goldman and Yang, 1994)
184 Option 1 is described by Goldman and Whelan (2002), in this case with the
185 additional parameter set to 0.5.
186 Option 2 was suggested by Muse and Gaut (1994).
187 Option 3 is included as an experiment, originally suggested by Bret Larget.
188 it does not appear to describe evolution very successfully and should not
189 be used for analyses.
190  
191 Kosakovsky-Pond has repeatedly stated that he finds incorporating codon
192 frequencies in the manner of option 2 to be superior to option 0. We find
193 that option 1 tends to perform better than either of these options.
194  
195 positive_only [0]
196 If only positively selected sites are of interest, set this to "1".
197 Calculation will be slightly faster, but information about sites under
198 purifying selection is lost.
199  
200 gencode [universal]
201 Which genetic code to use when determining whether a given mutation
202 is synonymous or nonsynonymous. Currently only "universal" and
203 "mammalian" mitochondrial are supported.
204  
205 nucleof [0]
206 Allow for empirical exchangabilities for nucleotide substitution.
207 0: No adjustment. All nucleotides treated the same, modulo
208 transition / transversion.
209 1: The rate at which a substitution caused a mutation from nucleotide
210 a to nucleotide b is adjust by a constant N_{ab}. This adjustment is
211 in addition to other adjustments (e.g. transition / transversion or
212 base frequencies).
213  
214 aminof [0]
215 Incorporate amino acid similarity parameters into substitution matrix,
216 adjusting omega for a change between amino acid i and amino acid j.
217 A_{ij} is a symmetric matrix of constants representing amino acid
218 similarities.
219 0: Constant omega for all amino acid changes
220 1: omega_{ij} = omega^{A_{ij}}
221 2: omega_{ij} = a_{ij} log(omega) / [ 1 - exp(-a_{ij} log(omega)) ]
222 Option 1 has the same form as the original codon subsitution model
223 proposed by Goldman and Yang (but with potentially different
224 constants).
225 Option 2 has a more population genetic derivtion, with omega being
226 interpreted as the ratio of fixation probabilities.
227  
228 nucfile [nuc.dat]
229 If nucleof is non-zero, read nucleotide substitution constants from
230 nucfile. If this file does not exist, hard coded constants are used.
231  
232 aminofile [amino.dat]
233 If aminof is non-zero, read amino acid similarity constants from
234 aminofile. If this file does not exist, hard coded constants are used.
235  
236 timemem [0]
237 Print summary of real time and CPU time used. Will eventually print
238 summary of memory use as well.
239  
240 ldiff [3.841459]
241 Twice log-likelihood difference used as a threshold for calculating
242 support (confidence) intervals for sitewise omega estimates. This
243 value should be the quantile from a chi-square distribution with one
244 degree of freedom corresponding to the support required.
245 E.g. qchisq(0.95,1) = 3.841459
246 0.4549364 = 50% support
247 1.323304 = 75% support
248 2.705543 = 90% support
249 3.841459 = 95% support
250 6.634897 = 99% support
251 7.879439 = 99.5% support
252 10.82757 = 99.9% support
253  
254 paramin []
255 If not blank, read in parameters from file given by the argument.
256  
257 paramout []
258 If not blank, write out parameter estimates to file given.
259  
260 skipsitewise [0]
261 Skip sitewise estimation of omega. Depending on other options given,
262 either calculate maximum likelihood or likelihood fixed at parameter
263 values given.
264  
265 seed [0]
266 Seed for random number generator. If seed is 0, then previously
267 produced seed file (~/.rng64) is used. If this does not exist, the
268 random number generator is initialised using the clock.
269  
270 saveseed [1]
271 If non-zero, save finial seed in file (~/.rng64) to be used as initial
272 seed in future runs of program.
273  
274 =head2 Results Format
275  
276 Results file (default: slr.res)
277 ------------
278 Results are presented in nine columns
279  
280 Site
281 Number of sites in alignment
282  
283 Neutral
284 (minus) Log-probability of observing site given that it was
285 evolving neutrally (omega=1)
286  
287 Optimal
288 (minus) Log-probability of observing site given that it was
289 evolving at the optimal value of omega.
290  
291 Omega
292 The value of omega which maximizes the log-probability of observing
293  
294 LRT_Stat
295 Log-likelihood ratio statistic for non-neutral selection (or
296 positive selection if the positive_only option is set to 1).
297 LRT_Stat = 2 * (Neutral-Optimal)
298  
299 Pval
300 P-value for non-neutral (or positive) selection at a site,
301 unadjusted for multiple comparisons.
302  
303 Adj. Pval
304 P-value for non-neutral (or positive) selection at a site, after
305 adjusting for multiple comparisons using the Hochberg procedure
306 (see the file "MultipleComparisons.txt" in the doc directory).
307  
308 Result
309 A simple visual guide to the result. Sites detected as having been
310 under positive selection are marked with a '+', sites under
311 purifying selection are marked with '-'. The number of symbols
312 Number symbols Threshold
313 1 95%
314 2 99%
315 3 95% after adjustment
316 4 99% after adjustment
317  
318 Occasionally the result may also contain an exclamation mark. This
319 indicates that the observation at a site is not significantly
320 different from random (equivalent to infinitely strong positive
321 selection). This may indicate that the alignment at that site is bad
322  
323 Note
324  
325 The following events are flagged:
326 Synonymous All codons at a site code for the same amino
327 acid.
328 Single character Only one sequence at the site is ungapped,
329 the result of a recent insertion for example.
330 All gaps All sequences at a site contain a gap
331 character.
332  
333 Sites marked "Single character" or "All gaps" are not counted
334 towards the number of sites for the purposes of correcting for
335 multiple comparisons since it is not possible to detect selection
336 from none or one observation under the assumptions made by the
337 sitewise likelihood ratio test.
338  
339 =cut
340  
341  
342 #' keep my emacs happy
343  
344 BEGIN {
345  
346 1 ▶ $MINNAMELEN = 25;
Subroutine BEGIN: called CC=5 SCAR=20.9
347 1 $PROGRAMNAME = 'Slr_Linux_static';
348 1 ▶ if ($^O =~ /darwin/i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($^O =~ /darwin/i) { } 0 1 1
elsif ($^O =~ /mswin/i) { } 0 1 1
349 0 $PROGRAMNAME = 'Slr_osx';
350 } elsif ($^O =~ /mswin/i) {
351 0 $PROGRAMNAME = 'Slr_windows.exe';
352 }
353 1 ▶ if( defined $ENV{'SLRDIR'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{"SLRDIR"}) 0 1 1
354 0 ▶ $PROGRAM = Bio::Root::IO->catfile($ENV{'SLRDIR'},$PROGRAMNAME). ($^O =~ /mswin/i ?'_windows.exe':'');;
Branch: 1 branch
BranchTrueFalseTotal
$^O =~ /mswin/i ? : 0 0 0
355 }
356
357 # valid values for parameters, the default one is always
358 # the first one in the array
359 # example file provided with the package
360 %VALIDVALUES = (
361 1 'outfile' => 'slr.res',
362 'reoptimise' => [ 1,0],
363 'kappa' => '2.0',
364 'omega' => '0.1',
365 'codonf' => [ 0, 1,2],
366 'freqtype' => [ 0, 1,2,3],
367 'positive_only' => [ 0, 1],
368 'gencode' => [ "universal", "mammalian"],
369 'nucleof' => [ 0, 1],
370 'aminof' => [ 0, 1,2],
371 'nucfile' => '',
372 'aminofile' => '',
373 'timemem' => [ 0, 1],
374 'ldiff' => [ 3.841459, 0.4549364,1.323304,2.705543,6.634897,7.879439,10.82757],
375 'paramin' => '',
376 'paramout' => '',
377 'skipsitewise' => [ 0, 1],
378 'seed' => [0],
379 'saveseed' => [ 1, 0]
380 );
381 }
382  
383 =head2 program_name
384  
385 Title : program_name
386 Usage : $factory->program_name()
387 Function: holds the program name
388 Returns: string
389 Args : None
390  
391 =cut
392  
393 sub program_name {
394 6 ▶ return $PROGRAMNAME;
Subroutine program_name: called CC=1 SCAR=0.0
Pod documented
395 }
396  
397 =head2 program_dir
398  
399 Title : program_dir
400 Usage : ->program_dir()
401 Function: returns the program directory, obtained from ENV variable.
402 Returns: string
403 Args :
404  
405 =cut
406  
407 sub program_dir {
408 3 ▶ return Bio::Root::IO->catfile($ENV{SLRDIR}) if $ENV{SLRDIR};
Subroutine program_dir: called CC=2 SCAR=7.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"SLRDIR"} 0 3 3
409 }
410  
411  
412 =head2 new
413  
414 Title : new
415 Usage : my $obj = Bio::Tools::Run::Phylo::SLR->new();
416 Function: Builds a new Bio::Tools::Run::Phylo::SLR object
417 Returns : Bio::Tools::Run::Phylo::SLR
418 Args : -alignment => the Bio::Align::AlignI object
419 -save_tempfiles => boolean to save the generated tempfiles and
420 NOT cleanup after onesself (default FALSE)
421 -tree => the Bio::Tree::TreeI object
422 -params => a hashref of SLR parameters (all passed to set_parameter)
423 -executable => where the SLR executable resides
424  
425 See also: L<Bio::Tree::TreeI>, L<Bio::Align::AlignI>
426  
427 =cut
428  
429 sub new {
430 1 ▶ my($class,@args) = @_;
Subroutine new: called CC=7 SCAR=23.7
Pod documented
431  
432 1 my $self = $class->SUPER::new(@args);
433 1 my ($aln, $tree, $st, $params, $exe,
434 $ubl) = $self->_rearrange([qw(ALIGNMENT TREE SAVE_TEMPFILES
435 PARAMS EXECUTABLE)],
436 @args);
437 1 ▶ defined $aln && $self->alignment($aln);
Branch: 1 branch
BranchTrueFalseTotal
defined $aln and $self->alignment($aln) 0 1 1
438 1 ▶ defined $tree && $self->tree($tree);
Branch: 1 branch
BranchTrueFalseTotal
defined $tree and $self->tree($tree) 0 1 1
439 1 ▶ defined $st && $self->save_tempfiles($st);
Branch: 1 branch
BranchTrueFalseTotal
defined $st and $self->save_tempfiles($st) 0 1 1
440 1 ▶ defined $exe && $self->executable($exe);
Branch: 1 branch
BranchTrueFalseTotal
defined $exe and $self->executable($exe) 0 1 1
441  
442 1 $self->set_default_parameters();
443 1 ▶ if( defined $params ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params) 0 1 1
444 0 ▶ if( ref($params) !~ /HASH/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref($params) =~ /HASH/i) { } 0 0 0
445 0 $self->warn("Must provide a valid hash ref for parameter -FLAGS");
446 } else {
447 0 map { $self->set_parameter($_, $$params{$_}) } keys %$params;
448 }
449 }
450 1 return $self;
451 }
452  
453  
454 =head2 prepare
455  
456 Title : prepare
457 Usage : my $rundir = $slr->prepare($aln);
458 Function: prepare the SLR analysis using the default or updated parameters
459 the alignment parameter must have been set
460 Returns : value of rundir
461 Args : L<Bio::Align::AlignI> object,
462 L<Bio::Tree::TreeI> object
463  
464 =cut
465  
466 sub prepare{
467 0 ▶ my ($self,$aln,$tree) = @_;
Subroutine prepare: not called CC=16 SCAR=56.1
Pod documented
468 0 ▶ unless ( $self->save_tempfiles ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->save_tempfiles) 0 0 0
469 # brush so we don't get plaque buildup ;)
470 0 $self->cleanup();
471 }
472 0 ▶ $tree = $self->tree unless $tree;
Branch: 1 branch
BranchTrueFalseTotal
unless $tree 0 0 0
473 0 ▶ $aln = $self->alignment unless $aln;
Branch: 1 branch
BranchTrueFalseTotal
unless $aln 0 0 0
474 0 ▶ if( ! $aln ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($aln) 0 0 0
475 0 $self->warn("must have supplied a valid alignment file in order to run SLR");
476 0 return 0;
477 }
478 0 ▶ if( ! $tree ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tree) 0 0 0
479 0 $self->warn("must have supplied a valid tree file in order to run SLR");
480 0 return 0;
481 }
482 0 my ($tempdir) = $self->tempdir();
483 0 my ($tempseqFH,$tempseqfile);
484  
485 # Reorder the alignment according to the tree
486 0 my $ct = 1;
487 0 my %order;
488 0 foreach my $node ($tree->get_leaf_nodes) {
489 0 $order{$node->id_output} = $ct++;
490 }
491 0 my @seq; my @ids;
492 0 foreach my $seq ( $aln->each_seq() ) {
493 0 push @seq, $seq;
494 0 push @ids, $seq->display_id;
495 }
496 # use the map-sort-map idiom:
497 0 my @sorted = map { $_->[1] } sort { $a->[0] <=> $b->[0] } map { [$order{$_->id()}, $_] } @seq;
498 0 my $sorted_aln = Bio::SimpleAlign->new();
499 0 foreach (@sorted) {
500 0 $sorted_aln->add_seq($_);
501 }
502  
503 # Rename the leaf nodes in the tree from 1 to n
504 0 $ct = 1;
505 0 foreach my $node ($tree->get_leaf_nodes) {
506 0 $node->id($ct++);
507 }
508  
509 0 ▶ ($tempseqFH,$tempseqfile) = $self->io->tempfile
Branch: 1 branch
BranchTrueFalseTotal
$self->save_tempfiles ? : 0 0 0
510 ('-dir' => $tempdir,
511 UNLINK => ($self->save_tempfiles ? 0 : 1));
512 0 ▶ my $alnout = Bio::AlignIO->new('-format' => 'phylip',
Branch: 1 branch
BranchTrueFalseTotal
$Bio::Tools::Run::Phylo::SLR::MINNAMELEN > $aln->maxdisplayname_length ? : 0 0 0
513 '-fh' => $tempseqFH,
514 '-interleaved' => 0,
515 '-idlinebreak' => 1,
516 '-idlength' => $MINNAMELEN > $aln->maxdisplayname_length() ? $MINNAMELEN : $aln->maxdisplayname_length() +1);
517  
518 0 $alnout->write_aln($sorted_aln);
519 0 $alnout->close();
520 0 undef $alnout;
521 0 close($tempseqFH);
522  
523 0 my ($temptreeFH,$temptreefile);
524 0 ▶ ($temptreeFH,$temptreefile) = $self->io->tempfile
Branch: 1 branch
BranchTrueFalseTotal
$self->save_tempfiles ? : 0 0 0
525 ('-dir' => $tempdir,
526 UNLINK => ($self->save_tempfiles ? 0 : 1));
527  
528 0 my $treeout = Bio::TreeIO->new('-format' => 'newick',
529 '-fh' => $temptreeFH);
530  
531 # We need to add a line with the num of leaves ($ct-1) and the
532 # num of trees (1)
533 0 $treeout->_print(sprintf("%d 1\n",($ct-1)));
534 0 $treeout->write_tree($tree);
535 0 $treeout->close();
536 0 close($temptreeFH);
537  
538 # now let's print the ctl file.
539 # many of the these programs are finicky about what the filename is
540 # and won't even run without the properly named file.
541  
542 0 my ($treevolume,$treedirectories,$treefile) = File::Spec->splitpath( $temptreefile );
543 0 my ($alnvolume,$alndirectories,$alnfile) = File::Spec->splitpath( $tempseqfile );
544 0 my $slr_ctl = "$tempdir/slr.ctl";
545 0 ▶ open(SLR, ">$slr_ctl") or $self->throw("cannot open $slr_ctl for writing");
Branch: 1 branch
BranchTrueFalseTotal
open SLR, ">$slr_ctl" or $self->throw("cannot open $slr_ctl for writing") 0 0 0
546 0 print SLR "seqfile\: $alnfile\n";
547 0 print SLR "treefile\: $treefile\n";
548 0 my $outfile = $self->outfile_name;
549 0 print SLR "outfile\: $outfile\n";
550  
551 0 my %params = $self->get_parameters;
552 0 ▶ while( my ($param,$val) = each %params ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %params) 0 0 0
553 0 ▶ next if $param eq 'outfile';
Branch: 1 branch
BranchTrueFalseTotal
if $param eq "outfile" 0 0 0
554 0 print SLR "$param\: $val\n";
555 }
556 0 close(SLR);
557 0 return $tempdir;
558 }
559  
560  
561  
562 =head2 run
563  
564 Title : run
565 Usage : my ($rc,$parser) = $slr->run($aln,$tree);
566 Function: run the SLR analysis using the default or updated parameters
567 the alignment parameter must have been set
568 Returns : Return code, L<Bio::Tools::Phylo::SLR>
569 Args : L<Bio::Align::AlignI> object,
570 L<Bio::Tree::TreeI> object
571  
572  
573 =cut
574  
575 sub run {
576 0 ▶ my ($self) = shift;;
Subroutine run: not called CC=19 SCAR=59.4
Pod documented
577 0 my $outfile = $self->outfile_name;
578 0 my $tmpdir = $self->prepare(@_);
579  
580 #my ($rc,$parser) = (1);
581 0 my ($rc,$results) = (1);
582 {
583 0 my $cwd = cwd();
584 0 my $exit_status;
585 0 chdir($tmpdir);
586 0 my $slrexe = $self->executable();
587 0 ▶ $self->throw("unable to find or run executable for SLR") unless $slrexe && -e $slrexe && -x _;
Branch: 1 branch
BranchTrueFalseTotal
unless $slrexe and -e $slrexe and -x _ 0 0 0
Condition0%0/6
$slrexe and -e $slrexe and -x _
!ll&&!rl&&r
000
$slrexe and -e $slrexe
!ll&&!rl&&r
000
MC/DC0%0/3
$slrexe and -e $slrexe and -x _
$slrexe -e $slrexe -x _
Truth table0%0/4
A and B and C
A= $slrexeB= -e $slrexeC= -x _
ABCresult
0XX0
10X0
1100
1111
588 0 my $run;
589 0 ▶ open($run, "$slrexe |") or $self->throw("Cannot open exe $slrexe");
Branch: 1 branch
BranchTrueFalseTotal
open $run, "$slrexe |" or $self->throw("Cannot open exe $slrexe") 0 0 0
590 0 my @output = <$run>;
591 0 $exit_status = close($run);
592 0 $self->error_string(join('',@output));
593 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
594 0 $self->warn("There was an error - see error_string for the program output");
595 0 $rc = 0;
596 }
597 0 eval {
598 0 ▶ open RESULTS, "$tmpdir/$outfile" or die "couldnt open results file: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open RESULTS, "$tmpdir/$outfile" or die "couldnt open results file: $!\n" 0 0 0
599 0 my $okay = 0;
600 0 my $sites;
601 0 my $type = 'default';
602 0 ▶ while (<RESULTS>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline RESULTS)) 0 0 0
603 0 chomp $_;
604 0 ▶ if ( /^\#/ ) {next;}
Branch: 1 branch
BranchTrueFalseTotal
if (/^\#/) 0 0 0
605 0 ▶ if ( /\!/ ) {$type = 'random';} # random is last
Branch: 7 branches
BranchTrueFalseTotal
if (/\!/) { } 0 0 0
elsif (/\+/) { } 0 0 0
elsif (/\-\s+/) { } 0 0 0
elsif (/Constant/) { } 0 0 0
elsif (/All gaps/) { } 0 0 0
elsif (/Single character/) { } 0 0 0
elsif (/Synonymous/) { } 0 0 0
606 0 elsif ( /\+/ ) {$type = 'positive';}
607 0 elsif ( /\-\s+/ ) {$type = 'negative';}
608 0 elsif ( /Constant/ ) {$type = 'constant';}
609 0 elsif ( /All gaps/ ) {$type = 'all_gaps';}
610 0 elsif ( /Single character/ ) {$type = 'single_character';}
611 0 elsif ( /Synonymous/ ) {$type = 'synonymous';}
612 0 else {$type = 'default'}
613 0 ▶ if ( /^\s+(\d+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s+(\d+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/) { } 0 0 0
614 0 push @{$sites->{$type}}, [$1,$2,$3,$4,$5,$6,$7,$8,$9];
615 } else {
616 0 $DB::single=1;1;
617 }
618 }
619 0 $results = $sites;
620 0 close RESULTS;
621 # TODO: we could have a proper parser object
622 # $parser = Bio::Tools::Phylo::SLR->new(-file => "$tmpdir/$outfile",
623 # -dir => "$tmpdir");
624 };
625 0 ▶ if( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
626 0 $self->warn($self->error_string);
627 }
628 0 chdir($cwd);
629 }
630 # return ($rc,$parser);
631 0 return ($rc,$results);
632 }
633  
634 =head2 error_string
635  
636 Title : error_string
637 Usage : $obj->error_string($newval)
638 Function: Where the output from the last analysus run is stored.
639 Returns : value of error_string
640 Args : newvalue (optional)
641  
642  
643 =cut
644  
645 sub error_string{
646 0 ▶ my ($self,$value) = @_;
Subroutine error_string: not called CC=2 SCAR=17.9
Pod documented
647 0 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 0 0 0
648 0 $self->{'error_string'} = $value;
649 }
650 0 return $self->{'error_string'};
651  
652 }
653  
654 =head2 alignment
655  
656 Title : alignment
657 Usage : $slr->align($aln);
658 Function: Get/Set the L<Bio::Align::AlignI> object
659 Returns : L<Bio::Align::AlignI> object
660 Args : [optional] L<Bio::Align::AlignI>
661 Comment : We could potentially add support for running directly on a file
662 but we shall keep it simple
663 See also: L<Bio::SimpleAlign>
664  
665 =cut
666  
667 sub alignment{
668 0 ▶ my ($self,$aln) = @_;
Subroutine alignment: not called CC=5 SCAR=34.0
Pod documented
669  
670 0 ▶ if( defined $aln ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $aln) 0 0 0
671 0 ▶ if( -e $aln ) {
Branch: 2 branches
BranchTrueFalseTotal
if (-e $aln) { } 0 0 0
elsif (not ref $aln && $aln->isa('Bio::Align::AlignI')) { } 0 0 0
672 0 $self->{'_alignment'} = $aln;
673 ▶ } elsif( !ref($aln) || ! $aln->isa('Bio::Align::AlignI') ) {
Condition0%0/3
ref $aln && $aln->isa('Bio::Align::AlignI')
!ll&&!rl&&r
000
MC/DC0%0/2
ref $aln && $aln->isa('Bio::Align::AlignI')
ref $aln $aln->isa('Bio::Align::AlignI')
Truth table0%0/3
A && B
A= ref $alnB= $aln->isa('Bio::Align::AlignI')
ABresult
0X0
100
111
674 0 $self->warn("Must specify a valid Bio::Align::AlignI object to the alignment function not $aln");
675 0 return undef;
676 } else {
677 0 $self->{'_alignment'} = $aln;
678 }
679 }
680 0 return $self->{'_alignment'};
681 }
682  
683 =head2 tree
684  
685 Title : tree
686 Usage : $slr->tree($tree, %params);
687 Function: Get/Set the L<Bio::Tree::TreeI> object
688 Returns : L<Bio::Tree::TreeI>
689 Args : [optional] $tree => L<Bio::Tree::TreeI>,
690  
691 Comment : We could potentially add support for running directly on a file
692 but we shall keep it simple
693 See also: L<Bio::Tree::Tree>
694  
695 =cut
696  
697 sub tree {
698 0 ▶ my ($self, $tree, %params) = @_;
Subroutine tree: not called CC=4 SCAR=30.0
Pod documented
699 0 ▶ if( defined $tree ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tree) 0 0 0
700 0 ▶ if( ! ref($tree) || ! $tree->isa('Bio::Tree::TreeI') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $tree and $tree->isa("Bio::Tree::TreeI")) 0 0 0
Condition0%0/3
ref $tree and $tree->isa("Bio::Tree::TreeI")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $tree and $tree->isa("Bio::Tree::TreeI")
ref $tree $tree->isa("Bio::Tree::TreeI")
Truth table0%0/3
A and B
A= ref $treeB= $tree->isa("Bio::Tree::TreeI")
ABresult
0X0
100
111
701 0 $self->warn("Must specify a valid Bio::Tree::TreeI object to the alignment function");
702 }
703 0 $self->{'_tree'} = $tree;
704 }
705 0 return $self->{'_tree'};
706 }
707  
708 =head2 get_parameters
709  
710 Title : get_parameters
711 Usage : my %params = $self->get_parameters();
712 Function: returns the list of parameters as a hash
713 Returns : associative array keyed on parameter names
714 Args : none
715  
716  
717 =cut
718  
719 sub get_parameters{
720 0 ▶ my ($self) = @_;
Subroutine get_parameters: not called CC=1 SCAR=6.9
Pod documented
721 # we're returning a copy of this
722 0 return %{ $self->{'_slrparams'} };
723 }
724  
725  
726 =head2 set_parameter
727  
728 Title : set_parameter
729 Usage : $slr->set_parameter($param,$val);
730 Function: Sets a SLR parameter, will be validated against
731 the valid values as set in the %VALIDVALUES class variable.
732 The checks can be ignored if one turns off param checks like this:
733 $slr->no_param_checks(1)
734 Returns : boolean if set was success, if verbose is set to -1
735 then no warning will be reported
736 Args : $param => name of the parameter
737 $value => value to set the parameter to
738 See also: L<no_param_checks()>
739  
740 =cut
741  
742 sub set_parameter{
743 0 ▶ my ($self,$param,$value) = @_;
Subroutine set_parameter: not called CC=7 SCAR=40.3
Pod documented
744 0 ▶ unless (defined $self->{'no_param_checks'} && $self->{'no_param_checks'} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"no_param_checks"} and $self->{"no_param_checks"} == 1) 0 0 0
Condition0%0/3
defined $self->{"no_param_checks"} and $self->{"no_param_checks"} == 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"no_param_checks"} and $self->{"no_param_checks"} == 1
defined $self->{"no_param_checks"} $self->{"no_param_checks"} == 1
Truth table0%0/3
A and B
A= defined $self->{"no_param_checks"}B= $self->{"no_param_checks"} == 1
ABresult
0X0
100
111
745 0 ▶ if ( ! defined $VALIDVALUES{$param} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $Bio::Tools::Run::Phylo::SLR::VALIDVALUES{$param}) 0 0 0
746 0 $self->warn("unknown parameter $param will not be set unless you force by setting no_param_checks to true");
747 0 return 0;
748 }
749 0 ▶ if ( ref( $VALIDVALUES{$param}) =~ /ARRAY/i &&
Branch: 1 branch
BranchTrueFalseTotal
if (ref($Bio::Tools::Run::Phylo::SLR::VALIDVALUES{$param}) =~ /ARRAY/i and scalar @{$Bio::Tools::Run::Phylo::SLR::VALIDVALUES{$param};} > 0) 0 0 0
Condition0%0/3
ref($Bio::Tools::Run::Phylo::SLR::VALIDVALUES{$param}) =~ /ARRAY/i and scalar @{$Bio::Tools::Run::Phylo::SLR::VALIDVALUES{$param};} > 0
!ll&&!rl&&r
000
MC/DC0%0/2
ref($Bio::Tools::Run::Phylo::SLR::VALIDVALUES{$param}) =~ /ARRAY/i and scalar @{$Bio::Tools::Run::Phylo::SLR::VALIDVALUES{$param};} > 0
ref($Bio::Tools::Run::Phylo::SLR::VALIDVALUES{$param}) =~ /ARRAY/i scalar @{$Bio::Tools::Run::Phylo::SLR::VALIDVALUES{$param};} > 0
Truth table0%0/3
A and B
A= ref($Bio::Tools::Run::Phylo::SLR::VALIDVALUES{$param}) =~ /ARRAY/iB= scalar @{$Bio::Tools::Run::Phylo::SLR::VALIDVALUES{$param};} > 0
ABresult
0X0
100
111
750 0 scalar @{$VALIDVALUES{$param}} > 0 ) {
751
752 0 ▶ unless ( grep { $value eq $_ } @{ $VALIDVALUES{$param} } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$value eq $_;} @{$Bio::Tools::Run::Phylo::SLR::VALIDVALUES{$param};}) 0 0 0
753 0 $self->warn("parameter $param specified value $value is not recognized, please see the documentation and the code for this module or set the no_param_checks to a true value");
754 0 return 0;
755 }
756 }
757 }
758 0 $self->{'_slrparams'}->{$param} = $value;
759 0 return 1;
760 }
761  
762 =head2 set_default_parameters
763  
764 Title : set_default_parameters
765 Usage : $slr->set_default_parameters(0);
766 Function: (Re)set the default parameters from the defaults
767 (the first value in each array in the
768 %VALIDVALUES class variable)
769 Returns : none
770 Args : boolean: keep existing parameter values
771  
772  
773 =cut
774  
775 sub set_default_parameters{
776 1 ▶ my ($self,$keepold) = @_;
Subroutine set_default_parameters: called CC=6 SCAR=18.6
Pod documented
777 1 ▶ $keepold = 0 unless defined $keepold;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $keepold 1 0 1
778
779 1 ▶ while( my ($param,$val) = each %VALIDVALUES ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %Bio::Tools::Run::Phylo::SLR::VALIDVALUES) 19 1 20
780 # skip if we want to keep old values and it is already set
781 19 ▶ next if( defined $self->{'_slrparams'}->{$param} && $keepold);
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_slrparams"}{$param} and $keepold 0 19 19
Condition33%1/3
defined $self->{"_slrparams"}{$param} and $keepold
!ll&&!rl&&r
1900
MC/DC0%0/2
defined $self->{"_slrparams"}{$param} and $keepold
defined $self->{"_slrparams"}{$param} $keepold
Truth table33%1/3
A and B
A= defined $self->{"_slrparams"}{$param}B= $keepold
ABresult
0X0
100
111
782 19 ▶ if(ref($val)=~/ARRAY/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($val) =~ /ARRAY/i) { } 12 7 19
783 12 $self->{'_slrparams'}->{$param} = $val->[0];
784 } else {
785 7 $self->{'_slrparams'}->{$param} = $val;
786 }
787 }
788 }
789  
790  
791 =head1 Bio::Tools::Run::WrapperBase methods
792  
793 =cut
794  
795 =head2 no_param_checks
796  
797 Title : no_param_checks
798 Usage : $obj->no_param_checks($newval)
799 Function: Boolean flag as to whether or not we should
800 trust the sanity checks for parameter values
801 Returns : value of no_param_checks
802 Args : newvalue (optional)
803  
804  
805 =cut
806  
807 sub no_param_checks{
808 0 ▶ my ($self,$value) = @_;
Subroutine no_param_checks: not called CC=2 SCAR=17.9
Pod documented
809 0 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 0 0 0
810 0 $self->{'no_param_checks'} = $value;
811 }
812 0 return $self->{'no_param_checks'};
813 }
814  
815  
816 =head2 save_tempfiles
817  
818 Title : save_tempfiles
819 Usage : $obj->save_tempfiles($newval)
820 Function:
821 Returns : value of save_tempfiles
822 Args : newvalue (optional)
823  
824  
825 =cut
826  
827 =head2 outfile_name
828  
829 Title : outfile_name
830 Usage : my $outfile = $slr->outfile_name();
831 Function: Get/Set the name of the output file for this run
832 (if you wanted to do something special)
833 Returns : string
834 Args : [optional] string to set value to
835  
836  
837 =cut
838  
839 sub outfile_name {
840 0 ▶ my $self = shift;
Subroutine outfile_name: not called CC=3 SCAR=24.8
Pod documented
841 0 ▶ if( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
842 0 return $self->{'_slrparams'}->{'outfile'} = shift @_;
843 }
844 0 ▶ unless (defined $self->{'_slrparams'}->{'outfile'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"_slrparams"}{"outfile"}) 0 0 0
845 0 $self->{'_slrparams'}->{'outfile'} = 'out.res';
846 }
847 0 return $self->{'_slrparams'}->{'outfile'};
848 }
849  
850 =head2 tempdir
851  
852 Title : tempdir
853 Usage : my $tmpdir = $self->tempdir();
854 Function: Retrieve a temporary directory name (which is created)
855 Returns : string which is the name of the temporary directory
856 Args : none
857  
858  
859 =cut
860  
861 =head2 cleanup
862  
863 Title : cleanup
864 Usage : $slr->cleanup();
865 Function: Will cleanup the tempdir directory after an SLR run
866 Returns : none
867 Args : none
868  
869  
870 =cut
871  
872 =head2 io
873  
874 Title : io
875 Usage : $obj->io($newval)
876 Function: Gets a L<Bio::Root::IO> object
877 Returns : L<Bio::Root::IO>
878 Args : none
879  
880  
881 =cut
882  
883 sub DESTROY {
884 1 ▶ my $self= shift;
Subroutine DESTROY: called CC=2 SCAR=7.0
885 1 ▶ unless ( $self->save_tempfiles ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->save_tempfiles) 1 0 1
886 1 $self->cleanup();
887 }
888 1 $self->SUPER::DESTROY();
889 }
890  
891 1 1;
« blib/lib/Bio/Tools/Run/Eponine.pm ↑ Summary blib/lib/Bio/Tools/Run/Alignment/Muscle.pm »