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

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

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

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

/**
 * Returns true if this is not a leaf.
 *
 * @return true is not leaf
 */
public boolean isInnerNode() {
  return !isLeaf();
}
origin: de.unijena.bioinf.phylo/gscm-lib

private boolean isLeaf() {
  return insertionPoint.isLeaf();
}
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.model

/**
 * Returns the number leaves of the tree.
 * (Leaves are all vertices with outdegree == 0).
 * <br> THIS DOES NOT CACHE and always recounts.
 *
 * @return number of leaves
 */
public int getNumTaxa() {
  int nTaxa = 0;
  for (TreeNode v : vertices()) {
    if (v.isLeaf())
      nTaxa++;
  }
  return nTaxa;
}
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.model

/**
 * Adds a TreeNode to the Partiton.
 *
 * @param node
 */
public void add(TreeNode node) {
  if (!node.isLeaf())
    return; // TODO: Throw some exception here
  String key = node.getLabel();//  getUserObject()).getID();
  if (key == null) {
    //throw new NullPointerException();
    key = "";
  }
  this.leavesMap.put(key, node);
  if (minKey == null) this.minKey = ((Comparable) key);
  else if (minKey.compareTo(key) > 0) {
    minKey = (Comparable) key;
  }
  if (maxKey == null) this.maxKey = ((Comparable) key);
  else if (maxKey.compareTo(key) < 0) {
    maxKey = (Comparable) key;
  }
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.utils

protected TreeNode find(String label, Tree tree) {
  if (label == null) return null;
  for (TreeNode v : tree.vertices()) {
    if (v.isLeaf() && label.equals(v.getLabel())) return v;
  }
  return null;
}
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

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

/**
 * Collect all leaf siblings of a given leaf. If the given node is a
 * inner node this returns null. Only direct leaf siblings are added to the
 * list of siblings
 *
 * @param node the node
 * @return siblings direct leaf siblings of a given leaf
 */
protected List<String> siblings(TreeNode node) {
  if (!node.isLeaf()) return null;
  ArrayList<String> siblings = new ArrayList<String>();
  if (node.getLabel() == null) throw new NullPointerException();
  siblings.add(node.getLabel());
  List<TreeNode> sibs = node.getSiblings();
  if (sibs != null) {
    for (TreeNode n : sibs) {
      if (n.isLeaf()) {
        siblings.add(n.getLabel());
      }
    }
  }
  return siblings;
}
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.model

public void addTree(Tree tree) {
  String name = tree.getName();
  this.treeList.add(tree);
  for (TreeNode treeNode : tree.vertices()) {
    if (!addInternaleTaxa && treeNode.isLeaf())
      taxa.addTaxon(treeNode.getLabel());
  }
  String nn = taxa.translate(name);
  if (nn == null) {
    nn = "tree_" + treeList.size();
  }
  this.trees.put(nn, tree);
}
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

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

/**
 * 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.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/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;
}
phylo.tree.modelTreeNodeisLeaf

Javadoc

Returns true if this node is a leaf.

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

  • Running tasks concurrently on multiple threads
  • getExternalFilesDir (Context)
  • compareTo (BigDecimal)
  • setScale (BigDecimal)
  • ServerSocket (java.net)
    This class represents a server-side socket that waits for incoming client connections. A ServerSocke
  • URL (java.net)
    A Uniform Resource Locator that identifies the location of an Internet resource as specified by RFC
  • SimpleDateFormat (java.text)
    Formats and parses dates in a locale-sensitive manner. Formatting turns a Date into a String, and pa
  • Servlet (javax.servlet)
    Defines methods that all servlets must implement. A servlet is a small Java program that runs within
  • IsNull (org.hamcrest.core)
    Is the value null?
  • Table (org.hibernate.mapping)
    A relational table
  • Top Sublime Text 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