git://source.jalview.org
/
jalview.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
TreePanel takes viewport
[jalview.git]
/
src
/
jalview
/
analysis
/
NJTree.java
diff --git
a/src/jalview/analysis/NJTree.java
b/src/jalview/analysis/NJTree.java
index
6daee9b
..
71d6737
100755
(executable)
--- a/
src/jalview/analysis/NJTree.java
+++ b/
src/jalview/analysis/NJTree.java
@@
-29,7
+29,14
@@
import jalview.util.*;
import java.util.*;
\r
\r
\r
import java.util.*;
\r
\r
\r
-public class NJTree {
\r
+/**
\r
+ * DOCUMENT ME!
\r
+ *
\r
+ * @author $author$
\r
+ * @version $Revision$
\r
+ */
\r
+public class NJTree
\r
+{
\r
Vector cluster;
\r
SequenceI[] sequence;
\r
int[] done;
\r
Vector cluster;
\r
SequenceI[] sequence;
\r
int[] done;
\r
@@
-54,12
+61,25
@@
public class NJTree {
int start;
\r
int end;
\r
\r
int start;
\r
int end;
\r
\r
- public NJTree(SequenceNode node) {
\r
+ /**
\r
+ * Creates a new NJTree object.
\r
+ *
\r
+ * @param node DOCUMENT ME!
\r
+ */
\r
+ public NJTree(SequenceNode node)
\r
+ {
\r
top = node;
\r
maxheight = findHeight(top);
\r
}
\r
\r
top = node;
\r
maxheight = findHeight(top);
\r
}
\r
\r
- public NJTree(SequenceI[] seqs, NewickFile treefile) {
\r
+ /**
\r
+ * Creates a new NJTree object.
\r
+ *
\r
+ * @param seqs DOCUMENT ME!
\r
+ * @param treefile DOCUMENT ME!
\r
+ */
\r
+ public NJTree(SequenceI[] seqs, NewickFile treefile)
\r
+ {
\r
top = treefile.getTree();
\r
maxheight = findHeight(top);
\r
\r
top = treefile.getTree();
\r
maxheight = findHeight(top);
\r
\r
@@
-75,31
+95,54
@@
public class NJTree {
SequenceI nam;
\r
String realnam;
\r
\r
SequenceI nam;
\r
String realnam;
\r
\r
- while (i < leaves.size()) {
\r
+ while (i < leaves.size())
\r
+ {
\r
j = (SequenceNode) leaves.elementAt(i++);
\r
realnam = j.getName();
\r
nam = null;
\r
\r
j = (SequenceNode) leaves.elementAt(i++);
\r
realnam = j.getName();
\r
nam = null;
\r
\r
- if (namesleft > -1) {
\r
+ if (namesleft > -1)
\r
+ {
\r
nam = algnIds.findIdMatch(realnam);
\r
}
\r
\r
nam = algnIds.findIdMatch(realnam);
\r
}
\r
\r
- if (nam != null) {
\r
+ if (nam != null)
\r
+ {
\r
j.setElement(nam);
\r
namesleft--;
\r
j.setElement(nam);
\r
namesleft--;
\r
- } else {
\r
+ }
\r
+ else
\r
+ {
\r
j.setElement(new Sequence(realnam, "THISISAPLACEHLDER"));
\r
j.setPlaceholder(true);
\r
}
\r
}
\r
}
\r
\r
j.setElement(new Sequence(realnam, "THISISAPLACEHLDER"));
\r
j.setPlaceholder(true);
\r
}
\r
}
\r
}
\r
\r
- public NJTree(SequenceI[] sequence, int start, int end) {
\r
+ /**
\r
+ * Creates a new NJTree object.
\r
+ *
\r
+ * @param sequence DOCUMENT ME!
\r
+ * @param start DOCUMENT ME!
\r
+ * @param end DOCUMENT ME!
\r
+ */
\r
+ public NJTree(SequenceI[] sequence, int start, int end)
\r
+ {
\r
this(sequence, "NJ", "BL", start, end);
\r
}
\r
\r
this(sequence, "NJ", "BL", start, end);
\r
}
\r
\r
+ /**
\r
+ * Creates a new NJTree object.
\r
+ *
\r
+ * @param sequence DOCUMENT ME!
\r
+ * @param type DOCUMENT ME!
\r
+ * @param pwtype DOCUMENT ME!
\r
+ * @param start DOCUMENT ME!
\r
+ * @param end DOCUMENT ME!
\r
+ */
\r
public NJTree(SequenceI[] sequence, String type, String pwtype, int start,
\r
public NJTree(SequenceI[] sequence, String type, String pwtype, int start,
\r
- int end) {
\r
+ int end)
\r
+ {
\r
this.sequence = sequence;
\r
this.node = new Vector();
\r
this.type = type;
\r
this.sequence = sequence;
\r
this.node = new Vector();
\r
this.type = type;
\r
@@
-107,11
+150,13
@@
public class NJTree {
this.start = start;
\r
this.end = end;
\r
\r
this.start = start;
\r
this.end = end;
\r
\r
- if (!(type.equals("NJ"))) {
\r
+ if (!(type.equals("NJ")))
\r
+ {
\r
type = "AV";
\r
}
\r
\r
type = "AV";
\r
}
\r
\r
- if (!(pwtype.equals("PID"))) {
\r
+ if (!(pwtype.equals("PID")))
\r
+ {
\r
type = "BL";
\r
}
\r
\r
type = "BL";
\r
}
\r
\r
@@
-119,7
+164,8
@@
public class NJTree {
\r
done = new int[sequence.length];
\r
\r
\r
done = new int[sequence.length];
\r
\r
- while ((i < sequence.length) && (sequence[i] != null)) {
\r
+ while ((i < sequence.length) && (sequence[i] != null))
\r
+ {
\r
done[i] = 0;
\r
i++;
\r
}
\r
done[i] = 0;
\r
i++;
\r
}
\r
@@
-135,7
+181,13
@@
public class NJTree {
cluster();
\r
}
\r
\r
cluster();
\r
}
\r
\r
- public String toString() {
\r
+ /**
\r
+ * DOCUMENT ME!
\r
+ *
\r
+ * @return DOCUMENT ME!
\r
+ */
\r
+ public String toString()
\r
+ {
\r
jalview.io.NewickFile fout = new jalview.io.NewickFile(getTopNode());
\r
\r
return fout.print(false, true); // distances only
\r
jalview.io.NewickFile fout = new jalview.io.NewickFile(getTopNode());
\r
\r
return fout.print(false, true); // distances only
\r
@@
-147,7
+199,8
@@
public class NJTree {
*
\r
* @param alignment Vector
\r
*/
\r
*
\r
* @param alignment Vector
\r
*/
\r
- public void UpdatePlaceHolders(Vector alignment) {
\r
+ public void UpdatePlaceHolders(Vector alignment)
\r
+ {
\r
Vector leaves = new Vector();
\r
findLeaves(top, leaves);
\r
\r
Vector leaves = new Vector();
\r
findLeaves(top, leaves);
\r
\r
@@
-155,13
+208,18
@@
public class NJTree {
SequenceIdMatcher seqmatcher = null;
\r
int i = 0;
\r
\r
SequenceIdMatcher seqmatcher = null;
\r
int i = 0;
\r
\r
- while (i < sz) {
\r
+ while (i < sz)
\r
+ {
\r
SequenceNode leaf = (SequenceNode) leaves.elementAt(i++);
\r
\r
SequenceNode leaf = (SequenceNode) leaves.elementAt(i++);
\r
\r
- if (alignment.contains(leaf.element())) {
\r
+ if (alignment.contains(leaf.element()))
\r
+ {
\r
leaf.setPlaceholder(false);
\r
leaf.setPlaceholder(false);
\r
- } else {
\r
- if (seqmatcher == null) {
\r
+ }
\r
+ else
\r
+ {
\r
+ if (seqmatcher == null)
\r
+ {
\r
// Only create this the first time we need it
\r
SequenceI[] seqs = new SequenceI[alignment.size()];
\r
\r
// Only create this the first time we need it
\r
SequenceI[] seqs = new SequenceI[alignment.size()];
\r
\r
@@
-173,21
+231,32
@@
public class NJTree {
\r
SequenceI nam = seqmatcher.findIdMatch(leaf.getName());
\r
\r
\r
SequenceI nam = seqmatcher.findIdMatch(leaf.getName());
\r
\r
- if (nam != null) {
\r
+ if (nam != null)
\r
+ {
\r
leaf.setPlaceholder(false);
\r
leaf.setElement(nam);
\r
leaf.setPlaceholder(false);
\r
leaf.setElement(nam);
\r
- } else {
\r
+ }
\r
+ else
\r
+ {
\r
leaf.setPlaceholder(true);
\r
}
\r
}
\r
}
\r
}
\r
\r
leaf.setPlaceholder(true);
\r
}
\r
}
\r
}
\r
}
\r
\r
- public void cluster() {
\r
- while (noClus > 2) {
\r
- if (type.equals("NJ")) {
\r
+ /**
\r
+ * DOCUMENT ME!
\r
+ */
\r
+ public void cluster()
\r
+ {
\r
+ while (noClus > 2)
\r
+ {
\r
+ if (type.equals("NJ"))
\r
+ {
\r
float mind = findMinNJDistance();
\r
float mind = findMinNJDistance();
\r
- } else {
\r
+ }
\r
+ else
\r
+ {
\r
float mind = findMinDistance();
\r
}
\r
\r
float mind = findMinDistance();
\r
}
\r
\r
@@
-206,12
+275,17
@@
public class NJTree {
int one = -1;
\r
int two = -1;
\r
\r
int one = -1;
\r
int two = -1;
\r
\r
- for (int i = 0; i < noseqs; i++) {
\r
- if (done[i] != 1) {
\r
- if (onefound == false) {
\r
+ for (int i = 0; i < noseqs; i++)
\r
+ {
\r
+ if (done[i] != 1)
\r
+ {
\r
+ if (onefound == false)
\r
+ {
\r
two = i;
\r
onefound = true;
\r
two = i;
\r
onefound = true;
\r
- } else {
\r
+ }
\r
+ else
\r
+ {
\r
one = i;
\r
}
\r
}
\r
one = i;
\r
}
\r
}
\r
@@
-225,7
+299,16
@@
public class NJTree {
findMaxDist(top);
\r
}
\r
\r
findMaxDist(top);
\r
}
\r
\r
- public Cluster joinClusters(int i, int j) {
\r
+ /**
\r
+ * DOCUMENT ME!
\r
+ *
\r
+ * @param i DOCUMENT ME!
\r
+ * @param j DOCUMENT ME!
\r
+ *
\r
+ * @return DOCUMENT ME!
\r
+ */
\r
+ public Cluster joinClusters(int i, int j)
\r
+ {
\r
float dist = distance[i][j];
\r
\r
int noi = ((Cluster) cluster.elementAt(i)).value.length;
\r
float dist = distance[i][j];
\r
\r
int noi = ((Cluster) cluster.elementAt(i)).value.length;
\r
@@
-233,11
+316,13
@@
public class NJTree {
\r
int[] value = new int[noi + noj];
\r
\r
\r
int[] value = new int[noi + noj];
\r
\r
- for (int ii = 0; ii < noi; ii++) {
\r
+ for (int ii = 0; ii < noi; ii++)
\r
+ {
\r
value[ii] = ((Cluster) cluster.elementAt(i)).value[ii];
\r
}
\r
\r
value[ii] = ((Cluster) cluster.elementAt(i)).value[ii];
\r
}
\r
\r
- for (int ii = noi; ii < (noi + noj); ii++) {
\r
+ for (int ii = noi; ii < (noi + noj); ii++)
\r
+ {
\r
value[ii] = ((Cluster) cluster.elementAt(j)).value[ii - noi];
\r
}
\r
\r
value[ii] = ((Cluster) cluster.elementAt(j)).value[ii - noi];
\r
}
\r
\r
@@
-246,9
+331,12
@@
public class NJTree {
ri = findr(i, j);
\r
rj = findr(j, i);
\r
\r
ri = findr(i, j);
\r
rj = findr(j, i);
\r
\r
- if (type.equals("NJ")) {
\r
+ if (type.equals("NJ"))
\r
+ {
\r
findClusterNJDistance(i, j);
\r
findClusterNJDistance(i, j);
\r
- } else {
\r
+ }
\r
+ else
\r
+ {
\r
findClusterDistance(i, j);
\r
}
\r
\r
findClusterDistance(i, j);
\r
}
\r
\r
@@
-260,9
+348,12
@@
public class NJTree {
SequenceNode tmpi = (SequenceNode) (node.elementAt(i));
\r
SequenceNode tmpj = (SequenceNode) (node.elementAt(j));
\r
\r
SequenceNode tmpi = (SequenceNode) (node.elementAt(i));
\r
SequenceNode tmpj = (SequenceNode) (node.elementAt(j));
\r
\r
- if (type.equals("NJ")) {
\r
+ if (type.equals("NJ"))
\r
+ {
\r
findNewNJDistances(tmpi, tmpj, dist);
\r
findNewNJDistances(tmpi, tmpj, dist);
\r
- } else {
\r
+ }
\r
+ else
\r
+ {
\r
findNewDistances(tmpi, tmpj, dist);
\r
}
\r
\r
findNewDistances(tmpi, tmpj, dist);
\r
}
\r
\r
@@
-274,8
+365,16
@@
public class NJTree {
return c;
\r
}
\r
\r
return c;
\r
}
\r
\r
+ /**
\r
+ * DOCUMENT ME!
\r
+ *
\r
+ * @param tmpi DOCUMENT ME!
\r
+ * @param tmpj DOCUMENT ME!
\r
+ * @param dist DOCUMENT ME!
\r
+ */
\r
public void findNewNJDistances(SequenceNode tmpi, SequenceNode tmpj,
\r
public void findNewNJDistances(SequenceNode tmpi, SequenceNode tmpj,
\r
- float dist) {
\r
+ float dist)
\r
+ {
\r
float ih = 0;
\r
float jh = 0;
\r
\r
float ih = 0;
\r
float jh = 0;
\r
\r
@@
-285,29
+384,41
@@
public class NJTree {
tmpi.dist = ((dist + ri) - rj) / 2;
\r
tmpj.dist = (dist - tmpi.dist);
\r
\r
tmpi.dist = ((dist + ri) - rj) / 2;
\r
tmpj.dist = (dist - tmpi.dist);
\r
\r
- if (tmpi.dist < 0) {
\r
+ if (tmpi.dist < 0)
\r
+ {
\r
tmpi.dist = 0;
\r
}
\r
\r
tmpi.dist = 0;
\r
}
\r
\r
- if (tmpj.dist < 0) {
\r
+ if (tmpj.dist < 0)
\r
+ {
\r
tmpj.dist = 0;
\r
}
\r
}
\r
\r
tmpj.dist = 0;
\r
}
\r
}
\r
\r
+ /**
\r
+ * DOCUMENT ME!
\r
+ *
\r
+ * @param tmpi DOCUMENT ME!
\r
+ * @param tmpj DOCUMENT ME!
\r
+ * @param dist DOCUMENT ME!
\r
+ */
\r
public void findNewDistances(SequenceNode tmpi, SequenceNode tmpj,
\r
public void findNewDistances(SequenceNode tmpi, SequenceNode tmpj,
\r
- float dist) {
\r
+ float dist)
\r
+ {
\r
float ih = 0;
\r
float jh = 0;
\r
\r
SequenceNode sni = tmpi;
\r
SequenceNode snj = tmpj;
\r
\r
float ih = 0;
\r
float jh = 0;
\r
\r
SequenceNode sni = tmpi;
\r
SequenceNode snj = tmpj;
\r
\r
- while (sni != null) {
\r
+ while (sni != null)
\r
+ {
\r
ih = ih + sni.dist;
\r
sni = (SequenceNode) sni.left();
\r
}
\r
\r
ih = ih + sni.dist;
\r
sni = (SequenceNode) sni.left();
\r
}
\r
\r
- while (snj != null) {
\r
+ while (snj != null)
\r
+ {
\r
jh = jh + snj.dist;
\r
snj = (SequenceNode) snj.left();
\r
}
\r
jh = jh + snj.dist;
\r
snj = (SequenceNode) snj.left();
\r
}
\r
@@
-316,75
+427,121
@@
public class NJTree {
tmpj.dist = ((dist / 2) - jh);
\r
}
\r
\r
tmpj.dist = ((dist / 2) - jh);
\r
}
\r
\r
- public void findClusterDistance(int i, int j) {
\r
+ /**
\r
+ * DOCUMENT ME!
\r
+ *
\r
+ * @param i DOCUMENT ME!
\r
+ * @param j DOCUMENT ME!
\r
+ */
\r
+ public void findClusterDistance(int i, int j)
\r
+ {
\r
int noi = ((Cluster) cluster.elementAt(i)).value.length;
\r
int noj = ((Cluster) cluster.elementAt(j)).value.length;
\r
\r
// New distances from cluster to others
\r
float[] newdist = new float[noseqs];
\r
\r
int noi = ((Cluster) cluster.elementAt(i)).value.length;
\r
int noj = ((Cluster) cluster.elementAt(j)).value.length;
\r
\r
// New distances from cluster to others
\r
float[] newdist = new float[noseqs];
\r
\r
- for (int l = 0; l < noseqs; l++) {
\r
- if ((l != i) && (l != j)) {
\r
+ for (int l = 0; l < noseqs; l++)
\r
+ {
\r
+ if ((l != i) && (l != j))
\r
+ {
\r
newdist[l] = ((distance[i][l] * noi) + (distance[j][l] * noj)) / (noi +
\r
noj);
\r
newdist[l] = ((distance[i][l] * noi) + (distance[j][l] * noj)) / (noi +
\r
noj);
\r
- } else {
\r
+ }
\r
+ else
\r
+ {
\r
newdist[l] = 0;
\r
}
\r
}
\r
\r
newdist[l] = 0;
\r
}
\r
}
\r
\r
- for (int ii = 0; ii < noseqs; ii++) {
\r
+ for (int ii = 0; ii < noseqs; ii++)
\r
+ {
\r
distance[i][ii] = newdist[ii];
\r
distance[ii][i] = newdist[ii];
\r
}
\r
}
\r
\r
distance[i][ii] = newdist[ii];
\r
distance[ii][i] = newdist[ii];
\r
}
\r
}
\r
\r
- public void findClusterNJDistance(int i, int j) {
\r
+ /**
\r
+ * DOCUMENT ME!
\r
+ *
\r
+ * @param i DOCUMENT ME!
\r
+ * @param j DOCUMENT ME!
\r
+ */
\r
+ public void findClusterNJDistance(int i, int j)
\r
+ {
\r
int noi = ((Cluster) cluster.elementAt(i)).value.length;
\r
int noj = ((Cluster) cluster.elementAt(j)).value.length;
\r
\r
// New distances from cluster to others
\r
float[] newdist = new float[noseqs];
\r
\r
int noi = ((Cluster) cluster.elementAt(i)).value.length;
\r
int noj = ((Cluster) cluster.elementAt(j)).value.length;
\r
\r
// New distances from cluster to others
\r
float[] newdist = new float[noseqs];
\r
\r
- for (int l = 0; l < noseqs; l++) {
\r
- if ((l != i) && (l != j)) {
\r
+ for (int l = 0; l < noseqs; l++)
\r
+ {
\r
+ if ((l != i) && (l != j))
\r
+ {
\r
newdist[l] = ((distance[i][l] + distance[j][l]) -
\r
distance[i][j]) / 2;
\r
newdist[l] = ((distance[i][l] + distance[j][l]) -
\r
distance[i][j]) / 2;
\r
- } else {
\r
+ }
\r
+ else
\r
+ {
\r
newdist[l] = 0;
\r
}
\r
}
\r
\r
newdist[l] = 0;
\r
}
\r
}
\r
\r
- for (int ii = 0; ii < noseqs; ii++) {
\r
+ for (int ii = 0; ii < noseqs; ii++)
\r
+ {
\r
distance[i][ii] = newdist[ii];
\r
distance[ii][i] = newdist[ii];
\r
}
\r
}
\r
\r
distance[i][ii] = newdist[ii];
\r
distance[ii][i] = newdist[ii];
\r
}
\r
}
\r
\r
- public float findr(int i, int j) {
\r
+ /**
\r
+ * DOCUMENT ME!
\r
+ *
\r
+ * @param i DOCUMENT ME!
\r
+ * @param j DOCUMENT ME!
\r
+ *
\r
+ * @return DOCUMENT ME!
\r
+ */
\r
+ public float findr(int i, int j)
\r
+ {
\r
float tmp = 1;
\r
\r
float tmp = 1;
\r
\r
- for (int k = 0; k < noseqs; k++) {
\r
- if ((k != i) && (k != j) && (done[k] != 1)) {
\r
+ for (int k = 0; k < noseqs; k++)
\r
+ {
\r
+ if ((k != i) && (k != j) && (done[k] != 1))
\r
+ {
\r
tmp = tmp + distance[i][k];
\r
}
\r
}
\r
\r
tmp = tmp + distance[i][k];
\r
}
\r
}
\r
\r
- if (noClus > 2) {
\r
+ if (noClus > 2)
\r
+ {
\r
tmp = tmp / (noClus - 2);
\r
}
\r
\r
return tmp;
\r
}
\r
\r
tmp = tmp / (noClus - 2);
\r
}
\r
\r
return tmp;
\r
}
\r
\r
- public float findMinNJDistance() {
\r
+ /**
\r
+ * DOCUMENT ME!
\r
+ *
\r
+ * @return DOCUMENT ME!
\r
+ */
\r
+ public float findMinNJDistance()
\r
+ {
\r
float min = 100000;
\r
\r
float min = 100000;
\r
\r
- for (int i = 0; i < (noseqs - 1); i++) {
\r
- for (int j = i + 1; j < noseqs; j++) {
\r
- if ((done[i] != 1) && (done[j] != 1)) {
\r
+ for (int i = 0; i < (noseqs - 1); i++)
\r
+ {
\r
+ for (int j = i + 1; j < noseqs; j++)
\r
+ {
\r
+ if ((done[i] != 1) && (done[j] != 1))
\r
+ {
\r
float tmp = distance[i][j] - (findr(i, j) + findr(j, i));
\r
\r
float tmp = distance[i][j] - (findr(i, j) + findr(j, i));
\r
\r
- if (tmp < min) {
\r
+ if (tmp < min)
\r
+ {
\r
mini = i;
\r
minj = j;
\r
\r
mini = i;
\r
minj = j;
\r
\r
@@
-397,13
+554,23
@@
public class NJTree {
return min;
\r
}
\r
\r
return min;
\r
}
\r
\r
- public float findMinDistance() {
\r
+ /**
\r
+ * DOCUMENT ME!
\r
+ *
\r
+ * @return DOCUMENT ME!
\r
+ */
\r
+ public float findMinDistance()
\r
+ {
\r
float min = 100000;
\r
\r
float min = 100000;
\r
\r
- for (int i = 0; i < (noseqs - 1); i++) {
\r
- for (int j = i + 1; j < noseqs; j++) {
\r
- if ((done[i] != 1) && (done[j] != 1)) {
\r
- if (distance[i][j] < min) {
\r
+ for (int i = 0; i < (noseqs - 1); i++)
\r
+ {
\r
+ for (int j = i + 1; j < noseqs; j++)
\r
+ {
\r
+ if ((done[i] != 1) && (done[j] != 1))
\r
+ {
\r
+ if (distance[i][j] < min)
\r
+ {
\r
mini = i;
\r
minj = j;
\r
\r
mini = i;
\r
minj = j;
\r
\r
@@
-416,34
+583,54
@@
public class NJTree {
return min;
\r
}
\r
\r
return min;
\r
}
\r
\r
- public float[][] findDistances() {
\r
+ /**
\r
+ * DOCUMENT ME!
\r
+ *
\r
+ * @return DOCUMENT ME!
\r
+ */
\r
+ public float[][] findDistances()
\r
+ {
\r
float[][] distance = new float[noseqs][noseqs];
\r
\r
float[][] distance = new float[noseqs][noseqs];
\r
\r
- if (pwtype.equals("PID")) {
\r
- for (int i = 0; i < (noseqs - 1); i++) {
\r
- for (int j = i; j < noseqs; j++) {
\r
- if (j == i) {
\r
+ if (pwtype.equals("PID"))
\r
+ {
\r
+ for (int i = 0; i < (noseqs - 1); i++)
\r
+ {
\r
+ for (int j = i; j < noseqs; j++)
\r
+ {
\r
+ if (j == i)
\r
+ {
\r
distance[i][i] = 0;
\r
distance[i][i] = 0;
\r
- } else {
\r
+ }
\r
+ else
\r
+ {
\r
distance[i][j] = 100 -
\r
Comparison.PID(sequence[i], sequence[j], start, end);
\r
distance[j][i] = distance[i][j];
\r
}
\r
}
\r
}
\r
distance[i][j] = 100 -
\r
Comparison.PID(sequence[i], sequence[j], start, end);
\r
distance[j][i] = distance[i][j];
\r
}
\r
}
\r
}
\r
- } else if (pwtype.equals("BL")) {
\r
+ }
\r
+ else if (pwtype.equals("BL"))
\r
+ {
\r
int maxscore = 0;
\r
\r
int maxscore = 0;
\r
\r
- for (int i = 0; i < (noseqs - 1); i++) {
\r
- for (int j = i; j < noseqs; j++) {
\r
+ for (int i = 0; i < (noseqs - 1); i++)
\r
+ {
\r
+ for (int j = i; j < noseqs; j++)
\r
+ {
\r
int score = 0;
\r
\r
int score = 0;
\r
\r
- for (int k = start; k < end; k++) {
\r
- try {
\r
+ for (int k = start; k < end; k++)
\r
+ {
\r
+ try
\r
+ {
\r
score += ResidueProperties.getBLOSUM62(sequence[i].getSequence(
\r
k, k + 1), sequence[j].getSequence(k, k +
\r
1));
\r
score += ResidueProperties.getBLOSUM62(sequence[i].getSequence(
\r
k, k + 1), sequence[j].getSequence(k, k +
\r
1));
\r
- } catch (Exception ex) {
\r
+ }
\r
+ catch (Exception ex)
\r
+ {
\r
System.err.println("err creating BLOSUM62 tree");
\r
ex.printStackTrace();
\r
}
\r
System.err.println("err creating BLOSUM62 tree");
\r
ex.printStackTrace();
\r
}
\r
@@
-451,37
+638,47
@@
public class NJTree {
\r
distance[i][j] = (float) score;
\r
\r
\r
distance[i][j] = (float) score;
\r
\r
- if (score > maxscore) {
\r
+ if (score > maxscore)
\r
+ {
\r
maxscore = score;
\r
}
\r
}
\r
}
\r
\r
maxscore = score;
\r
}
\r
}
\r
}
\r
\r
- for (int i = 0; i < (noseqs - 1); i++) {
\r
- for (int j = i; j < noseqs; j++) {
\r
+ for (int i = 0; i < (noseqs - 1); i++)
\r
+ {
\r
+ for (int j = i; j < noseqs; j++)
\r
+ {
\r
distance[i][j] = (float) maxscore - distance[i][j];
\r
distance[j][i] = distance[i][j];
\r
}
\r
}
\r
distance[i][j] = (float) maxscore - distance[i][j];
\r
distance[j][i] = distance[i][j];
\r
}
\r
}
\r
- } else if (pwtype.equals("SW")) {
\r
+ }
\r
+ else if (pwtype.equals("SW"))
\r
+ {
\r
float max = -1;
\r
\r
float max = -1;
\r
\r
- for (int i = 0; i < (noseqs - 1); i++) {
\r
- for (int j = i; j < noseqs; j++) {
\r
+ for (int i = 0; i < (noseqs - 1); i++)
\r
+ {
\r
+ for (int j = i; j < noseqs; j++)
\r
+ {
\r
AlignSeq as = new AlignSeq(sequence[i], sequence[j], "pep");
\r
as.calcScoreMatrix();
\r
as.traceAlignment();
\r
as.printAlignment();
\r
distance[i][j] = (float) as.maxscore;
\r
\r
AlignSeq as = new AlignSeq(sequence[i], sequence[j], "pep");
\r
as.calcScoreMatrix();
\r
as.traceAlignment();
\r
as.printAlignment();
\r
distance[i][j] = (float) as.maxscore;
\r
\r
- if (max < distance[i][j]) {
\r
+ if (max < distance[i][j])
\r
+ {
\r
max = distance[i][j];
\r
}
\r
}
\r
}
\r
\r
max = distance[i][j];
\r
}
\r
}
\r
}
\r
\r
- for (int i = 0; i < (noseqs - 1); i++) {
\r
- for (int j = i; j < noseqs; j++) {
\r
+ for (int i = 0; i < (noseqs - 1); i++)
\r
+ {
\r
+ for (int j = i; j < noseqs; j++)
\r
+ {
\r
distance[i][j] = max - distance[i][j];
\r
distance[j][i] = distance[i][j];
\r
}
\r
distance[i][j] = max - distance[i][j];
\r
distance[j][i] = distance[i][j];
\r
}
\r
@@
-491,10
+688,15
@@
public class NJTree {
return distance;
\r
}
\r
\r
return distance;
\r
}
\r
\r
- public void makeLeaves() {
\r
+ /**
\r
+ * DOCUMENT ME!
\r
+ */
\r
+ public void makeLeaves()
\r
+ {
\r
cluster = new Vector();
\r
\r
cluster = new Vector();
\r
\r
- for (int i = 0; i < noseqs; i++) {
\r
+ for (int i = 0; i < noseqs; i++)
\r
+ {
\r
SequenceNode sn = new SequenceNode();
\r
\r
sn.setElement(sequence[i]);
\r
SequenceNode sn = new SequenceNode();
\r
\r
sn.setElement(sequence[i]);
\r
@@
-509,16
+711,29
@@
public class NJTree {
}
\r
}
\r
\r
}
\r
}
\r
\r
- public Vector findLeaves(SequenceNode node, Vector leaves) {
\r
- if (node == null) {
\r
+ /**
\r
+ * DOCUMENT ME!
\r
+ *
\r
+ * @param node DOCUMENT ME!
\r
+ * @param leaves DOCUMENT ME!
\r
+ *
\r
+ * @return DOCUMENT ME!
\r
+ */
\r
+ public Vector findLeaves(SequenceNode node, Vector leaves)
\r
+ {
\r
+ if (node == null)
\r
+ {
\r
return leaves;
\r
}
\r
\r
return leaves;
\r
}
\r
\r
- if ((node.left() == null) && (node.right() == null)) {
\r
+ if ((node.left() == null) && (node.right() == null))
\r
+ {
\r
leaves.addElement(node);
\r
\r
return leaves;
\r
leaves.addElement(node);
\r
\r
return leaves;
\r
- } else {
\r
+ }
\r
+ else
\r
+ {
\r
findLeaves((SequenceNode) node.left(), leaves);
\r
findLeaves((SequenceNode) node.right(), leaves);
\r
}
\r
findLeaves((SequenceNode) node.left(), leaves);
\r
findLeaves((SequenceNode) node.right(), leaves);
\r
}
\r
@@
-526,22
+741,44
@@
public class NJTree {
return leaves;
\r
}
\r
\r
return leaves;
\r
}
\r
\r
- public Object findLeaf(SequenceNode node, int count) {
\r
+ /**
\r
+ * DOCUMENT ME!
\r
+ *
\r
+ * @param node DOCUMENT ME!
\r
+ * @param count DOCUMENT ME!
\r
+ *
\r
+ * @return DOCUMENT ME!
\r
+ */
\r
+ public Object findLeaf(SequenceNode node, int count)
\r
+ {
\r
found = _findLeaf(node, count);
\r
\r
return found;
\r
}
\r
\r
found = _findLeaf(node, count);
\r
\r
return found;
\r
}
\r
\r
- public Object _findLeaf(SequenceNode node, int count) {
\r
- if (node == null) {
\r
+ /**
\r
+ * DOCUMENT ME!
\r
+ *
\r
+ * @param node DOCUMENT ME!
\r
+ * @param count DOCUMENT ME!
\r
+ *
\r
+ * @return DOCUMENT ME!
\r
+ */
\r
+ public Object _findLeaf(SequenceNode node, int count)
\r
+ {
\r
+ if (node == null)
\r
+ {
\r
return null;
\r
}
\r
\r
return null;
\r
}
\r
\r
- if (node.ycount == count) {
\r
+ if (node.ycount == count)
\r
+ {
\r
found = node.element();
\r
\r
return found;
\r
found = node.element();
\r
\r
return found;
\r
- } else {
\r
+ }
\r
+ else
\r
+ {
\r
_findLeaf((SequenceNode) node.left(), count);
\r
_findLeaf((SequenceNode) node.right(), count);
\r
}
\r
_findLeaf((SequenceNode) node.left(), count);
\r
_findLeaf((SequenceNode) node.right(), count);
\r
}
\r
@@
-554,80
+791,137
@@
public class NJTree {
*
\r
* @param node SequenceNode
\r
*/
\r
*
\r
* @param node SequenceNode
\r
*/
\r
- public void printNode(SequenceNode node) {
\r
- if (node == null) {
\r
+ public void printNode(SequenceNode node)
\r
+ {
\r
+ if (node == null)
\r
+ {
\r
return;
\r
}
\r
\r
return;
\r
}
\r
\r
- if ((node.left() == null) && (node.right() == null)) {
\r
+ if ((node.left() == null) && (node.right() == null))
\r
+ {
\r
System.out.println("Leaf = " +
\r
((SequenceI) node.element()).getName());
\r
System.out.println("Dist " + ((SequenceNode) node).dist);
\r
System.out.println("Boot " + node.getBootstrap());
\r
System.out.println("Leaf = " +
\r
((SequenceI) node.element()).getName());
\r
System.out.println("Dist " + ((SequenceNode) node).dist);
\r
System.out.println("Boot " + node.getBootstrap());
\r
- } else {
\r
+ }
\r
+ else
\r
+ {
\r
System.out.println("Dist " + ((SequenceNode) node).dist);
\r
printNode((SequenceNode) node.left());
\r
printNode((SequenceNode) node.right());
\r
}
\r
}
\r
\r
System.out.println("Dist " + ((SequenceNode) node).dist);
\r
printNode((SequenceNode) node.left());
\r
printNode((SequenceNode) node.right());
\r
}
\r
}
\r
\r
- public void findMaxDist(SequenceNode node) {
\r
- if (node == null) {
\r
+ /**
\r
+ * DOCUMENT ME!
\r
+ *
\r
+ * @param node DOCUMENT ME!
\r
+ */
\r
+ public void findMaxDist(SequenceNode node)
\r
+ {
\r
+ if (node == null)
\r
+ {
\r
return;
\r
}
\r
\r
return;
\r
}
\r
\r
- if ((node.left() == null) && (node.right() == null)) {
\r
+ if ((node.left() == null) && (node.right() == null))
\r
+ {
\r
float dist = ((SequenceNode) node).dist;
\r
\r
float dist = ((SequenceNode) node).dist;
\r
\r
- if (dist > maxDistValue) {
\r
+ if (dist > maxDistValue)
\r
+ {
\r
maxdist = (SequenceNode) node;
\r
maxDistValue = dist;
\r
}
\r
maxdist = (SequenceNode) node;
\r
maxDistValue = dist;
\r
}
\r
- } else {
\r
+ }
\r
+ else
\r
+ {
\r
findMaxDist((SequenceNode) node.left());
\r
findMaxDist((SequenceNode) node.right());
\r
}
\r
}
\r
\r
findMaxDist((SequenceNode) node.left());
\r
findMaxDist((SequenceNode) node.right());
\r
}
\r
}
\r
\r
- public Vector getGroups() {
\r
+ /**
\r
+ * DOCUMENT ME!
\r
+ *
\r
+ * @return DOCUMENT ME!
\r
+ */
\r
+ public Vector getGroups()
\r
+ {
\r
return groups;
\r
}
\r
\r
return groups;
\r
}
\r
\r
- public float getMaxHeight() {
\r
+ /**
\r
+ * DOCUMENT ME!
\r
+ *
\r
+ * @return DOCUMENT ME!
\r
+ */
\r
+ public float getMaxHeight()
\r
+ {
\r
return maxheight;
\r
}
\r
\r
return maxheight;
\r
}
\r
\r
- public void groupNodes(SequenceNode node, float threshold) {
\r
- if (node == null) {
\r
+ /**
\r
+ * DOCUMENT ME!
\r
+ *
\r
+ * @param node DOCUMENT ME!
\r
+ * @param threshold DOCUMENT ME!
\r
+ */
\r
+ public void groupNodes(SequenceNode node, float threshold)
\r
+ {
\r
+ if (node == null)
\r
+ {
\r
return;
\r
}
\r
\r
return;
\r
}
\r
\r
- if ((node.height / maxheight) > threshold) {
\r
+ if ((node.height / maxheight) > threshold)
\r
+ {
\r
groups.addElement(node);
\r
groups.addElement(node);
\r
- } else {
\r
+ }
\r
+ else
\r
+ {
\r
groupNodes((SequenceNode) node.left(), threshold);
\r
groupNodes((SequenceNode) node.right(), threshold);
\r
}
\r
}
\r
\r
groupNodes((SequenceNode) node.left(), threshold);
\r
groupNodes((SequenceNode) node.right(), threshold);
\r
}
\r
}
\r
\r
- public float findHeight(SequenceNode node) {
\r
- if (node == null) {
\r
+ /**
\r
+ * DOCUMENT ME!
\r
+ *
\r
+ * @param node DOCUMENT ME!
\r
+ *
\r
+ * @return DOCUMENT ME!
\r
+ */
\r
+ public float findHeight(SequenceNode node)
\r
+ {
\r
+ if (node == null)
\r
+ {
\r
return maxheight;
\r
}
\r
\r
return maxheight;
\r
}
\r
\r
- if ((node.left() == null) && (node.right() == null)) {
\r
+ if ((node.left() == null) && (node.right() == null))
\r
+ {
\r
node.height = ((SequenceNode) node.parent()).height + node.dist;
\r
\r
node.height = ((SequenceNode) node.parent()).height + node.dist;
\r
\r
- if (node.height > maxheight) {
\r
+ if (node.height > maxheight)
\r
+ {
\r
return node.height;
\r
return node.height;
\r
- } else {
\r
+ }
\r
+ else
\r
+ {
\r
return maxheight;
\r
}
\r
return maxheight;
\r
}
\r
- } else {
\r
- if (node.parent() != null) {
\r
+ }
\r
+ else
\r
+ {
\r
+ if (node.parent() != null)
\r
+ {
\r
node.height = ((SequenceNode) node.parent()).height +
\r
node.dist;
\r
node.height = ((SequenceNode) node.parent()).height +
\r
node.dist;
\r
- } else {
\r
+ }
\r
+ else
\r
+ {
\r
maxheight = 0;
\r
node.height = (float) 0.0;
\r
}
\r
maxheight = 0;
\r
node.height = (float) 0.0;
\r
}
\r
@@
-639,8
+933,15
@@
public class NJTree {
return maxheight;
\r
}
\r
\r
return maxheight;
\r
}
\r
\r
- public SequenceNode reRoot() {
\r
- if (maxdist != null) {
\r
+ /**
\r
+ * DOCUMENT ME!
\r
+ *
\r
+ * @return DOCUMENT ME!
\r
+ */
\r
+ public SequenceNode reRoot()
\r
+ {
\r
+ if (maxdist != null)
\r
+ {
\r
ycount = 0;
\r
\r
float tmpdist = maxdist.dist;
\r
ycount = 0;
\r
\r
float tmpdist = maxdist.dist;
\r
@@
-673,15
+974,25
@@
public class NJTree {
return top;
\r
}
\r
\r
return top;
\r
}
\r
\r
- public static void printN(SequenceNode node) {
\r
- if (node == null) {
\r
+ /**
\r
+ * DOCUMENT ME!
\r
+ *
\r
+ * @param node DOCUMENT ME!
\r
+ */
\r
+ public static void printN(SequenceNode node)
\r
+ {
\r
+ if (node == null)
\r
+ {
\r
return;
\r
}
\r
\r
return;
\r
}
\r
\r
- if ((node.left() != null) && (node.right() != null)) {
\r
+ if ((node.left() != null) && (node.right() != null))
\r
+ {
\r
printN((SequenceNode) node.left());
\r
printN((SequenceNode) node.right());
\r
printN((SequenceNode) node.left());
\r
printN((SequenceNode) node.right());
\r
- } else {
\r
+ }
\r
+ else
\r
+ {
\r
System.out.println(" name = " +
\r
((SequenceI) node.element()).getName());
\r
}
\r
System.out.println(" name = " +
\r
((SequenceI) node.element()).getName());
\r
}
\r
@@
-690,17
+1001,31
@@
public class NJTree {
((SequenceNode) node).count + " " + ((SequenceNode) node).height);
\r
}
\r
\r
((SequenceNode) node).count + " " + ((SequenceNode) node).height);
\r
}
\r
\r
- public void reCount(SequenceNode node) {
\r
+ /**
\r
+ * DOCUMENT ME!
\r
+ *
\r
+ * @param node DOCUMENT ME!
\r
+ */
\r
+ public void reCount(SequenceNode node)
\r
+ {
\r
ycount = 0;
\r
_reCount(node);
\r
}
\r
\r
ycount = 0;
\r
_reCount(node);
\r
}
\r
\r
- public void _reCount(SequenceNode node) {
\r
- if (node == null) {
\r
+ /**
\r
+ * DOCUMENT ME!
\r
+ *
\r
+ * @param node DOCUMENT ME!
\r
+ */
\r
+ public void _reCount(SequenceNode node)
\r
+ {
\r
+ if (node == null)
\r
+ {
\r
return;
\r
}
\r
\r
return;
\r
}
\r
\r
- if ((node.left() != null) && (node.right() != null)) {
\r
+ if ((node.left() != null) && (node.right() != null))
\r
+ {
\r
_reCount((SequenceNode) node.left());
\r
_reCount((SequenceNode) node.right());
\r
\r
_reCount((SequenceNode) node.left());
\r
_reCount((SequenceNode) node.right());
\r
\r
@@
-709,14
+1034,23
@@
public class NJTree {
\r
((SequenceNode) node).count = l.count + r.count;
\r
((SequenceNode) node).ycount = (l.ycount + r.ycount) / 2;
\r
\r
((SequenceNode) node).count = l.count + r.count;
\r
((SequenceNode) node).ycount = (l.ycount + r.ycount) / 2;
\r
- } else {
\r
+ }
\r
+ else
\r
+ {
\r
((SequenceNode) node).count = 1;
\r
((SequenceNode) node).ycount = ycount++;
\r
}
\r
}
\r
\r
((SequenceNode) node).count = 1;
\r
((SequenceNode) node).ycount = ycount++;
\r
}
\r
}
\r
\r
- public void swapNodes(SequenceNode node) {
\r
- if (node == null) {
\r
+ /**
\r
+ * DOCUMENT ME!
\r
+ *
\r
+ * @param node DOCUMENT ME!
\r
+ */
\r
+ public void swapNodes(SequenceNode node)
\r
+ {
\r
+ if (node == null)
\r
+ {
\r
return;
\r
}
\r
\r
return;
\r
}
\r
\r
@@
-726,62
+1060,116
@@
public class NJTree {
node.setRight(tmp);
\r
}
\r
\r
node.setRight(tmp);
\r
}
\r
\r
- public void changeDirection(SequenceNode node, SequenceNode dir) {
\r
- if (node == null) {
\r
+ /**
\r
+ * DOCUMENT ME!
\r
+ *
\r
+ * @param node DOCUMENT ME!
\r
+ * @param dir DOCUMENT ME!
\r
+ */
\r
+ public void changeDirection(SequenceNode node, SequenceNode dir)
\r
+ {
\r
+ if (node == null)
\r
+ {
\r
return;
\r
}
\r
\r
return;
\r
}
\r
\r
- if (node.parent() != top) {
\r
+ if (node.parent() != top)
\r
+ {
\r
changeDirection((SequenceNode) node.parent(), node);
\r
\r
SequenceNode tmp = (SequenceNode) node.parent();
\r
\r
changeDirection((SequenceNode) node.parent(), node);
\r
\r
SequenceNode tmp = (SequenceNode) node.parent();
\r
\r
- if (dir == node.left()) {
\r
+ if (dir == node.left())
\r
+ {
\r
node.setParent(dir);
\r
node.setLeft(tmp);
\r
node.setParent(dir);
\r
node.setLeft(tmp);
\r
- } else if (dir == node.right()) {
\r
+ }
\r
+ else if (dir == node.right())
\r
+ {
\r
node.setParent(dir);
\r
node.setRight(tmp);
\r
}
\r
node.setParent(dir);
\r
node.setRight(tmp);
\r
}
\r
- } else {
\r
- if (dir == node.left()) {
\r
+ }
\r
+ else
\r
+ {
\r
+ if (dir == node.left())
\r
+ {
\r
node.setParent(node.left());
\r
\r
node.setParent(node.left());
\r
\r
- if (top.left() == node) {
\r
+ if (top.left() == node)
\r
+ {
\r
node.setRight(top.right());
\r
node.setRight(top.right());
\r
- } else {
\r
+ }
\r
+ else
\r
+ {
\r
node.setRight(top.left());
\r
}
\r
node.setRight(top.left());
\r
}
\r
- } else {
\r
+ }
\r
+ else
\r
+ {
\r
node.setParent(node.right());
\r
\r
node.setParent(node.right());
\r
\r
- if (top.left() == node) {
\r
+ if (top.left() == node)
\r
+ {
\r
node.setLeft(top.right());
\r
node.setLeft(top.right());
\r
- } else {
\r
+ }
\r
+ else
\r
+ {
\r
node.setLeft(top.left());
\r
}
\r
}
\r
}
\r
}
\r
\r
node.setLeft(top.left());
\r
}
\r
}
\r
}
\r
}
\r
\r
- public void setMaxDist(SequenceNode node) {
\r
+ /**
\r
+ * DOCUMENT ME!
\r
+ *
\r
+ * @param node DOCUMENT ME!
\r
+ */
\r
+ public void setMaxDist(SequenceNode node)
\r
+ {
\r
this.maxdist = maxdist;
\r
}
\r
\r
this.maxdist = maxdist;
\r
}
\r
\r
- public SequenceNode getMaxDist() {
\r
+ /**
\r
+ * DOCUMENT ME!
\r
+ *
\r
+ * @return DOCUMENT ME!
\r
+ */
\r
+ public SequenceNode getMaxDist()
\r
+ {
\r
return maxdist;
\r
}
\r
\r
return maxdist;
\r
}
\r
\r
- public SequenceNode getTopNode() {
\r
+ /**
\r
+ * DOCUMENT ME!
\r
+ *
\r
+ * @return DOCUMENT ME!
\r
+ */
\r
+ public SequenceNode getTopNode()
\r
+ {
\r
return top;
\r
}
\r
}
\r
\r
\r
return top;
\r
}
\r
}
\r
\r
\r
-class Cluster {
\r
+/**
\r
+ * DOCUMENT ME!
\r
+ *
\r
+ * @author $author$
\r
+ * @version $Revision$
\r
+ */
\r
+class Cluster
\r
+{
\r
int[] value;
\r
\r
int[] value;
\r
\r
- public Cluster(int[] value) {
\r
+ /**
\r
+ * Creates a new Cluster object.
\r
+ *
\r
+ * @param value DOCUMENT ME!
\r
+ */
\r
+ public Cluster(int[] value)
\r
+ {
\r
this.value = value;
\r
}
\r
}
\r
this.value = value;
\r
}
\r
}
\r