- * Process a feature type colour specification
- *
- * @param line
- * the current input line (for error messages only)
- * @param featureType
- * the first token on the line
- * @param gffColumns
- * holds tokens on the line
- * @param colours
- * map to which to add derived colour specification
- */
- protected void parseFeatureColour(String line, String featureType,
- String[] gffColumns, Map<String, Object> colours)
- {
- Object colour = null;
- String colscheme = gffColumns[1];
- if (colscheme.indexOf("|") > -1
- || colscheme.trim().equalsIgnoreCase("label"))
- {
- colour = parseGraduatedColourScheme(line, colscheme);
- }
- else
- {
- UserColourScheme ucs = new UserColourScheme(colscheme);
- colour = ucs.findColour('A');
- }
- if (colour != null)
- {
- colours.put(featureType, colour);
- }
- }
-
- /**
- * Parse a Jalview graduated colour descriptor
- *
- * @param line
- * @param colourDescriptor
- * @return
- */
- protected GraduatedColor parseGraduatedColourScheme(String line,
- String colourDescriptor)
- {
- // Parse '|' separated graduated colourscheme fields:
- // [label|][mincolour|maxcolour|[absolute|]minvalue|maxvalue|thresholdtype|thresholdvalue]
- // can either provide 'label' only, first is optional, next two
- // colors are required (but may be
- // left blank), next is optional, nxt two min/max are required.
- // first is either 'label'
- // first/second and third are both hexadecimal or word equivalent
- // colour.
- // next two are values parsed as floats.
- // fifth is either 'above','below', or 'none'.
- // sixth is a float value and only required when fifth is either
- // 'above' or 'below'.
- StringTokenizer gcol = new StringTokenizer(colourDescriptor, "|", true);
- // set defaults
- float min = Float.MIN_VALUE, max = Float.MAX_VALUE;
- boolean labelCol = false;
- // Parse spec line
- String mincol = gcol.nextToken();
- if (mincol == "|")
- {
- System.err
- .println("Expected either 'label' or a colour specification in the line: "
- + line);
- return null;
- }
- String maxcol = null;
- if (mincol.toLowerCase().indexOf("label") == 0)
- {
- labelCol = true;
- mincol = (gcol.hasMoreTokens() ? gcol.nextToken() : null); // skip '|'
- mincol = (gcol.hasMoreTokens() ? gcol.nextToken() : null);
- }
- String abso = null, minval, maxval;
- if (mincol != null)
- {
- // at least four more tokens
- if (mincol.equals("|"))
- {
- mincol = "";
- }
- else
- {
- gcol.nextToken(); // skip next '|'
- }
- // continue parsing rest of line
- maxcol = gcol.nextToken();
- if (maxcol.equals("|"))
- {
- maxcol = "";
- }
- else
- {
- gcol.nextToken(); // skip next '|'
- }
- abso = gcol.nextToken();
- gcol.nextToken(); // skip next '|'
- if (abso.toLowerCase().indexOf("abso") != 0)
- {
- minval = abso;
- abso = null;
- }
- else
- {
- minval = gcol.nextToken();
- gcol.nextToken(); // skip next '|'
- }
- maxval = gcol.nextToken();
- if (gcol.hasMoreTokens())
- {
- gcol.nextToken(); // skip next '|'
- }
- try
- {
- if (minval.length() > 0)
- {
- min = Float.valueOf(minval);
- }
- } catch (Exception e)
- {
- System.err
- .println("Couldn't parse the minimum value for graduated colour for type ("
- + colourDescriptor
- + ") - did you misspell 'auto' for the optional automatic colour switch ?");
- e.printStackTrace();
- }
- try
- {
- if (maxval.length() > 0)
- {
- max = Float.valueOf(maxval);
- }
- } catch (Exception e)
- {
- System.err
- .println("Couldn't parse the maximum value for graduated colour for type ("
- + colourDescriptor + ")");
- e.printStackTrace();
- }
- }
- else
- {
- // add in some dummy min/max colours for the label-only
- // colourscheme.
- mincol = "FFFFFF";
- maxcol = "000000";
- }
-
- GraduatedColor colour = null;
- try
- {
- colour = new GraduatedColor(
- new UserColourScheme(mincol).findColour('A'),
- new UserColourScheme(maxcol).findColour('A'), min, max);
- } catch (Exception e)
- {
- System.err.println("Couldn't parse the graduated colour scheme ("
- + colourDescriptor + ")");
- e.printStackTrace();
- }
- if (colour != null)
- {
- colour.setColourByLabel(labelCol);
- colour.setAutoScaled(abso == null);
- // add in any additional parameters
- String ttype = null, tval = null;
- if (gcol.hasMoreTokens())
- {
- // threshold type and possibly a threshold value
- ttype = gcol.nextToken();
- if (ttype.toLowerCase().startsWith("below"))
- {
- colour.setThreshType(AnnotationColourGradient.BELOW_THRESHOLD);
- }
- else if (ttype.toLowerCase().startsWith("above"))
- {
- colour.setThreshType(AnnotationColourGradient.ABOVE_THRESHOLD);
- }
- else
- {
- colour.setThreshType(AnnotationColourGradient.NO_THRESHOLD);
- if (!ttype.toLowerCase().startsWith("no"))
- {
- System.err.println("Ignoring unrecognised threshold type : "
- + ttype);
- }
- }
- }
- if (colour.getThreshType() != AnnotationColourGradient.NO_THRESHOLD)
- {
- try
- {
- gcol.nextToken();
- tval = gcol.nextToken();
- colour.setThresh(new Float(tval).floatValue());
- } catch (Exception e)
- {
- System.err.println("Couldn't parse threshold value as a float: ("
- + tval + ")");
- e.printStackTrace();
- }
- }
- // parse the thresh-is-min token ?
- if (gcol.hasMoreTokens())
- {
- System.err
- .println("Ignoring additional tokens in parameters in graduated colour specification\n");
- while (gcol.hasMoreTokens())
- {
- System.err.println("|" + gcol.nextToken());
- }
- System.err.println("\n");
- }
- }
- return colour;
- }
-
- /**