4 package jalview.ext.varna;
\r
6 import jalview.api.FeatureRenderer;
\r
7 import jalview.api.SequenceRenderer;
\r
8 import jalview.datamodel.AlignmentI;
\r
9 import jalview.datamodel.SequenceI;
\r
10 import jalview.structure.StructureMapping;
\r
11 import jalview.structure.StructureSelectionManager;
\r
12 import jalview.util.Comparison;
\r
14 import java.awt.Color;
\r
15 import java.util.ArrayList;
\r
18 * Routines for generating Jmol commands for Jalview/Jmol binding another
\r
19 * cruisecontrol test.
\r
24 public class VarnaCommands
\r
28 * Jmol utility which constructs the commands to colour chains by the given
\r
32 public static String[] getColourBySequenceCommand(
\r
33 StructureSelectionManager ssm, String[] files,
\r
34 SequenceI[][] sequence, SequenceRenderer sr, FeatureRenderer fr,
\r
35 AlignmentI alignment)
\r
37 ArrayList<String> str = new ArrayList<String>();
\r
38 StringBuffer command = new StringBuffer();
\r
40 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
\r
42 StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]);
\r
44 if (mapping == null || mapping.length < 1)
\r
48 for (int s = 0; s < sequence[pdbfnum].length; s++)
\r
50 for (int sp, m = 0; m < mapping.length; m++)
\r
52 if (mapping[m].getSequence() == sequence[pdbfnum][s]
\r
53 && (sp = alignment.findIndex(sequence[pdbfnum][s])) > -1)
\r
55 SequenceI asp = alignment.getSequenceAt(sp);
\r
56 for (int r = 0; r < asp.getLength(); r++)
\r
58 // no mapping to gaps in sequence
\r
59 if (jalview.util.Comparison.isGap(asp.getCharAt(r)))
\r
63 int pos = mapping[m].getPDBResNum(asp.findPosition(r));
\r
65 if (pos < 1 || pos == lastPos)
\r
70 Color col = sr.getResidueBoxColour(sequence[pdbfnum][s], r);
\r
73 col = fr.findFeatureColour(col, sequence[pdbfnum][s], r);
\r
74 String newSelcom = (mapping[m].getChain() != " " ? ":"
\r
75 + mapping[m].getChain() : "")
\r
84 + col.getBlue() + "]";
\r
85 if (command.length() > newSelcom.length()
\r
86 && command.substring(
\r
87 command.length() - newSelcom.length())
\r
90 command = VarnaCommands.condenseCommand(command, pos);
\r
93 // TODO: deal with case when buffer is too large for Jmol to parse
\r
94 // - execute command and flush
\r
96 command.append(";");
\r
97 if (command.length() > 51200)
\r
99 // add another chunk
\r
100 str.add(command.toString());
\r
101 command.setLength(0);
\r
103 command.append("select " + pos);
\r
104 command.append(newSelcom);
\r
113 str.add(command.toString());
\r
114 command.setLength(0);
\r
116 return str.toArray(new String[str.size()]);
\r
119 public static StringBuffer condenseCommand(StringBuffer command, int pos)
\r
122 // work back to last 'select'
\r
123 int p = command.length(), q = p;
\r
132 } while ((q = command.indexOf("select", p)) == -1 && p > 0);
\r
134 StringBuffer sb = new StringBuffer(command.substring(0, q + 7));
\r
136 command = command.delete(0, q + 7);
\r
140 if (command.indexOf("-") > -1)
\r
142 start = command.substring(0, command.indexOf("-"));
\r
146 start = command.substring(0, command.indexOf(":"));
\r
149 sb.append(start + "-" + pos + command.substring(command.indexOf(":")));
\r