Submissions for secondary structure prediction are now filtered to remove empty seque...
[jalview.git] / src / jalview / gui / AlignFrame.java
index f2d0b69..81e5564 100755 (executable)
@@ -34,6 +34,7 @@ import jalview.io.*;
 import jalview.jbgui.*;\r
 import jalview.schemes.*;\r
 import jalview.ws.*;\r
+import javax.swing.event.AncestorEvent;\r
 \r
 /**\r
  * DOCUMENT ME!\r
@@ -42,7 +43,7 @@ import jalview.ws.*;
  * @version $Revision$\r
  */\r
 public class AlignFrame\r
-    extends GAlignFrame\r
+    extends GAlignFrame implements ClipboardOwner\r
 {\r
   /** DOCUMENT ME!! */\r
   public static final int NEW_WINDOW_WIDTH = 700;\r
@@ -61,6 +62,7 @@ public class AlignFrame
   Stack redoList = new Stack();\r
   private int treeCount = 0;\r
 \r
+\r
   /**\r
    * Creates a new AlignFrame object.\r
    *\r
@@ -93,22 +95,24 @@ public class AlignFrame
     else if(sortby.equals("Pairwise Identity"))\r
       sortPairwiseMenuItem_actionPerformed(null);\r
 \r
-    tabbedPane.add(al.isNucleotide() ? "DNA":"Protein", alignPanel);\r
+   // remove(tabbedPane);\r
+    getContentPane().add(alignPanel, BorderLayout.CENTER);\r
+\r
+\r
+\r
+  //  tabbedPane.add(al.isNucleotide() ? "DNA":"Protein", alignPanel);\r
 \r
     ///Dataset tab\r
     /////////////////////////\r
-\r
     if(al.getDataset()==null)\r
     {\r
       al.setDataset(null);\r
     }\r
-\r
-    AlignViewport ds = new AlignViewport(al.getDataset());\r
-    ds.setDataset(true);\r
-    AlignmentPanel dap = new AlignmentPanel(this, ds);\r
-    tabbedPane.add("Dataset", dap);\r
-    viewports.add(ds);\r
-    alignPanels.add(dap);\r
+   // AlignViewport ds = new AlignViewport(al.getDataset(), true);\r
+   // AlignmentPanel dap = new AlignmentPanel(this, ds);\r
+  //  tabbedPane.add("Dataset", dap);\r
+  //  viewports.add(ds);\r
+  //  alignPanels.add(dap);\r
     /////////////////////////\r
 \r
 \r
@@ -124,8 +128,11 @@ public class AlignFrame
    });\r
 \r
 \r
-       if(Desktop.desktop!=null)\r
+  if (Desktop.desktop != null)\r
+  {\r
     addServiceListeners();\r
+    setGUINucleotide(al.isNucleotide());\r
+  }\r
   }\r
 \r
   /* Set up intrinsic listeners for dynamically generated GUI bits. */\r
@@ -162,6 +169,36 @@ public class AlignFrame
 \r
   }\r
 \r
