From b0cee3aaf7d8873910939f97b6acb217d518968d Mon Sep 17 00:00:00 2001 From: gmungoc Date: Fri, 16 Dec 2016 09:37:11 +0000 Subject: [PATCH] JAL-2360 refactoring for JalviewColourScheme enum, ColourSchemeI.getSchemeName(), isApplicableTo() --- examples/appletParameters.html | 2 +- src/jalview/appletgui/FeatureRenderer.java | 4 +- src/jalview/appletgui/TreeCanvas.java | 5 +- src/jalview/bin/Cache.java | 15 +- src/jalview/bin/JalviewLite.java | 16 +- src/jalview/ext/rbvi/chimera/ChimeraCommands.java | 13 +- src/jalview/gui/AlignFrame.java | 27 +- src/jalview/gui/ChimeraViewFrame.java | 16 +- src/jalview/gui/FeatureRenderer.java | 4 +- src/jalview/gui/Jalview2XML.java | 13 +- src/jalview/gui/PopupMenu.java | 23 +- src/jalview/gui/Preferences.java | 17 +- src/jalview/gui/TreeCanvas.java | 5 +- src/jalview/gui/UserDefinedColours.java | 12 +- src/jalview/io/AnnotationFile.java | 59 +- src/jalview/io/FeaturesFile.java | 7 +- src/jalview/io/JSONFile.java | 22 +- src/jalview/jbgui/GAlignFrame.java | 188 +----- src/jalview/schemes/AnnotationColourGradient.java | 7 + src/jalview/schemes/Blosum62ColourScheme.java | 12 + src/jalview/schemes/BuriedColourScheme.java | 12 + src/jalview/schemes/ClustalxColourScheme.java | 115 ++-- src/jalview/schemes/ColourSchemeI.java | 80 ++- src/jalview/schemes/ColourSchemeProperty.java | 610 ++------------------ src/jalview/schemes/CovariationColourScheme.java | 11 + src/jalview/schemes/FeatureColour.java | 9 +- src/jalview/schemes/FollowerColourScheme.java | 6 + src/jalview/schemes/HelixColourScheme.java | 12 + src/jalview/schemes/HydrophobicColourScheme.java | 12 + src/jalview/schemes/JalviewColourScheme.java | 204 +++++++ src/jalview/schemes/NucleotideColourScheme.java | 12 + src/jalview/schemes/PIDColourScheme.java | 6 + .../schemes/PurinePyrimidineColourScheme.java | 12 + src/jalview/schemes/RNAHelicesColour.java | 33 +- .../schemes/RNAInteractionColourScheme.java | 12 + src/jalview/schemes/ResidueColourScheme.java | 85 +++ src/jalview/schemes/ScoreColourScheme.java | 6 + src/jalview/schemes/StrandColourScheme.java | 12 + src/jalview/schemes/TCoffeeColourScheme.java | 31 + src/jalview/schemes/TaylorColourScheme.java | 12 + src/jalview/schemes/TurnColourScheme.java | 12 + src/jalview/schemes/UserColourScheme.java | 105 +--- src/jalview/schemes/ZappoColourScheme.java | 12 + src/jalview/util/ColorUtils.java | 159 +++++ .../seqfeatures/FeatureRendererModel.java | 4 +- src/jalview/ws/jws2/AADisorderClient.java | 4 +- .../ext/rbvi/chimera/ChimeraCommandsTest.java | 5 +- test/jalview/gui/AlignViewportTest.java | 4 +- test/jalview/io/Jalview2xmlTests.java | 4 +- test/jalview/schemes/ColourSchemePropertyTest.java | 68 +++ test/jalview/schemes/FeatureColourTest.java | 3 +- test/jalview/schemes/JalviewColourSchemeTest.java | 82 +++ test/jalview/schemes/ResidueColourSchemeTest.java | 155 +++++ test/jalview/schemes/UserColourSchemeTest.java | 50 -- test/jalview/util/ColorUtilsTest.java | 58 ++ 55 files changed, 1435 insertions(+), 1049 deletions(-) create mode 100644 src/jalview/schemes/JalviewColourScheme.java create mode 100644 test/jalview/schemes/ColourSchemePropertyTest.java create mode 100644 test/jalview/schemes/JalviewColourSchemeTest.java diff --git a/examples/appletParameters.html b/examples/appletParameters.html index cc95ecb..6ead5e6 100644 --- a/examples/appletParameters.html +++ b/examples/appletParameters.html @@ -114,7 +114,7 @@ the applet can be interacted with via its defaultColour One of:
Clustal, Blosum62, % Identity, Hydrophobic, Zappo, Taylor, Helix - Propensity, Strand Propensity, Turn Propensity, Buried Index, Nucleotide, T-Coffee Scores, RNA Helices + Propensity, Strand Propensity, Turn Propensity, Buried Index, Nucleotide, Purine/Pyrimidine, T-Coffee Scores, RNA Helices Default is no colour. diff --git a/src/jalview/appletgui/FeatureRenderer.java b/src/jalview/appletgui/FeatureRenderer.java index 2fca07d..67ca8e9 100644 --- a/src/jalview/appletgui/FeatureRenderer.java +++ b/src/jalview/appletgui/FeatureRenderer.java @@ -27,7 +27,7 @@ import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; import jalview.io.FeaturesFile; import jalview.schemes.FeatureColour; -import jalview.schemes.UserColourScheme; +import jalview.util.ColorUtils; import jalview.util.MessageManager; import jalview.viewmodel.AlignmentViewport; @@ -236,7 +236,7 @@ public class FeatureRenderer extends FeatureColourI col = getFeatureStyle(name.getText()); if (col == null) { - Color generatedColour = UserColourScheme + Color generatedColour = ColorUtils .createColourFromName(name.getText()); col = new FeatureColour(generatedColour); } diff --git a/src/jalview/appletgui/TreeCanvas.java b/src/jalview/appletgui/TreeCanvas.java index 8292a5a..69e76f1 100755 --- a/src/jalview/appletgui/TreeCanvas.java +++ b/src/jalview/appletgui/TreeCanvas.java @@ -656,8 +656,9 @@ public class TreeCanvas extends Panel implements MouseListener, } else { - cs = ColourSchemeProperty.getColour(sg, ColourSchemeProperty - .getColourName(av.getGlobalColourScheme())); + cs = ColourSchemeProperty.getColour(sg, + ColourSchemeProperty.getColourName(av + .getGlobalColourScheme())); } // cs is null if shading is an annotationColourGradient if (cs != null) diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index 8412dab..6b1aef9 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -22,6 +22,7 @@ package jalview.bin; import jalview.datamodel.PDBEntry; import jalview.structure.StructureImportSettings; +import jalview.util.ColorUtils; import jalview.ws.dbsources.das.api.DasSourceRegistryI; import jalview.ws.dbsources.das.datamodel.DasSourceRegistry; import jalview.ws.sifts.SiftsSettings; @@ -868,19 +869,11 @@ public class Cache { return defcolour; } - Color col = jalview.schemes.ColourSchemeProperty - .getAWTColorFromName(colprop); + Color col = ColorUtils.parseColourString(colprop); if (col == null) { - try - { - col = new jalview.schemes.UserColourScheme(colprop).findColour('A'); - } catch (Exception ex) - { - log.warn("Couldn't parse '" + colprop + "' as a colour for " - + property); - col = null; - } + log.warn("Couldn't parse '" + colprop + "' as a colour for " + + property); } return (col == null) ? defcolour : col; } diff --git a/src/jalview/bin/JalviewLite.java b/src/jalview/bin/JalviewLite.java index 9fd8a90..3ecf22b 100644 --- a/src/jalview/bin/JalviewLite.java +++ b/src/jalview/bin/JalviewLite.java @@ -51,6 +51,7 @@ import jalview.javascript.JsCallBack; import jalview.javascript.MouseOverStructureListener; import jalview.structure.SelectionListener; import jalview.structure.StructureSelectionManager; +import jalview.util.ColorUtils; import jalview.util.HttpUtils; import jalview.util.MessageManager; @@ -2883,22 +2884,13 @@ public class JalviewLite extends Applet implements { return defcolour; } - Color col = jalview.schemes.ColourSchemeProperty - .getAWTColorFromName(colprop); + Color col = ColorUtils.parseColourString(colprop); if (col == null) { - try - { - col = new jalview.schemes.UserColourScheme(colprop).findColour('A'); - } catch (Exception ex) - { - System.err.println("Couldn't parse '" + colprop - + "' as a colour for " + colparam); - col = null; - } + System.err.println("Couldn't parse '" + colprop + + "' as a colour for " + colparam); } return (col == null) ? defcolour : col; - } public void openJalviewHelpUrl() diff --git a/src/jalview/ext/rbvi/chimera/ChimeraCommands.java b/src/jalview/ext/rbvi/chimera/ChimeraCommands.java index a551ca2..8f6b2f1 100644 --- a/src/jalview/ext/rbvi/chimera/ChimeraCommands.java +++ b/src/jalview/ext/rbvi/chimera/ChimeraCommands.java @@ -35,6 +35,7 @@ import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.SortedMap; import java.util.TreeMap; /** @@ -58,7 +59,7 @@ public class ChimeraCommands SequenceI[][] sequence, SequenceRenderer sr, FeatureRenderer fr, AlignmentI alignment) { - Map>>> colourMap = buildColoursMap( + Map>>> colourMap = buildColoursMap( ssm, files, sequence, sr, fr, alignment); List colourCommands = buildColourCommands(colourMap); @@ -86,7 +87,7 @@ public class ChimeraCommands * @return */ protected static List buildColourCommands( - Map>>> colourMap) + Map>>> colourMap) { /* * This version concatenates all commands into a single String (semi-colon @@ -161,12 +162,12 @@ public class ChimeraCommands * Ordering is by order of addition (for colours and positions), natural ordering (for models and chains) * */ - protected static Map>>> buildColoursMap( + protected static Map>>> buildColoursMap( StructureSelectionManager ssm, String[] files, SequenceI[][] sequence, SequenceRenderer sr, FeatureRenderer fr, AlignmentI alignment) { - Map>>> colourMap = new LinkedHashMap>>>(); + Map>>> colourMap = new LinkedHashMap>>>(); Color lastColour = null; for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++) { @@ -251,13 +252,13 @@ public class ChimeraCommands * @param chain */ protected static void addColourRange( - Map>>> colourMap, + Map>>> colourMap, Color colour, int model, int startPos, int endPos, String chain) { /* * Get/initialize map of data for the colour */ - Map>> colourData = colourMap + SortedMap>> colourData = colourMap .get(colour); if (colourData == null) { diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 03e4534..9aed70d 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -87,7 +87,9 @@ import jalview.schemes.HydrophobicColourScheme; import jalview.schemes.NucleotideColourScheme; import jalview.schemes.PIDColourScheme; import jalview.schemes.PurinePyrimidineColourScheme; +import jalview.schemes.RNAHelicesColour; import jalview.schemes.RNAHelicesColourChooser; +import jalview.schemes.ResidueColourScheme; import jalview.schemes.ResidueProperties; import jalview.schemes.StrandColourScheme; import jalview.schemes.TCoffeeColourScheme; @@ -854,6 +856,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, conservationMenuItem.setEnabled(!nucleotide); modifyConservation.setEnabled(!nucleotide); showGroupConservation.setEnabled(!nucleotide); + + /* + * enable / disable colour schemes + * - the old, simple way (based on the nucleotide flag), or + * - the new, generic way (interrogate the colour scheme) + */ + AlignmentI al = getViewport().getAlignment(); clustalColour.setEnabled(!nucleotide); zappoColour.setEnabled(!nucleotide); taylorColour.setEnabled(!nucleotide); @@ -861,17 +870,25 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, helixColour.setEnabled(!nucleotide); strandColour.setEnabled(!nucleotide); turnColour.setEnabled(!nucleotide); - buriedColour.setEnabled(!nucleotide); + // buriedColour.setEnabled(!nucleotide); + // TODO make isApplicableTo static in ColourSchemeI in Java 8 + buriedColour.setEnabled(new BuriedColourScheme().isApplicableTo(al)); rnahelicesColour.setEnabled(nucleotide); nucleotideColour.setEnabled(nucleotide); - purinePyrimidineColour.setEnabled(nucleotide); + // purinePyrimidineColour.setEnabled(nucleotide); + purinePyrimidineColour.setEnabled(new PurinePyrimidineColourScheme() + .isApplicableTo(al)); + tcoffeeColour + .setEnabled(new TCoffeeColourScheme(al).isApplicableTo(al)); RNAInteractionColour.setEnabled(nucleotide); showComplementMenuItem.setText(nucleotide ? MessageManager .getString("label.protein") : MessageManager .getString("label.nucleotide")); + String selectedColourScheme = Cache.getDefault( nucleotide ? Preferences.DEFAULT_COLOUR_NUC - : Preferences.DEFAULT_COLOUR_PROT, "None"); + : Preferences.DEFAULT_COLOUR_PROT, + ResidueColourScheme.NONE); setColourSelected(selectedColourScheme); } @@ -935,7 +952,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, autoCalculate.setSelected(av.autoCalculateConsensus); sortByTree.setSelected(av.sortByTree); listenToViewSelections.setSelected(av.followSelection); - rnahelicesColour.setEnabled(av.getAlignment().hasRNAStructure()); + // rnahelicesColour.setEnabled(av.getAlignment().hasRNAStructure()); + rnahelicesColour.setEnabled(new RNAHelicesColour(av.getAlignment()) + .isApplicableTo(av.getAlignment())); rnahelicesColour .setSelected(av.getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour); diff --git a/src/jalview/gui/ChimeraViewFrame.java b/src/jalview/gui/ChimeraViewFrame.java index 7a8f07c..048f441 100644 --- a/src/jalview/gui/ChimeraViewFrame.java +++ b/src/jalview/gui/ChimeraViewFrame.java @@ -40,6 +40,7 @@ import jalview.schemes.PurinePyrimidineColourScheme; import jalview.schemes.StrandColourScheme; import jalview.schemes.TaylorColourScheme; import jalview.schemes.TurnColourScheme; +import jalview.schemes.UserColourScheme; import jalview.schemes.ZappoColourScheme; import jalview.structures.models.AAStructureBindingModel; import jalview.util.MessageManager; @@ -925,10 +926,19 @@ public class ChimeraViewFrame extends StructureViewerBase } @Override - public void userColour_actionPerformed(ActionEvent actionEvent) + public void userColour_actionPerformed(ActionEvent e) { - userColour.setSelected(true); - new UserDefinedColours(this, null); + if (e.getActionCommand().equals( + MessageManager.getString("action.user_defined"))) + { + new UserDefinedColours(this, null); + } + else + { + UserColourScheme udc = UserDefinedColours.getUserColourSchemes().get( + e.getActionCommand()); + jmb.setJalviewColourScheme(udc); + } } @Override diff --git a/src/jalview/gui/FeatureRenderer.java b/src/jalview/gui/FeatureRenderer.java index ae911ed..ed6a3c5 100644 --- a/src/jalview/gui/FeatureRenderer.java +++ b/src/jalview/gui/FeatureRenderer.java @@ -26,7 +26,7 @@ import jalview.datamodel.SearchResultsI; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; import jalview.schemes.FeatureColour; -import jalview.schemes.UserColourScheme; +import jalview.util.ColorUtils; import jalview.util.MessageManager; import java.awt.BorderLayout; @@ -211,7 +211,7 @@ public class FeatureRenderer extends FeatureColourI col = getFeatureStyle(name.getText()); if (col == null) { - col = new FeatureColour(UserColourScheme + col = new FeatureColour(ColorUtils .createColourFromName(name.getText())); } oldcol = fcol = col; diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java index 35db33f..2629f0a 100644 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -129,7 +129,6 @@ import java.util.jar.JarInputStream; import java.util.jar.JarOutputStream; import javax.swing.JInternalFrame; -import javax.swing.JOptionPane; import javax.swing.SwingUtilities; import org.exolab.castor.xml.Marshaller; @@ -1187,7 +1186,7 @@ public class Jalview2XML } else { - jGroup.setColour(ColourSchemeProperty.getColourName(sg.cs)); + jGroup.setColour(sg.cs.getSchemeName()); } } else if (sg.cs instanceof jalview.schemes.AnnotationColourGradient) @@ -1203,7 +1202,7 @@ public class Jalview2XML } else { - jGroup.setColour(ColourSchemeProperty.getColourName(sg.cs)); + jGroup.setColour(sg.cs.getSchemeName()); } jGroup.setPidThreshold(sg.cs.getThreshold()); @@ -1724,8 +1723,7 @@ public class Jalview2XML } else { - ac.setColourScheme(ColourSchemeProperty.getColourName(acg - .getBaseColour())); + ac.setColourScheme(ColourSchemeProperty.getColourName(acg.getBaseColour())); } ac.setMaxColour(acg.getMaxColour().getRGB()); @@ -4730,7 +4728,8 @@ public class Jalview2XML ); } - if (viewAnnColour.getColourScheme().equals("None")) + if (viewAnnColour.getColourScheme().equals( + ResidueColourScheme.NONE)) { cs = new AnnotationColourGradient( annAlignment.getAlignmentAnnotation()[i], @@ -4778,7 +4777,7 @@ public class Jalview2XML } /* - * if (viewAnnColour.getColourScheme().equals("None" )) { sg.cs = + * if (viewAnnColour.getColourScheme().equals(ResidueColourScheme.NONE)) { sg.cs = * new AnnotationColourGradient( * annAlignment.getAlignmentAnnotation()[i], new * java.awt.Color(viewAnnColour. getMinColour()), new diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index 838b534..0a133cf 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -1518,22 +1518,43 @@ public class PopupMenu extends JPopupMenu */ protected void buildColourMenu() { + SequenceGroup sg = getGroup(); colourMenu.removeAll(); colourMenu.add(textColour); colourMenu.add(noColourmenuItem); colourMenu.add(clustalColour); + // in Java 8, isApplicableTo can be a static method on the interface + clustalColour.setEnabled(new ClustalxColourScheme(sg, null) + .isApplicableTo(sg)); colourMenu.add(BLOSUM62Colour); + BLOSUM62Colour + .setEnabled(new Blosum62ColourScheme().isApplicableTo(sg)); colourMenu.add(PIDColour); + PIDColour.setEnabled(new PIDColourScheme().isApplicableTo(sg)); colourMenu.add(zappoColour); + zappoColour.setEnabled(new ZappoColourScheme().isApplicableTo(sg)); colourMenu.add(taylorColour); + taylorColour.setEnabled(new TaylorColourScheme().isApplicableTo(sg)); colourMenu.add(hydrophobicityColour); + hydrophobicityColour.setEnabled(new HydrophobicColourScheme() + .isApplicableTo(sg)); colourMenu.add(helixColour); + helixColour.setEnabled(new HelixColourScheme().isApplicableTo(sg)); colourMenu.add(strandColour); + strandColour.setEnabled(new StrandColourScheme().isApplicableTo(sg)); colourMenu.add(turnColour); + turnColour.setEnabled(new TurnColourScheme().isApplicableTo(sg)); colourMenu.add(buriedColour); + buriedColour.setEnabled(new BuriedColourScheme().isApplicableTo(sg)); colourMenu.add(nucleotideColour); + nucleotideColour.setEnabled(new NucleotideColourScheme() + .isApplicableTo(sg)); colourMenu.add(purinePyrimidineColour); + purinePyrimidineColour.setEnabled(new PurinePyrimidineColourScheme() + .isApplicableTo(sg)); colourMenu.add(tcoffeeColour); + tcoffeeColour + .setEnabled(new TCoffeeColourScheme(sg).isApplicableTo(sg)); SortedMap userColourSchemes = UserDefinedColours .getUserColourSchemes(); @@ -1556,8 +1577,8 @@ public class PopupMenu extends JPopupMenu colourMenu.add(userDefinedColour); colourMenu.addSeparator(); - colourMenu.add(abovePIDColour); colourMenu.add(conservationMenuItem); + colourMenu.add(abovePIDColour); /* * add some of these items to a ButtonGroup so their diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index 0b65c1b..4777c85 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -34,7 +34,8 @@ import jalview.io.JalviewFileChooser; import jalview.io.JalviewFileView; import jalview.jbgui.GPreferences; import jalview.jbgui.GSequenceLink; -import jalview.schemes.ColourSchemeProperty; +import jalview.schemes.JalviewColourScheme; +import jalview.schemes.ResidueColourScheme; import jalview.util.MessageManager; import jalview.util.Platform; import jalview.ws.sifts.SiftsSettings; @@ -290,12 +291,18 @@ public class Preferences extends GPreferences /* * Set Colours tab defaults */ - for (int i = ColourSchemeProperty.FIRST_COLOUR; i <= ColourSchemeProperty.LAST_COLOUR; i++) + protColour.addItem(ResidueColourScheme.NONE); + nucColour.addItem(ResidueColourScheme.NONE); + for (JalviewColourScheme cs : JalviewColourScheme.values()) { - protColour.addItem(ColourSchemeProperty.getColourName(i)); - nucColour.addItem(ColourSchemeProperty.getColourName(i)); + if (cs != JalviewColourScheme.UserDefined) + { + protColour.addItem(cs.toString()); + nucColour.addItem(cs.toString()); + } } - String oldProp = Cache.getDefault(DEFAULT_COLOUR, "None"); + String oldProp = Cache.getDefault(DEFAULT_COLOUR, + ResidueColourScheme.NONE); String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null); protColour.setSelectedItem(newProp != null ? newProp : oldProp); newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null); diff --git a/src/jalview/gui/TreeCanvas.java b/src/jalview/gui/TreeCanvas.java index 84fd82f..7acae98 100755 --- a/src/jalview/gui/TreeCanvas.java +++ b/src/jalview/gui/TreeCanvas.java @@ -997,8 +997,9 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, } else { - cs = ColourSchemeProperty.getColour(sg, ColourSchemeProperty - .getColourName(av.getGlobalColourScheme())); + cs = ColourSchemeProperty.getColour(sg, + ColourSchemeProperty.getColourName(av + .getGlobalColourScheme())); } // cs is null if shading is an annotationColourGradient if (cs != null) diff --git a/src/jalview/gui/UserDefinedColours.java b/src/jalview/gui/UserDefinedColours.java index 3b6ebfa..64e0e15 100755 --- a/src/jalview/gui/UserDefinedColours.java +++ b/src/jalview/gui/UserDefinedColours.java @@ -124,7 +124,7 @@ public class UserDefinedColours extends GUserDefinedColours implements if (oldColourScheme instanceof UserColourScheme) { - schemeName.setText(((UserColourScheme) oldColourScheme).getName()); + schemeName.setText(((UserColourScheme) oldColourScheme).getSchemeName()); if (((UserColourScheme) oldColourScheme).getLowerCaseColours() != null) { caseSensitive.setSelected(true); @@ -156,7 +156,7 @@ public class UserDefinedColours extends GUserDefinedColours implements if (oldColourScheme instanceof UserColourScheme) { - schemeName.setText(((UserColourScheme) oldColourScheme).getName()); + schemeName.setText(((UserColourScheme) oldColourScheme).getSchemeName()); } resetButtonPanel(false); @@ -632,7 +632,7 @@ public class UserDefinedColours extends GUserDefinedColours implements UserColourScheme ucs = loadColours(choice.getAbsolutePath()); Color[] colors = ucs.getColours(); - schemeName.setText(ucs.getName()); + schemeName.setText(ucs.getSchemeName()); if (ucs.getLowerCaseColours() != null) { @@ -999,7 +999,7 @@ public class UserDefinedColours extends GUserDefinedColours implements coloursFound.append("|"); } coloursFound.append(file); - userColourSchemes.put(ucs.getName(), ucs); + userColourSchemes.put(ucs.getSchemeName(), ucs); } } catch (Exception ex) { @@ -1037,14 +1037,14 @@ public class UserDefinedColours extends GUserDefinedColours implements try { UserColourScheme ucs = loadColours(file); - if (ucs != null && !ucs.getName().equals(target)) + if (ucs != null && !ucs.getSchemeName().equals(target)) { if (coloursFound.length() > 0) { coloursFound.append("|"); } coloursFound.append(file); - userColourSchemes.put(ucs.getName(), ucs); + userColourSchemes.put(ucs.getSchemeName(), ucs); } } catch (Exception ex) { diff --git a/src/jalview/io/AnnotationFile.java b/src/jalview/io/AnnotationFile.java index 82e71b5..1097617 100755 --- a/src/jalview/io/AnnotationFile.java +++ b/src/jalview/io/AnnotationFile.java @@ -33,7 +33,9 @@ import jalview.datamodel.SequenceI; import jalview.schemes.ColourSchemeI; import jalview.schemes.ColourSchemeProperty; import jalview.schemes.UserColourScheme; +import jalview.util.ColorUtils; +import java.awt.Color; import java.io.BufferedReader; import java.io.FileReader; import java.io.InputStreamReader; @@ -581,7 +583,7 @@ public class AnnotationFile if (sg.cs != null) { text.append("colour="); - text.append(ColourSchemeProperty.getColourName(sg.cs)); + text.append(sg.cs.toString()); text.append("\t"); if (sg.cs.getThreshold() != 0) { @@ -1223,29 +1225,21 @@ public class AnnotationFile Annotation parseAnnotation(String string, int graphStyle) { - boolean hasSymbols = (graphStyle == AlignmentAnnotation.NO_GRAPH); // don't - // do the - // glyph - // test - // if we - // don't - // want - // secondary - // structure + // don't do the glyph test if we don't want secondary structure + boolean hasSymbols = (graphStyle == AlignmentAnnotation.NO_GRAPH); String desc = null, displayChar = null; char ss = ' '; // secondaryStructure float value = 0; boolean parsedValue = false, dcset = false; // find colour here - java.awt.Color colour = null; + Color colour = null; int i = string.indexOf("["); int j = string.indexOf("]"); if (i > -1 && j > -1) { - UserColourScheme ucs = new UserColourScheme(); - - colour = ucs.getColourFromString(string.substring(i + 1, j)); + colour = ColorUtils.parseColourString(string.substring(i + 1, + j)); if (i > 0 && string.charAt(i - 1) == ',') { // clip the preceding comma as well @@ -1347,7 +1341,7 @@ public class AnnotationFile void colourAnnotations(AlignmentI al, String label, String colour) { - UserColourScheme ucs = new UserColourScheme(colour); + Color awtColour = ColorUtils.parseColourString(colour); Annotation[] annotations; for (int i = 0; i < al.getAlignmentAnnotation().length; i++) { @@ -1358,7 +1352,7 @@ public class AnnotationFile { if (annotations[j] != null) { - annotations[j].colour = ucs.findColour('A'); + annotations[j].colour = awtColour; } } } @@ -1428,15 +1422,22 @@ public class AnnotationFile SequenceGroup groupRef) { String group = st.nextToken(); - AlignmentAnnotation annotation = null, alannot[] = al - .getAlignmentAnnotation(); - float value = new Float(st.nextToken()).floatValue(); + AlignmentAnnotation[] alannot = al.getAlignmentAnnotation(); + String nextToken = st.nextToken(); + float value = 0f; + try + { + value = Float.valueOf(nextToken); + } catch (NumberFormatException e) + { + System.err.println("Threshold '" + nextToken + + "' invalid, setting to zero"); + } String label = st.hasMoreTokens() ? st.nextToken() : null; - java.awt.Color colour = null; + Color colour = null; if (st.hasMoreTokens()) { - UserColourScheme ucs = new UserColourScheme(st.nextToken()); - colour = ucs.findColour('A'); + colour = ColorUtils.parseColourString(st.nextToken()); } if (alannot != null) { @@ -1450,10 +1451,6 @@ public class AnnotationFile } } } - if (annotation == null) - { - return; - } } void addGroup(AlignmentI al, StringTokenizer st) @@ -1648,7 +1645,7 @@ public class AnnotationFile } else if (key.equalsIgnoreCase("outlineColour")) { - sg.setOutlineColour(new UserColourScheme(value).findColour('A')); + sg.setOutlineColour(ColorUtils.parseColourString(value)); } else if (key.equalsIgnoreCase("displayBoxes")) { @@ -1668,11 +1665,11 @@ public class AnnotationFile } else if (key.equalsIgnoreCase("textCol1")) { - sg.textColour = new UserColourScheme(value).findColour('A'); + sg.textColour = ColorUtils.parseColourString(value); } else if (key.equalsIgnoreCase("textCol2")) { - sg.textColour2 = new UserColourScheme(value).findColour('A'); + sg.textColour2 = ColorUtils.parseColourString(value); } else if (key.equalsIgnoreCase("textColThreshold")) { @@ -1681,8 +1678,8 @@ public class AnnotationFile else if (key.equalsIgnoreCase("idColour")) { // consider warning if colour doesn't resolve to a real colour - sg.setIdColour((def = new UserColourScheme(value)) - .findColour('A')); + def = new UserColourScheme(value); + sg.setIdColour(def.findColour()); } else if (key.equalsIgnoreCase("hide")) { diff --git a/src/jalview/io/FeaturesFile.java b/src/jalview/io/FeaturesFile.java index 6af0cdf..48eeee3 100755 --- a/src/jalview/io/FeaturesFile.java +++ b/src/jalview/io/FeaturesFile.java @@ -35,11 +35,12 @@ import jalview.io.gff.GffHelperBase; import jalview.io.gff.GffHelperFactory; import jalview.io.gff.GffHelperI; import jalview.schemes.FeatureColour; -import jalview.schemes.UserColourScheme; +import jalview.util.ColorUtils; import jalview.util.MapList; import jalview.util.ParseHtmlBodyAndLinks; import jalview.util.StringUtils; +import java.awt.Color; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -355,8 +356,8 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI * Perhaps an old style groups file with no colours - * synthesize a colour from the feature type */ - UserColourScheme ucs = new UserColourScheme(ft); - featureColours.put(ft, new FeatureColour(ucs.findColour('A'))); + Color colour = ColorUtils.createColourFromName(ft); + featureColours.put(ft, new FeatureColour(colour)); } SequenceFeature sf = new SequenceFeature(ft, desc, "", startPos, endPos, featureGroup); diff --git a/src/jalview/io/JSONFile.java b/src/jalview/io/JSONFile.java index 7a12076..bdd2dcb 100644 --- a/src/jalview/io/JSONFile.java +++ b/src/jalview/io/JSONFile.java @@ -46,8 +46,9 @@ import jalview.json.binding.biojson.v1.ColourSchemeMapper; import jalview.json.binding.biojson.v1.SequenceFeaturesPojo; import jalview.json.binding.biojson.v1.SequenceGrpPojo; import jalview.json.binding.biojson.v1.SequencePojo; -import jalview.schemes.ColourSchemeProperty; -import jalview.schemes.UserColourScheme; +import jalview.schemes.JalviewColourScheme; +import jalview.schemes.ResidueColourScheme; +import jalview.util.ColorUtils; import jalview.viewmodel.seqfeatures.FeaturesDisplayed; import java.awt.Color; @@ -215,10 +216,13 @@ public class JSONFile extends AlignFile implements ComplexAlignFile { // These color schemes require annotation, disable them if annotations // are not exported - if (globalColourScheme.equalsIgnoreCase("RNA Helices") - || globalColourScheme.equalsIgnoreCase("T-COFFEE SCORES")) + if (globalColourScheme + .equalsIgnoreCase(JalviewColourScheme.RNAHelices.toString()) + || globalColourScheme + .equalsIgnoreCase(JalviewColourScheme.TCoffee + .toString())) { - jsonAlignmentPojo.setGlobalColorScheme("None"); + jsonAlignmentPojo.setGlobalColorScheme(ResidueColourScheme.NONE); } } @@ -235,8 +239,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile { SequenceGrpPojo seqGrpPojo = new SequenceGrpPojo(); seqGrpPojo.setGroupName(seqGrp.getName()); - seqGrpPojo.setColourScheme(ColourSchemeProperty - .getColourName(seqGrp.cs)); + seqGrpPojo.setColourScheme(seqGrp.cs.getSchemeName()); seqGrpPojo.setColourText(seqGrp.getColourText()); seqGrpPojo.setDescription(seqGrp.getDescription()); seqGrpPojo.setDisplayBoxes(seqGrp.getDisplayBoxes()); @@ -563,7 +566,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile annotations[count] = new Annotation(displayChar, desc, ss, val); if (annot.get("colour") != null) { - Color color = UserColourScheme.getColourFromString(annot.get( + Color color = ColorUtils.parseColourString(annot.get( "colour").toString()); annotations[count].colour = color; } @@ -760,8 +763,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile } } } - globalColourScheme = ColourSchemeProperty.getColourName(viewport - .getGlobalColourScheme()); + globalColourScheme = viewport.getGlobalColourScheme().getSchemeName(); setDisplayedFeatures(viewport.getFeaturesDisplayed()); showSeqFeatures = viewport.isShowSequenceFeatures(); diff --git a/src/jalview/jbgui/GAlignFrame.java b/src/jalview/jbgui/GAlignFrame.java index 088ddfa..b38fab4 100755 --- a/src/jalview/jbgui/GAlignFrame.java +++ b/src/jalview/jbgui/GAlignFrame.java @@ -29,7 +29,8 @@ import jalview.gui.JvSwingUtils; import jalview.gui.Preferences; import jalview.gui.UserDefinedColours; import jalview.io.FileFormat; -import jalview.schemes.ColourSchemeProperty; +import jalview.schemes.JalviewColourScheme; +import jalview.schemes.ResidueColourScheme; import jalview.schemes.UserColourScheme; import jalview.util.MessageManager; import jalview.util.Platform; @@ -287,199 +288,71 @@ public class GAlignFrame extends JInternalFrame pasteMenu.setMnemonic('P'); reload.setMnemonic('R'); } - - // Map userColourSchemes = UserDefinedColours - // .getUserColourSchemes(); - // if (userColourSchemes != null) - // { - // int insertionPoint = findUserDefinedColourPosition(); - // for (String userColour : userColourSchemes.keySet()) - // { - // final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem( - // userColour); - // radioItem.setName(USER_DEFINED_COLOUR_SCHEME); - // radioItem.addMouseListener(new MouseAdapter() - // { - // @Override - // public void mousePressed(MouseEvent evt) - // { - // if (evt.isPopupTrigger()) // Mac - // { - // offerRemoval(); - // } - // } - // - // @Override - // public void mouseReleased(MouseEvent evt) - // { - // if (evt.isPopupTrigger()) // Windows - // { - // offerRemoval(); - // } - // } - // - // void offerRemoval() - // { - // radioItem.removeActionListener(radioItem.getActionListeners()[0]); - // - // int option = JvOptionPane.showInternalConfirmDialog( - // Desktop.desktop, MessageManager - // .getString("label.remove_from_default_list"), - // MessageManager - // .getString("label.remove_user_defined_colour"), - // JvOptionPane.YES_NO_OPTION); - // if (option == JvOptionPane.YES_OPTION) - // { - // UserDefinedColours.removeColourFromDefaults(radioItem - // .getText()); - // colourMenu.remove(radioItem); - // } - // else - // { - // radioItem.addActionListener(new ActionListener() - // { - // @Override - // public void actionPerformed(ActionEvent evt) - // { - // userDefinedColour_actionPerformed(evt); - // } - // }); - // } - // } - // }); - // radioItem.addActionListener(new ActionListener() - // { - // @Override - // public void actionPerformed(ActionEvent evt) - // { - // userDefinedColour_actionPerformed(evt); - // } - // }); - // colourMenu.insert(radioItem, insertionPoint); - // insertionPoint++; - // colours.add(radioItem); - // } - // } - // - // /* - // * add colours to a ButtonGroup to make their - // * selection mutually exclusive - // */ - // colours.add(noColourmenuItem); - // colours.add(clustalColour); - // colours.add(zappoColour); - // colours.add(taylorColour); - // colours.add(hydrophobicityColour); - // colours.add(helixColour); - // colours.add(strandColour); - // colours.add(turnColour); - // colours.add(buriedColour); - // colours.add(userDefinedColour); - // colours.add(PIDColour); - // colours.add(BLOSUM62Colour); - // colours.add(nucleotideColour); - // colours.add(purinePyrimidineColour); - // // colours.add(covariationColour); - // colours.add(tcoffeeColour); - // colours.add(RNAInteractionColour); - // setColourSelected(Cache.getDefault(Preferences.DEFAULT_COLOUR, "None")); } public void setColourSelected(String defaultColour) { - - if (defaultColour != null) + JalviewColourScheme scheme = JalviewColourScheme.forName(defaultColour); + if (scheme == null) + { + noColourmenuItem.setSelected(true); + return; + } + switch (scheme) { - int index = ColourSchemeProperty - .getColourIndexFromName(defaultColour); - switch (index) - { - case ColourSchemeProperty.CLUSTAL: + case Clustal: clustalColour.setSelected(true); - break; - - case ColourSchemeProperty.BLOSUM: + case Blosum62: BLOSUM62Colour.setSelected(true); - break; - - case ColourSchemeProperty.PID: + case PID: PIDColour.setSelected(true); - break; - - case ColourSchemeProperty.ZAPPO: + case Zappo: zappoColour.setSelected(true); - break; - - case ColourSchemeProperty.TAYLOR: + case Taylor: taylorColour.setSelected(true); break; - - case ColourSchemeProperty.HYDROPHOBIC: + case Hydrophobic: hydrophobicityColour.setSelected(true); - break; - - case ColourSchemeProperty.HELIX: + case Helix: helixColour.setSelected(true); - break; - - case ColourSchemeProperty.STRAND: + case Strand: strandColour.setSelected(true); - break; - - case ColourSchemeProperty.TURN: + case Turn: turnColour.setSelected(true); - break; - - case ColourSchemeProperty.BURIED: + case Buried: buriedColour.setSelected(true); - break; - - case ColourSchemeProperty.NUCLEOTIDE: + case Nucleotide: nucleotideColour.setSelected(true); - break; - - case ColourSchemeProperty.TCOFFEE: + case TCoffee: tcoffeeColour.setSelected(true); break; - - case ColourSchemeProperty.PURINEPYRIMIDINE: + case PurinePyrimidine: purinePyrimidineColour.setSelected(true); - - break; - - case ColourSchemeProperty.RNAINTERACTION: - RNAInteractionColour.setSelected(true); - break; - /* - * case ColourSchemeProperty.COVARIATION: - * covariationColour.setSelected(true); - * - * break; - */ - case ColourSchemeProperty.USER_DEFINED: + // case RNAInteraction: + // RNAInteractionColour.setSelected(true); + // break; + case RNAHelices: + rnahelicesColour.setSelected(true); + break; + case UserDefined: userDefinedColour.setSelected(true); - break; - case ColourSchemeProperty.NONE: default: noColourmenuItem.setSelected(true); break; - } - } - } private void jbInit() throws Exception @@ -2276,7 +2149,8 @@ public class GAlignFrame extends JInternalFrame // colours.add(covariationColour); colours.add(tcoffeeColour); colours.add(RNAInteractionColour); - setColourSelected(Cache.getDefault(Preferences.DEFAULT_COLOUR, "None")); + setColourSelected(Cache.getDefault(Preferences.DEFAULT_COLOUR, + ResidueColourScheme.NONE)); } diff --git a/src/jalview/schemes/AnnotationColourGradient.java b/src/jalview/schemes/AnnotationColourGradient.java index 89b8f07..466a216 100755 --- a/src/jalview/schemes/AnnotationColourGradient.java +++ b/src/jalview/schemes/AnnotationColourGradient.java @@ -250,6 +250,7 @@ public class AnnotationColourGradient extends FollowerColourScheme * * @return DOCUMENT ME! */ + @Override public Color findColour(char c) { return Color.red; @@ -419,4 +420,10 @@ public class AnnotationColourGradient extends FollowerColourScheme { seqAssociated = sassoc; } + + @Override + public String getSchemeName() + { + return "Annotation"; + } } diff --git a/src/jalview/schemes/Blosum62ColourScheme.java b/src/jalview/schemes/Blosum62ColourScheme.java index c47f171..83a3cd6 100755 --- a/src/jalview/schemes/Blosum62ColourScheme.java +++ b/src/jalview/schemes/Blosum62ColourScheme.java @@ -107,4 +107,16 @@ public class Blosum62ColourScheme extends ResidueColourScheme ColourSchemeI newcs = super.applyTo(sg, hiddenRepSequences); return newcs; } + + @Override + public boolean isPeptideSpecific() + { + return true; + } + + @Override + public String getSchemeName() + { + return JalviewColourScheme.Blosum62.toString(); + } } diff --git a/src/jalview/schemes/BuriedColourScheme.java b/src/jalview/schemes/BuriedColourScheme.java index 4a850f0..6b07abd 100755 --- a/src/jalview/schemes/BuriedColourScheme.java +++ b/src/jalview/schemes/BuriedColourScheme.java @@ -52,4 +52,16 @@ public class BuriedColourScheme extends ScoreColourScheme { return new Color(0, (float) (1.0 - c), c); } + + @Override + public boolean isPeptideSpecific() + { + return true; + } + + @Override + public String getSchemeName() + { + return JalviewColourScheme.Buried.toString(); + } } diff --git a/src/jalview/schemes/ClustalxColourScheme.java b/src/jalview/schemes/ClustalxColourScheme.java index 33bd0d9..7ff1c65 100755 --- a/src/jalview/schemes/ClustalxColourScheme.java +++ b/src/jalview/schemes/ClustalxColourScheme.java @@ -25,7 +25,6 @@ import jalview.datamodel.SequenceCollectionI; import jalview.datamodel.SequenceI; import java.awt.Color; -import java.util.HashMap; import java.util.List; import java.util.Map; @@ -39,10 +38,32 @@ public class ClustalxColourScheme extends ResidueColourScheme private static final int SIXTY = 60; - /* - * Map from conventional colour names to Clustal version of the same - */ - private static Map colhash = new HashMap(); + enum ClustalColour + { + RED(0.9f, 0.2f, 0.1f), BLUE(0.5f, 0.7f, 0.9f), GREEN(0.1f, 0.8f, 0.1f), + ORANGE(0.9f, 0.6f, 0.3f), CYAN(0.1f, 0.7f, 0.7f), + PINK(0.9f, 0.5f, 0.5f), MAGENTA(0.8f, 0.3f, 0.8f), YELLOW(0.8f, 0.8f, + 0.0f); + + final Color colour; + + ClustalColour(float r, float g, float b) + { + colour = new Color(r, g, b); + } + } + private class ConsensusColour + { + Consensus[] cons; + + Color c; + + public ConsensusColour(ClustalColour col, Consensus[] conses) + { + this.cons = conses; + this.c = col.colour; + } + } private int[][] cons2; @@ -56,18 +77,6 @@ public class ClustalxColourScheme extends ResidueColourScheme private boolean includeGaps = true; - static - { - colhash.put(Color.RED, new Color(0.9f, 0.2f, 0.1f)); - colhash.put(Color.BLUE, new Color(0.5f, 0.7f, 0.9f)); - colhash.put(Color.GREEN, new Color(0.1f, 0.8f, 0.1f)); - colhash.put(Color.ORANGE, new Color(0.9f, 0.6f, 0.3f)); - colhash.put(Color.CYAN, new Color(0.1f, 0.7f, 0.7f)); - colhash.put(Color.PINK, new Color(0.9f, 0.5f, 0.5f)); - colhash.put(Color.MAGENTA, new Color(0.8f, 0.3f, 0.8f)); - colhash.put(Color.YELLOW, new Color(0.8f, 0.8f, 0.0f)); - } - public ClustalxColourScheme(AnnotatedCollectionI alignment, Map hiddenReps) { @@ -84,29 +93,15 @@ public class ClustalxColourScheme extends ResidueColourScheme includeGaps = isIncludeGaps(); // does nothing - TODO replace with call to // get the current setting of the // includeGaps param. - int start = 0; - - // Initialize the array - for (int j = 0; j < 24; j++) - { - for (int i = 0; i < maxWidth; i++) - { - cons2[i][j] = 0; - } - } - - int res; - int i; - int j = 0; - char[] seq; + int res = 0; for (SequenceI sq : seqs) { - seq = sq.getSequence(); + char[] seq = sq.getSequence(); int end_j = seq.length - 1; - for (i = start; i <= end_j; i++) + for (int i = 0; i <= end_j; i++) { if ((seq.length - 1) < i) { @@ -116,18 +111,15 @@ public class ClustalxColourScheme extends ResidueColourScheme { res = ResidueProperties.aaIndex[seq[i]]; } - cons2[i][res]++; } - - j++; } this.size = seqs.size(); makeColours(); } - public void makeColours() + void makeColours() { conses[0] = new Consensus("WLVIMAFCYHP", SIXTY); conses[1] = new Consensus("WLVIMAFCYHP", EIGHTY); @@ -168,15 +160,15 @@ public class ClustalxColourScheme extends ResidueColourScheme Consensus[] tmp8 = new Consensus[1]; tmp8[0] = conses[30]; // G - colours[7] = new ConsensusColour(colhash.get(Color.ORANGE), tmp8); + colours[7] = new ConsensusColour(ClustalColour.ORANGE, tmp8); Consensus[] tmp9 = new Consensus[1]; tmp9[0] = conses[31]; // P - colours[8] = new ConsensusColour(colhash.get(Color.YELLOW), tmp9); + colours[8] = new ConsensusColour(ClustalColour.YELLOW, tmp9); Consensus[] tmp10 = new Consensus[1]; tmp10[0] = conses[27]; // C - colours[9] = new ConsensusColour(colhash.get(Color.PINK), tmp8); + colours[9] = new ConsensusColour(ClustalColour.PINK, tmp8); Consensus[] tmp1 = new Consensus[14]; tmp1[0] = conses[0]; // % @@ -193,9 +185,9 @@ public class ClustalxColourScheme extends ResidueColourScheme tmp1[11] = conses[25]; // Y tmp1[12] = conses[18]; // P tmp1[13] = conses[19]; // p - colours[0] = new ConsensusColour(colhash.get(Color.BLUE), tmp1); + colours[0] = new ConsensusColour(ClustalColour.BLUE, tmp1); - colours[10] = new ConsensusColour(colhash.get(Color.CYAN), tmp1); + colours[10] = new ConsensusColour(ClustalColour.CYAN, tmp1); Consensus[] tmp2 = new Consensus[5]; tmp2[0] = conses[8]; // t @@ -203,14 +195,14 @@ public class ClustalxColourScheme extends ResidueColourScheme tmp2[2] = conses[22]; // T tmp2[3] = conses[0]; // % tmp2[4] = conses[1]; // # - colours[1] = new ConsensusColour(colhash.get(Color.GREEN), tmp2); + colours[1] = new ConsensusColour(ClustalColour.GREEN, tmp2); Consensus[] tmp3 = new Consensus[3]; tmp3[0] = conses[17]; // N tmp3[1] = conses[29]; // D tmp3[2] = conses[5]; // n - colours[2] = new ConsensusColour(colhash.get(Color.GREEN), tmp3); + colours[2] = new ConsensusColour(ClustalColour.GREEN, tmp3); Consensus[] tmp4 = new Consensus[6]; tmp4[0] = conses[6]; // q = QE @@ -219,14 +211,14 @@ public class ClustalxColourScheme extends ResidueColourScheme tmp4[3] = conses[3]; // + tmp4[4] = conses[28]; // K tmp4[5] = conses[20]; // R - colours[3] = new ConsensusColour(colhash.get(Color.GREEN), tmp4); + colours[3] = new ConsensusColour(ClustalColour.GREEN, tmp4); Consensus[] tmp5 = new Consensus[4]; tmp5[0] = conses[3]; // + tmp5[1] = conses[28]; // K tmp5[2] = conses[20]; // R tmp5[3] = conses[19]; // Q - colours[4] = new ConsensusColour(colhash.get(Color.RED), tmp5); + colours[4] = new ConsensusColour(ClustalColour.RED, tmp5); Consensus[] tmp6 = new Consensus[6]; tmp6[0] = conses[3]; // - @@ -235,7 +227,7 @@ public class ClustalxColourScheme extends ResidueColourScheme tmp6[3] = conses[6]; // QE tmp6[4] = conses[19]; // Q tmp6[5] = conses[2]; // DE - colours[5] = new ConsensusColour(colhash.get(Color.MAGENTA), tmp6); + colours[5] = new ConsensusColour(ClustalColour.MAGENTA, tmp6); Consensus[] tmp7 = new Consensus[5]; tmp7[0] = conses[3]; // - @@ -243,7 +235,7 @@ public class ClustalxColourScheme extends ResidueColourScheme tmp7[2] = conses[10]; // E tmp7[3] = conses[17]; // N tmp7[4] = conses[2]; // DE - colours[6] = new ConsensusColour(colhash.get(Color.MAGENTA), tmp7); + colours[6] = new ConsensusColour(ClustalColour.MAGENTA, tmp7); // Now attach the ConsensusColours to the residue letters residueColour = new ConsensusColour[20]; @@ -295,9 +287,9 @@ public class ClustalxColourScheme extends ResidueColourScheme return currentColour; } - for (int k = 0; k < residueColour[i].conses.length; k++) + for (int k = 0; k < residueColour[i].cons.length; k++) { - if (residueColour[i].conses[k].isConserved(cons2, j, size, + if (residueColour[i].cons[k].isConserved(cons2, j, size, includeGaps)) { currentColour = residueColour[i].c; @@ -308,7 +300,7 @@ public class ClustalxColourScheme extends ResidueColourScheme { if (conses[27].isConserved(cons2, j, size, includeGaps)) { - currentColour = colhash.get(Color.PINK); + currentColour = ClustalColour.PINK.colour; } } @@ -346,19 +338,16 @@ public class ClustalxColourScheme extends ResidueColourScheme css.includeGaps = includeGaps; return css; } -} - -class ConsensusColour -{ - Consensus[] conses; - - Color c; - public ConsensusColour(Color c, Consensus[] conses) + @Override + public boolean isPeptideSpecific() { - this.conses = conses; + return true; + } - // this.list = list; - this.c = c; + @Override + public String getSchemeName() + { + return JalviewColourScheme.Clustal.toString(); } } diff --git a/src/jalview/schemes/ColourSchemeI.java b/src/jalview/schemes/ColourSchemeI.java index fb86888..f2e888e 100755 --- a/src/jalview/schemes/ColourSchemeI.java +++ b/src/jalview/schemes/ColourSchemeI.java @@ -20,6 +20,7 @@ */ package jalview.schemes; +import jalview.analysis.Conservation; import jalview.datamodel.AnnotatedCollectionI; import jalview.datamodel.ProfilesI; import jalview.datamodel.SequenceCollectionI; @@ -31,82 +32,94 @@ import java.util.Map; public interface ColourSchemeI { /** + * Returns the fixed colour for the colour scheme. For use when the colour + * does not vary. + * + * @return + */ + Color findColour(); + + /** + * Returns the colour for the given character. For use when the colour depends + * only on the symbol. * * @param c - * @return the colour for the given character + * @return */ Color findColour(char c); /** + * Returns the possibly context dependent colour for the given symbol at the + * aligned position in the given sequence. For example, the colour may depend + * on the symbol's relationship to the consensus residue for the column. * - * @param c - * - sequence symbol or gap - * @param j - * - position in seq + * @param symbol + * @param position * @param seq - * - sequence being coloured - * @return context dependent colour for the given symbol at the position in - * the given sequence + * @return */ - Color findColour(char c, int j, SequenceI seq); + Color findColour(char symbol, int position, SequenceI seq); /** - * assign the given consensus profile for the colourscheme + * Assigns the given consensus profile for the colourscheme */ void setConsensus(ProfilesI hconsensus); /** - * assign the given conservation to the colourscheme + * Assigns the given conservation to the colourscheme * * @param c */ - void setConservation(jalview.analysis.Conservation c); + void setConservation(Conservation c); /** - * enable or disable conservation shading for this colourscheme + * Enable or disable conservation shading for this colourscheme * * @param conservationApplied */ void setConservationApplied(boolean conservationApplied); /** + * Answers true if conservation shading is enabled for this colourscheme * - * @return true if conservation shading is enabled for this colourscheme + * @return */ boolean conservationApplied(); /** - * set scale factor for bleaching of colour in unconserved regions + * Sets the scale factor for bleaching of colour in unconserved regions * * @param i */ void setConservationInc(int i); /** + * Returns the scale factor for bleaching colour in unconserved regions * - * @return scale factor for bleaching colour in unconserved regions + * @return */ int getConservationInc(); /** + * Returns the percentage identity threshold for applying colourscheme * - * @return percentage identity threshold for applying colourscheme + * @return */ int getThreshold(); /** - * set percentage identity threshold and type of %age identity calculation for - * shading + * Sets the percentage identity threshold and type of %age identity + * calculation for shading * - * @param ct + * @param pct * 0..100 percentage identity for applying this colourscheme * @param ignoreGaps * when true, calculate PID without including gapped positions */ - void setThreshold(int ct, boolean ignoreGaps); + void setThreshold(int pct, boolean ignoreGaps); /** - * recalculate dependent data using the given sequence collection, taking + * Recalculate dependent data using the given sequence collection, taking * account of hidden rows * * @param alignment @@ -116,8 +129,8 @@ public interface ColourSchemeI Map hiddenReps); /** - * create a new instance of the colourscheme configured to colour the given - * connection + * Creates and returns a new instance of the colourscheme configured to colour + * the given connection * * @param sg * @param hiddenRepSequences @@ -125,4 +138,23 @@ public interface ColourSchemeI */ ColourSchemeI applyTo(AnnotatedCollectionI sg, Map hiddenRepSequences); + + /** + * Answers true if the colour scheme is suitable for the given data, else + * false. For example, some colour schemes are specific to either peptide or + * nucleotide, or only apply if certain kinds of annotation are present. + * + * @param ac + * @return + */ + // TODO can make this method static in Java 8 + boolean isApplicableTo(AnnotatedCollectionI ac); + + /** + * Answers the 'official' name of the colour scheme (as used, for example, as + * a Jalview startup parameter) + * + * @return + */ + String getSchemeName(); } diff --git a/src/jalview/schemes/ColourSchemeProperty.java b/src/jalview/schemes/ColourSchemeProperty.java index 0da773b..9b91066 100755 --- a/src/jalview/schemes/ColourSchemeProperty.java +++ b/src/jalview/schemes/ColourSchemeProperty.java @@ -21,6 +21,7 @@ package jalview.schemes; import jalview.datamodel.AnnotatedCollectionI; +import jalview.util.ColorUtils; import java.awt.Color; @@ -38,566 +39,72 @@ import java.awt.Color; */ public class ColourSchemeProperty { - /** Undefined Colourscheme Index */ - public static final int UNDEFINED = -1; - - /** for schemes defined on the fly */ - public static final int USER_DEFINED = 0; - - /** No Colourscheme Index */ - public static final int NONE = 1; - - /** DOCUMENT ME!! */ - public static final int CLUSTAL = 2; - - /** DOCUMENT ME!! */ - public static final int BLOSUM = 3; - - /** DOCUMENT ME!! */ - public static final int PID = 4; - - /** DOCUMENT ME!! */ - public static final int ZAPPO = 5; - - /** DOCUMENT ME!! */ - public static final int TAYLOR = 6; - - /** DOCUMENT ME!! */ - public static final int HYDROPHOBIC = 7; - - /** DOCUMENT ME!! */ - public static final int HELIX = 8; - - /** DOCUMENT ME!! */ - public static final int STRAND = 9; - - /** DOCUMENT ME!! */ - public static final int TURN = 10; - - /** DOCUMENT ME!! */ - public static final int BURIED = 11; - - /** DOCUMENT ME!! */ - public static final int NUCLEOTIDE = 12; /** - * purine/pyrimidine - */ - public static final int PURINEPYRIMIDINE = 13; - - public static final int COVARIATION = 14; - - public static final int TCOFFEE = 15; - - public static final int RNAHELIX = 16; - - public static final int RNAINTERACTION = 17; - - /** - * index of first colourscheme (includes 'None') - */ - public static final int FIRST_COLOUR = NONE; - - public static final int LAST_COLOUR = RNAINTERACTION; - - /** - * DOCUMENT ME! + * Returns a colour scheme for the given name, with which the given data may + * be coloured. The name may be one of + *
    + *
  • Clustal
  • + *
  • Blosum62
  • + *
  • % Identity
  • + *
  • Hydrophobic
  • + *
  • Zappo
  • + *
  • Taylor
  • + *
  • Helix Propensity
  • + *
  • Strand Propensity
  • + *
  • Turn Propensity
  • + *
  • Buried Index
  • + *
  • Nucleotide
  • + *
  • Purine/Pyrimidine
  • + *
  • T-Coffee Scores
  • + *
  • RNA Helices
  • + *
  • User Defined
  • + *
  • None
  • + *
  • an AWT colour name e.g. red
  • + *
  • residue colours list e.g. D,E=red;K,R,H=0022FF;c=yellow
  • + *
