-/**\r
- * \r
- */\r
-package jalview.ext.jmol;\r
-\r
-import jalview.api.FeatureRenderer;\r
-import jalview.api.SequenceRenderer;\r
-import jalview.datamodel.AlignmentI;\r
-import jalview.datamodel.SequenceI;\r
-import jalview.structure.StructureMapping;\r
-import jalview.structure.StructureSelectionManager;\r
-import jalview.util.Comparison;\r
-\r
-import java.awt.Color;\r
-import java.util.ArrayList;\r
-\r
-/**\r
- * Routines for generating Jmol commands for Jalview/Jmol binding\r
- * @author JimP\r
- *\r
- */\r
-public class JmolCommands\r
-{\r
-\r
- /**\r
- * Jmol utility which constructs the commands to colour chains by the given alignment\r
- * \r
- */\r
- public static String[] getColourBySequenceCommand(StructureSelectionManager ssm, String[] files, SequenceI[][] sequence, SequenceRenderer sr, FeatureRenderer fr, AlignmentI alignment)\r
- {\r
- ArrayList<String> str = new ArrayList<String>();\r
- StringBuffer command = new StringBuffer();\r
- \r
- for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)\r
- {\r
- StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]);\r
- \r
- if (mapping == null || mapping.length < 1)\r
- continue;\r
- \r
- int lastPos = -1;\r
- for (int s = 0; s < sequence[pdbfnum].length; s++)\r
- {\r
- for (int sp, m = 0; m < mapping.length; m++)\r
- {\r
- if (mapping[m].getSequence() == sequence[pdbfnum][s]\r
- && (sp = alignment.findIndex(sequence[pdbfnum][s])) > -1)\r
- {\r
- SequenceI asp = alignment.getSequenceAt(sp);\r
- for (int r = 0; r < asp.getLength(); r++)\r
- {\r
- // no mapping to gaps in sequence\r
- if (jalview.util.Comparison.isGap(asp.getCharAt(r)))\r
- {\r
- continue;\r
- }\r
- int pos = mapping[m].getPDBResNum(asp.findPosition(r));\r
- \r
- if (pos < 1 || pos == lastPos)\r
- continue;\r
- \r
- lastPos = pos;\r
- \r
- Color col = sr.getResidueBoxColour(sequence[pdbfnum][s], r);\r
- \r
- if (fr != null)\r
- col = fr.findFeatureColour(col, sequence[pdbfnum][s], r);\r
- String newSelcom = (mapping[m].getChain() != " " ? ":"\r
- + mapping[m].getChain() : "")\r
- + "/"\r
- + (pdbfnum + 1)\r
- + ".1"\r
- + ";color["\r
- + col.getRed()\r
- + ","\r
- + col.getGreen()\r
- + ","\r
- + col.getBlue() + "]";\r
- if (command.length()>newSelcom.length() && command.substring(command.length()-newSelcom.length()).equals(newSelcom))\r
- {\r
- command = JmolCommands.condenseCommand(command, pos);\r
- continue;\r
- }\r
- // TODO: deal with case when buffer is too large for Jmol to parse\r
- // - execute command and flush\r
- \r
- command.append(";");\r
- if (command.length()>51200)\r
- {\r
- // add another chunk\r
- str.add(command.toString());\r
- command.setLength(0);\r
- }\r
- command.append("select " + pos);\r
- command.append(newSelcom);\r
- }\r
- break;\r
- }\r
- }\r
- }\r
- }\r
- {\r
- // add final chunk\r
- str.add(command.toString());\r
- command.setLength(0);\r
- }\r
- return str.toArray(new String[str.size()]);\r
- }\r
-\r
- public static StringBuffer condenseCommand(StringBuffer command, int pos)\r
- {\r
- \r
- // work back to last 'select'\r
- int p=command.length(),q=p;\r
- do {\r
- p-=6;\r
- if (p<1) { p=0; };\r
- } while ((q=command.indexOf("select",p))==-1 && p>0);\r
- \r
- StringBuffer sb = new StringBuffer(command.substring(0,q+7));\r
- \r
- command = command.delete(0,q+7);\r
- \r
- String start;\r
- \r
- if (command.indexOf("-") > -1)\r
- {\r
- start = command.substring(0, command.indexOf("-"));\r
- }\r
- else\r
- {\r
- start = command.substring(0, command.indexOf(":"));\r
- }\r
- \r
- sb.append(start + "-" + pos + command.substring(command.indexOf(":")));\r
- \r
- return sb;\r
- }\r
-\r
-}\r
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.ext.jmol;
+
+import jalview.api.FeatureRenderer;
+import jalview.api.SequenceRenderer;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.SequenceI;
+import jalview.structure.StructureMapping;
+import jalview.structure.StructureMappingcommandSet;
+import jalview.structure.StructureSelectionManager;
+
+import java.awt.Color;
+import java.util.ArrayList;
+
+/**
+ * Routines for generating Jmol commands for Jalview/Jmol binding another
+ * cruisecontrol test.
+ *
+ * @author JimP
+ *
+ */
+public class JmolCommands
+{
+
+ /**
+ * Jmol utility which constructs the commands to colour chains by the given
+ * alignment
+ *
+ * @returns Object[] { Object[] { <model being coloured>,
+ *
+ */
+ public static StructureMappingcommandSet[] getColourBySequenceCommand(
+ StructureSelectionManager ssm, String[] files,
+ SequenceI[][] sequence, SequenceRenderer sr, FeatureRenderer fr,
+ AlignmentI alignment)
+ {
+
+ ArrayList<StructureMappingcommandSet> cset = new ArrayList<StructureMappingcommandSet>();
+
+ for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
+ {
+ StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]);
+ StringBuffer command = new StringBuffer();
+ StructureMappingcommandSet smc;
+ ArrayList<String> str = new ArrayList<String>();
+
+ if (mapping == null || mapping.length < 1)
+ {
+ continue;
+ }
+
+ int lastPos = -1;
+ for (int s = 0; s < sequence[pdbfnum].length; s++)
+ {
+ for (int sp, m = 0; m < mapping.length; m++)
+ {
+ if (mapping[m].getSequence() == sequence[pdbfnum][s]
+ && (sp = alignment.findIndex(sequence[pdbfnum][s])) > -1)
+ {
+ SequenceI asp = alignment.getSequenceAt(sp);
+ for (int r = 0; r < asp.getLength(); r++)
+ {
+ // no mapping to gaps in sequence
+ if (jalview.util.Comparison.isGap(asp.getCharAt(r)))
+ {
+ continue;
+ }
+ int pos = mapping[m].getPDBResNum(asp.findPosition(r));
+
+ if (pos < 1 || pos == lastPos)
+ {
+ continue;
+ }
+
+ lastPos = pos;
+
+ Color col = sr.getResidueBoxColour(sequence[pdbfnum][s], r);
+
+ if (fr != null)
+ {
+ col = fr.findFeatureColour(col, sequence[pdbfnum][s], r);
+ }
+ String newSelcom = (mapping[m].getChain() != " " ? ":"
+ + mapping[m].getChain() : "")
+ + "/"
+ + (pdbfnum + 1)
+ + ".1"
+ + ";color["
+ + col.getRed()
+ + ","
+ + col.getGreen()
+ + ","
+ + col.getBlue() + "]";
+ if (command.length() > newSelcom.length()
+ && command.substring(
+ command.length() - newSelcom.length())
+ .equals(newSelcom))
+ {
+ command = JmolCommands.condenseCommand(command, pos);
+ continue;
+ }
+ // TODO: deal with case when buffer is too large for Jmol to parse
+ // - execute command and flush
+
+ command.append(";");
+ if (command.length() > 51200)
+ {
+ // add another chunk
+ str.add(command.toString());
+ command.setLength(0);
+ }
+ command.append("select " + pos);
+ command.append(newSelcom);
+ }
+ // break;
+ }
+ }
+ }
+ {
+ // add final chunk
+ str.add(command.toString());
+ command.setLength(0);
+ }
+ // Finally, add the command set ready to be returned.
+ cset.add(new StructureMappingcommandSet(JmolCommands.class,
+ files[pdbfnum], str.toArray(new String[str.size()])));
+
+ }
+ return cset.toArray(new StructureMappingcommandSet[cset.size()]);
+ }
+
+ public static StringBuffer condenseCommand(StringBuffer command, int pos)
+ {
+
+ // work back to last 'select'
+ int p = command.length(), q = p;
+ do
+ {
+ p -= 6;
+ if (p < 1)
+ {
+ p = 0;
+ }
+ ;
+ } while ((q = command.indexOf("select", p)) == -1 && p > 0);
+
+ StringBuffer sb = new StringBuffer(command.substring(0, q + 7));
+
+ command = command.delete(0, q + 7);
+
+ String start;
+
+ if (command.indexOf("-") > -1)
+ {
+ start = command.substring(0, command.indexOf("-"));
+ }
+ else
+ {
+ start = command.substring(0, command.indexOf(":"));
+ }
+
+ sb.append(start + "-" + pos + command.substring(command.indexOf(":")));
+
+ return sb;
+ }
+
+}