congrats Icon
New! Tabnine Pro 14-day free trial
Start a free trial
Tabnine Logo
TreeNode.children
Code IndexAdd Tabnine to your IDE (free)

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

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

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

/**
 * Get a list of all children of this node.
 * It is helpful if one wants to iterate over all children and delete some children meanwhile.
 *
 * @return a list of all children of this node (may be empty if the node is a leaf)
 */
public ArrayList<TreeNode> getChildren() {
  ArrayList<TreeNode> children = new ArrayList<TreeNode>();
  for (TreeNode child : this.children()) {
    children.add(child);
  }
  return children;
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

public PostorderIterator(TreeNode node) {
  root = node;
  children = node.children().iterator();
  subtree = new EmptyIterable<TreeNode>();
}
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

private static Map<Set<String>, TreeNode> getTreeAsLeafMap(final Tree tree, final boolean setEdgeweightsToZero) {
  Map<Set<String>, TreeNode> childrenSets = new HashMap<Set<String>, TreeNode>(tree.vertexCount());
  for (TreeNode child : tree.getRoot().children()) {
    Set<String> childTaxaSet = new HashSet<String>();
    addLeafesFromChildren(childrenSets, child, childTaxaSet, setEdgeweightsToZero);
  }
  return childrenSets;
}
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

/**
 * Traverses the tree rooted at this node and counts leaves.
 *
 * @return leaves under this node
 */
public int leafCount() {
  if (isLeaf()) {
    return 1;
  }
  int i = 0;
  for (TreeNode n : children()) {
    i += n.leafCount();
  }
  return i;
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

public static void addLeafesFromChildren(final Map<Set<String>, TreeNode> childrenSets, final TreeNode current, final Set<String> parentTaxaSet, final boolean setEdgeweightsToZero) {
  if (setEdgeweightsToZero) current.getEdgeToParent().setWeight(0d);
  if (current.isLeaf()) {
    parentTaxaSet.add(current.getLabel());
  } else {
    Set<String> currentTaxaSet = new HashSet<String>();
    for (TreeNode child : current.children()) {
      addLeafesFromChildren(childrenSets, child, currentTaxaSet, setEdgeweightsToZero);
    }
    parentTaxaSet.addAll(currentTaxaSet);
    childrenSets.put(currentTaxaSet, current);
  }
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.utils

protected Range sortNode(TreeNode node) {
  if (node.isLeaf()) {
    return new Range(node, node);
  }
  SortedMap<Range, TreeNode> ranges = new TreeMap<Range, TreeNode>(new RangeComparator());
  for (TreeNode child : node.children()) {
    Range r = sortNode(child);
    ranges.put(r, child);
  }
  Range result = new Range(ranges.firstKey().min, ranges.lastKey().max);
  ArrayList<TreeNode> order = new ArrayList<TreeNode>();
  for (Range r : ranges.keySet()) {
    order.add(ranges.get(r));
  }
  node.setChildOrder(order);
  return result;
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

s.append("(");
boolean added = false;
for (TreeNode n : node.children()) {
  appendNode(n, s, writeWeights);
  s.append(',');
origin: de.unijena.bioinf.phylo/phyloTree-lib.utils

for (TreeNode child : treeNode.children()) {
  List<String> labels = labels(child);
  if (labels.contains(leftFix)) {
origin: de.unijena.bioinf.phylo/phyloTree-lib.utils

/**
 * Little helper that recursivly collects labeled nodes under the given node
 *
 * @param n
 * @param leaveList
 * @return
 */
private List<String> getLeaves(TreeNode n, List<String> leaveList) {
  if (n.isLeaf()) {
    leaveList.add(n.getLabel());
    return leaveList;
  }
  for (TreeNode c : n.children()) {
    getLeaves(c, leaveList);
  }
  if (n.getLabel() != null) {
    leaveList.add(n.getLabel());
  }
  return leaveList;
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.utils

for (TreeNode child : treeNode.children()) {
  List<String> labels = labels(child);
  if (labels.contains(leftFix)) {
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

/**
 * 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.consensus

/**
 * The second run, a preorder traversal of the tress to build the
 * consensus tree.
 *
 * @param node   the actual node
 * @param parent the parents bipartition
 */
protected void preOrder(TreeNode node, Bipartition parent) {
  Bipartition part = (Bipartition) nodes2partitions.get(node);
  if (((CountTupel) partitions.get(part)).count >= majorityThreshold) {
    if (part.getParentPartition() == null) {
      part.setParentPartition(parent == null ? null : parent);
    } else {
      if (part.getParentPartition().getCardinality() > parent.getCardinality())
        part.setParentPartition(parent);
    }
    parent = part;
  }
  // traverse the children
  for (TreeNode n : node.children()) {
    preOrder(n, parent);
  }
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.utils

for (TreeNode child : n.children()) {
  BCNScore score = sourceScrores.get(child);
  double child_score = score.getScore();
origin: de.unijena.bioinf.phylo/phyloTree-lib.utils

/**
 * Add subtree to existing tree, recursive iteration over the subtree to add
 *
 * @param tree    the target tree
 * @param parent  the parent node
 * @param newNode the current node to be added to the parent
 * @return node added node
 */
private TreeNode addSubtree(Tree tree, TreeNode parent, TreeNode newNode) {
  TreeNode nn = newNode.cloneNode();
  nn.setIndex(-1);
  tree.addVertex(nn);
  tree.addEdge(parent, nn);
  for (TreeNode child : newNode.children()) {
    addSubtree(tree, nn, child);
  }
  return nn;
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

@SuppressWarnings("unchecked")
private void hangIn(TreeNode newParent, TreeNode oldParent, Tree tree) {
  for (TreeNode n : oldParent.children()) {
    TreeNode newNode = n.cloneNode();
    newNode.setIndex(-1);
    tree.addVertex(newNode);
    Edge edge = tree.addEdge(newParent, newNode);
    edge.setWeight(n.getDistanceToParent());
    hangIn(newNode, n, tree);
  }
}
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

for (TreeNode child : n.children()) {
  if (!pruneTraverse(t, child, newNode, labels)) {
    missed = true;
phylo.tree.modelTreeNodechildren

Javadoc

Returns an Iterable over all children of this node.

This allow using nodes in foreach loop:

 
for(TreeNode child: node.children()){ 
//...do something with the child 
} 

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#
  • 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.
  • 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

  • Reactive rest calls using spring rest template
  • scheduleAtFixedRate (ScheduledExecutorService)
  • requestLocationUpdates (LocationManager)
  • addToBackStack (FragmentTransaction)
  • ObjectMapper (com.fasterxml.jackson.databind)
    ObjectMapper provides functionality for reading and writing JSON, either to and from basic POJOs (Pl
  • ServerSocket (java.net)
    This class represents a server-side socket that waits for incoming client connections. A ServerSocke
  • DecimalFormat (java.text)
    A concrete subclass of NumberFormat that formats decimal numbers. It has a variety of features desig
  • Scanner (java.util)
    A parser that parses a text string of primitive types and strings with the help of regular expressio
  • DataSource (javax.sql)
    An interface for the creation of Connection objects which represent a connection to a database. This
  • Response (javax.ws.rs.core)
    Defines the contract between a returned instance and the runtime when an application needs to provid
  • 14 Best Plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

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