+ * If none of these formats is matched, the string is converted to a colour + * using a hashing algorithm. * + * @param forData * @param name - * DOCUMENT ME! - * - * @return DOCUMENT ME! + * @return */ - public static int getColourIndexFromName(String name) + public static ColourSchemeI getColour(AnnotatedCollectionI forData, + String name) { - int ret = UNDEFINED; - - if (name.equalsIgnoreCase("Clustal")) - { - ret = CLUSTAL; - } - else if (name.equalsIgnoreCase("Blosum62")) - { - ret = BLOSUM; - } - else if (name.equalsIgnoreCase("% Identity")) - { - ret = PID; - } - else if (name.equalsIgnoreCase("Zappo")) - { - ret = ZAPPO; - } - else if (name.equalsIgnoreCase("Taylor")) - { - ret = TAYLOR; - } - else if (name.equalsIgnoreCase("Hydrophobic")) - { - ret = HYDROPHOBIC; - } - else if (name.equalsIgnoreCase("Helix Propensity")) - { - ret = HELIX; - } - else if (name.equalsIgnoreCase("Strand Propensity")) - { - ret = STRAND; - } - else if (name.equalsIgnoreCase("Turn Propensity")) - { - ret = TURN; - } - else if (name.equalsIgnoreCase("Buried Index")) - { - ret = BURIED; - } - else if (name.equalsIgnoreCase("Nucleotide")) - { - ret = NUCLEOTIDE; - } - else if (name.equalsIgnoreCase("T-Coffee Scores")) - { - ret = TCOFFEE; - } - - else if (name.equalsIgnoreCase("User Defined")) + JalviewColourScheme scheme = JalviewColourScheme.forName(name); + if (scheme != null) { - ret = USER_DEFINED; + // note JalviewColourScheme.None returns null here + return scheme.getColourScheme(forData); } - else if (name.equalsIgnoreCase("None")) - { - ret = NONE; - } - else if (name.equalsIgnoreCase("Purine/Pyrimidine")) - { - ret = PURINEPYRIMIDINE; - } - else if (name.equalsIgnoreCase("RNA Interaction type")) - { - ret = RNAINTERACTION; - } - else if (name.equalsIgnoreCase("RNA Helices")) - { - ret = RNAHELIX; - } - // else if (name.equalsIgnoreCase("Covariation")) - // { - // ret = COVARIATION; - // } - - return ret; - } - /** - * DOCUMENT ME! - * - * @param cs - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public static String getColourName(ColourSchemeI cs) - { - - int index = NONE; - - if (cs instanceof ClustalxColourScheme) - { - index = CLUSTAL; - } - else if (cs instanceof Blosum62ColourScheme) - { - index = BLOSUM; - } - else if (cs instanceof PIDColourScheme) - { - index = PID; - } - else if (cs instanceof ZappoColourScheme) - { - index = ZAPPO; - } - else if (cs instanceof TaylorColourScheme) + if (name.indexOf('=') == -1) { - index = TAYLOR; + /* + * 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); } - else if (cs instanceof HydrophobicColourScheme) - { - index = HYDROPHOBIC; - } - else if (cs instanceof HelixColourScheme) - { - index = HELIX; - } - else if (cs instanceof StrandColourScheme) - { - index = STRAND; - } - else if (cs instanceof TurnColourScheme) - { - index = TURN; - } - else if (cs instanceof BuriedColourScheme) - { - index = BURIED; - } - else if (cs instanceof NucleotideColourScheme) - { - index = NUCLEOTIDE; - } - else if (cs instanceof PurinePyrimidineColourScheme) - { - index = PURINEPYRIMIDINE; - } - else if (cs instanceof TCoffeeColourScheme) - { - index = TCOFFEE; - } - else if (cs instanceof RNAHelicesColour) - { - index = RNAHELIX; - } - /* - * else if (cs instanceof CovariationColourScheme) { index = COVARIATION; } - */ - else if (cs instanceof UserColourScheme) - { - if ((((UserColourScheme) cs).getName() != null) - && (((UserColourScheme) cs).getName().length() > 0)) - { - return ((UserColourScheme) cs).getName(); - } - // get default colourscheme name - index = USER_DEFINED; - } - - return getColourName(index); - } - - /** - * DOCUMENT ME! - * - * @param index - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public static String getColourName(int index) - { - String ret = null; - - switch (index) - { - case CLUSTAL: - ret = "Clustal"; - - break; - - case BLOSUM: - ret = "Blosum62"; - - break; - - case PID: - ret = "% Identity"; - - break; - - case ZAPPO: - ret = "Zappo"; - - break; - - case TAYLOR: - ret = "Taylor"; - break; - - case HYDROPHOBIC: - ret = "Hydrophobic"; - - break; - - case HELIX: - ret = "Helix Propensity"; - - break; - - case STRAND: - ret = "Strand Propensity"; - - break; - - case TURN: - ret = "Turn Propensity"; - - break; - - case BURIED: - ret = "Buried Index"; - - break; - - case NUCLEOTIDE: - ret = "Nucleotide"; - - break; - - case PURINEPYRIMIDINE: - ret = "Purine/Pyrimidine"; - break; - - case TCOFFEE: - ret = "T-Coffee Scores"; - - break; - - case RNAINTERACTION: - ret = "RNA Interaction type"; - - break; - case RNAHELIX: - ret = "RNA Helices"; - - break; /* - * case COVARIATION: ret = "Covariation"; - * - * break; + * try to parse the string as a residues colour scheme + * e.g. A=red;T,G=blue etc */ - case USER_DEFINED: - ret = "User Defined"; - - break; - - default: - ret = "None"; - - break; - } - - return ret; - } - - /** - * retrieve or create colourscheme associated with name - * - * @param seqs - * sequences to colour - * @param width - * range of sequences to colour - * @param name - * colourscheme name, applet colour parameter specification, or - * string to parse as colour for new coloursheme - * @return Valid Colourscheme - */ - public static ColourSchemeI getColour(AnnotatedCollectionI alignment, - String name) - { - int colindex = getColourIndexFromName(name); - if (colindex == UNDEFINED) - { - if (name.indexOf('=') == -1) - { - // try to build a colour from the string directly - try - { - return new UserColourScheme(name); - } catch (Exception e) - { - // System.err.println("Ignoring unknown colourscheme name"); - } - } - else - { - // try to parse the string as a residue colourscheme - try - { - // fix the launchApp user defined coloursheme transfer bug - UserColourScheme ucs = new UserColourScheme("white"); - ucs.parseAppletParameter(name); - - } catch (Exception e) - { - // System.err.println("Ignoring exception when parsing colourscheme as applet-parameter"); - } - } - } - return getColour(alignment, colindex); - } - - /** - * Construct an instance of ColourSchemeI corresponding to the given - * colourscheme index - * - * @param seqs - * sequences to be coloured by colourscheme - * @param width - * geometry of alignment - * @param index - * colourscheme number - * - * @return null or an instance of the colourscheme configured to colour given - * sequence set - */ - public static ColourSchemeI getColour( - jalview.datamodel.AnnotatedCollectionI coll, int index) - { - // TODO 3.0 2.8 refactor signature to take an alignmentI like container so - // colourschemes based on annotation can be initialised - ColourSchemeI cs = null; - - switch (index) + UserColourScheme ucs = null; + try { - case CLUSTAL: - cs = new ClustalxColourScheme(coll, null); - - break; - - case BLOSUM: - cs = new Blosum62ColourScheme(); - - break; - - case PID: - cs = new PIDColourScheme(); - - break; - - case ZAPPO: - cs = new ZappoColourScheme(); - - break; - - case TAYLOR: - cs = new TaylorColourScheme(); - break; - - case HYDROPHOBIC: - cs = new HydrophobicColourScheme(); - - break; - - case HELIX: - cs = new HelixColourScheme(); - - break; - - case STRAND: - cs = new StrandColourScheme(); - - break; - - case TURN: - cs = new TurnColourScheme(); - - break; - - case BURIED: - cs = new BuriedColourScheme(); - - break; - - case NUCLEOTIDE: - cs = new NucleotideColourScheme(); - - break; - - case PURINEPYRIMIDINE: - cs = new PurinePyrimidineColourScheme(); - - break; - - case TCOFFEE: - cs = new TCoffeeColourScheme(coll); - break; - - case RNAHELIX: - cs = new RNAHelicesColour(coll); - break; - - // case COVARIATION: - // cs = new CovariationColourScheme(annotation); - // break; - - case USER_DEFINED: - Color[] col = new Color[24]; - for (int i = 0; i < 24; i++) - { - col[i] = Color.white; - } - cs = new UserColourScheme(col); - break; - - default: - break; - } - - return cs; - } - - /** - * Returns the Color constant for a given colour name e.g. "pink", or null if - * the name is not recognised - * - * @param name - * @return - */ - public static Color getAWTColorFromName(String name) - { - if (name == null) + // fix the launchApp user defined colourscheme transfer bug + ucs = new UserColourScheme("white"); + ucs.parseAppletParameter(name); + } catch (Exception e) { - return null; + // System.err.println("Ignoring exception when parsing colourscheme as applet-parameter"); } - Color col = null; - name = name.toLowerCase(); - - // or make a static map; or use reflection on the field name - switch (name) - { - case "black": - col = Color.black; - break; - case "blue": - col = Color.blue; - break; - case "cyan": - col = Color.cyan; - break; - case "darkgray": - col = Color.darkGray; - break; - case "gray": - col = Color.gray; - break; - case "green": - col = Color.green; - break; - case "lightgray": - col = Color.lightGray; - break; - case "magenta": - col = Color.magenta; - break; - case "orange": - col = Color.orange; - break; - case "pink": - col = Color.pink; - break; - case "red": - col = Color.red; - break; - case "white": - col = Color.white; - break; - case "yellow": - col = Color.yellow; - break; - } - - return col; + return ucs; } public static Color rnaHelices[] = null; @@ -623,17 +130,28 @@ public class ColourSchemeProperty // Generate random colors and store for (; j <= n; j++) { - rnaHelices[j] = jalview.util.ColorUtils - .generateRandomColor(Color.white); + rnaHelices[j] = ColorUtils.generateRandomColor(Color.white); } } /** - * delete the existing cached RNA helces colours + * delete the existing cached RNA helices colours */ public static void resetRnaHelicesShading() { rnaHelices = null; } + /** + * Returns the name of the colour scheme (or "None" if it is null) + * + * @param cs + * @return + */ + public static String getColourName(ColourSchemeI cs) + { + return cs == null ? ResidueColourScheme.NONE : cs + .getSchemeName(); + } + } diff --git a/src/jalview/schemes/CovariationColourScheme.java b/src/jalview/schemes/CovariationColourScheme.java index 4701e0b..5f8f4c1 100644 --- a/src/jalview/schemes/CovariationColourScheme.java +++ b/src/jalview/schemes/CovariationColourScheme.java @@ -122,4 +122,15 @@ public class CovariationColourScheme extends ResidueColourScheme return currentColour; } + @Override + public boolean isNucleotideSpecific() + { + return true; + } + + @Override + public String getSchemeName() + { + return "Covariation"; + } } diff --git a/src/jalview/schemes/FeatureColour.java b/src/jalview/schemes/FeatureColour.java index 23087a8..70897de 100644 --- a/src/jalview/schemes/FeatureColour.java +++ b/src/jalview/schemes/FeatureColour.java @@ -22,6 +22,7 @@ package jalview.schemes; import jalview.api.FeatureColourI; import jalview.datamodel.SequenceFeature; +import jalview.util.ColorUtils; import jalview.util.Format; import java.awt.Color; @@ -121,7 +122,7 @@ public class FeatureColour implements FeatureColourI /* * only a simple colour specification - parse it */ - Color colour = UserColourScheme.getColourFromString(descriptor); + Color colour = ColorUtils.parseColourString(descriptor); if (colour == null) { throw new IllegalArgumentException("Invalid colour descriptor: " @@ -213,8 +214,8 @@ public class FeatureColour implements FeatureColourI try { featureColour = new FeatureColour( - new UserColourScheme(mincol).findColour('A'), - new UserColourScheme(maxcol).findColour('A'), min, max); + new UserColourScheme(mincol).findColour(), + new UserColourScheme(maxcol).findColour(), min, max); featureColour.setColourByLabel(labelColour); featureColour.setAutoScaled(autoScaled); // add in any additional parameters @@ -533,7 +534,7 @@ public class FeatureColour implements FeatureColourI { if (isColourByLabel()) { - return UserColourScheme + return ColorUtils .createColourFromName(feature.getDescription()); } diff --git a/src/jalview/schemes/FollowerColourScheme.java b/src/jalview/schemes/FollowerColourScheme.java index 35be31b..aaa36f3 100644 --- a/src/jalview/schemes/FollowerColourScheme.java +++ b/src/jalview/schemes/FollowerColourScheme.java @@ -66,4 +66,10 @@ public class FollowerColourScheme extends ResidueColourScheme } } + @Override + public String getSchemeName() + { + return "Follower"; + } + } diff --git a/src/jalview/schemes/HelixColourScheme.java b/src/jalview/schemes/HelixColourScheme.java index c6ac7a5..f99274b 100755 --- a/src/jalview/schemes/HelixColourScheme.java +++ b/src/jalview/schemes/HelixColourScheme.java @@ -35,4 +35,16 @@ public class HelixColourScheme extends ScoreColourScheme { return new Color(c, (float) 1.0 - c, c); } + + @Override + public boolean isPeptideSpecific() + { + return true; + } + + @Override + public String getSchemeName() + { + return JalviewColourScheme.Helix.toString(); + } } diff --git a/src/jalview/schemes/HydrophobicColourScheme.java b/src/jalview/schemes/HydrophobicColourScheme.java index 954471f..121b864 100755 --- a/src/jalview/schemes/HydrophobicColourScheme.java +++ b/src/jalview/schemes/HydrophobicColourScheme.java @@ -52,4 +52,16 @@ public class HydrophobicColourScheme extends ScoreColourScheme { return new Color(c, (float) 0.0, (float) 1.0 - c); } + + @Override + public boolean isPeptideSpecific() + { + return true; + } + + @Override + public String getSchemeName() + { + return JalviewColourScheme.Hydrophobic.toString(); + } } diff --git a/src/jalview/schemes/JalviewColourScheme.java b/src/jalview/schemes/JalviewColourScheme.java new file mode 100644 index 0000000..355ff83 --- /dev/null +++ b/src/jalview/schemes/JalviewColourScheme.java @@ -0,0 +1,204 @@ +package jalview.schemes; + +import jalview.datamodel.AnnotatedCollectionI; + +import java.awt.Color; +import java.util.HashMap; +import java.util.Map; + +/** + * An enum with the colour schemes supported by Jalview. + */ +public enum JalviewColourScheme +{ + Clustal("Clustal") + { + @Override + public ColourSchemeI getColourScheme(AnnotatedCollectionI coll) + { + return new ClustalxColourScheme(coll, null); + } + }, + Blosum62("Blosum62") + { + @Override + public ColourSchemeI getColourScheme(AnnotatedCollectionI coll) + { + return new Blosum62ColourScheme(); + } + }, + PID("% Identity") + { + @Override + public ColourSchemeI getColourScheme(AnnotatedCollectionI coll) + { + return new PIDColourScheme(); + } + }, + Zappo("Zappo") + { + @Override + public ColourSchemeI getColourScheme(AnnotatedCollectionI coll) + { + return new ZappoColourScheme(); + } + }, + Taylor("Taylor") + { + @Override + public ColourSchemeI getColourScheme(AnnotatedCollectionI coll) + { + return new TaylorColourScheme(); + } + }, + Hydrophobic("Hydrophobic") + { + @Override + public ColourSchemeI getColourScheme(AnnotatedCollectionI coll) + { + return new HydrophobicColourScheme(); + } + }, + Helix("Helix Propensity") + { + @Override + public ColourSchemeI getColourScheme(AnnotatedCollectionI coll) + { + return new HelixColourScheme(); + } + }, + Strand("Strand Propensity") + { + @Override + public ColourSchemeI getColourScheme(AnnotatedCollectionI coll) + { + return new StrandColourScheme(); + } + }, + Turn("Turn Propensity") + { + @Override + public ColourSchemeI getColourScheme(AnnotatedCollectionI coll) + { + return new TurnColourScheme(); + } + }, + Buried("Buried Index") + { + @Override + public ColourSchemeI getColourScheme(AnnotatedCollectionI coll) + { + return new BuriedColourScheme(); + } + }, + Nucleotide("Nucleotide") + { + @Override + public ColourSchemeI getColourScheme(AnnotatedCollectionI coll) + { + return new NucleotideColourScheme(); + } + }, + PurinePyrimidine("Purine/Pyrimidine") + { + @Override + public ColourSchemeI getColourScheme(AnnotatedCollectionI coll) + { + return new PurinePyrimidineColourScheme(); + } + }, + TCoffee("T-Coffee Scores") + { + @Override + public ColourSchemeI getColourScheme(AnnotatedCollectionI coll) + { + return new TCoffeeColourScheme(coll); + } + }, + RNAHelices("RNA Helices") + { + @Override + public ColourSchemeI getColourScheme(AnnotatedCollectionI coll) + { + return new RNAHelicesColour(coll); + } + }, + // RNAInteraction("RNA Interaction type") + // { + // @Override + // public ColourSchemeI getColourScheme(AnnotatedCollectionI coll) + // { + // return new RNAInteractionColourScheme(); + // } + // }, + UserDefined("User Defined") + { + @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"); + } + }; + + static Map names = new HashMap(); + + private String name; + + static + { + for (JalviewColourScheme scheme : values()) + { + names.put(scheme.name.toLowerCase(), scheme); + } + } + + /** + * Answers the colour scheme with the 'given name', or null if name is invalid + * or null. The name is not case-sensitive. + * + * @param name + * @return + */ + public static JalviewColourScheme forName(String name) + { + return name == null ? null : names.get(name.toLowerCase()); + } + + /** + * Constructor given the name of the colour scheme (as used in Jalview + * parameters). Note this is not necessarily the same as the 'display name' + * used in menu options (as this may be language-dependent). + * + * @param s + */ + JalviewColourScheme(String s) + { + name = s; + } + + /** + * Returns an instance of the colour scheme with which to colour the given + * data + * + * @param coll + * @return + */ + public abstract ColourSchemeI getColourScheme(AnnotatedCollectionI coll); + + /** + * Returns the 'official' name of this colour scheme. This is the name that + * identifies the colour scheme as a start-up parameter for the Jalview + * application or applet. Note that it may not be the name shown in menu + * options, as these may be internationalised. + */ + @Override + public String toString() + { + return name; + } +} diff --git a/src/jalview/schemes/NucleotideColourScheme.java b/src/jalview/schemes/NucleotideColourScheme.java index dff2bf3..3e6bd2f 100755 --- a/src/jalview/schemes/NucleotideColourScheme.java +++ b/src/jalview/schemes/NucleotideColourScheme.java @@ -92,4 +92,16 @@ public class NucleotideColourScheme extends ResidueColourScheme return currentColour; } + + @Override + public boolean isNucleotideSpecific() + { + return true; + } + + @Override + public String getSchemeName() + { + return JalviewColourScheme.Nucleotide.toString(); + } } diff --git a/src/jalview/schemes/PIDColourScheme.java b/src/jalview/schemes/PIDColourScheme.java index 0ad5b5c..175e904 100755 --- a/src/jalview/schemes/PIDColourScheme.java +++ b/src/jalview/schemes/PIDColourScheme.java @@ -94,4 +94,10 @@ public class PIDColourScheme extends ResidueColourScheme return currentColour; } + + @Override + public String getSchemeName() + { + return JalviewColourScheme.PID.toString(); + } } diff --git a/src/jalview/schemes/PurinePyrimidineColourScheme.java b/src/jalview/schemes/PurinePyrimidineColourScheme.java index 8bbbd15..c7c519c 100644 --- a/src/jalview/schemes/PurinePyrimidineColourScheme.java +++ b/src/jalview/schemes/PurinePyrimidineColourScheme.java @@ -88,4 +88,16 @@ public class PurinePyrimidineColourScheme extends ResidueColourScheme return currentColour; } + + @Override + public boolean isNucleotideSpecific() + { + return true; + } + + @Override + public String getSchemeName() + { + return JalviewColourScheme.PurinePyrimidine.toString(); + } } diff --git a/src/jalview/schemes/RNAHelicesColour.java b/src/jalview/schemes/RNAHelicesColour.java index 9729a83..6448898 100644 --- a/src/jalview/schemes/RNAHelicesColour.java +++ b/src/jalview/schemes/RNAHelicesColour.java @@ -21,6 +21,7 @@ package jalview.schemes; import jalview.datamodel.AlignmentAnnotation; +import jalview.datamodel.AlignmentI; import jalview.datamodel.AnnotatedCollectionI; import jalview.datamodel.SequenceCollectionI; import jalview.datamodel.SequenceI; @@ -202,4 +203,34 @@ public class RNAHelicesColour extends ResidueColourScheme { return new RNAHelicesColour(this); } -} \ No newline at end of file + + @Override + public boolean isNucleotideSpecific() + { + return true; + } + + /** + * Answers true if the data has RNA secondary structure annotation + */ + @Override + public boolean isApplicableTo(AnnotatedCollectionI ac) + { + AnnotatedCollectionI context = ac.getContext(); + if (context == null) + { + context = ac; + } + if (context instanceof AlignmentI) + { + return ((AlignmentI) context).hasRNAStructure(); + } + return false; + } + + @Override + public String getSchemeName() + { + return JalviewColourScheme.RNAHelices.toString(); + } +} diff --git a/src/jalview/schemes/RNAInteractionColourScheme.java b/src/jalview/schemes/RNAInteractionColourScheme.java index db1401a..707afd7 100644 --- a/src/jalview/schemes/RNAInteractionColourScheme.java +++ b/src/jalview/schemes/RNAInteractionColourScheme.java @@ -65,4 +65,16 @@ public class RNAInteractionColourScheme extends ResidueColourScheme return currentColour; } + + @Override + public boolean isNucleotideSpecific() + { + return true; + } + + @Override + public String getSchemeName() + { + return "RNA Interaction type"; + } } diff --git a/src/jalview/schemes/ResidueColourScheme.java b/src/jalview/schemes/ResidueColourScheme.java index e675a27..c1eeafa 100755 --- a/src/jalview/schemes/ResidueColourScheme.java +++ b/src/jalview/schemes/ResidueColourScheme.java @@ -21,6 +21,7 @@ package jalview.schemes; import jalview.analysis.Conservation; +import jalview.datamodel.AlignmentI; import jalview.datamodel.AnnotatedCollectionI; import jalview.datamodel.ProfileI; import jalview.datamodel.ProfilesI; @@ -38,6 +39,8 @@ import java.util.Map; */ public class ResidueColourScheme implements ColourSchemeI { + public static final String NONE = "None"; + final int[] symbolIndex; boolean conservationColouring = false; @@ -101,6 +104,16 @@ public class ResidueColourScheme implements ColourSchemeI } /** + * Returns the colour for symbol 'A'. Intended for use in a 'fixed colour' + * colour scheme (for example a feature colour). + */ + @Override + public Color findColour() + { + return findColour('A'); + } + + /** * Find a colour without an index in a sequence */ @Override @@ -340,4 +353,76 @@ public class ResidueColourScheme implements ColourSchemeI new String[] { getClass().getName() }), q); } } + + /** + * Answers false if the colour scheme is nucleotide or peptide specific, and + * the data does not match, else false. Override to modify or extend this test + * as required. + */ + @Override + public boolean isApplicableTo(AnnotatedCollectionI ac) + { + if (!isPeptideSpecific() && !isNucleotideSpecific()) + { + return true; + } + + /* + * inspect the data context (alignment dataset) for residue type + */ + boolean nucleotide = false; + AnnotatedCollectionI context = ac.getContext(); + if (context != null) + { + if (context instanceof AlignmentI) + { + nucleotide = ((AlignmentI) context).isNucleotide(); + } + else + { + // not sure what's going on, play safe + return true; + } + } + else if (ac instanceof AlignmentI) + { + nucleotide = ((AlignmentI) ac).isNucleotide(); + } + else + { + return true; + } + + /* + * does data type match colour scheme type? + */ + return (nucleotide && isNucleotideSpecific()) + || (!nucleotide && isPeptideSpecific()); + } + + /** + * Answers true if the colour scheme is normally only for peptide data + * + * @return + */ + public boolean isPeptideSpecific() + { + return false; + } + + /** + * Answers true if the colour scheme is normally only for nucleotide data + * + * @return + */ + public boolean isNucleotideSpecific() + { + return false; + } + + @Override + public String getSchemeName() + { + return "Residue"; + } } diff --git a/src/jalview/schemes/ScoreColourScheme.java b/src/jalview/schemes/ScoreColourScheme.java index 7eb920d..57e8458 100755 --- a/src/jalview/schemes/ScoreColourScheme.java +++ b/src/jalview/schemes/ScoreColourScheme.java @@ -129,4 +129,10 @@ public class ScoreColourScheme extends ResidueColourScheme { return new Color(c, (float) 0.0, (float) 1.0 - c); } + + @Override + public String getSchemeName() + { + return "Score"; + } } diff --git a/src/jalview/schemes/StrandColourScheme.java b/src/jalview/schemes/StrandColourScheme.java index 56a2d90..a6e4595 100755 --- a/src/jalview/schemes/StrandColourScheme.java +++ b/src/jalview/schemes/StrandColourScheme.java @@ -52,4 +52,16 @@ public class StrandColourScheme extends ScoreColourScheme { return new Color(c, c, (float) 1.0 - c); } + + @Override + public boolean isPeptideSpecific() + { + return true; + } + + @Override + public String getSchemeName() + { + return JalviewColourScheme.Strand.toString(); + } } diff --git a/src/jalview/schemes/TCoffeeColourScheme.java b/src/jalview/schemes/TCoffeeColourScheme.java index 2be51c2..19c92a0 100644 --- a/src/jalview/schemes/TCoffeeColourScheme.java +++ b/src/jalview/schemes/TCoffeeColourScheme.java @@ -141,4 +141,35 @@ public class TCoffeeColourScheme extends ResidueColourScheme { return new TCoffeeColourScheme(sg); } + + /** + * Answers true if the annotated data has TCoffee score annotation + */ + @Override + public boolean isApplicableTo(AnnotatedCollectionI ac) + { + if (ac.getContext() != null) + { + ac = ac.getContext(); + } + AlignmentAnnotation[] anns = ac.getAlignmentAnnotation(); + if (anns == null) + { + return false; + } + for (AlignmentAnnotation ann : anns) + { + if (TCoffeeScoreFile.TCOFFEE_SCORE.equals(ann.getCalcId())) + { + return true; + } + } + return false; + } + + @Override + public String getSchemeName() + { + return JalviewColourScheme.TCoffee.toString(); + } } diff --git a/src/jalview/schemes/TaylorColourScheme.java b/src/jalview/schemes/TaylorColourScheme.java index 8c46bba..5887220 100755 --- a/src/jalview/schemes/TaylorColourScheme.java +++ b/src/jalview/schemes/TaylorColourScheme.java @@ -26,4 +26,16 @@ public class TaylorColourScheme extends ResidueColourScheme { super(ResidueProperties.aaIndex, ResidueProperties.taylor, 0); } + + @Override + public boolean isPeptideSpecific() + { + return true; + } + + @Override + public String getSchemeName() + { + return JalviewColourScheme.Taylor.toString(); + } } diff --git a/src/jalview/schemes/TurnColourScheme.java b/src/jalview/schemes/TurnColourScheme.java index 2c95755..ac16b5b 100755 --- a/src/jalview/schemes/TurnColourScheme.java +++ b/src/jalview/schemes/TurnColourScheme.java @@ -52,4 +52,16 @@ public class TurnColourScheme extends ScoreColourScheme { return new Color(c, 1 - c, 1 - c); } + + @Override + public boolean isPeptideSpecific() + { + return true; + } + + @Override + public String getSchemeName() + { + return JalviewColourScheme.Turn.toString(); + } } diff --git a/src/jalview/schemes/UserColourScheme.java b/src/jalview/schemes/UserColourScheme.java index 4bb54f9..1865518 100755 --- a/src/jalview/schemes/UserColourScheme.java +++ b/src/jalview/schemes/UserColourScheme.java @@ -23,6 +23,7 @@ package jalview.schemes; import jalview.datamodel.AnnotatedCollectionI; import jalview.datamodel.SequenceCollectionI; import jalview.datamodel.SequenceI; +import jalview.util.ColorUtils; import java.awt.Color; import java.util.Map; @@ -63,12 +64,12 @@ public class UserColourScheme extends ResidueColourScheme public UserColourScheme(String colour) { super(ResidueProperties.aaIndex); - Color col = getColourFromString(colour); + Color col = ColorUtils.parseColourString(colour); if (col == null) { System.out.println("Making colour from name: " + colour); - col = createColourFromName(colour); + col = ColorUtils.createColourFromName(colour); } colors = new Color[24]; @@ -100,86 +101,6 @@ public class UserColourScheme extends ResidueColourScheme } /** - * Parses a string into a Color, where the accepted formats are - *
    - *
  • an AWT colour name e.g. white
  • - *
  • a hex colour value (without prefix) e.g. ff0000
  • - *
  • an rgb triple e.g. 100,50,150
  • - *
- * - * @param colour - * @return the parsed colour, or null if parsing fails - */ - public static Color getColourFromString(String colour) - { - if (colour == null) - { - return null; - } - colour = colour.trim(); - - Color col = null; - try - { - int value = Integer.parseInt(colour, 16); - col = new Color(value); - } catch (NumberFormatException ex) - { - } - - if (col == null) - { - col = ColourSchemeProperty.getAWTColorFromName(colour); - } - - if (col == null) - { - try - { - String[] tokens = colour.split(","); - if (tokens.length == 3) - { - int r = Integer.parseInt(tokens[0].trim()); - int g = Integer.parseInt(tokens[1].trim()); - int b = Integer.parseInt(tokens[2].trim()); - col = new Color(r, g, b); - } - } catch (Exception ex) - { - // non-numeric token or out of 0-255 range - } - } - - return col; - } - - public static Color createColourFromName(String name) - { - int r, g, b; - - int lsize = name.length(); - int start = 0, end = lsize / 3; - - int rgbOffset = Math.abs(name.hashCode() % 10) * 15; - - r = Math.abs(name.substring(start, end).hashCode() + rgbOffset) % 210 + 20; - start = end; - end += lsize / 3; - if (end > lsize) - { - end = lsize; - } - - g = Math.abs(name.substring(start, end).hashCode() + rgbOffset) % 210 + 20; - - b = Math.abs(name.substring(end).hashCode() + rgbOffset) % 210 + 20; - - Color color = new Color(r, g, b); - - return color; - } - - /** * Parse and save residue colours specified as (for example) * *
@@ -230,7 +151,7 @@ public class UserColourScheme extends ResidueColourScheme
             {
               if (lowerCaseColours[i] == null)
               {
-                lowerCaseColours[i] = getColourFromString(colour);
+                lowerCaseColours[i] = ColorUtils.parseColourString(colour);
               }
             }
 
@@ -243,11 +164,11 @@ public class UserColourScheme extends ResidueColourScheme
             {
               lowerCaseColours = new Color[23];
             }
-            lowerCaseColours[colIndex] = getColourFromString(colour);
+            lowerCaseColours[colIndex] = ColorUtils.parseColourString(colour);
           }
           else
           {
-            colors[colIndex] = getColourFromString(colour);
+            colors[colIndex] = ColorUtils.parseColourString(colour);
           }
         }
       }
@@ -313,4 +234,18 @@ public class UserColourScheme extends ResidueColourScheme
     return super.findColour(c);
   }
 
+  /**
+   * Answers the customised name of the colour scheme, if it has one, else
+   * "User Defined"
+   */
+  @Override
+  public String getSchemeName()
+  {
+    if (schemeName != null && schemeName.length() > 0)
+    {
+      return schemeName;
+    }
+    return JalviewColourScheme.UserDefined.toString();
+  }
+
 }
