From: gmungoc Date: Fri, 16 Dec 2016 10:43:35 +0000 (+0000) Subject: JAL-2360 getColour() renamed to getColourScheme(), handling of "None" X-Git-Tag: Release_2_10_3b1~357^2~50 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=320c96aed11f5c396a9efd9ea83b0e35f05e21e4;p=jalview.git JAL-2360 getColour() renamed to getColourScheme(), handling of "None" corrected, tests added --- diff --git a/src/jalview/appletgui/AlignViewport.java b/src/jalview/appletgui/AlignViewport.java index 4bd77b6..b025f64 100644 --- a/src/jalview/appletgui/AlignViewport.java +++ b/src/jalview/appletgui/AlignViewport.java @@ -208,8 +208,8 @@ public class AlignViewport extends AlignmentViewport implements if (colour != null) { - globalColourScheme = ColourSchemeProperty.getColour(alignment, - colour); + globalColourScheme = ColourSchemeProperty.getColourScheme( + alignment, colour); if (globalColourScheme != null) { globalColourScheme.setConsensus(hconsensus); diff --git a/src/jalview/appletgui/TreeCanvas.java b/src/jalview/appletgui/TreeCanvas.java index 69e76f1..ca9f2d8 100755 --- a/src/jalview/appletgui/TreeCanvas.java +++ b/src/jalview/appletgui/TreeCanvas.java @@ -656,7 +656,7 @@ public class TreeCanvas extends Panel implements MouseListener, } else { - cs = ColourSchemeProperty.getColour(sg, + cs = ColourSchemeProperty.getColourScheme(sg, ColourSchemeProperty.getColourName(av .getGlobalColourScheme())); } diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index 39c0a5b..c52b562 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -511,7 +511,7 @@ public class Jalview { data.replaceAll("%20", " "); - ColourSchemeI cs = ColourSchemeProperty.getColour(af + ColourSchemeI cs = ColourSchemeProperty.getColourScheme(af .getViewport().getAlignment(), data); if (cs == null) diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 53d118b..2115617 100644 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -292,7 +292,7 @@ public class AlignViewport extends AlignmentViewport implements } if (propertyValue != null) { - globalColourScheme = ColourSchemeProperty.getColour(alignment, + globalColourScheme = ColourSchemeProperty.getColourScheme(alignment, propertyValue); if (globalColourScheme instanceof UserColourScheme) diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java index 2629f0a..12e6d42 100644 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -3344,7 +3344,7 @@ public class Jalview2XML } else { - cs = ColourSchemeProperty.getColour(al, jGroup.getColour()); + cs = ColourSchemeProperty.getColourScheme(al, jGroup.getColour()); } if (cs != null) @@ -4468,7 +4468,7 @@ public class Jalview2XML } else { - cs = ColourSchemeProperty.getColour(al, view.getBgColour()); + cs = ColourSchemeProperty.getColourScheme(al, view.getBgColour()); } if (cs != null) @@ -4749,7 +4749,7 @@ public class Jalview2XML { cs = new AnnotationColourGradient( annAlignment.getAlignmentAnnotation()[i], - ColourSchemeProperty.getColour(al, + ColourSchemeProperty.getColourScheme(al, viewAnnColour.getColourScheme()), viewAnnColour.getAboveThreshold()); } diff --git a/src/jalview/gui/Jalview2XML_V1.java b/src/jalview/gui/Jalview2XML_V1.java index 52f61b1..aefc233 100755 --- a/src/jalview/gui/Jalview2XML_V1.java +++ b/src/jalview/gui/Jalview2XML_V1.java @@ -333,7 +333,7 @@ public class Jalview2XML_V1 } else { - cs = ColourSchemeProperty.getColour(al, groups[i].getColour()); + cs = ColourSchemeProperty.getColourScheme(al, groups[i].getColour()); } if (cs != null) @@ -401,7 +401,7 @@ public class Jalview2XML_V1 } else { - cs = ColourSchemeProperty.getColour(al, view.getBgColour()); + cs = ColourSchemeProperty.getColourScheme(al, view.getBgColour()); } if (cs != null) diff --git a/src/jalview/gui/TreeCanvas.java b/src/jalview/gui/TreeCanvas.java index 7acae98..8ad5699 100755 --- a/src/jalview/gui/TreeCanvas.java +++ b/src/jalview/gui/TreeCanvas.java @@ -997,7 +997,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, } else { - cs = ColourSchemeProperty.getColour(sg, + cs = ColourSchemeProperty.getColourScheme(sg, ColourSchemeProperty.getColourName(av .getGlobalColourScheme())); } diff --git a/src/jalview/io/AnnotationFile.java b/src/jalview/io/AnnotationFile.java index 1097617..f80adef 100755 --- a/src/jalview/io/AnnotationFile.java +++ b/src/jalview/io/AnnotationFile.java @@ -1624,7 +1624,7 @@ public class AnnotationFile } else if (key.equalsIgnoreCase("colour")) { - sg.cs = ColourSchemeProperty.getColour(al, value); + sg.cs = ColourSchemeProperty.getColourScheme(al, value); } else if (key.equalsIgnoreCase("pidThreshold")) { diff --git a/src/jalview/schemes/ColourSchemeProperty.java b/src/jalview/schemes/ColourSchemeProperty.java index 9b91066..425b3a1 100755 --- a/src/jalview/schemes/ColourSchemeProperty.java +++ b/src/jalview/schemes/ColourSchemeProperty.java @@ -42,7 +42,7 @@ public class ColourSchemeProperty /** * Returns a colour scheme for the given name, with which the given data may - * be coloured. The name may be one of + * be coloured. The name is not case-sensitive, and may be one of * * If none of these formats is matched, the string is converted to a colour - * using a hashing algorithm. + * using a hashing algorithm. For name "None", returns null. * * @param forData * @param name * @return */ - public static ColourSchemeI getColour(AnnotatedCollectionI forData, + public static ColourSchemeI getColourScheme(AnnotatedCollectionI forData, String name) { + if (ResidueColourScheme.NONE.equalsIgnoreCase(name)) + { + return null; + + } JalviewColourScheme scheme = JalviewColourScheme.forName(name); if (scheme != null) { - // note JalviewColourScheme.None returns null here return scheme.getColourScheme(forData); } diff --git a/test/jalview/io/Jalview2xmlTests.java b/test/jalview/io/Jalview2xmlTests.java index 434619e..af477f7 100644 --- a/test/jalview/io/Jalview2xmlTests.java +++ b/test/jalview/io/Jalview2xmlTests.java @@ -119,7 +119,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase assertSame("Didn't set T-coffee colourscheme", af.getViewport() .getGlobalColourScheme().getClass(), TCoffeeColourScheme.class); assertNotNull("Recognise T-Coffee score from string", - ColourSchemeProperty.getColour(af.getViewport() + ColourSchemeProperty.getColourScheme(af.getViewport() .getAlignment(), af.getViewport() .getGlobalColourScheme().getSchemeName())); diff --git a/test/jalview/schemes/ColourSchemePropertyTest.java b/test/jalview/schemes/ColourSchemePropertyTest.java index efea164..6fd830a 100644 --- a/test/jalview/schemes/ColourSchemePropertyTest.java +++ b/test/jalview/schemes/ColourSchemePropertyTest.java @@ -1,6 +1,8 @@ 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; @@ -65,4 +67,37 @@ public class ColourSchemePropertyTest assertEquals(ColourSchemeProperty.getColourName(null), "None"); } + + @Test + 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 coloour + assertTrue(ColourSchemeProperty.getColourScheme(al, "elephants") instanceof UserColourScheme); + } }