JAL-1499 patch from Mungo Carstairs
[jalview.git] / src / jalview / io / AppletFormatAdapter.java
old mode 100755 (executable)
new mode 100644 (file)
index d7da302..288d476
  */
 package jalview.io;
 
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentI;
+
 import java.io.File;
 import java.io.InputStream;
 
-import jalview.datamodel.*;
-
 /**
  * A low level class for alignment and feature IO with alignment formatting
  * methods used by both applet and application for generating flat alignment
@@ -40,22 +41,23 @@ public class AppletFormatAdapter
    * List of valid format strings used in the isValidFormat method
    */
   public static final String[] READABLE_FORMATS = new String[]
-  { "BLC", "CLUSTAL", "FASTA", "MSF", "PileUp", "PIR", "PFAM", "STH",
-      "PDB", "JnetFile", "RNAML" }; // , "SimpleBLAST" };
-
+  { "BLC", "CLUSTAL", "FASTA", "MEGA", "MSF", "PileUp", "PIR", "PFAM",
+    "PDB", "JnetFile", "RNAML" }; 
   /**
    * List of valid format strings for use by callers of the formatSequences
    * method
    */
   public static final String[] WRITEABLE_FORMATS = new String[]
-  { "BLC", "CLUSTAL", "FASTA", "MSF", "PileUp", "PIR", "PFAM", "AMSA" };
+  { "BLC", "CLUSTAL", "FASTA", "MEGA", "MSF", "PileUp", "PIR", "PFAM",
+      "STH",
+      "AMSA" };
 
   /**
    * List of extensions corresponding to file format types in WRITABLE_FNAMES
    * that are writable by the application.
    */
   public static final String[] WRITABLE_EXTENSIONS = new String[]
-  { "fa, fasta, mfa, fastq", "aln", "pfam", "msf", "pir", "blc", "amsa",
+  { "fa, fasta, mfa, fastq", "aln", "pfam", "meg", "msf", "pir", "blc", "amsa",
       "jvp", "sto,stk", "jar" };
 
   /**
@@ -63,15 +65,16 @@ public class AppletFormatAdapter
    * WRITABLE_EXTENSIONS list of formats.
    */
   public static final String[] WRITABLE_FNAMES = new String[]
-  { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "AMSA", "Jalview",
-      "STH", "Jalview" };
+  { "Fasta", "Clustal", "PFAM", "MEGA", "MSF", "PIR", "BLC", "AMSA",
+      "Jalview",
+      "STH", "Jalview"};
 
   /**
    * List of readable format file extensions by application in order
    * corresponding to READABLE_FNAMES
    */
   public static final String[] READABLE_EXTENSIONS = new String[]
-  { "fa, fasta, mfa, fastq", "aln", "pfam", "msf", "pir", "blc", "amsa",
+  { "fa, fasta, mfa, fastq", "aln", "pfam", "meg", "msf", "pir", "blc", "amsa",
       "jar,jvp", "sto,stk", "xml,rnaml" }; // ".blast"
 
   /**
@@ -79,8 +82,8 @@ public class AppletFormatAdapter
    * READABLE_EXTENSIONS
    */
   public static final String[] READABLE_FNAMES = new String[]
-  { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "AMSA", "Jalview",
-      "Stockholm", "RNAML" };// ,
+  { "Fasta", "Clustal", "PFAM", "MEGA", "MSF", "PIR", "BLC", "AMSA", "Jalview",
+      "Stockholm", "RNAML" };
 
   // "SimpleBLAST"
   // };
@@ -245,6 +248,10 @@ public class AppletFormatAdapter
       {
         afile = new RnamlFile(inFile, type);
       }
+      else if (format.equals("MEGA"))
+      {
+        afile = new MegaFile(inFile, type);
+      }
 
       Alignment al = new Alignment(afile.getSeqsAsArray());
 
@@ -360,6 +367,10 @@ public class AppletFormatAdapter
       {
         afile = new SimpleBlastFile(source);
       }
+      else if (format.equals("MEGA"))
+      {
+        afile = new MegaFile(source);
+      }
 
       Alignment al = new Alignment(afile.getSeqsAsArray());
 
@@ -467,7 +478,10 @@ public class AppletFormatAdapter
       {
         afile = new RnamlFile();
       }
-
+      else if (format.equalsIgnoreCase("MEGA"))
+      {
+        afile = new MegaFile();
+      }
       else
       {
         throw new Exception(