JAL-468 JAL-936 sort alignment by tree and autosort for new tree
authorjprocter <jprocter@compbio.dundee.ac.uk>
Fri, 16 Sep 2011 10:29:22 +0000 (11:29 +0100)
committerjprocter <jprocter@compbio.dundee.ac.uk>
Fri, 16 Sep 2011 10:29:22 +0000 (11:29 +0100)
help/html/calculations/treeviewer.html
help/html/menus/alwcalculate.html
src/jalview/appletgui/AlignFrame.java
src/jalview/gui/AlignFrame.java
src/jalview/gui/Preferences.java
src/jalview/gui/TreePanel.java
src/jalview/jbgui/GAlignFrame.java
src/jalview/jbgui/GPreferences.java
src/jalview/jbgui/GTreePanel.java

index 32db2ce..514b8c8 100755 (executable)
@@ -76,8 +76,8 @@ the tree. Tree imported from outside may also contain bootstrap information,
 and additional leaves from sequences not present in the associated
 alignment.
 </p>
-<p>The view menu contains options controlling the way a tree is
-rendered and labelled:
+<p>The view menu mostly contains options controlling the way a tree is
+rendered and labeled:
 <ul>
 <li><strong>Fit to Window</strong><p>
 The tree layout will be scaled to fit in the  display
@@ -99,12 +99,19 @@ Toggles the display of a '*' at the beginning of a leaf label to
 indicate that there is no sequence corresponding to that leaf in the
 associated alignment.
 </p></li>
-<li><strong>Associate Leaves with ...</strong><p>
-Only visible when there are <a href="../features/multipleviews.html">multiple views</a> of the same
-alignment to show and edit which alignment views are associated with
-the leaves of the displayed tree.
-</p>
-</ul>
+               <li><strong>Sort Alignment By Tree</strong>
+               <p>
+                               Sorts any associated alignment views using the current tree. (<em>Only
+                                       available in the Jalview Desktop</em>)
+                       </p>
+               </li>
+               <li><strong>Associate Leaves with ...</strong>
+               <p>
+                               Only visible when there are <a href="../features/multipleviews.html">multiple
+                                       views</a> of the same alignment to show and edit which alignment views
+                               are associated with the leaves of the displayed tree.
+                       </p>
+       </ul>
 </p>
 </body>
 </html>
index 85ec95c..01b84cd 100755 (executable)
  * 
  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
 -->
-<head><title>Alignment Window Menus</title></head>
+<head>
+<title>Alignment Window Menus</title>
+</head>
 
 <body>
