public double getNormalizedDistance() { // empty trees => distance 1 if (t1 == null && t2 == null) return 1.0; double d = getDistance(); // count internal nodes int c = t1.edgeCount() - t1.getNumTaxa(); c += t2.edgeCount() - t2.getNumTaxa(); // add 2, one for each root. the roots are not counted when we // use edge count - taxa to find internal nodes ! c += 2; return (d / (double) c); }
public double computeNormalizedDistance(Tree t1, Tree t2) { double c = t1.edgeCount() - t1.getNumTaxa(); c += t2.edgeCount() - t2.getNumTaxa(); c += 2; return TripletDistance.getTripletDistance(t1, t2, true) / c; }
public double computeNormalizedDistance(Tree t1, Tree t2, boolean prune) { double c = t1.edgeCount() - t1.getNumTaxa(); c += t2.edgeCount() - t2.getNumTaxa(); c += 2; return TripletDistance.getTripletDistance(t1, t2, prune) / c; }
public static double getNormalizedDifference(Tree tree, Tree otherTree, boolean prune) { RFDistance r = new RFDistance(tree, otherTree, prune); int d = r.getDifference(); // count internal nodes in both trees int c = tree.edgeCount() - tree.getNumTaxa(); c += otherTree.edgeCount() - otherTree.getNumTaxa(); // add 2, one for each root. the roots are not counted when we // use edge count - taxa to find internal nodes ! c += 2; return ((double) d / (double) c); }
private Map<TreeNode, Set<Object>> getNodeToLeafMap(Tree tree) { Map<TreeNode, Set<Object>> map = new HashMap<>(tree.getNumTaxa()); for (TreeNode node : tree.vertices()) { if (node.isInnerNode()) { Set<Object> leafSet = new HashSet<>(); for (TreeNode taxon : node.getLeaves()) { leafSet.add(nameToObject.get(taxon.getLabel())); } map.put(node, leafSet); } } return map; }
private double caclulateTreeResolution(Tree tree) { return TreeUtils.calculateTreeResolution(tree.getNumTaxa(), tree.vertexCount()); }
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 void reduceUnsupportedClades(Tree supertree) { int modifiedCharacters = 0; int deletedCharacters = 0; int innernodesBefore = supertree.vertexCount() - supertree.getNumTaxa(); int innernodesAfter = supertree.vertexCount() - supertree.getNumTaxa(); System.out.println("--------------> " + modifiedCharacters + "clades modified"); System.out.println("--------------> " + deletedCharacters + "clades deleted (counted)");
public static double[][] getNormalizedDifference(Tree[] trees, boolean prune, boolean useBCN) { double[][] d = new double[trees.length][trees.length]; // count internal nodes int[] counts = new int[trees.length]; for (int i = 0; i < counts.length; i++) { // +1 for the root counts[i] = (trees[i].edgeCount() - trees[i].getNumTaxa()) + 1; } for (int i = 0; i < d.length; i++) { for (int j = i; j < d[i].length; j++) { if (i == j) continue; double dist = 0; if (useBCN) { dist = RFDistance.getNormalizedBCNPartitionDist(trees[i], trees[j]); } else { dist = RFDistance.getDifference(trees[i], trees[j], prune); dist = dist / (counts[i] + counts[j]); } d[i][j] = dist; d[j][i] = d[i][j]; } } return d; }
CLI.LOGGER_WRAPPER.info("Clades in guide tree: " + (guideTree.vertexCount() - guideTree.getNumTaxa()));
List<Tree> bestRootedInputTrees = null; int totalNumberOfErrors = Integer.MAX_VALUE; int numTaxa = unrootedModel.getNumTaxa();
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; }
internalNodesCompareTree = getInternalNodes(compareTree); int allLeaves = tree.getNumTaxa(); int countLeavesSubTree = 0; int countLeavesSubCompareTree = 0;