JAL-2010 simple prototype of 'Highlight Selection' onto Chimera view
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 12 Feb 2016 15:03:51 +0000 (15:03 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 12 Feb 2016 15:03:51 +0000 (15:03 +0000)
resources/lang/Messages.properties
src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java
src/jalview/gui/ChimeraViewFrame.java
src/jalview/jbgui/GStructureViewer.java
src/jalview/structure/StructureSelectionManager.java

index c4d1098..5ce5f46 100644 (file)
@@ -133,6 +133,7 @@ action.using_jmol = Using Jmol
 action.link = Link
 action.group_link = Group Link
 action.show_chain = Show Chain
+label.highlight_selection = Highlight Selection
 action.show_group = Show Group
 action.fetch_db_references = Fetch DB References
 action.view_flanking_regions = Show flanking regions
@@ -1287,4 +1288,4 @@ label.mapping_method = Sequence \u27f7 Structure mapping method
 label.mapping_method = Sequence \u27f7 Structure mapping method
 status.waiting_for_user_to_select_output_file = Waiting for user to select {0} file.
 status.cancelled_image_export_operation = Cancelled {0} export operation.
-info.error_creating_file = Error creating {0} file.
\ No newline at end of file
+info.error_creating_file = Error creating {0} file.
index eee8bca..af87e44 100644 (file)
@@ -108,7 +108,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
    */
   String[] modelFileNames = null;
 
-  String lastMousedOverAtomSpec;
+  String lastHighlightCommand;
 
   private List<String> lastReply;
 
@@ -818,8 +818,8 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
    * Construct and send a command to highlight zero, one or more atoms.
    * 
    * <pre>
-   * Done by generating a command like (to 'highlight' position 44)
-   *   show #0:44.C
+   * Done by generating a command like (to 'highlight' positions 44 and 46)
+   *   show #0:44,46.C
    * </pre>
    */
   @Override
@@ -829,8 +829,9 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
     {
       return;
     }
-    StringBuilder atomSpecs = new StringBuilder();
+    StringBuilder cmd = new StringBuilder(128);
     boolean first = true;
+    boolean found = false;
 
     for (AtomSpec atom : atoms)
     {
@@ -840,35 +841,42 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
       List<ChimeraModel> cms = chimeraMaps.get(pdbfile);
       if (cms != null && !cms.isEmpty())
       {
-        atomSpecs.append(first ? "" : ",");
+        if (first)
+        {
+          cmd.append("show #").append(cms.get(0).getModelNumber())
+                  .append(":");
+        }
+        else
+        {
+          cmd.append(",");
+        }
         first = false;
-        atomSpecs.append(cms.get(0).getModelNumber());
-        atomSpecs.append(":" + pdbResNum);
+        cmd.append(cms.get(0).getModelNumber()).append(":");
+        cmd.append(pdbResNum);
         if (!chain.equals(" "))
         {
-          atomSpecs.append("." + chain);
+          cmd.append(".").append(chain);
         }
+        found = true;
       }
     }
-    String atomSpec = atomSpecs.toString();
+    String command = cmd.toString();
 
     /*
      * Avoid repeated commands for the same residue
      */
-    if (atomSpec.equals(lastMousedOverAtomSpec))
+    if (command.equals(lastHighlightCommand))
     {
       return;
     }
 
-    StringBuilder command = new StringBuilder(32);
     viewerCommandHistory(false);
-    if (atomSpec.length() > 0)
+    if (found)
     {
-      command.append("show #").append(atomSpec);
       viewer.sendChimeraCommand(command.toString(), false);
     }
     viewerCommandHistory(true);
-    this.lastMousedOverAtomSpec = atomSpec;
+    this.lastHighlightCommand = command;
   }
 
   /**
@@ -1115,4 +1123,30 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
   {
     sendChimeraCommand("focus", false);
   }
+
+  /**
+   * Send a 'show' command for all atoms in the currently selected columns
+   * 
+   * @param vp
+   */
+  public void highlightSelection(AlignmentViewPanel vp)
+  {
+    List<Integer> cols = vp.getAlignViewport().getColumnSelection()
+            .getSelected();
+    AlignmentI alignment = vp.getAlignment();
+    StructureSelectionManager sm = getSsm();
+    for (SequenceI seq : alignment.getSequences())
+    {
+      /*
+       * convert selected columns into sequence positions
+       */
+      int[] positions = new int[cols.size()];
+      int i = 0;
+      for (Integer col : cols)
+      {
+        positions[i++] = seq.findPosition(col);
+      }
+      sm.highlightStructure(this, seq, positions);
+    }
+  }
 }