-<p><strong>Alignment Window Calculate Menu</strong></p>
-<ul>
-  <li><strong>Sort </strong> 
-    <ul>
-      <li><strong>by ID</strong><em><br>
-        This will sort the sequences according to sequence name. If the sort is 
-        repeated, the order of the sorted sequences will be inverted. </em></li>
-      <li><strong>by Length</strong><em><br>
-        This will sort the sequences according to their length (excluding gap characters). If the sort is 
-        repeated, the order of the sorted sequences will be inverted. </em></li>
-      <li><strong>by Group</strong><strong><br>
-        </strong><em>This will sort the sequences according to sequence name. 
-        If the sort is repeated, the order of the sorted sequences will be inverted. 
-        </em><strong></strong></li>
-      <li><strong>by Pairwise Identity<br>
-        </strong><em>This will sort the selected sequences by their percentage 
-        identity to the consensus sequence. The most similar sequence is put at 
-        the top. </em></li>
-      <li><em>The <a href="../calculations/sorting.html">Sort menu</a> will have 
-        some additional options if the alignment has any associated
-       score annotation, or you have just done a multiple alignment calculation
-        or opened a tree viewer window.</em><br>
-      </li>
-    </ul>
-  </li>
-  <li><strong>Calculate Tree </strong> <br>
-    <em>Functions for calculating trees on the alignment or the currently selected 
-    region. See <a
-    href="../calculations/tree.html">calculating trees</a>.</em> 
-    <ul>
-      <li><strong>Average Distance Using % Identity</strong></li>
-      <li><strong>Neighbour Joining Using % Identity</strong></li>
-      <li><strong>Average Distance Using Blosum62</strong></li>
-      <li><strong>Neighbour Joining Using Blosum62<br>
-        </strong></li>
-    </ul>
-  </li>
-  <li><strong>Pairwise Alignments</strong><br>
-    <em>Applies Smith and Waterman algorithm to selected sequences. See <a href="../calculations/pairwise.html">pairwise 
-    alignments</a>.</em><br>
-  </li>
-  <li><strong>Principal Component Analysis</strong><br>
-    <em>Shows a spatial clustering of the sequences based on the BLOSUM62 scores 
-    in the alignment. See <a href="../calculations/pca.html">Principal Component 
-    Analysis</a>.</em> <br>
-  </li>
-       <li><strong>Extract Scores ... (optional)</strong><br>
-               <em>This option is only visible if Jalview detects one or more white-space separated values in the description line of the alignment sequences.<br>
-               When selected, these numbers are parsed into sequence associated annotation which can 
-               then be used to sort the alignment via the Sort by&#8594;Score menu.</em> <br>
-       </li>
-  
-  <li><strong>Autocalculate Consensus</strong><br>
-    <em>For large alignments it can be useful to deselect &quot;Autocalculate 
-    Consensus&quot; when editing. This prevents the sometimes lengthy calculations 
-    performed after each sequence edit.</em> <br>
-  </li>
-</ul>
-  </body>
+       <p>
+               <strong>Alignment Window Calculate Menu</strong>
+       </p>
+       <ul>
+               <li><strong>Sort </strong>
+                       <ul>
+                               <li><strong>by ID</strong><em><br> This will sort the
+                                               sequences according to sequence name. If the sort is repeated, the
+                                               order of the sorted sequences will be inverted. </em>
+                               </li>
+                               <li><strong>by Length</strong><em><br> This will sort
+                                               the sequences according to their length (excluding gap
+                                               characters). If the sort is repeated, the order of the sorted
+                                               sequences will be inverted. </em>
+                               </li>
+                               <li><strong>by Group</strong><strong><br> </strong><em>This
+                                               will sort the sequences according to sequence name. If the sort is
+                                               repeated, the order of the sorted sequences will be inverted. </em><strong></strong>
+                               </li>
+                               <li><strong>by Pairwise Identity<br> </strong><em>This
+                                               will sort the selected sequences by their percentage identity to
+                                               the consensus sequence. The most similar sequence is put at the
+                                               top. </em>
+                               </li>
+                               <li><em>The <a href="../calculations/sorting.html">Sort
+                                                       menu</a> will have some additional options if the alignment has any
+                                               associated score annotation, or you have just done a multiple
+                                               alignment calculation or opened a tree viewer window.</em><br></li>
+                       </ul></li>
+               <li><strong>Calculate Tree </strong> <br> <em>Functions
+                               for calculating trees on the alignment or the currently selected
+                               region. See <a href="../calculations/tree.html">calculating
+                                       trees</a>.</em>
+                       <ul>
+                               <li><strong>Average Distance Using % Identity</strong>
+                               </li>
+                               <li><strong>Neighbour Joining Using % Identity</strong>
+                               </li>
+                               <li><strong>Average Distance Using Blosum62</strong>
+                               </li>
+                               <li><strong>Neighbour Joining Using Blosum62<br>
+                               </strong>
+                               </li>
+                       </ul></li>
+               <li><strong>Pairwise Alignments</strong><br> <em>Applies
+                               Smith and Waterman algorithm to selected sequences. See <a
+                               href="../calculations/pairwise.html">pairwise alignments</a>.</em><br>
+               </li>
+               <li><strong>Principal Component Analysis</strong><br> <em>Shows
+                               a spatial clustering of the sequences based on the BLOSUM62 scores
+                               in the alignment. See <a href="../calculations/pca.html">Principal
+                                       Component Analysis</a>.</em> <br></li>
+               <li><strong>Extract Scores ... (optional)</strong><br> <em>This
+                               option is only visible if Jalview detects one or more white-space
+                               separated values in the description line of the alignment sequences.<br>
+                               When selected, these numbers are parsed into sequence associated
+                               annotation which can then be used to sort the alignment via the Sort
+                               by&#8594;Score menu.</em> <br></li>
+
+               <li><strong>Autocalculate Consensus</strong><br> <em>For
+                               large alignments it can be useful to deselect &quot;Autocalculate
+                               Consensus&quot; when editing. This prevents the sometimes lengthy
+                               calculations performed after each sequence edit.</em> <br></li>
+               <li><strong>Sort Alignment With New Tree</strong><br> <em>If
+                               this option is selected, the alignment will be automatically sorted
+                               whenever a new tree is calculated or loaded.</em> <br>
+               </li>
+       </ul>
+</body>
 </html>
