File Coverage

blib/lib/Bio/Tools/Run/Phylo/Hyphy/REL.pm
Criterion Covered Total %
statement 32 56 57.1
branch 5 16 31.2
condition n/a
subroutine 9 11 81.8
pod 4 4 100.0
total 50 87 57.4


line stmt bran cond sub pod time code
1             # $Id$
2             #
3             # BioPerl module for Bio::Tools::Run::Phylo::Hyphy::REL
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::REL - Wrapper around the Hyphy REL analysis
18              
19             =head1 SYNOPSIS
20              
21             use Bio::Tools::Run::Phylo::Hyphy::REL;
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 $rel = Bio::Tools::Run::Phylo::Hyphy::REL->new();
34             $rel->alignment($aln);
35             $rel->tree($tree);
36             my ($rc,$results) = $rel->run();
37              
38             =head1 DESCRIPTION
39              
40             This is a wrapper around the REL analysis of HyPhy ([Hy]pothesis
41             Testing Using [Phy]logenies) package of Sergei Kosakowsky Pond,
42             Spencer V. Muse, Simon D.W. Frost and Art Poon. See
43             http://www.hyphy.org for more information.
44              
45             This module will generate the correct list of options for interfacing
46             with TemplateBatchFiles/Ghostrides/Wrapper.bf.
47              
48             =head1 FEEDBACK
49              
50             =head2 Mailing Lists
51              
52             User feedback is an integral part of the evolution of this and other
53             Bioperl modules. Send your comments and suggestions preferably to
54             the Bioperl mailing list. Your participation is much appreciated.
55              
56             bioperl-l@bioperl.org - General discussion
57             http://bioperl.org/wiki/Mailing_lists - About the mailing lists
58              
59             =head2 Support
60              
61             Please direct usage questions or support issues to the mailing list:
62              
63             I
64              
65             rather than to the module maintainer directly. Many experienced and
66             reponsive experts will be able look at the problem and quickly
67             address it. Please include a thorough description of the problem
68             with code and data examples if at all possible.
69              
70             =head2 Reporting Bugs
71              
72             Report bugs to the Bioperl bug tracking system to help us keep track
73             of the bugs and their resolution. Bug reports can be submitted via the
74             web:
75              
76             http://redmine.open-bio.org/projects/bioperl/
77              
78             =head1 AUTHOR - Albert Vilella
79              
80             Email avilella-at-gmail-dot-com
81              
82             =head1 CONTRIBUTORS
83              
84             Additional contributors names and emails here
85              
86             =head1 APPENDIX
87              
88             The rest of the documentation details each of the object methods.
89             Internal methods are usually preceded with a _
90              
91             =cut
92              
93              
94             # Let the code begin...
95              
96              
97             package Bio::Tools::Run::Phylo::Hyphy::REL;
98 1     1   839 use strict;
  1         2  
  1         23  
99 1     1   4 use Bio::Root::Root;
  1         0  
  1         13  
100 1     1   3 use Bio::AlignIO;
  1         1  
  1         16  
101 1     1   3 use Bio::TreeIO;
  1         1  
  1         12  
102 1     1   12 use Bio::Tools::Run::Phylo::Hyphy::Base;
  1         1  
  1         14  
103 1     1   2 use Bio::Tools::Run::WrapperBase;
  1         1  
  1         18  
104              
105 1     1   3 use base qw(Bio::Root::Root Bio::Tools::Run::Phylo::Hyphy::Base);
  1         1  
  1         466  