+  public void setGUINucleotide(boolean nucleotide)\r
+  {\r
+    showTranslation.setVisible( nucleotide );\r
+    sequenceFeatures.setVisible(!nucleotide );\r
+    featureSettings.setVisible( !nucleotide );\r
+    conservationMenuItem.setVisible( !nucleotide );\r
+    modifyConservation.setVisible(   !nucleotide );\r
+\r
+    //Deal with separators\r
+    //Remember AlignFrame always starts as protein\r
+    if(nucleotide)\r
+    {\r
+      viewMenu.remove(viewMenu.getItemCount()-2);\r
+    }\r
+    else\r
+    {\r
+      calculateMenu.remove(calculateMenu.getItemCount()-2);\r
+    }\r
+  }\r
+\r
+\r
+  /*\r
+   Added so Castor Mapping file can obtain Jalview Version\r
+  */\r
+  public String getVersion()\r
+  {\r
+    return  jalview.bin.Cache.getProperty("VERSION");\r
+  }\r
+\r
+\r
   /**\r
    * DOCUMENT ME!\r
    *\r
@@ -217,11 +254,18 @@ public class AlignFrame
 \r
           type = st.nextToken();\r
 \r
+          if (fr.getColour(type) == null)\r
+          {\r
+            // Probably the old style groups file\r
+            UserColourScheme ucs = new UserColourScheme(type);\r
+            fr.setColour(type, ucs.findColour("A"));\r
+          }\r
+\r
+\r
           sf = new SequenceFeature(type, desc, "", start, end);\r
 \r
           seq.addSequenceFeature(sf);\r
 \r
-          System.out.println(sf.getType()+" "+sf.getBegin());\r
 \r
          // sg = new SequenceGroup(text, ucs, true, true, false, start, end);\r
          // sg.addSequence(seq, false);\r
@@ -232,7 +276,6 @@ public class AlignFrame
       }\r
 \r
       viewport.showSequenceFeatures = true;\r
-      ((Alignment)viewport.alignment).featuresAdded = true;\r
 \r
       alignPanel.repaint();\r
 \r
@@ -243,6 +286,12 @@ public class AlignFrame
     }\r
   }\r
 \r
+  public void fetchSequence_actionPerformed(ActionEvent e)\r
+  {\r
+    new SequenceFetcher(this);\r
+  }\r
+\r
+\r
   /**\r
    * DOCUMENT ME!\r
    *\r
@@ -361,7 +410,9 @@ public class AlignFrame
    */\r
   protected void htmlMenuItem_actionPerformed(ActionEvent e)\r
   {\r
-    new HTMLOutput(viewport);\r
+    new HTMLOutput(viewport,\r
+                   alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),\r
+        alignPanel.seqPanel.seqCanvas.getFeatureRenderer());\r
   }\r
 \r
   public void createImageMap(File file, String image)\r
@@ -596,6 +647,12 @@ public class AlignFrame
     alignPanel.repaint();\r
   }\r
 \r
