1 package jalview.schemes;
3 import static org.testng.Assert.assertEquals;
4 import static org.testng.Assert.assertNull;
5 import static org.testng.Assert.assertTrue;
7 import jalview.datamodel.Alignment;
8 import jalview.datamodel.AlignmentI;
9 import jalview.datamodel.Sequence;
10 import jalview.datamodel.SequenceI;
12 import java.awt.Color;
14 import org.testng.annotations.Test;
16 public class ColourSchemePropertyTest
18 @Test(groups = "Functional")
19 public void testGetColourName()
21 SequenceI seq = new Sequence("Seq1", "abcd");
22 AlignmentI al = new Alignment(new SequenceI[] { seq });
23 ColourSchemeI cs = new ClustalxColourScheme(al, null);
24 assertEquals(ColourSchemeProperty.getColourName(cs), "Clustal");
25 cs = new Blosum62ColourScheme();
26 assertEquals(ColourSchemeProperty.getColourName(cs), "Blosum62");
27 cs = new PIDColourScheme();
28 assertEquals(ColourSchemeProperty.getColourName(cs), "% Identity");
29 cs = new HydrophobicColourScheme();
30 assertEquals(ColourSchemeProperty.getColourName(cs), "Hydrophobic");
31 cs = new ZappoColourScheme();
32 assertEquals(ColourSchemeProperty.getColourName(cs), "Zappo");
33 cs = new TaylorColourScheme();
34 assertEquals(ColourSchemeProperty.getColourName(cs), "Taylor");
35 cs = new HelixColourScheme();
36 assertEquals(ColourSchemeProperty.getColourName(cs),
38 cs = new StrandColourScheme();
39 assertEquals(ColourSchemeProperty.getColourName(cs),
41 cs = new TurnColourScheme();
42 assertEquals(ColourSchemeProperty.getColourName(cs), "Turn Propensity");
43 cs = new BuriedColourScheme();
44 assertEquals(ColourSchemeProperty.getColourName(cs), "Buried Index");
45 cs = new NucleotideColourScheme();
46 assertEquals(ColourSchemeProperty.getColourName(cs), "Nucleotide");
47 cs = new PurinePyrimidineColourScheme();
48 assertEquals(ColourSchemeProperty.getColourName(cs),
50 cs = new TCoffeeColourScheme(al);
51 assertEquals(ColourSchemeProperty.getColourName(cs), "T-Coffee Scores");
52 cs = new RNAHelicesColour(al);
53 assertEquals(ColourSchemeProperty.getColourName(cs), "RNA Helices");
54 cs = new RNAInteractionColourScheme();
55 assertEquals(ColourSchemeProperty.getColourName(cs),
56 "RNA Interaction type");
57 cs = new UserColourScheme();
58 assertEquals(ColourSchemeProperty.getColourName(cs), "User Defined");
61 * UserColourScheme may have a bespoke name
63 ((UserColourScheme) cs).setName("stripy");
64 assertEquals(ColourSchemeProperty.getColourName(cs), "stripy");
65 ((UserColourScheme) cs).setName("");
66 assertEquals(ColourSchemeProperty.getColourName(cs), "User Defined");
67 ((UserColourScheme) cs).setName(null);
68 assertEquals(ColourSchemeProperty.getColourName(cs), "User Defined");
70 assertEquals(ColourSchemeProperty.getColourName(null), "None");
73 @Test(groups = "Functional")
74 public void testGetColourScheme()
76 SequenceI seq = new Sequence("Seq1", "abcd");
77 AlignmentI al = new Alignment(new SequenceI[] { seq });
78 // the strings here correspond to JalviewColourScheme.toString() values
79 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(al, "Clustal");
80 assertTrue(cs instanceof ClustalxColourScheme);
82 cs = ColourSchemeProperty.getColourScheme(al, "CLUSTAL");
83 assertTrue(cs instanceof ClustalxColourScheme);
84 cs = ColourSchemeProperty.getColourScheme(al, "clustal");
85 assertTrue(cs instanceof ClustalxColourScheme);
86 cs = ColourSchemeProperty.getColourScheme(al, "Blosum62");
87 assertTrue(cs instanceof Blosum62ColourScheme);
88 cs = ColourSchemeProperty.getColourScheme(al, "% Identity");
89 assertTrue(cs instanceof PIDColourScheme);
90 cs = ColourSchemeProperty.getColourScheme(al, "Zappo");
91 assertTrue(cs instanceof ZappoColourScheme);
92 cs = ColourSchemeProperty.getColourScheme(al, "Taylor");
93 assertTrue(cs instanceof TaylorColourScheme);
94 cs = ColourSchemeProperty.getColourScheme(al, "Hydrophobic");
95 assertTrue(cs instanceof HydrophobicColourScheme);
96 cs = ColourSchemeProperty.getColourScheme(al, "Helix Propensity");
97 assertTrue(cs instanceof HelixColourScheme);
98 cs = ColourSchemeProperty.getColourScheme(al, "Strand Propensity");
99 assertTrue(cs instanceof StrandColourScheme);
100 cs = ColourSchemeProperty.getColourScheme(al, "Turn Propensity");
101 assertTrue(cs instanceof TurnColourScheme);
102 cs = ColourSchemeProperty.getColourScheme(al, "Buried Index");
103 assertTrue(cs instanceof BuriedColourScheme);
104 cs = ColourSchemeProperty.getColourScheme(al, "Nucleotide");
105 assertTrue(cs instanceof NucleotideColourScheme);
106 cs = ColourSchemeProperty.getColourScheme(al, "Purine/Pyrimidine");
107 assertTrue(cs instanceof PurinePyrimidineColourScheme);
108 cs = ColourSchemeProperty.getColourScheme(al, "T-Coffee Scores");
109 assertTrue(cs instanceof TCoffeeColourScheme);
110 cs = ColourSchemeProperty.getColourScheme(al, "RNA Helices");
111 assertTrue(cs instanceof RNAHelicesColour);
112 // 'None' is a special value
113 assertNull(ColourSchemeProperty.getColourScheme(al, "None"));
114 assertNull(ColourSchemeProperty.getColourScheme(al, "none"));
115 // default is to convert the name into a fixed colour
116 cs = ColourSchemeProperty.getColourScheme(al, "elephants");
117 assertTrue(cs instanceof UserColourScheme);
120 * explicit aa colours
122 UserColourScheme ucs = (UserColourScheme) ColourSchemeProperty
124 "R,G=red;C=blue;c=green;Q=10,20,30;S,T=11ffdd");
125 assertEquals(ucs.findColour('H'), Color.white);
126 assertEquals(ucs.findColour('R'), Color.red);
127 assertEquals(ucs.findColour('r'), Color.red);
128 assertEquals(ucs.findColour('G'), Color.red);
129 assertEquals(ucs.findColour('C'), Color.blue);
130 assertEquals(ucs.findColour('c'), Color.green);
131 assertEquals(ucs.findColour('Q'), new Color(10, 20, 30));
132 assertEquals(ucs.findColour('S'), new Color(0x11ffdd));
133 assertEquals(ucs.findColour('T'), new Color(0x11ffdd));