JAL-1641 Further refactoring of JSON export option, introduction of Viewport to the...
authortcofoegbu <tcnofoegbu@dundee.ac.uk>
Tue, 19 May 2015 10:07:59 +0000 (11:07 +0100)
committertcofoegbu <tcnofoegbu@dundee.ac.uk>
Tue, 19 May 2015 10:07:59 +0000 (11:07 +0100)
17 files changed:
examples/example.json [new file with mode: 0644]
src/jalview/api/AlignViewportI.java
src/jalview/appletgui/AlignViewport.java
src/jalview/gui/AlignFrame.java
src/jalview/gui/AlignViewport.java
src/jalview/gui/CutAndPasteTransfer.java
src/jalview/gui/Desktop.java
src/jalview/io/AppletFormatAdapter.java
src/jalview/io/FileLoader.java
src/jalview/io/FileParse.java
src/jalview/io/FormatAdapter.java
src/jalview/io/HtmlFile.java
src/jalview/io/HtmlSvgOutput.java
src/jalview/io/JSONFile.java
src/jalview/json/binding/v1/SequenceFeaturesPojo.java
test/jalview/io/BioJsHTMLOutputTest.java
test/jalview/io/JSONFileTest.java

diff --git a/examples/example.json b/examples/example.json
new file mode 100644 (file)
index 0000000..47ea429
--- /dev/null
@@ -0,0 +1 @@
+{"seqs":[{"name":"FER_CAPAN/3-34","start":3,"end":34,"id":"FER_CAPAN_1580333149","seq":"SVSATMISTSFMPRKPAVTSL-KPIPNVGE--ALF","order":1},{"name":"FER1_SOLLC/3-34","start":3,"end":34,"id":"FER1_SOLLC_1952300006","seq":"SISGTMISTSFLPRKPAVTSL-KAISNVGE--ALF","order":2},{"name":"Q93XJ9_SOLTU/3-34","start":3,"end":34,"id":"Q93XJ9_SOLTU_1274067508","seq":"SISGTMISTSFLPRKPVVTSL-KAISNVGE--ALF","order":3},{"name":"FER1_PEA/6-37","start":6,"end":37,"id":"FER1_PEA_1823806146","seq":"ALYGTAVSTSFLRTQPMPMSV-TTTKAFSN--GFL","order":4},{"name":"Q7XA98_TRIPR/6-39","start":6,"end":39,"id":"Q7XA98_TRIPR_1024982041","seq":"ALYGTAVSTSFMRRQPVPMSV-ATTTTTKAFPSGF","order":5}],"seqGroups":[{"displayText":true,"startRes":21,"groupName":"JGroup:1883305585","endRes":29,"colourText":false,"seqsHash":["FER1_SOLLC_1952300006","Q93XJ9_SOLTU_1274067508","FER1_PEA_1823806146","Q7XA98_TRIPR_1024982041"],"showNonconserved":false,"colourScheme":"Zappo","displayBoxes":true}],"alignAnnotation":[{"annotations":[{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"},{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"},{"displayCharacter":"α","value":0,"secondaryStructure":"H"},{"displayCharacter":"α","value":0,"secondaryStructure":"H"},{"displayCharacter":"α","value":0,"secondaryStructure":"H"},{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"},{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"},{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"},{"displayCharacter":"β","value":0,"secondaryStructure":"E"},{"displayCharacter":"β","value":0,"secondaryStructure":"E"},{"displayCharacter":"β","value":0,"secondaryStructure":"E"},{"displayCharacter":"β","value":0,"secondaryStructure":"E"},{"displayCharacter":"β","value":0,"secondaryStructure":"E"},{"displayCharacter":"β","value":0,"secondaryStructure":"E"},{"displayCharacter":"β","value":0,"secondaryStructure":"E"},{"displayCharacter":"β","value":0,"secondaryStructure":"E"},{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"},{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"},{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"},{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"},{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"},{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"},{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"},{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"},{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"},{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"},{"displayCharacter":"α","value":0,"secondaryStructure":"H"},{"displayCharacter":"α","value":0,"secondaryStructure":"H"},{"displayCharacter":"α","value":0,"secondaryStructure":"H"},{"displayCharacter":"α","value":0,"secondaryStructure":"H"},{"displayCharacter":"α","value":0,"secondaryStructure":"H"},{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"},{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"},{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"},{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"}],"description":"New description","label":"Secondary Structure"}],"jalviewSettings":{"globalColorScheme":"foo","jalviewVersion":"Test","webStartUrl":"http://www.jalview.org/services/launchApp","showSeqFeatures":true,"wrapModeEnabled":false},"seqFeatures":[{"fillColor":"#ff0033","score":0,"sequenceRef":"Q93XJ9_SOLTU_1274067508","featureGroup":"Jalview","description":"desciption","xStart":3,"xEnd":13,"type":"feature_x"},{"fillColor":"#ff0033","score":0,"sequenceRef":"FER1_PEA_1823806146","featureGroup":"Jalview","description":"desciption","xStart":3,"xEnd":13,"type":"feature_x"},{"fillColor":"#ff0033","score":0,"sequenceRef":"Q7XA98_TRIPR_1024982041","featureGroup":"Jalview","description":"desciption","xStart":3,"xEnd":13,"type":"feature_x"}]}
\ No newline at end of file
index 8482f6b..b4d2592 100644 (file)
  */
 package jalview.api;
 
-import java.awt.Color;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Map;
-
 import jalview.analysis.Conservation;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
@@ -36,6 +31,11 @@ import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.schemes.ColourSchemeI;
 
+import java.awt.Color;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
 /**
  * @author jimp
  * 
@@ -372,4 +372,9 @@ public interface AlignViewportI extends ViewStyleI
    * Set whether view should scroll to show the highlighted region of a sequence
    */
   void setFollowHighlight(boolean b);
+
+  public FeatureRenderer getFeatureRenderer();
+
+  public void setFeatureRenderer(FeatureRenderer featureRenderer);
+
 }
index 1ed4583..ef17215 100644 (file)
  */
 package jalview.appletgui;
 
-import java.awt.Font;
-
 import jalview.analysis.NJTree;
 import jalview.api.AlignViewportI;
+import jalview.api.FeatureRenderer;
 import jalview.bin.JalviewLite;
 import jalview.commands.CommandI;
 import jalview.datamodel.AlignmentI;
@@ -40,6 +39,8 @@ import jalview.structure.StructureSelectionManager;
 import jalview.structure.VamsasSource;
 import jalview.viewmodel.AlignmentViewport;
 
+import java.awt.Font;
+
 public class AlignViewport extends AlignmentViewport implements
         SelectionSource, VamsasSource, CommandListener
 {
@@ -57,6 +58,8 @@ public class AlignViewport extends AlignmentViewport implements
 
   private AnnotationColumnChooser annotationColumnSelectionState;
 
+  private FeatureRenderer featureRenderer;
+
   public void finalize()
   {
     applet = null;
@@ -467,4 +470,17 @@ public class AlignViewport extends AlignmentViewport implements
     }
   }
 
+  @Override
+  public FeatureRenderer getFeatureRenderer()
+  {
+    return featureRenderer;
+  }
+
+  @Override
+  public void setFeatureRenderer(FeatureRenderer featureRenderer)
+  {
+    this.featureRenderer = featureRenderer;
+
+  }
+
 }
index 1b2410a..61073e3 100644 (file)
  */
 package jalview.gui;
 
-import java.awt.BorderLayout;
-import java.awt.Component;
-import java.awt.GridLayout;
-import java.awt.Rectangle;
-import java.awt.Toolkit;
-import java.awt.datatransfer.Clipboard;
-import java.awt.datatransfer.DataFlavor;
-import java.awt.datatransfer.StringSelection;
-import java.awt.datatransfer.Transferable;
-import java.awt.dnd.DnDConstants;
-import java.awt.dnd.DropTargetDragEvent;
-import java.awt.dnd.DropTargetDropEvent;
-import java.awt.dnd.DropTargetEvent;
-import java.awt.dnd.DropTargetListener;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.ItemEvent;
-import java.awt.event.ItemListener;
-import java.awt.event.KeyAdapter;
-import java.awt.event.KeyEvent;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-import java.awt.print.PageFormat;
-import java.awt.print.PrinterJob;
-import java.beans.PropertyChangeEvent;
-import java.io.File;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Deque;
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Set;
-import java.util.Vector;
-
-import javax.swing.JButton;
-import javax.swing.JCheckBoxMenuItem;
-import javax.swing.JEditorPane;
-import javax.swing.JInternalFrame;
-import javax.swing.JLabel;
-import javax.swing.JLayeredPane;
-import javax.swing.JMenu;
-import javax.swing.JMenuItem;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JProgressBar;
-import javax.swing.JRadioButtonMenuItem;
-import javax.swing.JScrollPane;
-import javax.swing.SwingUtilities;
-
 import jalview.analysis.AAFrequency;
 import jalview.analysis.AlignmentSorter;
 import jalview.analysis.AlignmentUtils;
@@ -148,6 +97,57 @@ import jalview.ws.jws2.Jws2Discoverer;
 import jalview.ws.jws2.jabaws2.Jws2Instance;
 import jalview.ws.seqfetcher.DbSourceProxy;
 
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.GridLayout;
+import java.awt.Rectangle;
+import java.awt.Toolkit;
+import java.awt.datatransfer.Clipboard;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.StringSelection;
+import java.awt.datatransfer.Transferable;
+import java.awt.dnd.DnDConstants;
+import java.awt.dnd.DropTargetDragEvent;
+import java.awt.dnd.DropTargetDropEvent;
+import java.awt.dnd.DropTargetEvent;
+import java.awt.dnd.DropTargetListener;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.print.PageFormat;
+import java.awt.print.PrinterJob;
+import java.beans.PropertyChangeEvent;
+import java.io.File;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Deque;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Set;
+import java.util.Vector;
+
+import javax.swing.JButton;
+import javax.swing.JCheckBoxMenuItem;
+import javax.swing.JEditorPane;
+import javax.swing.JInternalFrame;
+import javax.swing.JLabel;
+import javax.swing.JLayeredPane;
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JProgressBar;
+import javax.swing.JRadioButtonMenuItem;
+import javax.swing.JScrollPane;
+import javax.swing.SwingUtilities;
+
 /**
  * DOCUMENT ME!
  * 
@@ -1212,7 +1212,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
           omitHidden = viewport.getViewAsString(false);
         }
       }
-      FormatAdapter f = new FormatAdapter();
+      FeatureRenderer fr = new FeatureRenderer(this.alignPanel);
+      viewport.setFeatureRenderer(fr);
+      FormatAdapter f = new FormatAdapter(viewport);
       String output = f.formatSequences(format,
               viewport.getAlignment(), // class cast exceptions will
               // occur in the distant future
@@ -1282,7 +1284,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   protected void outputText_actionPerformed(ActionEvent e)
   {
     String[] omitHidden = null;
-
+    FeatureRenderer fr = new FeatureRenderer(this.alignPanel);
+    viewport.setFeatureRenderer(fr);
     if (viewport.hasHiddenColumns())
     {
       int reply = JOptionPane
@@ -1306,8 +1309,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
     try
     {
-      Desktop.setCurrentAlignFrame(this);
-      cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
+      cap.setText(new FormatAdapter(viewport).formatSequences(
+              e.getActionCommand(),
               viewport.getAlignment(), omitHidden,
               viewport.getColumnSelection()));
       Desktop.addInternalFrame(cap, MessageManager.formatMessage(
index a54fa99..e32e910 100644 (file)
  */
 package jalview.gui;
 
-import java.awt.Container;
-import java.awt.Dimension;
-import java.awt.Font;
-import java.awt.Rectangle;
-import java.util.ArrayList;
-import java.util.Hashtable;
-import java.util.Set;
-import java.util.Vector;
-
-import javax.swing.JInternalFrame;
-import javax.swing.JOptionPane;
-
 import jalview.analysis.AlignmentUtils;
 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
 import jalview.analysis.NJTree;
 import jalview.api.AlignViewportI;
+import jalview.api.FeatureRenderer;
 import jalview.api.ViewStyleI;
 import jalview.bin.Cache;
 import jalview.commands.CommandI;
@@ -76,6 +65,18 @@ import jalview.util.MessageManager;
 import jalview.viewmodel.AlignmentViewport;
 import jalview.ws.params.AutoCalcSetting;
 
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.Rectangle;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Set;
+import java.util.Vector;
+
+import javax.swing.JInternalFrame;
+import javax.swing.JOptionPane;
+
 /**
  * DOCUMENT ME!
  * 
@@ -95,6 +96,8 @@ public class AlignViewport extends AlignmentViewport implements
 
   private Rectangle explodedGeometry;
 
+  private FeatureRenderer featureRenderer;
+
   String viewName;
 
   /*
@@ -1038,4 +1041,16 @@ public class AlignViewport extends AlignmentViewport implements
       complementPanel.scrollToCentre(sr, seqOffset);
     }
   }
+
+  @Override
+  public FeatureRenderer getFeatureRenderer()
+  {
+    return featureRenderer;
+  }
+
+  @Override
+  public void setFeatureRenderer(FeatureRenderer featureRenderer)
+  {
+    this.featureRenderer = featureRenderer;
+  }
 }
index 6511cd8..3f4aa71 100644 (file)
@@ -21,7 +21,9 @@
 package jalview.gui;
 
 import jalview.datamodel.Alignment;
+import jalview.io.FileParse;
 import jalview.io.FormatAdapter;
+import jalview.io.HtmlFile;
 import jalview.io.IdentifyFile;
 import jalview.io.JSONFile;
 import jalview.io.JalviewFileChooser;
@@ -54,6 +56,7 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer
 
   AlignViewport viewport;
 
+  FileParse source = null;
   public CutAndPasteTransfer()
   {
     SwingUtilities.invokeLater(new Runnable()
@@ -189,7 +192,10 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer
     {
       try
       {
-        al = new FormatAdapter().readFile(getText(), "Paste", format);
+        FormatAdapter fa = new FormatAdapter(viewport);
+        al = fa.readFile(getText(), "Paste", format);
+        source = fa.getAlignFile();
+
       } catch (java.io.IOException ex)
       {
         JOptionPane.showInternalMessageDialog(Desktop.desktop,
@@ -220,10 +226,15 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer
         af.statusBar.setText(MessageManager
                 .getString("label.successfully_pasted_alignment_file"));
 
-        af.setShowSeqFeatures(JSONFile.isSeqFeaturesEnabled());
+        if (source instanceof HtmlFile)
+        {
+          ((HtmlFile) source).LoadAlignmentFeatures(af);
+        }
+        else if (source instanceof JSONFile)
+        {
+          ((JSONFile) source).LoadAlignmentFeatures(af);
+        }
 
-        af.changeColour(JSONFile.getColourScheme());
-        af.setMenusForViewport();
 
         try
         {
index 9e5bbff..1228965 100644 (file)
@@ -26,7 +26,6 @@ import jalview.bin.Cache;
 import jalview.io.FileLoader;
 import jalview.io.FormatAdapter;
 import jalview.io.IdentifyFile;
-import jalview.io.JSONFile;
 import jalview.io.JalviewFileChooser;
 import jalview.io.JalviewFileView;
 import jalview.jbgui.GSplitFrame;
@@ -1025,13 +1024,13 @@ public class Desktop extends jalview.jbgui.GDesktop implements
       {
         new FileLoader().LoadFile(viewport, choice, FormatAdapter.FILE,
                 format);
-        viewport.setShowSequenceFeatures(JSONFile.isSeqFeaturesEnabled());
-        AlignFrame af = viewport.getAlignPanel().alignFrame;
-        if (af != null)
-        {
-          af.changeColour(JSONFile.getColourScheme());
-          af.setMenusForViewport();
-        }
+        // viewport.setShowSequenceFeatures(JSONFile.isSeqFeaturesEnabled());
+        // AlignFrame af = viewport.getAlignPanel().alignFrame;
+        // if (af != null)
+        // {
+        // af.changeColour(JSONFile.getColourScheme());
+        // af.setMenusForViewport();
+        // }
       }
       else
       {
@@ -3084,15 +3083,15 @@ public class Desktop extends jalview.jbgui.GDesktop implements
 
   }
 
-  public static AlignFrame getCurrentAlignFrame()
-  {
-    return currentAlignFrame;
-  }
-
-  public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
-  {
-    Desktop.currentAlignFrame = currentAlignFrame;
-  }
+  // public static AlignFrame getCurrentAlignFrame()
+  // {
+  // return currentAlignFrame;
+  // }
+  //
+  // public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
+  // {
+  // Desktop.currentAlignFrame = currentAlignFrame;
+  // }
 
 
 }
index 41fac7f..5601f27 100755 (executable)
@@ -43,6 +43,40 @@ import java.util.List;
  */
 public class AppletFormatAdapter
 {
+  private AlignViewportI viewport;
+
+  public static String FILE = "File";
+
+  public static String URL = "URL";
+
+  public static String PASTE = "Paste";
+
+  public static String CLASSLOADER = "ClassLoader";
+
+  /**
+   * add jalview-derived non-secondary structure annotation from PDB structure
+   */
+  boolean annotFromStructure = false;
+
+  /**
+   * add secondary structure from PDB data with built-in algorithms
+   */
+  boolean localSecondaryStruct = false;
+
+  /**
+   * process PDB data with web services
+   */
+  boolean serviceSecondaryStruct = false;
+
+  private AlignFile alignFile = null;
+
+  String inFile;
+
+  /**
+   * character used to write newlines
+   */
+  protected String newline = System.getProperty("line.separator");
+
   /**
    * List of valid format strings used in the isValidFormat method
    */
@@ -99,6 +133,15 @@ public class AppletFormatAdapter
   public static String SUPPORTED_FORMATS = "Formats currently supported are\n"
           + prettyPrint(READABLE_FORMATS);
 
+  public AppletFormatAdapter()
+  {
+  }
+
+  public AppletFormatAdapter(AlignViewportI viewport)
+  {
+    this.viewport = viewport;
+  }
+
   /**
    *
    * @param els
@@ -116,37 +159,6 @@ public class AppletFormatAdapter
     return list.toString();
   }
 
-  public static String FILE = "File";
-
-  public static String URL = "URL";
-
-  public static String PASTE = "Paste";
-
-  public static String CLASSLOADER = "ClassLoader";
-
-  /**
-   * add jalview-derived non-secondary structure annotation from PDB structure
-   */
-  boolean annotFromStructure = false;
-
-  /**
-   * add secondary structure from PDB data with built-in algorithms
-   */
-  boolean localSecondaryStruct = false;
-
-  /**
-   * process PDB data with web services
-   */
-  boolean serviceSecondaryStruct = false;
-
-  AlignFile afile = null;
-
-  String inFile;
-
-  /**
-   * character used to write newlines
-   */
-  protected String newline = System.getProperty("line.separator");
 
   public void setNewlineString(String nl)
   {
@@ -220,62 +232,63 @@ public class AppletFormatAdapter
       Alignment al;
       if (format.equals("FASTA"))
       {
-        afile = new FastaFile(inFile, type);
+        alignFile = new FastaFile(inFile, type);
       }
       else if (format.equals("MSF"))
       {
-        afile = new MSFfile(inFile, type);
+        alignFile = new MSFfile(inFile, type);
       }
       else if (format.equals("PileUp"))
       {
-        afile = new PileUpfile(inFile, type);
+        alignFile = new PileUpfile(inFile, type);
       }
       else if (format.equals("CLUSTAL"))
       {
-        afile = new ClustalFile(inFile, type);
+        alignFile = new ClustalFile(inFile, type);
       }
       else if (format.equals("BLC"))
       {
-        afile = new BLCFile(inFile, type);
+        alignFile = new BLCFile(inFile, type);
       }
       else if (format.equals("PIR"))
       {
-        afile = new PIRFile(inFile, type);
+        alignFile = new PIRFile(inFile, type);
       }
       else if (format.equals("PFAM"))
       {
-        afile = new PfamFile(inFile, type);
+        alignFile = new PfamFile(inFile, type);
       }
       else if (format.equals("JnetFile"))
       {
-        afile = new JPredFile(inFile, type);
-        ((JPredFile) afile).removeNonSequences();
+        alignFile = new JPredFile(inFile, type);
+        ((JPredFile) alignFile).removeNonSequences();
       }
       else if (format.equals("PDB"))
       {
-        afile = new MCview.PDBfile(annotFromStructure,
+        alignFile = new MCview.PDBfile(annotFromStructure,
                 localSecondaryStruct, serviceSecondaryStruct, inFile, type);
         // Uncomment to test Jmol data based PDB processing: JAL-1213
         // afile = new jalview.ext.jmol.PDBFileWithJmol(inFile, type);
       }
       else if (format.equals("STH"))
       {
-        afile = new StockholmFile(inFile, type);
+        alignFile = new StockholmFile(inFile, type);
       }
       else if (format.equals("SimpleBLAST"))
       {
-        afile = new SimpleBlastFile(inFile, type);
+        alignFile = new SimpleBlastFile(inFile, type);
       }
       else if (format.equals(PhylipFile.FILE_DESC))
       {
-        afile = new PhylipFile(inFile, type);
+        alignFile = new PhylipFile(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())
+        alignFile = new JSONFile(inFile, type);
+        al = new Alignment(alignFile.getSeqsAsArray());
+        alignFile.addAnnotations(al);
+        ((JSONFile) alignFile).setViewport(viewport);
+        for (SequenceGroup sg : alignFile.getSeqGroups())
         {
           al.addGroup(sg);
         }
@@ -283,10 +296,10 @@ public class AppletFormatAdapter
       }
       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())
+        alignFile = new HtmlFile(inFile, type);
+        al = new Alignment(alignFile.getSeqsAsArray());
+        alignFile.addAnnotations(al);
+        for (SequenceGroup sg : alignFile.getSeqGroups())
         {
           al.addGroup(sg);
         }
@@ -294,12 +307,12 @@ public class AppletFormatAdapter
       }
       else if (format.equals("RNAML"))
       {
-        afile = new RnamlFile(inFile, type);
+        alignFile = new RnamlFile(inFile, type);
       }
 
-      al = new Alignment(afile.getSeqsAsArray());
+      al = new Alignment(alignFile.getSeqsAsArray());
 
-      afile.addAnnotations(al);
+      alignFile.addAnnotations(al);
 
       return al;
     } catch (Exception e)
@@ -320,11 +333,11 @@ public class AppletFormatAdapter
         try
         {
           // Possible sequence is just residues with no label
-          afile = new FastaFile(">UNKNOWN\n" + inFile, "Paste");
-          Alignment al = new Alignment(afile.getSeqsAsArray());
+          alignFile = new FastaFile(">UNKNOWN\n" + inFile, "Paste");
+          Alignment al = new Alignment(alignFile.getSeqsAsArray());
 
-          afile.addSeqGroups(al);
-          afile.addAnnotations(al);
+          alignFile.addSeqGroups(al);
+          alignFile.addAnnotations(al);
           return al;
 
         } catch (Exception ex)
@@ -367,72 +380,73 @@ public class AppletFormatAdapter
       Alignment al;
       if (format.equals("FASTA"))
       {
-        afile = new FastaFile(source);
+        alignFile = new FastaFile(source);
       }
       else if (format.equals("MSF"))
       {
-        afile = new MSFfile(source);
+        alignFile = new MSFfile(source);
       }
       else if (format.equals("PileUp"))
       {
-        afile = new PileUpfile(source);
+        alignFile = new PileUpfile(source);
       }
       else if (format.equals("CLUSTAL"))
       {
-        afile = new ClustalFile(source);
+        alignFile = new ClustalFile(source);
       }
       else if (format.equals("BLC"))
       {
-        afile = new BLCFile(source);
+        alignFile = new BLCFile(source);
       }
       else if (format.equals("PIR"))
       {
-        afile = new PIRFile(source);
+        alignFile = new PIRFile(source);
       }
       else if (format.equals("PFAM"))
       {
-        afile = new PfamFile(source);
+        alignFile = new PfamFile(source);
       }
       else if (format.equals("JnetFile"))
       {
-        afile = new JPredFile(source);
-        ((JPredFile) afile).removeNonSequences();
+        alignFile = new JPredFile(source);
+        ((JPredFile) alignFile).removeNonSequences();
       }
       else if (format.equals("PDB"))
       {
-        afile = new MCview.PDBfile(annotFromStructure,
+        alignFile = new MCview.PDBfile(annotFromStructure,
                 localSecondaryStruct, serviceSecondaryStruct, source);
       }
       else if (format.equals("STH"))
       {
-        afile = new StockholmFile(source);
+        alignFile = new StockholmFile(source);
       }
       else if (format.equals("RNAML"))
       {
-        afile = new RnamlFile(source);
+        alignFile = new RnamlFile(source);
       }
       else if (format.equals("SimpleBLAST"))
       {
-        afile = new SimpleBlastFile(source);
+        alignFile = new SimpleBlastFile(source);
       }
       else if (format.equals(PhylipFile.FILE_DESC))
       {
-        afile = new PhylipFile(source);
+        alignFile = new PhylipFile(source);
       }
       else if (format.equals(JSONFile.FILE_DESC))
       {
-        afile = new JSONFile(source);
-        al = new Alignment(afile.getSeqsAsArray());
-        afile.addAnnotations(al);
-        afile.addSeqGroups(al);
+        alignFile = new JSONFile(source);
+        // ((JSONFile) afile).setViewport(viewport);
+        al = new Alignment(alignFile.getSeqsAsArray());
+        alignFile.addAnnotations(al);
+        alignFile.addSeqGroups(al);
         return al;
       }
       else if (format.equals(HtmlFile.FILE_DESC))
       {
-        afile = new HtmlFile(source);
+        alignFile = new HtmlFile(source);
       }
-      al = new Alignment(afile.getSeqsAsArray());
-      afile.addAnnotations(al);
+      al = new Alignment(alignFile.getSeqsAsArray());
+      alignFile.addAnnotations(al);
 
       return al;
     } catch (Exception e)
@@ -453,10 +467,10 @@ public class AppletFormatAdapter
         try
         {
           // Possible sequence is just residues with no label
-          afile = new FastaFile(">UNKNOWN\n" + inFile, "Paste");
-          Alignment al = new Alignment(afile.getSeqsAsArray());
-          afile.addAnnotations(al);
-          afile.addSeqGroups(al);
+          alignFile = new FastaFile(">UNKNOWN\n" + inFile, "Paste");
+          Alignment al = new Alignment(alignFile.getSeqsAsArray());
+          alignFile.addAnnotations(al);
+          alignFile.addSeqGroups(al);
           return al;
 
         } catch (Exception ex)
@@ -568,6 +582,7 @@ public class AppletFormatAdapter
        else if (format.equalsIgnoreCase(JSONFile.FILE_DESC))
        {
         afile = new JSONFile();
+        afile.setViewport(viewport);
         // Add groups to AlignFile
         afile.seqGroups = alignment.getGroups();
 
@@ -857,4 +872,14 @@ public class AppletFormatAdapter
     }
     return null;
   }
+
+  public AlignFile getAlignFile()
+  {
+    return alignFile;
+  }
+
+  public void setAlignFile(AlignFile alignFile)
+  {
+    this.alignFile = alignFile;
+  }
 }
index cd9258c..9ccde9e 100755 (executable)
@@ -296,7 +296,7 @@ public class FileLoader implements Runnable
               // open a new source and read from it
               FormatAdapter fa = new FormatAdapter();
               al = fa.readFile(file, protocol, format);
-              source = fa.afile; // keep reference for later if necessary.
+              source = fa.getAlignFile(); // keep reference for later if necessary.
             }
           } catch (java.io.IOException ex)
           {
index 69c362f..f9c717d 100755 (executable)
@@ -20,6 +20,7 @@
  */
 package jalview.io;
 
+import jalview.api.AlignViewportI;
 import jalview.util.MessageManager;
 
 import java.io.BufferedReader;
@@ -48,6 +49,8 @@ public class FileParse
 
   public File inFile = null;
 
+  private AlignViewportI viewport;
+
   public int index = 1; // sequence counter for FileParse object created from
 
   // same data source
@@ -488,4 +491,14 @@ public class FileParse
     }
     return null;
   }
