JAL-1369 dead code TODO?
[jalview.git] / src / jalview / gui / Jalview2XML.java
index 2434b00..5c5d209 100644 (file)
@@ -20,6 +20,7 @@
  */
 package jalview.gui;
 
+import jalview.api.ViewStyleI;
 import jalview.api.structures.JalviewStructureDisplayI;
 import jalview.bin.Cache;
 import jalview.datamodel.AlignedCodonFrame;
@@ -78,6 +79,7 @@ import jalview.structure.StructureSelectionManager;
 import jalview.structures.models.AAStructureBindingModel;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
+import jalview.util.StringUtils;
 import jalview.util.jarInputStreamProvider;
 import jalview.viewmodel.AlignmentViewport;
 import jalview.viewmodel.seqfeatures.FeatureRendererSettings;
@@ -89,6 +91,7 @@ import jalview.ws.params.ArgumentI;
 import jalview.ws.params.AutoCalcSetting;
 import jalview.ws.params.WsParamSetI;
 
+import java.awt.Color;
 import java.awt.Rectangle;
 import java.io.BufferedReader;
 import java.io.DataInputStream;
@@ -115,7 +118,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
-import java.util.StringTokenizer;
 import java.util.Vector;
 import java.util.jar.JarEntry;
 import java.util.jar.JarInputStream;
@@ -162,7 +164,7 @@ public class Jalview2XML
    */
   Map<String, SequenceI> seqRefIds = null;
 
-  Vector frefedSequence = null;
+  Vector<Object[]> frefedSequence = null;
 
   boolean raiseGUI = true; // whether errors are raised in dialog boxes or not
 
