PhyloSort

phylosort
Class TreeNodeUtil

java.lang.Object
  extended by phylosort.TreeNodeUtil

public final class TreeNodeUtil
extends java.lang.Object

Utility methods for general TreeNode processing.

Version:
$Revision: 1.11 $
Author:
Ahmed Moustafa

Constructor Summary
TreeNodeUtil()
           
 
Method Summary
static boolean belongs(TreeNode node, java.util.Set<java.lang.String> taxa)
          Checks whether the set of all OTUs is a subset of taxa
static boolean contains(TreeNode node, java.util.Set<java.lang.String> taxa)
          Checks whether each group of taxa is represented at least by one OTU
static TreeNode copy(TreeNode root, TreeNode exclude)
          Returns a copy of a TreeNode
static TreeNode findOutgroup(TreeNode node, java.util.List<java.util.Set<java.lang.String>> taxa)
          Finds a leaf node with a taxon not included within a list of taxa
static TreeNode findOutgroup(TreeNode node, java.util.Set<java.lang.String> taxa)
          Finds a leaf node with a taxon not included within a list of taxa
static java.util.Collection<TreeNode> getAllMonophyleticNodes(TreeNode tree, java.util.List<java.util.List<java.lang.String>> taxa)
          Checks whether a tree has a common branch holding groups of taxa
static java.util.Collection<TreeNode> getAllMonophyleticNodes(TreeNode tree, java.util.List<java.util.List<java.lang.String>> taxa, boolean exclusive)
          Checks whether a tree has a common branch holding groups of taxa
static float getAverageNumberOfCopies(TreeNode root)
          Returns the average number of copies per species
static TreeNode getMonophyleticNode(TreeNode tree, java.util.List<java.util.List<java.lang.String>> taxa)
          Checks whether a tree has a common branch holding groups of taxa
static TreeNode getMonophyleticNode(TreeNode tree, java.util.List<java.util.List<java.lang.String>> taxa, boolean exclusive)
          Checks whether a tree has a common branch holding groups of taxa
static java.util.Collection<TreeNode> getNodesByTaxa(TreeNode tree, java.util.Set<java.lang.String> taxa)
          Returns all OTU nodes with labels matching the set of taxa
static java.util.Collection<TreeNode> getNodesByTaxa(TreeNode node, java.util.Set<java.lang.String> taxa, boolean equal)
          Returns all OTU nodes with labels matching the set of taxa
static java.util.Set<java.lang.String> getTaxa(java.io.File file)
          Returns a Set of String of all taxa in a file
static java.util.Set<java.lang.String> getTaxa(TreeNode node)
          Returns a Set of String of taxa in a TreeNode
static int hasMonophyly(TreeNode node, java.util.Set<java.lang.String> extended, java.util.List<java.util.Set<java.lang.String>> sets, java.util.Set<java.lang.Integer> excluded)
          Returns node id if the node is valid, otherwise returns -1
static int lca(java.lang.Iterable<TreeNode> nodes)
          Returns the lowest common ancestor (LCA) for a list of nodes
static TreeNode load(java.io.File file)
          Loads a tree from a text file
static TreeNode reroot(TreeNode outgroup)
          Reroots a tree based on an outgroup node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TreeNodeUtil

public TreeNodeUtil()
Method Detail

belongs

public static boolean belongs(TreeNode node,
                              java.util.Set<java.lang.String> taxa)
Checks whether the set of all OTUs is a subset of taxa

Parameters:
node - Tree to check it OTUs
taxa - Set of taxa to check aganist
Returns:
True if the set of all OTUs is a subset of taxa, otherwise false

contains

public static boolean contains(TreeNode node,
                               java.util.Set<java.lang.String> taxa)
Checks whether each group of taxa is represented at least by one OTU

Parameters:
node - Tree to check it OTUs
taxa - Sets of taxa to check
Returns:
True if each group of taxa is represented in the tree, otherwise false

getMonophyleticNode

public static TreeNode getMonophyleticNode(TreeNode tree,
                                           java.util.List<java.util.List<java.lang.String>> taxa)
Checks whether a tree has a common branch holding groups of taxa

Parameters:
tree - Tree to search in for a common branch
taxa - Groups of taxa (labels) to search for a common branch
Returns:
Node id of the internal node rooting the taxa

getMonophyleticNode

public static TreeNode getMonophyleticNode(TreeNode tree,
                                           java.util.List<java.util.List<java.lang.String>> taxa,
                                           boolean exclusive)
Checks whether a tree has a common branch holding groups of taxa

Parameters:
tree - Tree to search in for a common branch
taxa - Groups of taxa (labels) to search for a common branch
exclusive - Validation type indicator
Returns:
Node id of the internal node rooting the taxa