+
+  public AlignViewportI getViewport()
+  {
+    return viewport;
+  }
+
+  public void setViewport(AlignViewportI viewport)
+  {
+    this.viewport = viewport;
+  }
 }
index 86ec140..7c117b9 100755 (executable)
@@ -37,10 +37,20 @@ import jalview.datamodel.SequenceI;
  */
 public class FormatAdapter extends AppletFormatAdapter
 {
+  public FormatAdapter(AlignViewportI viewport)
+  {
+    super(viewport);
+    init();
+  }
 
   public FormatAdapter()
   {
     super();
+    init();
+  }
+
+  private void init()
+  {
     if (jalview.bin.Cache.getDefault("STRUCT_FROM_PDB", true))
     {
       annotFromStructure = jalview.bin.Cache.getDefault("ADD_TEMPFACT_ANN",
@@ -58,6 +68,7 @@ public class FormatAdapter extends AppletFormatAdapter
       serviceSecondaryStruct = false;
     }
   }
+
   public String formatSequences(String format, SequenceI[] seqs,
           String[] omitHiddenColumns)
   {
index 7272830..fd07893 100644 (file)
@@ -15,7 +15,9 @@ public class HtmlFile extends AlignFile
 
   public static final String FILE_DESC = "HTML";
 
-  private ColourSchemeI cs;
+  private ColourSchemeI colourScheme;
+
+  private boolean showSeqFeatures;
 
   public HtmlFile()
   {
@@ -52,6 +54,8 @@ public class HtmlFile extends AlignFile
       seqs = jsonFile.seqs;
       seqGroups = jsonFile.seqGroups;
       annotations = jsonFile.annotations;
+      showSeqFeatures = jsonFile.isShowSeqFeatures();
+      colourScheme = jsonFile.getColourScheme();
     } catch (Exception e)
     {
       e.printStackTrace();
@@ -60,8 +64,8 @@ public class HtmlFile extends AlignFile
 
   public void LoadAlignmentFeatures(AlignFrame af)
   {
-    af.setShowSeqFeatures(JSONFile.isSeqFeaturesEnabled());
-    af.changeColour(JSONFile.getColourScheme());
+    af.setShowSeqFeatures(isShowSeqFeatures());
+    af.changeColour(getColourScheme());
     af.setMenusForViewport();
   }
 
@@ -73,4 +77,24 @@ public class HtmlFile extends AlignFile
             "Print method of HtmlFile not yet supported!");
   }
 
+  public boolean isShowSeqFeatures()
+  {
+    return showSeqFeatures;
+  }
+
+  public void setShowSeqFeatures(boolean showSeqFeatures)
+  {
+    this.showSeqFeatures = showSeqFeatures;
+  }
+
+  public ColourSchemeI getColourScheme()
+  {
+    return colourScheme;
+  }
+
+  public void setColourScheme(ColourSchemeI colourScheme)
+  {
+    this.colourScheme = colourScheme;
+  }
+
 }
index 64dfc1c..db34c2f 100644 (file)
@@ -1,12 +1,9 @@
 package jalview.io;
 
-import jalview.datamodel.Alignment;
-import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.SequenceI;
 import jalview.gui.AlignViewport;
 import jalview.gui.AlignmentPanel;
 import jalview.gui.AnnotationPanel;
-import jalview.gui.Desktop;
 import jalview.gui.FeatureRenderer;
 import jalview.gui.HTMLOptions;
 import jalview.math.AlignmentDimension;
@@ -37,6 +34,7 @@ public class HtmlSvgOutput
 
       this.av = ap.av;
       this.ap = ap;
+    av.setFeatureRenderer(new FeatureRenderer(ap));
       this.annotationPanel = ap.getAnnotationPanel();
     generateHtmlSvgOutput(file);
   }
