JAL-1705 features transferred to CDS sequence; makeExon renamed makeCds
[jalview.git] / src / jalview / gui / AlignFrame.java
index 88271b9..9113b66 100644 (file)
@@ -131,7 +131,6 @@ import java.util.Deque;
 import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.List;
-import java.util.Set;
 import java.util.Vector;
 
 import javax.swing.JCheckBoxMenuItem;
@@ -828,6 +827,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   public void setGUINucleotide(boolean nucleotide)
   {
     showTranslation.setVisible(nucleotide);
+    showReverse.setVisible(nucleotide);
+    showReverseComplement.setVisible(nucleotide);
     conservationMenuItem.setEnabled(!nucleotide);
     modifyConservation.setEnabled(!nucleotide);
     showGroupConservation.setEnabled(!nucleotide);
@@ -845,6 +846,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * operation that affects the data in the current view (selection changed,
    * etc) to update the menus to reflect the new state.
    */
+  @Override
   public void setMenusForViewport()
   {
     setMenusFromViewport(viewport);
@@ -1309,19 +1311,16 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     int startPos = aligmentStartEnd[0];
     int endPos = aligmentStartEnd[1];
 
-    int[] lowestRange = new int[2];
-    int[] higestRange = new int[2];
+    int[] lowestRange = new int[] { -1, -1 };
+    int[] higestRange = new int[] { -1, -1 };
 
     for (int[] hiddenCol : hiddenCols)
     {
-      // System.out.println("comparing : " + hiddenCol[0] + "-" + hiddenCol[1]);
       lowestRange = (hiddenCol[0] <= startPos) ? hiddenCol : lowestRange;
       higestRange = (hiddenCol[1] >= endPos) ? hiddenCol : higestRange;
     }
-    // System.out.println("min : " + lowestRange[0] + "-" + lowestRange[1]);
-    // System.out.println("max : " + higestRange[0] + "-" + higestRange[1]);
 
-    if (lowestRange[0] == 0 && lowestRange[1] == 0)
+    if (lowestRange[0] == -1 && lowestRange[1] == -1)
     {
       startPos = aligmentStartEnd[0];
     }
@@ -1330,27 +1329,27 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       startPos = lowestRange[1] + 1;
     }
 
-    if (higestRange[0] == 0 && higestRange[1] == 0)
+    if (higestRange[0] == -1 && higestRange[1] == -1)
     {
       endPos = aligmentStartEnd[1];
     }
     else
     {
-      endPos = higestRange[0];
+      endPos = higestRange[0] - 1;
     }
 
-    // System.out.println("Export range : " + minPos + " - " + maxPos);
+    // System.out.println("Export range : " + startPos + " - " + endPos);
     return new int[] { startPos, endPos };
   }
 
   public static void main(String[] args)
   {
     ArrayList<int[]> hiddenCols = new ArrayList<int[]>();
-    hiddenCols.add(new int[] { 0, 4 });
+    hiddenCols.add(new int[] { 0, 0 });
     hiddenCols.add(new int[] { 6, 9 });
     hiddenCols.add(new int[] { 11, 12 });
     hiddenCols.add(new int[] { 33, 33 });
-    hiddenCols.add(new int[] { 45, 50 });
+    hiddenCols.add(new int[] { 50, 50 });
 
     int[] x = getStartEnd(new int[] { 0, 50 }, hiddenCols);
     // System.out.println("Export range : " + x[0] + " - " + x[1]);
@@ -1404,6 +1403,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     alignPanel.makeEPS(f);
   }
 
+  @Override
   public void createSVG(File f)
   {
     alignPanel.makeSVG(f);
@@ -1577,6 +1577,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     }
   }
 
+  @Override
   public void addHistoryItem(CommandI command)
   {
     if (command.getSize() > 0)
@@ -1980,7 +1981,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
           return;
         }
 
-        format = new IdentifyFile().Identify(str, "Paste");
+        format = new IdentifyFile().identify(str, "Paste");
 
       } catch (OutOfMemoryError er)
       {
@@ -2375,20 +2376,24 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
      */
     if (sg.getSize() == viewport.getAlignment().getHeight())
     {
-      int confirm = JOptionPane.showConfirmDialog(this,
-              MessageManager.getString("warn.delete_all"), // $NON-NLS-1$
-              MessageManager.getString("label.delete_all"), // $NON-NLS-1$
-              JOptionPane.OK_CANCEL_OPTION);
-
-      if (confirm == JOptionPane.CANCEL_OPTION
-              || confirm == JOptionPane.CLOSED_OPTION)
+      boolean isEntireAlignWidth = (((sg.getEndRes() - sg.getStartRes()) + 1) == viewport
+              .getAlignment().getWidth()) ? true : false;
+      if (isEntireAlignWidth)
       {
-        return;
+        int confirm = JOptionPane.showConfirmDialog(this,
+                MessageManager.getString("warn.delete_all"), // $NON-NLS-1$
+                MessageManager.getString("label.delete_all"), // $NON-NLS-1$
+                JOptionPane.OK_CANCEL_OPTION);
+
+        if (confirm == JOptionPane.CANCEL_OPTION
+                || confirm == JOptionPane.CLOSED_OPTION)
+        {
+          return;
+        }
       }
       viewport.getColumnSelection().removeElements(sg.getStartRes(),
               sg.getEndRes() + 1);
     }
-
     SequenceI[] cut = sg.getSequences()
             .toArray(new SequenceI[sg.getSize()]);
 
@@ -3496,6 +3501,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param cs
    *          DOCUMENT ME!
    */
+  @Override
   public void changeColour(ColourSchemeI cs)
   {
     // TODO: pull up to controller method
@@ -3515,6 +3521,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
                 cs, "Background"));
       }