+  public void lostOwnership(Clipboard clipboard, Transferable contents)\r
+  {\r
+    Desktop.jalviewClipboard = null;\r
+  }\r
+\r
+\r
   /**\r
    * DOCUMENT ME!\r
    *\r
@@ -605,7 +662,6 @@ public class AlignFrame
   {\r
     if (viewport.getSelectionGroup() == null)\r
     {\r
-      System.out.println("null here");\r
       return;\r
     }\r
 \r
@@ -614,7 +670,7 @@ public class AlignFrame
     Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();\r
 \r
     Hashtable orderedSeqs = new Hashtable();\r
-    SequenceI [] seqs = new SequenceI[sg.getSize()];\r
+    SequenceI[] seqs = new SequenceI[sg.getSize()];\r
 \r
     for (int i = 0; i < sg.getSize(); i++)\r
     {\r
@@ -645,7 +701,6 @@ public class AlignFrame
         }\r
       }\r
 \r
-\r
       //FIND START RES\r
       //Returns residue following index if gap\r
       startRes = seq.findPosition(sg.getStartRes());\r
@@ -669,12 +724,20 @@ public class AlignFrame
       }\r
 \r
       seqs[i] = new Sequence(seq.getName(),\r
-                             seq.getSequence(sg.getStartRes(), sg.getEndRes()+1),\r
+                             seq.getSequence(sg.getStartRes(), sg.getEndRes() + 1),\r
                              startRes,\r
                              endRes);\r
+      seqs[i].setDescription(seq.getDescription());\r
+      seqs[i].setDBRef(seq.getDBRef());\r
+      seqs[i].setSequenceFeatures(seq.getSequenceFeatures());\r
+      seqs[i].setDatasetSequence(seq.getDatasetSequence());\r
+\r
     }\r
 \r
-    c.setContents(new StringSelection(new FastaFile().print(seqs)), null);\r
+    FastaFile ff = new FastaFile();\r
+    ff.addJVSuffix( viewport.showJVSuffix );\r
+    c.setContents(new StringSelection( ff.print(seqs)), this);\r
+    Desktop.jalviewClipboard = new Object[]{seqs,  viewport.alignment.getDataset()};\r
   }\r
 \r
   /**\r
@@ -721,13 +784,30 @@ public class AlignFrame
         return;\r
 \r
       String format = IdentifyFile.Identify(str, "Paste");\r
-      SequenceI[] sequences = new FormatAdapter().readFile(str, "Paste", format);\r
+      SequenceI[] sequences;\r
 \r
+     if(Desktop.jalviewClipboard!=null)\r
+     {\r
+       // The clipboard was filled from within Jalview, we must use the sequences\r
+       // And dataset from the copied alignment\r
+       sequences = (SequenceI[])Desktop.jalviewClipboard[0];\r
+     }\r
+     else\r
+     {\r
+       sequences = new FormatAdapter().readFile(str, "Paste", format);\r
+     }\r
 \r
       if (newAlignment)\r
       {\r
+\r
         Alignment alignment = new Alignment(sequences);\r
-        alignment.setDataset( viewport.alignment.getDataset() );\r
+\r
+        if(Desktop.jalviewClipboard!=null)\r
+           alignment.setDataset( (Alignment)Desktop.jalviewClipboard[1] );\r
+        else\r
+           alignment.setDataset( null );\r
+\r
+\r
         AlignFrame af = new AlignFrame(alignment);\r
         String newtitle = new String("Copied sequences");\r
 \r
@@ -747,8 +827,25 @@ public class AlignFrame
       {\r
         //!newAlignment\r
         for (int i = 0; i < sequences.length; i++)\r
-          viewport.alignment.addSequence(sequences[i]);\r
+        {\r
+          Sequence newseq = new Sequence(sequences[i].getName(),\r
+              sequences[i].getSequence(), sequences[i].getStart(),\r
+              sequences[i].getEnd());\r
+          viewport.alignment.addSequence(newseq);\r
+          if(sequences[i].getDatasetSequence()==null)\r
+          {\r
+             ////////////////////////////\r
+            //Datset needs extension;\r
+            /////////////////////////////\r
+            Sequence ds = new Sequence(sequences[i].getName(),\r
+                                       AlignSeq.extractGaps("-. ", sequences[i].getSequence()),\r
+                                       sequences[i].getStart(),\r
+                                       sequences[i].getEnd());\r
+            newseq.setDatasetSequence(ds);\r
+            viewport.alignment.getDataset().addSequence(ds);\r
+          }\r
 \r
+        }\r
         viewport.setEndSeq(viewport.alignment.getHeight());\r
         viewport.alignment.getWidth();\r
         viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());\r
@@ -881,6 +978,7 @@ public class AlignFrame
     viewport.setSelectionGroup(null);\r
     viewport.getColumnSelection().clear();\r
     viewport.setSelectionGroup(null);\r
+    alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);\r
     alignPanel.annotationPanel.activeRes = null;\r
     PaintRefresher.Refresh(null, viewport.alignment);\r
   }\r
@@ -1108,16 +1206,6 @@ public class AlignFrame
    if(alignPanel.overviewPanel!=null)\r
      alignPanel.overviewPanel.updateOverviewImage();\r
 \r
-  Provenance prov = viewport.alignment.getProvenance();\r
-  if(prov == null)\r
-   {\r
-     prov = new Provenance();\r
-     viewport.alignment.setProvenance(prov);\r
-   }\r
-\r
-   prov.addEntry("Me",\r
-       "Edited in Jalview", new java.util.Date(), "myID");\r
-\r
    alignPanel.repaint();\r
  }\r
 \r
@@ -1216,14 +1304,15 @@ public class AlignFrame
    *\r
    * @param e DOCUMENT ME!\r
    */\r
-  protected void fullSeqId_actionPerformed(ActionEvent e)\r
+  protected void seqLimit_actionPerformed(ActionEvent e)\r
   {\r
-    viewport.setShowFullId(fullSeqId.isSelected());\r
+    viewport.setShowJVSuffix(seqLimits.isSelected());\r
 \r
     alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel.calculateIdWidth());\r
     alignPanel.repaint();\r
   }\r
 \r
