JAL_793 implemented embeding source data in exported html
[jalview.git] / src / jalview / io / AppletFormatAdapter.java
index 649aad3..f97a341 100755 (executable)
@@ -25,6 +25,7 @@ import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.AlignmentView;
+import jalview.datamodel.SequenceGroup;
 import jalview.util.MessageManager;
 
 import java.io.File;
@@ -57,7 +58,7 @@ public class AppletFormatAdapter
   public static final String[] READABLE_EXTENSIONS = new String[]
   { "fa, fasta, mfa, fastq", "aln", "pfam", "msf", "pir", "blc", "amsa",
       "sto,stk", "xml,rnaml", PhylipFile.FILE_EXT, JSONFile.FILE_EXT,
-      "jar,jvp", "html" };
+      "jar,jvp", HtmlFile.FILE_EXT };
 
   /**
    * List of readable formats by application in order corresponding to
@@ -65,7 +66,8 @@ public class AppletFormatAdapter
    */
   public static final String[] READABLE_FNAMES = new String[]
   { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "AMSA", "Stockholm",
-      "RNAML", PhylipFile.FILE_DESC, JSONFile.FILE_DESC, "Jalview", "HTML" };
+      "RNAML", PhylipFile.FILE_DESC, JSONFile.FILE_DESC, "Jalview",
+      HtmlFile.FILE_DESC };
 
   /**
    * List of valid format strings for use by callers of the formatSequences
@@ -215,6 +217,7 @@ public class AppletFormatAdapter
     this.inFile = inFile;
     try
     {
+      Alignment al;
       if (format.equals("FASTA"))
       {
         afile = new FastaFile(inFile, type);
@@ -267,19 +270,37 @@ public class AppletFormatAdapter
       {
         afile = new PhylipFile(inFile, type);
       }
-       else if (format.equals(JSONFile.FILE_DESC))
-       {
-       afile = new JSONFile(inFile, type);
-       }
+      else if (format.equals(JSONFile.FILE_DESC))
+      {
+        afile = new JSONFile(inFile, type);
+        al = new Alignment(afile.getSeqsAsArray());
+        afile.addAnnotations(al);
+        for (SequenceGroup sg : afile.getSeqGroups())
+        {
+          al.addGroup(sg);
+        }
+        return al;
+      }
+      else if (format.equals(HtmlFile.FILE_DESC))
+      {
+        afile = new HtmlFile(inFile, type);
+        al = new Alignment(afile.getSeqsAsArray());
+        afile.addAnnotations(al);
+        for (SequenceGroup sg : afile.getSeqGroups())
+        {
+          al.addGroup(sg);
+        }
+        return al;
+      }
       else if (format.equals("RNAML"))
       {
         afile = new RnamlFile(inFile, type);
       }
 
-      Alignment al = new Alignment(afile.getSeqsAsArray());
+      al = new Alignment(afile.getSeqsAsArray());
 
-      afile.addAnnotations(al);
-      afile.addSeqGroups(al);
+      // afile.addAnnotations(al);
+      // afile.addSeqGroups(al);
 
       return al;
     } catch (Exception e)
@@ -344,6 +365,7 @@ public class AppletFormatAdapter
     String type = source.type;
     try
     {
+      Alignment al;
       if (format.equals("FASTA"))
       {
         afile = new FastaFile(source);
@@ -398,14 +420,19 @@ public class AppletFormatAdapter
       {
         afile = new PhylipFile(source);
       }
-       else if (format.equals(JSONFile.FILE_DESC))
-       {
-       afile = new JSONFile(source);
-       }
-      Alignment al = new Alignment(afile.getSeqsAsArray());
-
-      afile.addAnnotations(al);
-      afile.addSeqGroups(al);
+      else if (format.equals(JSONFile.FILE_DESC))
+      {
+        afile = new JSONFile(source);
+        al = new Alignment(afile.getSeqsAsArray());
+        afile.addAnnotations(al);
+        afile.addSeqGroups(al);
+        return al;
+      }
+      else if (format.equals(HtmlFile.FILE_DESC))
+      {
+        afile = new HtmlFile(source);
+      }
+      al = new Alignment(afile.getSeqsAsArray());
 
       return al;
     } catch (Exception e)