X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fext%2Fjmol%2FJmolCommands.java;h=603202a84ef71776fb441992bdac1e7d606f51fa;hb=1450fb2e94eea45507c0147e7e3d993dc98f1633;hp=a809caecc1b7126cae8d62fb243590c64ccdaa01;hpb=799c26111d6936a2e70cb5f1fd7d7312311e6db9;p=jalview.git diff --git a/src/jalview/ext/jmol/JmolCommands.java b/src/jalview/ext/jmol/JmolCommands.java index a809cae..603202a 100644 --- a/src/jalview/ext/jmol/JmolCommands.java +++ b/src/jalview/ext/jmol/JmolCommands.java @@ -21,11 +21,13 @@ 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.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.SequenceI; +import jalview.renderer.seqfeatures.FeatureColourFinder; import jalview.structure.StructureMapping; import jalview.structure.StructureMappingcommandSet; import jalview.structure.StructureSelectionManager; @@ -53,17 +55,20 @@ public class JmolCommands */ public static StructureMappingcommandSet[] getColourBySequenceCommand( StructureSelectionManager ssm, String[] files, - SequenceI[][] sequence, SequenceRenderer sr, FeatureRenderer fr, - AlignViewportI viewport) + SequenceI[][] sequence, SequenceRenderer sr, + AlignmentViewPanel viewPanel) { - ColumnSelection cs = viewport.getColumnSelection(); + FeatureRenderer fr = viewPanel.getFeatureRenderer(); + FeatureColourFinder finder = new FeatureColourFinder(fr); + AlignViewportI viewport = viewPanel.getAlignViewport(); + HiddenColumns cs = viewport.getAlignment().getHiddenColumns(); AlignmentI al = viewport.getAlignment(); List cset = new ArrayList(); for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++) { StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]); - StringBuffer command = new StringBuffer(); + StringBuilder command = new StringBuilder(); StructureMappingcommandSet smc; ArrayList str = new ArrayList(); @@ -72,7 +77,6 @@ public class JmolCommands continue; } - int lastPos = -1; for (int s = 0; s < sequence[pdbfnum].length; s++) { for (int sp, m = 0; m < mapping.length; m++) @@ -80,6 +84,7 @@ public class JmolCommands if (mapping[m].getSequence() == sequence[pdbfnum][s] && (sp = al.findIndex(sequence[pdbfnum][s])) > -1) { + int lastPos = StructureMapping.UNASSIGNED_VALUE; SequenceI asp = al.getSequenceAt(sp); for (int r = 0; r < asp.getLength(); r++) { @@ -90,44 +95,47 @@ public class JmolCommands } int pos = mapping[m].getPDBResNum(asp.findPosition(r)); - if (pos < 1 || pos == lastPos) + if (pos == lastPos) { continue; } + if (pos == StructureMapping.UNASSIGNED_VALUE) + { + // terminate current colour op + if (command.length() > 0 + && command.charAt(command.length() - 1) != ';') + { + command.append(";"); + } + // reset lastPos + lastPos = StructureMapping.UNASSIGNED_VALUE; + continue; + } lastPos = pos; - Color col = sr.getResidueBoxColour(sequence[pdbfnum][s], r); - - if (fr != null) - { - col = fr.findFeatureColour(col, sequence[pdbfnum][s], r); - } + Color col = sr.getResidueColour(sequence[pdbfnum][s], r, + finder); /* * shade hidden regions darker */ if (!cs.isVisible(r)) { - // col = ColorUtils.darkerThan(col); col = Color.GRAY; } - String newSelcom = (mapping[m].getChain() != " " ? ":" - + mapping[m].getChain() : "") - + "/" - + (pdbfnum + 1) - + ".1" - + ";color[" - + col.getRed() - + "," - + col.getGreen() - + "," + // todo JAL-3152 handle 'no chain' case without errors + boolean hasChain = true || mapping[m].getChain() != " "; + String chainSpec = hasChain + ? ":" + mapping[m].getChain() + : ""; + String newSelcom = chainSpec + "/" + (pdbfnum + 1) + ".1" + ";color[" + + col.getRed() + "," + col.getGreen() + "," + col.getBlue() + "]"; - if (command.length() > newSelcom.length() - && command.substring( - command.length() - newSelcom.length()) - .equals(newSelcom)) + if (command.length() > newSelcom.length() && command + .substring(command.length() - newSelcom.length()) + .equals(newSelcom)) { command = JmolCommands.condenseCommand(command, pos); continue; @@ -135,7 +143,12 @@ public class JmolCommands // TODO: deal with case when buffer is too large for Jmol to parse // - execute command and flush - command.append(";"); + if (command.length() > 0 + && command.charAt(command.length() - 1) != ';') + { + command.append(";"); + } + if (command.length() > 51200) { // add another chunk @@ -162,7 +175,7 @@ public class JmolCommands return cset.toArray(new StructureMappingcommandSet[cset.size()]); } - public static StringBuffer condenseCommand(StringBuffer command, int pos) + public static StringBuilder condenseCommand(StringBuilder command, int pos) { // work back to last 'select' @@ -177,7 +190,7 @@ public class JmolCommands ; } while ((q = command.indexOf("select", p)) == -1 && p > 0); - StringBuffer sb = new StringBuffer(command.substring(0, q + 7)); + StringBuilder sb = new StringBuilder(command.substring(0, q + 7)); command = command.delete(0, q + 7);