+\r
   /**\r
    * DOCUMENT ME!\r
    *\r
@@ -1325,11 +1414,10 @@ public class AlignFrame
   {\r
     viewport.showSequenceFeatures(sequenceFeatures.isSelected());\r
 \r
-    if (viewport.showSequenceFeatures &&\r
-        ! ( (Alignment) viewport.alignment).featuresAdded)\r
+    if (viewport.showSequenceFeatures)\r
     {\r
       new SequenceFeatureFetcher(viewport.\r
-          alignment,\r
+         alignment,\r
           alignPanel);\r
     }\r
 \r
@@ -2120,7 +2208,16 @@ public class AlignFrame
   {\r
     SequenceI seq = null;\r
     SequenceI[] msa = null;\r
+/*\r
+         if (predictindex==-1) {\r
 \r
+          JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
+                                                "The alignment contains no columns or residues usable for prediction!",\r
+                                                "Invalid Alignment Selection", JOptionPane.WARNING_MESSAGE);\r
+          this.\r
+          return;\r
+        }\r
+*/\r
     if ( (viewport.getSelectionGroup() != null) &&\r
         (viewport.getSelectionGroup().getSize() > 0))\r
     {\r
@@ -2310,7 +2407,7 @@ public class AlignFrame
             {\r
               SequenceI[] msa = gatherSequencesForAlignment();\r
               new jalview.ws.MsaWSClient(sh, title, msa,\r
-                  false, true);\r
+                  false, true, viewport.getAlignment().getDataset());\r
 \r
             }\r
 \r
@@ -2327,7 +2424,7 @@ public class AlignFrame
               {\r
                 SequenceI[] msa = gatherSequencesForAlignment();\r
                 new jalview.ws.MsaWSClient(sh, title, msa,\r
-                    true, true);\r
+                    true, true, viewport.getAlignment().getDataset());\r
 \r
               }\r
 \r
