Tabnine Logo
TreeNode.getParent
Code IndexAdd Tabnine to your IDE (free)

How to use
getParent
method
in
phylo.tree.model.TreeNode

Best Java code snippets using phylo.tree.model.TreeNode.getParent (Showing top 20 results out of 315)

origin: de.unijena.bioinf.phylo/phyloTree-lib.model

/**
 * Lazy and one time computation of the level of this node.
 *
 * @return int level
 */
public int getLevel() {
  if (level == -1) {
    TreeNode parent = this;
    level = 0;
    while ((parent = parent.getParent()) != null)
      level++;
  }
  return level;
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

/**
 * Compute a list of ALL children of a {@link TreeNode}.
 * ALL means all nodes, that are adjacent to this node. That are all direct children
 * and the parent (if there is one).
 * <p>
 * Runtime: O(d)
 */
public ArrayList<TreeNode> getAllChildren() {
  ArrayList<TreeNode> children = new ArrayList<TreeNode>();
  //add all children
  for (TreeNode child : this.children()) {
    children.add(child);
  }
  /**Alternative: children.addAll(node.getChildren()); => but needs maybe O(d^2)*/
  //add the parent
  if (this.getParent() != null) {
    children.add(this.getParent());
  }
  return children;
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

/**
 * @return siblings all siblings of this node
 */
public List<TreeNode> getSiblings() {
  TreeNode p = getParent();
  if (p == null)
    return null;
  List<TreeNode> siblings = new ArrayList<TreeNode>();
  for (TreeNode child : p.children()) {
    if (child != this) siblings.add(child);
  }
  return siblings;
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

/**
 * Indicates, if this node is a child of the given node.
 *
 * @param node: the node, that may be parent of this node
 * @return true, if this node is a child of the given node, false otherwise
 */
public boolean isChildOf(TreeNode node) {
  if (this.getParent().equalsNode(node)) {
    return true;
  } else {
    return false;
  }
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

/**
 * Returns true if the given node is sibling of this node.
 *
 * @param node the other node
 * @return true if the other node is sibling of this node
 */
public boolean isNodeSibling(TreeNode node) {
  TreeNode p = getParent();
  if (p == null)
    return false;
  for (Edge<TreeNode> oe : p.edges()) {
    if (oe.getOpposit(p) == this)
      return true;
  }
  return false;
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

/**
 * Returns the root node of this tree. If the root was not set explicitly, this
 * searches the tree and returns the first node with in-degree equal to 0.
 * <p>
 * The search is only done once and the found root node is cached, so make sure to call
 * that after the tree is complete (all nodes and edges inserted) or call {@link #setRoot(TreeNode)}
 * with null to reset the root node cache.
 *
 * @return root node of the tree
 */
public TreeNode getRoot() {
  if (root == null) {
    // find root, do a search for the node
    // with inDegree 0
    for (TreeNode v : vertices()) {
      if (v.getParent() == null) {
        setRoot(v);
      }
    }
  }
  return (TreeNode) root;
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.utils

public DistanceMatrix(Tree tree) {
  TreeNode[] leafes = tree.getLeaves();
  matrix = new double[leafes.length][leafes.length];
  for (int i = 0; i < leafes.length; i++) {
    leafToIndex.put(leafes[i].getLabel(), i);
    for (int j = 0; j < leafes.length; j++) {
      if (i != j) {
        TreeNode lca = tree.findLeastCommonAncestor(leafes[i], leafes[j]);
        //BigDecimal weight = new BigDecimal(leafes[i].getDistanceToParent());
        double weight = leafes[i].getDistanceToParent();
        TreeNode parent = leafes[i].getParent();
        while (parent != lca) {
          //weight = weight.add(new BigDecimal(parent.getDistanceToParent()));
          weight = weight + parent.getDistanceToParent();
          parent = parent.getParent();
        }
        //weight = weight.add(new BigDecimal(leafes[j].getDistanceToParent()));
        weight = weight + leafes[j].getDistanceToParent();
        parent = leafes[j].getParent();
        while (parent != lca) {
          //weight = weight.add(new BigDecimal(parent.getDistanceToParent()));
          weight = weight + parent.getDistanceToParent();
          parent = parent.getParent();
        }
        matrix[i][j] = weight;//.doubleValue();//weight.multiply(new BigDecimal(ACCURACY)).doubleValue();
        matrix[j][i] = matrix[i][j];
      }
    }
  }
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

/**
 * This method returns the last common ancestor of two nodes of a tree.
 * <p>
 * This eventually returns null if one of the given nodes is null or the given nodes
 * are not in this tree.
 *
 * @param nodeA
 * @param nodeB
 * @return the LCA of nodeA and nodeB or null if no LCA exists
 */
public TreeNode findLeastCommonAncestor(TreeNode nodeA, TreeNode nodeB) {
  if (nodeA == null || nodeB == null) return null;
  if (nodeA.getGraph() != this || nodeB.getGraph() != this) return null;
  /* set nodeA and nodeB to equal level */
  if (nodeA.getLevel() < nodeB.getLevel()) {
    while (nodeA.getLevel() != nodeB.getLevel()) {
      nodeB = (TreeNode) nodeB.getParent();
    }
  } else {
    while (nodeA.getLevel() != nodeB.getLevel()) {
      nodeA = (TreeNode) nodeA.getParent();
    }
  }
  /* set both nodes to their parent, until they are equal */
  while (nodeA != nodeB) {
    nodeA = (TreeNode) nodeA.getParent();
    nodeB = (TreeNode) nodeB.getParent();
  }
  return (nodeA);
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

/**
 * @return previous sibling of this node
 */
public TreeNode getPreviousSibling() {
  TreeNode p = getParent();
  if (p == null)
    return null;
  TreeNode prev = null;
  for (Edge<TreeNode> oe : p.edges()) {
    if (oe.getOpposit(p) == this) {
      return prev;
    }
    prev = oe.getOpposit(p);
  }
  return null;
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

/**
 * @return next sibling of this node
 */
public TreeNode getNextSibling() {
  TreeNode p = getParent();
  if (p == null)
    return null;
  boolean returnNext = false;
  for (Edge<TreeNode> oe : p.edges()) {
    if (returnNext)
      return oe.getOpposit(p);
    if (oe.getOpposit(p) == this) {
      returnNext = true;
    }
  }
  return null;
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.utils

/**
 * remove the taxon with the given label and prune the tree
 *
 * @param merge merge label
 * @param taxa  the taxa
 * @param trees pruned trees
 */
protected void removeAndPrune(String merge, List<String> taxa, List<Tree> trees) {
  for (Tree tree : trees) {
    for (TreeNode node : tree.vertices()) {
      if (node.getLabel() != null && taxa.contains(node.getLabel()) && !node.getLabel().equals(merge)) {
        // remove
        TreeNode parent = node.getParent();
        tree.removeVertex(node);
      }
    }
    TreeUtils.pruneDegreeOneNodes(tree, sumEdgeWeightsWhenPruning, USE_PARENT_WEIGHT);
  }
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.consensus

TreeNode p = node.getParent();
if (!p.equals(tree.getRoot())) {
  Bipartition parentPartition = lcaToLabels.get(p);
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

/**
 * Computes the number of the given child for this node.
 * This number is 0 {@literal <=} childNum {@literal <} 'number of children', if the child is a real child of this node.
 * It is childNum = 'number of children', if the given child is parent of this node.
 *
 * @param child: the child, for that its number has to be computed
 * @return the child number for the  given node
 */
public int getChildNumber(TreeNode child) {
  if (this.getParent().equalsNode(child)) {
    return childCount();
  } else if (child.isChildOf(this)) {
    int num = 0;
    for (TreeNode nodesChild : this.children()) {
      if (!nodesChild.equalsNode(child)) {
        num++;
      } else {
        break;
      }
    }
    return num;
  } else {
    throw new RuntimeException("Given child is no child of this node!");
  }
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

private static void connectParent(Tree tree, TreeNode newRoot, TreeNode parent, double weight) {
  TreeNode next = parent.getParent();
  double nextWeight = 1;
  if (next != null) {
    nextWeight = tree.getEdge(next, parent).getWeight();
    tree.removeEdge(next, parent);
  }
  tree.addEdge(newRoot, parent).setWeight(weight);
  if (next != null) {
    connectParent(tree, parent, next, nextWeight);
  }
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

private static void stepUp(Tree tree, TreeNode child, TreeNode parent, String oldChildLabel) {
  TreeNode newParent = parent.getParent();
  String newOldLabel = parent.getLabel();
  double weight = child.getDistanceToParent();
  tree.removeEdge(parent, child);
  tree.addEdge(child, parent).setWeight(weight);
  parent.setLabel(oldChildLabel);
  if (newParent != null) {
    stepUp(tree, parent, newParent, newOldLabel);
  }
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

public static boolean moveFakeRoot(Tree tree, TreeNode newRoot) {
  if (tree.containsVertex(newRoot) && newRoot.isInnerNode()) {
    TreeNode oldRoot = tree.getRoot();
    TreeNode parent = newRoot.getParent();
    if (parent != null) {
      String label = newRoot.getLabel();
      newRoot.setLabel(null);
      stepUp(tree, newRoot, parent, label);
      tree.setRoot(newRoot);
    }// if not node is already root
  }
  return false;
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.utils

public Edge getDistanceEdge(TreeNode source, TreeNode target) {
  int intersection = 0;
  double s = 0;
  for (TreeNode treeNodeSource : source.getPartition()
      .getLeavesArray()) {
    for (TreeNode treeNodeTarget : target.getPartition()
        .getLeavesArray()) {
      if (treeNodeSource.getLabel().equals(
          treeNodeTarget.getLabel())) {
        // if (treeNodeSource.equals(treeNodeTarget)){
        intersection++;
      }
    }
  }
  // //System.out.println("getDistance Methode likelihoods: intersection --> "+intersection);
  TreeNode getRootHelp = source;
  while (getRootHelp.getParent() != null) {
    getRootHelp = getRootHelp.getParent();
  }
  int allLeaves = getRootHelp.getLeaves().length;
  s = BCNWithLikelihoods.computeValueWithDouble(allLeaves, source
          .getPartition().getSize(), target.getPartition().getSize(),
      intersection);
  return new Edge(source, target, s);
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

private void hangIn(TreeNode n, HashMap<String, MultiNode> labeledNodes,
          HashMap<TreeNode, MultiNode> all, EdgeType type) {
  MultiNode m = null;
  if (n.getLabel() != null) {
    m = labeledNodes.get(n.getLabel());
  }
  if (m == null) {
    m = new MultiNode();
    all.put(n, m);
    if (n.getLabel() != null) {
      m.setLabel(n.getLabel());
      labeledNodes.put(n.getLabel(), m);
    }
    addVertex(m);
  }
  if (n.getEdgeToParent() != null) {
    MultiNode p = all.get(n.getParent());
    addEdge(p, m, type).setWeight(n.getEdgeToParent().getWeight());
  }
  for (TreeNode c : n.children()) {
    hangIn(c, labeledNodes, all, type);
  }
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

/**
 * Reroot tree with the new root placed at the incomming edge of the given outgroup
 *
 * @param tree     the tree
 * @param outgroup the outgroup taxon
 */
public static void rerootToOutgroup(Tree tree, TreeNode outgroup, double edgeLengthToOutgroup) {
  TreeNode parent = outgroup.getParent();
  if (parent == null) return;
  TreeNode newRoot = new TreeNode();
  // add outgroup to new root
  tree.addVertex(newRoot);
  double oldWeight = tree.getEdge(parent, outgroup).getWeight();
  tree.removeEdge(parent, outgroup);
  final Edge<TreeNode> edge = tree.addEdge(newRoot, outgroup);
  edge.setWeight(edgeLengthToOutgroup);
  // connect parent
  connectParent(tree, newRoot, parent, oldWeight - edgeLengthToOutgroup);
  tree.setRoot(newRoot);
  pruneDegreeOneNodes(tree);
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

TreeNode parent = node.getParent();
double weight_parent = node.getDistanceToParent();
double weight_child = child.getDistanceToParent();
phylo.tree.modelTreeNodegetParent

Javadoc

Return the parent of this node.

Popular methods of TreeNode

  • <init>
    Create a new node with given label
  • childCount
    Returns the number of children of this node.
  • depthFirstIterator
    Returns a depth first Iterable. This enables iterating the subtree rooted at this node in post order
  • getLabel
    The label of this node. If the label is not set, this looks for a label property TreeNodeProperties#
  • isInnerNode
    Returns true if this is not a leaf.
  • isLeaf
    Returns true if this node is a leaf.
  • children
    Returns an Iterable over all children of this node. This allow using nodes in foreach loop: for(Tre
  • getChildren
    Get a list of all children of this node. It is helpful if one wants to iterate over all children and
  • getEdgeToParent
    Return the edge to the parent node or null.
  • getLevel
    Lazy and one time computation of the level of this node.
  • getDistanceToParent
    Returns the distance to the parent node. If the node has no parent (root node ) -1 is returned.
  • getLeaves
    Returns the leaves under this node in depths first traversal order.
  • getDistanceToParent,
  • getLeaves,
  • setLabel,
  • cloneNode,
  • equalsNode,
  • getChildAt,
  • getGraph,
  • getIndex,
  • getPartition

Popular in Java

  • Reading from database using SQL prepared statement
  • getResourceAsStream (ClassLoader)
  • getSharedPreferences (Context)
  • putExtra (Intent)
  • Color (java.awt)
    The Color class is used to encapsulate colors in the default sRGB color space or colors in arbitrary
  • FlowLayout (java.awt)
    A flow layout arranges components in a left-to-right flow, much like lines of text in a paragraph. F
  • DateFormat (java.text)
    Formats or parses dates and times.This class provides factories for obtaining instances configured f
  • TimeUnit (java.util.concurrent)
    A TimeUnit represents time durations at a given unit of granularity and provides utility methods to
  • ServletException (javax.servlet)
    Defines a general exception a servlet can throw when it encounters difficulty.
  • BoxLayout (javax.swing)
  • Top plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now