info.bioinfweb.treegraph.document.io.newick
Class NewickStringReader
java.lang.Object
info.bioinfweb.treegraph.document.io.newick.NewickStringChars
info.bioinfweb.treegraph.document.io.newick.NewickStringReader
public class NewickStringReader
- extends NewickStringChars
This class converts a tree in the Newick format to a Document
. First
the string is decomposed into Tokens by a NewickParser
and then the
developed token list is syntactically analyzed. The following grammar is used:
Tree --> Branch TERMINAL_SYMBOL
Subtree --> Leaf | Internal
Leaf --> Name
Internal --> SUBTREE_START BranchList SUBTREE_END Name
BranchList --> Branch | Branch ELEMENT_SEPERATOR BranchList
Branch --> Subtree Length
Name --> ε | NAME
Length --> ε | LENGTH
Note that this grammar differs from the usual Newick grammar becuase it allows
the root node to have a branch length.
- Author:
- Ben Stöver
Method Summary |
boolean |
getHiddenDataAdded()
Returns whether hidden data has been read from commetns in the newick string (e.g. from BEAST)
during the last call of
read(String, NodeBranchDataAdapter, NodeBranchDataAdapter, TranslTable, boolean)
or one of its convenience methods. |
static NewickStringReader |
getSharedInstance()
|
Tree |
read(String newick)
|
static Tree[] |
read(String[] newick,
NodeBranchDataAdapter internalAdapter,
NodeBranchDataAdapter branchLengthsAdapter,
TranslTable translTable,
boolean translateInternals)
|
Tree |
read(String newick,
NodeBranchDataAdapter internalAdapter,
NodeBranchDataAdapter branchLengthsAdapter)
|
Tree |
read(String newick,
NodeBranchDataAdapter internalAdapter,
NodeBranchDataAdapter branchLengthsAdapter,
TranslTable translTable,
boolean translateInternals)
|
private Node |
readBranch(int start,
int end,
Node root)
|
private void |
readBranchList(int start,
int end,
Node root)
|
private Node |
readInternal(int start,
int end)
|
private Node |
readLeaf(int start,
int end)
|
private void |
readName(int previousEnd,
int end,
Node root,
NodeBranchDataAdapter adapter,
TranslTable translTable)
|
private Node |
readSubtree(int start,
int end)
|
private Tree |
readTree()
|
private int |
searchSubtreeEnd(int start,
int end)
|
private int |
searchToken(int start,
int end,
TokenType type)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
LEAF_ADAPTER
public static final NodeNameAdapter LEAF_ADAPTER
BRANCH_LENGTH_ADAPTER
public static final BranchLengthAdapter BRANCH_LENGTH_ADAPTER
sharedInstance
private static NewickStringReader sharedInstance
newickDescription
private String newickDescription
tokens
private List<NewickToken> tokens
internalAdapter
private NodeBranchDataAdapter internalAdapter
branchLengthsAdapter
private NodeBranchDataAdapter branchLengthsAdapter
translTable
private TranslTable translTable
translateInternals
private boolean translateInternals
hiddenDataAdded
private boolean hiddenDataAdded
commentDataReader
private CommentDataReader commentDataReader
NewickStringReader
public NewickStringReader()
getSharedInstance
public static NewickStringReader getSharedInstance()
searchSubtreeEnd
private int searchSubtreeEnd(int start,
int end)
searchToken
private int searchToken(int start,
int end,
TokenType type)
readBranch
private Node readBranch(int start,
int end,
Node root)
throws NewickException
- Throws:
NewickException
readBranchList
private void readBranchList(int start,
int end,
Node root)
throws NewickException
- Throws:
NewickException
readName
private void readName(int previousEnd,
int end,
Node root,
NodeBranchDataAdapter adapter,
TranslTable translTable)
throws NewickException
- Throws:
NewickException
readInternal
private Node readInternal(int start,
int end)
throws NewickException
- Throws:
NewickException
readLeaf
private Node readLeaf(int start,
int end)
throws NewickException
- Throws:
NewickException
readSubtree
private Node readSubtree(int start,
int end)
throws NewickException
- Throws:
NewickException
readTree
private Tree readTree()
throws NewickException
- Throws:
NewickException
getHiddenDataAdded
public boolean getHiddenDataAdded()
- Returns whether hidden data has been read from commetns in the newick string (e.g. from BEAST)
during the last call of
read(String, NodeBranchDataAdapter, NodeBranchDataAdapter, TranslTable, boolean)
or one of its convenience methods.
- Returns:
read
public Tree read(String newick)
throws NewickException
- Throws:
NewickException
read
public Tree read(String newick,
NodeBranchDataAdapter internalAdapter,
NodeBranchDataAdapter branchLengthsAdapter)
throws NewickException
- Throws:
NewickException
read
public Tree read(String newick,
NodeBranchDataAdapter internalAdapter,
NodeBranchDataAdapter branchLengthsAdapter,
TranslTable translTable,
boolean translateInternals)
throws NewickException
- Throws:
NewickException
read
public static Tree[] read(String[] newick,
NodeBranchDataAdapter internalAdapter,
NodeBranchDataAdapter branchLengthsAdapter,
TranslTable translTable,
boolean translateInternals)
throws NewickException
- Throws:
NewickException