private static int[] calculateNumberOfMissingClades(Tree calculated, Tree model, boolean prune) { Tree[] trees = {calculated, model}; if (prune) { trees = TreeUtils.cloneAndPruneTrees(trees); } if (trees == null) return null; return calculateNumberOfMissingClades(trees[0], trees[1]); }
Tree[] pruned = TreeUtils.cloneAndPruneTrees(new Tree[]{t1, t2});
public static double[] calculateRates(Tree calculated, Tree model, boolean prune) { Tree[] trees = {calculated, model}; if (prune) { trees = TreeUtils.cloneAndPruneTrees(trees); } if (trees == null) return null; int[] numbers = calculateNumberOfMissingClades(trees[0], trees[1]); double[] rates = new double[4]; rates[0] = (double) numbers[0] / (numbers[2]); //rates[0] = (double) numbers[0] / (trees[0].getNumTaxa() - 3); rates[1] = (double) numbers[1] / (numbers[3]); //rates[1] = (double) numbers[1] / (trees[1].getNumTaxa() - 3); rates[2] = (double) numbers[0]; rates[3] = (double) numbers[1]; return rates; }
public static Tree findMostCompatibleRootToScaffoldTree(Tree inputTree, Tree model) { List<Tree> bothTrees = new ArrayList<>(Arrays.asList(TreeUtils.cloneAndPruneTrees(new Tree[]{inputTree, model}))); Tree tree = bothTrees.get(0); Tree prunedModel = bothTrees.get(1); if (bothTrees.size() < 2) { if (TreeUtils.VERBOSE_ROOTING) { System.out.println("[RerootByModelTree] Rooting by Modeltree not possible for tree: " + tree.getName() + " because trees have no overlapping taxa!"); } return null; } if (prunedModel.getRoot().childCount() == 2) { findMostCompatibleRoot(tree, prunedModel); } else { findMostCompatibleFakeRoot(tree, prunedModel); } return tree; }
public static double[] calculateSumOfRates(Tree calculated, Tree[] sourceTrees) { int sumOfFNFP[] = new int[4]; Arrays.fill(sumOfFNFP, 0); int maxTotalNumOfPartitions = 0; for (Tree sourceTree : sourceTrees) { Tree[] trees = {calculated, sourceTree}; trees = TreeUtils.cloneAndPruneTrees(trees); if (trees != null) { maxTotalNumOfPartitions += (trees[0].getNumTaxa() - 3); int[] toAdd = calculateNumberOfMissingClades(trees[0], trees[1]); for (int i = 0; i < toAdd.length; i++) { sumOfFNFP[i] += toAdd[i]; } } } double[] sumOfRates = new double[6]; sumOfRates[0] = (double) sumOfFNFP[0] / (double) sumOfFNFP[2]; sumOfRates[1] = (double) sumOfFNFP[1] / (double) sumOfFNFP[2]; sumOfRates[2] = (double) sumOfFNFP[0]; sumOfRates[3] = (double) sumOfFNFP[1]; sumOfRates[4] = (double) sumOfFNFP[0] / (double) maxTotalNumOfPartitions; sumOfRates[5] = (double) sumOfFNFP[1] / (double) maxTotalNumOfPartitions; return sumOfRates; }
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);
/** * Computes the triplet distance between tree1 and tree2 * * @param tree1 the first tree * @param tree2 the second tree * @param toPrune true if the trees should be pruned to same leave set * @return distance triplet distance between the two trees */ public static double getTripletDistance(Tree tree1, Tree tree2, boolean toPrune) { if (toPrune) { Tree[] pruned = TreeUtils.cloneAndPruneTrees(new Tree[]{tree1, tree2}); // empty trees => distance 1 if (pruned == null) return 1.0; return new TripletDistance().computeDistance(pruned[0], pruned[1]); } return new TripletDistance().computeDistance(tree1, tree2); }
Tree[] forRooting = TreeUtils.cloneAndPruneTrees(new Tree[]{tree, rootedModel});
public RFDistance(Tree tree, Tree compareTree, boolean prune) { if (prune && !tree.getRoot().getPartition().equals(compareTree.getRoot().getPartition())) { Tree[] ts = new Tree[]{tree, compareTree}; ts = TreeUtils.cloneAndPruneTrees(ts); if (ts != null) { this.tree = ts[0]; this.compareTree = ts[1]; } else { // pruning failed, the two trees have nothing in // common so we set the difference to max // count internal nodes int c = tree.edgeCount() - tree.getNumTaxa(); c += compareTree.edgeCount() - compareTree.getNumTaxa(); // add 2, one for each root. the roots are not counted when we // use edge count - taxa to find internal nodes ! c += 2; this.difference = c; } } else { this.tree = tree; this.compareTree = compareTree; } this.roots = new TreeNode[2]; this.roots[0] = (TreeNode) compareTree.getRoot(); this.roots[1] = (TreeNode) tree.getRoot(); this.sym = false; }