index 7030637..0263d72 100644 (file)
@@ -601,6 +601,10 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     {\r
       viewport.autocalculateConsensus = autoCalculate.getState();\r
     }\r
+    else if (evt.getSource() == sortByTree)\r
+    {\r
+      viewport.sortByTree = sortByTree.getState();\r
+    }\r
     else if (evt.getSource() == this.centreColumnLabelFlag)\r
     {\r
       centreColumnLabelFlag_stateChanged();\r
@@ -2551,7 +2555,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
         sortByTree(treePanel, title); // treePanel.getTitle());\r
       }\r
     });\r
-\r
+    \r
     treePanel.addWindowListener(new WindowAdapter()\r
     {\r
       public void windowOpened(WindowEvent e)\r
@@ -2585,6 +2589,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     alignPanel.paintAlignment(true);\r
     return true;\r
   }\r
+\r
   protected void documentation_actionPerformed()\r
   {\r
     alignPanel.av.applet.openJalviewHelpUrl();\r
@@ -2818,6 +2823,9 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   CheckboxMenuItem autoCalculate = new CheckboxMenuItem(\r
           "Autocalculate Consensus", true);\r
 \r
+  CheckboxMenuItem sortByTree = new CheckboxMenuItem(\r
+          "Sort Alignment With New Tree", true);\r
+\r
   Menu sortByTreeMenu = new Menu();\r
 \r
   Menu sort = new Menu();\r
@@ -3013,6 +3021,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     sort.setLabel("Sort");\r
     calculate.setLabel("Calculate Tree");\r
     autoCalculate.addItemListener(this);\r
+    sortByTree.addItemListener(this);\r
     inputText.setLabel("Input from textbox");\r
     inputText.addActionListener(this);\r
     centreColumnLabelFlag.setLabel("Centre column labels");\r
@@ -3157,6 +3166,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     calculateMenu.add(pairwiseAlignmentMenuItem);\r
     calculateMenu.add(PCAMenuItem);\r
     calculateMenu.add(autoCalculate);\r
+    calculateMenu.add(sortByTree);\r
     this.add(statusBar, BorderLayout.SOUTH);\r
     pasteMenu.add(pasteNew);\r
     pasteMenu.add(pasteThis);\r
index b9ba4e0..9df4931 100755 (executable)
@@ -699,6 +699,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     applyToAllGroups.setState(av.colourAppliesToAllGroups);
     showNpFeatsMenuitem.setSelected(av.isShowNpFeats());
     showDbRefsMenuitem.setSelected(av.isShowDbRefs());
+    autoCalculate.setSelected(av.autoCalculateConsensus);
+    sortByTree.setSelected(av.sortByTree);
 
     setShowProductsEnabled();
 
@@ -3420,6 +3422,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
               .getAlignment().getSequences());
     }
   }
