import java.awt.Color;
import java.util.ArrayList;
+import java.util.Hashtable;
/**
* Routines for generating Chimera commands for Jalview/Chimera binding
{
ArrayList<StructureMappingcommandSet> cset = new ArrayList<StructureMappingcommandSet>();
-
+ Hashtable<String,StringBuffer> colranges=new Hashtable<String,StringBuffer>();
for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
{
float cols[] = new float[4];
{
if (lastCol != null)
{
-
- lastCol.getRGBComponents(cols);
- String newSelcom = "color " + cols[0] + "," + cols[1]
- + "," + cols[2] + " #" + startModel + ":"
- + startPos + "-" + lastPos + "." + lastChain;
- if (str.size() > 0
- && (str.get(str.size() - 1).length() + newSelcom
- .length()) < 4096)
- {
- str.set(str.size() - 1, str.get(str.size() - 1) + ";"
- + newSelcom);
- }
- else
- {
- str.add(newSelcom);
- }
+ addColourRange(colranges, lastCol,startModel,startPos,lastPos,lastChain);
}
lastCol = null;
startPos = pos;
// final colour range
if (lastCol != null)
{
-
- lastCol.getRGBComponents(cols);
- String newSelcom = "color " + cols[0] + "," + cols[1] + ","
- + cols[2] + " #" + startModel + ":" + startPos + "-"
- + lastPos + "." + lastChain;
- if (str.size() > 0
- && (str.get(str.size() - 1).length() + newSelcom
- .length()) < 4096)
- {
- str.set(str.size() - 1, str.get(str.size() - 1) + ";"
- + newSelcom);
- }
- else
- {
- str.add(newSelcom);
- }
+ addColourRange(colranges, lastCol,startModel,startPos,lastPos,lastChain);
}
break;
}
}
}
// Finally, add the command set ready to be returned.
+ StringBuffer coms=new StringBuffer();
+ for (String cr:colranges.keySet())
+ {
+ coms.append("color #"+cr+" "+colranges.get(cr)+";");
+ }
cset.add(new StructureMappingcommandSet(ChimeraCommands.class,
- files[pdbfnum], str.toArray(new String[str.size()])));
+ files[pdbfnum], new String[] { coms.toString() }));
}
return cset.toArray(new StructureMappingcommandSet[cset.size()]);
}
+ private static void addColourRange(Hashtable<String, StringBuffer> colranges, Color lastCol, int startModel,
+ int startPos, int lastPos, String lastChain)
+ {
+
+ String colstring = ((lastCol.getRed()< 16) ? "0":"")+Integer.toHexString(lastCol.getRed())
+ + ((lastCol.getGreen()< 16) ? "0":"")+Integer.toHexString(lastCol.getGreen())
+ + ((lastCol.getBlue()< 16) ? "0":"")+Integer.toHexString(lastCol.getBlue());
+ StringBuffer currange = colranges.get(colstring);
+ if (currange==null)
+ {
+ colranges.put(colstring,currange = new StringBuffer());
+ }
+ if (currange.length()>0)
+ {
+ currange.append("|");
+ }
+ currange.append("#" + startModel + ":" + ((startPos==lastPos) ? startPos : startPos + "-"
+ + lastPos) + "." + lastChain);
+ }
+
}