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

How to use
TreeNode
in
phylo.tree.model

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

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

/**
 * Clones this node.
 *
 * @return node the new node
 */
public TreeNode cloneNode() {
  TreeNode n = new TreeNode();
  n.setLabel(getLabel());
  n.setIndex(getIndex());
  return n;
}
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.utils

  private List<String> labels(TreeNode n) {
    List<String> l = new ArrayList<String>();
    for (TreeNode node : n.depthFirstIterator()) {
      if (node.isLeaf()) {
        String label = node.getLabel();
        if (label != null) {
          l.add(label);
        }
      }
    }
    return l;
  }
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

/**
 * Traverses the tree rooted at this node and counts all inner-vertices/clades .
 *
 * @return clades under this node
 */
public int cladeCount(){
  int i = 0;
  for (TreeNode node : depthFirstIterator()) {
    if (node.isInnerNode())
      i++;
  }
  return i;
}
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.utils

private static int findMostCompatibleRoot(Tree tree, Tree prunedModel) {
  List<Set<String>> rootEdges = new ArrayList<>(prunedModel.getRoot().childCount()); //should be 2 otherwise method will not work
  for (TreeNode child : prunedModel.getRoot().getChildren()) {
    rootEdges.add(TreeUtils.getLeafLabels(child));
      if (node.isInnerNode()) {
        p1 = TreeUtils.getLeafLabels(node);
      } else {
        p1 = new HashSet<>(1);
        p1.add(node.getLabel());
  TreeUtils.reorderingBootstrapLabelsForRooting(bestRoot.getEdgeToParent());
  TreeUtils.rerootToOutgroup(tree, bestRoot);
origin: de.unijena.bioinf.phylo/phyloTree-lib.utils

if (treeNode.getLabel() != null && treeNode.getLabel().length() > 0) {
  nodes.put(treeNode.getLabel(), treeNode);
    TreeNode newRoot = new TreeNode();
    tree.addVertex(newRoot);
    tree.addEdge(newRoot, tree.getRoot());
    parent = new TreeNode();
    tree.addVertex(parent);
    TreeNode lcaParent = lca.getParent();
    tree.removeEdge(lcaParent, lca);
    tree.addEdge(lcaParent, parent);
  newNode = new TreeNode(singleTaxon.subtree);
  tree.addVertex(newNode);
  tree.addEdge(parent, newNode);
    TreeNode node = subtree.getRoot().getChildAt(0);
    newNode = addSubtree(tree, parent, node);
  } else {
if (newNode.isLeaf()) {
  nodes.put(newNode.getLabel(), newNode);
} else {
  for (TreeNode treeNode : newNode.depthFirstIterator()) {
    if (treeNode.getLabel() != null && treeNode.getLabel().length() > 0) {
      nodes.put(treeNode.getLabel(), treeNode);
origin: de.unijena.bioinf.phylo/gscm-lib

for (TreeNode node : t.getRoot().depthFirstIterator()) {
  if (node.isLeaf()) {
    if (!commonLeafes.contains(node.getLabel())) {
      maxSingleSubtreeRoots.add(node);
    final int childCount = node.childCount();
    List<TreeNode> children = new ArrayList<>(childCount);
    for (TreeNode child : node.children()) {
      children.add(child);
      if (maxSingleSubtreeRoots.contains(child))
    Set<String> siblingLeaves = new THashSet<>();
    int numOfSiblings = 0;
    for (TreeNode sibling : node.getParent().children()) {
      if (!sibling.equals(node)) {
        numOfSiblings++;
    if (node.isInnerNode()) {
      t.removeSubtree(node);
    } else {
    for (TreeNode child : node.children()) {
      stack.push(child);
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

protected static boolean pruneTraverse(Tree t, TreeNode n, TreeNode parent, Set<String> labels) {
  if (n.isLeaf()) {
    if (n.getLabel() != null && labels.contains(n.getLabel())) {
      TreeNode newNode = new TreeNode(n.getLabel());
      edge.setWeight(n.getDistanceToParent());
      return true;
    } else {
    TreeNode newNode = new TreeNode();
    newNode.setLabel(n.getLabel());
      edge.setWeight(n.getDistanceToParent());
    for (TreeNode child : n.children()) {
      if (!pruneTraverse(t, child, newNode, labels)) {
        missed = true;
      if (newNode.childCount() == 0) {
        t.removeVertex(newNode);
      } else if (newNode.childCount() == 1) {
        TreeNode child = newNode.getChildAt(0);
        t.removeVertex(newNode);
        if (parent != null) {
          edge.setWeight(child.getDistanceToParent());
origin: de.unijena.bioinf.phylo/phyloTree-lib.consensus

for (TreeNode node : t2.getRoot().depthFirstIterator()) {
  if (!node.equals(t2.getRoot())) {
    Bipartition nodePartition = lcaToLabels2.get(node);
    if (node.isLeaf()) {
      numOfTaxa++;
      String l = node.getLabel();
      allLeafes.put(l, numOfTaxa);
    } else {
    if (!node.getParent().equals(t2.getRoot())) {
      TreeNode p = node.getParent();
      if (node.isLeaf()) {
        parentPartition.addChild(numOfTaxa);
      } else {
for (TreeNode node : t1.getRoot().depthFirstIterator()) {
  if (!node.equals(t1.getRoot())) {
    Bipartition nodePartition = lcaToLabels1.get(node);
    if (node.isLeaf()) {
      index = allLeafes.get(node.getLabel());
      indexToLeaf1.put(index, node);
    } else {
    if (!node.getParent().equals(t1.getRoot())) {
      TreeNode p = node.getParent();
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

  if (current.childCount() > 2) {
    while (j < current.childCount() - 1) {
      int i = j + 1;
      TreeNode e1 = current.getChildren().get(j);
      TreeNode e2 = current.getChildren().get(i);
      TreeNode newNode = new TreeNode();
    if (!current.isLeaf()) {
      queue.addAll(current.getChildren());
for (TreeNode treeNode : tree.getRoot().depthFirstIterator()) {
  if (treeNode.isInnerNode()) {
    while (treeNode.getChildren().size() > 2) {
      List<TreeNode> list = treeNode.getChildren();
      Collections.shuffle(list);
      TreeNode newNode = new TreeNode();
      tree.addVertex(newNode);
for (TreeNode treeNode : tree.getRoot().depthFirstIterator()) {
  if (treeNode.isInnerNode()) {
    while (treeNode.getChildren().size() > 2) {
        e1 = treeNode.getChildren().get(0);
        e2 = treeNode.getChildren().get(1);
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

if (t == null || order == null || order.size() > t.getRoot().leafCount()) return;
for (TreeNode i : t.getRoot().depthFirstIterator()) {
  List<TreeNode> ns;
  ns = leveltoTreeNode.get(i.getLevel());
  if (ns == null) {
    ns = new ArrayList<TreeNode>();
  leveltoTreeNode.put(i.getLevel(), ns);
    if (parent.isLeaf()) continue;
    ArrayList<TreeNode> kids = parent.getChildren();
    ArrayList<TreeNode> sortme = new ArrayList<TreeNode>();
    ArrayList<TreeNode> neworder = new ArrayList<TreeNode>();
      if (!child.isLeaf()) {
        for (TreeNode newchild : child.getLeaves()) {
          if (order.contains(newchild.getLabel())) {
            child = newchild;
            sortme.add(child);
        if (order.contains(child.getLabel())) {
          sortme.add(child);
        if (label.equals(a.getLabel())) {
          neworder.add(a);
origin: de.unijena.bioinf.phylo/phyloTree-lib.utils

Set<Object> cladeTaxa = leafMap.get(cladeToCheck);
Map<Set<Object>, TreeNode> partition = new HashMap<>(cladeToCheck.childCount());
for (TreeNode child : cladeToCheck.getChildren()) {
  if (child.isInnerNode()) {
    partition.put(new HashSet<Object>(leafMap.get(child)), child);
  } else {
    Set<Object> s = new HashSet<Object>();
    s.add(nameToObject.get(child.getLabel()));
    partition.put(s, child);
TreeNode parent = cladeToCheck.getParent();
if (parent.childCount() > 2) {
  Collection<TreeNode> toRemove = checkNonBinaryClade(parent, supertree, leafMap);
  innerNodes.removeAll(toRemove);
} else {
  Set<Object> parentTaxa = new HashSet<>(leafMap.get(cladeToCheck.getParent()));
  parentTaxa.removeAll(cladeTaxa);
  checkBinaryClade(cladeToCheck, supertree, parentTaxa, partition, leafMap);
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

private static void checkForChilds(TreeNode topologyNode, TreeNode treeToMergeNode) {
  for (TreeNode topologyChild : topologyNode.children()) {
    if (topologyChild.isLeaf()) {
      double treeToMergeEdgeWeight = 0;
      for (TreeNode treeToMergeChild : treeToMergeNode.children()) {
        if (treeToMergeChild.isLeaf() && treeToMergeChild.getLabel().equalsIgnoreCase(topologyChild.getLabel())) {
          //found the correct child
          treeToMergeEdgeWeight = treeToMergeChild.getEdgeToParent().getWeight();
          break;
        }
      }
      Edge topologyChildEdgeToParent = topologyChild.getEdgeToParent();
      topologyChildEdgeToParent.setWeight(topologyChildEdgeToParent.getWeight() + treeToMergeEdgeWeight);
    }
  }
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

public static Tree deleteRootNode(Tree sourceTree, boolean clone) {
  if (clone)
    sourceTree = sourceTree.cloneTree();
  TreeNode r = sourceTree.getRoot();
  if (r.childCount() == 2) {
    List<TreeNode> children = r.getChildren();
    sourceTree.removeVertex(r);
    TreeNode c1 = children.get(0);
    TreeNode c2 = children.get(1);
    if (c1.isInnerNode()) {
      sourceTree.addEdge(c1, c2);
      sourceTree.setRoot(c1);
    } else if (c2.isInnerNode()) {
      sourceTree.addEdge(c2, c1);
      sourceTree.setRoot(c2);
    } else {
      System.out.println("Could not unroot tree. Tree seems not to be a tree!");
      return null;
    }
  }
  return sourceTree;
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

if (node.isInnerNode() && node.childCount() == 1) {
  TreeNode child = node.getChildAt(0);
  TreeNode parent = node.getParent();
  double weight_parent = node.getDistanceToParent();
  double weight_child = child.getDistanceToParent();
  tree.removeVertex(node);
  if (parent != null) {
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

StringBuffer label = new StringBuffer();
StringBuffer nhx = new StringBuffer();
TreeNode n = new TreeNode();
TreeNode x = new TreeNode();
t.addVertex(x);
t.addVertex(n);
        switch (st.ttype) {
          case '(':
            c = new TreeNode();
            t.addVertex(c);
            t.addEdge(n, c);
            setLabel(n, label, nhx);
            if (d != 1.0) {
              n.getEdgeToParent().setWeight(d);
              d = 1.0;
            n = n.getParent();
            break;
          case ',':
            setLabel(n, label, nhx);
            if (d != 1.0) {
              n.getEdgeToParent().setWeight(d);
              d = 1.0;
            c = new TreeNode();
            t.addVertex(c);
            t.addEdge(n.getParent(), c);
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

if (!a.isLeaf() || !b.isLeaf()) return;
if (a.getGraph() != t || b.getGraph() != t) return;
List<TreeNode> nodes = ancestor.getChildren();
  if (!node.isLeaf()) {
    for (TreeNode leaf : node.getLeaves()) {
      if (leaf.equalsNode(a)) posA = x;
      if (leaf.equalsNode(b)) posB = x;
    if (node.equalsNode(a)) posA = x;
    if (node.equalsNode(b)) posB = x;
  ancestor.removeEdge(t.getEdge(ancestor, node));
  x++;
  if (i == posA) ancestor.addEdge(edges.get(posB));
  else if (i == posB) ancestor.addEdge(edges.get(posA));
  else ancestor.addEdge(edges.get(i));
origin: de.unijena.bioinf.phylo/phyloTree-lib.consensus

private Tree addCompatibleCladesToBackboneTree(Tree backboneTree, Collection<Bipartition> partitionsToInsert) {
  for (Bipartition partition : partitionsToInsert) {
    Set<TreeNode> leafes = new HashSet<>();
    for (int i = partition.partition.nextSetBit(0); i >= 0; i = partition.partition.nextSetBit(i + 1)) {
      leafes.add(indexToLeaf1.get(i));
    }
    TreeNode lca = backboneTree.findLeastCommonAncestor(new ArrayList<>(leafes));
    TreeNode nuLca = new TreeNode();
    backboneTree.addVertex(nuLca);
    for (TreeNode child : lca.getChildren()) {
      TreeNode leaf;
      if (child.isInnerNode()) {
        leaf = child.depthFirstIterator().iterator().next();
      } else {
        leaf = child;
      }
      if (leafes.contains(leaf)) {
        backboneTree.removeEdge(lca, child);
        backboneTree.addEdge(nuLca, child);
      }
    }
    backboneTree.addEdge(lca, nuLca);
  }
  return backboneTree;
}
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;
}
phylo.tree.modelTreeNode

Javadoc

Tree node used in the EPoS Tree model. The node supports properties and provides iteration functionality.

Most used methods

  • <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#
  • getParent
    Return the parent of this node.
  • 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.
  • getLevel,
  • getDistanceToParent,
  • getLeaves,
  • setLabel,
  • cloneNode,
  • equalsNode,
  • getChildAt,
  • getGraph,
  • getIndex,
  • getPartition

Popular in Java

  • Creating JSON documents from java classes using gson
  • addToBackStack (FragmentTransaction)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • onRequestPermissionsResult (Fragment)
  • Component (java.awt)
    A component is an object having a graphical representation that can be displayed on the screen and t
  • Socket (java.net)
    Provides a client-side TCP socket.
  • KeyStore (java.security)
    KeyStore is responsible for maintaining cryptographic keys and their owners. The type of the syste
  • Deque (java.util)
    A linear collection that supports element insertion and removal at both ends. The name deque is shor
  • Stack (java.util)
    Stack is a Last-In/First-Out(LIFO) data structure which represents a stack of objects. It enables u
  • ExecutorService (java.util.concurrent)
    An Executor that provides methods to manage termination and methods that can produce a Future for tr
  • Top Vim plugins
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