index 09451dc..f1c5097 100644 (file)
@@ -143,6 +143,7 @@ public class ChimeraViewFrame extends StructureViewerBase
             });
     viewMenu.add(seqColourBy);
     viewMenu.add(fitToWindow);
+    viewMenu.add(highlightSelection);
 
     final ItemListener handler;
     JMenu alpanels = new ViewSelectionMenu(
@@ -270,6 +271,7 @@ public class ChimeraViewFrame extends StructureViewerBase
 
     this.addInternalFrameListener(new InternalFrameAdapter()
     {
+      @Override
       public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
       {
         closeViewer(false);
@@ -460,6 +462,7 @@ public class ChimeraViewFrame extends StructureViewerBase
             MessageManager.getString("label.all"));
     menuItem.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent evt)
       {
         allChainsSelected = true;
@@ -482,6 +485,7 @@ public class ChimeraViewFrame extends StructureViewerBase
       menuItem = new JCheckBoxMenuItem(chainName, true);
       menuItem.addItemListener(new ItemListener()
       {
+        @Override
         public void itemStateChanged(ItemEvent evt)
         {
           if (!allChainsSelected)
@@ -523,6 +527,7 @@ public class ChimeraViewFrame extends StructureViewerBase
    * @param closeChimera
    *          if true, close any linked Chimera process; if false, prompt first
    */
+  @Override
   public void closeViewer(boolean closeChimera)
   {
     if (jmb != null && jmb.isChimeraRunning())
@@ -553,6 +558,7 @@ public class ChimeraViewFrame extends StructureViewerBase
    * Open any newly added PDB structures in Chimera, having first fetched data
    * from PDB (if not already saved).
    */
+  @Override
   public void run()
   {
     _started = true;
@@ -699,6 +705,7 @@ public class ChimeraViewFrame extends StructureViewerBase
       {
         new Thread(new Runnable()
         {
+          @Override
           public void run()
           {
             alignStructs_withAllAlignPanels();
@@ -1091,6 +1098,7 @@ public class ChimeraViewFrame extends StructureViewerBase
     }
   }
 
+  @Override
   public void setJalviewColourScheme(ColourSchemeI ucs)
   {
     jmb.setJalviewColourScheme(ucs);
@@ -1198,6 +1206,12 @@ public class ChimeraViewFrame extends StructureViewerBase
   }
 
   @Override
+  protected void highlightSelection_actionPerformed()
+  {
+    jmb.highlightSelection(getAlignmentPanel());
+  }
+
+  @Override
   public ViewerType getViewerType()
   {
     return ViewerType.CHIMERA;
index 943aa8c..179607f 100644 (file)
@@ -53,6 +53,8 @@ public abstract class GStructureViewer extends JInternalFrame implements
 
   protected JMenuItem fitToWindow = new JMenuItem();
 
+  protected JMenuItem highlightSelection = new JMenuItem();
+
   protected JRadioButtonMenuItem seqColour = new JRadioButtonMenuItem();
 
   protected JRadioButtonMenuItem chainColour = new JRadioButtonMenuItem();
@@ -114,6 +116,7 @@ public abstract class GStructureViewer extends JInternalFrame implements
     pdbFile.setText(MessageManager.getString("label.pdb_file"));
     pdbFile.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent actionEvent)
       {
         pdbFile_actionPerformed(actionEvent);
@@ -124,6 +127,7 @@ public abstract class GStructureViewer extends JInternalFrame implements
     png.setText("PNG");
     png.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent actionEvent)
       {
         png_actionPerformed(actionEvent);
@@ -134,6 +138,7 @@ public abstract class GStructureViewer extends JInternalFrame implements
     eps.setText("EPS");
     eps.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent actionEvent)
       {
         eps_actionPerformed(actionEvent);
@@ -144,6 +149,7 @@ public abstract class GStructureViewer extends JInternalFrame implements
     viewMapping.setText(MessageManager.getString("label.view_mapping"));
     viewMapping.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent actionEvent)
       {
         viewMapping_actionPerformed(actionEvent);
@@ -156,12 +162,24 @@ public abstract class GStructureViewer extends JInternalFrame implements
     fitToWindow.setText(MessageManager.getString("label.fit_to_window"));
     fitToWindow.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent actionEvent)
       {
         fitToWindow_actionPerformed();
       }
     });
 
+    highlightSelection.setText(MessageManager
+            .getString("label.highlight_selection"));
+    highlightSelection.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent actionEvent)
+      {
+        highlightSelection_actionPerformed();
+      }
+    });
+
     JMenu colourMenu = new JMenu();
     colourMenu.setText(MessageManager.getString("label.colours"));
 
@@ -170,6 +188,7 @@ public abstract class GStructureViewer extends JInternalFrame implements
             .setText(MessageManager.getString("action.background_colour"));
     backGround.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent actionEvent)
       {
         backGround_actionPerformed(actionEvent);
@@ -179,6 +198,7 @@ public abstract class GStructureViewer extends JInternalFrame implements
     seqColour.setText(MessageManager.getString("action.by_sequence"));
     seqColour.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent actionEvent)
       {
         seqColour_actionPerformed(actionEvent);
@@ -187,6 +207,7 @@ public abstract class GStructureViewer extends JInternalFrame implements
     chainColour.setText(MessageManager.getString("action.by_chain"));
     chainColour.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent actionEvent)
       {
         chainColour_actionPerformed(actionEvent);
@@ -195,6 +216,7 @@ public abstract class GStructureViewer extends JInternalFrame implements
     chargeColour.setText(MessageManager.getString("label.charge_cysteine"));
     chargeColour.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent actionEvent)
       {
         chargeColour_actionPerformed(actionEvent);
@@ -203,6 +225,7 @@ public abstract class GStructureViewer extends JInternalFrame implements
     zappoColour.setText(MessageManager.getString("label.zappo"));
     zappoColour.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent actionEvent)
       {
         zappoColour_actionPerformed(actionEvent);
@@ -211,6 +234,7 @@ public abstract class GStructureViewer extends JInternalFrame implements
     taylorColour.setText(MessageManager.getString("label.taylor"));
     taylorColour.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent actionEvent)
       {
         taylorColour_actionPerformed(actionEvent);
@@ -219,6 +243,7 @@ public abstract class GStructureViewer extends JInternalFrame implements
     hydroColour.setText(MessageManager.getString("label.hydrophobicity"));
     hydroColour.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent actionEvent)
       {
         hydroColour_actionPerformed(actionEvent);
@@ -228,6 +253,7 @@ public abstract class GStructureViewer extends JInternalFrame implements
             .getString("label.strand_propensity"));
     strandColour.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent actionEvent)
       {
         strandColour_actionPerformed(actionEvent);
@@ -236,6 +262,7 @@ public abstract class GStructureViewer extends JInternalFrame implements
     helixColour.setText(MessageManager.getString("label.helix_propensity"));
     helixColour.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent actionEvent)
       {
         helixColour_actionPerformed(actionEvent);
@@ -244,6 +271,7 @@ public abstract class GStructureViewer extends JInternalFrame implements
     turnColour.setText(MessageManager.getString("label.turn_propensity"));
     turnColour.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent actionEvent)
       {
         turnColour_actionPerformed(actionEvent);
@@ -252,6 +280,7 @@ public abstract class GStructureViewer extends JInternalFrame implements
     buriedColour.setText(MessageManager.getString("label.buried_index"));
     buriedColour.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent actionEvent)
       {
         buriedColour_actionPerformed(actionEvent);
@@ -261,6 +290,7 @@ public abstract class GStructureViewer extends JInternalFrame implements
             .getString("label.purine_pyrimidine"));
     purinePyrimidineColour.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent actionEvent)
       {
         purinePyrimidineColour_actionPerformed(actionEvent);
@@ -270,6 +300,7 @@ public abstract class GStructureViewer extends JInternalFrame implements
     userColour.setText(MessageManager.getString("action.user_defined"));
     userColour.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent actionEvent)
       {
         userColour_actionPerformed(actionEvent);
@@ -282,6 +313,7 @@ public abstract class GStructureViewer extends JInternalFrame implements
             .getString("label.let_jmol_manage_structure_colours"));
     viewerColour.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent actionEvent)
       {
         viewerColour_actionPerformed(actionEvent);
@@ -293,6 +325,7 @@ public abstract class GStructureViewer extends JInternalFrame implements
     helpItem.setText(MessageManager.getString("label.jmol_help"));
     helpItem.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent actionEvent)
       {
         showHelp_actionPerformed(actionEvent);
@@ -302,6 +335,7 @@ public abstract class GStructureViewer extends JInternalFrame implements
             .setText(MessageManager.getString("label.align_structures"));
     alignStructs.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent actionEvent)
       {
         alignStructs_actionPerformed(actionEvent);
@@ -364,6 +398,10 @@ public abstract class GStructureViewer extends JInternalFrame implements
   {
   }
 
+  protected void highlightSelection_actionPerformed()
+  {
+  }
+
   protected void viewerColour_actionPerformed(ActionEvent actionEvent)
   {
   }
index 4da715e..b6bb70d 100644 (file)
@@ -768,19 +768,19 @@ public class StructureSelectionManager
    *          the sequence that the mouse over occurred on
    * @param indexpos
    *          the absolute position being mouseovered in seq (0 to seq.length())
-   * @param index
+   * @param seqPos
    *          the sequence position (if -1, seq.findPosition is called to
    *          resolve the residue number)
    */
-  public void mouseOverSequence(SequenceI seq, int indexpos, int index,
+  public void mouseOverSequence(SequenceI seq, int indexpos, int seqPos,
           VamsasSource source)
   {
     boolean hasSequenceListeners = handlingVamsasMo
             || !seqmappings.isEmpty();
     SearchResults results = null;
-    if (index == -1)
+    if (seqPos == -1)
     {
-      index = seq.findPosition(indexpos);
+      seqPos = seq.findPosition(indexpos);
     }
     for (int i = 0; i < listeners.size(); i++)
     {
@@ -793,7 +793,7 @@ public class StructureSelectionManager
       }
       if (listener instanceof StructureListener)
       {
-        highlightStructure((StructureListener) listener, seq, index);
+        highlightStructure((StructureListener) listener, seq, seqPos);
       }
       else
       {
@@ -807,12 +807,12 @@ public class StructureSelectionManager
             {
               if (results == null)
               {
-                results = MappingUtils.buildSearchResults(seq, index,
+                results = MappingUtils.buildSearchResults(seq, seqPos,
                         seqmappings);
               }
               if (handlingVamsasMo)
               {
-                results.addResult(seq, index, index);
+                results.addResult(seq, seqPos, seqPos);
 
               }
               if (!results.isEmpty())
@@ -830,7 +830,7 @@ public class StructureSelectionManager
         else if (listener instanceof SecondaryStructureListener)
         {
           ((SecondaryStructureListener) listener).mouseOverSequence(seq,
-                  indexpos, index);
+                  indexpos, seqPos);
         }
       }
     }
@@ -838,14 +838,14 @@ public class StructureSelectionManager
 
   /**
    * Send suitable messages to a StructureListener to highlight atoms
-   * corresponding to the given sequence position.
+   * corresponding to the given sequence position(s)
    * 
    * @param sl
    * @param seq
-   * @param index
+   * @param positions
    */
-  protected void highlightStructure(StructureListener sl, SequenceI seq,
-          int index)
+  public void highlightStructure(StructureListener sl, SequenceI seq,
+          int... positions)
   {
     if (!sl.isListeningFor(seq))
     {
@@ -857,12 +857,15 @@ public class StructureSelectionManager
     {
       if (sm.sequence == seq || sm.sequence == seq.getDatasetSequence())
       {
-        atomNo = sm.getAtomNum(index);
-
-        if (atomNo > 0)
+        for (int index : positions)
         {
-          atoms.add(new AtomSpec(sm.pdbfile, sm.pdbchain, sm
-                  .getPDBResNum(index), atomNo));
+          atomNo = sm.getAtomNum(index);
+
+          if (atomNo > 0)
+          {
+            atoms.add(new AtomSpec(sm.pdbfile, sm.pdbchain, sm
+                    .getPDBResNum(index), atomNo));
+          }
         }
       }
     }