+  public void sortByTreeOption_actionPerformed(ActionEvent e)
+  {
+    viewport.sortByTree = sortByTree.isSelected();
+  }
 
   /**
    * DOCUMENT ME!
@@ -3703,21 +3709,16 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
     for (i = 0; i < treePanels.size(); i++)
     {
-      TreePanel tp = (TreePanel) treePanels.elementAt(i);
+      final TreePanel tp = (TreePanel) treePanels.elementAt(i);
       final JMenuItem item = new JMenuItem(tp.getTitle());
       final NJTree tree = ((TreePanel) treePanels.elementAt(i)).getTree();
       item.addActionListener(new java.awt.event.ActionListener()
       {
         public void actionPerformed(ActionEvent e)
         {
-          SequenceI[] oldOrder = viewport.getAlignment()
-                  .getSequencesArray();
-          AlignmentSorter.sortByTree(viewport.getAlignment(), tree);
-
-          addHistoryItem(new OrderCommand("Tree Sort", oldOrder,
-                  viewport.alignment));
-
-          alignPanel.paintAlignment(true);
+          tp.sortByTree_actionPerformed(null);
+          addHistoryItem(tp.sortAlignmentIn(alignPanel));
+          
         }
       });
 
index 9267800..80a42a9 100755 (executable)
@@ -137,7 +137,7 @@ public class Preferences extends GPreferences
             .getDefault("SHOW_NPFEATS_TOOLTIP", true));
     showDbRefTooltip.setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP",
             true));
-
+    sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
     for (int i = ColourSchemeProperty.FIRST_COLOUR; i <= ColourSchemeProperty.LAST_COLOUR; i++)
     {
       colour.addItem(ColourSchemeProperty.getColourName(i));
@@ -452,6 +452,8 @@ public class Preferences extends GPreferences
 
     Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
             Boolean.toString(autoCalculateConsCheck.isSelected()));
+    Cache.applicationProperties.setProperty("SORT_BY_TREE",
+            Boolean.toString(sortByTree.isSelected()));
     Cache.applicationProperties.setProperty("PAD_GAPS",
             Boolean.toString(padGaps.isSelected()));
 
index ea0b791..3b7cb14 100755 (executable)
@@ -29,6 +29,7 @@ import javax.swing.*;
 
 import org.jibble.epsgraphics.*;
 import jalview.analysis.*;
+import jalview.commands.CommandI;
 import jalview.commands.OrderCommand;
 import jalview.datamodel.*;
 import jalview.io.*;
@@ -508,17 +509,72 @@ public class TreePanel extends GTreePanel
    */
   public void sortByTree_actionPerformed(ActionEvent e)
   {
-    AlignmentPanel ap = av.getAlignPanel();
-    SequenceI[] oldOrder = av.getAlignment().getSequencesArray();
-    AlignmentSorter.sortByTree(av.getAlignment(), tree);
-
-    ap.alignFrame.addHistoryItem(new OrderCommand("Tree Sort", oldOrder,
-            av.alignment));
+    
+    if (treeCanvas.applyToAllViews)
+    {
+      final ArrayList<CommandI> commands = new ArrayList<CommandI>();
+      for (AlignmentPanel ap: PaintRefresher.getAssociatedPanels(av
+              .getSequenceSetId()))
+      {
+        commands.add(sortAlignmentIn(ap.av.getAlignPanel()));
+      }
+      av.getAlignPanel().alignFrame.addHistoryItem(new CommandI()
+      {
+        
+        @Override
+        public void undoCommand(AlignmentI[] views)
+        {
+          for (CommandI tsort:commands)
+          {
+            tsort.undoCommand(views);
+          }          
+        }
+        
+        @Override
+        public int getSize()
+        {
+          return commands.size();
+        }
+        
+        @Override
+        public String getDescription()
+        {
+          return "Tree Sort (many views)";
+        }
+        
+        @Override
+        public void doCommand(AlignmentI[] views)
+        {
 
-    ap.paintAlignment(true);
+          for (CommandI tsort:commands)
+          {
+            tsort.doCommand(views);
+          }          
+        }
+      });
+      for (AlignmentPanel ap: PaintRefresher.getAssociatedPanels(av
+              .getSequenceSetId()))
+      {
+        // ensure all the alignFrames refresh their GI after adding an undo item
+        ap.alignFrame.updateEditMenuBar();
+      }
+    } else {
+      treeCanvas.ap.alignFrame.addHistoryItem(sortAlignmentIn(treeCanvas.ap));
+    }
 
   }
+  public CommandI sortAlignmentIn(AlignmentPanel ap)
+  {
+    AlignViewport av = ap.av;
+    SequenceI[] oldOrder = av.getAlignment().getSequencesArray();
+    AlignmentSorter.sortByTree(av.getAlignment(), tree);
+    CommandI undo;
+    undo=new OrderCommand("Tree Sort", oldOrder,
+          av.alignment);
 
+    ap.paintAlignment(true);    
+    return undo;
+  }
   /**
    * DOCUMENT ME!
    * 
index 9260b23..22d27e9 100755 (executable)
@@ -221,6 +221,8 @@ public class GAlignFrame extends JInternalFrame
 
   protected JCheckBoxMenuItem autoCalculate = new JCheckBoxMenuItem();
 
+  protected JCheckBoxMenuItem sortByTree = new JCheckBoxMenuItem();
+
   JMenu addSequenceMenu = new JMenu();
 
   JMenuItem addFromFile = new JMenuItem();
@@ -1403,6 +1405,18 @@ public class GAlignFrame extends JInternalFrame
         autoCalculate_actionPerformed(e);
       }
     });
+    sortByTree.setText("Sort Alignment With New Tree");
+    sortByTree.setToolTipText("<html>Enable this to automatically sort<br>the alignment when you open<br> a new tree.");
+    sortByTree.setState(jalview.bin.Cache.getDefault(
+            "SORT_BY_TREE", false));
+    sortByTree.addActionListener(new ActionListener()
+    {
+      public void actionPerformed(ActionEvent e)
+      {
+        sortByTreeOption_actionPerformed(e);
+      }
+    });
+    
     addSequenceMenu.setText("Add Sequences");
     addFromFile.setText("From File");
     addFromFile.addActionListener(new ActionListener()
@@ -1749,6 +1763,7 @@ public class GAlignFrame extends JInternalFrame
     calculateMenu.add(showTranslation);
     calculateMenu.add(showProducts);
     calculateMenu.add(autoCalculate);
+    calculateMenu.add(sortByTree);
     calculateMenu.addSeparator();
     calculateMenu.add(extractScores);
     webServiceNoServices = new JMenuItem("<No Services>");
@@ -2266,6 +2281,11 @@ public class GAlignFrame extends JInternalFrame
 
   }
 
+  public void sortByTreeOption_actionPerformed(ActionEvent e)
+  {
+
+  }
+
   public void showAllSeqs_actionPerformed(ActionEvent e)
   {
 
index 9eb6cf1..2b71c03 100755 (executable)
@@ -241,6 +241,8 @@ public class GPreferences extends JPanel
 
   protected JCheckBox followHighlight = new JCheckBox();
 
+  protected JCheckBox sortByTree= new JCheckBox();
+
   /**
    * Creates a new GPreferences object.
    */