getAllMonophyleticNodes

public static java.util.Collection<TreeNode> getAllMonophyleticNodes(TreeNode tree,
                                                                     java.util.List<java.util.List<java.lang.String>> taxa)
Checks whether a tree has a common branch holding groups of taxa

Parameters:
tree - Tree to search in for a common branch
taxa - Groups of taxa (labels) to search for a common branch
Returns:
Node id of the internal node rooting the taxa

getAllMonophyleticNodes

public static java.util.Collection<TreeNode> getAllMonophyleticNodes(TreeNode tree,
                                                                     java.util.List<java.util.List<java.lang.String>> taxa,
                                                                     boolean exclusive)
Checks whether a tree has a common branch holding groups of taxa

Parameters:
tree - Tree to search in for a common branch
taxa - Groups of taxa (labels) to search for a common branch
exclusive - Validation type indicator
Returns:
Node id of the internal node rooting the taxa

hasMonophyly

public static int hasMonophyly(TreeNode node,
                               java.util.Set<java.lang.String> extended,
                               java.util.List<java.util.Set<java.lang.String>> sets,
                               java.util.Set<java.lang.Integer> excluded)
Returns node id if the node is valid, otherwise returns -1

Parameters:
node - Node to validate
extended - Extended list of taxa
sets - Taxa in groups
excluded - List of ids of exlcuded nodes (already visited)
Returns:
If valid node, returns node id; otherwise, returns -1

getTaxa

public static java.util.Set<java.lang.String> getTaxa(TreeNode node)
Returns a Set of String of taxa in a TreeNode

Parameters:
node - TreeNode
Returns:
A Set of String of taxa in a TreeNode

getTaxa

public static java.util.Set<java.lang.String> getTaxa(java.io.File file)
                                               throws java.lang.Exception
Returns a Set of String of all taxa in a file

Parameters:
file - Input file
Returns:
A Set of String of all taxa in a file
Throws:
java.lang.Exception

getNodesByTaxa

public static java.util.Collection<TreeNode> getNodesByTaxa(TreeNode tree,
                                                            java.util.Set<java.lang.String> taxa)
Returns all OTU nodes with labels matching the set of taxa

Parameters:
tree - Tree to search in
taxa - Taxa to search for
Returns:
Collection of the OTU TreeNode

getNodesByTaxa

public static java.util.Collection<TreeNode> getNodesByTaxa(TreeNode node,
                                                            java.util.Set<java.lang.String> taxa,
                                                            boolean equal)
Returns all OTU nodes with labels matching the set of taxa

Parameters:
node - Tree to search in
taxa - Taxa to search for
equal - Flag to search of equality or non-equality
Returns:
Collection of the OTU TreeNode

load

public static TreeNode load(java.io.File file)
                     throws java.lang.Exception
Loads a tree from a text file

Parameters:
file - Tree text file
Returns:
TreeNode root of the tree (midpoint?)
Throws:
java.lang.Exception

lca

public static int lca(java.lang.Iterable<TreeNode> nodes)
Returns the lowest common ancestor (LCA) for a list of nodes

Parameters:
nodes - The list of tree nodes
Returns:
The id (int) of the LCA
See Also:
TreeNode

reroot

public static TreeNode reroot(TreeNode outgroup)
Reroots a tree based on an outgroup node.

Parameters:
outgroup - TreeNode outgroup node
Returns:
Rerooted TreeNode

copy

public static TreeNode copy(TreeNode root,
                            TreeNode exclude)
Returns a copy of a TreeNode

Parameters:
root - TreeNode to start coping from
exclude - TreeNode to exclude while coping
Returns:
TreeNode copy of the root node

findOutgroup

public static TreeNode findOutgroup(TreeNode node,
                                    java.util.List<java.util.Set<java.lang.String>> taxa)
Finds a leaf node with a taxon not included within a list of taxa

Parameters:
node - TreeNode root of a tree to search for an outgroup
taxa - List of taxa (ingroup)
Returns:
TreeNode outgroup leaf node or null if no outgroup is found

findOutgroup

public static TreeNode findOutgroup(TreeNode node,
                                    java.util.Set<java.lang.String> taxa)
Finds a leaf node with a taxon not included within a list of taxa

Parameters:
node - TreeNode root of a tree to search for an outgroup
taxa - List of taxa (ingroup)
Returns:
TreeNode outgroup leaf node or null if no outgroup is found

getAverageNumberOfCopies

public static float getAverageNumberOfCopies(TreeNode root)
Returns the average number of copies per species

Parameters:
root - TreeNode root of a tree
Returns:
The average number of copies per species (decimal number)

PhyloSort

SourceForge.Net