if (applet.getParameter("userDefinedColour") != null)
{
- ((UserColourScheme) globalColourScheme).parseAppletParameter(applet
- .getParameter("userDefinedColour"));
+ globalColourScheme = new UserColourScheme(
+ applet.getParameter("userDefinedColour"));
}
}
initAutoAnnotation();
import jalview.io.gff.SequenceOntologyFactory;
import jalview.schemes.ColourSchemeI;
import jalview.schemes.ColourSchemeProperty;
-import jalview.schemes.UserColourScheme;
import jalview.util.MessageManager;
import jalview.util.Platform;
import jalview.ws.jws2.Jws2Discoverer;
ColourSchemeI cs = ColourSchemeProperty.getColourScheme(af
.getViewport().getAlignment(), data);
- if (cs == null)
- {
- UserColourScheme ucs = new UserColourScheme("white");
- ucs.parseAppletParameter(data);
- cs = ucs;
- }
- else
+ if (cs != null)
{
System.out.println("CMD [-color " + data
+ "] executed successfully!");
* <li>RNA Helices</li>
* <li>User Defined</li>
* <li>an AWT colour name e.g. red</li>
+ * <li>an AWT hex rgb colour e.g. ff2288</li>
* <li>residue colours list e.g. D,E=red;K,R,H=0022FF;c=yellow</li>
* </ul>
* If none of these formats is matched, the string is converted to a colour
return scheme.getColourScheme(forData);
}
- if (name.indexOf('=') == -1)
- {
- /*
- * parse the name as a colour specification
- * e.g. "red" or "ff00ed",
- * or failing that hash the name to a colour
- */
- return new UserColourScheme(name);
- }
-
/*
* try to parse the string as a residues colour scheme
* e.g. A=red;T,G=blue etc
+ * else parse the name as a colour specification
+ * e.g. "red" or "ff00ed",
+ * or failing that hash the name to a colour
*/
UserColourScheme ucs = null;
try
{
- // fix the launchApp user defined colourscheme transfer bug
- ucs = new UserColourScheme("white");
- ucs.parseAppletParameter(name);
+ ucs = new UserColourScheme(name);
} catch (Exception e)
{
// System.err.println("Ignoring exception when parsing colourscheme as applet-parameter");
import jalview.datamodel.AnnotatedCollectionI;
-import java.awt.Color;
import java.util.HashMap;
import java.util.Map;
@Override
public ColourSchemeI getColourScheme(AnnotatedCollectionI coll)
{
- Color[] col = new Color[24];
- for (int i = 0; i < 24; i++)
- {
- col[i] = Color.white;
- }
return new UserColourScheme("white");
}
};
{
public static final String NONE = "None";
+ /*
+ * lookup up by character value e.g. 'G' to the colors array index
+ * e.g. if symbolIndex['K'] = 11 then colors[11] is the colour for K
+ */
final int[] symbolIndex;
boolean conservationColouring = false;
+ /*
+ * colour for residue characters as indexed by symbolIndex
+ */
Color[] colors = null;
int threshold = 0;
import jalview.util.ColorUtils;
import java.awt.Color;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.StringTokenizer;
public class UserColourScheme extends ResidueColourScheme
{
+ /*
+ * lookup (by symbol index) of lower case colours (if configured)
+ */
Color[] lowerCaseColours;
protected String schemeName;
UserColourScheme usc = new UserColourScheme(colors);
if (lowerCaseColours != null)
{
- usc.schemeName = new String(schemeName);
+ usc.schemeName = schemeName;
usc.lowerCaseColours = new Color[lowerCaseColours.length];
System.arraycopy(lowerCaseColours, 0, usc.lowerCaseColours, 0,
lowerCaseColours.length);
return usc;
}
+ /**
+ * Constructor for an animino acid colour scheme. The colour specification may
+ * be one of
+ * <ul>
+ * <li>an AWT colour name e.g. red</li>
+ * <li>an AWT hex rgb colour e.g. ff2288</li>
+ * <li>residue colours list e.g. D,E=red;K,R,H=0022FF;c=yellow</li>
+ * </ul>
+ *
+ * @param colour
+ */
public UserColourScheme(String colour)
{
super(ResidueProperties.aaIndex);
+
+ if (colour.contains("="))
+ {
+ /*
+ * a list of colours per residue(s)
+ */
+ parseAppletParameter(colour);
+ return;
+ }
+
Color col = ColorUtils.parseColourString(colour);
if (col == null)
col = ColorUtils.createColourFromName(colour);
}
- colors = new Color[24];
- for (int i = 0; i < 24; i++)
+ setAll(col);
+ schemeName = colour;
+ }
+
+ /**
+ * Sets all symbols to the specified colour
+ *
+ * @param col
+ */
+ protected void setAll(Color col)
+ {
+ if (symbolIndex == null)
+ {
+ return;
+ }
+ int max = 0;
+ for (int index : symbolIndex)
+ {
+ max = Math.max(max, index);
+ }
+ colors = new Color[max + 1];
+ for (int i = 0; i <= max; i++)
{
colors[i] = col;
}
- schemeName = colour;
}
public Color[] getColours()
*
* @param paramValue
*/
- public void parseAppletParameter(String paramValue)
+ void parseAppletParameter(String paramValue)
{
- // TODO: need a function to generate appletParameter colour string from a
- // UCS
+ setAll(Color.white);
+
StringTokenizer st = new StringTokenizer(paramValue, ";");
StringTokenizer st2;
String token = null, colour, residues;
{
if (lowerCaseColours == null)
{
- lowerCaseColours = new Color[23];
+ lowerCaseColours = new Color[colors.length];
}
- for (int i = 0; i < 23; i++)
+ for (int i = 0; i < lowerCaseColours.length; i++)
{
if (lowerCaseColours[i] == null)
{
{
if (lowerCaseColours == null)
{
- lowerCaseColours = new Color[23];
+ lowerCaseColours = new Color[colors.length];
}
lowerCaseColours[colIndex] = ColorUtils.parseColourString(colour);
}
return JalviewColourScheme.UserDefined.toString();
}
+ /**
+ * Generate an applet colour parameter like A,C,D=12ffe9;Q,W=2393fd;w=9178dd
+ *
+ * @return
+ */
+ public String toAppletParameter()
+ {
+ Map<Color, List<String>> colours = new HashMap<Color, List<String>>();
+
+ for (char symbol = 'A'; symbol <= 'Z'; symbol++)
+ {
+ String residue = String.valueOf(symbol);
+ int index = symbolIndex[symbol];
+ Color c = colors[index];
+ if (c != null && !c.equals(Color.white))
+ {
+ if (colours.get(c) == null)
+ {
+ colours.put(c, new ArrayList<String>());
+ }
+ colours.get(c).add(residue);
+ }
+ if (lowerCaseColours != null)
+ {
+ c = lowerCaseColours[index];
+ if (c != null && !c.equals(Color.white))
+ {
+ residue = residue.toLowerCase();
+ if (colours.get(c) == null)
+ {
+ colours.put(c, new ArrayList<String>());
+ }
+ colours.get(c).add(residue);
+ }
+ }
+ }
+ StringBuilder sb = new StringBuilder();
+ for (Entry<Color, List<String>> cols : colours.entrySet())
+ {
+ if (sb.length() > 0)
+ {
+ sb.append(";");
+ }
+ boolean first = true;
+ for (String residue : cols.getValue())
+ {
+ if (!first)
+ {
+ sb.append(",");
+ }
+ sb.append(residue);
+ first = false;
+ }
+ sb.append("=");
+ /*
+ * get color as hex value, dropping the alpha (ff) part
+ */
+ String hexString = Integer.toHexString(cols.getKey().getRGB())
+ .substring(2);
+ sb.append(hexString);
+ }
+
+ return sb.toString();
+ }
}
">seq0\nKKKWWWQW\n";
// @formatter:on
- @Test
+ @Test(groups = "Functional")
public void testFindColour()
{
AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(FASTA,
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceI;
+import java.awt.Color;
+
import org.testng.annotations.Test;
public class ColourSchemePropertyTest
{
- @Test
+ @Test(groups = "Functional")
public void testGetColourName()
{
SequenceI seq = new Sequence("Seq1", "abcd");
assertEquals(ColourSchemeProperty.getColourName(null), "None");
}
- @Test
+ @Test(groups = "Functional")
public void testGetColourScheme()
{
SequenceI seq = new Sequence("Seq1", "abcd");
assertNull(ColourSchemeProperty.getColourScheme(al, "none"));
// default is to convert the name into a fixed coloour
assertTrue(ColourSchemeProperty.getColourScheme(al, "elephants") instanceof UserColourScheme);
+
+ /*
+ * explicit aa colours
+ */
+ ColourSchemeI cs = ColourSchemeProperty.getColourScheme(al,
+ "R,G=red;C=blue;c=green;Q=10,20,30;S,T=11ffdd");
+ assertEquals(cs.findColour('H'), Color.white);
+ assertEquals(cs.findColour('R'), Color.red);
+ assertEquals(cs.findColour('r'), Color.red);
+ assertEquals(cs.findColour('G'), Color.red);
+ assertEquals(cs.findColour('C'), Color.blue);
+ assertEquals(cs.findColour('c'), Color.green);
+ assertEquals(cs.findColour('Q'), new Color(10, 20, 30));
+ assertEquals(cs.findColour('S'), new Color(0x11ffdd));
+ assertEquals(cs.findColour('T'), new Color(0x11ffdd));
}
}
public class JalviewColourSchemeTest
{
- @Test
+ @Test(groups = "Functional")
public void testForName()
{
assertSame(JalviewColourScheme.Clustal,
assertNull(JalviewColourScheme.forName(null));
}
- @Test
+ @Test(groups = "Functional")
public void testGetColourScheme()
{
SequenceI seq = new Sequence("Seq1", "abcd");
assertEquals(Color.WHITE, rcs.applyConservation(colour, 12));
}
- @Test
+ @Test(groups = "Functional")
public void testIsApplicableTo()
{
SequenceI pep1 = new Sequence("pep1", "APQTWLS");
assertTrue(new RNAHelicesColour(nucleotide).isApplicableTo(nucleotide));
}
- @Test
+ @Test(groups = "Functional")
public void testIsApplicableTo_dynamicColourScheme()
{
SequenceI pep1 = new Sequence("pep1", "APQTWLS");
assertEquals(c2, cs.findColour('c'));
cs = new UserColourScheme("white");
- cs.parseAppletParameter("D,E=red; K,R,H=0022FF; c=10 , 20,30;lowercase=blue;s=pink");
+ cs.parseAppletParameter("D,E=red; K,R,H=0022FF; c=10 , 20,30;t=orange;lowercase=blue;s=pink");
assertEquals(Color.RED, cs.findColour('D'));
assertEquals(Color.blue, cs.findColour('d'));
assertEquals(Color.RED, cs.findColour('E'));
assertEquals(Color.blue, cs.findColour('h'));
assertEquals(c2, cs.findColour('c'));
// 'lowercase' sets all lower-case not already set to the given colour
+ assertEquals(Color.orange, cs.findColour('t'));
assertEquals(Color.blue, cs.findColour('k'));
assertEquals(Color.blue, cs.findColour('a'));
assertEquals(Color.pink, cs.findColour('s'));
}
+
+ @Test(groups = "Functional")
+ public void testToAppletParameter()
+ {
+ UserColourScheme cs = new UserColourScheme(
+ "E,D=red; K,R,H=0022FF; c=10 , 20,30");
+ String param = cs.toAppletParameter();
+ assertEquals("H,K,R=0022ff;c=0a141e;D,E=ff0000", param);
+ }
}
assertNull(ColorUtils.parseColourString("100,200,100,200")); // too many
}
- @Test
+ @Test(groups = "Functional")
public void testGetAWTColorFromName() {
assertEquals(Color.white, ColorUtils.getAWTColorFromName("white"));
assertEquals(Color.white, ColorUtils.getAWTColorFromName("White"));