@@ -257,7 +259,7 @@ public class Jalview2XML
       int r = 0, rSize = frefedSequence.size();
       while (r < rSize)
       {
-        Object[] ref = (Object[]) frefedSequence.elementAt(r);
+        Object[] ref = frefedSequence.elementAt(r);
         if (ref != null)
         {
           String sref = (String) ref[0];
@@ -632,11 +634,15 @@ public class Jalview2XML
     object.setVersion(jalview.bin.Cache.getDefault("VERSION",
             "Development Build"));
 
-    jalview.datamodel.AlignmentI jal = av.getAlignment();
+    /**
+     * rjal is full height alignment, jal is actual alignment with full metadata
+     * but excludes hidden sequences.
+     */
+    jalview.datamodel.AlignmentI rjal = av.getAlignment(), jal = rjal;
 
     if (av.hasHiddenRows())
     {
-      jal = jal.getHiddenSequences().getFullAlignment();
+      rjal = jal.getHiddenSequences().getFullAlignment();
     }
 
     SequenceSet vamsasSet = new SequenceSet();
@@ -653,6 +659,7 @@ public class Jalview2XML
       {
         // switch jal and the dataset
         jal = jal.getDataset();
+        rjal = jal;
       }
     }
     if (jal.getProperties() != null)
@@ -672,12 +679,11 @@ public class Jalview2XML
     Set<String> calcIdSet = new HashSet<String>();
 
     // SAVE SEQUENCES
-    for (int i = 0; i < jal.getHeight(); i++)
+    for (int i = 0; i < rjal.getHeight(); i++)
     {
-      final SequenceI jds = jal.getSequenceAt(i);
+      final SequenceI jds = rjal.getSequenceAt(i);
       final SequenceI jdatasq = jds.getDatasetSequence() == null ? jds
-              : jds
-              .getDatasetSequence();
+              : jds.getDatasetSequence();
       String id = seqHash(jds);
 
       if (seqRefIds.get(id) != null)
@@ -714,20 +720,21 @@ public class Jalview2XML
         // Store any sequences this sequence represents
         if (av.hasHiddenRows())
         {
+          // use rjal, contains the full height alignment
           jseq.setHidden(av.getAlignment().getHiddenSequences()
                   .isHidden(jds));
 
-          if (av.isHiddenRepSequence(jal.getSequenceAt(i)))
+          if (av.isHiddenRepSequence(rjal.getSequenceAt(i)))
           {
             jalview.datamodel.SequenceI[] reps = av
-                    .getRepresentedSequences(jal.getSequenceAt(i))
-                    .getSequencesInOrder(jal);
+                    .getRepresentedSequences(rjal.getSequenceAt(i))
+                    .getSequencesInOrder(rjal);
 
             for (int h = 0; h < reps.length; h++)
             {
-              if (reps[h] != jal.getSequenceAt(i))
+              if (reps[h] != rjal.getSequenceAt(i))
               {
-                jseq.addHiddenSequences(jal.findIndex(reps[h]));
+                jseq.addHiddenSequences(rjal.findIndex(reps[h]));
               }
             }
           }
@@ -736,8 +743,7 @@ public class Jalview2XML
 
       if (jds.getSequenceFeatures() != null)
       {
-        jalview.datamodel.SequenceFeature[] sf = jds
-                .getSequenceFeatures();
+        jalview.datamodel.SequenceFeature[] sf = jds.getSequenceFeatures();
         int index = 0;
         while (index < sf.length)
         {
@@ -762,10 +768,11 @@ public class Jalview2XML
           if (sf[index].otherDetails != null)
           {
             String key;
-            Enumeration keys = sf[index].otherDetails.keys();
-            while (keys.hasMoreElements())
+            Iterator<String> keys = sf[index].otherDetails.keySet()
+                    .iterator();
+            while (keys.hasNext())
             {
-              key = keys.nextElement().toString();
+              key = keys.next();
               OtherData keyValue = new OtherData();
               keyValue.setKey(key);
               keyValue.setValue(sf[index].otherDetails.get(key).toString());
@@ -778,9 +785,9 @@ public class Jalview2XML
         }
       }
 
-      if (jdatasq.getPDBId() != null)
+      if (jdatasq.getAllPDBEntries() != null)
       {
-        Enumeration en = jdatasq.getPDBId().elements();
+        Enumeration en = jdatasq.getAllPDBEntries().elements();
         while (en.hasMoreElements())
         {
           Pdbids pdb = new Pdbids();
@@ -880,7 +887,7 @@ public class Jalview2XML
     // SAVE MAPPINGS
     if (jal.getCodonFrames() != null)
     {
-      Set<AlignedCodonFrame> jac = jal.getCodonFrames();
+      List<AlignedCodonFrame> jac = jal.getCodonFrames();
       for (AlignedCodonFrame acf : jac)
       {
         AlcodonFrame alc = new AlcodonFrame();
@@ -899,37 +906,37 @@ public class Jalview2XML
             alc.addAlcodMap(alcmap);
           }
         }
-
-//      {
-//        AlcodonFrame alc = new AlcodonFrame();
-//        vamsasSet.addAlcodonFrame(alc);
-//        for (int p = 0; p < acf.aaWidth; p++)
-//        {
-//          Alcodon cmap = new Alcodon();
-//          if (acf.codons[p] != null)
-//          {
-//            // Null codons indicate a gapped column in the translated peptide
-//            // alignment.
-//            cmap.setPos1(acf.codons[p][0]);
-//            cmap.setPos2(acf.codons[p][1]);
-//            cmap.setPos3(acf.codons[p][2]);
-//          }
-//          alc.addAlcodon(cmap);
-//        }
-//        if (acf.getProtMappings() != null
-//                && acf.getProtMappings().length > 0)
-//        {
-//          SequenceI[] dnas = acf.getdnaSeqs();
-//          jalview.datamodel.Mapping[] pmaps = acf.getProtMappings();
-//          for (int m = 0; m < pmaps.length; m++)
-//          {
-//            AlcodMap alcmap = new AlcodMap();
-//            alcmap.setDnasq(seqHash(dnas[m]));
-//            alcmap.setMapping(createVamsasMapping(pmaps[m], dnas[m], null,
-//                    false));
-//            alc.addAlcodMap(alcmap);
-//          }
-//        }
+        // TODO: delete this ? dead code from 2.8.3->2.9 ?
+        // {
+        // AlcodonFrame alc = new AlcodonFrame();
+        // vamsasSet.addAlcodonFrame(alc);
+        // for (int p = 0; p < acf.aaWidth; p++)
+        // {
+        // Alcodon cmap = new Alcodon();
+        // if (acf.codons[p] != null)
+        // {
+        // // Null codons indicate a gapped column in the translated peptide
+        // // alignment.
+        // cmap.setPos1(acf.codons[p][0]);
+        // cmap.setPos2(acf.codons[p][1]);
+        // cmap.setPos3(acf.codons[p][2]);
+        // }
+        // alc.addAlcodon(cmap);
+        // }
+        // if (acf.getProtMappings() != null
+        // && acf.getProtMappings().length > 0)
+        // {
+        // SequenceI[] dnas = acf.getdnaSeqs();
+        // jalview.datamodel.Mapping[] pmaps = acf.getProtMappings();
+        // for (int m = 0; m < pmaps.length; m++)
+        // {
+        // AlcodMap alcmap = new AlcodMap();
+        // alcmap.setDnasq(seqHash(dnas[m]));
+        // alcmap.setMapping(createVamsasMapping(pmaps[m], dnas[m], null,
+        // false));
+        // alc.addAlcodMap(alcmap);
+        // }
+        // }
       }
     }
 
@@ -1032,13 +1039,11 @@ public class Jalview2XML
 
             if (sg.cs instanceof jalview.schemes.UserColourScheme)
             {
-              jGroup.setColour(setUserColourScheme(sg.cs, userColours,
-                      jms));
+              jGroup.setColour(setUserColourScheme(sg.cs, userColours, jms));
             }
             else
             {
-              jGroup
-                      .setColour(ColourSchemeProperty.getColourName(sg.cs));
+              jGroup.setColour(ColourSchemeProperty.getColourName(sg.cs));
             }
           }
           else if (sg.cs instanceof jalview.schemes.AnnotationColourGradient)
@@ -1050,8 +1055,7 @@ public class Jalview2XML
           }
           else if (sg.cs instanceof jalview.schemes.UserColourScheme)
           {
-            jGroup
-                    .setColour(setUserColourScheme(sg.cs, userColours, jms));
+            jGroup.setColour(setUserColourScheme(sg.cs, userColours, jms));
           }
           else
           {
@@ -1096,15 +1100,26 @@ public class Jalview2XML
       view.setViewName(av.viewName);
       view.setGatheredViews(av.isGatherViewsHere());
 
-      Rectangle position = ap.av.getExplodedGeometry();
-      if (position == null)
+      Rectangle size = ap.av.getExplodedGeometry();
+      Rectangle position = size;
+      if (size == null)
       {
-        position = ap.alignFrame.getBounds();
+        size = ap.alignFrame.getBounds();
+        if (av.getCodingComplement() != null)
+        {
+          position = ((SplitFrame) ap.alignFrame.getSplitViewContainer())
+                  .getBounds();
+        }
+        else
+        {
+          position = size;
+        }
       }
       view.setXpos(position.x);
       view.setYpos(position.y);
-      view.setWidth(position.width);
-      view.setHeight(position.height);
+
+      view.setWidth(size.width);
+      view.setHeight(size.height);
 
       view.setStartRes(av.startRes);
       view.setStartSeq(av.startSeq);
@@ -1154,6 +1169,7 @@ public class Jalview2XML
       view.setFontName(av.font.getName());
       view.setFontSize(av.font.getSize());
       view.setFontStyle(av.font.getStyle());
+      view.setScaleProteinAsCdna(av.getViewStyle().isScaleProteinAsCdna());
       view.setRenderGaps(av.isRenderGaps());
       view.setShowAnnotation(av.isShowAnnotation());
       view.setShowBoxes(av.getShowBoxes());
@@ -1185,17 +1201,17 @@ public class Jalview2XML
                 .getFeatureRenderer().getRenderOrder()
                 .toArray(new String[0]);
 
-        Vector settingsAdded = new Vector();
+        Vector<String> settingsAdded = new Vector<String>();
         Object gstyle = null;
         GraduatedColor gcol = null;
         if (renderOrder != null)
         {
-          for (int ro = 0; ro < renderOrder.length; ro++)
+          for (String featureType : renderOrder)
           {
             gstyle = ap.getSeqPanel().seqCanvas.getFeatureRenderer()
-                    .getFeatureStyle(renderOrder[ro]);
+                    .getFeatureStyle(featureType);
             Setting setting = new Setting();
-            setting.setType(renderOrder[ro]);
+            setting.setType(featureType);
             if (gstyle instanceof GraduatedColor)
             {
               gcol = (GraduatedColor) gstyle;
@@ -1210,57 +1226,30 @@ public class Jalview2XML
             }
             else
             {
-              setting.setColour(ap.getSeqPanel().seqCanvas
-                      .getFeatureRenderer()
-                      .getColour(renderOrder[ro]).getRGB());
+              setting.setColour(((Color) gstyle).getRGB());
             }
 
             setting.setDisplay(av.getFeaturesDisplayed().isVisible(
-                    renderOrder[ro]));
+                    featureType));
             float rorder = ap.getSeqPanel().seqCanvas.getFeatureRenderer()
-                    .getOrder(renderOrder[ro]);
+                    .getOrder(featureType);
             if (rorder > -1)
             {
               setting.setOrder(rorder);
             }
             fs.addSetting(setting);
-            settingsAdded.addElement(renderOrder[ro]);
+            settingsAdded.addElement(featureType);
           }
         }
 
-        // Make sure we save none displayed feature settings
-        Iterator en = ap.getSeqPanel().seqCanvas.getFeatureRenderer()
-                .getFeatureColours().keySet().iterator();
-        while (en.hasNext())
-        {
-          String key = en.next().toString();
-          if (settingsAdded.contains(key))
-          {
-            continue;
-          }
-
-          Setting setting = new Setting();
-          setting.setType(key);
-          setting.setColour(ap.getSeqPanel().seqCanvas.getFeatureRenderer()
-                  .getColour(key).getRGB());
-
-          setting.setDisplay(false);
-          float rorder = ap.getSeqPanel().seqCanvas.getFeatureRenderer()
-                  .getOrder(key);
-          if (rorder > -1)
-          {
-            setting.setOrder(rorder);
-          }
-          fs.addSetting(setting);
-          settingsAdded.addElement(key);
-        }
         // is groups actually supposed to be a map here ?
-        en = ap.getSeqPanel().seqCanvas.getFeatureRenderer()
+        Iterator<String> en = ap.getSeqPanel().seqCanvas
+                .getFeatureRenderer()
                 .getFeatureGroups().iterator();
-        Vector groupsAdded = new Vector();
+        Vector<String> groupsAdded = new Vector<String>();
         while (en.hasNext())
         {
-          String grp = en.next().toString();
+          String grp = en.next();
           if (groupsAdded.contains(grp))
           {
             continue;
@@ -1372,6 +1361,10 @@ public class Jalview2XML
           final SequenceI jds, List<String> viewIds, AlignmentPanel ap,
           boolean storeDataset)
   {
+    if (Desktop.desktop == null)
+    {
+      return;
+    }
     JInternalFrame[] frames = Desktop.desktop.getAllFrames();
     for (int f = frames.length - 1; f > -1; f--)
     {
@@ -1420,8 +1413,7 @@ public class Jalview2XML
               {
 
                 String varnaStateFile = varna.getStateInfo(model.rna);
-                jarEntryName = RNA_PREFIX + viewId + "_"
-                      + nextCounter();
+                jarEntryName = RNA_PREFIX + viewId + "_" + nextCounter();
                 copyFileToJar(jout, varnaStateFile, jarEntryName);
                 rnaSessions.put(model, jarEntryName);
               }
@@ -1604,8 +1596,8 @@ public class Jalview2XML
 
   private void storeAlignmentAnnotation(AlignmentAnnotation[] aa,
           IdentityHashMap<SequenceGroup, String> groupRefs,
-          AlignmentViewport av,
-          Set<String> calcIdSet, boolean storeDS, SequenceSet vamsasSet)
+          AlignmentViewport av, Set<String> calcIdSet, boolean storeDS,
+          SequenceSet vamsasSet)
   {
 
     for (int i = 0; i < aa.length; i++)
@@ -1635,9 +1627,11 @@ public class Jalview2XML
         if (groupIdr == null)
         {
           // make a locally unique String
-          groupRefs.put(annotation.groupRef,
+          groupRefs.put(
+                  annotation.groupRef,
                   groupIdr = ("" + System.currentTimeMillis()
-                          + annotation.groupRef.getName() + groupRefs.size()));
+                          + annotation.groupRef.getName() + groupRefs
+                          .size()));
         }
         an.setGroupRef(groupIdr.toString());
       }
@@ -1852,8 +1846,8 @@ public class Jalview2XML
       }
     }
     throw new Error(MessageManager.formatMessage(
-            "error.unsupported_version_calcIdparam", new Object[]
-            { calcIdParam.toString() }));
+            "error.unsupported_version_calcIdparam",
+            new Object[] { calcIdParam.toString() }));
   }
 
   /**
@@ -1935,16 +1929,16 @@ public class Jalview2XML
     if (jds.getDatasetSequence() != null)
     {
       vamsasSeq.setDsseqid(seqHash(jds.getDatasetSequence()));
-      if (jds.getDatasetSequence().getDBRef() != null)
+      if (jds.getDatasetSequence().getDBRefs() != null)
       {
-        dbrefs = jds.getDatasetSequence().getDBRef();
+        dbrefs = jds.getDatasetSequence().getDBRefs();
       }
     }
     else
     {
       vamsasSeq.setDsseqid(id); // so we can tell which sequences really are
       // dataset sequences only
-      dbrefs = jds.getDBRef();
+      dbrefs = jds.getDBRefs();
     }
     if (dbrefs != null)
     {
@@ -2165,6 +2159,7 @@ public class Jalview2XML
       {
         SwingUtilities.invokeAndWait(new Runnable()
         {
+          @Override
           public void run()
           {
             setLoadingFinishedForNewStructureViewers();
@@ -2239,7 +2234,7 @@ public class Jalview2XML
     }
     if (frefedSequence == null)
     {
-      frefedSequence = new Vector();
+      frefedSequence = new Vector<Object[]>();
     }
 
     AlignFrame af = null, _af = null;
@@ -2415,7 +2410,8 @@ public class Jalview2XML
             .entrySet())
     {
       AlignFrame af = candidate.getValue();
-      if (!addedToSplitFrames.contains(af)) {
+      if (!addedToSplitFrames.contains(af))
+      {
         Viewport view = candidate.getKey();
         Desktop.addInternalFrame(af, view.getTitle(), view.getWidth(),
                 view.getHeight());
@@ -2450,6 +2446,11 @@ public class Jalview2XML
     int width = (int) dnaFrame.getBounds().getWidth();
     int height = (int) (dnaFrame.getBounds().getHeight()
             + proteinFrame.getBounds().getHeight() + 50);
+
+    /*
+     * SplitFrame location is saved to both enclosed frames
+     */
+    splitFrame.setLocation(dnaFrame.getX(), dnaFrame.getY());
     Desktop.addInternalFrame(splitFrame, title, width, height);
 
     /*
@@ -2829,15 +2830,15 @@ public class Jalview2XML
             {
               mapping = addMapping(maps[m].getMapping());
             }
-            if (dnaseq != null)
+            if (dnaseq != null && mapping.getTo() != null)
             {
               cf.addMap(dnaseq, mapping.getTo(), mapping.getMap());
             }
             else
             {
               // defer to later
-              frefedSequence.add(new Object[]
-              { maps[m].getDnasq(), cf, mapping });
+              frefedSequence.add(new Object[] { maps[m].getDnasq(), cf,
+                  mapping });
             }
           }
         }
@@ -2888,8 +2889,7 @@ public class Jalview2XML
 
         // set visiblity for other annotation in this view
         String annotationId = annotation.getId();
-        if (annotationId != null
-                && annotationIds.containsKey(annotationId))
+        if (annotationId != null && annotationIds.containsKey(annotationId))
         {
           AlignmentAnnotation jda = annotationIds.get(annotationId);
           // in principle Visible should always be true for annotation displayed
@@ -3123,8 +3123,7 @@ public class Jalview2XML
 
         SequenceGroup sg = new SequenceGroup(seqs, jGroup.getName(), cs,
                 jGroup.getDisplayBoxes(), jGroup.getDisplayText(),
-                jGroup.getColourText(), jGroup.getStart(),
-                jGroup.getEnd());
+                jGroup.getColourText(), jGroup.getStart(), jGroup.getEnd());
 
         sg.setOutlineColour(new java.awt.Color(jGroup.getOutlineColour()));
 
@@ -3163,8 +3162,8 @@ public class Jalview2XML
         if (jGroup.getId() != null && groupAnnotRefs.size() > 0)
         {
           // re-instate unique group/annotation row reference
-          List<AlignmentAnnotation> jaal = groupAnnotRefs
-                  .get(jGroup.getId());
+          List<AlignmentAnnotation> jaal = groupAnnotRefs.get(jGroup
+                  .getId());
           if (jaal != null)
           {
             for (AlignmentAnnotation jaa : jaal)
@@ -3192,8 +3191,8 @@ public class Jalview2XML
         if (addAnnotSchemeGroup)
         {
           // reconstruct the annotation colourscheme
-          sg.cs = constructAnnotationColour(
-                  jGroup.getAnnotationColours(), null, al, jms, false);
+          sg.cs = constructAnnotationColour(jGroup.getAnnotationColours(),
+                  null, al, jms, false);
         }
       }
     }
@@ -3249,8 +3248,8 @@ public class Jalview2XML
      * indicate that annotation colours are applied across all groups (pre
      * Jalview 2.8.1 behaviour)
      */
