/** * 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 int compareTo(Object o) { try { return compareTo((Partition) o); } catch (Exception e) { e.printStackTrace(); } return 0; }
if (this.minKey.compareTo(otherPartition.getMaxKey()) > 0) return null; if (otherPartition.getMinKey().compareTo(this.getMaxKey()) > 0) return null; } catch (ClassCastException e) { System.out.println("Class Cast Exception" + e.getMessage() + " " + e); Partition schnitt = new Partition(); Iterator myLeavesIterator = null; myLeavesIterator = getLeavesIterator(); Object value = otherPartition.get(key); TreeNode node = this.get(key); schnitt.add(node); if (schnitt.isEmpty()) { return null; } else {
/** * Add a partition onto this one. * * @param p Partition */ public void add(Partition p) { Iterator i = p.getLeavesIterator(); while (i.hasNext()) { TreeNode n = (TreeNode) i.next(); //System.out.println("Try to add node from partition " + n); this.add(p.getNode(n)); //System.out.println(" done"); } }
/** * Checks if this partition is subset of another partition. * if the other partition contains all leaves of this parititon * 1 will be returned otherwise 0. */ public int isSubset(Partition otherPartition) { if (otherPartition == null) return 0; Iterator myLeavesIterator = getLeavesIterator(); while (myLeavesIterator.hasNext()) { Object key = myLeavesIterator.next(); Object value = otherPartition.getNode(key); if (value == null) {//alle Nodes der Partition muessen in der anderen vorkommen return 0; } } return 1; }
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); }
Partition sPartition = rootNode.getPartition().intersect(partition); Iterator it = sPartition.getLeavesIterator(); TreeNode erster = (TreeNode) sPartition.get(it.next()); newAncestor = erster; TreeNode n = (TreeNode) sPartition.get(it.next()); dummyAncestor = model.findLeastCommonAncestor(n, erster);
Object id; TreeNode newNode; switch (p[i].getSize()) { case 1: id = p[i].getLeavesIterator().next(); result.addVertex(newNode); result.addEdge(node, newNode); Iterator it = p[i].getLeavesIterator(); while (it.hasNext()) { id = it.next();
/** * 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); }
/** * 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(); }
/** * Returns the String representation of the Partition. * * @see Object#toString() */ public String toString() { Iterator i = this.getLeavesIterator(); String s = "["; while (i.hasNext()) { s = s + (i.next() + ","); } s = s.substring(0, s.length() - 1) + "]"; return s; }
/** * Creates and returns the {@link Partition} of this node. Partitions are not * cached and recomputed for each call. * * @return partition of this node */ public Partition getPartition() { Partition partition = new Partition(); for (TreeNode n : depthFirstIterator()) { if (n.isLeaf()) { partition.add(n); } } return partition; }
private TreeNode searchForNode(Tree model, TreeNode node) { TreeNode found = ((TreeNode) model.getRoot()).getPartition().getNode(node); return found; }
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) { 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); } }
/** * Returns a String representation of the Partition. * Better use the toString Method. * * @return String The String representation. * @deprecated Use the standart toString() Method! */ public String toHashString() { Iterator i = this.getLeavesIterator(); Vector leaves = new Vector(); int n = 0; while (i.hasNext()) { int j = 0; Object next = i.next(); while (j < leaves.size()) { if (leaves.elementAt(j).toString().compareTo(next.toString()) > 0) { break; } j++; } leaves.insertElementAt(next, j); } String orderedHash = new String(); for (int j = 0; j < leaves.size(); j++) { orderedHash = orderedHash + leaves.elementAt(j).toString() + ","; } orderedHash = orderedHash.substring(0, orderedHash.length() - 1); return orderedHash; }
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); }
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; }
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; }