JAL-250 save the less redundant neighbour for each sequence
authorJim Procter <jprocter@issues.jalview.org>
Mon, 28 Mar 2016 15:48:10 +0000 (16:48 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Tue, 2 Aug 2016 15:24:10 +0000 (16:24 +0100)
src/jalview/analysis/AlignSeq.java

index 369721d..76b8fe9 100755 (executable)
@@ -1201,8 +1201,18 @@ public class AlignSeq
           SequenceI[] originalSequences, String[] omitHidden, int start,
           int end, boolean ungapped)
   {
+    return (float[]) computeRedundancyMatrixWithRep(originalSequences,
+            omitHidden, start, end, ungapped)[0];
+  }
+
+  public static Object[] computeRedundancyMatrixWithRep(
+          SequenceI[] originalSequences, String[] omitHidden, int start,
+          int end, boolean ungapped)
+  {
+
     int height = originalSequences.length;
     float[] redundancy = new float[height];
+    SequenceI[] rep = new SequenceI[height];
     int[] lngth = new int[height];
     for (int i = 0; i < height; i++)
     {
@@ -1257,15 +1267,23 @@ public class AlignSeq
         // use real sequence length rather than string length
         if (lngth[j] < lngth[i])
         {
-          redundancy[j] = Math.max(pid, redundancy[j]);
+          if (pid > redundancy[j])
+          {
+            rep[j] = originalSequences[i];
+            redundancy[j] = pid;
+          }
         }
         else
         {
-          redundancy[i] = Math.max(pid, redundancy[i]);
+          if (pid > redundancy[i])
+          {
+            rep[i] = originalSequences[j];
+            redundancy[i] = pid;
+          }
         }
 
       }
     }
-    return redundancy;
+    return new Object[] { redundancy, rep };
   }
 }