JAL-1483 refactor NJTree constructor to allow preconfigured scoremodel to be passed...
[jalview.git] / src / jalview / analysis / NJTree.java
index ec5b79b..f08a436 100644 (file)
@@ -218,7 +218,7 @@ public class NJTree
    *          DOCUMENT ME!
    */
   public NJTree(SequenceI[] sequence, AlignmentView seqData, String type,
-          String pwtype, int start, int end)
+          String pwtype, ScoreModelI sm, int start, int end)
   {
     this.sequence = sequence;
     this.node = new Vector();
@@ -245,7 +245,7 @@ public class NJTree
       type = "AV";
     }
 
-    if (!(pwtype.equals("PID")))
+    if (sm == null && !(pwtype.equals("PID")))
     {
       if (ResidueProperties.getScoreMatrix(pwtype) == null)
       {
@@ -265,7 +265,7 @@ public class NJTree
 
     noseqs = i++;
 
-    distance = findDistances();
+    distance = findDistances(sm);
     // System.err.println("Made distances");// dbg
     makeLeaves();
     // System.err.println("Made leaves");// dbg
@@ -323,7 +323,7 @@ public class NJTree
 
           for (int j = 0; j < seqs.length; j++)
           {
-            seqs[j] = (SequenceI) list.get(j);
+            seqs[j] = list.get(j);
           }
 
           seqmatcher = new SequenceIdMatcher(seqs);
@@ -730,16 +730,18 @@ public class NJTree
    * 
    * @return similarity matrix used to compute tree
    */
-  public float[][] findDistances()
+  public float[][] findDistances(ScoreModelI _pwmatrix)
   {
 
     float[][] distance = new float[noseqs][noseqs];
-
-    // Pairwise substitution score (with no gap penalties)
-    ScoreModelI _pwmatrix = ResidueProperties.getScoreModel(pwtype);
     if (_pwmatrix == null)
     {
-      _pwmatrix = ResidueProperties.getScoreMatrix("BLOSUM62");
+      // Resolve substitution model
+      _pwmatrix = ResidueProperties.getScoreModel(pwtype);
+      if (_pwmatrix == null)
+      {
+        _pwmatrix = ResidueProperties.getScoreMatrix("BLOSUM62");
+      }
     }
     distance = _pwmatrix.findDistances(seqData);
     return distance;