Bio::TreeIO nexus
SummaryIncluded librariesPackage variablesSynopsisDescriptionGeneral documentationMethods
Summary
Bio::TreeIO::nexus - A TreeIO driver module for parsing Nexus tree output from PAUP
Package variables
No package variables defined.
Included modules
Bio::Event::EventGeneratorI
Bio::TreeIO
IO::String
Inherit
Bio::TreeIO
Synopsis
  use Bio::TreeIO;
  my $in = new Bio::TreeIO(-file => 't/data/cat_tre.tre');
  while( my $tree = $in->next_tree ) {
  }
Description
This is a driver module for parsing PAUP Nexus tree format which
basically is just a remapping of trees.
Methods
next_treeDescriptionCode
rewind
No description
Code
_parse
No description
Code
write_treeDescriptionCode
Methods description
next_treecode    nextTop
 Title   : next_tree
 Usage   : my $tree = $treeio->next_tree
 Function: Gets the next tree in the stream
 Returns : Bio::Tree::TreeI
 Args    : none
write_treecodeprevnextTop
 Title   : write_tree
 Usage   : $treeio->write_tree($tree);
 Function: Writes a tree onto the stream
 Returns : none
 Args    : Bio::Tree::TreeI
Methods code
next_treedescriptionprevnextTop
sub next_tree {
    my ($self) = @_;
    unless ( $self->{'_parsed'} ) { 
	$self->_parse;
    }
    return $self->{'_trees'}->[$self->{'_treeiter'}++];
}
rewinddescriptionprevnextTop
sub rewind {
     shift->{'_treeiter'} = 0;
}
_parsedescriptionprevnextTop
sub _parse {
   my ($self) = @_;

   $self->{'_parsed'} = 1;
   $self->{'_treeiter'} = 0;

   while( defined ( $_ = $self->_readline ) ) {
       next if /^\s+$/;
       last;
   }
   return unless( defined $_ );
   
   unless( /^\#NEXUS/i ) {
       $self->warn("File does not start with #NEXUS"); #'
return; } my $state = 0; my %translate; while( defined ( $_ = $self->_readline ) ) { if( $state > 0 ) { if( /^\[/ ) { $state++; } elsif( /^\]/ ) { $state--; } elsif( /^\s*Translate/ ) { $state = 3; } elsif( $state == 3) { if( /^\s+(\S+)\s+(\S+)\,\s*$/ ) { $translate{$1} = $2; } elsif( /^\s+;/) { $state = 1; } } elsif( /^tree\s+(\S+)\s+\=\s+(?:\[\S+\])?\s+(.+\;)\s*$/ ) { my $buf = new IO::String($2); my $treeio = new Bio::TreeIO(-format => 'newick', -fh => $buf); my $tree = $treeio->next_tree; foreach my $node ( grep { $_->is_Leaf } $tree->get_nodes ) { my $id = $node->id; my $lookup = $translate{$id}; $node->id($lookup || $id); } push @{$self->{'_trees'}},$tree; } } elsif( /^\s*Begin\s+trees;/i ) { $state = 1; } elsif( /^\s*End(\s+trees);/i ) { $state = 0; return; } }
}
write_treedescriptionprevnextTop
sub write_tree {
   my ($self,$tree) = @_;
   $self->throw("Cannot call method write_tree on Bio::TreeIO object must use a subclass");
}
General documentation
FEEDBACKTop
Mailing ListsTop
User feedback is an integral part of the evolution of this and other
Bioperl modules. Send your comments and suggestions preferably to
the Bioperl mailing list. Your participation is much appreciated.
  bioperl-l@bioperl.org              - General discussion
  http://bioperl.org/MailList.shtml  - About the mailing lists
Reporting BugsTop
Report bugs to the Bioperl bug tracking system to help us keep track
of the bugs and their resolution. Bug reports can be submitted via
the web:
  http://bugzilla.bioperl.org/
AUTHOR - Jason StajichTop
Email jason-at-open-bio-dot-org
Describe contact details here
CONTRIBUTORSTop
Additional contributors names and emails here
APPENDIXTop
The rest of the documentation details each of the object methods.
Internal methods are usually preceded with a _