package jalview.schemes; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceI; import java.awt.Color; import org.testng.annotations.Test; public class ColourSchemePropertyTest { @Test(groups = "Functional") public void testGetColourName() { SequenceI seq = new Sequence("Seq1", "abcd"); AlignmentI al = new Alignment(new SequenceI[] { seq }); ColourSchemeI cs = new ClustalxColourScheme(al, null); assertEquals(ColourSchemeProperty.getColourName(cs), "Clustal"); cs = new Blosum62ColourScheme(); assertEquals(ColourSchemeProperty.getColourName(cs), "Blosum62"); cs = new PIDColourScheme(); assertEquals(ColourSchemeProperty.getColourName(cs), "% Identity"); cs = new HydrophobicColourScheme(); assertEquals(ColourSchemeProperty.getColourName(cs), "Hydrophobic"); cs = new ZappoColourScheme(); assertEquals(ColourSchemeProperty.getColourName(cs), "Zappo"); cs = new TaylorColourScheme(); assertEquals(ColourSchemeProperty.getColourName(cs), "Taylor"); cs = new HelixColourScheme(); assertEquals(ColourSchemeProperty.getColourName(cs), "Helix Propensity"); cs = new StrandColourScheme(); assertEquals(ColourSchemeProperty.getColourName(cs), "Strand Propensity"); cs = new TurnColourScheme(); assertEquals(ColourSchemeProperty.getColourName(cs), "Turn Propensity"); cs = new BuriedColourScheme(); assertEquals(ColourSchemeProperty.getColourName(cs), "Buried Index"); cs = new NucleotideColourScheme(); assertEquals(ColourSchemeProperty.getColourName(cs), "Nucleotide"); cs = new PurinePyrimidineColourScheme(); assertEquals(ColourSchemeProperty.getColourName(cs), "Purine/Pyrimidine"); cs = new TCoffeeColourScheme(al); assertEquals(ColourSchemeProperty.getColourName(cs), "T-Coffee Scores"); cs = new RNAHelicesColour(al); assertEquals(ColourSchemeProperty.getColourName(cs), "RNA Helices"); cs = new RNAInteractionColourScheme(); assertEquals(ColourSchemeProperty.getColourName(cs), "RNA Interaction type"); cs = new UserColourScheme(); assertEquals(ColourSchemeProperty.getColourName(cs), "User Defined"); /* * UserColourScheme may have a bespoke name */ ((UserColourScheme) cs).setName("stripy"); assertEquals(ColourSchemeProperty.getColourName(cs), "stripy"); ((UserColourScheme) cs).setName(""); assertEquals(ColourSchemeProperty.getColourName(cs), "User Defined"); ((UserColourScheme) cs).setName(null); assertEquals(ColourSchemeProperty.getColourName(cs), "User Defined"); assertEquals(ColourSchemeProperty.getColourName(null), "None"); } @Test(groups = "Functional") public void testGetColourScheme() { SequenceI seq = new Sequence("Seq1", "abcd"); AlignmentI al = new Alignment(new SequenceI[] { seq }); // the strings here correspond to JalviewColourScheme.toString() values assertTrue(ColourSchemeProperty.getColourScheme(al, "Clustal") instanceof ClustalxColourScheme); // not case-sensitive assertTrue(ColourSchemeProperty.getColourScheme(al, "CLUSTAL") instanceof ClustalxColourScheme); assertTrue(ColourSchemeProperty.getColourScheme(al, "clustal") instanceof ClustalxColourScheme); assertTrue(ColourSchemeProperty.getColourScheme(al, "Blosum62") instanceof Blosum62ColourScheme); assertTrue(ColourSchemeProperty.getColourScheme(al, "% Identity") instanceof PIDColourScheme); assertTrue(ColourSchemeProperty.getColourScheme(al, "Zappo") instanceof ZappoColourScheme); assertTrue(ColourSchemeProperty.getColourScheme(al, "Taylor") instanceof TaylorColourScheme); assertTrue(ColourSchemeProperty.getColourScheme(al, "Hydrophobic") instanceof HydrophobicColourScheme); assertTrue(ColourSchemeProperty.getColourScheme(al, "Helix Propensity") instanceof HelixColourScheme); assertTrue(ColourSchemeProperty .getColourScheme(al, "Strand Propensity") instanceof StrandColourScheme); assertTrue(ColourSchemeProperty.getColourScheme(al, "Turn Propensity") instanceof TurnColourScheme); assertTrue(ColourSchemeProperty.getColourScheme(al, "Buried Index") instanceof BuriedColourScheme); assertTrue(ColourSchemeProperty.getColourScheme(al, "Nucleotide") instanceof NucleotideColourScheme); assertTrue(ColourSchemeProperty .getColourScheme(al, "Purine/Pyrimidine") instanceof PurinePyrimidineColourScheme); assertTrue(ColourSchemeProperty.getColourScheme(al, "T-Coffee Scores") instanceof TCoffeeColourScheme); assertTrue(ColourSchemeProperty.getColourScheme(al, "RNA Helices") instanceof RNAHelicesColour); assertTrue(ColourSchemeProperty.getColourScheme(al, "User Defined") instanceof UserColourScheme); // 'None' is a special value assertNull(ColourSchemeProperty.getColourScheme(al, "None")); assertNull(ColourSchemeProperty.getColourScheme(al, "none")); // default is to convert the name into a fixed colour assertTrue(ColourSchemeProperty.getColourScheme(al, "elephants") instanceof UserColourScheme); /* * explicit aa colours */ UserColourScheme cs = (UserColourScheme) 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)); } }