JAL-1690 scaleProteinAsCdna new optional attribute on Viewport in
[jalview.git] / src / jalview / gui / Jalview2XML.java
index 2434b00..2f90e91 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;
@@ -676,8 +677,7 @@ public class Jalview2XML
     {
       final SequenceI jds = jal.getSequenceAt(i);
       final SequenceI jdatasq = jds.getDatasetSequence() == null ? jds
-              : jds
-              .getDatasetSequence();
+              : jds.getDatasetSequence();
       String id = seqHash(jds);
 
       if (seqRefIds.get(id) != null)
@@ -736,8 +736,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)
         {
@@ -778,9 +777,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();
@@ -900,36 +899,36 @@ public class Jalview2XML
           }
         }
 
-//      {
-//        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);
-//          }
-//        }
+        // {
+        // 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 +1031,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 +1047,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
           {
@@ -1154,6 +1150,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());
@@ -1211,8 +1208,8 @@ public class Jalview2XML
             else
             {
               setting.setColour(ap.getSeqPanel().seqCanvas
-                      .getFeatureRenderer()
-                      .getColour(renderOrder[ro]).getRGB());
+                      .getFeatureRenderer().getColour(renderOrder[ro])
+                      .getRGB());
             }
 
             setting.setDisplay(av.getFeaturesDisplayed().isVisible(
@@ -1372,6 +1369,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 +1421,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 +1604,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 +1635,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());
       }
@@ -2415,7 +2417,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());
@@ -2888,8 +2891,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 +3125,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 +3164,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 +3193,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);
         }
       }
     }
@@ -3325,8 +3326,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 +3345,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 +3389,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 +3675,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 +3717,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 +3884,7 @@ public class Jalview2XML
     {
       // e.printStackTrace();
     }
+
   }
 
   /**
@@ -4195,6 +4196,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 +4424,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
@@ -5325,7 +5329,7 @@ public class Jalview2XML
         }
       }
     }
-  
+
     return result;
   }