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://github.com/bioperl/bioperl-live/issues
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();
152 # Only pass filename if filehandle is not available,
153 # or "Bio::Phylo" will create a new filehandle that ends
154 # out of scope and can't be closed directly, leaving 2 open
155 # filehandles for the same file (so file can't be deleted)
158 if ( exists $self->{'_filehandle'}
159 and defined $self->{'_filehandle'}
161 $file_arg = '-handle';
162 $file_value = $self->{'_filehandle'};
166 $file_value = $self->{'_file'};
170 $file_arg => $file_value,
171 '-format' => 'nexml',
175 $self->{'_trees'} = $fac->create_bperl_tree($self);
181 Usage : $treeio->write_tree($tree);
182 Function: Writes a tree onto the stream
184 Args : L<Bio::Tree::TreeI>
190 my ($self, $bp_tree) = @_;
192 my $fac = Bio
::Nexml
::Factory
->new();
193 my $taxa = $fac->create_bphylo_taxa($bp_tree);
194 my ($tree) = $fac->create_bphylo_tree($bp_tree, $taxa);
196 my $forest = Bio
::Phylo
::Factory
->create_forest();
197 $self->doc(Bio
::Phylo
::Factory
->create_project());
199 $forest->set_taxa($taxa);
200 $forest->insert($tree);
202 $self->doc->insert($forest);
204 my $ret = $self->_print($self->doc->to_xml());