<td>defaultColour</td>
<td> <em>One of: </em><br>
Clustal, Blosum62, % Identity, Hydrophobic, Zappo, Taylor, Helix
- Propensity, Strand Propensity, Turn Propensity, Buried Index, Nucleotide, T-Coffee Scores, RNA Helices</td>
+ Propensity, Strand Propensity, Turn Propensity, Buried Index, Nucleotide, Purine/Pyrimidine, T-Coffee Scores, RNA Helices</td>
<td>Default is no colour.</td>
</tr>
<tr>
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;
FeatureColourI col = getFeatureStyle(name.getText());
if (col == null)
{
- Color generatedColour = UserColourScheme
+ Color generatedColour = ColorUtils
.createColourFromName(name.getText());
col = new FeatureColour(generatedColour);
}
}
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)
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;
{
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;
}
import jalview.javascript.MouseOverStructureListener;
import jalview.structure.SelectionListener;
import jalview.structure.StructureSelectionManager;
+import jalview.util.ColorUtils;
import jalview.util.HttpUtils;
import jalview.util.MessageManager;
{
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()
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.SortedMap;
import java.util.TreeMap;
/**
SequenceI[][] sequence, SequenceRenderer sr, FeatureRenderer fr,
AlignmentI alignment)
{
- Map<Color, Map<Integer, Map<String, List<int[]>>>> colourMap = buildColoursMap(
+ Map<Color, SortedMap<Integer, Map<String, List<int[]>>>> colourMap = buildColoursMap(
ssm, files, sequence, sr, fr, alignment);
List<String> colourCommands = buildColourCommands(colourMap);
* @return
*/
protected static List<String> buildColourCommands(
- Map<Color, Map<Integer, Map<String, List<int[]>>>> colourMap)
+ Map<Color, SortedMap<Integer, Map<String, List<int[]>>>> colourMap)
{
/*
* This version concatenates all commands into a single String (semi-colon
* Ordering is by order of addition (for colours and positions), natural ordering (for models and chains)
* </pre>
*/
- protected static Map<Color, Map<Integer, Map<String, List<int[]>>>> buildColoursMap(
+ protected static Map<Color, SortedMap<Integer, Map<String, List<int[]>>>> buildColoursMap(
StructureSelectionManager ssm, String[] files,
SequenceI[][] sequence, SequenceRenderer sr, FeatureRenderer fr,
AlignmentI alignment)
{
- Map<Color, Map<Integer, Map<String, List<int[]>>>> colourMap = new LinkedHashMap<Color, Map<Integer, Map<String, List<int[]>>>>();
+ Map<Color, SortedMap<Integer, Map<String, List<int[]>>>> colourMap = new LinkedHashMap<Color, SortedMap<Integer, Map<String, List<int[]>>>>();
Color lastColour = null;
for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
{
* @param chain
*/
protected static void addColourRange(
- Map<Color, Map<Integer, Map<String, List<int[]>>>> colourMap,
+ Map<Color, SortedMap<Integer, Map<String, List<int[]>>>> colourMap,
Color colour, int model, int startPos, int endPos, String chain)
{
/*
* Get/initialize map of data for the colour
*/
- Map<Integer, Map<String, List<int[]>>> colourData = colourMap
+ SortedMap<Integer, Map<String, List<int[]>>> colourData = colourMap
.get(colour);
if (colourData == null)
{
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;
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);
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);
}
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);
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;
}
@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
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;
FeatureColourI col = getFeatureStyle(name.getText());
if (col == null)
{
- col = new FeatureColour(UserColourScheme
+ col = new FeatureColour(ColorUtils
.createColourFromName(name.getText()));
}
oldcol = fcol = col;
import java.util.jar.JarOutputStream;
import javax.swing.JInternalFrame;
-import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import org.exolab.castor.xml.Marshaller;
}
else
{
- jGroup.setColour(ColourSchemeProperty.getColourName(sg.cs));
+ jGroup.setColour(sg.cs.getSchemeName());
}
}
else if (sg.cs instanceof jalview.schemes.AnnotationColourGradient)
}
else
{
- jGroup.setColour(ColourSchemeProperty.getColourName(sg.cs));
+ jGroup.setColour(sg.cs.getSchemeName());
}
jGroup.setPidThreshold(sg.cs.getThreshold());
}
else
{
- ac.setColourScheme(ColourSchemeProperty.getColourName(acg
- .getBaseColour()));
+ ac.setColourScheme(ColourSchemeProperty.getColourName(acg.getBaseColour()));
}
ac.setMaxColour(acg.getMaxColour().getRGB());
);
}
- if (viewAnnColour.getColourScheme().equals("None"))
+ if (viewAnnColour.getColourScheme().equals(
+ ResidueColourScheme.NONE))
{
cs = new AnnotationColourGradient(
annAlignment.getAlignmentAnnotation()[i],
}
/*
- * 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
*/
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<String, UserColourScheme> userColourSchemes = UserDefinedColours
.getUserColourSchemes();
colourMenu.add(userDefinedColour);
colourMenu.addSeparator();
- colourMenu.add(abovePIDColour);
colourMenu.add(conservationMenuItem);
+ colourMenu.add(abovePIDColour);
/*
* add some of these items to a ButtonGroup so their
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;
/*
* 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);
}
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)
if (oldColourScheme instanceof UserColourScheme)
{
- schemeName.setText(((UserColourScheme) oldColourScheme).getName());
+ schemeName.setText(((UserColourScheme) oldColourScheme).getSchemeName());
if (((UserColourScheme) oldColourScheme).getLowerCaseColours() != null)
{
caseSensitive.setSelected(true);
if (oldColourScheme instanceof UserColourScheme)
{
- schemeName.setText(((UserColourScheme) oldColourScheme).getName());
+ schemeName.setText(((UserColourScheme) oldColourScheme).getSchemeName());
}
resetButtonPanel(false);
UserColourScheme ucs = loadColours(choice.getAbsolutePath());
Color[] colors = ucs.getColours();
- schemeName.setText(ucs.getName());
+ schemeName.setText(ucs.getSchemeName());
if (ucs.getLowerCaseColours() != null)
{
coloursFound.append("|");
}
coloursFound.append(file);
- userColourSchemes.put(ucs.getName(), ucs);
+ userColourSchemes.put(ucs.getSchemeName(), ucs);
}
} catch (Exception ex)
{
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)
{
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;
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)
{
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
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++)
{
{
if (annotations[j] != null)
{
- annotations[j].colour = ucs.findColour('A');
+ annotations[j].colour = awtColour;
}
}
}
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)
{
}
}
}
- if (annotation == null)
- {
- return;
- }
}
void addGroup(AlignmentI al, StringTokenizer st)
}
else if (key.equalsIgnoreCase("outlineColour"))
{
- sg.setOutlineColour(new UserColourScheme(value).findColour('A'));
+ sg.setOutlineColour(ColorUtils.parseColourString(value));
}
else if (key.equalsIgnoreCase("displayBoxes"))
{
}
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"))
{
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"))
{
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;
* 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);
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;
{
// 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);
}
}
{
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());
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;
}
}
}
}
- globalColourScheme = ColourSchemeProperty.getColourName(viewport
- .getGlobalColourScheme());
+ globalColourScheme = viewport.getGlobalColourScheme().getSchemeName();
setDisplayedFeatures(viewport.getFeaturesDisplayed());
showSeqFeatures = viewport.isShowSequenceFeatures();
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;
pasteMenu.setMnemonic('P');
reload.setMnemonic('R');
}
-
- // Map<String, UserColourScheme> 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
// colours.add(covariationColour);
colours.add(tcoffeeColour);
colours.add(RNAInteractionColour);
- setColourSelected(Cache.getDefault(Preferences.DEFAULT_COLOUR, "None"));
+ setColourSelected(Cache.getDefault(Preferences.DEFAULT_COLOUR,
+ ResidueColourScheme.NONE));
}
*
* @return DOCUMENT ME!
*/
+ @Override
public Color findColour(char c)
{
return Color.red;
{
seqAssociated = sassoc;
}
+
+ @Override
+ public String getSchemeName()
+ {
+ return "Annotation";
+ }
}
ColourSchemeI newcs = super.applyTo(sg, hiddenRepSequences);
return newcs;
}
+
+ @Override
+ public boolean isPeptideSpecific()
+ {
+ return true;
+ }
+
+ @Override
+ public String getSchemeName()
+ {
+ return JalviewColourScheme.Blosum62.toString();
+ }
}
{
return new Color(0, (float) (1.0 - c), c);
}
+
+ @Override
+ public boolean isPeptideSpecific()
+ {
+ return true;
+ }
+
+ @Override
+ public String getSchemeName()
+ {
+ return JalviewColourScheme.Buried.toString();
+ }
}
import jalview.datamodel.SequenceI;
import java.awt.Color;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
private static final int SIXTY = 60;
- /*
- * Map from conventional colour names to Clustal version of the same
- */
- private static Map<Color, Color> colhash = new HashMap<Color, Color>();
+ 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;
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<SequenceI, SequenceCollectionI> hiddenReps)
{
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)
{
{
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);
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]; // %
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
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
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]; // -
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]; // -
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];
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;
{
if (conses[27].isConserved(cons2, j, size, includeGaps))
{
- currentColour = colhash.get(Color.PINK);
+ currentColour = ClustalColour.PINK.colour;
}
}
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();
}
}
*/
package jalview.schemes;
+import jalview.analysis.Conservation;
import jalview.datamodel.AnnotatedCollectionI;
import jalview.datamodel.ProfilesI;
import jalview.datamodel.SequenceCollectionI;
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
Map<SequenceI, SequenceCollectionI> 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
*/
ColourSchemeI applyTo(AnnotatedCollectionI sg,
Map<SequenceI, SequenceCollectionI> 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();
}
package jalview.schemes;
import jalview.datamodel.AnnotatedCollectionI;
+import jalview.util.ColorUtils;
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
+ * <ul>
+ * <li>Clustal</li>
+ * <li>Blosum62</li>
+ * <li>% Identity</li>
+ * <li>Hydrophobic</li>
+ * <li>Zappo</li>
+ * <li>Taylor</li>
+ * <li>Helix Propensity</li>
+ * <li>Strand Propensity</li>
+ * <li>Turn Propensity</li>
+ * <li>Buried Index</li>
+ * <li>Nucleotide</li>
+ * <li>Purine/Pyrimidine</li>
+ * <li>T-Coffee Scores</li>
+ * <li>RNA Helices</li>
+ * <li>User Defined</li>
+ * <li>None</li>
+ * <li>an AWT colour name e.g. red</li>
+ * <li>residue colours list e.g. D,E=red;K,R,H=0022FF;c=yellow</li>
+ * </ul>
+ * 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;
// 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();
+ }
+
}
return currentColour;
}
+ @Override
+ public boolean isNucleotideSpecific()
+ {
+ return true;
+ }
+
+ @Override
+ public String getSchemeName()
+ {
+ return "Covariation";
+ }
}
import jalview.api.FeatureColourI;
import jalview.datamodel.SequenceFeature;
+import jalview.util.ColorUtils;
import jalview.util.Format;
import java.awt.Color;
/*
* 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: "
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
{
if (isColourByLabel())
{
- return UserColourScheme
+ return ColorUtils
.createColourFromName(feature.getDescription());
}
}
}
+ @Override
+ public String getSchemeName()
+ {
+ return "Follower";
+ }
+
}
{
return new Color(c, (float) 1.0 - c, c);
}
+
+ @Override
+ public boolean isPeptideSpecific()
+ {
+ return true;
+ }
+
+ @Override
+ public String getSchemeName()
+ {
+ return JalviewColourScheme.Helix.toString();
+ }
}
{
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();
+ }
}
--- /dev/null
+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<String, JalviewColourScheme> names = new HashMap<String, JalviewColourScheme>();
+
+ 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;
+ }
+}
return currentColour;
}
+
+ @Override
+ public boolean isNucleotideSpecific()
+ {
+ return true;
+ }
+
+ @Override
+ public String getSchemeName()
+ {
+ return JalviewColourScheme.Nucleotide.toString();
+ }
}
return currentColour;
}
+
+ @Override
+ public String getSchemeName()
+ {
+ return JalviewColourScheme.PID.toString();
+ }
}
return currentColour;
}
+
+ @Override
+ public boolean isNucleotideSpecific()
+ {
+ return true;
+ }
+
+ @Override
+ public String getSchemeName()
+ {
+ return JalviewColourScheme.PurinePyrimidine.toString();
+ }
}
package jalview.schemes;
import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentI;
import jalview.datamodel.AnnotatedCollectionI;
import jalview.datamodel.SequenceCollectionI;
import jalview.datamodel.SequenceI;
{
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();
+ }
+}
return currentColour;
}
+
+ @Override
+ public boolean isNucleotideSpecific()
+ {
+ return true;
+ }
+
+ @Override
+ public String getSchemeName()
+ {
+ return "RNA Interaction type";
+ }
}
package jalview.schemes;
import jalview.analysis.Conservation;
+import jalview.datamodel.AlignmentI;
import jalview.datamodel.AnnotatedCollectionI;
import jalview.datamodel.ProfileI;
import jalview.datamodel.ProfilesI;
*/
public class ResidueColourScheme implements ColourSchemeI
{
+ public static final String NONE = "None";
+
final int[] symbolIndex;
boolean conservationColouring = false;
}
/**
+ * 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
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";
+ }
}
{
return new Color(c, (float) 0.0, (float) 1.0 - c);
}
+
+ @Override
+ public String getSchemeName()
+ {
+ return "Score";
+ }
}
{
return new Color(c, c, (float) 1.0 - c);
}
+
+ @Override
+ public boolean isPeptideSpecific()
+ {
+ return true;
+ }
+
+ @Override
+ public String getSchemeName()
+ {
+ return JalviewColourScheme.Strand.toString();
+ }
}
{
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();
+ }
}
{
super(ResidueProperties.aaIndex, ResidueProperties.taylor, 0);
}
+
+ @Override
+ public boolean isPeptideSpecific()
+ {
+ return true;
+ }
+
+ @Override
+ public String getSchemeName()
+ {
+ return JalviewColourScheme.Taylor.toString();
+ }
}
{
return new Color(c, 1 - c, 1 - c);
}
+
+ @Override
+ public boolean isPeptideSpecific()
+ {
+ return true;
+ }
+
+ @Override
+ public String getSchemeName()
+ {
+ return JalviewColourScheme.Turn.toString();
+ }
}
import jalview.datamodel.AnnotatedCollectionI;
import jalview.datamodel.SequenceCollectionI;
import jalview.datamodel.SequenceI;
+import jalview.util.ColorUtils;
import java.awt.Color;
import java.util.Map;
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];
}
/**
- * Parses a string into a Color, where the accepted formats are
- * <ul>
- * <li>an AWT colour name e.g. white</li>
- * <li>a hex colour value (without prefix) e.g. ff0000</li>
- * <li>an rgb triple e.g. 100,50,150</li>
- * </ul>
- *
- * @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)
*
* <pre>
{
if (lowerCaseColours[i] == null)
{
- lowerCaseColours[i] = getColourFromString(colour);
+ lowerCaseColours[i] = ColorUtils.parseColourString(colour);
}
}
{
lowerCaseColours = new Color[23];
}
- lowerCaseColours[colIndex] = getColourFromString(colour);
+ lowerCaseColours[colIndex] = ColorUtils.parseColourString(colour);
}
else
{
- colors[colIndex] = getColourFromString(colour);
+ colors[colIndex] = ColorUtils.parseColourString(colour);
}
}
}
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();
+ }
+
}
{
super(ResidueProperties.aaIndex, ResidueProperties.zappo, 0);
}
+
+ @Override
+ public boolean isPeptideSpecific()
+ {
+ return true;
+ }
+
+ @Override
+ public String getSchemeName()
+ {
+ return JalviewColourScheme.Zappo.toString();
+ }
}
return new Color(red, green, blue);
}
}
+
+ /**
+ * Parses a string into a Color, where the accepted formats are
+ * <ul>
+ * <li>an AWT colour name e.g. white</li>
+ * <li>a hex colour value (without prefix) e.g. ff0000</li>
+ * <li>an rgb triple e.g. 100,50,150</li>
+ * </ul>
+ *
+ * @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;
+ }
}
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;
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);
}
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;
annot.description += "<br/>" + threshNote;
}
annot.description += "</html>";
- Color col = UserColourScheme.createColourFromName(typeName
+ Color col = ColorUtils.createColourFromName(typeName
+ scr.getMethod());
for (int p = 0, ps = annot.annotations.length; p < ps; p++)
{
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;
@Test(groups = { "Functional" })
public void testAddColourRange()
{
- Map<Color, Map<Integer, Map<String, List<int[]>>>> map = new LinkedHashMap<Color, Map<Integer, Map<String, List<int[]>>>>();
+ Map<Color, SortedMap<Integer, Map<String, List<int[]>>>> map = new LinkedHashMap<Color, SortedMap<Integer, Map<String, List<int[]>>>>();
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");
public void testBuildColourCommands()
{
- Map<Color, Map<Integer, Map<String, List<int[]>>>> map = new LinkedHashMap<Color, Map<Integer, Map<String, List<int[]>>>>();
+ Map<Color, SortedMap<Integer, Map<String, List<int[]>>>> map = new LinkedHashMap<Color, SortedMap<Integer, Map<String, List<int[]>>>>();
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");
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(
.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));
--- /dev/null
+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");
+ }
+}
import jalview.datamodel.SequenceFeature;
import jalview.gui.JvOptionPane;
+import jalview.util.ColorUtils;
import jalview.util.Format;
import java.awt.Color;
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));
}
--- /dev/null
+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);
+ }
+}
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;
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());
+ }
}
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;
}
@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");
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));
+ }
}