JAL-2145 fix: build alignments before building AlignFrame/SplitFrame pair
authorJim Procter <jprocter@issues.jalview.org>
Mon, 18 Jul 2016 08:21:56 +0000 (09:21 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Mon, 18 Jul 2016 08:21:56 +0000 (09:21 +0100)
src/jalview/gui/AlignFrame.java

index 891fdd6..48bd998 100644 (file)
@@ -4741,97 +4741,102 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
             xrefsAlignment.alignAs(alignment);
           }
 
-          AlignFrame newFrame = new AlignFrame(xrefsAlignment, DEFAULT_WIDTH,
-                  DEFAULT_HEIGHT);
-          if (Cache.getDefault("HIDE_INTRONS", true))
-          {
-            newFrame.hideFeatureColumns(SequenceOntologyI.EXON, false);
-          }
-          String newtitle = String.format("%s %s %s", MessageManager
-                  .getString(dna ? "label.proteins" : "label.nucleotides"),
-                  MessageManager.getString("label.for"), getTitle());
-          newFrame.setTitle(newtitle);
-
-          if (!Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
-          {
-            /*
-             * split frame display is turned off in preferences file
-             */
-            Desktop.addInternalFrame(newFrame, newtitle, DEFAULT_WIDTH,
-                    DEFAULT_HEIGHT);
-            return; // via finally clause
-          }
-
           /*
-           * Make a copy of this alignment (sharing the same dataset
+           * If we are opening a splitframe, make a copy of this alignment (sharing the same dataset
            * sequences). If we are DNA, drop introns and update mappings
            */
           AlignmentI copyAlignment = null;
-          boolean copyAlignmentIsAligned = false;
-          if (dna)
+
+          if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
           {
-            copyAlignment = AlignmentUtils.makeCdsAlignment(sel, dataset,
-                    xrefsAlignment.getSequencesArray());
-            if (copyAlignment.getHeight() == 0)
+            boolean copyAlignmentIsAligned = false;
+            if (dna)
             {
-              System.err.println("Failed to make CDS alignment");
-            }
+              copyAlignment = AlignmentUtils.makeCdsAlignment(sel, dataset,
+                      xrefsAlignment.getSequencesArray());
+              if (copyAlignment.getHeight() == 0)
+              {
+                System.err.println("Failed to make CDS alignment");
+              }
 
-            /*
-             * pending getting Embl transcripts to 'align', 
-             * we are only doing this for Ensembl
-             */
-            // TODO proper criteria for 'can align as cdna'
-            if (DBRefSource.ENSEMBL.equalsIgnoreCase(source)
-                    || AlignmentUtils.looksLikeEnsembl(alignment))
+              /*
+               * pending getting Embl transcripts to 'align', 
+               * we are only doing this for Ensembl
+               */
+              // TODO proper criteria for 'can align as cdna'
+              if (DBRefSource.ENSEMBL.equalsIgnoreCase(source)
+                      || AlignmentUtils.looksLikeEnsembl(alignment))
+              {
+                copyAlignment.alignAs(alignment);
+                copyAlignmentIsAligned = true;
+              }
+            }
+            else
             {
-              copyAlignment.alignAs(alignment);
-              copyAlignmentIsAligned = true;
+              copyAlignment = AlignmentUtils.makeCopyAlignment(sel,
+                      xrefs.getSequencesArray(), dataset);
             }
-          }
-          else
-          {
-            copyAlignment = AlignmentUtils.makeCopyAlignment(sel,
-                    xrefs.getSequencesArray(), dataset);
-          }
-          copyAlignment.setGapCharacter(AlignFrame.this.viewport
-                  .getGapCharacter());
+            copyAlignment.setGapCharacter(AlignFrame.this.viewport
+                    .getGapCharacter());
 
-          StructureSelectionManager ssm = StructureSelectionManager
-                  .getStructureSelectionManager(Desktop.instance);
+            StructureSelectionManager ssm = StructureSelectionManager
+                    .getStructureSelectionManager(Desktop.instance);
 
-          /*
-           * register any new mappings for sequence mouseover etc
-           * (will not duplicate any previously registered mappings)
-           */
-          ssm.registerMappings(dataset.getCodonFrames());
+            /*
+             * register any new mappings for sequence mouseover etc
+             * (will not duplicate any previously registered mappings)
+             */
+            ssm.registerMappings(dataset.getCodonFrames());
 
-          if (copyAlignment.getHeight() <= 0)
-          {
-            System.err.println("No Sequences generated for xRef type "
-                    + source);
-            return;
+            if (copyAlignment.getHeight() <= 0)
+            {
+              System.err.println("No Sequences generated for xRef type "
+                      + source);
+              return;
+            }
+            /*
+             * align protein to dna
+             */
+            if (dna && copyAlignmentIsAligned)
+            {
+              xrefsAlignment.alignAs(copyAlignment);
+            }
+            else
+            {
+              /*
+               * align cdna to protein - currently only if 
+               * fetching and aligning Ensembl transcripts!
+               */
+              // TODO: generalise for other sources of locus/transcript/cds data
+              if (dna && DBRefSource.ENSEMBL.equalsIgnoreCase(source))
+              {
+                copyAlignment.alignAs(xrefsAlignment);
+              }
+            }
           }
           /*
-           * align protein to dna
+           * build AlignFrame(s) according to available alignment data
            */
-          if (dna && copyAlignmentIsAligned)
+          AlignFrame newFrame = new AlignFrame(xrefsAlignment,
+                  DEFAULT_WIDTH, DEFAULT_HEIGHT);
+          if (Cache.getDefault("HIDE_INTRONS", true))
           {
-            xrefsAlignment.alignAs(copyAlignment);
+            newFrame.hideFeatureColumns(SequenceOntologyI.EXON, false);
           }
-          else
+          String newtitle = String.format("%s %s %s", MessageManager
+                  .getString(dna ? "label.proteins" : "label.nucleotides"),
+                  MessageManager.getString("label.for"), getTitle());
+          newFrame.setTitle(newtitle);
+
+          if (copyAlignment == null)
           {
             /*
-             * align cdna to protein - currently only if 
-             * fetching and aligning Ensembl transcripts!
+             * split frame display is turned off in preferences file
              */
-            // TODO: generalise for other sources of locus/transcript/cds data
-            if (dna && DBRefSource.ENSEMBL.equalsIgnoreCase(source))
-            {
-              copyAlignment.alignAs(xrefsAlignment);
-            }
+            Desktop.addInternalFrame(newFrame, newtitle, DEFAULT_WIDTH,
+                    DEFAULT_HEIGHT);
+            return; // via finally clause
           }
-
           AlignFrame copyThis = new AlignFrame(copyAlignment,
                   AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
           copyThis.setTitle(AlignFrame.this.getTitle());