org.forester.io.parsers.nhx
Class NHXParser

java.lang.Object
  extended by org.forester.io.parsers.nhx.NHXParser
All Implemented Interfaces:
PhylogenyParser

public final class NHXParser
extends Object
implements PhylogenyParser


Nested Class Summary
static class NHXParser.TAXONOMY_EXTRACTION
           
 
Field Summary
static boolean LIMIT_SPECIES_NAMES_TO_FIVE_CHARS
           
static boolean REPLACE_UNDERSCORES_DEFAULT
           
static NHXParser.TAXONOMY_EXTRACTION TAXONOMY_EXTRACTION_DEFAULT
           
 
Constructor Summary
NHXParser()
           
 
Method Summary
 NHXParser.TAXONOMY_EXTRACTION getTaxonomyExtraction()
           
 boolean hasNext()
           
 Phylogeny[] parse()
          Parses the source set with setSource( final Object nhx_source ).
 Phylogeny parseNext()
           
static void parseNHX(String s, PhylogenyNode node_to_annotate, NHXParser.TAXONOMY_EXTRACTION taxonomy_extraction, boolean replace_underscores)
           
 void setGuessRootedness(boolean guess_rootedness)
           
 void setIgnoreQuotes(boolean ignore_quotes)
           
 void setReplaceUnderscores(boolean replace_underscores)
           
 void setSource(Object nhx_source)
          This sets the source to be parsed.
 void setTaxonomyExtraction(NHXParser.TAXONOMY_EXTRACTION taxonomy_extraction)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LIMIT_SPECIES_NAMES_TO_FIVE_CHARS

public static final boolean LIMIT_SPECIES_NAMES_TO_FIVE_CHARS
See Also:
Constant Field Values

TAXONOMY_EXTRACTION_DEFAULT

public static final NHXParser.TAXONOMY_EXTRACTION TAXONOMY_EXTRACTION_DEFAULT

REPLACE_UNDERSCORES_DEFAULT

public static final boolean REPLACE_UNDERSCORES_DEFAULT
See Also:
Constant Field Values
Constructor Detail

NHXParser

public NHXParser()
Method Detail

getTaxonomyExtraction

public NHXParser.TAXONOMY_EXTRACTION getTaxonomyExtraction()

hasNext

public boolean hasNext()

parse

public Phylogeny[] parse()
                  throws IOException,
                         NHXFormatException
Parses the source set with setSource( final Object nhx_source ). Returns the Phylogenies found in the source as Phylogeny[]. Everything between [ and ] is considered comment and ignored, unless: "[&&NHX... ]" or ":digits and/or.[bootstrap]"

Specified by:
parse in interface PhylogenyParser
Returns:
Phylogeny[]
Throws:
IOException
NHXFormatException
PhylogenyParserException
See Also:
#setSource( final Object nhx_source ), PhylogenyParser.parse()

parseNext

public Phylogeny parseNext()
                    throws IOException,
                           NHXFormatException
Throws:
IOException
NHXFormatException

setGuessRootedness

public void setGuessRootedness(boolean guess_rootedness)

setIgnoreQuotes

public void setIgnoreQuotes(boolean ignore_quotes)

setReplaceUnderscores

public void setReplaceUnderscores(boolean replace_underscores)

setSource

public void setSource(Object nhx_source)
               throws PhylogenyParserException,
                      IOException
This sets the source to be parsed. The source can be: String, StringBuffer, char[], File, or InputStream. The source can contain more than one phylogenies in either New Hamphshire (NH) or New Hamphshire Extended (NHX) format. There is no need to separate phylogenies with any special character. White space is always ignored, as are semicolons inbetween phylogenies. Example of a source describing two phylogenies (source is a String, in this example): "(A,(B,(C,(D,E)de)cde)bcde)abcde ((((A,B)ab,C)abc,D)abcd,E)abcde". Everything between a '[' followed by any character other than '&' and ']' is considered a comment and ignored (example: "[this is a comment]"). NHX tags are surrounded by '[&&NHX' and ']' (example: "[&&NHX:S=Varanus_storri]"). A sequence like "[& some info]" is ignored, too (at the PhylogenyNode level, though). Exception: numbers only between [ and ] (e.g. [90]) are interpreted as support values.

Specified by:
setSource in interface PhylogenyParser
Parameters:
nhx_source - the source to be parsed (String, StringBuffer, char[], File, or InputStream)
Throws:
IOException
PhylogenyParserException
See Also:
parse(), PhylogenyParser.setSource(java.lang.Object)

setTaxonomyExtraction

public void setTaxonomyExtraction(NHXParser.TAXONOMY_EXTRACTION taxonomy_extraction)

parseNHX

public static void parseNHX(String s,
                            PhylogenyNode node_to_annotate,
                            NHXParser.TAXONOMY_EXTRACTION taxonomy_extraction,
                            boolean replace_underscores)
                     throws NHXFormatException
Throws:
NHXFormatException