File Coverage

blib/lib/Bio/Tools/Run/Phylo/Hyphy/SLAC.pm
Criterion Covered Total %
statement 21 57 36.8
branch 0 18 0.0
condition n/a
subroutine 7 11 63.6
pod 4 4 100.0
total 32 90 35.5


line stmt bran cond sub pod time code
1             # $Id$
2             #
3             # BioPerl module for Bio::Tools::Run::Phylo::Hyphy::SLAC
4             #
5             # Please direct questions and support issues to
6             #
7             # Cared for by Albert Vilella
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
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     1   107488 use strict;
  1         2  
  1         24  
97 1     1   471 use Bio::Root::Root;
  1         17971  
  1         35  
98 1     1   499 use Bio::AlignIO;
  1         71905  
  1         38  
99 1     1   404 use Bio::TreeIO;
  1         14312  
  1         31  
100 1     1   470 use Bio::Tools::Run::Phylo::Hyphy::Base;
  1         2  
  1         27  
101 1     1   5 use Bio::Tools::Run::WrapperBase;
  1         1  
  1         16  
102              
103 1     1   3 use base qw(Bio::Root::Root Bio::Tools::Run::Phylo::Hyphy::Base);
  1         1  
  1         512  
104              
105             =head2 Default Values
106              
107             Valid and default values for SLAC are listed below. The default
108             values are always the first one listed. These descriptions are
109             essentially lifted from the python wrapper or provided by the author.
110              
111             INCOMPLETE DOCUMENTATION OF ALL METHODS
112              
113             =cut
114              
115             =head2 valid_values
116              
117             Title : valid_values
118             Usage : $factory->valid_values()
119             Function: returns the possible parameters
120             Returns: an array holding all possible parameters. The default
121             values are always the first one listed. These descriptions are
122             essentially lifted from the python wrapper or provided by the author.
123             Args : None
124              
125             =cut
126              
127              
128              
129             sub valid_values {
130 0 0   0 1   my $null = ($^O =~ m/mswin/i) ? 'NUL' : '/dev/null';
131             return
132             (
133 0           {'geneticCode' => [ "Universal","VertebratemtDNA","YeastmtDNA","Mold/ProtozoanmtDNA",
134             "InvertebratemtDNA","CiliateNuclear","EchinodermmtDNA","EuplotidNuclear",
135             "Alt.YeastNuclear","AscidianmtDNA","FlatwormmtDNA","BlepharismaNuclear"]},
136             {'New/Restore' => [ "New Analysis", "Restore"]},
137             {'tempalnfile' => undef }, # aln file goes here
138             {'Model Options' => [ { "Custom" => '010010' },
139             { "Default" => undef } ]
140             },
141             {'temptreefile' => undef }, # tree file goes here
142             {'Model Fit Results' => [ $null] }, # Windows have NUL instead of /dev/null
143             {'dN/dS bias parameter' => [ { "Estimate dN/dS only" => undef },
144             { "Neutral" => undef },
145             { "Estimate" => undef },
146             { "Estimate + CI" => undef },
147             { "User" => '3' } ] },
148             {'Ancestor Counting' => [ 'Single Ancestor Counting','Weighted Ancestor Counting',
149             'Sample Ancestal States','Process Sampled Ancestal States',
150             'One rate FEL','Two rate FEL','Rate Distribution',
151             'Full site-by-site LRT','Multirate FEL'] },
152             {'SLAC Options' => ['Full tree','Tips vs Internals'] },
153             {'Treatment of Ambiguities' => ['Resolved','Averaged'] },
154             {'Test Statistic' => ['Approximate','Simulated Null'] },
155             {'Significance level' => '0.05' },
156             {'Output options' => 'Export to File' }, #we force a tsv file here
157             {'outfile' => undef }, # outfile goes here
158             {'Rate class estimator' => [ 'Skip','Count'] },
159             );
160             }
161              
162              
163             =head2 new
164              
165             Title : new
166             Usage : my $obj = Bio::Tools::Run::Phylo::Hyphy::SLAC->new();
167             Function: Builds a new Bio::Tools::Run::Phylo::Hyphy::SLAC object
168             Returns : Bio::Tools::Run::Phylo::Hyphy::SLAC
169             Args : -alignment => the Bio::Align::AlignI object
170             -save_tempfiles => boolean to save the generated tempfiles and
171             NOT cleanup after onesself (default FALSE)
172             -tree => the Bio::Tree::TreeI object
173             -params => a hashref of parameters (all passed to set_parameter)
174             -executable => where the hyphy executable resides
175              
176             See also: L, L
177              
178             =cut
179              
180             sub new {
181 0     0 1   my($class,@args) = @_;
182              
183 0           my $self = $class->SUPER::new(@args);
184              
185 0           my ($aln, $tree, $st, $params, $exe,
186             $ubl) = $self->_rearrange([qw(ALIGNMENT TREE SAVE_TEMPFILES
187             PARAMS EXECUTABLE)],
188             @args);
189 0 0         defined $aln && $self->alignment($aln);
190 0 0         defined $tree && $self->tree($tree);
191 0 0         defined $st && $self->save_tempfiles($st);
192 0 0         defined $exe && $self->executable($exe);
193 0           $self->set_default_parameters();
194 0 0         if( defined $params ) {
195 0 0         if( ref($params) !~ /HASH/i ) {
196 0           $self->warn("Must provide a valid hash ref for parameter -FLAGS");
197             } else {
198 0           map { $self->set_parameter($_, $$params{$_}) } keys %$params;
  0            
199             }
200             }
201 0           return $self;
202             }
203              
204              
205             =head2 run
206              
207             Title : run
208             Usage : my ($rc,$results) = $slac->run($aln);
209             Function: run the slac analysis using the default or updated parameters
210             the alignment parameter must have been set
211             Returns : Return code, hash
212             Args : L object,
213             L object [optional]
214              
215              
216             =cut
217              
218             sub run {
219 0     0 1   my $self = shift;
220 0           my $results = {};
221 0           my ($rc, $run_output) = $self->SUPER::run();
222 0           my $outfile = $self->outfile_name();
223 0 0         open(OUTFILE, "$outfile") or $self->throw("cannot open $outfile for reading");
224 0           my $readed_header = 0;
225 0           my @elems;
226 0           while (my $line = ) {
227 0 0         if ($readed_header) {
228             # SLAC results are tsv
229 0           my @values = split("\t",$line);
230 0           for my $i (0 .. (scalar(@values)-1)) {
231 0           $elems[$i] =~ s/\n//g;
232 0           push @{$results->{$elems[$i]}}, $values[$i];
  0            
233             }
234             } else {
235 0           @elems = split("\t",$line);
236 0           $readed_header = 1;
237             }
238             }
239 0           return ($rc, $results);
240             }
241              
242             =head2 create_wrapper
243              
244             Title : create_wrapper
245             Usage : $self->create_wrapper
246             Function: It will create the wrapper file that interfaces with the analysis bf file
247             Example :
248             Returns :
249             Args :
250              
251              
252             =cut
253              
254             sub create_wrapper {
255 0     0 1   my $self = shift;
256              
257 0           my $batchfile = "QuickSelectionDetection.bf";
258 0           $self->SUPER::create_wrapper($batchfile);
259             }
260              
261             1;