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

How to use
TreeUtils
in
phylo.tree.model

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

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

/**
 * The number of labels of all leafs in the input trees
 *
 * @param trees tree to get leafs from
 * @return number of leafs in this list of trees
 */
public static int getLeafCount(List<Tree> trees) {
  return getLeafLabels(trees).size();
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

/**
 * Iterates over the tree and removes all inner vertices with outdegree == 1.
 * The resulting tree is at least binary.
 *
 * @param tree the tree
 */
public static void pruneDegreeOneNodes(Tree tree) {
  pruneDegreeOneNodes(tree, true, false);
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

/**
 * Returns the list of leaves contained in all trees
 *
 * @param trees the trees
 * @return sharedLeaves the leaves common to all trees
 */
public static List<String> commonLeaves(Collection<Tree> trees) {
  return commonLeaves(trees.toArray(new Tree[trees.size()]));
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.utils

public static Tree rerootTreesByModelTree(Tree inputTree, Tree model) {
  List<Tree> bothTrees = new ArrayList<Tree>(Arrays.asList(TreeUtils.cloneAndPruneTrees(new Tree[]{inputTree, model})));
  Tree tree = bothTrees.get(0);
  Tree prunedModel = bothTrees.get(1);
    rootEdges.add(TreeUtils.getLeafLabels(child));
  Set<String> allLabels = TreeUtils.getLeafLabels(tree.getRoot());
  boolean newRootFound = false;
        Set<String> p1;
        if (node.isInnerNode()) {
          p1 = TreeUtils.getLeafLabels(node);
        } else {
          p1 = new HashSet<String>(1);
          TreeUtils.reorderingBootstrapLabelsForRooting(node.getEdgeToParent());
          TreeUtils.rerootToOutgroup(tree, node);
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));
  Set<String> allLabels = TreeUtils.getLeafLabels(tree.getRoot());
        p1 = TreeUtils.getLeafLabels(node);
      } else {
        p1 = new HashSet<>(1);
  TreeUtils.reorderingBootstrapLabelsForRooting(bestRoot.getEdgeToParent());
  TreeUtils.rerootToOutgroup(tree, bestRoot);
origin: de.unijena.bioinf.phylo/gscm-lib

    if (!sibling.equals(node)) {
      numOfSiblings++;
      siblingLeaves.addAll(TreeUtils.getLeafLabels(sibling));
  TreeUtils.pruneDegreeOneNodes(t, false, false);
} else {
  for (TreeNode child : node.children()) {
origin: de.unijena.bioinf.phylo/phyloTree-lib.utils

public static Tree addCladewiseSplitFit(List<WeightedTreePartitions> biparts, Tree tree) {
  Map<Set<String>, TreeNode> labelsToClade = getChildrenMap(tree);
  Set<String> all = getLeafLabels(tree);
  Map<WeightedTreePartitions, AtomicDouble> partitionsToConflicts = new HashMap<>(labelsToClade.size());
  for (Set<String> leafesInClade : labelsToClade.keySet()) {
    partitionsToConflicts.put(new WeightedTreePartitions(leafesInClade, all), new AtomicDouble(0));
  }
  double numberOfChars = 0;
  for (WeightedTreePartitions sourcePartition : biparts) {
    numberOfChars += sourcePartition.weight;
    for (Map.Entry<WeightedTreePartitions, AtomicDouble> e : partitionsToConflicts.entrySet()) {
      if (e.getKey().isIncompatible(sourcePartition)) {
        e.getValue().addAndGet(e.getKey().weight);
      }
    }
  }
  for (Map.Entry<WeightedTreePartitions, AtomicDouble> entry : partitionsToConflicts.entrySet()) {
    TreeNode first = labelsToClade.remove(entry.getKey().getGroupA());
    TreeNode second = labelsToClade.remove(entry.getKey().getGroupB());
    String l = String.valueOf(1 - (entry.getValue().doubleValue() / numberOfChars));
    if (first != null)
      first.setLabel(l);
    if (second != null)
      second.setLabel(l);
  }
  return tree;
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

public static double claculateMinumCharaterDeletionCosts(Tree tree, List<Tree> sourceTrees) {
  Set<TreeNode> deletedNodes = new HashSet<TreeNode>();
  for (Tree sourceTree : sourceTrees) {
    for (TreeNode treeNode : sourceTree.vertices()) {
      if (treeNode.isInnerNode() && treeNode != sourceTree.getRoot()) {
        Set<String> sourceLeafLabels = getLeafLabels(treeNode);
        Set<TreeNode> superLeafes = getLeafesFromLabels(sourceLeafLabels, tree);
        TreeNode lca = tree.findLeastCommonAncestor(new ArrayList<TreeNode>(superLeafes));
        Set<String> superLeafLabels = getLeafLabels(lca);
        if (!sourceLeafLabels.equals(superLeafLabels)) {
          deletedNodes.add(treeNode);
        }
      }
    }
  }
  double costs = 0;
  for (TreeNode deletedNode : deletedNodes) {
    costs += deletedNode.getDistanceToParent();
  }
  return costs;
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

double weightTOChild = edgeToReroot.getWeight() - weightFromParent;
reorderingBootstrapLabelsForRooting(edgeToReroot);
rerootToOutgroup(tree, edgeToReroot.getTarget(), weightTOChild);
origin: de.unijena.bioinf.phylo/phyloTree-lib.utils

private static int findMostCompatibleFakeRoot(Tree tree, Tree prunedModel) {
  List<Set<String>> rootEdges = new ArrayList<>(prunedModel.getRoot().childCount()); //should be >2 otherwise use the real root method
  for (TreeNode child : prunedModel.getRoot().getChildren()) {
    rootEdges.add(TreeUtils.getLeafLabels(child));
  Set<String> allLabels = TreeUtils.getLeafLabels(tree.getRoot());
        Set<String> clade = TreeUtils.getLeafLabels(child);
        if (splitsCopy.contains(clade))
          splitsCopy.remove(clade);
        clade.removeAll(TreeUtils.getLeafLabels(node));
        if (splitsCopy.contains(clade))
          splitsCopy.remove(clade);
    TreeUtils.moveFakeRoot(tree, bestRoot);
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

Set<String> characterTaxa = getLeafLabels(character);
Tree sourceTree = (Tree) character.getGraph();
TreeNode[] sourceTreeTaxa = sourceTree.getLeaves();
    valueSets.put(parent, buildFitchUnion(parent, valueSets));
  } else {
    valueSets.put(parent, intersection);
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

nt.setName(t.getName());
TreeNode root = (TreeNode) t.getRoot();
pruneTraverse(nt, root, null, labels);
if (nt.vertexCount() > 0 && ((TreeNode) nt.getRoot()).childCount() > 0) {
  newTrees.add(nt);
pruneDegreeOneNodes(tree);
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

/**
 * Deletes the specified node from the tree.The child of this node becomes child
 * of its parent.
 * If the node has more than one child, nothing have to be done.
 *
 * @param node: the node, that has to be deleted
 * @param tree: the tree, from that the tree has to be deleted
 */
public static void pruneInnerNode(TreeNode node, Tree tree) {
  pruneInnerNode(node, tree, true, false);
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

/**
 * Remove the list of nodes from the tree and prune the tree afterwards.
 *
 * @param toRemove leaves to remove
 * @param tree     the tree
 */
private void removeSubtreeFromTree(List<TreeNode> toRemove, Tree tree) {
  removeSubtreeFromTree(toRemove, tree, false);
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

addingEnabled = false;
for (Tree treeTopology : topologies) {
  mergedSets.put(getChildrenMap(treeTopology, true), treeTopology);
Map<Set<String>, TreeNode> treeAsMap = getChildrenMap(tree);
treeSetToNode.put(treeAsMap, tree);
Set<Set<String>> treeAsSet = treeAsMap.keySet();
  Tree mergedTree = mergedSets.get(mergedAsMap);
  if (minOccurence <= (toAddAsMap.size() + 1)) {
    mergeTrees(mergedAsMap, mergedTree, toAddAsMap, treeSetToNode);
    tressToReturn.add(mergedTree);
    mergeTrees(mergedAsMap, mergedTree, toAddAsMap, treeSetToNode);
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

/**
 * Clones all trees and removes all innter vertex labels from the clones. The given source trees
 * are not manipulated
 *
 * @param sourceTrees the source trees
 * @return clones the clones without any innter vertices
 */
public static Tree[] deleteInnerLabels(Tree[] sourceTrees) {
  Tree[] trees = new Tree[sourceTrees.length];
  for (int i = 0; i < sourceTrees.length; i++) {
    trees[i] = deleteInnerLabels(sourceTrees[i]);
  }
  return trees;
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

public static Map<Set<String>, TreeNode> getChildrenMap(final Tree tree) {
  return getChildrenMap(tree, false);
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.model

public static void rerootToOutgroup(Tree tree, TreeNode outgroup) {
  rerootToOutgroup(tree, outgroup, (outgroup.getDistanceToParent() / 2d));
}
origin: de.unijena.bioinf.phylo/phyloTree-lib.utils

Set<String> clade = TreeUtils.getLeafLabels(node);
if (clade.size() > 2 && (numTaxa - clade.size()) > 2) {
  TreeUtils.reorderingBootstrapLabelsForRooting(edgeToReroot);
  TreeUtils.rerootToOutgroup(rootedModel, edgeToReroot.getTarget());
    Tree[] forRooting = TreeUtils.cloneAndPruneTrees(new Tree[]{tree, rootedModel});
phylo.tree.modelTreeUtils

Most used methods

  • getLeafLabels
    The set of labels of all leafs below the input tree node
  • pruneDegreeOneNodes
  • commonLeaves
    Returns the list of leaves contained in all trees
  • deleteInnerLabels
    Clones all trees and removes all innter vertex labels from the clones. The given source trees are no
  • getChildrenMap
  • pruneInnerNode
    Deletes the specified node from the tree.The child of this node becomes child of its parent. If the
  • removeSubtreeFromTree
  • reorderingBootstrapLabelsForRooting
  • rerootToOutgroup
    Reroot tree with the new root placed at the incomming edge of the given outgroup
  • addLeafesFromChildren
  • buildFitchUnion
  • calculateTreeResolution
  • buildFitchUnion,
  • calculateTreeResolution,
  • checkForChilds,
  • cloneAndPruneTrees,
  • connectParent,
  • containsInnerLabels,
  • deleteRootNode,
  • findAndMergeDuplicates,
  • flipLeaves,
  • getLeafesFromLabels

Popular in Java

  • Running tasks concurrently on multiple threads
  • runOnUiThread (Activity)
  • getSystemService (Context)
  • setRequestProperty (URLConnection)
  • Component (java.awt)
    A component is an object having a graphical representation that can be displayed on the screen and t
  • BufferedWriter (java.io)
    Wraps an existing Writer and buffers the output. Expensive interaction with the underlying reader is
  • UnknownHostException (java.net)
    Thrown when a hostname can not be resolved.
  • Permission (java.security)
    Legacy security code; do not use.
  • Comparator (java.util)
    A Comparator is used to compare two objects to determine their ordering with respect to each other.
  • Hashtable (java.util)
    A plug-in replacement for JDK1.5 java.util.Hashtable. This version is based on org.cliffc.high_scale
  • Top plugins for WebStorm
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