phylonet.tree.io
Class NewickReader

java.lang.Object
  extended by phylonet.tree.io.NewickReader

public class NewickReader
extends java.lang.Object

This class reads trees in newick format from a stream provided as a Reader. The tree read is loaded into a Tree object provided.

The exact format supported is as follows:

[TREENAME =] [ROOTING] NEWICKSTRING[;]

All components in square braces are optional. TREENAME can be any legitimate string of characters. ROOTING is "[&U]" for unrooted trees and "[&R]" for rooted trees. The semicolon is optionally used to indicate the end of the tree.

Because of the way that this reader tokenizes, you cannot use a reader to read a tree and then use the same reader to read other parts of a larger input stream. Rather, it is necessary for you to read the tree containing section out of the larger input stream and feed this string/stream to the tree by itself. If you don't do this, the tokenizer inside the NewickReader will potentially tokenize characters past the end of the trees.

Author:
Derek Ruths

Constructor Summary
NewickReader(java.io.Reader r)
           
 
Method Summary
 boolean isNextRooted()
           
 boolean reachedEOF()
          Indicates whether the end of the reader has been reached.
 MutableTree readTree()
          This method reads in a tree and returns the tree read in.
 void readTree(MutableTree tree)
          This method reads a tree from the reader.
 void readTree(STITree<java.lang.Double> tree)
          This method reads a tree from the reader.
 java.lang.String readTreeName()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NewickReader

public NewickReader(java.io.Reader r)
Method Detail

readTree

public MutableTree readTree()
                     throws java.io.IOException,
                            ParseException
This method reads in a tree and returns the tree read in. It also handles the construction of a tree, using the STITree implementation of the MutableTree interface. readTree(Tree) can be used to read the tree structure into a different tree implementation.

Throws:
java.io.IOException
ParseException

readTreeName

public java.lang.String readTreeName()
                              throws java.io.IOException,
                                     ParseException
Throws:
java.io.IOException
ParseException

isNextRooted

public boolean isNextRooted()
                     throws java.io.IOException,
                            ParseException
Returns:
true if the tree that will be parsed by the next call to readTree is rooted.
Throws:
ParseException - if the rootedness of this tree cannot be determined due to a syntax error. Once this exception is thrown, this object may not parse remaining trees correctly.
java.io.IOException

readTree

public void readTree(STITree<java.lang.Double> tree)
              throws java.io.IOException,
                     ParseException
This method reads a tree from the reader. The newick format is extended to include both bootstrap values and branch lengths.

Parameters:
tree -
Throws:
java.io.IOException
ParseException

readTree

public void readTree(MutableTree tree)
              throws java.io.IOException,
                     ParseException
This method reads a tree from the reader. If the tree cannot be read, an exception will be thrown. tree should be a newly created tree, with no other structure in it. The structure of the tree that is read will be pushed directly into the tree data structure underneath the root.

Throws:
java.io.IOException
ParseException

reachedEOF

public boolean reachedEOF()
                   throws java.io.IOException
Indicates whether the end of the reader has been reached.

Throws:
java.io.IOException