JAL-1177 additional saveState calls to write a dataset only jalview xml document
authorJim Procter <jprocter@dundee.ac.uk>
Fri, 25 Apr 2014 13:27:23 +0000 (14:27 +0100)
committerJim Procter <jprocter@dundee.ac.uk>
Fri, 25 Apr 2014 13:27:23 +0000 (14:27 +0100)
src/jalview/gui/Jalview2XML.java

index 3499f6d..3bca941 100644 (file)
@@ -39,6 +39,7 @@ import jalview.schemabinding.version2.*;
 import jalview.schemes.*;
 import jalview.util.Platform;
 import jalview.util.jarInputStreamProvider;
+import jalview.viewmodel.AlignmentViewport;
 import jalview.ws.jws2.Jws2Discoverer;
 import jalview.ws.jws2.dm.AAConSettings;
 import jalview.ws.jws2.jabaws2.Jws2Instance;
@@ -278,6 +279,8 @@ public class Jalview2XML
       return;
     }
 
+    Hashtable<String,AlignFrame> dsses = new Hashtable<String,AlignFrame>();
+
     try
     {
 
@@ -332,6 +335,7 @@ public class Jalview2XML
           }
 
           int ap, apSize = af.alignPanels.size();
+
           for (ap = 0; ap < apSize; ap++)
           {
             AlignmentPanel apanel = (AlignmentPanel) af.alignPanels
@@ -343,9 +347,19 @@ public class Jalview2XML
             }
 
             SaveState(apanel, fileName, jout);
+
+            String dssid = getDatasetIdRef(af.getViewport().getAlignment().getDataset());
+            if (!dsses.containsKey(dssid))
+            {
+              dsses.put(dssid, af);
+            }
+
           }
         }
       }
+
+      writeDatasetFor(dsses, ""+jout.hashCode()+" "+uniqueSetSuffix, jout);
+      
       try
       {
         jout.flush();
@@ -375,6 +389,7 @@ public class Jalview2XML
       int ap, apSize = af.alignPanels.size();
       FileOutputStream fos = new FileOutputStream(jarFile);
       JarOutputStream jout = new JarOutputStream(fos);
+      Hashtable<String,AlignFrame> dsses = new Hashtable<String,AlignFrame>();
       for (ap = 0; ap < apSize; ap++)
       {
         AlignmentPanel apanel = (AlignmentPanel) af.alignPanels
@@ -385,8 +400,13 @@ public class Jalview2XML
           jfileName = jfileName + ".xml";
         }
         SaveState(apanel, jfileName, jout);
+        String dssid = getDatasetIdRef(af.getViewport().getAlignment().getDataset());
+        if (!dsses.containsKey(dssid))
+        {
+          dsses.put(dssid, af);
+        }
       }
-
+      writeDatasetFor(dsses, fileName, jout);
       try
       {
         jout.flush();
@@ -404,6 +424,22 @@ public class Jalview2XML
     }
   }
 
+  private void writeDatasetFor(Hashtable<String, AlignFrame> dsses,
+          String fileName, JarOutputStream jout)
+  {
+
+    for (String dssids:dsses.keySet())
+    {
+      AlignFrame _af = dsses.get(dssids);
+      String jfileName = fileName + " Dataset for "+ _af.getTitle();
+      if (!jfileName.endsWith(".xml"))
+      {
+        jfileName = jfileName + ".xml";
+      }
+      SaveState(_af.alignPanel, jfileName, true, jout);
+    }
+  }
+
   /**
    * create a JalviewModel from an algnment view and marshall it to a
    * JarOutputStream