JAL-2805 loads of file reorganizing, interfaces expanded
[jalview.git] / src / jalview / ext / forester / ForesterMatrix.java
index 92e88c8..a12dc1d 100644 (file)
@@ -1,6 +1,6 @@
 package jalview.ext.forester;
 
-import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceI;
 import jalview.math.MatrixI;
 import jalview.util.MessageManager;
 
@@ -22,20 +22,16 @@ public class ForesterMatrix implements DistanceMatrix
 
   private final MatrixI jalviewMatrix;
 
-  private Sequence[] sequences;
-
   private final String[] identifiers;
 
   public ForesterMatrix(final MatrixI jalviewInputMatrix,
-          final Sequence[] matrixSequences)
+          final SequenceI[] matrixSequences)
   {
     this.jalviewMatrix = jalviewInputMatrix;
-    this.sequences = matrixSequences;
-    this.identifiers = new String[sequences.length];
+    this.identifiers = new String[matrixSequences.length];
 
     int i = 0;
-
-    for (Sequence sequence : sequences)
+    for (SequenceI sequence : matrixSequences)
     {
       identifiers[i] = sequence.getName();
       i++;
@@ -54,7 +50,7 @@ public class ForesterMatrix implements DistanceMatrix
   @Override
   public String getIdentifier(final int i)
   {
-    return identifiers[i];
+    return identifiers[i]; // add handling if index is out of bounds
   }
 
 
@@ -64,7 +60,9 @@ public class ForesterMatrix implements DistanceMatrix
     try {
     return IntStream.range(0, identifiers.length)
             .filter(x -> identifier.equals(identifiers[x])).findAny()
-            .getAsInt();
+              .getAsInt(); // stream to bypass otherwise having to duplicate the
+                           // list
+                           // with Arrays.aslist
     }
     catch (NoSuchElementException ex) {
       throw new Error(MessageManager.formatMessage(
@@ -164,5 +162,23 @@ public class ForesterMatrix implements DistanceMatrix
 
   }
 
+  public static DistanceMatrix convertJalviewToForester(
+          final MatrixI jalviewInputMatrix,
+          final SequenceI[] matrixSequences)
+  {
+    return DataConversions.createForesterDistanceMatrix(
+            jalviewInputMatrix, matrixSequences);
+
+  }
+
+  public static DistanceMatrix convertJalviewToForester(
+          final MatrixI jalviewInputMatrix,
+          final String[] matrixIdentifiers)
+  {
+    return DataConversions.createForesterDistanceMatrix(
+            jalviewInputMatrix, matrixIdentifiers);
+
+  }
+
 
 }
\ No newline at end of file