106              
107              
108             =head2 valid_values
109              
110             Title : valid_values
111             Usage : $factory->valid_values()
112             Function: returns the possible parameters
113             Returns: an array holding all possible parameters. The default
114             values are always the first one listed. These descriptions are
115             essentially lifted from the python wrapper or provided by the author.
116             Args : None
117              
118             =cut
119              
120             sub valid_values {
121             return
122             (
123 1     1 1 13 {'geneticCode' => [ "Universal","VertebratemtDNA","YeastmtDNA","Mold/ProtozoanmtDNA",
124             "InvertebratemtDNA","CiliateNuclear","EchinodermmtDNA","EuplotidNuclear",
125             "Alt.YeastNuclear","AscidianmtDNA","FlatwormmtDNA","BlepharismaNuclear"]},
126             {'tempalnfile' => undef }, # aln file goes here
127             {'temptreefile' => undef }, # tree file goes here
128             {'Model' => [ "Null for Test 1", "Null for Test 2", "Alternative"]},
129             {'outfile' => undef } # site-by-site conditional probabilities go to this file
130             );
131             }
132              
133             =head2 new
134              
135             Title : new
136             Usage : my $obj = Bio::Tools::Run::Phylo::Hyphy::REL->new();
137             Function: Builds a new Bio::Tools::Run::Phylo::Hyphy::REL object
138             Returns : Bio::Tools::Run::Phylo::Hyphy::REL
139             Args : -alignment => the Bio::Align::AlignI object
140             -save_tempfiles => boolean to save the generated tempfiles and
141             NOT cleanup after onesself (default FALSE)
142             -tree => the Bio::Tree::TreeI object
143             -params => a hashref of parameters (all passed to set_parameter)
144             -executable => where the hyphy executable resides
145              
146             See also: L, L
147              
148             =cut
149              
150             sub new {
151 1     1 1 77 my($class,@args) = @_;
152 1         11 my $self = $class->SUPER::new(@args);
153 1         18 my ($aln, $tree, $st, $params, $exe,
154             $ubl) = $self->_rearrange([qw(ALIGNMENT TREE SAVE_TEMPFILES PARAMS EXECUTABLE)], @args);
155 1 50       7 defined $aln && $self->alignment($aln);
156 1 50       13 defined $tree && $self->tree($tree);
157 1 50       3 defined $st && $self->save_tempfiles($st);
158 1 50       2 defined $exe && $self->executable($exe);
159              
160 1         9 $self->set_default_parameters();
161 1 50       3 if( defined $params ) {
162 0 0       0 if( ref($params) !~ /HASH/i ) {
163 0         0 $self->warn("Must provide a valid hash ref for parameter -FLAGS");
164             } else {
165 0         0 map { $self->set_parameter($_, $$params{$_}) } keys %$params;
  0         0  
166             }
167             }
168 1         3 return $self;
169             }
170              
171              
172             =head2 run
173              
174             Title : run
175             Usage : my ($rc,$results) = $rel->run($aln);
176             Function: run the rel analysis using the default or updated parameters
177             the alignment parameter must have been set
178             Returns : Return code, Hash
179             Args : L object,
180             L object [optional]
181              
182              
183             =cut
184              
185             sub run {
186 0     0 1   my $self = shift;
187 0           my ($rc,$run_results) = $self->SUPER::run();
188 0           my $results = {};
189 0           my $outfile = $self->outfile_name();
190 0 0         open(OUTFILE, "$outfile") or $self->throw("cannot open $outfile for reading");
191 0           my $readed_header = 0;
192 0           my @elems;
193 0           while () {
194 0 0         if ($readed_header) {
195             # REL results are csv
196 0           my @values = split("\,",$_);
197 0           for my $i (0 .. (scalar(@values)-1)) {
198 0           $elems[$i] =~ s/\n//g;
199 0           push @{$results->{$elems[$i]}}, $values[$i];
  0            
200             }
201             } else {
202 0           @elems = split("\,",$_);
203 0           $readed_header = 1;
204             }
205             }
206 0           return ($rc,$results);
207             }
208              
209             =head2 create_wrapper
210              
211             Title : create_wrapper
212             Usage : $self->create_wrapper
213             Function: It will create the wrapper file that interfaces with the analysis bf file
214             Example :
215             Returns :
216             Args :
217              
218              
219             =cut
220              
221             sub create_wrapper {
222 0     0 1   my $self = shift;
223              
224 0           my $batchfile = "YangNielsenBranchSite2005.bf";
225 0           $self->SUPER::create_wrapper($batchfile);
226             }
227              
228             1;