-    boolean doGroupAnnColour = isVersionStringLaterThan("2.8.1",
-            object.getVersion());
+    boolean doGroupAnnColour = Jalview2XML.isVersionStringLaterThan(
+            "2.8.1", object.getVersion());
 
     AlignmentPanel ap = null;
     boolean isnewview = true;
@@ -3325,8 +3324,8 @@ public class Jalview2XML
       for (int i = 0; i < jseq.getRnaViewerCount(); i++)
       {
         RnaViewer viewer = jseq.getRnaViewer(i);
-        AppVarna appVarna = findOrCreateVarnaViewer(viewer, uniqueSetSuffix,
-                ap);
+        AppVarna appVarna = findOrCreateVarnaViewer(viewer,
+                uniqueSetSuffix, ap);
 
         for (int j = 0; j < viewer.getSecondaryStructureCount(); j++)
         {
@@ -3344,9 +3343,8 @@ public class Jalview2XML
           String sessionState = ss.getViewerState();
           String tempStateFile = copyJarEntry(jprovider, sessionState,
                   "varna");
-          RnaModel rna = new RnaModel(rnaTitle, ann, seq, null, gapped,
-                  tempStateFile);
-          appVarna.addModel(rna, rnaTitle);
+          RnaModel rna = new RnaModel(rnaTitle, ann, seq, null, gapped);
+          appVarna.addModelSession(rna, rnaTitle, tempStateFile);
         }
         appVarna.setInitialSelection(viewer.getSelectedRna());
       }
