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

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

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

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

/**
 * Traverses the tree rooted at this node and counts all vertices.
 *
 * @return vertices under this node
 */
public int vertexCount(){
  int i = 0;
  for (TreeNode node : depthFirstIterator()) {
    i++;
  }
  return i;
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

public void removeEdge(Edge<TreeNode> e) {
  if (incompingEdge != null && e == incompingEdge) {
    incompingEdge = null;
    level = -1;
  } else {
    edges.remove(e);
    /*
    Fix #145 - we have to reset the level of all nodes below this one
     */
    for (TreeNode node : this.depthFirstIterator()) {
      node.level = -1;
    }
  }
}
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.utils

/**
 * @param t a tree
 * @return map mapping between the TreeNodes of a tree (including the
 * leaves) and indices
 */
public Map<Integer, TreeNode> getIndizes(Tree t) {
  Map<Integer, TreeNode> map = new HashMap<Integer, TreeNode>();
  int i = 0;
  for (TreeNode treeNode : t.getRoot().depthFirstIterator()) {
    if (Thread.interrupted()) return null;
    map.put(i, treeNode);
    i++;
  }
  return map;
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.utils

private void getLeaves(Tree model) {
  TreeNode root2 = (TreeNode) model.getRoot();
  if (!sym)
    whichRoot += 1;
  leaves = new ArrayList<TreeNode>();
  for (TreeNode dummy : root2.depthFirstIterator()) {
    if (dummy.isLeaf())
      leaves.add(dummy);
  }
}
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.utils

/**
 * method fills a vector with the nodes of the compare tree
 *
 * @param tree
 */
public static Vector<TreeNode> getInternalNodes(Tree tree) {
  TreeNode root = (TreeNode) tree.getRoot();
  Vector<TreeNode> internalNodes = new Vector<TreeNode>();
  for (TreeNode dummy : root.depthFirstIterator()) {
    if (!dummy.isLeaf()) {
      internalNodes.add(dummy);
    }
  }
  return internalNodes;
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

/**
 * Returns the leaves under this node in depths first traversal order.
 *
 * @return leaves under this node
 * @see #depthFirstIterator()
 */
public TreeNode[] getLeaves() {
  if (isLeaf())
    return new TreeNode[]{this};
  List<TreeNode> l = new ArrayList<TreeNode>();
  for (TreeNode c : depthFirstIterator()) {
    if (c.isLeaf()) {
      l.add(c);
    }
  }
  TreeNode[] n = new TreeNode[l.size()];
  l.toArray(n);
  return n;
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.utils

/**
 * method fills a vector with the nodes of the compare tree
 *
 * @param compareTree
 */
private void getInternalNodes(Tree compareTree) {
  this.compareTree = compareTree;
  TreeNode root = (TreeNode) compareTree.getRoot();
  internalNodes = new ArrayList<TreeNode>();
  for (TreeNode dummy : root.depthFirstIterator()) {
    if (!dummy.isLeaf()) {
      internalNodes.add(dummy);
    }
  }
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

/**
 * The set of labels of all leafs below the input tree node
 *
 * @param treeNode the input node
 * @return The Set of leaf labels
 */
public static Set<String> getLeafLabels(TreeNode treeNode) {
  Set<String> leafSet = new HashSet<String>();
  if (treeNode.isLeaf()) {
    leafSet.add(treeNode.getLabel());
  } else {
    for (TreeNode node : treeNode.depthFirstIterator()) {
      if (node.isLeaf())
        leafSet.add(node.getLabel());
    }
  }
  return leafSet;
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.utils

private void buildNormTrees() {
  normalizedTrees = new ArrayList<Tree>(trees.size());
  for (int i = 0; i < factors.length; i++) {
    double factor = factors[i];
    Tree clone = trees.get(i).cloneTree();
    if (factor != 1d) {
      Set<Edge> edges = new HashSet<Edge>(clone.edgeCount());
      for (TreeNode node : clone.getRoot().depthFirstIterator()) {
        edges.addAll(node.getAllEdges());
      }
      for (Edge edge : edges) {
        edge.setWeight(edge.getWeight() * factor);
      }
    }
    normalizedTrees.add(clone);
  }
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.utils

private static List<TreeNode> checkForBootstrapErrors(Tree tree) {
  List<TreeNode> errorNodes = new LinkedList<>();
  for (TreeNode node : tree.getRoot().depthFirstIterator()) {
    if (!node.equals(tree.getRoot()) && node.isInnerNode()) {
      String label = node.getLabel();
      if (node.getLabel() != null) {
        try {
          int bs = Integer.valueOf(node.getLabel());
        } catch (NumberFormatException e) {
          e.printStackTrace();
          errorNodes.add(node);
        }
      } else {
        errorNodes.add(node);
      }
    }
  }
  if (errorNodes.isEmpty())
    return null;
  return errorNodes;
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

private static void removePolytomies(Tree tree, Comparator<TreeNode> comp) {
  tree.getRoot().depthFirstIterator().forEach(node -> {
    int toRemove = node.childCount() - 2;
    if (toRemove > 0) {
      ArrayList<TreeNode> children = node.getChildren();
      sortChildren(children, comp);
      for (int i = 0; i < toRemove; i++) {
        TreeNode remove = children.get(i);
        tree.removeSubtree(remove);
      }
    }
  });
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

/**
 * Add an edge to this node.
 */
@SuppressWarnings("unchecked")
public void addEdge(Edge e) {
  if (e.getSource() == this) {
    if (getEdge(e.getTarget()) == null) {
      edges.add(e);
      /*
      Fix #145 - we have to reset the level of all nodes below this one
       */
      for (TreeNode node : this.depthFirstIterator()) {
        node.level = -1;
      }
    }
  } else {
    incompingEdge = e;
    level = -1;
  }
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

/**
 * Creates and returns the {@link Partition} of this node. Partitions are not
 * cached and recomputed for each call.
 *
 * @return partition of this node
 */
public Partition getPartition() {
  Partition partition = new Partition();
  for (TreeNode n : depthFirstIterator()) {
    if (n.isLeaf()) {
      partition.add(n);
    }
  }
  return partition;
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.utils

public static List<WeightedTreePartitions> getBiparts(Tree sourceTree){
  List<WeightedTreePartitions> biparts = new LinkedList<>();
  final TreeNode r = sourceTree.getRoot();
  Set<String> sourceLeafes = getLeafLabels(r);
  for (TreeNode treeNode : sourceTree.getRoot().depthFirstIterator()) {
    if (treeNode != r && treeNode.isInnerNode()) {
      biparts.add(new WeightedTreePartitions(getLeafLabels(treeNode), sourceLeafes));
    }
  }
  return biparts;
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

/**
 * Returns true if all trees are binary.
 *
 * @param trees the trees
 * @return True, if trees are binary
 */
public static boolean isBinary(Tree[] trees) {
  for (Tree tree : trees) {
    for (TreeNode node : tree.getRoot().depthFirstIterator()) {
      if (node.isInnerNode() && node.childCount() > 2) {
        return false;
      }
    }
  }
  return true;
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

/**
 * Removes al inner vertices on the tree and sets branch length to 1
 * the given tree is modified
 *
 * @param tree the source tree
 */
public static void cleanTree(Tree tree) {
  for (TreeNode node : tree.getRoot().depthFirstIterator()) {
    if (!node.equals(tree.getRoot()))
      node.getEdgeToParent().setWeight(1d);
    if (node.isInnerNode())
      node.setLabel(null);
  }
}
origin: de.unijena.bioinf.phylo/gscm-lib

THashSet<String> getLeafLabels(Tree tree1) {
  THashSet<String> taxonSet = new THashSet<>(tree1.vertexCount());
  for (TreeNode taxon : tree1.getRoot().depthFirstIterator()) {
    if (taxon.isLeaf()) {
      taxonSet.add(taxon.getLabel());
    }
  }
  return taxonSet;
}
origin: de.unijena.bioinf.phylo/flipcut-core

  public static void addCladewiseSplitFit(List<Tree> sourceTrees, FlipCutWeights.Weights weighting, Collection<Tree> trees) {
    final SimpleCosts comp;
    if (weighting == FlipCutWeights.Weights.UNIT_COST) {
      comp =  new UnitCostComputer(sourceTrees,null);
    } else {
      comp = new WeightCostComputer(sourceTrees,weighting);
    }

    List<WeightedTreePartitions> biparts = new LinkedList<>();
    for (Tree sourceTree : sourceTrees) {
      final TreeNode r = sourceTree.getRoot();
      Set<String> sourceLeafes = getLeafLabels(r);
      for (TreeNode treeNode : sourceTree.getRoot().depthFirstIterator()) {
        if (treeNode != r && treeNode.isInnerNode()) {
          biparts.add(new WeightedTreePartitions(getLeafLabels(treeNode), sourceLeafes, comp.getEdgeWeight(treeNode)));
        }
      }
    }

    for (Tree tree : trees) {
      addCladewiseSplitFit(biparts, tree);
    }
  }
}
phylo.tree.modelTreeNodedepthFirstIterator

Javadoc

Returns a depth first Iterable. This enables iterating the subtree rooted at this node in post order within a foreach loop:
 
for(TreeNode next:node.depthFirstIterator()){ 
//...do something with next node 
} 

Popular methods of TreeNode

  • <init>
    Create a new node with given label
  • childCount
    Returns the number of children of this node.
  • 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.
  • getLeaves
    Returns the leaves under this node in depths first traversal order.
  • getDistanceToParent,
  • getLeaves,
  • setLabel,
  • cloneNode,
  • equalsNode,
  • getChildAt,
  • getGraph,
  • getIndex,
  • getPartition

Popular in Java

  • Finding current android device location
  • runOnUiThread (Activity)
  • onRequestPermissionsResult (Fragment)
  • getSupportFragmentManager (FragmentActivity)
  • File (java.io)
    An "abstract" representation of a file system entity identified by a pathname. The pathname may be a
  • Connection (java.sql)
    A connection represents a link from a Java application to a database. All SQL statements and results
  • MessageFormat (java.text)
    Produces concatenated messages in language-neutral way. New code should probably use java.util.Forma
  • NoSuchElementException (java.util)
    Thrown when trying to retrieve an element past the end of an Enumeration or Iterator.
  • SortedSet (java.util)
    SortedSet is a Set which iterates over its elements in a sorted order. The order is determined eithe
  • UUID (java.util)
    UUID is an immutable representation of a 128-bit universally unique identifier (UUID). There are mul
  • Top 12 Jupyter Notebook extensions
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