node;
+ private AlignmentView seqStrings;
/**
* Constructor
@@ -68,7 +58,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;
@@ -79,8 +69,8 @@ public abstract class TreeBuilder
{
start = av.getSelectionGroup().getStartRes();
end = av.getSelectionGroup().getEndRes() + 1;
- this.sequences = av.getSelectionGroup().getSequencesInOrder(
- av.getAlignment());
+ this.sequences = av.getSelectionGroup()
+ .getSequencesInOrder(av.getAlignment());
}
init(seqStrings, start, end);
@@ -94,115 +84,6 @@ public abstract class TreeBuilder
}
/**
- * DOCUMENT ME!
- *
- * @param nd
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- double findHeight(SequenceNode nd)
- {
- if (nd == null)
- {
- return maxheight;
- }
-
- if ((nd.left() == null) && (nd.right() == null))
- {
- nd.height = ((SequenceNode) nd.parent()).height + nd.dist;
-
- if (nd.height > maxheight)
- {
- return nd.height;
- }
- else
- {
- return maxheight;
- }
- }
- else
- {
- if (nd.parent() != null)
- {
- nd.height = ((SequenceNode) nd.parent()).height + nd.dist;
- }
- else
- {
- maxheight = 0;
- nd.height = (float) 0.0;
- }
-
- maxheight = findHeight((SequenceNode) (nd.left()));
- maxheight = findHeight((SequenceNode) (nd.right()));
- }
-
- return maxheight;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param nd
- * DOCUMENT ME!
- */
- void reCount(SequenceNode nd)
- {
- ycount = 0;
- // _lycount = 0;
- // _lylimit = this.node.size();
- _reCount(nd);
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param nd
- * DOCUMENT ME!
- */
- void _reCount(SequenceNode nd)
- {
- // if (_lycount<_lylimit)
- // {
- // System.err.println("Warning: depth of _recount greater than number of nodes.");
- // }
- if (nd == null)
- {
- return;
- }
- // _lycount++;
-
- if ((nd.left() != null) && (nd.right() != null))
- {
-
- _reCount((SequenceNode) nd.left());
- _reCount((SequenceNode) nd.right());
-
- SequenceNode l = (SequenceNode) nd.left();
- SequenceNode r = (SequenceNode) nd.right();
-
- nd.count = l.count + r.count;
- nd.ycount = (l.ycount + r.ycount) / 2;
- }
- else
- {
- nd.count = 1;
- nd.ycount = ycount++;
- }
- // _lycount--;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public SequenceNode getTopNode()
- {
- return top;
- }
-
- /**
*
* @return true if tree has real distances
*/
@@ -226,34 +107,6 @@ public abstract class TreeBuilder
}
/**
- * Form clusters by grouping sub-clusters, starting from one sequence per
- * cluster, and finishing when only two clusters remain
- */
- void cluster()
- {
- while (noClus > 2)
- {
- findMinDistance();
-
- joinClusters(mini, minj);
-
- noClus--;
- }
-
- int rightChild = done.nextClearBit(0);
- int leftChild = done.nextClearBit(rightChild + 1);
-
- joinClusters(leftChild, rightChild);
- top = (node.elementAt(leftChild));
-
- reCount(top);
- findHeight(top);
- findMaxDist(top);
- }
-
- protected abstract double findMinDistance();
-
- /**
* Calculates the tree using the given score model and parameters, and the
* configured tree type
*
@@ -268,92 +121,18 @@ 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();
-
- noClus = clusters.size();
-
- cluster();
- }
- /**
- * DOCUMENT ME!
- *
- * @param nd
- * DOCUMENT ME!
- */
- void findMaxDist(SequenceNode nd)
- {
- if (nd == null)
- {
- return;
- }
-
- if ((nd.left() == null) && (nd.right() == null))
- {
- double dist = nd.dist;
-
- if (dist > maxDistValue)
- {
- maxdist = nd;
- maxDistValue = dist;
- }
- }
- else
- {
- findMaxDist((SequenceNode) nd.left());
- findMaxDist((SequenceNode) nd.right());
- }
- }
+ noClus = clusters.size();
- /**
- * DOCUMENT ME!
- *
- * @param i
- * DOCUMENT ME!
- * @param j
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- protected double findr(int i, int j)
- {
- double tmp = 1;
-
- for (int k = 0; k < noseqs; k++)
- {
- if ((k != i) && (k != j) && (!done.get(k)))
- {
- tmp = tmp + distances.getValue(i, k);
- }
- }
-
- if (noClus > 2)
- {
- tmp = tmp / (noClus - 2);
- }
-
- return tmp;
+ cluster();
}
protected void init(AlignmentView seqView, int start, int end)
{
- this.node = new Vector();
+ this.node = new Vector();
if (seqView != null)
{
this.seqData = seqView;
@@ -369,14 +148,14 @@ public abstract class TreeBuilder
sdata.addOperation(CigarArray.M, end - start + 1);
this.seqData = new AlignmentView(sdata, start);
}
-
+
/*
* count the non-null sequences
*/
noseqs = 0;
-
+
done = new BitSet();
-
+
for (SequenceI seq : sequences)
{
if (seq != null)
@@ -387,71 +166,16 @@ public abstract class TreeBuilder
}
/**
- * Merges cluster(j) to cluster(i) and recalculates cluster and node distances
- *
- * @param i
- * @param j
- */
- void joinClusters(final int i, final int j)
- {
- 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);
-
- findClusterDistance(i, j);
-
- SequenceNode sn = new SequenceNode();
-
- sn.setLeft((node.elementAt(i)));
- sn.setRight((node.elementAt(j)));
-
- SequenceNode tmpi = (node.elementAt(i));
- SequenceNode tmpj = (node.elementAt(j));
-
- findNewDistances(tmpi, tmpj, dist);
-
- tmpi.setParent(sn);
- tmpj.setParent(sn);
-
- node.setElementAt(sn, i);
-
- /*
- * mark cluster j as disposed of
- */
- done.set(j);
- clusters.setElementAt(null, j);
- }
-
- protected abstract void findNewDistances(SequenceNode tmpi, SequenceNode tmpj,
- double dist);
-
- /**
- * Calculates and saves the distance between the combination of cluster(i) and
- * cluster(j) and all other clusters. The form of the calculation depends on
- * the tree clustering method being used.
- *
- * @param i
- * @param j
- */
- protected abstract void findClusterDistance(int i, int j);
-
- /**
* Start by making a cluster for each individual sequence
*/
void makeLeaves()
{
clusters = new Vector();
-
+
for (int i = 0; i < noseqs; i++)
{
SequenceNode sn = new SequenceNode();
-
+
sn.setElement(sequences[i]);
sn.setName(sequences[i].getName());
node.addElement(sn);
@@ -461,4 +185,9 @@ public abstract class TreeBuilder
}
}
+ public AlignmentView getOriginalData()
+ {
+ return seqStrings;
+ }
+
}