From: gmungoc Date: Tue, 6 Nov 2018 16:04:38 +0000 (+0000) Subject: JAL-3148 show/hide features on structure independent of alignment X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=a5e22141bc3185284588761a69f023d527e7f18e;p=jalview.git JAL-3148 show/hide features on structure independent of alignment --- diff --git a/src/jalview/appletgui/AppletJmol.java b/src/jalview/appletgui/AppletJmol.java index 22c467d..681fc7d 100644 --- a/src/jalview/appletgui/AppletJmol.java +++ b/src/jalview/appletgui/AppletJmol.java @@ -528,7 +528,7 @@ public class AppletJmol extends EmbmenuFrame implements private void setColourScheme(ColourSchemeI cs) { - jmb.setJalviewColourScheme(cs, ap); + jmb.setJalviewColourScheme(cs, ap, ap.av.isShowSequenceFeatures()); } /** @@ -555,7 +555,7 @@ public class AppletJmol extends EmbmenuFrame implements else if (evt.getSource() == seqColour) { setEnabled(seqColour); - jmb.colourBySequence(ap); + jmb.colourBySequence(ap, ap.av.isShowSequenceFeatures()); } else if (!allChainsSelected) { @@ -588,7 +588,7 @@ public class AppletJmol extends EmbmenuFrame implements public void updateColours(Object source) { AlignmentPanel panel = (AlignmentPanel) source; - jmb.colourBySequence(panel); + jmb.colourBySequence(panel, ap.av.isShowSequenceFeatures()); } public void updateTitleAndMenus() @@ -599,7 +599,7 @@ public class AppletJmol extends EmbmenuFrame implements return; } setChainMenuItems(jmb.getChainNames()); - jmb.colourBySequence(ap); + jmb.colourBySequence(ap, ap.av.isShowSequenceFeatures()); setTitle(jmb.getViewerTitle()); } diff --git a/src/jalview/appletgui/AppletJmolBinding.java b/src/jalview/appletgui/AppletJmolBinding.java index 636d2e0..696a272 100644 --- a/src/jalview/appletgui/AppletJmolBinding.java +++ b/src/jalview/appletgui/AppletJmolBinding.java @@ -96,7 +96,7 @@ class AppletJmolBinding extends JalviewJmolBinding public void updateColours(Object source) { AlignmentPanel ap = (AlignmentPanel) source; - colourBySequence(ap); + colourBySequence(ap, ap.av.isShowSequenceFeatures()); } @Override diff --git a/src/jalview/ext/jmol/JalviewJmolBinding.java b/src/jalview/ext/jmol/JalviewJmolBinding.java index 7a8bc9c..eb13c30 100644 --- a/src/jalview/ext/jmol/JalviewJmolBinding.java +++ b/src/jalview/ext/jmol/JalviewJmolBinding.java @@ -175,7 +175,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel @Override public void colourByChain() { - super.colourByChain(); + super.colourByChain(); // TODO: colour by chain should colour each chain distinctly across all // visible models // TODO: http://issues.jalview.org/browse/JAL-628 @@ -518,10 +518,10 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel */ @Override protected StructureMappingcommandSet[] getColourBySequenceCommands( - String[] files, SequenceRendererI sr, AlignmentViewPanel viewPanel) + String[] files, SequenceRendererI sr, AlignmentViewPanel viewPanel, boolean showFeatures) { return JmolCommands.getColourBySequenceCommand(getSsm(), files, - getSequence(), sr, viewPanel); + getSequence(), sr, viewPanel, showFeatures); } /** diff --git a/src/jalview/ext/jmol/JmolCommands.java b/src/jalview/ext/jmol/JmolCommands.java index b2aeee4..f3de86b 100644 --- a/src/jalview/ext/jmol/JmolCommands.java +++ b/src/jalview/ext/jmol/JmolCommands.java @@ -49,6 +49,7 @@ public class JmolCommands /** * Jmol utility which constructs the commands to colour chains by the given * alignment + * @param showFeatures * * @returns Object[] { Object[] { , * @@ -56,10 +57,10 @@ public class JmolCommands public static StructureMappingcommandSet[] getColourBySequenceCommand( StructureSelectionManager ssm, String[] files, SequenceI[][] sequence, SequenceRendererI sr, - AlignmentViewPanel viewPanel) + AlignmentViewPanel viewPanel, boolean showFeatures) { FeatureRenderer fr = viewPanel.getFeatureRenderer(); - FeatureColourFinder finder = new FeatureColourFinder(fr); + FeatureColourFinder finder = showFeatures ? new FeatureColourFinder(fr) : null; AlignViewportI viewport = viewPanel.getAlignViewport(); HiddenColumns cs = viewport.getAlignment().getHiddenColumns(); AlignmentI al = viewport.getAlignment(); diff --git a/src/jalview/ext/rbvi/chimera/ChimeraCommands.java b/src/jalview/ext/rbvi/chimera/ChimeraCommands.java index f952bff..ba8f4b8 100644 --- a/src/jalview/ext/rbvi/chimera/ChimeraCommands.java +++ b/src/jalview/ext/rbvi/chimera/ChimeraCommands.java @@ -67,10 +67,10 @@ public class ChimeraCommands public static StructureMappingcommandSet[] getColourBySequenceCommand( StructureSelectionManager ssm, String[] files, SequenceI[][] sequence, SequenceRendererI sr, - AlignmentViewPanel viewPanel) + AlignmentViewPanel viewPanel, boolean showFeatures) { Map colourMap = buildColoursMap(ssm, files, - sequence, sr, viewPanel); + sequence, sr, viewPanel, showFeatures); List colourCommands = buildColourCommands(colourMap); @@ -189,10 +189,10 @@ public class ChimeraCommands protected static Map buildColoursMap( StructureSelectionManager ssm, String[] files, SequenceI[][] sequence, SequenceRendererI sr, - AlignmentViewPanel viewPanel) + AlignmentViewPanel viewPanel, boolean showFeatures) { FeatureRenderer fr = viewPanel.getFeatureRenderer(); - FeatureColourFinder finder = new FeatureColourFinder(fr); + FeatureColourFinder finder = showFeatures ? new FeatureColourFinder(fr) : null; AlignViewportI viewport = viewPanel.getAlignViewport(); HiddenColumns cs = viewport.getAlignment().getHiddenColumns(); AlignmentI al = viewport.getAlignment(); diff --git a/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java b/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java index 844f718..7e40426 100644 --- a/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java +++ b/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java @@ -696,10 +696,10 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel */ @Override protected StructureMappingcommandSet[] getColourBySequenceCommands( - String[] files, SequenceRendererI sr, AlignmentViewPanel viewPanel) + String[] files, SequenceRendererI sr, AlignmentViewPanel viewPanel, boolean showFeatures) { return ChimeraCommands.getColourBySequenceCommand(getSsm(), files, - getSequence(), sr, viewPanel); + getSequence(), sr, viewPanel, showFeatures); } /** diff --git a/src/jalview/gui/StructureViewerBase.java b/src/jalview/gui/StructureViewerBase.java index 05a163b..a9dc31e 100644 --- a/src/jalview/gui/StructureViewerBase.java +++ b/src/jalview/gui/StructureViewerBase.java @@ -53,9 +53,11 @@ import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; +import java.util.Enumeration; import java.util.List; import java.util.Vector; +import javax.swing.AbstractButton; import javax.swing.ButtonGroup; import javax.swing.JCheckBoxMenuItem; import javax.swing.JColorChooser; @@ -122,6 +124,8 @@ public abstract class StructureViewerBase extends GStructureViewer */ protected volatile boolean seqColoursApplied = false; + private JCheckBoxMenuItem showFeatures; + /** * Default constructor */ @@ -166,7 +170,8 @@ public abstract class StructureViewerBase extends GStructureViewer return (_alignwith != null) && _alignwith.contains(ap2); } - public boolean isUsedForColourBy(Object o) + @Override +public boolean isUsedForColourBy(Object o) { return (_colourwith != null) && _colourwith.contains(o); } @@ -564,10 +569,11 @@ public abstract class StructureViewerBase extends GStructureViewer @Override public void changeColour_actionPerformed(String colourSchemeName) { + showFeatures.setEnabled(true); AlignmentI al = getAlignmentPanel().av.getAlignment(); ColourSchemeI cs = ColourSchemes.getInstance() .getColourScheme(colourSchemeName, al, null); - getBinding().setJalviewColourScheme(cs, getAlignmentPanel()); + getBinding().setJalviewColourScheme(cs, getAlignmentPanel(), showFeatures.isSelected()); } /** @@ -578,7 +584,10 @@ public abstract class StructureViewerBase extends GStructureViewer colourMenu.removeAll(); AlignmentI al = getAlignmentPanel().av.getAlignment(); - colourMenu.addSeparator(); + showFeatures = new JCheckBoxMenuItem(MessageManager.getString( + "label.show_sequence_features")); + colourMenu.add(showFeatures); + colourMenu.addSeparator(); /* * add colour by sequence, by chain, by charge and cysteine @@ -588,9 +597,9 @@ public abstract class StructureViewerBase extends GStructureViewer colourMenu.add(chargeColour); chargeColour.setEnabled(!al.isNucleotide()); - /* - * add all colour schemes registered to Jalview - */ + /* + * add all colour schemes registered to Jalview + */ ButtonGroup itemGroup = ColourMenuHelper.addMenuItems(colourMenu, this, al); @@ -632,6 +641,27 @@ public abstract class StructureViewerBase extends GStructureViewer itemGroup.add(chainColour); itemGroup.add(chargeColour); itemGroup.add(viewerColour); + + /* + * action on show/hide features is to 'click' the currently + * selected colour in order to update the display + */ + showFeatures.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + Enumeration items = itemGroup.getElements(); + while (items.hasMoreElements()) + { + AbstractButton item = items.nextElement(); + if (item.isSelected()) + { + item.doClick(); + return; + } + } + }}); } /** @@ -822,53 +852,51 @@ public abstract class StructureViewerBase extends GStructureViewer @Override public void viewerColour_actionPerformed(ActionEvent actionEvent) { - if (viewerColour.isSelected()) - { - // disable automatic sequence colouring. - getBinding().setColourBy(ColourBy.Viewer); - } + showFeatures.setEnabled(false); + getBinding().setColourBy(ColourBy.Viewer); } @Override public void chainColour_actionPerformed(ActionEvent actionEvent) { - chainColour.setSelected(true); + showFeatures.setEnabled(false); getBinding().colourByChain(); } @Override public void chargeColour_actionPerformed(ActionEvent actionEvent) { - chargeColour.setSelected(true); + showFeatures.setEnabled(false); getBinding().colourByCharge(); } @Override public void seqColour_actionPerformed(ActionEvent actionEvent) { + showFeatures.setEnabled(false); AAStructureBindingModel binding = getBinding(); - boolean colourBySequence = seqColour.isSelected(); if (_colourwith == null) { _colourwith = new Vector<>(); } - if (colourBySequence) + + if (!binding.isLoadingFromArchive()) { - if (!binding.isLoadingFromArchive()) + if (_colourwith.isEmpty() && ap != null) { - if (_colourwith.size() == 0 && getAlignmentPanel() != null) - { - // Make the currently displayed alignment panel the associated view - _colourwith.add(getAlignmentPanel().alignFrame.alignPanel); - } - } - // Set the colour using the current view for the associated alignframe - for (AlignmentPanel alignPanel : _colourwith) - { - binding.colourBySequence(alignPanel); + // Make the currently displayed alignment panel the associated view + _colourwith.add(ap);//.alignFrame.alignPanel); ?!? } - seqColoursApplied = true; } + + showFeatures.setSelected(ap == null ? false : ap.av.isShowSequenceFeatures()); + + // Set the colour using the current view for the associated alignframe + for (AlignmentPanel alignPanel : _colourwith) + { + binding.colourBySequence(alignPanel, showFeatures.isSelected()); + } + seqColoursApplied = true; } @Override diff --git a/src/jalview/javascript/MouseOverStructureListener.java b/src/jalview/javascript/MouseOverStructureListener.java index fd2a4d5..239d0f3 100644 --- a/src/jalview/javascript/MouseOverStructureListener.java +++ b/src/jalview/javascript/MouseOverStructureListener.java @@ -224,7 +224,7 @@ public class MouseOverStructureListener extends JSFunctionExec ArrayList pdbfn = new ArrayList(); StructureMappingcommandSet[] colcommands = JmolCommands .getColourBySequenceCommand(ssm, modelSet, sequence, sr, - (AlignmentViewPanel) source); + (AlignmentViewPanel) source, true); if (colcommands == null) { return; diff --git a/src/jalview/structures/models/AAStructureBindingModel.java b/src/jalview/structures/models/AAStructureBindingModel.java index fc82827..0b19d51 100644 --- a/src/jalview/structures/models/AAStructureBindingModel.java +++ b/src/jalview/structures/models/AAStructureBindingModel.java @@ -46,6 +46,8 @@ import java.util.Arrays; import java.util.BitSet; import java.util.List; +import org.springframework.web.filter.ShallowEtagHeaderFilter; + /** * * A base class to hold common function for protein structure model binding. @@ -74,6 +76,12 @@ public abstract class AAStructureBindingModel */ private ColourSchemeI colourScheme; + /* + * flag for whether to include feature colouring, if using a Jalview colour + * scheme (independently of whether features are shown on alignment) + */ + private boolean showFeatures; + private StructureSelectionManager ssm; /* @@ -350,7 +358,7 @@ public abstract class AAStructureBindingModel public void setColourBy(ColourBy option) { - colourBy = option; + colourBy = option; } public boolean isColourBySequence() @@ -360,7 +368,7 @@ public abstract class AAStructureBindingModel protected boolean isJalviewColourScheme() { - return colourBy == ColourBy.Jalview; + return colourBy == ColourBy.Jalview; } protected void addSequenceAndChain(int pe, SequenceI[] seq, @@ -773,19 +781,22 @@ public abstract class AAStructureBindingModel * * @param cs * @param ap + * @param showFeats */ - public void setJalviewColourScheme(ColourSchemeI cs, AlignmentViewPanel ap) + public void setJalviewColourScheme(ColourSchemeI cs, AlignmentViewPanel ap, + boolean showFeats) { colourBy = ColourBy.Jalview; colourScheme = cs; + showFeatures = showFeats; - if (cs == null || cs.isSimple()) + if (!showFeats && (cs == null || cs.isSimple())) { setSimpleColourScheme(cs); } else { - colourBySequence(ap, new SequenceRenderer(ap.getAlignViewport(), cs)); + colourBySequence(ap, new SequenceRenderer(ap.getAlignViewport(), cs), showFeatures); } } @@ -819,7 +830,7 @@ public abstract class AAStructureBindingModel public abstract void setBackgroundColour(Color col); protected abstract StructureMappingcommandSet[] getColourBySequenceCommands( - String[] files, SequenceRendererI sr, AlignmentViewPanel avp); + String[] files, SequenceRendererI sr, AlignmentViewPanel avp, boolean showFeatures); protected abstract void colourBySequence( StructureMappingcommandSet[] colourBySequenceCommands); @@ -831,20 +842,21 @@ public abstract class AAStructureBindingModel public void colourByCharge() { - colourBy = ColourBy.ChargeAndCysteine; + colourBy = ColourBy.ChargeAndCysteine; } - public void colourBySequence(AlignmentViewPanel alignmentv) + public void colourBySequence(AlignmentViewPanel alignmentv, boolean showFeatures) { - colourBySequence(alignmentv, alignmentv.getSequenceRenderer()); + colourBySequence(alignmentv, alignmentv.getSequenceRenderer(), showFeatures); } /** * Colours any structures associated with sequences in the given alignment view * using the getFeatureRenderer() and getSequenceRenderer() renderers */ - public void colourBySequence(AlignmentViewPanel alignmentv, SequenceRendererI sr) + public void colourBySequence(AlignmentViewPanel alignmentv, SequenceRendererI sr, boolean showFeats) { + showFeatures = showFeats; if (!isLoadingFinished()) { return; @@ -856,7 +868,7 @@ public abstract class AAStructureBindingModel String[] files = getStructureFiles(); StructureMappingcommandSet[] colourBySequenceCommands = getColourBySequenceCommands( - files, sr, alignmentv); + files, sr, alignmentv, showFeatures); colourBySequence(colourBySequenceCommands); } @@ -888,7 +900,7 @@ public void updateColours(Object source) { { return; } - if (colourScheme == null || colourScheme.isSimple()) + if (!showFeatures && (colourScheme == null || colourScheme.isSimple())) { return; } @@ -897,11 +909,13 @@ public void updateColours(Object source) { { if (isColourBySequence()) { - colourBySequence(ap, new SequenceRenderer(ap.getAlignViewport())); + colourBySequence(ap, new SequenceRenderer(ap.getAlignViewport()), + showFeatures); } else { - colourBySequence(ap, new SequenceRenderer(ap.getAlignViewport(), colourScheme)); + colourBySequence(ap, new SequenceRenderer(ap.getAlignViewport(), + colourScheme), showFeatures); } } } diff --git a/test/jalview/ext/jmol/JmolCommandsTest.java b/test/jalview/ext/jmol/JmolCommandsTest.java index e42b54f..51bb885 100644 --- a/test/jalview/ext/jmol/JmolCommandsTest.java +++ b/test/jalview/ext/jmol/JmolCommandsTest.java @@ -66,7 +66,7 @@ public class JmolCommandsTest // need some mappings! StructureMappingcommandSet[] commands = JmolCommands - .getColourBySequenceCommand(ssm, files, seqs, sr, af.alignPanel); + .getColourBySequenceCommand(ssm, files, seqs, sr, af.alignPanel, false); } @Test(groups = { "Functional" }) @@ -108,7 +108,7 @@ public class JmolCommandsTest ssm.addStructureMapping(sm2); StructureMappingcommandSet[] commands = JmolCommands - .getColourBySequenceCommand(ssm, files, seqs, sr, af.alignPanel); + .getColourBySequenceCommand(ssm, files, seqs, sr, af.alignPanel, false); assertEquals(commands.length, 2); assertEquals(commands[0].commands.length, 1); diff --git a/test/jalview/ext/rbvi/chimera/ChimeraCommandsTest.java b/test/jalview/ext/rbvi/chimera/ChimeraCommandsTest.java index 2c973ca..0118f80 100644 --- a/test/jalview/ext/rbvi/chimera/ChimeraCommandsTest.java +++ b/test/jalview/ext/rbvi/chimera/ChimeraCommandsTest.java @@ -202,7 +202,7 @@ public class ChimeraCommandsTest ssm.addStructureMapping(sm2); StructureMappingcommandSet[] commands = ChimeraCommands - .getColourBySequenceCommand(ssm, files, seqs, sr, af.alignPanel); + .getColourBySequenceCommand(ssm, files, seqs, sr, af.alignPanel, false); assertEquals(1, commands.length); assertEquals(1, commands[0].commands.length); String theCommand = commands[0].commands[0]; diff --git a/test/jalview/structure/StructureSelectionManagerTest.java b/test/jalview/structure/StructureSelectionManagerTest.java index 286be1b..2e9e873 100644 --- a/test/jalview/structure/StructureSelectionManagerTest.java +++ b/test/jalview/structure/StructureSelectionManagerTest.java @@ -320,7 +320,7 @@ public class StructureSelectionManagerTest extends Jalview2xmlBase new SequenceI[][] { new SequenceI[] { pdb_viewseq } }, new SequenceRenderer(alf.alignPanel.getAlignViewport()), - alf.alignPanel); + alf.alignPanel, false); // Expected - all residues are white for (StructureMappingcommandSet smm : smcr) { diff --git a/test/jalview/structures/models/AAStructureBindingModelTest.java b/test/jalview/structures/models/AAStructureBindingModelTest.java index 1b5045a..b296586 100644 --- a/test/jalview/structures/models/AAStructureBindingModelTest.java +++ b/test/jalview/structures/models/AAStructureBindingModelTest.java @@ -183,7 +183,8 @@ public class AAStructureBindingModelTest @Override protected StructureMappingcommandSet[] getColourBySequenceCommands( - String[] files, SequenceRendererI sr, AlignmentViewPanel avp) + String[] files, SequenceRendererI sr, AlignmentViewPanel avp, + boolean showFeatures) { return null; } @@ -302,7 +303,8 @@ public class AAStructureBindingModelTest @Override protected StructureMappingcommandSet[] getColourBySequenceCommands( - String[] files, SequenceRendererI sr, AlignmentViewPanel avp) + String[] files, SequenceRendererI sr, AlignmentViewPanel avp, + boolean showFeatures) { return null; }