Package org.biojavax.bio.phylo.io.nexus
Class TreesBlock
java.lang.Object
org.biojavax.bio.phylo.io.nexus.NexusBlock.Abstract
org.biojavax.bio.phylo.io.nexus.TreesBlock
- All Implemented Interfaces:
NexusBlock
,NexusObject
Represents Nexus trees blocks.
- Since:
- 1.6
- Author:
- Richard Holland, Tobias Thierer, Jim Balhoff, Tiago Antao
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
A simple representation of a Newick tree as a single string.Nested classes/interfaces inherited from interface org.biojavax.bio.phylo.io.nexus.NexusBlock
NexusBlock.Abstract
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
A constant representing the name of Trees blocks. -
Constructor Summary
ConstructorsConstructorDescriptionDelegates to NexusBlock.Abstract constructor using TreesBlock.TREES_BLOCK as the name. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addComment
(NexusComment comment) Adds a comment.void
addTranslation
(String label, String taxa) Add a translation.void
addTree
(String label, TreesBlock.NewickTreeString tree) Adds a tree.void
addTree
(String label, org.jgrapht.WeightedGraph<String, org.jgrapht.graph.DefaultWeightedEdge> treegraph) Deprecated.void
addTree
(String label, org.jgrapht.WeightedGraph<String, org.jgrapht.graph.DefaultWeightedEdge> treegraph, String topLabel) Add a tree, converting weighted graph (JGraphT) to NewickString.boolean
containsTranslation
(String label) Checks to see if we contain the given translation.boolean
containsTree
(String label) Checks to see if we contain the given tree.Returns all comments.Returns the node prefix.Returns the top node of the previously requested graph.Get the translations added so far.Returns a tree for given labelorg.jgrapht.WeightedGraph
<String, org.jgrapht.graph.DefaultWeightedEdge> getTreeAsWeightedJGraphT
(String label) Get given (NewickString) tree by label, converts it to weighted graph (JGraphT).getTrees()
Returns all trees.getTreeText
(org.jgrapht.UndirectedGraph<String, org.jgrapht.graph.DefaultEdge> treegraph, String node, String parent) getTreeText
(org.jgrapht.WeightedGraph<String, org.jgrapht.graph.DefaultWeightedEdge> treegraph, String node, String parent) void
removeComment
(NexusComment comment) Removes a comment.void
removeTranslation
(String label) Removes the given translation.void
removeTree
(String label) Removes a tree.void
setNodePrefix
(String prefix) Sets the node prefix of intermediate nodes for returned graphs.protected void
writeBlockContents
(Writer writer) Implement this to write out block contents, not including the BEGIN and END tags.Methods inherited from class org.biojavax.bio.phylo.io.nexus.NexusBlock.Abstract
getBlockName, writeObject, writeToken
-
Field Details
-
TREES_BLOCK
A constant representing the name of Trees blocks.- See Also:
-
-
Constructor Details
-
TreesBlock
public TreesBlock()Delegates to NexusBlock.Abstract constructor using TreesBlock.TREES_BLOCK as the name.
-
-
Method Details
-
addTranslation
Add a translation.- Parameters:
label
- the label to add.taxa
- the taxa name this label will represent.
-
removeTranslation
Removes the given translation.- Parameters:
label
- the label to remove.
-
containsTranslation
Checks to see if we contain the given translation.- Parameters:
label
- the label to check for.- Returns:
- true if we already contain it.
-
getTranslations
Get the translations added so far.- Returns:
- the translations added so far.
-
addTree
Adds a tree.- Parameters:
label
- the label to give the tree.tree
- the tree to add.
-
removeTree
Removes a tree.- Parameters:
label
- the label to remove.
-
containsTree
Checks to see if we contain the given tree.- Parameters:
label
- the label to check for.- Returns:
- true if we already contain it.
-
getTrees
Returns all trees.- Returns:
- all the selected trees.
-
getTree
Returns a tree for given label- Parameters:
label
- the label to select.- Returns:
- selected tree.
-
getTreeText
public String getTreeText(org.jgrapht.UndirectedGraph<String, org.jgrapht.graph.DefaultEdge> treegraph, String node, String parent) -
addTree
public void addTree(String label, org.jgrapht.WeightedGraph<String, org.jgrapht.graph.DefaultWeightedEdge> treegraph) Deprecated.Add a tree, converting weighted graph (JGraphT) to NewickString This will assume a (arbitrary) root node using the old convention of labeling intermediate nodes as p*.- Parameters:
label
- the label to addtreegraph
- the treegraph to convert.
-
getTreeText
public String getTreeText(org.jgrapht.WeightedGraph<String, org.jgrapht.graph.DefaultWeightedEdge> treegraph, String node, String parent) -
addTree
public void addTree(String label, org.jgrapht.WeightedGraph<String, org.jgrapht.graph.DefaultWeightedEdge> treegraph, String topLabel) Add a tree, converting weighted graph (JGraphT) to NewickString.- Parameters:
label
- the label to addtreegraph
- the treegraph to convert.topLabel
- the label of the top (root if rooted tree) node.
-
getTreeAsWeightedJGraphT
public org.jgrapht.WeightedGraph<String,org.jgrapht.graph.DefaultWeightedEdge> getTreeAsWeightedJGraphT(String label) throws ParseException Get given (NewickString) tree by label, converts it to weighted graph (JGraphT). Alters this.weighted!- Parameters:
label
- label for tree selection- Returns:
- converted tree as undirectedGraph
- Throws:
ParseException
-
addComment
Adds a comment.- Parameters:
comment
- the comment to add.
-
removeComment
Removes a comment.- Parameters:
comment
- the comment to remove.
-
getComments
Returns all comments.- Returns:
- all the selected comments.
-
writeBlockContents
Description copied from class:NexusBlock.Abstract
Implement this to write out block contents, not including the BEGIN and END tags.- Specified by:
writeBlockContents
in classNexusBlock.Abstract
- Parameters:
writer
- the writer to write to.- Throws:
IOException
- if writing failed.
-
getTopNode
Returns the top node of the previously requested graph. The topNode will be the root node if the tree is rooted, if not then it will just be the top most node of the newick string with no biological meaning. The top node from theinvalid reference
#getTreeAsJGraphT(java.lang.String)
getTreeAsWeightedJGraphT(java.lang.String)
might vary, and this function will return the top node of the previously called method only. If no method was called, null is returned. Note: the top node between graphs, probably does not vary, but, just in case, the note is here and the user should get a different top for each type of graph.- Returns:
- the top node.
-
setNodePrefix
Sets the node prefix of intermediate nodes for returned graphs. The intermediate nodes of graphs have to be named, the conventions being: 1. Generate a new node name using a prefix plus an integer 2. If the node name clashes with any taxon name, use another integer- Parameters:
prefix
- The prefix
-
getNodePrefix
Returns the node prefix.- Returns:
- the node prefix
-