Merge branch 'develop' into spike/JAL-4047/JAL-4048_columns_in_sequenceID
[jalview.git] / src / jalview / analysis / AverageDistanceEngine.java
index e6a763b..d81dd44 100644 (file)
@@ -44,29 +44,31 @@ public class AverageDistanceEngine extends TreeEngine
 
   AlignmentAnnotation aa;
 
+  // 0 - normalised dot product
+  // 1 - L1 - ie (abs(v_1-v_2)/dim(v))
+  // L1 is more rational - since can reason about value of difference,
+  // normalised dot product might give cleaner clusters, but more difficult to
+  // understand.
+
+  int mode = 1;
+
   /**
    * compute cosine distance matrix for a given contact matrix and create a
    * UPGMA tree
-   * 
    * @param cm
+   * @param cosineOrDifference false - dot product : true - L1
    */
   public AverageDistanceEngine(AlignmentViewport av, AlignmentAnnotation aa,
-          ContactMatrixI cm)
+          ContactMatrixI cm, boolean cosineOrDifference)
   {
     this.av = av;
     this.aa = aa;
     this.cm = cm;
+    mode = (cosineOrDifference) ? 1 :0; 
     calculate(cm);
 
   }
 
-  // 0 - normalised dot product
-  // 1 - L1 - ie (abs(v_1-v_2)/dim(v))
-  // L1 is more rational - since can reason about value of difference,
-  // normalised dot product might give cleaner clusters, but more difficult to
-  // understand.
-
-  int mode = 1;
 
   public void calculate(ContactMatrixI cm)
   {
@@ -100,11 +102,18 @@ public class AverageDistanceEngine extends TreeEngine
 
       // compute distance matrix element
       ContactListI ith = cm.getContactList(i);
-
+      distances.setValue(i, i, 0);
+      if (ith==null)
+      {
+        continue;
+      }
       for (int j = 0; j < i; j++)
       {
-        distances.setValue(i, i, 0);
         ContactListI jth = cm.getContactList(j);
+        if (jth == null)
+        {
+          break;
+        }
         double prd = 0;
         for (int indx = 0; indx < cm.getHeight(); indx++)
         {