2 # BioPerl module for Bio::TreeIO::nexml
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Chase Miller <chmille4@gmail.com>
8 # Copyright Chase Miller
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
16 Bio::TreeIO::nexml - A TreeIO driver module for parsing NeXML tree files
21 my $in = Bio::TreeIO->new(-file => 'data.nexml' -format => 'Nexml');
22 while( my $tree = $in->next_tree ) {
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>.
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.
38 bioperl-l@bioperl.org - General discussion
39 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
43 Please direct usage questions or support issues to the mailing list:
45 I<bioperl-l@bioperl.org>
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.
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
58 https://redmine.open-bio.org/projects/bioperl/
60 =head1 AUTHOR - Chase Miller
62 Email chmille4@gmail.com
66 The rest of the documentation details each of the object methods.
67 Internal methods are usually preceded with a _
71 # Let the code begin...
73 package Bio
::TreeIO
::nexml
;
77 use Bio
::Event
::EventGeneratorI
;
79 use Bio
::Nexml
::Factory
;
80 use Bio
::Phylo
::IO qw
(parse unparse
);
83 use base
qw(Bio::TreeIO);
88 $self->SUPER::_initialize
(@_);
89 $self->{_doc
} = undef;
95 Usage : my $tree = $treeio->next_tree
96 Function: Gets the next tree in the stream
97 Returns : L<Bio::Tree::TreeI>
105 unless ( $self->{'_parsed'} ) {
108 return $self->{'_trees'}->[ $self->{'_treeiter'}++ ];
115 Function: Returns the biophylo nexml document object
116 Returns : Bio::Phylo::Project
117 Args : none or Bio::Phylo::Project object
122 my ($obj,$value) = @_;
123 if( defined $value) {
124 $obj->{'_doc'} = $value;
126 return $obj->{'_doc'};
133 Usage : $treeio->rewind
134 Function: Resets the stream
142 $self->{'_treeiter'} = 0;
148 $self->{'_parsed'} = 1;
149 $self->{'_treeiter'} = 0;
150 my $fac = Bio
::Nexml
::Factory
->new();
154 '-file' => $self->{'_file'},
155 '-format' => 'nexml',
159 $self->{'_trees'} = $fac->create_bperl_tree($self);
165 Usage : $treeio->write_tree($tree);
166 Function: Writes a tree onto the stream
168 Args : L<Bio::Tree::TreeI>
174 my ($self, $bp_tree) = @_;
176 my $fac = Bio
::Nexml
::Factory
->new();
177 my $taxa = $fac->create_bphylo_taxa($bp_tree);
178 my ($tree) = $fac->create_bphylo_tree($bp_tree, $taxa);
180 my $forest = Bio
::Phylo
::Factory
->create_forest();
181 $self->doc(Bio
::Phylo
::Factory
->create_project());
183 $forest->set_taxa($taxa);
184 $forest->insert($tree);
186 $self->doc->insert($forest);
188 my $ret = $self->_print($self->doc->to_xml());