| 1 | # | ||||||||||||||||||||||||||||
| 2 | # BioPerl module for Bio::TreeIO::nexml | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | # Please direct questions and support issues to <bioperl-l@bioperl.org> | ||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||
| 6 | # Cared for by Chase Miller <chmille4@gmail.com> | ||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||
| 8 | # Copyright Chase Miller | ||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||
| 10 | # You may distribute this module under the same terms as perl itself | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | # POD documentation - main docs before the code | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | =head1 NAME | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | Bio::TreeIO::nexml - A TreeIO driver module for parsing NeXML tree files | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | use Bio::TreeIO; | ||||||||||||||||||||||||||||
| 21 | my $in = Bio::TreeIO->new(-file => 'data.nexml' -format => 'Nexml'); | ||||||||||||||||||||||||||||
| 22 | while( my $tree = $in->next_tree ) { | ||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | This is a driver module for parsing tree data in a NeXML format. For | ||||||||||||||||||||||||||||
| 28 | more information on NeXML, visit L<http://www.nexml.org>. | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | =head1 FEEDBACK | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | =head2 Mailing Lists | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | User feedback is an integral part of the evolution of this and other | ||||||||||||||||||||||||||||
| 35 | Bioperl modules. Send your comments and suggestions preferably to | ||||||||||||||||||||||||||||
| 36 | the Bioperl mailing list. Your participation is much appreciated. | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | bioperl-l@bioperl.org - General discussion | ||||||||||||||||||||||||||||
| 39 | http://bioperl.org/wiki/Mailing_lists - About the mailing lists | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =head2 Support | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | Please direct usage questions or support issues to the mailing list: | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | I<bioperl-l@bioperl.org> | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | rather than to the module maintainer directly. Many experienced and | ||||||||||||||||||||||||||||
| 48 | reponsive experts will be able look at the problem and quickly | ||||||||||||||||||||||||||||
| 49 | address it. Please include a thorough description of the problem | ||||||||||||||||||||||||||||
| 50 | with code and data examples if at all possible. | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =head2 Reporting Bugs | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | Report bugs to the Bioperl bug tracking system to help us keep track | ||||||||||||||||||||||||||||
| 55 | of the bugs and their resolution. Bug reports can be submitted via | ||||||||||||||||||||||||||||
| 56 | the web: | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | https://github.com/bioperl/bioperl-live/issues | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | =head1 AUTHOR - Chase Miller | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | Email chmille4@gmail.com | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | =head1 APPENDIX | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | The rest of the documentation details each of the object methods. | ||||||||||||||||||||||||||||
| 67 | Internal methods are usually preceded with a _ | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | =cut | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | # Let the code begin... | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | package Bio::TreeIO::nexml; | ||||||||||||||||||||||||||||
| 74 | 3 | $Bio::TreeIO::nexml::VERSION = '1.7.3'; | |||||||||||||||||||||||||||
| 75 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 3 | ▶ | use lib '../..'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 78 | 3 | ▶ | use Bio::Event::EventGeneratorI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 79 | 3 | ▶ | use IO::String; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 80 | 3 | ▶ | use Bio::Nexml::Factory; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 81 | 3 | ▶ | use Bio::Phylo::IO qw (parse unparse); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 3 | ▶ | use base qw(Bio::TreeIO); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | sub _initialize { | ||||||||||||||||||||||||||
|
Subroutine
_initialize: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 88 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 89 | 0 | $self->SUPER::_initialize(@_); | |||||||||||||||||||||||||||
| 90 | 0 | $self->{_doc} = undef; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | =head2 next_tree | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | Title : next_tree | ||||||||||||||||||||||||||||
| 96 | Usage : my $tree = $treeio->next_tree | ||||||||||||||||||||||||||||
| 97 | Function: Gets the next tree in the stream | ||||||||||||||||||||||||||||
| 98 | Returns : L<Bio::Tree::TreeI> | ||||||||||||||||||||||||||||
| 99 | Args : none | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =cut | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | ▶ | sub next_tree { | ||||||||||||||||||||||||||
|
Subroutine
next_tree: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 105 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 106 | 0 | ▶ | unless ( $self->{'_parsed'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | 0 | $self->_parse; | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | 0 | return $self->{'_trees'}->[ $self->{'_treeiter'}++ ]; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | =head2 doc | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | Title : doc | ||||||||||||||||||||||||||||
| 115 | Usage : $treeio->doc | ||||||||||||||||||||||||||||
| 116 | Function: Returns the biophylo nexml document object | ||||||||||||||||||||||||||||
| 117 | Returns : Bio::Phylo::Project | ||||||||||||||||||||||||||||
| 118 | Args : none or Bio::Phylo::Project object | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | =cut | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 0 | ▶ | sub doc { | ||||||||||||||||||||||||||
|
Subroutine
doc: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 123 | 0 | my ($obj,$value) = @_; | |||||||||||||||||||||||||||
| 124 | 0 | ▶ | if( defined $value) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | 0 | $obj->{'_doc'} = $value; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | 0 | return $obj->{'_doc'}; | |||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | =head2 rewind | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | Title : rewind | ||||||||||||||||||||||||||||
| 134 | Usage : $treeio->rewind | ||||||||||||||||||||||||||||
| 135 | Function: Resets the stream | ||||||||||||||||||||||||||||
| 136 | Returns : none | ||||||||||||||||||||||||||||
| 137 | Args : none | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | =cut | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 0 | ▶ | sub rewind { | ||||||||||||||||||||||||||
|
Subroutine
rewind: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 142 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 143 | 0 | $self->{'_treeiter'} = 0; | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 0 | ▶ | sub _parse { | ||||||||||||||||||||||||||
|
Subroutine
_parse: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 147 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 0 | $self->{'_parsed'} = 1; | |||||||||||||||||||||||||||
| 150 | 0 | $self->{'_treeiter'} = 0; | |||||||||||||||||||||||||||
| 151 | 0 | my $fac = Bio::Nexml::Factory->new(); | |||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | # Only pass filename if filehandle is not available, | ||||||||||||||||||||||||||||
| 154 | # or "Bio::Phylo" will create a new filehandle that ends | ||||||||||||||||||||||||||||
| 155 | # out of scope and can't be closed directly, leaving 2 open | ||||||||||||||||||||||||||||
| 156 | # filehandles for the same file (so file can't be deleted) | ||||||||||||||||||||||||||||
| 157 | 0 | my $file_arg; | |||||||||||||||||||||||||||
| 158 | my $file_value; | ||||||||||||||||||||||||||||
| 159 | 0 | ▶ | if ( exists $self->{'_filehandle'} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $self->{"_filehandle"} and defined $self->{"_filehandle"}
MC/DC0%0/2
exists $self->{"_filehandle"} and defined $self->{"_filehandle"}
exists $self->{"_filehandle"}
defined $self->{"_filehandle"}
Truth table0%0/3
A and B
A= exists $self->{"_filehandle"}B= defined $self->{"_filehandle"}
| |||||||||||||||||||||||||||||
| 160 | and defined $self->{'_filehandle'} | ||||||||||||||||||||||||||||
| 161 | ) { | ||||||||||||||||||||||||||||
| 162 | 0 | $file_arg = '-handle'; | |||||||||||||||||||||||||||
| 163 | 0 | $file_value = $self->{'_filehandle'}; | |||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | else { | ||||||||||||||||||||||||||||
| 166 | 0 | $file_arg = '-file'; | |||||||||||||||||||||||||||
| 167 | 0 | $file_value = $self->{'_file'}; | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 0 | $self->doc(parse( | |||||||||||||||||||||||||||
| 171 | $file_arg => $file_value, | ||||||||||||||||||||||||||||
| 172 | '-format' => 'nexml', | ||||||||||||||||||||||||||||
| 173 | '-as_project' => '1' | ||||||||||||||||||||||||||||
| 174 | ) | ||||||||||||||||||||||||||||
| 175 | ); | ||||||||||||||||||||||||||||
| 176 | 0 | $self->{'_trees'} = $fac->create_bperl_tree($self); | |||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | =head2 write_tree | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | Title : write_tree | ||||||||||||||||||||||||||||
| 182 | Usage : $treeio->write_tree($tree); | ||||||||||||||||||||||||||||
| 183 | Function: Writes a tree onto the stream | ||||||||||||||||||||||||||||
| 184 | Returns : none | ||||||||||||||||||||||||||||
| 185 | Args : L<Bio::Tree::TreeI> | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | =cut | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 0 | ▶ | sub write_tree { | ||||||||||||||||||||||||||
|
Subroutine
write_tree: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 191 | 0 | my ($self, $bp_tree) = @_; | |||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 0 | my $fac = Bio::Nexml::Factory->new(); | |||||||||||||||||||||||||||
| 194 | 0 | my $taxa = $fac->create_bphylo_taxa($bp_tree); | |||||||||||||||||||||||||||
| 195 | 0 | my ($tree) = $fac->create_bphylo_tree($bp_tree, $taxa); | |||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | 0 | my $forest = Bio::Phylo::Factory->create_forest(); | |||||||||||||||||||||||||||
| 198 | 0 | $self->doc(Bio::Phylo::Factory->create_project()); | |||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | 0 | $forest->set_taxa($taxa); | |||||||||||||||||||||||||||
| 201 | 0 | $forest->insert($tree); | |||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | 0 | $self->doc->insert($forest); | |||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 0 | my $ret = $self->_print($self->doc->to_xml()); | |||||||||||||||||||||||||||
| 206 | 0 | $self->flush; | |||||||||||||||||||||||||||
| 207 | 0 | return $ret; | |||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 3 | 1; | |||||||||||||||||||||||||||