Merge branch 'Release_2_8_3_Branch' of https://source.jalview.org/git/jalview into...
[jalview.git] / src / jalview / gui / AlignFrame.java
index c7792a5..fcf4301 100644 (file)
@@ -140,6 +140,7 @@ import jalview.schemes.TaylorColourScheme;
 import jalview.schemes.TurnColourScheme;
 import jalview.schemes.UserColourScheme;
 import jalview.schemes.ZappoColourScheme;
+import jalview.structure.StructureSelectionManager;
 import jalview.util.MessageManager;
 import jalview.viewmodel.AlignmentViewport;
 import jalview.ws.jws1.Discoverer;
@@ -2849,7 +2850,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
      * Set the 'follow' flag on the Viewport (and scroll to position if now
      * true).
      */
-    if (viewport.followHighlight = this.followHighlightMenuItem.getState())
+    final boolean state = this.followHighlightMenuItem.getState();
+    viewport.setFollowHighlight(state);
+    if (state)
     {
       alignPanel.scrollToPosition(
               alignPanel.getSeqPanel().seqCanvas.searchResults, false);
@@ -4779,8 +4782,15 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
               sprods[s].updatePDBIds();
             }
             Alignment al = new Alignment(sprods);
-            Set<AlignedCodonFrame> cf = prods.getCodonFrames();
             al.setDataset(ds);
+
+            /*
+             * Copy dna-to-protein mappings to new alignment
+             */
+            // TODO 1: no mappings are set up for EMBL product
+            // TODO 2: if they were, should add them to protein alignment, not
+            // dna
+            Set<AlignedCodonFrame> cf = prods.getCodonFrames();
             for (AlignedCodonFrame acf : cf)
             {
               al.addCodonFrame(acf);
@@ -4792,12 +4802,33 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                     + getTitle();
             naf.setTitle(newtitle);
 
-            // remove this flag once confirmed we want a split view
-            boolean asSplitFrame = true;
+            // temporary flag until SplitFrame is released
+            boolean asSplitFrame = Cache.getDefault(
+                    Preferences.ENABLE_SPLIT_FRAME, false);
             if (asSplitFrame)
             {
-              final Alignment copyAlignment = new Alignment(new Alignment(
-                      AlignFrame.this.viewport.getSequenceSelection()));
+              /*
+               * Make a copy of this alignment (sharing the same dataset
+               * sequences). If we are DNA, drop introns and update mappings
+               */
+              AlignmentI copyAlignment = null;
+              final SequenceI[] sequenceSelection = AlignFrame.this.viewport
+                      .getSequenceSelection();
+              if (dna)
+              {
+                copyAlignment = AlignmentUtils.makeExonAlignment(
+                        sequenceSelection, cf);
+                al.getCodonFrames().clear();
+                al.getCodonFrames().addAll(cf);
+                final StructureSelectionManager ssm = StructureSelectionManager
+                        .getStructureSelectionManager(Desktop.instance);
+                ssm.addMappings(cf);
+              }
+              else
+              {
+                copyAlignment = new Alignment(new Alignment(
+                        sequenceSelection));
+              }
               AlignFrame copyThis = new AlignFrame(copyAlignment,
                       AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
               copyThis.setTitle(AlignFrame.this.getTitle());
@@ -4905,9 +4936,17 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
               "label.translation_of_params", new Object[]
               { this.getTitle() });
       af.setTitle(newTitle);
-      final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
-      viewport.openSplitFrame(af, new Alignment(seqs), al.getCodonFrames());
-      // Desktop.addInternalFrame(af, newTitle, DEFAULT_WIDTH, DEFAULT_HEIGHT);
+      if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, false))
+      {
+        final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
+        viewport.openSplitFrame(af, new Alignment(seqs),
+                al.getCodonFrames());
+      }
+      else
+      {
+        Desktop.addInternalFrame(af, newTitle, DEFAULT_WIDTH,
+                DEFAULT_HEIGHT);
+      }
     }
   }