JAL-2403 ScoreModelI now DistanceModelI, ScoreMatrix delegate of
[jalview.git] / src / jalview / analysis / NJTree.java
index e0e50fb..7140867 100644 (file)
@@ -20,7 +20,8 @@
  */
 package jalview.analysis;
 
-import jalview.api.analysis.ScoreModelI;
+import jalview.analysis.scoremodels.ScoreModels;
+import jalview.api.analysis.DistanceModelI;
 import jalview.datamodel.AlignmentView;
 import jalview.datamodel.BinaryNode;
 import jalview.datamodel.CigarArray;
@@ -30,7 +31,6 @@ import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceI;
 import jalview.datamodel.SequenceNode;
 import jalview.io.NewickFile;
-import jalview.schemes.ResidueProperties;
 
 import java.util.Enumeration;
 import java.util.List;
@@ -44,6 +44,15 @@ import java.util.Vector;
  */
 public class NJTree
 {
+  /*
+   * 'methods'
+   */
+  public static final String AVERAGE_DISTANCE = "AV";
+
+  public static final String NEIGHBOUR_JOINING = "NJ";
+
+  public static final String FROM_FILE = "FromFile";
+
   Vector<Cluster> cluster;
 
   SequenceI[] sequence;
@@ -215,7 +224,7 @@ public class NJTree
    *          DOCUMENT ME!
    */
   public NJTree(SequenceI[] sequence, AlignmentView seqData, String type,
-          String pwtype, ScoreModelI sm, int start, int end)
+          String pwtype, DistanceModelI sm, int start, int end)
   {
     this.sequence = sequence;
     this.node = new Vector<SequenceNode>();
@@ -237,14 +246,14 @@ public class NJTree
       this.seqData = new AlignmentView(sdata, start);
     }
     // System.err.println("Made seqData");// dbg
-    if (!(type.equals("NJ")))
+    if (!(type.equals(NEIGHBOUR_JOINING)))
     {
-      type = "AV";
+      type = AVERAGE_DISTANCE;
     }
 
     if (sm == null && !(pwtype.equals("PID")))
     {
-      if (ResidueProperties.getScoreMatrix(pwtype) == null)
+      if (ScoreModels.getInstance().forName(pwtype) == null)
       {
         pwtype = "BLOSUM62";
       }
@@ -384,7 +393,7 @@ public class NJTree
   {
     while (noClus > 2)
     {
-      if (type.equals("NJ"))
+      if (type.equals(NEIGHBOUR_JOINING))
       {
         findMinNJDistance();
       }
@@ -466,7 +475,7 @@ public class NJTree
     ri = findr(i, j);
     rj = findr(j, i);
 
-    if (type.equals("NJ"))
+    if (type.equals(NEIGHBOUR_JOINING))
     {
       findClusterNJDistance(i, j);
     }
@@ -483,7 +492,7 @@ public class NJTree
     SequenceNode tmpi = (node.elementAt(i));
     SequenceNode tmpj = (node.elementAt(j));
 
-    if (type.equals("NJ"))
+    if (type.equals(NEIGHBOUR_JOINING))
     {
       findNewNJDistances(tmpi, tmpj, dist);
     }
@@ -727,17 +736,17 @@ public class NJTree
    * 
    * @return similarity matrix used to compute tree
    */
-  public float[][] findDistances(ScoreModelI _pwmatrix)
+  public float[][] findDistances(DistanceModelI _pwmatrix)
   {
 
     float[][] dist = new float[noseqs][noseqs];
     if (_pwmatrix == null)
     {
       // Resolve substitution model
-      _pwmatrix = ResidueProperties.getScoreModel(pwtype);
+      _pwmatrix = ScoreModels.getInstance().forName(pwtype);
       if (_pwmatrix == null)
       {
-        _pwmatrix = ResidueProperties.getScoreMatrix("BLOSUM62");
+        _pwmatrix = ScoreModels.getInstance().forName("BLOSUM62");
       }
     }
     dist = _pwmatrix.findDistances(seqData);