X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fanalysis%2FTreeBuilder.java;h=effef9a405fe3140b0f47f439b81f0ed5d285f6a;hb=00918171094ad58563bd0b82e18ecf19537ba132;hp=49c56c964f9e20d9b8e8a9e0e46691e2b446f13b;hpb=be27d7b3cadbfb5c488066034c48b1735799b429;p=jalview.git diff --git a/src/jalview/analysis/TreeBuilder.java b/src/jalview/analysis/TreeBuilder.java index 49c56c9..effef9a 100644 --- a/src/jalview/analysis/TreeBuilder.java +++ b/src/jalview/analysis/TreeBuilder.java @@ -1,9 +1,7 @@ package jalview.analysis; -import jalview.api.analysis.DistanceScoreModelI; import jalview.api.analysis.ScoreModelI; import jalview.api.analysis.SimilarityParamsI; -import jalview.api.analysis.SimilarityScoreModelI; import jalview.datamodel.AlignmentView; import jalview.datamodel.CigarArray; import jalview.datamodel.SeqCigar; @@ -55,6 +53,8 @@ public abstract class TreeBuilder Vector node; + private AlignmentView seqStrings; + /** * Constructor * @@ -68,7 +68,7 @@ public abstract class TreeBuilder int start, end; boolean selview = av.getSelectionGroup() != null && av.getSelectionGroup().getSize() > 1; - AlignmentView seqStrings = av.getAlignmentView(selview); + seqStrings = av.getAlignmentView(selview); if (!selview) { start = 0; @@ -251,6 +251,12 @@ public abstract class TreeBuilder findMaxDist(top); } + /** + * Returns the minimum distance between two clusters, and also sets the + * indices of the clusters in fields mini and minj + * + * @return + */ protected abstract double findMinDistance(); /** @@ -268,21 +274,7 @@ public abstract class TreeBuilder */ protected void computeTree(ScoreModelI sm, SimilarityParamsI scoreOptions) { - if (sm instanceof DistanceScoreModelI) - { - distances = ((DistanceScoreModelI) sm).findDistances(seqData, - scoreOptions); - } - else if (sm instanceof SimilarityScoreModelI) - { - /* - * compute similarity and invert it to give a distance measure - */ - MatrixI result = ((SimilarityScoreModelI) sm).findSimilarities( - seqData, scoreOptions); - result.reverseRange(true); - distances = result; - } + distances = sm.findDistances(seqData, scoreOptions); makeLeaves(); @@ -292,10 +284,10 @@ public abstract class TreeBuilder } /** - * DOCUMENT ME! + * Finds the node, at or below the given node, with the maximum distance, and + * saves the node and the distance value * * @param nd - * DOCUMENT ME! */ void findMaxDist(SequenceNode nd) { @@ -322,14 +314,12 @@ public abstract class TreeBuilder } /** - * DOCUMENT ME! + * Calculates and returns r, whatever that is * * @param i - * DOCUMENT ME! * @param j - * DOCUMENT ME! * - * @return DOCUMENT ME! + * @return */ protected double findr(int i, int j) { @@ -396,11 +386,6 @@ public abstract class TreeBuilder { double dist = distances.getValue(i, j); - /* - * add the members of cluster(j) to cluster(i) - */ - clusters.get(i).or(clusters.get(j)); - ri = findr(i, j); rj = findr(j, i); @@ -422,14 +407,20 @@ public abstract class TreeBuilder node.setElementAt(sn, i); /* - * mark cluster j as disposed of + * move the members of cluster(j) to cluster(i) + * and mark cluster j as out of the game */ + clusters.get(i).or(clusters.get(j)); + clusters.get(j).clear(); done.set(j); - clusters.setElementAt(null, j); } - protected abstract void findNewDistances(SequenceNode tmpi, SequenceNode tmpj, - double dist); + /* + * Computes and stores new distances for nodei and nodej, given the previous + * distance between them + */ + protected abstract void findNewDistances(SequenceNode nodei, + SequenceNode nodej, double previousDistance); /** * Calculates and saves the distance between the combination of cluster(i) and @@ -461,4 +452,9 @@ public abstract class TreeBuilder } } + public AlignmentView getOriginalData() + { + return seqStrings; + } + }