| 1 | # $Id$ | ||||||||||
| 2 | # | ||||||||||
| 3 | # BioPerl module for Bio::Tools::Run::Phylo::Hyphy::REL | ||||||||||
| 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::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<bioperl-l@bioperl.org> | ||||||||||
| 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 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 99 | 1 | ▶ | use Bio::Root::Root; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 100 | 1 | ▶ | use Bio::AlignIO; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 101 | 1 | ▶ | use Bio::TreeIO; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 102 | 1 | ▶ | use Bio::Tools::Run::Phylo::Hyphy::Base; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 103 | 1 | ▶ | use Bio::Tools::Run::WrapperBase; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 104 | |||||||||||
| 105 | 1 | ▶ | use base qw(Bio::Root::Root Bio::Tools::Run::Phylo::Hyphy::Base); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 | 1 | ▶ | sub valid_values { | ||||||||
|
Subroutine
valid_values: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 121 | return | ||||||||||
| 122 | ( | ||||||||||
| 123 | 1 | {'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<Bio::Tree::TreeI>, L<Bio::Align::AlignI> | ||||||||||
| 147 | |||||||||||
| 148 | =cut | ||||||||||
| 149 | |||||||||||
| 150 | 1 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=7 SCAR=23.7
Pod
documented
| |||||||||||
| 151 | 1 | my($class,@args) = @_; | |||||||||
| 152 | 1 | my $self = $class->SUPER::new(@args); | |||||||||
| 153 | 1 | my ($aln, $tree, $st, $params, $exe, | |||||||||
| 154 | $ubl) = $self->_rearrange([qw(ALIGNMENT TREE SAVE_TEMPFILES PARAMS EXECUTABLE)], @args); | ||||||||||
| 155 | 1 | ▶ | defined $aln && $self->alignment($aln); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 156 | 1 | ▶ | defined $tree && $self->tree($tree); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 157 | 1 | ▶ | defined $st && $self->save_tempfiles($st); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 158 | 1 | ▶ | defined $exe && $self->executable($exe); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 159 | |||||||||||
| 160 | 1 | $self->set_default_parameters(); | |||||||||
| 161 | 1 | ▶ | if( defined $params ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 162 | 0 | ▶ | if( ref($params) !~ /HASH/i ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 163 | 0 | $self->warn("Must provide a valid hash ref for parameter -FLAGS"); | |||||||||
| 164 | } else { | ||||||||||
| 165 | 0 | map { $self->set_parameter($_, $$params{$_}) } keys %$params; | |||||||||
| 166 | } | ||||||||||
| 167 | } | ||||||||||
| 168 | 1 | 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<Bio::Align::AlignI> object, | ||||||||||
| 180 | L<Bio::Tree::TreeI> object [optional] | ||||||||||
| 181 | |||||||||||
| 182 | |||||||||||
| 183 | =cut | ||||||||||
| 184 | |||||||||||
| 185 | 0 | ▶ | sub run { | ||||||||
|
Subroutine
run: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||
| 186 | 0 | 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 | ▶ | open(OUTFILE, "$outfile") or $self->throw("cannot open $outfile for reading"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 191 | 0 | my $readed_header = 0; | |||||||||
| 192 | 0 | my @elems; | |||||||||
| 193 | 0 | ▶ | while (<OUTFILE>) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 194 | 0 | ▶ | if ($readed_header) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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]; | |||||||||
| 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 | 0 | ▶ | sub create_wrapper { | ||||||||
|
Subroutine
create_wrapper: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 222 | 0 | my $self = shift; | |||||||||
| 223 | |||||||||||
| 224 | 0 | my $batchfile = "YangNielsenBranchSite2005.bf"; | |||||||||
| 225 | 0 | $self->SUPER::create_wrapper($batchfile); | |||||||||
| 226 | } | ||||||||||
| 227 | |||||||||||
| 228 | 1 | 1; | |||||||||