JAL-2795 created static class for forester conversions
authorkjvdheide <kjvanderheide@dundee.ac.uk>
Wed, 8 Nov 2017 17:46:52 +0000 (17:46 +0000)
committerkjvdheide <kjvanderheide@dundee.ac.uk>
Wed, 8 Nov 2017 17:46:52 +0000 (17:46 +0000)
src/jalview/ext/forester/ForesterConversions.java [new file with mode: 0644]
src/jalview/ext/forester/ForesterMatrix.java

diff --git a/src/jalview/ext/forester/ForesterConversions.java b/src/jalview/ext/forester/ForesterConversions.java
new file mode 100644 (file)
index 0000000..e35132c
--- /dev/null
@@ -0,0 +1,80 @@
+package jalview.ext.forester;
+
+import jalview.datamodel.SequenceI;
+import jalview.math.MatrixI;
+
+import org.forester.evoinference.matrix.distance.DistanceMatrix;
+import org.forester.io.parsers.phyloxml.PhyloXmlDataFormatException;
+
+public final class ForesterConversions
+{
+  public static org.forester.phylogeny.data.Sequence createForesterSequence(
+          SequenceI jalviewSequence)
+  {
+    org.forester.phylogeny.data.Sequence foresterSeq = new org.forester.phylogeny.data.Sequence();
+    if (jalviewSequence.getDescription() != null)
+    {
+      foresterSeq.setName(jalviewSequence.getDescription());
+    }
+    foresterSeq.setMolecularSequenceAligned(true); // all tree sequences should
+                                                   // be aligned already
+    foresterSeq.setMolecularSequence(jalviewSequence.getSequenceAsString());
+    if (jalviewSequence.isProtein()) // add checks for DNA or RNA (infer from
+                                     // forester itself?)
+    {
+      try
+      {
+        foresterSeq.setType("protein");
+      } catch (final PhyloXmlDataFormatException ignore)
+      {
+        // do nothing
+      }
+
+    }
+
+    return foresterSeq;
+
+  }
+
+
+  // public static org.forester.phylogeny.data.Accession
+  // createForesterAccession(
+  // SequenceI jalviewSequence)
+  // {
+  //
+  //
+  // org.forester.phylogeny.data.Accession foresterAcs = new
+  // org.forester.phylogeny.data.Accession();
+  //
+  // return foresterAcs;
+  // }
+
+  public static DistanceMatrix createForesterDistanceMatrix(
+          final MatrixI jalviewInputMatrix,
+          final String[] matrixIdentifiers)
+  {
+    if (jalviewInputMatrix.width() != jalviewInputMatrix.height())
+    {
+      // some kind of warning?
+    }
+
+    DistanceMatrix foresterMatrix = new ForesterMatrix(jalviewInputMatrix,
+            matrixIdentifiers);
+    return foresterMatrix;
+
+  }
+
+  public static DistanceMatrix createForesterDistanceMatrix(
+          final MatrixI jalviewInputMatrix,
+          final SequenceI[] matrixSequences)
+  {
+    if (jalviewInputMatrix.width() != jalviewInputMatrix.height())
+    {
+      // some kind of warning?
+    }
+    DistanceMatrix foresterMatrix = new ForesterMatrix(jalviewInputMatrix,
+            matrixSequences);
+    return foresterMatrix;
+
+  }
+}
index a1381be..7d3d295 100644 (file)
@@ -31,7 +31,6 @@ public class ForesterMatrix implements DistanceMatrix
     this.identifiers = new String[matrixSequences.length];
 
     int i = 0;
-
     for (SequenceI sequence : matrixSequences)
     {
       identifiers[i] = sequence.getName();
@@ -167,13 +166,8 @@ public class ForesterMatrix implements DistanceMatrix
           final MatrixI jalviewInputMatrix,
           final SequenceI[] matrixSequences)
   {
-    if (jalviewInputMatrix.width() != jalviewInputMatrix.height())
-    {
-      // some kind of warning?
-    }
-    DistanceMatrix foresterMatrix = new ForesterMatrix(jalviewInputMatrix,
-            matrixSequences);
-    return foresterMatrix;
+    return ForesterConversions.createForesterDistanceMatrix(
+            jalviewInputMatrix, matrixSequences);
 
   }
 
@@ -181,14 +175,8 @@ public class ForesterMatrix implements DistanceMatrix
           final MatrixI jalviewInputMatrix,
           final String[] matrixIdentifiers)
   {
-    if (jalviewInputMatrix.width() != jalviewInputMatrix.height())
-    {
-      // some kind of warning?
-    }
-
-    DistanceMatrix foresterMatrix = new ForesterMatrix(jalviewInputMatrix,
-            matrixIdentifiers);
-    return foresterMatrix;
+    return ForesterConversions.createForesterDistanceMatrix(
+            jalviewInputMatrix, matrixIdentifiers);
 
   }