JAL-845 start cDNA consensus on 'add alignment' (as well as translate or
[jalview.git] / src / jalview / gui / AlignViewport.java
index 93d8c19..289a0ea 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
- * Copyright (C) 2014 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
@@ -39,7 +39,6 @@
 package jalview.gui;
 
 import jalview.analysis.AlignmentUtils;
-import jalview.analysis.AlignmentUtils.MappingResult;
 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
 import jalview.analysis.NJTree;
 import jalview.api.AlignViewportI;
@@ -951,17 +950,11 @@ public class AlignViewport extends AlignmentViewport implements
      * If one alignment is protein and one nucleotide, with at least one
      * sequence name in common, offer to open a linked alignment.
      */
-    if (getAlignment().isNucleotide() != al.isNucleotide())
+    if (AlignmentUtils.isMappable(al, getAlignment()))
     {
-      // TODO: JAL-845 try a bit harder to link up imported sequences
-      final Set<String> sequenceNames = getAlignment().getSequenceNames();
-      sequenceNames.retainAll(al.getSequenceNames());
-      if (!sequenceNames.isEmpty()) // at least one sequence name in both
+      if (openLinkedAlignment(al, title))
       {
-        if (openLinkedAlignment(al, title))
-        {
-          return;
-        }
+        return;
       }
     }
     // TODO: JAL-407 regardless of above - identical sequences (based on ID and
@@ -1042,21 +1035,11 @@ public class AlignViewport extends AlignmentViewport implements
     }
 
     /*
-     * Try to find mappings for at least one sequence. Any mappings made will be
-     * added to the protein alignment.
+     * Map sequences. At least one should get mapped as we have already passed
+     * the test for 'mappability'. Any mappings made will be added to the
+     * protein alignment.
      */
-    MappingResult mapped = AlignmentUtils.mapProteinToCdna(protein, cdna);
-    if (mapped != MappingResult.Mapped)
-    {
-      /*
-       * No mapping possible - warn the user, but leave window open.
-       */
-      final String msg = JvSwingUtils.wrapTooltip(true,
-              MessageManager.getString("label.mapping_failed"));
-      JOptionPane.showInternalMessageDialog(Desktop.desktop, msg,
-              MessageManager.getString("label.no_mappings"),
-              JOptionPane.WARNING_MESSAGE);
-    }
+    AlignmentUtils.mapProteinToCdna(protein, cdna);
 
     try
     {
@@ -1069,8 +1052,8 @@ public class AlignViewport extends AlignmentViewport implements
 
     if (openSplitPane)
     {
-      protein = openSplitFrame(newAlignFrame,
-              thisAlignment.getSequencesArray(), protein.getCodonFrames());
+      protein = openSplitFrame(newAlignFrame, thisAlignment,
+              protein.getCodonFrames());
     }
 
     /*
@@ -1090,20 +1073,18 @@ public class AlignViewport extends AlignmentViewport implements
    * 
    * @param newAlignFrame
    *          containing a new alignment to be shown
-   * @param seqs
-   *          'complementary' sequences to show in the other split half
+   * @param complement
+   *          cdna/protein complement alignment to show in the other split half
    * @param mappings
    * @return the protein alignment in the split frame
    */
   protected AlignmentI openSplitFrame(AlignFrame newAlignFrame,
-          SequenceI[] seqs, Set<AlignedCodonFrame> mappings)
+          AlignmentI complement, Set<AlignedCodonFrame> mappings)
   {
-    AlignmentI complementAlignment = new Alignment(seqs);
-    // TODO: move this to a factory/controller method ?
     /*
      * Open in split pane. DNA sequence above, protein below.
      */
-    AlignFrame copyMe = new AlignFrame(complementAlignment,
+    AlignFrame copyMe = new AlignFrame(complement,
             AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
     copyMe.setTitle(getAlignPanel().alignFrame.getTitle());
 
@@ -1114,6 +1095,7 @@ public class AlignViewport extends AlignmentViewport implements
             : copyMe;
     AlignmentI protein = proteinFrame.viewport.getAlignment();
     protein.setCodonFrames(mappings);
+    proteinFrame.viewport.initComplementConsensus();
 
     cdnaFrame.setVisible(true);
     proteinFrame.setVisible(true);