/** * 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(); }
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); } }
/** * Compares this Partition to another Partition. * <p> * Returns 0 if both are equal, this means they have the same size and * contain the same Elements. A negative Value is returned if the size of * this Partition is smaller than the size of the other Partition. A positive * Value is returned if the size of this Patition is larger than the size of the * other one. If both Partitons have the same size but do not contain the same Elements, * an Exception is thrown. * * @param otherPartition * @return int */ public int compareTo(Partition otherPartition) throws Exception { if (this.getSize() < otherPartition.getSize()) return -1; if (this.getSize() > otherPartition.getSize()) return 1; if (this.equals(otherPartition)) return 0; throw new Exception(); }
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; }