Tools/Run/Phylo/Hyphy/SLAC.pm

filter: Statementstmt 37.9% 22 / 58 Branchbran 0.0% 0 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 63.6% 7 / 11 Podpod 100% 4 / 4 totaltotal 35.4% 33 / 93 CC 12 SCAR 32.4
CC
12
Cov
28%
new
56.0
run
30.0
valid_values
6.0
CRAP 25.6
« Tools/Run/Phylo/Hyphy/FEL.pm ↑ Summary Factory/EMBOSS.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 strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
97 1 ▶use Bio::Root::Root;
Subroutine BEGIN: called CC=1 SCAR=0.0
98 1 ▶use Bio::AlignIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
99 1 ▶use Bio::TreeIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
100 1 ▶use Bio::Tools::Run::Phylo::Hyphy::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
101 1 ▶use Bio::Tools::Run::WrapperBase;
Subroutine BEGIN: called CC=1 SCAR=0.0
102  
103 1 ▶use base qw(Bio::Root::Root Bio::Tools::Run::Phylo::Hyphy::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
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 0 ▶sub valid_values {
Subroutine valid_values: not called CC=2 SCAR=17.9
Pod documented
130 0 ▶ my $null = ($^O =~ m/mswin/i) ? 'NUL' : '/dev/null';
Branch: 1 branch
BranchTrueFalseTotal
$^O =~ /mswin/i ? : 0 0 0
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<Bio::Tree::TreeI>, L<Bio::Align::AlignI>
177  
178 =cut
179  
180 0 ▶sub new {
Subroutine new: not called CC=7 SCAR=40.3
Pod documented
181 0 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 ▶ defined $aln && $self->alignment($aln);
Branch: 1 branch
BranchTrueFalseTotal
defined $aln and $self->alignment($aln) 0 0 0
190 0 ▶ defined $tree && $self->tree($tree);
Branch: 1 branch
BranchTrueFalseTotal
defined $tree and $self->tree($tree) 0 0 0
191 0 ▶ defined $st && $self->save_tempfiles($st);
Branch: 1 branch
BranchTrueFalseTotal
defined $st and $self->save_tempfiles($st) 0 0 0
192 0 ▶ defined $exe && $self->executable($exe);
Branch: 1 branch
BranchTrueFalseTotal
defined $exe and $self->executable($exe) 0 0 0
193 0 $self->set_default_parameters();
194 0 ▶ if( defined $params ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params) 0 0 0
195 0 ▶ if( ref($params) !~ /HASH/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref($params) =~ /HASH/i) { } 0 0 0
196 0 $self->warn("Must provide a valid hash ref for parameter -FLAGS");
197 } else {
198 0 map { $self->set_parameter($_, $$params{$_}) } keys %$params;
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<Bio::Align::AlignI> object,
213 L<Bio::Tree::TreeI> object [optional]
214  
215  
216 =cut
217  
218 0 ▶sub run {
Subroutine run: not called CC=5 SCAR=34.0
Pod documented
219 0 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 ▶ 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
224 0 my $readed_header = 0;
225 0 my @elems;
226 0 ▶ while (my $line = <OUTFILE>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline OUTFILE)) 0 0 0
227 0 ▶ if ($readed_header) {
Branch: 1 branch
BranchTrueFalseTotal
if ($readed_header) { } 0 0 0
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];
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 0 ▶sub create_wrapper {
Subroutine create_wrapper: not called CC=1 SCAR=6.9
Pod documented
255 0 my $self = shift;
256  
257 0 my $batchfile = "QuickSelectionDetection.bf";
258 0 $self->SUPER::create_wrapper($batchfile);
259 }
260  
261 1 1;
« Tools/Run/Phylo/Hyphy/FEL.pm ↑ Summary Factory/EMBOSS.pm »