@@ -103,7 +101,7 @@ public class HtmlSvgOutput
 
       String titleSvgData = g1.getSVGDocument();
       String alignSvgData = g2.getSVGDocument();
-      String jsonData = getJSONData();
+      String jsonData = JSONFile.getJSONData(av);
       String htmlData = getHtml(titleSvgData, alignSvgData, jsonData);
 
       out.write(htmlData.getBytes());
@@ -261,39 +259,6 @@ public class HtmlSvgOutput
     return Printable.PAGE_EXISTS;
   }
   
-  private String getJSONData()
-  {
-    JSONFile jsonFile = new JSONFile();
-    Alignment al = new Alignment(av.getAlignment().getSequencesArray());
-    jsonFile.seqGroups = av.getAlignment().getGroups();
-    // jsonFile.addAnnotations(al);
-    jsonFile.setDisplayedFeatures(av.getFeaturesDisplayed());
-    Desktop.setCurrentAlignFrame(av.getAlignPanel().alignFrame);
-    for (SequenceI seq : av.getAlignment().getSequences())
-    {
-      jsonFile.seqs.add(seq);
-    }
-
-    // Add non auto calculated annotation to AlignFile
-    for (AlignmentAnnotation annot : av.getAlignment()
-            .getAlignmentAnnotation())
-    {
-      if (annot != null && !annot.autoCalculated)
-      {
-        if (annot.label.equals("PDB.CATempFactor"))
-        {
-          continue;
-        }
-        jsonFile.annotations.add(annot);
-      }
-    }
-
-    // jsonFile.setGlobalColorScheme(av.getGlobalColourScheme());
-    String jsonString = jsonFile.print();
-    System.out.println(">>>>>>>>>>> JSONFile : " + jsonString);
-    return jsonString;
-  }
-
   private String getHtml(String titleSvg, String alignmentSvg,
           String jsonData)
   {
index e38812c..fcedb2b 100644 (file)
@@ -1,5 +1,7 @@
 package jalview.io;
 
+import jalview.api.AlignViewportI;
+import jalview.api.FeatureRenderer;
 import jalview.api.FeaturesDisplayedI;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.Annotation;
@@ -8,7 +10,6 @@ import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.gui.AlignFrame;
-import jalview.gui.Desktop;
 import jalview.json.binding.v1.AlignmentAnnotationPojo;
 import jalview.json.binding.v1.AlignmentPojo;
 import jalview.json.binding.v1.AnnotationPojo;
@@ -19,8 +20,8 @@ import jalview.json.binding.v1.SequenceGrpPojo;
 import jalview.json.binding.v1.SequencePojo;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.ColourSchemeProperty;
-import jalview.viewmodel.AlignmentViewport;
 
+import java.awt.Color;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Hashtable;
@@ -34,13 +35,13 @@ import org.json.simple.parser.JSONParser;
 
 public class JSONFile extends AlignFile
 {
-  private static ColourSchemeI colourScheme;
+  private ColourSchemeI colourScheme;
 
-  private static boolean seqFeaturesEnabled;
+  // private static boolean seqFeaturesEnabled;
 
   private String jalviewVersion;
 
-  private String webStartLaunchServletUrl = "http://www.jalview.org/services/launchApp";
+  private String webStartLaunchServletUrl;
 
   public static final String FILE_EXT = "json";
 
@@ -54,7 +55,9 @@ public class JSONFile extends AlignFile
 
   private FeaturesDisplayedI displayedFeatures;
 
-  private AlignmentViewport av;
+  // private AlignViewportI viewport;
+
+  private FeatureRenderer fr;
 
   private JSONExportSettings jsonExportSettings;
 
@@ -101,15 +104,15 @@ public class JSONFile extends AlignFile
       }
 
       AlignmentPojo jsonAlignmentPojo = new AlignmentPojo();
-      if (Desktop.getCurrentAlignFrame() != null)
+      if (getViewport() != null)
       {
-        globalColorScheme = ColourSchemeProperty.getColourName(Desktop
-                .getCurrentAlignFrame().getViewport()
+        globalColorScheme = ColourSchemeProperty
+                .getColourName(getViewport()
                 .getGlobalColourScheme());
-        this.av = Desktop.getCurrentAlignFrame().getCurrentView();
-        setDisplayedFeatures(av.getFeaturesDisplayed());
-        showSeqFeatures = Desktop.getCurrentAlignFrame().showSeqFeatures
-                .isSelected();
+        setDisplayedFeatures(getViewport().getFeaturesDisplayed());
+        showSeqFeatures = getViewport().isShowSequenceFeatures();
+        fr = getViewport().getFeatureRenderer();
+        // setSeqFeaturesEnabled(viewport.isShowSequenceFeatures());
       }
 
       int count = 0;
@@ -130,6 +133,11 @@ public class JSONFile extends AlignFile
 
       if (jsonExportSettings.isExportJalviewSettings())
       {
+        jalviewVersion = jalview.bin.Cache.getProperty("VERSION");
+        webStartLaunchServletUrl = jalview.bin.Cache.getDefault(
+                "www.jalview.org", "http://www.jalview.org")
+                + "/services/launchApp";
+
         JalviewSettingsPojo jvSettings = new JalviewSettingsPojo();
         jvSettings.setGlobalColorScheme(globalColorScheme);
         jvSettings.setJalviewVersion(jalviewVersion);
@@ -146,8 +154,8 @@ public class JSONFile extends AlignFile
 
       if (jsonExportSettings.isExportSequenceFeatures())
       {
-        jsonAlignmentPojo.setSeqFeatures(sequenceFeatureToJsonPojo(seqs,
-                getDisplayedFeatures()));
+        jsonAlignmentPojo
+                .setSeqFeatures(sequenceFeatureToJsonPojo(seqs, fr));
       }
 
       if (jsonExportSettings.isExportGroups() && seqGroups != null
@@ -187,8 +195,10 @@ public class JSONFile extends AlignFile
   }
 
   public static List<SequenceFeaturesPojo> sequenceFeatureToJsonPojo(
-          List<SequenceI> seqs, FeaturesDisplayedI displayedFeatures)
+          List<SequenceI> seqs, FeatureRenderer fr)
   {
+    FeaturesDisplayedI displayedFeatures = (fr == null) ? null : fr
+            .getFeaturesDisplayed();
     List<SequenceFeaturesPojo> sequenceFeaturesPojo = new ArrayList<SequenceFeaturesPojo>();
     for (SequenceI seq : seqs)
     {
@@ -208,6 +218,10 @@ public class JSONFile extends AlignFile
         {
           SequenceFeaturesPojo jsonFeature = new SequenceFeaturesPojo(
                   seq.getName() + "_" + seq.hashCode());
+          String featureColour = (fr == null) ? null : jalview.util.Format
+                  .getHexString(fr
+                  .findFeatureColour(Color.white, seq,
+                          seq.findIndex(sf.getBegin())));
           jsonFeature.setXstart(seq.findIndex(sf.getBegin()) - 1);
           jsonFeature.setXend(seq.findIndex(sf.getEnd()));
           jsonFeature.setType(sf.getType());
@@ -215,6 +229,7 @@ public class JSONFile extends AlignFile
           jsonFeature.setLinks(sf.links);
           jsonFeature.setOtherDetails(sf.otherDetails);
           jsonFeature.setScore(sf.getScore());
+          jsonFeature.setFillColor(featureColour);
           jsonFeature.setFeatureGroup(sf.getFeatureGroup());
           sequenceFeaturesPojo.add(jsonFeature);
         }
@@ -283,7 +298,8 @@ public class JSONFile extends AlignFile
         Boolean showFeatures = Boolean.valueOf(jvSettingsJsonObj.get(
                 "showSeqFeatures").toString());
         setColourScheme(getJalviewColorScheme(jsColourScheme));
-        JSONFile.setSeqFeaturesEnabled(showFeatures);
+        // JSONFile.setSeqFeaturesEnabled(showFeatures);
+        setShowSeqFeatures(showFeatures);
       }
 
       seqMap = new Hashtable<String, Sequence>();
@@ -435,7 +451,8 @@ public class JSONFile extends AlignFile
     }
   }
 
-  public ColourSchemeI getJalviewColorScheme(String bioJsColourSchemeName)
+  public static ColourSchemeI getJalviewColorScheme(
+          String bioJsColourSchemeName)
   {
     ColourSchemeI jalviewColor = null;
     for (JalviewBioJsColorSchemeMapper cs : JalviewBioJsColorSchemeMapper
@@ -452,7 +469,7 @@ public class JSONFile extends AlignFile
 
   public void LoadAlignmentFeatures(AlignFrame af)
   {
-    af.setShowSeqFeatures(JSONFile.isSeqFeaturesEnabled());
+    af.setShowSeqFeatures(isShowSeqFeatures());
     af.changeColour(getColourScheme());
     af.setMenusForViewport();
   }
@@ -467,24 +484,14 @@ public class JSONFile extends AlignFile
     this.globalColorScheme = globalColorScheme;
   }
 
-  public static ColourSchemeI getColourScheme()
+  public ColourSchemeI getColourScheme()
   {
     return colourScheme;
   }
 
-  public static void setColourScheme(ColourSchemeI colourScheme)
-  {
-    JSONFile.colourScheme = colourScheme;
-  }
-
-  public static boolean isSeqFeaturesEnabled()
-  {
-    return seqFeaturesEnabled;
-  }
-
-  public static void setSeqFeaturesEnabled(boolean seqFeaturesEnabled)
+  public void setColourScheme(ColourSchemeI colourScheme)
   {
-    JSONFile.seqFeaturesEnabled = seqFeaturesEnabled;
+    this.colourScheme = colourScheme;
   }
 
   public FeaturesDisplayedI getDisplayedFeatures()
@@ -507,6 +514,45 @@ public class JSONFile extends AlignFile
     this.jsonExportSettings = jsonExportSettings;
   }
 
+  public static String getJSONData(AlignViewportI av)
+  {
+    JSONFile jsonFile = new JSONFile();
+    jsonFile.setViewport(av);
+    jsonFile.seqGroups = av.getAlignment().getGroups();
+    jsonFile.setDisplayedFeatures(av.getFeaturesDisplayed());
+
+    for (SequenceI seq : av.getAlignment().getSequences())
+    {
+      jsonFile.seqs.add(seq);
+    }
+  
+    // Add non auto calculated annotation to AlignFile
+    for (AlignmentAnnotation annot : av.getAlignment()
+            .getAlignmentAnnotation())
+    {
+      if (annot != null && !annot.autoCalculated)
+      {
+        if (annot.label.equals("PDB.CATempFactor"))
+        {
+          continue;
+        }
+        jsonFile.annotations.add(annot);
+      }
+    }
+    String jsonString = jsonFile.print();
+    return jsonString;
+  }
+
+  public boolean isShowSeqFeatures()
+  {
+    return showSeqFeatures;
+  }
+
+  public void setShowSeqFeatures(boolean showSeqFeatures)
+  {
+    this.showSeqFeatures = showSeqFeatures;
+  }
+
   public class JSONExportSettings
   {
     private boolean exportSequence;
index d8508ad..c69d811 100644 (file)
@@ -20,6 +20,8 @@ public class SequenceFeaturesPojo
 
   private Hashtable otherDetails;
 
+  private String fillColor;
+
   private String featureGroup;
 
   private Vector<String> links;
@@ -33,15 +35,15 @@ public class SequenceFeaturesPojo
     this.sequenceRef = sequenceRef;
   }
 
-  // public String getFillColor()
-  // {
-  // return "#" + fillColor;
-  // }
-  //
-  // public void setFillColor(String fillColor)
-  // {
-  // this.fillColor = fillColor;
-  // }
+  public String getFillColor()
+  {
+    return "#" + fillColor;
+  }
+
+  public void setFillColor(String fillColor)
+  {
+    this.fillColor = fillColor;
+  }
 
   public int getXstart()
   {
index bb8784a..8c4b639 100644 (file)
 package jalview.io;
 
-import jalview.datamodel.Alignment;
-import jalview.datamodel.Sequence;
+import org.junit.Ignore;
+import org.junit.Test;
 
-import java.io.IOException;
-import java.util.Iterator;
-
-import org.json.simple.JSONArray;
-import org.json.simple.JSONObject;
-import org.json.simple.parser.JSONParser;
-import org.json.simple.parser.ParseException;
-import org.junit.Assert;
-
-import com.json.JSONException;
 
 public class BioJsHTMLOutputTest
 {
 
 
-  // @Test
+  @Test
+  @Ignore
   public void getJalviewAlignmentAsJsonString()
   {
     BioJsHTMLOutput bioJsHtmlOuput = new BioJsHTMLOutput(null, null);
-    bioJsHtmlOuput.setGlobalColorScheme("Zappo");
-
-    Sequence[] seqs = new Sequence[1];
-    Sequence seq = new Sequence("name", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1, 26);
-    // SequenceFeature seqFeature = new SequenceFeature("type", "desc",
-    // "status", 1, 5, "jalview");
-    // seq.addSequenceFeature(seqFeature);
-    seq.setDatasetSequence(seq);
-    seqs[0] = seq;
-
-    Alignment al = new Alignment(seqs);
-    try
-    {
-
-      JSONParser jsonParser = new JSONParser();
-      String actualJsonString = bioJsHtmlOuput
-              .getJalviewAlignmentAsJsonString(al);
-
-      JSONObject actualJsonObj = (JSONObject) jsonParser.parse(actualJsonString);
-
-      // System.out.println("Output : " + actualJsonString);
-      Assert.assertTrue(actualJsonObj.get("globalColorScheme") != null); 
-      Assert.assertTrue((actualJsonObj.get("globalColorScheme").toString()).equals("zappo")); 
-      
-      Assert.assertTrue(actualJsonObj.get("webStartUrl") != null);
-      Assert.assertTrue((actualJsonObj.get("webStartUrl").toString())
-              .equals("http://www.jalview.org/services/launchApp"));
-
-      JSONArray actualSeqJsonObj = (JSONArray) actualJsonObj.get("seqs");
-      Assert.assertTrue(actualSeqJsonObj != null);
-      Assert.assertTrue(actualSeqJsonObj.size() == 1);
-
-      @SuppressWarnings("unchecked")
-      Iterator<JSONObject> jsonIter = actualSeqJsonObj.iterator();
-      JSONObject jsonSeq = jsonIter.next();
-      Assert.assertTrue(jsonSeq != null);
-
-      Assert.assertTrue("'name' cannot be null!",
-              jsonSeq.get("name") != null);
-      Assert.assertTrue("Expected name mismatched!",
-              (jsonSeq.get("name").toString())
-              .equals("name/1-26"));
-
-      Assert.assertTrue("'seq' cannot be null!", jsonSeq.get("seq") != null);
-      Assert.assertTrue("Expected sequence mismatched!", (jsonSeq
-              .get("seq").toString())
-              .equals("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
-
-      Assert.assertTrue("'id' cannot be null!", jsonSeq.get("id") != null);
-      Assert.assertTrue("Expected id mismatched!",
-              (jsonSeq.get("id").toString()).equals("1"));
-
-      Assert.assertTrue("'start' cannot be null!",
-              jsonSeq.get("start") != null);
-      Assert.assertTrue("Expected start mismatched!",
-              (jsonSeq.get("start").toString()).equals("1"));
-
-      Assert.assertTrue("'end' cannot be null!", jsonSeq.get("end") != null);
-      Assert.assertTrue("Expected end mismatched!",
-              (jsonSeq.get("end").toString()).equals("26"));
-
-      Assert.assertTrue("'features' cannot be null!",
-              jsonSeq.get("features") != null);
-      Assert.assertTrue("Expected features mismatched!",
-              jsonSeq.get("features").toString().equals("[]"));
 
-    } catch (IOException e)
-    {
-      e.printStackTrace();
-    } catch (JSONException e)
-    {
-      e.printStackTrace();
-    } catch (ParseException e)
-    {
-      e.printStackTrace();
-    }
   }
   
 }
index d2960d9..92b172c 100644 (file)
@@ -1,15 +1,23 @@
 package jalview.io;
 
+
+import static org.junit.Assert.assertNotNull;
+import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentI;
 import jalview.datamodel.Annotation;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
+import jalview.gui.AlignFrame;
+import jalview.gui.AlignmentPanel;
 import jalview.schemes.ColourSchemeI;
 import jalview.viewmodel.seqfeatures.FeaturesDisplayed;
 
+import java.io.IOException;
 import java.util.ArrayList;
+import java.util.HashMap;
 
 import org.junit.After;
 import org.junit.Assert;
@@ -18,7 +26,6 @@ import org.junit.Test;
 
 public class JSONFileTest
 {
-  private JSONFile jsonFile;
 
   private int TEST_SEQ_HEIGHT = 0;
 
@@ -26,11 +33,19 @@ public class JSONFileTest
 
   private int TEST_ANOT_HEIGHT = 0;
 
+  private AlignFrame af;
+
+  AlignmentI alignment;
+
+  AlignmentPanel alignPanel;
+
+  HashMap<String, SequenceI> testSeqs = new HashMap<String, SequenceI>();
+  HashMap<String, AlignmentAnnotation> testAnnots = new HashMap<String, AlignmentAnnotation>();
+  HashMap<String, SequenceGroup> testGrps = new HashMap<String, SequenceGroup>();
+
   @Before
-  public void setUp() throws Exception
+  public void setup() throws Exception
   {
-    jsonFile = new JSONFile();
-
     // create and add sequences
     Sequence[] seqs = new Sequence[5];
     seqs[0] = new Sequence("FER_CAPAN",
@@ -46,11 +61,11 @@ public class JSONFileTest
 
     // create and add sequence features
     SequenceFeature seqFeature2 = new SequenceFeature("feature_x",
-            "desciption", "status", 22, 29, "jalview");
+            "desciption", "status", 6, 15, "Jalview");
     SequenceFeature seqFeature3 = new SequenceFeature("feature_x",
-            "desciption", "status", 25, 32, "jalview");
+            "desciption", "status", 9, 18, "Jalview");
     SequenceFeature seqFeature4 = new SequenceFeature("feature_x",
-            "desciption", "status", 25, 32, "jalview");
+            "desciption", "status", 9, 18, "Jalview");
     seqs[2].addSequenceFeature(seqFeature2);
     seqs[3].addSequenceFeature(seqFeature3);
     seqs[4].addSequenceFeature(seqFeature4);
@@ -58,26 +73,29 @@ public class JSONFileTest
     // add created features to features displayed
     FeaturesDisplayed fDis = new FeaturesDisplayed();
     fDis.setVisible("feature_x");
-    jsonFile.setDisplayedFeatures(fDis);
-    JSONFile.setSeqFeaturesEnabled(true);
+    // jsonFile.setDisplayedFeatures(fDis);
+    // jsonFile.setShowSeqFeatures(true);
 
     for (Sequence seq : seqs)
     {
       seq.setDatasetSequence(seq);
-      jsonFile.seqs.add(seq);
+      testSeqs.put(seq.getName(), seq);
+      // jsonFile.seqs.add(seq);
     }
 
     // create and add sequence groups
     ArrayList<SequenceI> grpSeqs = new ArrayList<SequenceI>();
-    grpSeqs.add(seqs[0]);
     grpSeqs.add(seqs[1]);
     grpSeqs.add(seqs[2]);
-    ColourSchemeI scheme = jsonFile.getJalviewColorScheme("zappo");
-    SequenceGroup seqGrp = new SequenceGroup(grpSeqs, "JGroup:1114606272",
-            scheme, true, true, false, 2, 9);
+    grpSeqs.add(seqs[3]);
+    grpSeqs.add(seqs[4]);
+    ColourSchemeI scheme = JSONFile.getJalviewColorScheme("zappo");
+    SequenceGroup seqGrp = new SequenceGroup(grpSeqs, "JGroup:1883305585",
+            scheme, true, true, false, 21, 29);
     seqGrp.setShowNonconserved(false);
     seqGrp.setDescription(null);
-    jsonFile.seqGroups.add(seqGrp);
+    // jsonFile.seqGroups.add(seqGrp);
+    testGrps.put(seqGrp.getName(), seqGrp);
 
     // create and add annotation
     Annotation[] annot = new Annotation[35];
@@ -86,46 +104,46 @@ public class JSONFileTest
     annot[2] = new Annotation("α", "", 'H', 0);
     annot[3] = new Annotation("α", "", 'H', 0);
     annot[4] = new Annotation("α", "", 'H', 0);
-    annot[5] = new Annotation("α", "", 'H', 0);
+    annot[5] = new Annotation("", "", '\u0000', 0);
     annot[6] = new Annotation("", "", '\u0000', 0);
     annot[7] = new Annotation("", "", '\u0000', 0);
-    annot[8] = new Annotation("", "", '\u0000', 0);
-    annot[9] = new Annotation("", "", '\u0000', 0);
+    annot[8] = new Annotation("β", "", 'E', 0);
+    annot[9] = new Annotation("β", "", 'E', 0);
     annot[10] = new Annotation("β", "", 'E', 0);
     annot[11] = new Annotation("β", "", 'E', 0);
-    annot[12] = new Annotation("", "", '\u0000', 0);
-    annot[13] = new Annotation("", "", '\u0000', 0);
-    annot[14] = new Annotation("", "", '\u0000', 0);
-    annot[15] = new Annotation("", "", '\u0000', 0);
-    annot[16] = new Annotation("α", "", 'H', 0);
-    annot[17] = new Annotation("α", "", 'H', 0);
-    annot[18] = new Annotation("α", "", 'H', 0);
-    annot[19] = new Annotation("α", "", 'H', 0);
-    annot[20] = new Annotation("α", "", 'H', 0);
-
+    annot[12] = new Annotation("β", "", 'E', 0);
+    annot[13] = new Annotation("β", "", 'E', 0);
+    annot[14] = new Annotation("β", "", 'E', 0);
+    annot[15] = new Annotation("β", "", 'E', 0);
+    annot[16] = new Annotation("", "", '\u0000', 0);
+    annot[17] = new Annotation("", "", '\u0000', 0);
+    annot[18] = new Annotation("", "", '\u0000', 0);
+    annot[19] = new Annotation("", "", '\u0000', 0);
+    annot[20] = new Annotation("", "", '\u0000', 0);
     annot[21] = new Annotation("", "", '\u0000', 0);
     annot[22] = new Annotation("", "", '\u0000', 0);
     annot[23] = new Annotation("", "", '\u0000', 0);
     annot[24] = new Annotation("", "", '\u0000', 0);
     annot[25] = new Annotation("", "", '\u0000', 0);
-    annot[26] = new Annotation("", "", '\u0000', 0);
-    annot[27] = new Annotation("", "", '\u0000', 0);
-    annot[28] = new Annotation("", "", '\u0000', 0);
-    annot[29] = new Annotation("", "", '\u0000', 0);
-    annot[30] = new Annotation("", "", '\u0000', 0);
+    annot[26] = new Annotation("α", "", 'H', 0);
+    annot[27] = new Annotation("α", "", 'H', 0);
+    annot[28] = new Annotation("α", "", 'H', 0);
+    annot[29] = new Annotation("α", "", 'H', 0);
+    annot[30] = new Annotation("α", "", 'H', 0);
     annot[31] = new Annotation("", "", '\u0000', 0);
-    annot[32] = new Annotation("β", "", 'E', 0);
-    annot[33] = new Annotation("β", "", 'E', 0);
-    annot[34] = new Annotation("β", "", 'E', 0);
+    annot[32] = new Annotation("", "", '\u0000', 0);
+    annot[33] = new Annotation("", "", '\u0000', 0);
+    annot[34] = new Annotation("", "", '\u0000', 0);
 
     AlignmentAnnotation alignAnnot = new AlignmentAnnotation(
             "Secondary Structure", "New description", annot);
-    jsonFile.annotations.add(alignAnnot);
+    // jsonFile.annotations.add(alignAnnot);
+    testAnnots.put(alignAnnot.label, alignAnnot);
 
     // Alignment al = new Alignment(seqs);
-    TEST_SEQ_HEIGHT = jsonFile.seqs.size();
-    TEST_GRP_HEIGHT = jsonFile.seqGroups.size();
-    TEST_ANOT_HEIGHT = jsonFile.annotations.size();
+    TEST_SEQ_HEIGHT = testSeqs.size();
+    TEST_GRP_HEIGHT = testGrps.size();
+    TEST_ANOT_HEIGHT = testAnnots.size();
   }
 
   @After
@@ -134,77 +152,134 @@ public class JSONFileTest
   }
 
   @Test
-  public void test()
+  public void testParse()
   {
-    String jsonOuput = jsonFile.print();
-    // System.out.println(">>>>>>>>>>>>>> " + jsonOuput);
-    JSONFile output = new JSONFile().parse(jsonOuput);
+    String jsonFile = "examples/example.json";
+    AppletFormatAdapter rf = new AppletFormatAdapter();
+    Alignment al = null;
+    try
+    {
+      al = rf.readFile(jsonFile, AppletFormatAdapter.FILE,
+              JSONFile.FILE_DESC);
+    } catch (IOException e)
+    {
+      e.printStackTrace();
+    }
+    assertNotNull("Couldn't read supplied alignment data.", al);
 
-    int matchedCounter = 0;
-    for (SequenceI in : jsonFile.getSeqs())
+    int passedCount = 0;
+    for (SequenceI seq : al.getSequences())
     {
-      for (SequenceI out : output.getSeqs())
-      {
-        if (in.getName().equals(out.getName())
-                && in.getSequenceAsString().equals(
-                        out.getSequenceAsString())
-                && in.getStart() == out.getStart()
-                && in.getEnd() == out.getEnd() && featuresMatched(in, out))
-        {
-          // System.out.println(">>>> Seq Match Detected");
-          ++matchedCounter;
-        }
-      }
+      SequenceI expectedSeq = testSeqs.get(seq.getName());
+      Assert.assertTrue("Failed Sequence Test  for >>> " + seq.getName(),
+              isSeqMatched(expectedSeq, seq));
+      passedCount++;
     }
-    Assert.assertTrue(matchedCounter == TEST_SEQ_HEIGHT);
+    Assert.assertEquals("Some Sequences did not pass the test",
+            TEST_SEQ_HEIGHT, passedCount);
 
-    matchedCounter = 0;
-    for (SequenceGroup in : jsonFile.getSeqGroups())
+    passedCount = 0;
+    for (SequenceGroup seqGrp : al.getGroups())
     {
-      for (SequenceGroup out : output.getSeqGroups())
-      {
-        if (in.getName().equals(out.getName())
-                && in.getColourText() == out.getColourText()
-                && in.getDisplayBoxes() == out.getDisplayBoxes()
-                && in.getIgnoreGapsConsensus() == out
-                        .getIgnoreGapsConsensus() && in.cs.equals(out.cs)
-                && in.getSequences().size() == out.getSequences().size())
-        {
-          // System.out.println(">>>> Grp Match Detected");
-          ++matchedCounter;
-        }
-      }
+      SequenceGroup expectedGrp = testGrps.get(seqGrp.getName());
+      Assert.assertTrue(
+              "Failed SequenceGroup Test for >>> " + seqGrp.getName(),
+              isGroupMatched(expectedGrp, seqGrp));
+      passedCount++;
     }
-    Assert.assertTrue(matchedCounter == TEST_GRP_HEIGHT);
+    Assert.assertEquals("Some SequenceGroups did not pass the test",
+            TEST_GRP_HEIGHT, passedCount);
 
-    matchedCounter = 0;
-    for (AlignmentAnnotation in : jsonFile.annotations)
+    passedCount = 0;
+    for (AlignmentAnnotation annot : al.getAlignmentAnnotation())
     {
-      for (AlignmentAnnotation out : output.annotations)
+      AlignmentAnnotation expectedAnnot = testAnnots.get(annot.label);
+      Assert.assertTrue("Failed AlignmentAnnotation Test for >>> "
+              + annot.label, isAnnotationMatched(expectedAnnot, annot));
+      passedCount++;
+    }
+    Assert.assertEquals("Some Sequences did not pass the test",
+            TEST_ANOT_HEIGHT, passedCount);
+
+    // af = new AlignFrame(al, 700, 500);
+    // AlignViewport viewport = af.getViewport();
+    // alignPanel = new AlignmentPanel(af, viewport);
+  }
+
+  public boolean isAnnotationMatched(AlignmentAnnotation eAnnot,
+          AlignmentAnnotation annot)
+  {
+    if (!eAnnot.label.equals(annot.label)
+            || !eAnnot.description.equals(annot.description)
+            || eAnnot.annotations.length != annot.annotations.length)
+    {
+      return false;
+    }
+
+    for (int x = 0; x < annot.annotations.length; x++)
+    {
+      Annotation y = annot.annotations[x];
+      Annotation z = annot.annotations[x];
+
+      if (!y.displayCharacter.equals(z.displayCharacter)
+              || y.value != z.value
+              || y.secondaryStructure != z.secondaryStructure)
       {
-        try
-        {
-          // System.out.println("label >>>>> " + in.label + " | " + out.label);
-          // System.out.println("label >>>>> " + in.description + " | "
-          // + out.description);
-          // System.out.println("label >>>>> " + in.annotations.length + " | "
-          // + out.annotations.length);
-          if (in.label.equals(out.label)
-                  && in.description.equals(out.description)
-                && in.annotations.length == out.annotations.length)
-        {
-          ++matchedCounter;
-        }
-        } catch (Exception e)
-        {
-          e.printStackTrace();
-        }
+        return false;
       }
     }
-    // System.out.println("matched >>>>> " + matchedCounter + " | "
-    // + TEST_ANOT_HEIGHT);
-    Assert.assertTrue(matchedCounter == TEST_ANOT_HEIGHT);
+    return true;
+  }
+
+  public boolean isSeqMatched(SequenceI expectedSeq, SequenceI actualSeq)
+  {
+    System.out.println("Testing >>> " + actualSeq.getName());
+
+    if (expectedSeq.getName().equals(actualSeq.getName())
+            && expectedSeq.getSequenceAsString().equals(
+                    actualSeq.getSequenceAsString())
+            && expectedSeq.getStart() == actualSeq.getStart()
+            && expectedSeq.getEnd() == actualSeq.getEnd()
+            && featuresMatched(expectedSeq, actualSeq))
+    {
+      return true;
+    }
+    return false;
+  }
 
+  public boolean isGroupMatched(SequenceGroup expectedGrp,
+          SequenceGroup actualGrp)
+  {
+
+    System.out.println("Testing >>> " + actualGrp.getName());
+    System.out.println(expectedGrp.getName() + " | " + actualGrp.getName());
+    System.out.println(expectedGrp.getColourText() + " | "
+            + actualGrp.getColourText());
+    System.out.println(expectedGrp.getDisplayBoxes() + " | "
+            + actualGrp.getDisplayBoxes());
+    System.out.println(expectedGrp.getIgnoreGapsConsensus() + " | "
+            + actualGrp.getIgnoreGapsConsensus());
+    System.out.println(expectedGrp.getSequences().size() + " | "
+            + actualGrp.getSequences().size());
+    System.out.println(expectedGrp.getStartRes() + " | "
+            + actualGrp.getStartRes());
+    System.out.println(expectedGrp.getEndRes() + " | "
+            + actualGrp.getEndRes());
+
+    if (expectedGrp.getName().equals(actualGrp.getName())
+            && expectedGrp.getColourText() == actualGrp.getColourText()
+            && expectedGrp.getDisplayBoxes() == actualGrp.getDisplayBoxes()
+            && expectedGrp.getIgnoreGapsConsensus() == actualGrp
+                    .getIgnoreGapsConsensus()
+            && expectedGrp.cs.equals(actualGrp.cs)
+            && expectedGrp.getSequences().size() == actualGrp
+                    .getSequences().size()
+            && expectedGrp.getStartRes() == actualGrp.getStartRes()
+            && expectedGrp.getEndRes() == actualGrp.getEndRes())
+    {
+      return true;
+    }
+    return false;
   }
 
   private boolean featuresMatched(SequenceI seq1, SequenceI seq2)
@@ -232,22 +307,27 @@ public class JSONFileTest
 
       int testSize = inFeature.length;
       int matchedCount = 0;
-      // System.out.println(">>>>>>>>>>>>> 1");
       for (SequenceFeature in : inFeature)
       {
-        for (SequenceFeature out : inFeature)
+        for (SequenceFeature out : outFeature)
         {
+          System.out.println(out.getType() + " | " + in.getType());
+          System.out.println(out.getBegin() + " | " + in.getBegin());
+          System.out.println(out.getEnd() + " | " + in.getEnd());
+
           if (inFeature.length == outFeature.length
                   && in.getBegin() == out.getBegin()
                   && in.getEnd() == out.getEnd()
                   && in.getScore() == out.getScore()
-                  && in.getFeatureGroup().equals(out.getFeatureGroup()))
+                  && in.getFeatureGroup().equals(out.getFeatureGroup())
+                  && in.getType().equals(out.getType()))
           {
 
             ++matchedCount;
           }
         }
       }
+      System.out.println("matched count >>>>>> " + matchedCount);
       if (testSize == matchedCount)
       {
         matched = true;