diff --git a/src/jalview/schemes/ZappoColourScheme.java b/src/jalview/schemes/ZappoColourScheme.java
index 8fa1656..62c32d8 100755
--- a/src/jalview/schemes/ZappoColourScheme.java
+++ b/src/jalview/schemes/ZappoColourScheme.java
@@ -35,4 +35,16 @@ public class ZappoColourScheme extends ResidueColourScheme
   {
     super(ResidueProperties.aaIndex, ResidueProperties.zappo, 0);
   }
+
+  @Override
+  public boolean isPeptideSpecific()
+  {
+    return true;
+  }
+
+  @Override
+  public String getSchemeName()
+  {
+    return JalviewColourScheme.Zappo.toString();
+  }
 }
diff --git a/src/jalview/util/ColorUtils.java b/src/jalview/util/ColorUtils.java
index 525bfdb..55db824 100644
--- a/src/jalview/util/ColorUtils.java
+++ b/src/jalview/util/ColorUtils.java
@@ -191,4 +191,163 @@ public class ColorUtils
       return new Color(red, green, blue);
     }
   }
+
+  /**
+   * Parses a string into a Color, where the accepted formats are
+   * 
    + *
  • an AWT colour name e.g. white
  • + *
  • a hex colour value (without prefix) e.g. ff0000
  • + *
  • an rgb triple e.g. 100,50,150
  • + *
+ * + * @param colour + * @return the parsed colour, or null if parsing fails + */ + public static Color parseColourString(String colour) + { + if (colour == null) + { + return null; + } + colour = colour.trim(); + + Color col = null; + try + { + int value = Integer.parseInt(colour, 16); + col = new Color(value); + } catch (NumberFormatException ex) + { + } + + if (col == null) + { + col = ColorUtils.getAWTColorFromName(colour); + } + + if (col == null) + { + try + { + String[] tokens = colour.split(","); + if (tokens.length == 3) + { + int r = Integer.parseInt(tokens[0].trim()); + int g = Integer.parseInt(tokens[1].trim()); + int b = Integer.parseInt(tokens[2].trim()); + col = new Color(r, g, b); + } + } catch (Exception ex) + { + // non-numeric token or out of 0-255 range + } + } + + return col; + } + + /** + * Constructs a colour from a text string. The hashcode of the whole string is + * scaled to the range 0-135. This is added to RGB values made from the + * hashcode of each third of the string, and scaled to the range 20-229. + * + * @param name + * @return + */ + public static Color createColourFromName(String name) + { + int lsize = name.length(); + int start = 0; + int end = lsize / 3; + + int rgbOffset = Math.abs(name.hashCode() % 10) * 15; + + /* + * red: first third + */ + int r = Math.abs(name.substring(start, end).hashCode() + rgbOffset) % 210 + 20; + start = end; + end += lsize / 3; + if (end > lsize) + { + end = lsize; + } + + /* + * green: second third + */ + int g = Math.abs(name.substring(start, end).hashCode() + rgbOffset) % 210 + 20; + + /* + * blue: third third + */ + int b = Math.abs(name.substring(end).hashCode() + rgbOffset) % 210 + 20; + + Color color = new Color(r, g, b); + + return color; + } + + /** + * Returns the Color constant for a given colour name e.g. "pink", or null if + * the name is not recognised + * + * @param name + * @return + */ + public static Color getAWTColorFromName(String name) + { + if (name == null) + { + return null; + } + Color col = null; + name = name.toLowerCase(); + + // or make a static map; or use reflection on the field name + switch (name) + { + case "black": + col = Color.black; + break; + case "blue": + col = Color.blue; + break; + case "cyan": + col = Color.cyan; + break; + case "darkgray": + col = Color.darkGray; + break; + case "gray": + col = Color.gray; + break; + case "green": + col = Color.green; + break; + case "lightgray": + col = Color.lightGray; + break; + case "magenta": + col = Color.magenta; + break; + case "orange": + col = Color.orange; + break; + case "pink": + col = Color.pink; + break; + case "red": + col = Color.red; + break; + case "white": + col = Color.white; + break; + case "yellow": + col = Color.yellow; + break; + } + + return col; + } } diff --git a/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java b/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java index c1ad465..8468329 100644 --- a/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java +++ b/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java @@ -28,7 +28,7 @@ import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; import jalview.renderer.seqfeatures.FeatureRenderer; import jalview.schemes.FeatureColour; -import jalview.schemes.UserColourScheme; +import jalview.util.ColorUtils; import java.awt.Color; import java.beans.PropertyChangeListener; @@ -542,7 +542,7 @@ public abstract class FeatureRendererModel implements FeatureColourI fc = featureColours.get(featureType); if (fc == null) { - Color col = UserColourScheme.createColourFromName(featureType); + Color col = ColorUtils.createColourFromName(featureType); fc = new FeatureColour(col); featureColours.put(featureType, fc); } diff --git a/src/jalview/ws/jws2/AADisorderClient.java b/src/jalview/ws/jws2/AADisorderClient.java index 0cf76e0..001f6a8 100644 --- a/src/jalview/ws/jws2/AADisorderClient.java +++ b/src/jalview/ws/jws2/AADisorderClient.java @@ -29,7 +29,7 @@ import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; import jalview.gui.AlignFrame; import jalview.schemes.FeatureColour; -import jalview.schemes.UserColourScheme; +import jalview.util.ColorUtils; import jalview.ws.jws2.jabaws2.Jws2Instance; import jalview.ws.params.WsParamSetI; @@ -308,7 +308,7 @@ public class AADisorderClient extends JabawsCalcWorker annot.description += "
" + threshNote; } annot.description += ""; - Color col = UserColourScheme.createColourFromName(typeName + Color col = ColorUtils.createColourFromName(typeName + scr.getMethod()); for (int p = 0, ps = annot.annotations.length; p < ps; p++) { diff --git a/test/jalview/ext/rbvi/chimera/ChimeraCommandsTest.java b/test/jalview/ext/rbvi/chimera/ChimeraCommandsTest.java index d0ea751..ffb886c 100644 --- a/test/jalview/ext/rbvi/chimera/ChimeraCommandsTest.java +++ b/test/jalview/ext/rbvi/chimera/ChimeraCommandsTest.java @@ -30,6 +30,7 @@ import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.SortedMap; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -47,7 +48,7 @@ public class ChimeraCommandsTest @Test(groups = { "Functional" }) public void testAddColourRange() { - Map>>> map = new LinkedHashMap>>>(); + Map>>> map = new LinkedHashMap>>>(); ChimeraCommands.addColourRange(map, Color.pink, 1, 2, 4, "A"); ChimeraCommands.addColourRange(map, Color.pink, 1, 8, 8, "A"); ChimeraCommands.addColourRange(map, Color.pink, 1, 5, 7, "B"); @@ -96,7 +97,7 @@ public class ChimeraCommandsTest public void testBuildColourCommands() { - Map>>> map = new LinkedHashMap>>>(); + Map>>> map = new LinkedHashMap>>>(); ChimeraCommands.addColourRange(map, Color.blue, 0, 2, 5, "A"); ChimeraCommands.addColourRange(map, Color.blue, 0, 7, 7, "B"); ChimeraCommands.addColourRange(map, Color.blue, 0, 9, 23, "A"); diff --git a/test/jalview/gui/AlignViewportTest.java b/test/jalview/gui/AlignViewportTest.java index 5695b15..213f769 100644 --- a/test/jalview/gui/AlignViewportTest.java +++ b/test/jalview/gui/AlignViewportTest.java @@ -345,9 +345,9 @@ public class AlignViewportTest public void testSetGlobalColourScheme() { /* - * test for JAL-2283 don't inadvertently turn on colour by conservation + * test for JAL-2283: don't inadvertently turn on colour by conservation */ - Cache.applicationProperties.setProperty("DEFAULT_COLOUR_PROT", "NONE"); + Cache.applicationProperties.setProperty("DEFAULT_COLOUR_PROT", "None"); Cache.applicationProperties.setProperty("SHOW_CONSERVATION", Boolean.TRUE.toString()); AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( diff --git a/test/jalview/io/Jalview2xmlTests.java b/test/jalview/io/Jalview2xmlTests.java index 88f3fdd..434619e 100644 --- a/test/jalview/io/Jalview2xmlTests.java +++ b/test/jalview/io/Jalview2xmlTests.java @@ -120,8 +120,8 @@ public class Jalview2xmlTests extends Jalview2xmlBase .getGlobalColourScheme().getClass(), TCoffeeColourScheme.class); assertNotNull("Recognise T-Coffee score from string", ColourSchemeProperty.getColour(af.getViewport() - .getAlignment(), ColourSchemeProperty.getColourName(af - .getViewport().getGlobalColourScheme()))); + .getAlignment(), af.getViewport() + .getGlobalColourScheme().getSchemeName())); assertTrue("Failed to store as a project.", af.saveAlignment(tfile, FileFormat.Jalview)); diff --git a/test/jalview/schemes/ColourSchemePropertyTest.java b/test/jalview/schemes/ColourSchemePropertyTest.java new file mode 100644 index 0000000..efea164 --- /dev/null +++ b/test/jalview/schemes/ColourSchemePropertyTest.java @@ -0,0 +1,68 @@ +package jalview.schemes; + +import static org.testng.Assert.assertEquals; + +import jalview.datamodel.Alignment; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.Sequence; +import jalview.datamodel.SequenceI; + +import org.testng.annotations.Test; + +public class ColourSchemePropertyTest +{ + @Test + 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"); + } +} diff --git a/test/jalview/schemes/FeatureColourTest.java b/test/jalview/schemes/FeatureColourTest.java index 47613a1..c16d541 100644 --- a/test/jalview/schemes/FeatureColourTest.java +++ b/test/jalview/schemes/FeatureColourTest.java @@ -27,6 +27,7 @@ import static org.testng.AssertJUnit.fail; import jalview.datamodel.SequenceFeature; import jalview.gui.JvOptionPane; +import jalview.util.ColorUtils; import jalview.util.Format; import java.awt.Color; @@ -146,7 +147,7 @@ public class FeatureColourTest fc.setColourByLabel(true); SequenceFeature sf = new SequenceFeature("type", "desc", 0, 20, 1f, null); - Color expected = UserColourScheme.createColourFromName("desc"); + Color expected = ColorUtils.createColourFromName("desc"); assertEquals(expected, fc.getColor(sf)); } diff --git a/test/jalview/schemes/JalviewColourSchemeTest.java b/test/jalview/schemes/JalviewColourSchemeTest.java new file mode 100644 index 0000000..8bc0893 --- /dev/null +++ b/test/jalview/schemes/JalviewColourSchemeTest.java @@ -0,0 +1,82 @@ +package jalview.schemes; + +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertSame; +import static org.testng.Assert.assertTrue; + +import jalview.datamodel.Alignment; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.Sequence; +import jalview.datamodel.SequenceI; + +import org.testng.annotations.Test; + +public class JalviewColourSchemeTest +{ + @Test + public void testForName() + { + assertSame(JalviewColourScheme.Clustal, + JalviewColourScheme.forName("Clustal")); + assertSame(JalviewColourScheme.Clustal, + JalviewColourScheme.forName("CLUSTAL")); + assertSame(JalviewColourScheme.Blosum62, + JalviewColourScheme.forName("Blosum62")); + assertSame(JalviewColourScheme.PID, + JalviewColourScheme.forName("% Identity")); + assertSame(JalviewColourScheme.Hydrophobic, + JalviewColourScheme.forName("Hydrophobic")); + assertSame(JalviewColourScheme.Zappo, + JalviewColourScheme.forName("Zappo")); + assertSame(JalviewColourScheme.Taylor, + JalviewColourScheme.forName("Taylor")); + assertSame(JalviewColourScheme.Helix, + JalviewColourScheme.forName("Helix Propensity")); + assertSame(JalviewColourScheme.Strand, + JalviewColourScheme.forName("Strand Propensity")); + assertSame(JalviewColourScheme.Turn, + JalviewColourScheme.forName("Turn Propensity")); + assertSame(JalviewColourScheme.Buried, + JalviewColourScheme.forName("Buried Index")); + assertSame(JalviewColourScheme.Nucleotide, + JalviewColourScheme.forName("Nucleotide")); + assertSame(JalviewColourScheme.PurinePyrimidine, + JalviewColourScheme.forName("Purine/Pyrimidine")); + assertSame(JalviewColourScheme.TCoffee, + JalviewColourScheme.forName("T-Coffee Scores")); + assertSame(JalviewColourScheme.RNAHelices, + JalviewColourScheme.forName("RNA Helices")); + // assertSame(JalviewColourScheme.RNAInteraction, + // JalviewColourScheme.forName("RNA Interaction type")); + assertSame(JalviewColourScheme.UserDefined, + JalviewColourScheme.forName("User Defined")); + + assertNull(JalviewColourScheme.forName("PID")); + assertNull(JalviewColourScheme.forName("")); + assertNull(JalviewColourScheme.forName(null)); + } + + @Test + public void testGetColourScheme() + { + SequenceI seq = new Sequence("Seq1", "abcd"); + AlignmentI al = new Alignment(new SequenceI[] { seq }); + assertTrue(JalviewColourScheme.Clustal.getColourScheme(al) instanceof ClustalxColourScheme); + assertTrue(JalviewColourScheme.Blosum62.getColourScheme(al) instanceof Blosum62ColourScheme); + assertTrue(JalviewColourScheme.PID.getColourScheme(al) instanceof PIDColourScheme); + assertTrue(JalviewColourScheme.Hydrophobic.getColourScheme(al) instanceof HydrophobicColourScheme); + assertTrue(JalviewColourScheme.Zappo.getColourScheme(al) instanceof ZappoColourScheme); + assertTrue(JalviewColourScheme.Taylor.getColourScheme(al) instanceof TaylorColourScheme); + assertTrue(JalviewColourScheme.Helix.getColourScheme(al) instanceof HelixColourScheme); + assertTrue(JalviewColourScheme.Strand.getColourScheme(al) instanceof StrandColourScheme); + assertTrue(JalviewColourScheme.Turn.getColourScheme(al) instanceof TurnColourScheme); + assertTrue(JalviewColourScheme.Buried.getColourScheme(al) instanceof BuriedColourScheme); + assertTrue(JalviewColourScheme.Nucleotide.getColourScheme(al) instanceof NucleotideColourScheme); + assertTrue(JalviewColourScheme.PurinePyrimidine.getColourScheme(al) instanceof PurinePyrimidineColourScheme); + assertTrue(JalviewColourScheme.TCoffee.getColourScheme(al) instanceof TCoffeeColourScheme); + assertTrue(JalviewColourScheme.RNAHelices.getColourScheme(al) instanceof RNAHelicesColour); + // assertTrue(JalviewColourScheme.RNAInteraction.getColourScheme(al) + // instanceof RNAInteractionColourScheme); + assertTrue(JalviewColourScheme.UserDefined.getColourScheme(al) instanceof UserColourScheme); + } +} diff --git a/test/jalview/schemes/ResidueColourSchemeTest.java b/test/jalview/schemes/ResidueColourSchemeTest.java index d3a4fff..809dce3 100644 --- a/test/jalview/schemes/ResidueColourSchemeTest.java +++ b/test/jalview/schemes/ResidueColourSchemeTest.java @@ -24,10 +24,18 @@ import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertFalse; import static org.testng.AssertJUnit.assertTrue; +import jalview.datamodel.Alignment; +import jalview.datamodel.AlignmentAnnotation; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.AnnotatedCollectionI; +import jalview.datamodel.Annotation; import jalview.datamodel.Profile; import jalview.datamodel.ProfileI; import jalview.datamodel.Profiles; +import jalview.datamodel.Sequence; +import jalview.datamodel.SequenceI; import jalview.gui.JvOptionPane; +import jalview.io.TCoffeeScoreFile; import java.awt.Color; @@ -176,4 +184,151 @@ public class ResidueColourSchemeTest assertEquals(colour, rcs.applyConservation(colour, 11)); assertEquals(Color.WHITE, rcs.applyConservation(colour, 12)); } + + @Test + public void testIsApplicableTo() + { + SequenceI pep1 = new Sequence("pep1", "APQTWLS"); + SequenceI pep2 = new Sequence("pep2", "AILFQYG"); + SequenceI dna1 = new Sequence("dna1", "ACTGAC"); + SequenceI dna2 = new Sequence("dna2", "TCCAAG"); + AlignmentI peptide = new Alignment(new SequenceI[] { pep1, pep2 }); + AlignmentI nucleotide = new Alignment(new SequenceI[] { dna1, dna2 }); + + /* + * peptide-specific colour schemes + */ + assertTrue(new ClustalxColourScheme(peptide, null) + .isApplicableTo(peptide)); + assertFalse(new ClustalxColourScheme(nucleotide, null) + .isApplicableTo(nucleotide)); + assertTrue(new Blosum62ColourScheme().isApplicableTo(peptide)); + assertFalse(new Blosum62ColourScheme().isApplicableTo(nucleotide)); + assertTrue(new BuriedColourScheme().isApplicableTo(peptide)); + assertFalse(new BuriedColourScheme().isApplicableTo(nucleotide)); + assertTrue(new HelixColourScheme().isApplicableTo(peptide)); + assertFalse(new HelixColourScheme().isApplicableTo(nucleotide)); + assertTrue(new HydrophobicColourScheme().isApplicableTo(peptide)); + assertFalse(new HydrophobicColourScheme().isApplicableTo(nucleotide)); + assertTrue(new StrandColourScheme().isApplicableTo(peptide)); + assertFalse(new StrandColourScheme().isApplicableTo(nucleotide)); + assertTrue(new TaylorColourScheme().isApplicableTo(peptide)); + assertFalse(new TaylorColourScheme().isApplicableTo(nucleotide)); + assertTrue(new TurnColourScheme().isApplicableTo(peptide)); + assertFalse(new TurnColourScheme().isApplicableTo(nucleotide)); + assertTrue(new ZappoColourScheme().isApplicableTo(peptide)); + assertFalse(new ZappoColourScheme().isApplicableTo(nucleotide)); + + /* + * nucleotide-specific colour schemes + */ + assertFalse(new NucleotideColourScheme().isApplicableTo(peptide)); + assertTrue(new NucleotideColourScheme().isApplicableTo(nucleotide)); + assertFalse(new PurinePyrimidineColourScheme().isApplicableTo(peptide)); + assertTrue(new PurinePyrimidineColourScheme() + .isApplicableTo(nucleotide)); + assertFalse(new RNAInteractionColourScheme().isApplicableTo(peptide)); + assertTrue(new RNAInteractionColourScheme().isApplicableTo(nucleotide)); + + /* + * indifferent + */ + assertTrue(new UserColourScheme().isApplicableTo(peptide)); + assertTrue(new UserColourScheme().isApplicableTo(nucleotide)); + assertTrue(new ScoreColourScheme(new int[] {}, new double[] {}, 0, 0d) + .isApplicableTo(peptide)); + assertTrue(new ScoreColourScheme(new int[] {}, new double[] {}, 0, 0d) + .isApplicableTo(nucleotide)); + assertTrue(new ResidueColourScheme().isApplicableTo(peptide)); + assertTrue(new ResidueColourScheme().isApplicableTo(nucleotide)); + assertTrue(new PIDColourScheme().isApplicableTo(peptide)); + assertTrue(new PIDColourScheme().isApplicableTo(nucleotide)); + assertTrue(new FollowerColourScheme().isApplicableTo(peptide)); + assertTrue(new FollowerColourScheme().isApplicableTo(nucleotide)); + + /* + * TCoffee colour requires the presence of TCoffee score annotation + */ + assertFalse(new TCoffeeColourScheme(peptide).isApplicableTo(peptide)); + assertFalse(new TCoffeeColourScheme(nucleotide) + .isApplicableTo(nucleotide)); + AlignmentAnnotation aa = new AlignmentAnnotation("T-COFFEE", "", null); + aa.setCalcId(TCoffeeScoreFile.TCOFFEE_SCORE); + peptide.addAnnotation(aa); + aa = new AlignmentAnnotation("T-COFFEE", "", null); + aa.setCalcId(TCoffeeScoreFile.TCOFFEE_SCORE); + nucleotide.addAnnotation(aa); + assertTrue(new TCoffeeColourScheme(peptide).isApplicableTo(peptide)); + assertTrue(new TCoffeeColourScheme(nucleotide) + .isApplicableTo(nucleotide)); + + /* + * RNAHelices requires the presence of rna secondary structure + */ + assertFalse(new RNAHelicesColour(peptide).isApplicableTo(peptide)); + assertFalse(new RNAHelicesColour(nucleotide).isApplicableTo(nucleotide)); + // add secondary structure (small but perfectly formed) + Annotation[] ss = new Annotation[2]; + ss[0] = new Annotation("", "", '{', 0f); + ss[1] = new Annotation("", "", '}', 0f); + nucleotide.addAnnotation(new AlignmentAnnotation("SS", "", ss)); + assertTrue(new RNAHelicesColour(nucleotide).isApplicableTo(nucleotide)); + } + + @Test + public void testIsApplicableTo_dynamicColourScheme() + { + SequenceI pep1 = new Sequence("pep1", "APQTWLS"); + SequenceI pep2 = new Sequence("pep2", "AILFQYG"); + AlignmentI peptide = new Alignment(new SequenceI[] { pep1, pep2 }); + + /* + * demonstrate that we can 'plug in' a colour scheme with specified + * criteria for applicability; here, that there are more than 2 sequences + */ + ColourSchemeI cs = new UserColourScheme() + { + @Override + public boolean isApplicableTo(AnnotatedCollectionI ac) + { + AlignmentI al = ac.getContext() == null ? (AlignmentI) ac + : (AlignmentI) ac.getContext(); + return al.getSequences().size() > 2; + } + }; + assertFalse(cs.isApplicableTo(peptide)); + peptide.addSequence(pep1); + assertTrue(cs.isApplicableTo(peptide)); + } + + @Test + public void testGetName() + { + SequenceI pep1 = new Sequence("pep1", "APQTWLS"); + AlignmentI peptide = new Alignment(new SequenceI[] { pep1 }); + + assertEquals("Blosum62", new Blosum62ColourScheme().getSchemeName()); + assertEquals("Buried Index", new BuriedColourScheme().getSchemeName()); + assertEquals("Helix Propensity", new HelixColourScheme().getSchemeName()); + assertEquals("Hydrophobic", new HydrophobicColourScheme().getSchemeName()); + assertEquals("Strand Propensity", new StrandColourScheme().getSchemeName()); + assertEquals("Taylor", new TaylorColourScheme().getSchemeName()); + assertEquals("Turn Propensity", new TurnColourScheme().getSchemeName()); + assertEquals("Zappo", new ZappoColourScheme().getSchemeName()); + assertEquals("Nucleotide", new NucleotideColourScheme().getSchemeName()); + assertEquals("Purine/Pyrimidine", + new PurinePyrimidineColourScheme().getSchemeName()); + assertEquals("RNA Interaction type", + new RNAInteractionColourScheme().getSchemeName()); + assertEquals("User Defined", new UserColourScheme().getSchemeName()); + assertEquals("Score", new ScoreColourScheme(new int[] {}, + new double[] {}, 0, 0d).getSchemeName()); + assertEquals("Residue", new ResidueColourScheme().getSchemeName()); + assertEquals("% Identity", new PIDColourScheme().getSchemeName()); + assertEquals("Follower", new FollowerColourScheme().getSchemeName()); + assertEquals("T-Coffee Scores", + new TCoffeeColourScheme(peptide).getSchemeName()); + assertEquals("RNA Helices", + new RNAHelicesColour(peptide).getSchemeName()); + } } diff --git a/test/jalview/schemes/UserColourSchemeTest.java b/test/jalview/schemes/UserColourSchemeTest.java index f4875ee..f89568b 100644 --- a/test/jalview/schemes/UserColourSchemeTest.java +++ b/test/jalview/schemes/UserColourSchemeTest.java @@ -21,8 +21,6 @@ package jalview.schemes; import static org.testng.AssertJUnit.assertEquals; -import static org.testng.AssertJUnit.assertNull; -import static org.testng.AssertJUnit.assertSame; import jalview.gui.JvOptionPane; @@ -42,54 +40,6 @@ public class UserColourSchemeTest } @Test(groups = "Functional") - public void testGetColourFromString() - { - /* - * by colour name - if known to AWT, and included in - * - * @see ColourSchemeProperty.getAWTColorFromName() - */ - assertSame(Color.RED, UserColourScheme.getColourFromString("red")); - assertSame(Color.RED, UserColourScheme.getColourFromString("Red")); - assertSame(Color.RED, UserColourScheme.getColourFromString(" RED ")); - - /* - * by RGB hex code - */ - String hexColour = Integer.toHexString(Color.RED.getRGB() & 0xffffff); - assertEquals("ff0000", hexColour); - assertEquals(Color.RED, UserColourScheme.getColourFromString(hexColour)); - // 'hex' prefixes _not_ wanted here - assertNull(UserColourScheme.getColourFromString("0x" + hexColour)); - assertNull(UserColourScheme.getColourFromString("#" + hexColour)); - // out of range, but Color constructor just or's the rgb value with 0 - assertEquals(Color.black, - UserColourScheme.getColourFromString("1000000")); - - /* - * by RGB triplet - */ - Color c = Color.pink; - String rgb = String.format("%d,%d,%d", c.getRed(), c.getGreen(), - c.getBlue()); - assertEquals("255,175,175", rgb); - assertEquals(c, UserColourScheme.getColourFromString(rgb)); - assertEquals(c, UserColourScheme.getColourFromString("255, 175 , 175")); - - /* - * odds and ends - */ - assertNull(UserColourScheme.getColourFromString(null)); - assertNull(UserColourScheme.getColourFromString("rubbish")); - assertEquals(Color.WHITE, UserColourScheme.getColourFromString("-1")); - assertNull(UserColourScheme.getColourFromString(String - .valueOf(Integer.MAX_VALUE))); - assertNull(UserColourScheme.getColourFromString("100,200,300")); - assertNull(UserColourScheme.getColourFromString("100,200")); - assertNull(UserColourScheme.getColourFromString("100,200,100,200")); - } - - @Test(groups = "Functional") public void testParseAppletParameter() { UserColourScheme cs = new UserColourScheme("white"); diff --git a/test/jalview/util/ColorUtilsTest.java b/test/jalview/util/ColorUtilsTest.java index 9a5d093..77a03d6 100644 --- a/test/jalview/util/ColorUtilsTest.java +++ b/test/jalview/util/ColorUtilsTest.java @@ -166,4 +166,62 @@ public class ColorUtilsTest assertEquals(new Color(46, 31, 16), // with rounding down ColorUtils.bleachColour(colour, -0.7f)); } + + @Test(groups = "Functional") + public void testParseColourString() + { + /* + * by colour name - if known to AWT, and included in + * + * @see ColourSchemeProperty.getAWTColorFromName() + */ + assertSame(Color.RED, ColorUtils.parseColourString("red")); + assertSame(Color.RED, ColorUtils.parseColourString("Red")); + assertSame(Color.RED, ColorUtils.parseColourString(" RED ")); + + /* + * by RGB hex code + */ + String hexColour = Integer.toHexString(Color.RED.getRGB() & 0xffffff); + assertEquals("ff0000", hexColour); + assertEquals(Color.RED, ColorUtils.parseColourString(hexColour)); + // 'hex' prefixes _not_ wanted here + assertNull(ColorUtils.parseColourString("0x" + hexColour)); + assertNull(ColorUtils.parseColourString("#" + hexColour)); + // out of range, but Color constructor just or's the rgb value with 0 + assertEquals(Color.black, ColorUtils.parseColourString("1000000")); + + /* + * by RGB triplet + */ + Color c = Color.pink; + String rgb = String.format("%d,%d,%d", c.getRed(), c.getGreen(), + c.getBlue()); + assertEquals("255,175,175", rgb); + assertEquals(c, ColorUtils.parseColourString(rgb)); + assertEquals(c, ColorUtils.parseColourString("255, 175 , 175")); + + /* + * odds and ends + */ + assertNull(ColorUtils.parseColourString(null)); + assertNull(ColorUtils.parseColourString("rubbish")); + assertEquals(Color.WHITE, ColorUtils.parseColourString("-1")); + assertNull(ColorUtils.parseColourString(String + .valueOf(Integer.MAX_VALUE))); + assertNull(ColorUtils.parseColourString("100,200,300")); // out of range + assertNull(ColorUtils.parseColourString("100,200")); // too few + assertNull(ColorUtils.parseColourString("100,200,100,200")); // too many + } + + @Test + public void testGetAWTColorFromName() { + assertEquals(Color.white, ColorUtils.getAWTColorFromName("white")); + assertEquals(Color.white, ColorUtils.getAWTColorFromName("White")); + assertEquals(Color.white, ColorUtils.getAWTColorFromName("WHITE")); + assertEquals(Color.pink, ColorUtils.getAWTColorFromName("pink")); + assertNull(ColorUtils.getAWTColorFromName("mauve")); // no such name + assertNull(ColorUtils.getAWTColorFromName("")); + assertNull(ColorUtils.getAWTColorFromName(null)); + } } -- 1.7.10.2