JAL-3660 JAL-3561 output alignment as requested file format as validated by FileForma... bug/JAL-3561_translatefileformats
authorJim Procter <jprocter@issues.jalview.org>
Tue, 16 Jun 2020 16:12:54 +0000 (17:12 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Tue, 16 Jun 2020 16:12:54 +0000 (17:12 +0100)
src/jalview/bin/Jalview.java

index 8c9d391..208a6f1 100755 (executable)
@@ -30,6 +30,7 @@ import jalview.io.DataSourceType;
 import jalview.io.FileFormat;
 import jalview.io.FileFormatException;
 import jalview.io.FileFormatI;
+import jalview.io.FileFormats;
 import jalview.io.FileLoader;
 import jalview.io.HtmlSvgOutput;
 import jalview.io.IdentifyFile;
@@ -666,18 +667,34 @@ public class Jalview
             af.createEPS(outputFile);
             continue;
           }
-
-          if (af.saveAlignment(file, format))
-          {
-            System.out.println("Written alignment in " + format
-                    + " format to " + file);
+          FileFormatI outFormat=null;
+          try {
+            outFormat = FileFormats.getInstance().forName(outputFormat);
+          } catch (Exception formatP) {
+            System.out.println("Couldn't parse "+outFormat+" as a valid Jalview format string.");
           }
-          else
+          if (outFormat != null)
           {
-            System.out.println("Error writing file " + file + " in "
-                    + format + " format!!");
+            if (!outFormat.isWritable())
+            {
+              System.out.println(
+                      "This version of Jalview does not support alignment export as "
+                              + outputFormat);
+            }
+            else
+            {
+              if (af.saveAlignment(file, outFormat))
+              {
+                System.out.println("Written alignment in " + format
+                        + " format to " + file);
+              }
+              else
+              {
+                System.out.println("Error writing file " + file + " in "
+                        + format + " format!!");
+              }
+            }
           }
-
         }
 
         while (aparser.getSize() > 0)