From: gmungoc Date: Tue, 3 Mar 2020 14:24:23 +0000 (+0000) Subject: JAL-3518 more pull up / test coverage of structure command generation X-Git-Tag: Release_2_11_2_0~37^2~28 X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=commitdiff_plain;h=fea6f8ed76719fd78b600adfea8891dafb8c9d12 JAL-3518 more pull up / test coverage of structure command generation --- diff --git a/src/jalview/ext/jmol/JalviewJmolBinding.java b/src/jalview/ext/jmol/JalviewJmolBinding.java index 6b0a696..20952f2 100644 --- a/src/jalview/ext/jmol/JalviewJmolBinding.java +++ b/src/jalview/ext/jmol/JalviewJmolBinding.java @@ -177,6 +177,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel public String superposeStructures(AlignmentI[] _alignment, int[] _refStructure, HiddenColumns[] _hiddenCols) { + // TODO delete method while (jmolViewer.isScriptExecuting()) { try diff --git a/src/jalview/ext/jmol/JmolCommands.java b/src/jalview/ext/jmol/JmolCommands.java index 7dd5c0b..6f682be 100644 --- a/src/jalview/ext/jmol/JmolCommands.java +++ b/src/jalview/ext/jmol/JmolCommands.java @@ -71,7 +71,13 @@ public class JmolCommands extends StructureCommandsBase return 1; } - @Override + /** + * Returns a string representation of the given colour suitable for inclusion + * in Jmol commands + * + * @param c + * @return + */ protected String getColourString(Color c) { return c == null ? null @@ -79,27 +85,13 @@ public class JmolCommands extends StructureCommandsBase c.getBlue()); } - /** - * Returns commands (one per colour key in the map) like - * - *
-   *   select 2:A/1.1|3-27:B/1.1|9-12:A/2.1;color[173,0,82]
-   * 
- */ - @Override - public String[] colourBySequence(Map colourMap) - { - List colourCommands = buildColourCommands(colourMap); - - return colourCommands.toArray(new String[colourCommands.size()]); - } public String[] colourBySequence(StructureSelectionManager ssm, String[] files, SequenceI[][] sequence, SequenceRenderer sr, AlignmentViewPanel viewPanel) { - // TODO refactor to call buildColoursMap() first... + // TODO delete method FeatureRenderer fr = viewPanel.getFeatureRenderer(); FeatureColourFinder finder = new FeatureColourFinder(fr); diff --git a/src/jalview/ext/rbvi/chimera/ChimeraCommands.java b/src/jalview/ext/rbvi/chimera/ChimeraCommands.java index 14699ef..1b1dd35 100644 --- a/src/jalview/ext/rbvi/chimera/ChimeraCommands.java +++ b/src/jalview/ext/rbvi/chimera/ChimeraCommands.java @@ -62,14 +62,6 @@ public class ChimeraCommands extends StructureCommandsBase private static final String NO_ALTLOCS = "&~@.B-Z&~@.2-9"; @Override - public String[] colourBySequence(Map colourMap) - { - List colourCommands = buildColourCommands(colourMap); - - return colourCommands.toArray(new String[colourCommands.size()]); - } - - @Override public String getColourCommand(String atomSpec, Color colour) { // https://www.cgl.ucsf.edu/chimera/current/docs/UsersGuide/midas/color.html @@ -83,7 +75,6 @@ public class ChimeraCommands extends StructureCommandsBase * @param colour * @return */ - @Override protected String getColourString(Color colour) { return ColorUtils.toTkCode(colour); @@ -108,9 +99,7 @@ public class ChimeraCommands extends StructureCommandsBase Map> featureMap = buildFeaturesMap( ssm, files, seqs, viewPanel); - List commands = buildSetAttributeCommands(featureMap); - - return commands.toArray(new String[commands.size()]); + return setAttributes(featureMap); } /** @@ -354,7 +343,7 @@ public class ChimeraCommands extends StructureCommandsBase * @param featureMap * @return */ - protected List buildSetAttributeCommands( + protected String[] setAttributes( Map> featureMap) { List commands = new ArrayList<>(); @@ -379,13 +368,13 @@ public class ChimeraCommands extends StructureCommandsBase AtomSpecModel atomSpecModel = values.get(value); String featureValue = value.toString(); featureValue = featureValue.replaceAll("\\'", "'"); - String cmd = getSetAttributeCommand(attributeName, featureValue, + String cmd = setAttribute(attributeName, featureValue, atomSpecModel); commands.add(cmd); } } - return commands; + return commands.toArray(new String[commands.size()]); } /** @@ -401,7 +390,7 @@ public class ChimeraCommands extends StructureCommandsBase * @param atomSpecModel * @return */ - protected String getSetAttributeCommand(String attributeName, + protected String setAttribute(String attributeName, String attributeValue, AtomSpecModel atomSpecModel) { diff --git a/src/jalview/ext/rbvi/chimera/ChimeraXCommands.java b/src/jalview/ext/rbvi/chimera/ChimeraXCommands.java index 7ece122..5eba203 100644 --- a/src/jalview/ext/rbvi/chimera/ChimeraXCommands.java +++ b/src/jalview/ext/rbvi/chimera/ChimeraXCommands.java @@ -96,7 +96,7 @@ public class ChimeraXCommands extends ChimeraCommands * @return */ @Override - protected String getSetAttributeCommand(String attributeName, + protected String setAttribute(String attributeName, String attributeValue, AtomSpecModel atomSpecModel) { StringBuilder sb = new StringBuilder(128); @@ -165,8 +165,7 @@ public class ChimeraXCommands extends ChimeraCommands for (String chain : atomSpec.getChains(model)) { boolean firstPositionForChain = true; - chain = " ".equals(chain) ? chain : chain.trim(); - sb.append("/").append(chain).append(":"); + sb.append("/").append(chain.trim()).append(":"); List rangeList = atomSpec.getRanges(model, chain); /* diff --git a/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java b/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java index 731ffea..3656204 100644 --- a/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java +++ b/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java @@ -273,6 +273,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel public String superposeStructures(AlignmentI[] _alignment, int[] _refStructure, HiddenColumns[] _hiddenCols) { + // TODO delete method StringBuilder allComs = new StringBuilder(128); String[] files = getStructureFiles(); diff --git a/src/jalview/structure/StructureCommandsBase.java b/src/jalview/structure/StructureCommandsBase.java index 921c9cd..44764db 100644 --- a/src/jalview/structure/StructureCommandsBase.java +++ b/src/jalview/structure/StructureCommandsBase.java @@ -58,118 +58,6 @@ public abstract class StructureCommandsBase implements StructureCommandsI } /** - *
-   * Build a data structure which records contiguous subsequences for each colour. 
-   * From this we can easily generate the viewer 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)
-   * 
- * - * @param ssm - * @param files - * @param sequence - * @param sr - * @param viewPanel - * @return - */ - protected Map buildColoursMap( - StructureSelectionManager ssm, String[] files, - SequenceI[][] sequence, SequenceRenderer sr, AlignmentViewPanel viewPanel) - { - FeatureRenderer fr = viewPanel.getFeatureRenderer(); - FeatureColourFinder finder = new FeatureColourFinder(fr); - AlignViewportI viewport = viewPanel.getAlignViewport(); - HiddenColumns cs = viewport.getAlignment().getHiddenColumns(); - AlignmentI al = viewport.getAlignment(); - Map colourMap = new LinkedHashMap<>(); - Color lastColour = null; - - for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++) - { - final int modelNumber = pdbfnum + getModelStartNo(); - StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]); - - if (mapping == null || mapping.length < 1) - { - continue; - } - - int startPos = -1, lastPos = -1; - String lastChain = ""; - for (int s = 0; s < sequence[pdbfnum].length; s++) - { - for (int sp, m = 0; m < mapping.length; m++) - { - final SequenceI seq = sequence[pdbfnum][s]; - if (mapping[m].getSequence() == seq - && (sp = al.findIndex(seq)) > -1) - { - SequenceI asp = al.getSequenceAt(sp); - for (int r = 0; r < asp.getLength(); r++) - { - // no mapping to gaps in sequence - if (Comparison.isGap(asp.getCharAt(r))) - { - continue; - } - int pos = mapping[m].getPDBResNum(asp.findPosition(r)); - - if (pos < 1 || pos == lastPos) - { - continue; - } - - Color colour = sr.getResidueColour(seq, r, finder); - - /* - * darker colour for hidden regions - */ - if (!cs.isVisible(r)) - { - colour = Color.GRAY; - } - - final String chain = mapping[m].getChain(); - - /* - * Just keep incrementing the end position for this colour range - * _unless_ colour, PDB model or chain has changed, or there is a - * gap in the mapped residue sequence - */ - final boolean newColour = !colour.equals(lastColour); - final boolean nonContig = lastPos + 1 != pos; - final boolean newChain = !chain.equals(lastChain); - if (newColour || nonContig || newChain) - { - if (startPos != -1) - { - addAtomSpecRange(colourMap, lastColour, modelNumber, - startPos, lastPos, lastChain); - } - startPos = pos; - } - lastColour = colour; - lastPos = pos; - lastChain = chain; - } - // final colour range - if (lastColour != null) - { - addAtomSpecRange(colourMap, lastColour, modelNumber, startPos, - lastPos, lastChain); - } - // break; - } - } - } - } - return colourMap; - } - - /** * Helper method to add one contiguous range to the AtomSpec model for the given * value (creating the model if necessary). As used by Jalview, {@code value} is *