1
# $Id: nexus.pm,v 1.2 2003/12/06 18:10:26 jason Exp $
3
# BioPerl module for Bio::TreeIO::nexus
5
# Cared for by Jason Stajich <jason-at-open-bio-dot-org>
7
# Copyright Jason Stajich
9
# You may distribute this module under the same terms as perl itself
11
# POD documentation - main docs before the code
15
Bio::TreeIO::nexus - A TreeIO driver module for parsing Nexus tree output from PAUP
20
my $in = new Bio::TreeIO(-file => 't/data/cat_tre.tre');
21
while( my $tree = $in->next_tree ) {
26
This is a driver module for parsing PAUP Nexus tree format which
27
basically is just a remapping of trees.
33
User feedback is an integral part of the evolution of this and other
34
Bioperl modules. Send your comments and suggestions preferably to
35
the Bioperl mailing list. Your participation is much appreciated.
37
bioperl-l@bioperl.org - General discussion
38
http://bioperl.org/MailList.shtml - About the mailing lists
42
Report bugs to the Bioperl bug tracking system to help us keep track
43
of the bugs and their resolution. Bug reports can be submitted via
46
http://bugzilla.bioperl.org/
48
=head1 AUTHOR - Jason Stajich
50
Email jason-at-open-bio-dot-org
52
Describe contact details here
56
Additional contributors names and emails here
60
The rest of the documentation details each of the object methods.
61
Internal methods are usually preceded with a _
66
# Let the code begin...
69
package Bio::TreeIO::nexus;
74
use Bio::Event::EventGeneratorI;
77
@ISA = qw(Bio::TreeIO );
83
Usage : my $tree = $treeio->next_tree
84
Function: Gets the next tree in the stream
85
Returns : Bio::Tree::TreeI
93
unless ( $self->{'_parsed'} ) {
96
return $self->{'_trees'}->[$self->{'_treeiter'}++];
100
shift->{'_treeiter'} = 0;
106
$self->{'_parsed'} = 1;
107
$self->{'_treeiter'} = 0;
109
while( defined ( $_ = $self->_readline ) ) {
113
return unless( defined $_ );
115
unless( /^\#NEXUS/i ) {
116
$self->warn("File does not start with #NEXUS"); #'
121
while( defined ( $_ = $self->_readline ) ) {
127
} elsif( /^\s*Translate/ ) {
129
} elsif( $state == 3) {
130
if( /^\s+(\S+)\s+(\S+)\,\s*$/ ) {
135
} elsif( /^tree\s+(\S+)\s+\=\s+(?:\[\S+\])?\s+(.+\;)\s*$/ ) {
136
my $buf = new IO::String($2);
137
my $treeio = new Bio::TreeIO(-format => 'newick',
139
my $tree = $treeio->next_tree;
140
foreach my $node ( grep { $_->is_Leaf } $tree->get_nodes ) {
142
my $lookup = $translate{$id};
143
$node->id($lookup || $id);
145
push @{$self->{'_trees'}},$tree;
147
} elsif( /^\s*Begin\s+trees;/i ) {
149
} elsif( /^\s*End(\s+trees);/i ) {
160
Usage : $treeio->write_tree($tree);
161
Function: Writes a tree onto the stream
163
Args : Bio::Tree::TreeI
169
my ($self,$tree) = @_;
170
$self->throw("Cannot call method write_tree on Bio::TreeIO object must use a subclass");