Merge branch 'kjvdh/features/PhylogenyViewer_tabbedsupport' into merge/2_11_2/kjvdh...
[jalview.git] / src / jalview / analysis / TreeBuilder.java
index b290428..c4a94eb 100644 (file)
@@ -1,3 +1,23 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ * 
+ * This file is part of Jalview.
+ * 
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License 
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *  
+ * Jalview is distributed in the hope that it will be useful, but 
+ * WITHOUT ANY WARRANTY; without even the implied warranty 
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+ * PURPOSE.  See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
 package jalview.analysis;
 
 import jalview.api.analysis.ScoreModelI;
@@ -47,13 +67,19 @@ public abstract class TreeBuilder
 
   double maxDistValue;
 
-  double maxheight;
+  double maxHeight;
 
   int ycount;
 
   Vector<SequenceNode> node;
 
-  private AlignmentView seqStrings;
+  protected ScoreModelI scoreModel;
+
+  protected SimilarityParamsI scoreParams;
+
+  private AlignmentViewport avport;
+
+  private AlignmentView seqStrings; // redundant? (see seqData)
 
   /**
    * Constructor
@@ -66,6 +92,7 @@ public abstract class TreeBuilder
           SimilarityParamsI scoreParameters)
   {
     int start, end;
+    avport = av;
     boolean selview = av.getSelectionGroup() != null
             && av.getSelectionGroup().getSize() > 1;
     seqStrings = av.getAlignmentView(selview);
@@ -105,20 +132,20 @@ public abstract class TreeBuilder
   {
     if (nd == null)
     {
-      return maxheight;
+      return maxHeight;
     }
 
     if ((nd.left() == null) && (nd.right() == null))
     {
       nd.height = ((SequenceNode) nd.parent()).height + nd.dist;
 
-      if (nd.height > maxheight)
+      if (nd.height > maxHeight)
       {
         return nd.height;
       }
       else
       {
-        return maxheight;
+        return maxHeight;
       }
     }
     else
@@ -129,15 +156,15 @@ public abstract class TreeBuilder
       }
       else
       {
-        maxheight = 0;
+        maxHeight = 0;
         nd.height = (float) 0.0;
       }
 
-      maxheight = findHeight((SequenceNode) (nd.left()));
-      maxheight = findHeight((SequenceNode) (nd.right()));
+      maxHeight = findHeight((SequenceNode) (nd.left()));
+      maxHeight = findHeight((SequenceNode) (nd.right()));
     }
 
-    return maxheight;
+    return maxHeight;
   }
 
   /**
@@ -275,7 +302,11 @@ public abstract class TreeBuilder
    */
   protected void computeTree(ScoreModelI sm, SimilarityParamsI scoreOptions)
   {
-    distances = sm.findDistances(seqData, scoreOptions);
+
+    this.scoreModel = sm;
+    this.scoreParams = scoreOptions;
+
+    distances = scoreModel.findDistances(seqData, scoreParams);
 
     makeLeaves();
 
@@ -344,7 +375,7 @@ public abstract class TreeBuilder
 
   protected void init(AlignmentView seqView, int start, int end)
   {
-    this.node = new Vector<SequenceNode>();
+    this.node = new Vector<>();
     if (seqView != null)
     {
       this.seqData = seqView;
@@ -438,7 +469,7 @@ public abstract class TreeBuilder
    */
   void makeLeaves()
   {
-    clusters = new Vector<BitSet>();
+    clusters = new Vector<>();
 
     for (int i = 0; i < noseqs; i++)
     {
@@ -447,6 +478,7 @@ public abstract class TreeBuilder
       sn.setElement(sequences[i]);
       sn.setName(sequences[i].getName());
       node.addElement(sn);
+
       BitSet bs = new BitSet();
       bs.set(i);
       clusters.addElement(bs);
@@ -458,4 +490,24 @@ public abstract class TreeBuilder
     return seqStrings;
   }
 
+  public MatrixI getDistances()
+  {
+    return distances;
+  }
+
+  public ScoreModelI getScoreModel()
+  {
+    return scoreModel;
+  }
+
+  public SimilarityParamsI getScoreParams()
+  {
+    return scoreParams;
+  }
+
+  public AlignmentViewport getAvport()
+  {
+    return avport;
+  }
+
 }