Class Phylogeny

java.lang.Object
org.forester.phylogeny.Phylogeny

public class Phylogeny extends Object
  • Field Details

    • ALLOW_MULTIPLE_PARENTS_DEFAULT

      public static final boolean ALLOW_MULTIPLE_PARENTS_DEFAULT
      See Also:
  • Constructor Details

    • Phylogeny

      public Phylogeny()
      Default Phylogeny constructor. Constructs an empty Phylogeny.
  • Method Details

    • addAsChild

      public void addAsChild(PhylogenyNode parent)
      Adds this Phylogeny to the list of child nodes of PhylogenyNode parent and sets the parent of this to parent.
      Parameters:
      n - the PhylogenyNode to add
    • addAsSibling

      public void addAsSibling(PhylogenyNode sibling)
    • calculateSubtreeHeight

      public double calculateSubtreeHeight(PhylogenyNode n)
      This calculates the height of the subtree emanating at n for rooted, tree-shaped phylogenies
      Parameters:
      n - the root-node of a subtree
      Returns:
      the height of the subtree emanating at n
    • clearHashIdToNodeMap

      public void clearHashIdToNodeMap()
    • copy

      public Phylogeny copy()
      Returns a deep copy of this Phylogeny.

      (The resulting Phylogeny has its references in the external nodes corrected, if they are lacking/obsolete in this.)

    • copy

      public Phylogeny copy(PhylogenyNode source)
      Returns a deep copy of this Phylogeny.

      (The resulting Phylogeny has its references in the external nodes corrected, if they are lacking/obsolete in this.)

    • copyShallow

      public Phylogeny copyShallow()
      Returns a shallow copy of this Phylogeny.

      (The resulting Phylogeny has its references in the external nodes corrected, if they are lacking/obsolete in this.)

    • copyShallow

      public Phylogeny copyShallow(PhylogenyNode source)
    • deleteSubtree

      public void deleteSubtree(PhylogenyNode remove_us, boolean collapse_resulting_node_with_one_desc)
      Need to call clearHashIdToNodeMap() afterwards (not done automatically to allow client multiple deletions in linear time). Need to call 'recalculateNumberOfExternalDescendants(boolean)' after this if tree is to be displayed.
      Parameters:
      remove_us - the parent node of the subtree to be deleted
    • externalNodesHaveChanged

      public void externalNodesHaveChanged()
    • getAllExternalNodeNames

      public String[] getAllExternalNodeNames()
    • getConfidence

      public Confidence getConfidence()
    • getDescription

      public String getDescription()
    • getDistanceUnit

      public String getDistanceUnit()
    • createInstanceFromNhxString

      public static final Phylogeny createInstanceFromNhxString(String nhx) throws IOException
      Throws:
      IOException
    • getExternalNodes

      public List<PhylogenyNode> getExternalNodes()
      Warning. The order of the returned nodes is random -- and hence cannot be relied on.
      Returns:
      Unordered set of PhylogenyNode
    • getFirstExternalNode

      public PhylogenyNode getFirstExternalNode()
      Returns the first external PhylogenyNode.
    • getHeight

      public double getHeight()
      This calculates the height for rooted, tree-shaped phylogenies. The height is the longest distance from the root to an external node. Please note. Child nodes of collapsed nodes are ignored -- which is useful for display purposes but might be misleading for other applications.
      Returns:
      the height for rooted, tree-shaped phylogenies
    • getIdentifier

      public Identifier getIdentifier()
    • getName

      public String getName()
      Returns the name of this Phylogeny.
    • getNode

      public PhylogenyNode getNode(long id) throws NoSuchElementException
      Finds the PhylogenyNode of this Phylogeny which has a matching ID number.
      Returns:
      PhylogenyNode with matching ID, null if not found
      Throws:
      NoSuchElementException
    • getNode

      public PhylogenyNode getNode(String name)
      Returns a PhylogenyNode of this Phylogeny which has a matching name. Throws an Exception if seqname is not present in this or not unique.
      Parameters:
      name - name (String) of PhylogenyNode to find
      Returns:
      PhylogenyNode with matchin name
    • getNodeCount

      public int getNodeCount()
      This is time-inefficient since it runs a iterator each time it is called.
    • getNodes

      public List<PhylogenyNode> getNodes(String name)
      Returns a List with references to all Nodes of this Phylogeny which have a matching name.
      Parameters:
      name - name (String) of Nodes to find
      Returns:
      Vector of references to Nodes of this Phylogeny with matching names
      See Also:
    • getNodesViaSequenceName

      public List<PhylogenyNode> getNodesViaSequenceName(String seq_name)
    • getNodesViaSequenceSymbol

      public List<PhylogenyNode> getNodesViaSequenceSymbol(String seq_name)
    • getNodesViaGeneName

      public List<PhylogenyNode> getNodesViaGeneName(String seq_name)
    • getNodesViaTaxonomyCode

      public List<PhylogenyNode> getNodesViaTaxonomyCode(String taxonomy_code)
    • getNodesWithMatchingSpecies

      public List<PhylogenyNode> getNodesWithMatchingSpecies(String specname)
      Returns a Vector with references to all Nodes of this Phylogeny which have a matching species name.
      Parameters:
      specname - species name (String) of Nodes to find
      Returns:
      Vector of references to Nodes of this Phylogeny with matching species names.
      See Also:
    • getNodeViaSequenceName

      public PhylogenyNode getNodeViaSequenceName(String seq_name)
    • getNodeViaTaxonomyCode

      public PhylogenyNode getNodeViaTaxonomyCode(String taxonomy_code)
    • getNumberOfBranches

      public int getNumberOfBranches()
    • getNumberOfInternalNodes

      public int getNumberOfInternalNodes()
    • getNumberOfExternalNodes

      public int getNumberOfExternalNodes()
      Returns the sum of external Nodes of this Phylogeny (int).
    • getParalogousNodes

      public List<PhylogenyNode> getParalogousNodes(PhylogenyNode n, String[] taxonomyCodeRange)
      Returns all paralogs of the external PhylogenyNode n of this Phylogeny. paralog are returned as List of node references.

      PRECONDITION: This tree must be binary and rooted, and speciation - duplication need to be assigned for each of its internal Nodes.

      Returns null if this Phylogeny is empty or if n is internal.

      (Last modified: 11/22/00) Olivier CHABROL : olivier.chabrol@univ-provence.fr

      Parameters:
      n - external PhylogenyNode whose orthologs are to be returned
      Returns:
      Vector of references to all orthologous Nodes of PhylogenyNode n of this Phylogeny, null if this Phylogeny is empty or if n is internal
    • getRelevantSequenceRelationTypes

      public Collection<SequenceRelation.SEQUENCE_RELATION_TYPE> getRelevantSequenceRelationTypes()
    • getRoot

      public PhylogenyNode getRoot()
      Returns the root PhylogenyNode of this Phylogeny.
    • getSequenceRelationQueries

      public Collection<Sequence> getSequenceRelationQueries()
    • getType

      public String getType()
    • init

      public void init()
      Deletes this Phylogeny.
    • isCompletelyBinary

      public boolean isCompletelyBinary()
      Returns whether this is a completely binary tree (i.e. all internal nodes are bifurcations).
    • isEmpty

      public boolean isEmpty()
      Checks whether a Phylogeny object is deleted (or empty).
      Returns:
      true if the tree is deleted (or empty), false otherwise
    • isRerootable

      public boolean isRerootable()
    • isRooted

      public boolean isRooted()
      Returns true is this Phylogeny is rooted.
    • isTree

      public boolean isTree()
    • iteratorExternalForward

      public PhylogenyNodeIterator iteratorExternalForward()
    • iteratorLevelOrder

      public PhylogenyNodeIterator iteratorLevelOrder()
    • iteratorPostorder

      public PhylogenyNodeIterator iteratorPostorder()
    • iteratorPreorder

      public PhylogenyNodeIterator iteratorPreorder()
    • levelOrderReID

      public void levelOrderReID()
      Resets the ID numbers of the nodes of this Phylogeny in level order, starting with start_label (for the root).
      WARNING. After this method has been called, node IDs are no longer unique.
    • printExtNodes

      public void printExtNodes()
      Prints descriptions of all external Nodes of this Phylogeny to System.out.
    • recalculateNumberOfExternalDescendants

      public void recalculateNumberOfExternalDescendants(boolean consider_collapsed_nodes)
      (Re)counts the number of children for each PhylogenyNode of this Phylogeny. As an example, this method needs to be called after a Phylogeny has been reRooted and it is to be displayed.
      Parameters:
      consider_collapsed_nodes - set to true to take into account collapsed nodes (collapsed nodes have 1 child).
    • reRoot

      public void reRoot(long id)
      Places the root of this Phylogeny on the parent branch of the PhylogenyNode with a corresponding ID. The new root is always placed on the middle of the branch. If the resulting reRooted Phylogeny is to be used any further, in most cases the following methods have to be called on the resulting Phylogeny:

    • recalculateNumberOfExternalDescendants(boolean)
    • recalculateAndReset()
    • Parameters:
      id - ID (int) of PhylogenyNode of this Phylogeny
    • reRoot

      public void reRoot(PhylogenyNode n)
      Places the root of this Phylogeny on the parent branch PhylogenyNode n. The new root is always placed on the middle of the branch.

      If the resulting reRooted Phylogeny is to be used any further, in most cases the following three methods have to be called on the resulting Phylogeny:

      • recalculateNumberOfExternalDescendants(boolean)
      • recalculateAndReset()

      (Last modified: 10/01/01)

      Parameters:
      n - PhylogenyNode of this Phylogeny\
    • reRoot

      public void reRoot(PhylogenyNode n, double distance_n_to_parent)
    • setAllNodesToNotCollapse

      public void setAllNodesToNotCollapse()
      Sets all Nodes of this Phylogeny to not-collapsed.

      In most cases methods adjustNodeCount(false) and recalculateAndReset() need to be called after this method has been called.

    • setConfidence

      public void setConfidence(Confidence confidence)
    • setDescription

      public void setDescription(String description)
    • setDistanceUnit

      public void setDistanceUnit(String _distance_unit)
    • setIdentifier

      public void setIdentifier(Identifier identifier)
    • setIdToNodeMap

      public void setIdToNodeMap(HashMap<Long,PhylogenyNode> idhash)
    • setIndicatorsToZero

      public void setIndicatorsToZero()
      Sets the indicators of all Nodes of this Phylogeny to 0.
    • setName

      public void setName(String s)
      Sets the name of this Phylogeny to s.
    • setRelevantSequenceRelationTypes

      public void setRelevantSequenceRelationTypes(Collection<SequenceRelation.SEQUENCE_RELATION_TYPE> types)
    • setRerootable

      public void setRerootable(boolean rerootable)
    • setRoot

      public void setRoot(PhylogenyNode n)
    • setRooted

      public void setRooted(boolean b)
      Sets whether this Phylogeny is rooted or not.
    • setSequenceRelationQueries

      public void setSequenceRelationQueries(Collection<Sequence> sequencesByName)
    • setType

      public void setType(String type)
    • toNewHampshire

      public String toNewHampshire()
    • toNewHampshire

      public String toNewHampshire(PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE nh_conversion_support_style)
    • toNewHampshireX

      public String toNewHampshireX()
    • toNexus

      public String toNexus()
    • toNexus

    • toPhyloXML

      public String toPhyloXML(int phyloxml_level)
    • toString

      public String toString()
      Converts this Phylogeny to a New Hampshire X (String) representation.
      Overrides:
      toString in class Object
      Returns:
      New Hampshire X (String) representation of this
      See Also:
    • unRoot

      public void unRoot() throws RuntimeException
      Removes the root PhylogenyNode this Phylogeny.
      Throws:
      RuntimeException