From: gmungoc Date: Mon, 5 Aug 2019 14:24:11 +0000 (+0100) Subject: JAL-3390 new View menu option to hide hidden regions in structure X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=e34c8452beda2cf80c2a3224f236d3096db69ae9;p=jalview.git JAL-3390 new View menu option to hide hidden regions in structure --- diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index d2d8e88..c54e414 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -1400,3 +1400,5 @@ label.pca = PCA label.create_image_of = Create {0} image of {1} label.click_to_edit = Click to edit, right-click for menu label.by_annotation_tooltip = Annotation Colour is configured from the main Colour menu +label.show_alignment_only = Show alignment only +label.hide_hidden_regions = Hide hidden columns / sequences \ No newline at end of file diff --git a/resources/lang/Messages_es.properties b/resources/lang/Messages_es.properties index e9e18ce..a99d3bb 100644 --- a/resources/lang/Messages_es.properties +++ b/resources/lang/Messages_es.properties @@ -311,7 +311,8 @@ label.copied_sequences_to_clipboard = Copiadas {0} secuencias en el portapapeles label.check_file_matches_sequence_ids_alignment = Comprobar que el fichero coincide con el ID de la secuencia en el alineamiento. label.problem_reading_tcoffee_score_file = Problema de lectura del fichero de puntuaciones T-COFFEE label.source_to_target = {0} a {1} -label.per_sequence_only= Sólo por secuencia +label.per_sequence_ += Sólo por secuencia label.to_file = a fichero label.to_textbox = a cuadro de texto label.jalview = Jalview @@ -1401,3 +1402,5 @@ label.pca = ACP label.create_image_of = Crear imagen {0} de {1} label.click_to_edit = Haga clic para editar, clic en el botón derecho para ver el menú label.by_annotation_tooltip = El color de anotación se configura desde el menú principal de colores +label.show_alignment_only = Mostrar solo alineamiento +label.hide_hidden_regions = Ocultar columnas / secuencias ocultas \ No newline at end of file diff --git a/src/jalview/ext/jmol/JalviewJmolBinding.java b/src/jalview/ext/jmol/JalviewJmolBinding.java index e5a1733..d317722 100644 --- a/src/jalview/ext/jmol/JalviewJmolBinding.java +++ b/src/jalview/ext/jmol/JalviewJmolBinding.java @@ -23,7 +23,6 @@ package jalview.ext.jmol; import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; import jalview.api.FeatureRenderer; -import jalview.api.SequenceRenderer; import jalview.datamodel.AlignmentI; import jalview.datamodel.HiddenColumns; import jalview.datamodel.PDBEntry; @@ -510,16 +509,15 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel /** * @param files - * @param sr * @param viewPanel * @return */ @Override protected StructureMappingcommandSet[] getColourBySequenceCommands( - String[] files, SequenceRenderer sr, AlignmentViewPanel viewPanel) + String[] files, AlignmentViewPanel viewPanel) { return JmolCommands.getColourBySequenceCommand(getSsm(), files, - getSequence(), sr, viewPanel); + this, viewPanel); } /** diff --git a/src/jalview/ext/jmol/JmolCommands.java b/src/jalview/ext/jmol/JmolCommands.java index 8fb0de6..c981165 100644 --- a/src/jalview/ext/jmol/JmolCommands.java +++ b/src/jalview/ext/jmol/JmolCommands.java @@ -31,6 +31,7 @@ import jalview.renderer.seqfeatures.FeatureColourFinder; import jalview.structure.StructureMapping; import jalview.structure.StructureMappingcommandSet; import jalview.structure.StructureSelectionManager; +import jalview.structures.models.AAStructureBindingModel; import java.awt.Color; import java.util.ArrayList; @@ -55,6 +56,15 @@ public class JmolCommands */ public static StructureMappingcommandSet[] getColourBySequenceCommand( StructureSelectionManager ssm, String[] files, + AAStructureBindingModel binding, AlignmentViewPanel viewPanel) + { + SequenceRenderer sr = binding.getSequenceRenderer(viewPanel); + SequenceI[][] sequence = binding.getSequence(); + return getColourBySequenceCommand(ssm, files, sequence, sr, viewPanel); + } + + public static StructureMappingcommandSet[] getColourBySequenceCommand( + StructureSelectionManager ssm, String[] files, SequenceI[][] sequence, SequenceRenderer sr, AlignmentViewPanel viewPanel) { @@ -63,14 +73,14 @@ public class JmolCommands AlignViewportI viewport = viewPanel.getAlignViewport(); HiddenColumns cs = viewport.getAlignment().getHiddenColumns(); AlignmentI al = viewport.getAlignment(); - List cset = new ArrayList(); + List cset = new ArrayList<>(); for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++) { StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]); StringBuffer command = new StringBuffer(); StructureMappingcommandSet smc; - ArrayList str = new ArrayList(); + ArrayList str = new ArrayList<>(); if (mapping == null || mapping.length < 1) { diff --git a/src/jalview/ext/rbvi/chimera/ChimeraCommands.java b/src/jalview/ext/rbvi/chimera/ChimeraCommands.java index ec94e7d..dc53c2b 100644 --- a/src/jalview/ext/rbvi/chimera/ChimeraCommands.java +++ b/src/jalview/ext/rbvi/chimera/ChimeraCommands.java @@ -32,6 +32,7 @@ import jalview.renderer.seqfeatures.FeatureColourFinder; import jalview.structure.StructureMapping; import jalview.structure.StructureMappingcommandSet; import jalview.structure.StructureSelectionManager; +import jalview.structures.models.AAStructureBindingModel; import jalview.util.ColorUtils; import jalview.util.Comparison; @@ -68,11 +69,24 @@ public class ChimeraCommands */ public static StructureMappingcommandSet[] getColourBySequenceCommand( StructureSelectionManager ssm, String[] files, + AAStructureBindingModel binding, AlignmentViewPanel viewPanel) + { + SequenceRenderer sr = binding.getSequenceRenderer(viewPanel); + SequenceI[][] sequence = binding.getSequence(); + boolean hideHiddenRegions = binding.isShowAlignmentOnly() + && binding.isHideHiddenRegions(); + + return getColourBySequenceCommand(ssm, files, sequence, sr, + hideHiddenRegions, viewPanel); + } + + static StructureMappingcommandSet[] getColourBySequenceCommand( + StructureSelectionManager ssm, String[] files, SequenceI[][] sequence, SequenceRenderer sr, - AlignmentViewPanel viewPanel) + boolean hideHiddenRegions, AlignmentViewPanel viewPanel) { Map colourMap = buildColoursMap(ssm, files, - sequence, sr, viewPanel); + sequence, sr, hideHiddenRegions, viewPanel); List colourCommands = buildColourCommands(colourMap); @@ -175,20 +189,31 @@ public class ChimeraCommands } /** - *
-   * Build a data structure which records contiguous subsequences for each colour. 
+   * Build a data structure which records contiguous subsequences for each colour.
    * From this we can easily generate the Chimera command for colour by sequence.
+   * 
+   * 
    * Color
    *     Model number
    *         Chain
    *             list of start/end ranges
-   * Ordering is by order of addition (for colours and positions), natural ordering (for models and chains)
    * 
+ * + * Ordering is by order of addition (for colours and positions), natural + * ordering (for models and chains) + * + * @param ssm + * @param files + * @param sequence + * @param sr + * @param hideHiddenRegions + * @param viewPanel + * @return */ protected static Map buildColoursMap( StructureSelectionManager ssm, String[] files, SequenceI[][] sequence, SequenceRenderer sr, - AlignmentViewPanel viewPanel) + boolean hideHiddenRegions, AlignmentViewPanel viewPanel) { FeatureRenderer fr = viewPanel.getFeatureRenderer(); FeatureColourFinder finder = new FeatureColourFinder(fr); @@ -235,12 +260,18 @@ public class ChimeraCommands Color colour = sr.getResidueColour(seq, r, finder); /* - * hidden regions are shown gray - * todo: iterate over visible columns only + * hidden regions are shown gray or, optionally, ignored */ if (!cs.isVisible(r)) { - continue; // colour = Color.GRAY; + if (hideHiddenRegions) + { + continue; + } + else + { + colour = Color.GRAY; + } } final String chain = mapping[m].getChain(); diff --git a/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java b/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java index 1731a05..fc6dd26 100644 --- a/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java +++ b/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java @@ -22,7 +22,6 @@ package jalview.ext.rbvi.chimera; import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; -import jalview.api.SequenceRenderer; import jalview.api.structures.JalviewStructureDisplayI; import jalview.bin.Cache; import jalview.datamodel.AlignmentI; @@ -667,16 +666,15 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel /** * @param files - * @param sr * @param viewPanel * @return */ @Override protected StructureMappingcommandSet[] getColourBySequenceCommands( - String[] files, SequenceRenderer sr, AlignmentViewPanel viewPanel) + String[] files, AlignmentViewPanel viewPanel) { return ChimeraCommands.getColourBySequenceCommand(getSsm(), files, - getSequence(), sr, viewPanel); + this, viewPanel); } /** @@ -1350,7 +1348,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel continue; } Iterator visible; - if (isShowAlignmentOnly()) + if (isShowAlignmentOnly() && isHideHiddenRegions()) { visible = alignment.getHiddenColumns() .getVisContigsIterator(0, width, true); diff --git a/src/jalview/gui/StructureViewerBase.java b/src/jalview/gui/StructureViewerBase.java index cc431ac..ec51943 100644 --- a/src/jalview/gui/StructureViewerBase.java +++ b/src/jalview/gui/StructureViewerBase.java @@ -711,12 +711,14 @@ public abstract class StructureViewerBase extends GStructureViewer }); viewMenu.add(seqColourBy); - showAlignmentOnly = new JCheckBoxMenuItem("Visible alignment only"); + showAlignmentOnly = new JCheckBoxMenuItem( + MessageManager.getString("label.show_alignment_only")); showAlignmentOnly.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { + hideHiddenRegions.setEnabled(showAlignmentOnly.isSelected()); getBinding().setShowAlignmentOnly(showAlignmentOnly.isSelected()); getBinding().showStructures(getAlignmentPanel().getAlignViewport(), true); @@ -724,6 +726,21 @@ public abstract class StructureViewerBase extends GStructureViewer }); viewMenu.add(showAlignmentOnly); + hideHiddenRegions = new JCheckBoxMenuItem( + MessageManager.getString("label.hide_hidden_regions")); + hideHiddenRegions.setEnabled(false); + hideHiddenRegions.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + getBinding().setHideHiddenRegions(hideHiddenRegions.isSelected()); + getBinding().showStructures(getAlignmentPanel().getAlignViewport(), + false); + } + }); + viewMenu.add(hideHiddenRegions); + final ItemListener handler = new ItemListener() { @Override diff --git a/src/jalview/jbgui/GStructureViewer.java b/src/jalview/jbgui/GStructureViewer.java index 418e413..66cd8f2 100644 --- a/src/jalview/jbgui/GStructureViewer.java +++ b/src/jalview/jbgui/GStructureViewer.java @@ -59,6 +59,8 @@ public abstract class GStructureViewer extends JInternalFrame protected JCheckBoxMenuItem showAlignmentOnly; + protected JCheckBoxMenuItem hideHiddenRegions; + protected JMenuItem fitToWindow; protected JRadioButtonMenuItem seqColour; diff --git a/src/jalview/structures/models/AAStructureBindingModel.java b/src/jalview/structures/models/AAStructureBindingModel.java index 1fc59ed..ef4fed3 100644 --- a/src/jalview/structures/models/AAStructureBindingModel.java +++ b/src/jalview/structures/models/AAStructureBindingModel.java @@ -104,6 +104,8 @@ public abstract class AAStructureBindingModel // TODO make private once showStructures() deals with this protected List chainsToShow; + private boolean hideHiddenRegions; + /** * Data bean class to simplify parameterisation in superposeStructures */ @@ -785,7 +787,7 @@ public abstract class AAStructureBindingModel public abstract void setBackgroundColour(Color col); protected abstract StructureMappingcommandSet[] getColourBySequenceCommands( - String[] files, SequenceRenderer sr, AlignmentViewPanel avp); + String[] files, AlignmentViewPanel avp); /** * returns the current sequenceRenderer that should be used to colour the @@ -829,10 +831,8 @@ public abstract class AAStructureBindingModel } String[] files = getStructureFiles(); - SequenceRenderer sr = getSequenceRenderer(alignmentv); - StructureMappingcommandSet[] colourBySequenceCommands = getColourBySequenceCommands( - files, sr, alignmentv); + files, alignmentv); colourBySequence(colourBySequenceCommands); } @@ -856,8 +856,8 @@ public abstract class AAStructureBindingModel } /** - * Answers true if only mapped visible residues in the alignment should be - * visible in the structure viewer, else false + * Answers true if only residues mapped to the alignment should be shown in the + * structure viewer, else false * * @return */ @@ -867,6 +867,30 @@ public abstract class AAStructureBindingModel } /** + * Sets the flag for hiding regions of structure which are hidden in the + * alignment (only applies when the structure viewer is restricted to the + * alignment only) + * + * @param b + */ + public void setHideHiddenRegions(boolean b) + { + hideHiddenRegions = b; + } + + /** + * Answers true if regions hidden in the alignment should also be hidden in the + * structure viewer, else false (only applies when the structure viewer is + * restricted to the alignment only) + * + * @return + */ + public boolean isHideHiddenRegions() + { + return hideHiddenRegions; + } + + /** * Shows the structures in the viewer, without changing their colouring. This is * to support toggling of whether the whole structure is shown, or only residues * mapped to visible regions of the alignment. diff --git a/test/jalview/ext/rbvi/chimera/ChimeraCommandsTest.java b/test/jalview/ext/rbvi/chimera/ChimeraCommandsTest.java index 2c973ca..fbfe33c 100644 --- a/test/jalview/ext/rbvi/chimera/ChimeraCommandsTest.java +++ b/test/jalview/ext/rbvi/chimera/ChimeraCommandsTest.java @@ -59,7 +59,7 @@ public class ChimeraCommandsTest public void testBuildColourCommands() { - Map map = new LinkedHashMap(); + Map map = new LinkedHashMap<>(); ChimeraCommands.addColourRange(map, Color.blue, 0, 2, 5, "A"); ChimeraCommands.addColourRange(map, Color.blue, 0, 7, 7, "B"); ChimeraCommands.addColourRange(map, Color.blue, 0, 9, 23, "A"); @@ -72,10 +72,11 @@ public class ChimeraCommandsTest // Colours should appear in the Chimera command in the order in which // they were added; within colour, by model, by chain, ranges in start order + // all prefixed with #808080 to colour hidden regions (if shown) gray String command = ChimeraCommands.buildColourCommands(map).get(0); assertEquals( command, - "color #0000ff #0:2-5.A,9-23.A,7.B|#1:1.A,4-7.B; color #ffff00 #1:3-5.A,8.A; color #ff0000 #0:3-9.A"); + "color #808080; color #0000ff #0:2-5.A,9-23.A,7.B|#1:1.A,4-7.B; color #ffff00 #1:3-5.A,8.A; color #ff0000 #0:3-9.A"); } @Test(groups = { "Functional" }) @@ -84,8 +85,8 @@ public class ChimeraCommandsTest /* * make a map of { featureType, {featureValue, {residue range specification } } } */ - Map> featuresMap = new LinkedHashMap>(); - Map featureValues = new HashMap(); + Map> featuresMap = new LinkedHashMap<>(); + Map featureValues = new HashMap<>(); /* * start with just one feature/value... @@ -189,7 +190,7 @@ public class ChimeraCommandsTest /* * map residues 1-10 to residues 21-30 (atoms 105-150) in structures */ - HashMap map = new HashMap(); + HashMap map = new HashMap<>(); for (int pos = 1; pos <= seq1.getLength(); pos++) { map.put(pos, new int[] { 20 + pos, 5 * (20 + pos) }); @@ -202,7 +203,8 @@ public class ChimeraCommandsTest ssm.addStructureMapping(sm2); StructureMappingcommandSet[] commands = ChimeraCommands - .getColourBySequenceCommand(ssm, files, seqs, sr, af.alignPanel); + .getColourBySequenceCommand(ssm, files, seqs, sr, false, + af.alignPanel); assertEquals(1, commands.length); assertEquals(1, commands[0].commands.length); String theCommand = commands[0].commands[0]; diff --git a/test/jalview/structures/models/AAStructureBindingModelTest.java b/test/jalview/structures/models/AAStructureBindingModelTest.java index af02d5e..dde7d14 100644 --- a/test/jalview/structures/models/AAStructureBindingModelTest.java +++ b/test/jalview/structures/models/AAStructureBindingModelTest.java @@ -202,7 +202,7 @@ public class AAStructureBindingModelTest @Override protected StructureMappingcommandSet[] getColourBySequenceCommands( - String[] files, SequenceRenderer sr, AlignmentViewPanel avp) + String[] files, AlignmentViewPanel avp) { // TODO Auto-generated method stub return null; @@ -329,7 +329,7 @@ public class AAStructureBindingModelTest @Override protected StructureMappingcommandSet[] getColourBySequenceCommands( - String[] files, SequenceRenderer sr, AlignmentViewPanel avp) + String[] files, AlignmentViewPanel avp) { return null; }