From: jprocter Date: Fri, 16 Sep 2011 10:29:22 +0000 (+0100) Subject: JAL-468 JAL-936 sort alignment by tree and autosort for new tree X-Git-Tag: Release_2_7~38 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=6403068c0c328cfb63af451f7fa1bd568fa0fdd3;p=jalview.git JAL-468 JAL-936 sort alignment by tree and autosort for new tree --- diff --git a/help/html/calculations/treeviewer.html b/help/html/calculations/treeviewer.html index 32db2ce..514b8c8 100755 --- a/help/html/calculations/treeviewer.html +++ b/help/html/calculations/treeviewer.html @@ -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.

-

The view menu contains options controlling the way a tree is -rendered and labelled: +

The view menu mostly contains options controlling the way a tree is +rendered and labeled:

+
  • Sort Alignment By Tree +

    + Sorts any associated alignment views using the current tree. (Only + available in the Jalview Desktop) +

    +
  • +
  • Associate Leaves with ... +

    + Only visible when there are multiple + views of the same alignment to show and edit which alignment views + are associated with the leaves of the displayed tree. +

    +

    diff --git a/help/html/menus/alwcalculate.html b/help/html/menus/alwcalculate.html index 85ec95c..01b84cd 100755 --- a/help/html/menus/alwcalculate.html +++ b/help/html/menus/alwcalculate.html @@ -16,66 +16,78 @@ * * You should have received a copy of the GNU General Public License along with Jalview. If not, see . --> -Alignment Window Menus + +Alignment Window Menus + -

    Alignment Window Calculate Menu

    -
      -
    • Sort -
        -
      • by ID
        - This will sort the sequences according to sequence name. If the sort is - repeated, the order of the sorted sequences will be inverted.
      • -
      • by Length
        - 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.
      • -
      • by Group
        -
        This will sort the sequences according to sequence name. - If the sort is repeated, the order of the sorted sequences will be inverted. -
      • -
      • by Pairwise Identity
        -
        This will sort the selected sequences by their percentage - identity to the consensus sequence. The most similar sequence is put at - the top.
      • -
      • The Sort menu 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.
        -
      • -
      -
    • -
    • Calculate Tree
      - Functions for calculating trees on the alignment or the currently selected - region. See calculating trees. -
        -
      • Average Distance Using % Identity
      • -
      • Neighbour Joining Using % Identity
      • -
      • Average Distance Using Blosum62
      • -
      • Neighbour Joining Using Blosum62
        -
      • -
      -
    • -
    • Pairwise Alignments
      - Applies Smith and Waterman algorithm to selected sequences. See pairwise - alignments.
      -
    • -
    • Principal Component Analysis
      - Shows a spatial clustering of the sequences based on the BLOSUM62 scores - in the alignment. See Principal Component - Analysis.
      -
    • -
    • Extract Scores ... (optional)
      - This option is only visible if Jalview detects one or more white-space separated values in the description line of the alignment sequences.
      - When selected, these numbers are parsed into sequence associated annotation which can - then be used to sort the alignment via the Sort by→Score menu.

      -
    • - -
    • Autocalculate Consensus
      - For large alignments it can be useful to deselect "Autocalculate - Consensus" when editing. This prevents the sometimes lengthy calculations - performed after each sequence edit.
      -
    • -
    - +

    + Alignment Window Calculate Menu +

    +
      +
    • Sort +
        +
      • by ID
        This will sort the + sequences according to sequence name. If the sort is repeated, the + order of the sorted sequences will be inverted.
        +
      • +
      • by Length
        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.
        +
      • +
      • by Group
        This + will sort the sequences according to sequence name. If the sort is + repeated, the order of the sorted sequences will be inverted. +
      • +
      • by Pairwise Identity
        This + will sort the selected sequences by their percentage identity to + the consensus sequence. The most similar sequence is put at the + top. +
      • +
      • The Sort + menu 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.
      • +
    • +
    • Calculate Tree
      Functions + for calculating trees on the alignment or the currently selected + region. See calculating + trees. +
        +
      • Average Distance Using % Identity +
      • +
      • Neighbour Joining Using % Identity +
      • +
      • Average Distance Using Blosum62 +
      • +
      • Neighbour Joining Using Blosum62
        +
        +
      • +
    • +
    • Pairwise Alignments
      Applies + Smith and Waterman algorithm to selected sequences. See pairwise alignments.
      +
    • +
    • Principal Component Analysis
      Shows + a spatial clustering of the sequences based on the BLOSUM62 scores + in the alignment. See Principal + Component Analysis.
    • +
    • Extract Scores ... (optional)
      This + option is only visible if Jalview detects one or more white-space + separated values in the description line of the alignment sequences.
      + When selected, these numbers are parsed into sequence associated + annotation which can then be used to sort the alignment via the Sort + by→Score menu.

    • + +
    • Autocalculate Consensus
      For + large alignments it can be useful to deselect "Autocalculate + Consensus" when editing. This prevents the sometimes lengthy + calculations performed after each sequence edit.
    • +
    • Sort Alignment With New Tree
      If + this option is selected, the alignment will be automatically sorted + whenever a new tree is calculated or loaded.
      +
    • +
    + diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index 7030637..0263d72 100644 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -601,6 +601,10 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, { viewport.autocalculateConsensus = autoCalculate.getState(); } + else if (evt.getSource() == sortByTree) + { + viewport.sortByTree = sortByTree.getState(); + } else if (evt.getSource() == this.centreColumnLabelFlag) { centreColumnLabelFlag_stateChanged(); @@ -2551,7 +2555,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, sortByTree(treePanel, title); // treePanel.getTitle()); } }); - + treePanel.addWindowListener(new WindowAdapter() { public void windowOpened(WindowEvent e) @@ -2585,6 +2589,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, alignPanel.paintAlignment(true); return true; } + protected void documentation_actionPerformed() { alignPanel.av.applet.openJalviewHelpUrl(); @@ -2818,6 +2823,9 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, CheckboxMenuItem autoCalculate = new CheckboxMenuItem( "Autocalculate Consensus", true); + CheckboxMenuItem sortByTree = new CheckboxMenuItem( + "Sort Alignment With New Tree", true); + Menu sortByTreeMenu = new Menu(); Menu sort = new Menu(); @@ -3013,6 +3021,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, sort.setLabel("Sort"); calculate.setLabel("Calculate Tree"); autoCalculate.addItemListener(this); + sortByTree.addItemListener(this); inputText.setLabel("Input from textbox"); inputText.addActionListener(this); centreColumnLabelFlag.setLabel("Centre column labels"); @@ -3157,6 +3166,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, calculateMenu.add(pairwiseAlignmentMenuItem); calculateMenu.add(PCAMenuItem); calculateMenu.add(autoCalculate); + calculateMenu.add(sortByTree); this.add(statusBar, BorderLayout.SOUTH); pasteMenu.add(pasteNew); pasteMenu.add(pasteThis); diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index b9ba4e0..9df4931 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -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)); + } }); diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index 9267800..80a42a9 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -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())); diff --git a/src/jalview/gui/TreePanel.java b/src/jalview/gui/TreePanel.java index ea0b791..3b7cb14 100755 --- a/src/jalview/gui/TreePanel.java +++ b/src/jalview/gui/TreePanel.java @@ -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 commands = new ArrayList(); + 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! * diff --git a/src/jalview/jbgui/GAlignFrame.java b/src/jalview/jbgui/GAlignFrame.java index 9260b23..22d27e9 100755 --- a/src/jalview/jbgui/GAlignFrame.java +++ b/src/jalview/jbgui/GAlignFrame.java @@ -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("Enable this to automatically sort
    the alignment when you open
    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(""); @@ -2266,6 +2281,11 @@ public class GAlignFrame extends JInternalFrame } + public void sortByTreeOption_actionPerformed(ActionEvent e) + { + + } + public void showAllSeqs_actionPerformed(ActionEvent e) { diff --git a/src/jalview/jbgui/GPreferences.java b/src/jalview/jbgui/GPreferences.java index 9eb6cf1..2b71c03 100755 --- a/src/jalview/jbgui/GPreferences.java +++ b/src/jalview/jbgui/GPreferences.java @@ -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"); diff --git a/src/jalview/jbgui/GTreePanel.java b/src/jalview/jbgui/GTreePanel.java index d3385a5..f8a7203 100755 --- a/src/jalview/jbgui/GTreePanel.java +++ b/src/jalview/jbgui/GTreePanel.java @@ -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) + { + + } + }