@@ -447,6 +449,7 @@ public class GPreferences extends JPanel
           maxColour_actionPerformed();
       }
     });
+    
     startupCheckbox.setText("Open file");
     startupCheckbox.setFont(verdana11);
     startupCheckbox.setHorizontalAlignment(SwingConstants.RIGHT);
@@ -626,8 +629,12 @@ public class GPreferences extends JPanel
     autoCalculateConsCheck.setText("AutoCalculate Consensus");
     autoCalculateConsCheck.setBounds(new Rectangle(21, 52, 209, 23));
     padGaps.setFont(JvSwingUtils.getLabelFont());
-    padGaps.setText("Pad gaps when editing");
+    padGaps.setText("Pad Gaps When Editing");
     padGaps.setBounds(new Rectangle(22, 94, 168, 23));
+    sortByTree.setFont(JvSwingUtils.getLabelFont());
+    sortByTree.setText("Sort Alignment With New Tree");
+    sortByTree.setToolTipText("When selected, any trees calculated or laoded onto the alignment will automatically sort the alignment.");
+    sortByTree.setBounds(new Rectangle(22, 136, 168, 23));
     modellerOutput.setFont(JvSwingUtils.getLabelFont());
     modellerOutput.setText("Use Modeller Output");
     modellerOutput.setBounds(new Rectangle(228, 226, 168, 23));
@@ -790,6 +797,8 @@ public class GPreferences extends JPanel
     tabbedPane.add(calcTab, "Editing");
     calcTab.add(autoCalculateConsCheck);
     calcTab.add(padGaps);
+    calcTab.add(sortByTree);
+    
     tabbedPane.add(dasPanel, "DAS Settings");
     tabbedPane.add(wsPanel, "Web Services");
 
index d3385a5..f8a7203 100755 (executable)
@@ -40,6 +40,8 @@ public class GTreePanel extends JInternalFrame
 
   public JMenuItem font = new JMenuItem();
 
+  public JMenuItem sortAssocViews = new JMenuItem();
+
   public JCheckBoxMenuItem bootstrapMenu = new JCheckBoxMenuItem();
 
   public JCheckBoxMenuItem distanceMenu = new JCheckBoxMenuItem();
@@ -111,6 +113,14 @@ public class GTreePanel extends JInternalFrame
       {
       }
     });
+    sortAssocViews.setText("Sort Alignment By Tree");
+    sortAssocViews.addActionListener(new java.awt.event.ActionListener()
+    {
+      public void actionPerformed(ActionEvent e)
+      {
+        sortByTree_actionPerformed(e);
+      }
+    });
     font.setText("Font...");
     font.addActionListener(new java.awt.event.ActionListener()
     {
@@ -200,6 +210,7 @@ public class GTreePanel extends JInternalFrame
     viewMenu.add(distanceMenu);
     viewMenu.add(bootstrapMenu);
     viewMenu.add(placeholdersMenu);
+    viewMenu.add(sortAssocViews);
     viewMenu.add(associateLeavesMenu);
     saveAsMenu.add(saveAsNewick);
     saveAsMenu.add(epsTree);
@@ -259,4 +270,9 @@ public class GTreePanel extends JInternalFrame
   public void viewMenu_menuSelected()
   {
   }
+  public void sortByTree_actionPerformed(ActionEvent e)
+  {
+
+  }
+
 }