/** * method looks if the content of two nodes is really equal * * @param node1 * @param node2 * @return 0 if node 1 equals node 2 (throws ClassCastException) */ public int equals(TreeNode node1, TreeNode node2) throws ClassCastException { if (node1.getPartition().equals(node2.getPartition())) return 0; throw new ClassCastException(); }
@Override public String toString() { return source.getPartition() + " -> " + (isDummy() ? "Dummy" : target.getPartition().toString()) + ":" + distance; }
public Edge getDistanceEdge(TreeNode source, TreeNode target) { if (source.getPartition().equals(target.getPartition())) { // System.out.println("GELICH: Partition tree1: "+source.getPartition().toString()+", Partition tree2: "+target.getPartition().toString()); return new Edge(source, target, 0); } else { // create dummy edges for non matching partitions // System.out.println("UNGLEICH: Partition tree1: "+source.getPartition().toString()+", Partition tree2: "+target.getPartition().toString()); return new Edge(source, source, 1); } }
/** * method first compare the size of two nodes, if the size is the same * the equals method is called * * @return -1 if node 1 < node 2, * 1 if node 1 > node 2, else equals (node 1,node2) */ public int compare(TreeNode node1, TreeNode node2) { if (node1 == null || node2 == null) { throw new ClassCastException(); } if (node1.getPartition().getSize() < node2.getPartition().getSize()) { return -1; } else if (node1.getPartition().getSize() > node2.getPartition().getSize()) { return 1; } return equals(node1, node2); }
private TreeNode searchForNode(Tree model, TreeNode node) { TreeNode found = ((TreeNode) model.getRoot()).getPartition().getNode(node); return found; }
public Edge getDistanceEdge(TreeNode source, TreeNode target) { int intersection = 0; double s = 0; for (TreeNode treeNodeSource : source.getPartition() .getLeavesArray()) { for (TreeNode treeNodeTarget : target.getPartition() .getLeavesArray()) { if (treeNodeSource.getLabel().equals( treeNodeTarget.getLabel())) { // if (treeNodeSource.equals(treeNodeTarget)){ intersection++; } } } s = (intersection / (Math.pow( (double) (source.getPartition().getSize() + target .getPartition().getSize()), parameter))); return new Edge(source, target, s); }
protected static int bcnPartitionDist(Tree t1, Tree t2) { int dist = 0; TreeCompareDefault tc = new TreeCompareDefault(t1); HashMap<TreeNode, BCNScore> c = tc.compare(t2); for (TreeNode n : c.keySet()) { BCNScore s = c.get(n); TreeNode o = t2.getVertex(s.getTargetIndex()); //System.out.println("Compare " + n.getPartition() + " to " + o.getPartition()); try { if (n.getPartition().compareTo(o.getPartition()) != 0) { dist++; } } catch (Exception e) { dist++; } } return dist; }
public Edge getDistanceEdge(TreeNode source, TreeNode target) { // //System.out.println("getDistance Methode: Source treeNode partition --> "+source.getPartition().toString()); // //System.out.println("getDistance Methode: Target treeNode partition --> "+target.getPartition().toString()); int intersection = 0; int union = 0; double s = 0; for (TreeNode treeNodeSource : source.getPartition() .getLeavesArray()) { for (TreeNode treeNodeTarget : target.getPartition() .getLeavesArray()) { if (treeNodeSource.getLabel().equals( treeNodeTarget.getLabel())) { // if (treeNodeSource.equals(treeNodeTarget)){ intersection++; } } } // //System.out.println("getDistance Methode: intersection --> "+intersection); union = source.getPartition().getSize() + target.getPartition().getSize() - intersection; // //System.out.println("getDistance Methode: union --> "+union); s = (double) intersection / (double) union; // //System.out.println("getDistance Methdode: Distance --> "+s); return new Edge(source, target, s); }
public Edge getDistanceEdge(TreeNode source, TreeNode target) { int intersection = 0; double s = 0; for (TreeNode treeNodeSource : source.getPartition() .getLeavesArray()) { for (TreeNode treeNodeTarget : target.getPartition() .getLeavesArray()) { if (treeNodeSource.getLabel().equals( treeNodeTarget.getLabel())) { // if (treeNodeSource.equals(treeNodeTarget)){ intersection++; } } } // //System.out.println("getDistance Methode likelihoods: intersection --> "+intersection); TreeNode getRootHelp = source; while (getRootHelp.getParent() != null) { getRootHelp = getRootHelp.getParent(); } int allLeaves = getRootHelp.getLeaves().length; s = BCNWithLikelihoods.computeValueWithDouble(allLeaves, source .getPartition().getSize(), target.getPartition().getSize(), intersection); return new Edge(source, target, s); }
Partition sPartition = rootNode.getPartition().intersect(partition);
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; }
int z = 0; for (TreeNode n : treeNodes[i].children()) { childPartitions[z++] = n.getPartition();