+      if (cs instanceof TCoffeeColourScheme)
+      {
+        tcoffeeColour.setEnabled(true);
+        tcoffeeColour.setSelected(true);
+      }
     }
 
     viewport.setGlobalColourScheme(cs);
@@ -4773,7 +4784,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
             // 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();
+            List<AlignedCodonFrame> cf = prods.getCodonFrames();
             for (AlignedCodonFrame acf : cf)
             {
               al.addCodonFrame(acf);
@@ -5091,7 +5102,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
               String type = null;
               try
               {
-                type = new IdentifyFile().Identify(file, protocol);
+                type = new IdentifyFile().identify(file, protocol);
               } catch (Exception ex)
               {
                 type = null;
@@ -5190,7 +5201,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
   /**
    * Attempt to load a "dropped" file or URL string: First by testing whether
-   * it's and Annotation file, then a JNet file, and finally a features file. If
+   * it's an Annotation file, then a JNet file, and finally a features file. If
    * all are false then the user may have dropped an alignment file onto this
    * AlignFrame.
    * 
@@ -5204,7 +5215,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     {
       if (protocol == null)
       {
-        protocol = jalview.io.FormatAdapter.checkProtocol(file);
+        protocol = FormatAdapter.checkProtocol(file);
       }
       // if the file isn't identified, or not positively identified as some
       // other filetype (PFAM is default unidentified alignment file type) then
@@ -5265,7 +5276,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
           // try to parse it as a features file
           if (format == null)
           {
-            format = new IdentifyFile().Identify(file, protocol);
+            format = new IdentifyFile().identify(file, protocol);
           }
           if (format.equalsIgnoreCase("JnetFile"))
           {
@@ -5281,42 +5292,17 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
             viewport.setColumnSelection(cs);
             isAnnotation = true;
           }
-          else
+          else if (IdentifyFile.FeaturesFile.equals(format))
           {
-            /*
-             * if (format.equalsIgnoreCase("PDB")) {
-             * 
-             * String pdbfn = ""; // try to match up filename with sequence id
-             * try { if (protocol == jalview.io.FormatAdapter.FILE) { File fl =
-             * new File(file); pdbfn = fl.getName(); } else if (protocol ==
-             * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn =
-             * url.getFile(); } } catch (Exception e) { } ; if (assocSeq ==
-             * null) { SequenceIdMatcher idm = new SequenceIdMatcher(viewport
-             * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) {
-             * // attempt to find a match in the alignment SequenceI mtch =
-             * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while
-             * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) >
-             * l) { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch
-             * = idm.findIdMatch(pdbfn); } if (mtch != null) { // try and
-             * associate // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq()
-             * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null)
-             * { System.err.println("Associated file : " + file + " with " +
-             * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } //
-             * TODO: maybe need to load as normal otherwise return; } }
-             */
-            // try to parse it as a features file
-            boolean isGroupsFile = parseFeaturesFile(file, protocol);
-            // if it wasn't a features file then we just treat it as a general
-            // alignment file to load into the current view.
-            if (!isGroupsFile)
+            if (parseFeaturesFile(file, protocol))
             {
-              new FileLoader().LoadFile(viewport, file, protocol, format);
+              alignPanel.paintAlignment(true);
             }
+          }
             else
             {
-              alignPanel.paintAlignment(true);
+              new FileLoader().LoadFile(viewport, file, protocol, format);
             }
-          }
         }
       }
       if (isAnnotation)
@@ -5338,7 +5324,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       } catch (Exception x)
       {
       }
-      ;
       new OOMWarning(
               "loading data "
                       + (protocol != null ? (protocol.equals(FormatAdapter.PASTE) ? "from clipboard."
@@ -5749,6 +5734,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     viewport.firePropertyChange("alignment", null, al);
   }
 
+  @Override
   public void setShowSeqFeatures(boolean b)
   {
     showSeqFeatures.setSelected(b);
@@ -5975,7 +5961,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   {
     // TODO no longer a menu action - refactor as required
     final AlignmentI alignment = getViewport().getAlignment();
-    Set<AlignedCodonFrame> mappings = alignment.getCodonFrames();
+    List<AlignedCodonFrame> mappings = alignment.getCodonFrames();
     if (mappings == null)
     {
       return;
@@ -6030,6 +6016,27 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       sf.setComplementVisible(this, show);
     }
   }
+
+  /**
+   * Generate the reverse (optionally complemented) of the selected sequences,
+   * and add them to the alignment
+   */
+  @Override
+  protected void showReverse_actionPerformed(boolean complement)
+  {
+    AlignmentI al = null;
+    try
+    {
+      Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
+
+      al = dna.reverseCdna(complement);
+      viewport.addAlignment(al, "");
+    } catch (Exception ex)
+    {
+      System.err.println(ex.getMessage());
+      return;
+    }
+  }
 }
 
 class PrintThread extends Thread