2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.schemes;
23 import static org.testng.Assert.assertEquals;
24 import static org.testng.Assert.assertNull;
25 import static org.testng.Assert.assertTrue;
27 import jalview.datamodel.Alignment;
28 import jalview.datamodel.AlignmentI;
29 import jalview.datamodel.Sequence;
30 import jalview.datamodel.SequenceI;
32 import java.awt.Color;
34 import org.testng.annotations.Test;
36 public class ColourSchemePropertyTest
38 @Test(groups = "Functional")
39 public void testGetColourName()
41 SequenceI seq = new Sequence("Seq1", "abcd");
42 AlignmentI al = new Alignment(new SequenceI[] { seq });
43 ColourSchemeI cs = new ClustalxColourScheme(al, null);
44 assertEquals(ColourSchemeProperty.getColourName(cs), "Clustal");
45 cs = new Blosum62ColourScheme();
46 assertEquals(ColourSchemeProperty.getColourName(cs), "Blosum62");
47 cs = new PIDColourScheme();
48 assertEquals(ColourSchemeProperty.getColourName(cs), "% Identity");
49 cs = new HydrophobicColourScheme();
50 assertEquals(ColourSchemeProperty.getColourName(cs), "Hydrophobic");
51 cs = new ZappoColourScheme();
52 assertEquals(ColourSchemeProperty.getColourName(cs), "Zappo");
53 cs = new TaylorColourScheme();
54 assertEquals(ColourSchemeProperty.getColourName(cs), "Taylor");
55 cs = new HelixColourScheme();
56 assertEquals(ColourSchemeProperty.getColourName(cs),
58 cs = new StrandColourScheme();
59 assertEquals(ColourSchemeProperty.getColourName(cs),
61 cs = new TurnColourScheme();
62 assertEquals(ColourSchemeProperty.getColourName(cs), "Turn Propensity");
63 cs = new BuriedColourScheme();
64 assertEquals(ColourSchemeProperty.getColourName(cs), "Buried Index");
65 cs = new NucleotideColourScheme();
66 assertEquals(ColourSchemeProperty.getColourName(cs), "Nucleotide");
67 cs = new PurinePyrimidineColourScheme();
68 assertEquals(ColourSchemeProperty.getColourName(cs),
70 cs = new TCoffeeColourScheme(al);
71 assertEquals(ColourSchemeProperty.getColourName(cs), "T-Coffee Scores");
72 cs = new RNAHelicesColour(al);
73 assertEquals(ColourSchemeProperty.getColourName(cs), "RNA Helices");
74 cs = new RNAInteractionColourScheme();
75 assertEquals(ColourSchemeProperty.getColourName(cs),
76 "RNA Interaction type");
77 cs = new UserColourScheme();
78 assertEquals(ColourSchemeProperty.getColourName(cs), "User Defined");
81 * UserColourScheme may have a bespoke name
83 ((UserColourScheme) cs).setName("stripy");
84 assertEquals(ColourSchemeProperty.getColourName(cs), "stripy");
85 ((UserColourScheme) cs).setName("");
86 assertEquals(ColourSchemeProperty.getColourName(cs), "User Defined");
87 ((UserColourScheme) cs).setName(null);
88 assertEquals(ColourSchemeProperty.getColourName(cs), "User Defined");
90 assertEquals(ColourSchemeProperty.getColourName(null), "None");
93 @Test(groups = "Functional")
94 public void testGetColourScheme()
96 SequenceI seq = new Sequence("Seq1", "abcd");
97 AlignmentI al = new Alignment(new SequenceI[] { seq });
98 // the strings here correspond to JalviewColourScheme.toString() values
99 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(null, al,
101 assertTrue(cs instanceof ClustalxColourScheme);
102 // not case-sensitive
103 cs = ColourSchemeProperty.getColourScheme(null, al, "CLUSTAL");
104 assertTrue(cs instanceof ClustalxColourScheme);
105 cs = ColourSchemeProperty.getColourScheme(null, al, "clustal");
106 assertTrue(cs instanceof ClustalxColourScheme);
107 cs = ColourSchemeProperty.getColourScheme(null, al, "Blosum62");
108 assertTrue(cs instanceof Blosum62ColourScheme);
109 cs = ColourSchemeProperty.getColourScheme(null, al, "% Identity");
110 assertTrue(cs instanceof PIDColourScheme);
111 cs = ColourSchemeProperty.getColourScheme(null, al, "Zappo");
112 assertTrue(cs instanceof ZappoColourScheme);
113 cs = ColourSchemeProperty.getColourScheme(null, al, "Taylor");
114 assertTrue(cs instanceof TaylorColourScheme);
115 cs = ColourSchemeProperty.getColourScheme(null, al, "Hydrophobic");
116 assertTrue(cs instanceof HydrophobicColourScheme);
117 cs = ColourSchemeProperty.getColourScheme(null, al, "Helix Propensity");
118 assertTrue(cs instanceof HelixColourScheme);
119 cs = ColourSchemeProperty.getColourScheme(null, al,
120 "Strand Propensity");
121 assertTrue(cs instanceof StrandColourScheme);
122 cs = ColourSchemeProperty.getColourScheme(null, al, "Turn Propensity");
123 assertTrue(cs instanceof TurnColourScheme);
124 cs = ColourSchemeProperty.getColourScheme(null, al, "Buried Index");
125 assertTrue(cs instanceof BuriedColourScheme);
126 cs = ColourSchemeProperty.getColourScheme(null, al, "Nucleotide");
127 assertTrue(cs instanceof NucleotideColourScheme);
128 cs = ColourSchemeProperty.getColourScheme(null, al,
129 "Purine/Pyrimidine");
130 assertTrue(cs instanceof PurinePyrimidineColourScheme);
131 cs = ColourSchemeProperty.getColourScheme(null, al, "T-Coffee Scores");
132 assertTrue(cs instanceof TCoffeeColourScheme);
133 cs = ColourSchemeProperty.getColourScheme(null, al, "RNA Helices");
134 assertTrue(cs instanceof RNAHelicesColour);
135 // 'None' is a special value
136 assertNull(ColourSchemeProperty.getColourScheme(null, al, "None"));
137 assertNull(ColourSchemeProperty.getColourScheme(null, al, "none"));
138 // default is to convert the name into a fixed colour
139 cs = ColourSchemeProperty.getColourScheme(null, al, "elephants");
140 assertTrue(cs instanceof UserColourScheme);
143 * explicit aa colours
145 UserColourScheme ucs = (UserColourScheme) ColourSchemeProperty
146 .getColourScheme(null, al,
147 "R,G=red;C=blue;c=green;Q=10,20,30;S,T=11ffdd");
148 assertEquals(ucs.findColour('H'), Color.white);
149 assertEquals(ucs.findColour('R'), Color.red);
150 assertEquals(ucs.findColour('r'), Color.red);
151 assertEquals(ucs.findColour('G'), Color.red);
152 assertEquals(ucs.findColour('C'), Color.blue);
153 assertEquals(ucs.findColour('c'), Color.green);
154 assertEquals(ucs.findColour('Q'), new Color(10, 20, 30));
155 assertEquals(ucs.findColour('S'), new Color(0x11ffdd));
156 assertEquals(ucs.findColour('T'), new Color(0x11ffdd));