From 8f0f304ea24d01bc052089dde29a22934c73b326 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 8 Aug 2019 10:16:34 +0100 Subject: [PATCH] JAL-3400 include sequence name in View | Show Chain menu --- src/jalview/ext/jmol/JalviewJmolBinding.java | 8 ---- .../ext/rbvi/chimera/JalviewChimeraBinding.java | 14 ------ src/jalview/gui/StructureViewerBase.java | 46 +++++++++++++++++++- src/jalview/jbgui/GStructureViewer.java | 2 +- .../structure/StructureSelectionManager.java | 22 ++++++++++ .../structures/models/AAStructureBindingModel.java | 20 ++++++--- .../ext/rbvi/chimera/ChimeraCommandsTest.java | 6 --- .../models/AAStructureBindingModelTest.java | 13 ------ 8 files changed, 80 insertions(+), 51 deletions(-) diff --git a/src/jalview/ext/jmol/JalviewJmolBinding.java b/src/jalview/ext/jmol/JalviewJmolBinding.java index d820273..c727baf 100644 --- a/src/jalview/ext/jmol/JalviewJmolBinding.java +++ b/src/jalview/ext/jmol/JalviewJmolBinding.java @@ -77,8 +77,6 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel Vector atomsPicked = new Vector<>(); - private List chainNames; - Hashtable chainFile; /* @@ -1196,12 +1194,6 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel setLoadingFromArchive(false); } - @Override - public List getChainNames() - { - return chainNames; - } - protected IProgressIndicator getIProgressIndicator() { return null; diff --git a/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java b/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java index 381bbea..a5273f5 100644 --- a/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java +++ b/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java @@ -76,8 +76,6 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel private static final String ALPHACARBON = "CA"; - private List chainNames = new ArrayList<>(); - private Hashtable chainFile = new Hashtable<>(); /* @@ -1021,18 +1019,6 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel } /** - * Returns a list of chains mapped in this viewer. Note this list is not - * currently scoped per structure. - * - * @return - */ - @Override - public List getChainNames() - { - return chainNames; - } - - /** * Send a 'focus' command to Chimera to recentre the visible display */ public void focusView() diff --git a/src/jalview/gui/StructureViewerBase.java b/src/jalview/gui/StructureViewerBase.java index d04d1d6..853ecc1 100644 --- a/src/jalview/gui/StructureViewerBase.java +++ b/src/jalview/gui/StructureViewerBase.java @@ -53,6 +53,7 @@ import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Vector; @@ -515,6 +516,10 @@ public abstract class StructureViewerBase extends GStructureViewer { return; } + + /* + * add the 'All' menu item + */ JMenuItem menuItem = new JMenuItem( MessageManager.getString("label.all")); menuItem.addActionListener(new ActionListener() @@ -534,12 +539,29 @@ public abstract class StructureViewerBase extends GStructureViewer allChainsSelected = false; } }); - chainMenu.add(menuItem); + /* + * add a menu item for each structure and chain + */ + Collections.sort(chainNames); + String lastSeqName = ""; for (String chain : chainNames) { - menuItem = new JCheckBoxMenuItem(chain, true); + String seqName = getSequenceNameForChain(chain); + int nameLength = seqName.length(); + if (nameLength > 16) + { + seqName = seqName.substring(0, 8) + "..." + + seqName.substring(nameLength - 8, nameLength); + } + String text = chain; + if (!lastSeqName.equals(seqName)) + { + text = text + " " + seqName; + } + lastSeqName = seqName; + menuItem = new JCheckBoxMenuItem(text, true); menuItem.addItemListener(new ItemListener() { @Override @@ -557,6 +579,26 @@ public abstract class StructureViewerBase extends GStructureViewer } /** + * Answers the name of the sequence mapped to the given chain (formatted as + * pdbId:chainId, e.g. 1A70:A). Answers null if no mapped sequence is found. If + * more than one sequence is matched, just answers the name of the first one + * found. + * + * @param chain + * @return + */ + private String getSequenceNameForChain(String chain) + { + String[] tokens = chain.split(":"); + String pdbId = tokens[0]; + String chainId = tokens[1]; + List mappings = getBinding().getSsm() + .getMappingForChain(pdbId, chainId); + return mappings.isEmpty() ? null + : mappings.get(0).getSequence().getName(); + } + + /** * Action on selecting one of Jalview's registered colour schemes */ @Override diff --git a/src/jalview/jbgui/GStructureViewer.java b/src/jalview/jbgui/GStructureViewer.java index 66cd8f2..a7a970f 100644 --- a/src/jalview/jbgui/GStructureViewer.java +++ b/src/jalview/jbgui/GStructureViewer.java @@ -291,7 +291,7 @@ public abstract class GStructureViewer extends JInternalFrame JCheckBoxMenuItem item = (JCheckBoxMenuItem) menuItem; if (item.isSelected()) { - chains.add(item.getText()); + chains.add(item.getText().split(" ")[0]); } } } diff --git a/src/jalview/structure/StructureSelectionManager.java b/src/jalview/structure/StructureSelectionManager.java index 054ed2f..e1045c0 100644 --- a/src/jalview/structure/StructureSelectionManager.java +++ b/src/jalview/structure/StructureSelectionManager.java @@ -1161,6 +1161,28 @@ public class StructureSelectionManager } /** + * Answers a (possibly empty) list of structure to sequence mappings matching + * the given pdb and chain ids + * + * @param pdbId + * @param chain + * @return + */ + public List getMappingForChain(String pdbId, + String chain) + { + List result = new ArrayList<>(); + for (StructureMapping sm : mappings) + { + if (sm.pdbid.equals(pdbId) && sm.pdbchain.equals(chain)) + { + result.add(sm); + } + } + return result; + } + + /** * Returns a readable description of all mappings for the given pdbfile to any * of the given sequences * diff --git a/src/jalview/structures/models/AAStructureBindingModel.java b/src/jalview/structures/models/AAStructureBindingModel.java index 8a7c355..b55885d 100644 --- a/src/jalview/structures/models/AAStructureBindingModel.java +++ b/src/jalview/structures/models/AAStructureBindingModel.java @@ -113,6 +113,8 @@ public abstract class AAStructureBindingModel private boolean hideHiddenRegions; + protected List chainNames = new ArrayList<>(); + /** * Data bean class to simplify parameterisation in superposeStructures */ @@ -754,13 +756,6 @@ public abstract class AAStructureBindingModel } /** - * Returns a list of chains mapped in this viewer. - * - * @return - */ - public abstract List getChainNames(); - - /** * Returns the Jalview panel hosting the structure viewer (if any) * * @return @@ -1175,4 +1170,15 @@ public abstract class AAStructureBindingModel } return colourMap; } + + /** + * Returns a list of chains mapped in this viewer. Note this list is not + * currently scoped per structure. + * + * @return + */ + public List getChainNames() + { + return chainNames; + } } diff --git a/test/jalview/ext/rbvi/chimera/ChimeraCommandsTest.java b/test/jalview/ext/rbvi/chimera/ChimeraCommandsTest.java index 1d620c4..18c4a14 100644 --- a/test/jalview/ext/rbvi/chimera/ChimeraCommandsTest.java +++ b/test/jalview/ext/rbvi/chimera/ChimeraCommandsTest.java @@ -72,12 +72,6 @@ public class ChimeraCommandsTest } @Override - public List getChainNames() - { - return null; - } - - @Override public void setJalviewColourScheme(ColourSchemeI cs) { } diff --git a/test/jalview/structures/models/AAStructureBindingModelTest.java b/test/jalview/structures/models/AAStructureBindingModelTest.java index ee155ac..3992746 100644 --- a/test/jalview/structures/models/AAStructureBindingModelTest.java +++ b/test/jalview/structures/models/AAStructureBindingModelTest.java @@ -208,13 +208,6 @@ public class AAStructureBindingModelTest } @Override - public List getChainNames() - { - // TODO Auto-generated method stub - return null; - } - - @Override protected void colourBySequence(String[] colourBySequenceCommands) { // TODO Auto-generated method stub @@ -303,12 +296,6 @@ public class AAStructureBindingModelTest } @Override - public List getChainNames() - { - return null; - } - - @Override public void setJalviewColourScheme(ColourSchemeI cs) { } -- 1.7.10.2