From 27f24d1f14b8e8704d72797286f7a6e5f60b2119 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Mon, 11 May 2020 15:56:55 +0100 Subject: [PATCH] JAL-3551 concatenate colour by sequence commands for all except PyMOL --- src/jalview/ext/jmol/JmolCommands.java | 2 +- src/jalview/ext/pymol/PymolCommands.java | 24 ++++++++++++ src/jalview/ext/rbvi/chimera/ChimeraCommands.java | 43 +++++++++++++++++---- src/jalview/structure/StructureCommandsBase.java | 24 ++++++++---- 4 files changed, 76 insertions(+), 17 deletions(-) diff --git a/src/jalview/ext/jmol/JmolCommands.java b/src/jalview/ext/jmol/JmolCommands.java index 797c25b..9c05a37 100644 --- a/src/jalview/ext/jmol/JmolCommands.java +++ b/src/jalview/ext/jmol/JmolCommands.java @@ -98,7 +98,7 @@ public class JmolCommands extends StructureCommandsBase c.getBlue()); } - + @Deprecated public String[] colourBySequence(StructureSelectionManager ssm, String[] files, SequenceI[][] sequence, SequenceRenderer sr, diff --git a/src/jalview/ext/pymol/PymolCommands.java b/src/jalview/ext/pymol/PymolCommands.java index 115efa1..e4f9f5f 100644 --- a/src/jalview/ext/pymol/PymolCommands.java +++ b/src/jalview/ext/pymol/PymolCommands.java @@ -3,6 +3,7 @@ package jalview.ext.pymol; import java.awt.Color; import java.util.ArrayList; import java.util.List; +import java.util.Map; import jalview.structure.AtomSpecModel; import jalview.structure.StructureCommand; @@ -209,4 +210,27 @@ public class PymolCommands extends StructureCommandsBase return new StructureCommand("load", file); } + /** + * Overrides the default implementation (which generates concatenated + * commands) to generate one per colour (because the XML-RPC interface to + * PyMOL only accepts one command at a time) + * + * @param colourMap + * @return + */ + @Override + public List colourBySequence( + Map colourMap) + { + List commands = new ArrayList<>(); + for (Object key : colourMap.keySet()) + { + Color colour = (Color) key; + final AtomSpecModel colourData = colourMap.get(colour); + commands.add(getColourCommand(colourData, colour)); + } + + return commands; + } + } diff --git a/src/jalview/ext/rbvi/chimera/ChimeraCommands.java b/src/jalview/ext/rbvi/chimera/ChimeraCommands.java index c355abe..c9dbc1d 100644 --- a/src/jalview/ext/rbvi/chimera/ChimeraCommands.java +++ b/src/jalview/ext/rbvi/chimera/ChimeraCommands.java @@ -20,6 +20,14 @@ */ package jalview.ext.rbvi.chimera; +import java.awt.Color; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; import jalview.api.FeatureRenderer; @@ -36,14 +44,6 @@ import jalview.structure.StructureMapping; import jalview.structure.StructureSelectionManager; import jalview.util.ColorUtils; -import java.awt.Color; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - /** * Routines for generating Chimera commands for Jalview/Chimera binding * @@ -641,4 +641,31 @@ public class ChimeraCommands extends StructureCommandsBase return new StructureCommand("open " + file); } + /** + * Overrides the default method to concatenate colour commands into one + */ + @Override + public List colourBySequence( + Map colourMap) + { + List commands = new ArrayList<>(); + StringBuilder sb = new StringBuilder(colourMap.size() * 20); + boolean first = true; + for (Object key : colourMap.keySet()) + { + Color colour = (Color) key; + final AtomSpecModel colourData = colourMap.get(colour); + StructureCommandI command = getColourCommand(colourData, colour); + if (!first) + { + sb.append(getCommandSeparator()); + } + first = false; + sb.append(command.getCommand()); + } + + commands.add(new StructureCommand(sb.toString())); + return commands; + } + } diff --git a/src/jalview/structure/StructureCommandsBase.java b/src/jalview/structure/StructureCommandsBase.java index 8c6ea4e..e688b64 100644 --- a/src/jalview/structure/StructureCommandsBase.java +++ b/src/jalview/structure/StructureCommandsBase.java @@ -1,14 +1,14 @@ package jalview.structure; -import jalview.api.AlignmentViewPanel; -import jalview.datamodel.SequenceI; - import java.awt.Color; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import jalview.api.AlignmentViewPanel; +import jalview.datamodel.SequenceI; + /** * A base class holding methods useful to all classes that implement commands * for structure viewers @@ -87,6 +87,9 @@ public abstract class StructureCommandsBase implements StructureCommandsI * Traverse the map of colours/models/chains/positions to construct a list of * 'color' commands (one per distinct colour used). The format of each command * is specific to the structure viewer. + *

+ * The default implementation returns a single command containing one command + * per colour, concatenated. * * @param colourMap * @return @@ -95,18 +98,23 @@ public abstract class StructureCommandsBase implements StructureCommandsI public List colourBySequence( Map colourMap) { - /* - * default implementation creates one command per colour; - * override to concatenate colour commands if wanted - */ List commands = new ArrayList<>(); + StringBuilder sb = new StringBuilder(colourMap.size() * 20); + boolean first = true; for (Object key : colourMap.keySet()) { Color colour = (Color) key; final AtomSpecModel colourData = colourMap.get(colour); - commands.add(getColourCommand(colourData, colour)); + StructureCommandI command = getColourCommand(colourData, colour); + if (!first) + { + sb.append(getCommandSeparator()); + } + first = false; + sb.append(command.getCommand()); } + commands.add(new StructureCommand(sb.toString())); return commands; } -- 1.7.10.2