@@ -2351,7 +2448,18 @@ public class AlignFrame
           {\r
             public void actionPerformed(ActionEvent e)\r
             {\r
-              SequenceI[] msa = gatherSeqOrMsaForSecStrPrediction();\r
+              SequenceI[] msa = SeqsetUtils.getNonEmptySequenceSet(gatherSeqOrMsaForSecStrPrediction());\r
+              if (msa==null) {\r
+                JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
+                    "There are no columns or residues usable for prediction!\n"\r
+                    +"There must be valid residues in at least one\n"\r
+                    +"of the sequences in the alignment,\n"\r
+                    +"or in the currently selected region.",\r
+                    "Invalid Input for Secondary Structure Prediction",\r
+                    JOptionPane.WARNING_MESSAGE);\r
+                return;\r
+              }\r
+\r
               if (msa.length == 1)\r
               {\r
                 // Single Sequence prediction\r
@@ -2361,7 +2469,7 @@ public class AlignFrame
               {\r
                 if (msa.length > 1)\r
                 {\r
-                  // Single Sequence prediction\r
+                  // Aligned Sequences prediction\r
                   jalview.ws.JPredClient ct = new jalview.ws.JPredClient(sh,\r
                       title, msa);\r
                 }\r
@@ -2388,7 +2496,7 @@ public class AlignFrame
     // TODO: group services by location as well as function.\r
   }\r
 \r
-  public void vamsasStore_actionPerformed(ActionEvent e)\r
+ /* public void vamsasStore_actionPerformed(ActionEvent e)\r
   {\r
     JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.\r
         getProperty("LAST_DIRECTORY"));\r
@@ -2402,10 +2510,10 @@ public class AlignFrame
     if (value == JalviewFileChooser.APPROVE_OPTION)\r
     {\r
       jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);\r
-      vs.store(chooser.getSelectedFile().getAbsolutePath()\r
-          );\r
+      //vs.store(chooser.getSelectedFile().getAbsolutePath()   );\r
+      vs.storeJalview( chooser.getSelectedFile().getAbsolutePath(), this);\r
     }\r
-  }\r
+  }*/\r
 \r
   public void featureSettings_actionPerformed(ActionEvent e)\r
   {\r
@@ -2416,29 +2524,20 @@ public class AlignFrame
 \r
 public void showTranslation_actionPerformed(ActionEvent e)\r
 {\r
-\r
-  if(!viewport.alignment.isNucleotide())\r
-    return;\r
-\r
-  viewport.showTranslation(showTranslation.isSelected());\r
-\r
-  if(!viewport.alignment.isNucleotide())\r
-    return;\r
-\r
   int s, sSize = viewport.alignment.getHeight();\r
   SequenceI [] newSeq = new SequenceI[sSize];\r
 \r
   int res, resSize;\r
   StringBuffer protein;\r
-  SequenceI seq;\r
+  String seq;\r
   for(s=0; s<sSize; s++)\r
   {\r
     protein = new StringBuffer();\r
-    seq = (SequenceI)viewport.alignment.getSequenceAt(s);\r
-    resSize = seq.getLength();\r
+    seq = AlignSeq.extractGaps("-. ", viewport.alignment.getSequenceAt(s).getSequence());\r
+    resSize = seq.length();\r
     for(res = 0; res < resSize; res+=3)\r
     {\r
-      String codon = seq.getSequence(res, res+3);\r
+      String codon = seq.substring(res, res+3);\r
       codon = codon.replace('U', 'T');\r
       String aa = ResidueProperties.codonTranslate(codon);\r
       if(aa==null)\r
@@ -2448,7 +2547,7 @@ public void showTranslation_actionPerformed(ActionEvent e)
       else\r
         protein.append( aa );\r
     }\r
-    newSeq[s] = new Sequence(seq.getName(), protein.toString());\r
+    newSeq[s] = new Sequence(viewport.alignment.getSequenceAt(s).getName(), protein.toString());\r
   }\r
 \r
 \r
@@ -2497,35 +2596,36 @@ public void showTranslation_actionPerformed(ActionEvent e)
   }\r
 \r
 \r
-   // Desktop.addInternalFrame(af, "Translation of "+this.getTitle(),\r
-    //                         NEW_WINDOW_WIDTH,\r
-     //                        NEW_WINDOW_HEIGHT);\r
+    AlignFrame af = new AlignFrame(al);\r
+    Desktop.addInternalFrame(af, "Translation of "+this.getTitle(),\r
+                             NEW_WINDOW_WIDTH,\r
+                             NEW_WINDOW_HEIGHT);\r
+\r
 \r
-    AlignViewport newViewport = new AlignViewport(al);\r
-    AlignmentPanel ap = new AlignmentPanel(this, newViewport);\r
-    tabbedPane.add("Protein", ap);\r
-    viewports.add(newViewport);\r
-    alignPanels.add(ap);\r
+   // AlignViewport newViewport = new AlignViewport(al);\r
+   // AlignmentPanel ap = new AlignmentPanel(this, newViewport);\r
+   // tabbedPane.add("Protein", ap);\r
+   // viewports.add(newViewport);\r
+  //  alignPanels.add(ap);\r
 \r
     ///Dataset tab\r
   /////////////////////////\r
 \r
-    AlignViewport ds = new AlignViewport(al.getDataset());\r
-    ds.setDataset(true);\r
-    AlignmentPanel dap = new AlignmentPanel(this, ds);\r
-    tabbedPane.add("Dataset", dap);\r
-    viewports.add(ds);\r
-    alignPanels.add(dap);\r
+  //  AlignViewport ds = new AlignViewport(al.getDataset());\r
+  //  ds.setDataset(true);\r
+  //  AlignmentPanel dap = new AlignmentPanel(this, ds);\r
+  //  tabbedPane.add("Dataset", dap);\r
+  //  viewports.add(ds);\r
+  //  alignPanels.add(dap);\r
   /////////////////////////\r
 \r
 \r
 }\r
 \r
-public void tabSelected()\r
-{\r
+/*public void tabSelected()\r
+ {\r
   int index = tabbedPane.getSelectedIndex();\r
   viewport = (AlignViewport)viewports.elementAt(index);\r
   alignPanel = (AlignmentPanel)alignPanels.elementAt(index);\r
-}\r
-\r
+ }*/\r
 }\r