@@ -3389,8 +3387,8 @@ public class Jalview2XML
      * viewer not found - make it
      */
     RnaViewerModel model = new RnaViewerModel(postLoadId,
-            viewer.getTitle(), viewer.getXpos(),
-            viewer.getYpos(), viewer.getWidth(), viewer.getHeight(),
+            viewer.getTitle(), viewer.getXpos(), viewer.getYpos(),
+            viewer.getWidth(), viewer.getHeight(),
             viewer.getDividerLocation());
     AppVarna varna = new AppVarna(model, ap);
 
@@ -3675,12 +3673,12 @@ public class Jalview2XML
    * @param af
    * @param jprovider
    */
-  protected void createChimeraViewer(Entry<String, StructureViewerModel> viewerData,
-          AlignFrame af,
+  protected void createChimeraViewer(
+          Entry<String, StructureViewerModel> viewerData, AlignFrame af,
           jarInputStreamProvider jprovider)
   {
     StructureViewerModel data = viewerData.getValue();
-    String chimeraSessionFile =  data.getStateData();
+    String chimeraSessionFile = data.getStateData();
 
     /*
      * Copy Chimera session from jar entry "viewer_"+viewId to a temporary file
@@ -3717,8 +3715,8 @@ public class Jalview2XML
     String newViewId = viewerData.getKey();
 
     ChimeraViewFrame cvf = new ChimeraViewFrame(chimeraSessionFile,
-            af.alignPanel, pdbArray,
-            seqsArray, colourByChimera, colourBySequence, newViewId);
+            af.alignPanel, pdbArray, seqsArray, colourByChimera,
+            colourBySequence, newViewId);
     cvf.setSize(data.getWidth(), data.getHeight());
     cvf.setLocation(data.getX(), data.getY());
   }
@@ -3884,6 +3882,7 @@ public class Jalview2XML
     {
       // e.printStackTrace();
     }
+
   }
 
   /**
@@ -4028,18 +4027,22 @@ public class Jalview2XML
   }
 
   /**
+   * Answers true if 'version' is equal to or later than 'supported', where each
+   * is formatted as major/minor versions like "2.8.3" or "2.3.4b1" for bugfix
+   * changes. Development and test values for 'version' are leniently treated
+   * i.e. answer true.
    * 
    * @param supported
    *          - minimum version we are comparing against
    * @param version
-   *          - version of data being processsed.
-   * @return true if version is development/null or evaluates to the same or
-   *         later X.Y.Z (where X,Y,Z are like [0-9]+b?[0-9]*)
+   *          - version of data being processsed
+   * @return
    */
-  protected boolean isVersionStringLaterThan(String supported,
+  public static boolean isVersionStringLaterThan(String supported,
           String version)
   {
-    if (version == null || version.equalsIgnoreCase("DEVELOPMENT BUILD")
+    if (supported == null || version == null
+            || version.equalsIgnoreCase("DEVELOPMENT BUILD")
             || version.equalsIgnoreCase("Test")
             || version.equalsIgnoreCase("AUTOMATED BUILD"))
     {
@@ -4050,38 +4053,8 @@ public class Jalview2XML
     }
     else
     {
-      StringTokenizer currentV = new StringTokenizer(supported, "."), fileV = new StringTokenizer(
-              version, ".");
-      while (currentV.hasMoreTokens() && fileV.hasMoreTokens())
-      {
-        // convert b to decimal to catch bugfix releases within a series
-        String curT = currentV.nextToken().toLowerCase().replace('b', '.');
-        String fileT = fileV.nextToken().toLowerCase().replace('b', '.');
-        try
-        {
-          if (Float.valueOf(curT) > Float.valueOf(fileT))
-          {
-            // current version is newer than the version that wrote the file
-            return false;
-          }
-        } catch (NumberFormatException nfe)
-        {
-          System.err
-                  .println("** WARNING: Version comparison failed for tokens ("
-                          + curT
-                          + ") and ("
-                          + fileT
-                          + ")\n** Current: '"
-                          + supported + "' and Version: '" + version + "'");
-        }
-      }
-      if (currentV.hasMoreElements())
-      {
-        // fileV has no minor version but identical series to current
-        return false;
-      }
+      return StringUtils.compareVersions(version, supported, "b") >= 0;
     }
-    return true;
   }
 
   Vector<JalviewStructureDisplayI> newStructureViewers = null;
@@ -4195,6 +4168,9 @@ public class Jalview2XML
     af.viewport.setFont(
             new java.awt.Font(view.getFontName(), view.getFontStyle(), view
                     .getFontSize()), true);
+    ViewStyleI vs = af.viewport.getViewStyle();
+    vs.setScaleProteinAsCdna(view.isScaleProteinAsCdna());
+    af.viewport.setViewStyle(vs);
     // TODO: allow custom charWidth/Heights to be restored by updating them
     // after setting font - which means set above to false
     af.viewport.setRenderGaps(view.getRenderGaps());
@@ -4420,7 +4396,7 @@ public class Jalview2XML
       }
     }
     af.setMenusFromViewport(af.viewport);
-    
+
     // TODO: we don't need to do this if the viewport is aready visible.
     /*
      * Add the AlignFrame to the desktop (it may be 'gathered' later), unless it
@@ -4579,8 +4555,8 @@ public class Jalview2XML
       /**
        * Kludge for magic autoannotation names (see JAL-811)
        */
-      String[] magicNames = new String[]
-      { "Consensus", "Quality", "Conservation" };
+      String[] magicNames = new String[] { "Consensus", "Quality",
+          "Conservation" };
       JvAnnotRow nullAnnot = new JvAnnotRow(-1, null);
       Hashtable<String, JvAnnotRow> visan = new Hashtable<String, JvAnnotRow>();
       for (String nm : magicNames)
@@ -4990,8 +4966,7 @@ public class Jalview2XML
         }
         else
         {
-          frefedSequence.add(new Object[]
-          { dsfor, jmap });
+          frefedSequence.add(new Object[] { dsfor, jmap });
         }
       }
       else
@@ -5325,7 +5300,7 @@ public class Jalview2XML
         }
       }
     }
-  
+
     return result;
   }