Reinstated 'create tree from selected region only' with better indication that only...
[jalview.git] / src / jalview / gui / AlignFrame.java
index 6447005..4d97f49 100755 (executable)
@@ -82,8 +82,11 @@ public class AlignFrame extends GAlignFrame
 
       if (currentFileFormat.equals("Jalview"))
       {
-        String shortName = title.replace('/', '_');
-        title = title.replace('\\', '_');
+        String shortName = title;
+        if(shortName.indexOf(java.io.File.separatorChar)>-1)
+              shortName = shortName.substring(
+                    shortName.lastIndexOf(java.io.File.separatorChar)+1);
+
         String choice = chooser.getSelectedFile().getPath();
         Jalview2XML.SaveState(this, choice, shortName);
         // USE Jalview2XML to save this file
@@ -106,9 +109,7 @@ public class AlignFrame extends GAlignFrame
   protected void outputText_actionPerformed(ActionEvent e)
   {
      CutAndPasteTransfer cap = new CutAndPasteTransfer();
-     JInternalFrame frame = new JInternalFrame();
-     frame.setContentPane(cap);
-     Desktop.addInternalFrame(frame, "Alignment output - "+e.getActionCommand(), 600, 500);
+     Desktop.addInternalFrame(cap, "Alignment output - "+e.getActionCommand(), 600, 500);
      cap.setText( FormatAdapter.formatSequences(e.getActionCommand(), viewport.getAlignment().getSequences()));
   }
 
@@ -252,12 +253,12 @@ public class AlignFrame extends GAlignFrame
             viewport.alignment.deleteSequence(i);
         }
       }
-      viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
       updateEditMenuBar();
 
       viewport.updateConsensus();
       viewport.updateConservation();
       alignPanel.repaint();
+      viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
   }
 
   public void moveSelectedSequences(boolean up)
@@ -997,7 +998,7 @@ public class AlignFrame extends GAlignFrame
 
   public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
   {
-    RedundancyPanel sp = new RedundancyPanel(alignPanel, this);
+    RedundancyPanel sp = new RedundancyPanel(alignPanel,this);
     JInternalFrame frame = new JInternalFrame();
     frame.setContentPane(sp);
     Desktop.addInternalFrame(frame, "Redundancy threshold selection", 400, 100, false);
@@ -1006,7 +1007,8 @@ public class AlignFrame extends GAlignFrame
 
   public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
   {
-    if(viewport.getSelectionGroup().getSize()<2)
+    if((viewport.getSelectionGroup()==null) ||
+       viewport.getSelectionGroup().getSize()<2)
       JOptionPane.showInternalMessageDialog(this, "You must select at least 2 sequences.", "Invalid Selection", JOptionPane.WARNING_MESSAGE);
     else
     {
@@ -1066,33 +1068,51 @@ public class AlignFrame extends GAlignFrame
 
   void NewTreePanel(String type, String pwType, String title)
   {
-    //are the sequences aligned?
-    if(!viewport.alignment.isAligned())
-    {
-      JOptionPane.showMessageDialog(Desktop.desktop, "The sequences must be aligned before creating a tree.\n"
-                                   +"Try using the Pad function in the edit menu,\n"
-                                  +"or one of the multiple sequence alignment web services.",
-                                    "Sequences not aligned", JOptionPane.WARNING_MESSAGE);
-      return;
-    }
-
+    String ltitle;
     final TreePanel tp;
     if (viewport.getSelectionGroup() != null &&
         viewport.getSelectionGroup().getSize() > 3)
     {
+      int s=0;
+      SequenceGroup sg = viewport.getSelectionGroup();
+
+      /* Decide if the selection is a column region */
+      while (s<sg.sequences.size()) {
+        if (((SequenceI) sg.sequences.elementAt(s++)).getLength()<sg.getEndRes()) {
+          JOptionPane.showMessageDialog(Desktop.desktop,
+                                        "The selected region to create a tree may\nonly contain residues or gaps.\n"
+                                       +"Try using the Pad function in the edit menu,\n"
+                                      +"or one of the multiple sequence alignment web services.",
+                                        "Sequences in selection are not aligned", JOptionPane.WARNING_MESSAGE);
+          return;
+        }
+
+      }
+      title=title+" on region";
       tp = new TreePanel(viewport, viewport.getSelectionGroup().sequences, type,
                          pwType,
-                         0, viewport.alignment.getWidth());
+                         sg.getStartRes(), sg.getEndRes());
     }
     else
     {
-      tp = new TreePanel(viewport, viewport.getAlignment().getSequences(),
-                         type, pwType, 0, viewport.alignment.getWidth());
-    }
+
+     //are the sequences aligned?
+     if(!viewport.alignment.isAligned())
+     {
+       JOptionPane.showMessageDialog(Desktop.desktop, "The sequences must be aligned before creating a tree.\n"
+                                     +"Try using the Pad function in the edit menu,\n"
+                                     +"or one of the multiple sequence alignment web services.",
+                                     "Sequences not aligned", JOptionPane.WARNING_MESSAGE);
+       return;
+     }
+     tp = new TreePanel(viewport, viewport.getAlignment().getSequences(),
+                        type, pwType, 0, viewport.alignment.getWidth());
+   }
 
    addTreeMenuItem(tp, title);
+   viewport.setCurrentTree(tp.getTree());
 
-   Desktop.addInternalFrame(tp, title, 600, 500);
+   Desktop.addInternalFrame(tp, title+" from "+this.title, 600, 500);
   }
 
   public void addSortByOrderMenuItem(String title, final AlignmentOrder order) {
@@ -1188,10 +1208,46 @@ public class AlignFrame extends GAlignFrame
 
         }
         if (msa!=null) {
+          jalview.ws.MsaWSClient ct = new jalview.ws.MsaWSClient("ClustalWS", title, msa, false, true);
+        }
+  }
+  public void ClustalRealign_actionPerformed(ActionEvent e)
+  {
+      // TODO:resolve which menu item was actually selected
+      // Now, check we have enough sequences
+        SequenceI[] msa=null;
+        if (viewport.getSelectionGroup() != null && viewport.getSelectionGroup().getSize()>1)
+        {
+          // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
+          SequenceGroup seqs = viewport.getSelectionGroup();
+          int sz;
+          msa = new SequenceI[sz=seqs.getSize()];
+          for (int i = 0; i < sz; i++)
+          {
+            msa[i] = (SequenceI) seqs.getSequenceAt(i);
+          }
+
+          }
+        else
+        {
+          Vector seqs = viewport.getAlignment().getSequences();
+
+          if (seqs.size() > 1) {
+            msa = new SequenceI[seqs.size()];
+            for (int i = 0; i < seqs.size(); i++)
+            {
+              msa[i] = (SequenceI) seqs.elementAt(i);
+            }
+
+          }
+
+        }
+        if (msa!=null) {
           jalview.ws.MsaWSClient ct = new jalview.ws.MsaWSClient("ClustalWS", title, msa, true, true);
         }
   }
 
+
   protected void jpred_actionPerformed(ActionEvent e)
 {
     SequenceI seq=null;
@@ -1274,7 +1330,7 @@ public class AlignFrame extends GAlignFrame
 
       }
       if (msa!=null) {
-        MsaWSClient ct = new jalview.ws.MsaWSClient("MuscleWS",title, msa, true, true);
+        MsaWSClient ct = new jalview.ws.MsaWSClient("MuscleWS",title, msa, false, true);
       }
   }
     protected void LoadtreeMenuItem_actionPerformed(ActionEvent e) {