2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.analysis;
23 import jalview.api.analysis.ScoreModelI;
24 import jalview.api.analysis.SimilarityParamsI;
25 import jalview.datamodel.SequenceNode;
26 import jalview.viewmodel.AlignmentViewport;
34 public class NJTree extends TreeBuilder
37 * Constructor given a viewport, tree type and score model
40 * the current alignment viewport
42 * a distance or similarity score model to use to compute the tree
43 * @param scoreParameters
45 public NJTree(AlignmentViewport av, ScoreModelI sm,
46 SimilarityParamsI scoreParameters)
48 super(av, sm, scoreParameters);
50 // private long _lycount = 0, _lylimit = 0;
55 * @return DOCUMENT ME!
59 double findMinDistance()
61 double min = Double.MAX_VALUE;
63 for (int i = 0; i < (noseqs - 1); i++)
65 for (int j = i + 1; j < noseqs; j++)
67 if (!done.get(i) && !done.get(j))
69 double tmp = distances.getValue(i, j)
70 - (findr(i, j) + findr(j, i));
98 void findNewDistances(SequenceNode tmpi, SequenceNode tmpj, double dist)
101 tmpi.dist = ((dist + ri) - rj) / 2;
102 tmpj.dist = (dist - tmpi.dist);
118 * Calculates and saves the distance between the combination of cluster(i) and
119 * cluster(j) and all other clusters. The new distance to cluster k is
120 * calculated as the average of the distances from i to k and from j to k,
121 * less half the distance from i to j.
128 void findClusterDistance(int i, int j)
130 // New distances from cluster i to others
131 double[] newdist = new double[noseqs];
133 double ijDistance = distances.getValue(i, j);
134 for (int l = 0; l < noseqs; l++)
136 if ((l != i) && (l != j))
138 newdist[l] = (distances.getValue(i, l) + distances.getValue(j, l) - ijDistance) / 2;
146 for (int ii = 0; ii < noseqs; ii++)
148 distances.setValue(i, ii, newdist[ii]);
149 distances.setValue(ii, i, newdist[ii]);