import jalview.datamodel.SequenceI;
import jalview.schemes.ColourSchemeI;
import jalview.schemes.ColourSchemeProperty;
-import jalview.schemes.ResidueProperties;
-import jalview.schemes.UserColourScheme;
+import jalview.util.ColorUtils;
+import java.awt.Color;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
}
/**
- * convenience method for pre-2.8.3 annotation files which have no view,
- * hidden columns or hidden row keywords.
+ * convenience method for pre-2.9 annotation files which have no view, hidden
+ * columns or hidden row keywords.
*
* @param annotations
* @param list
}
else
{
- graphGroup_refs.put(key, new Object[]
- { refSeq, refGroup });
+ graphGroup_refs.put(key, new Object[] { refSeq, refGroup });
graphGroup.put(key, row.label);
}
}
text.append(properties.get(key));
}
// TODO: output alignment visualization settings here if required
- // iterate through one or more views, defining, marking columns and rows as visible/hidden, and emmitting view properties.
- // View specific annotation is
+ // iterate through one or more views, defining, marking columns and rows
+ // as visible/hidden, and emmitting view properties.
+ // View specific annotation is
}
return text.toString();
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)
{
String refSeqId = null;
public boolean annotateAlignmentView(AlignViewportI viewport,
- String file, String protocol)
+ String file, DataSourceType protocol)
{
ColumnSelection colSel = viewport.getColumnSelection();
if (colSel == null)
}
boolean rslt = readAnnotationFile(viewport.getAlignment(), colSel,
file, protocol);
- if (rslt
- && (colSel.hasSelectedColumns() || colSel.hasHiddenColumns()))
+ if (rslt && (colSel.hasSelectedColumns() || colSel.hasHiddenColumns()))
{
viewport.setColumnSelection(colSel);
}
return rslt;
}
+
public boolean readAnnotationFile(AlignmentI al, String file,
- String protocol)
+ DataSourceType sourceType)
{
- return readAnnotationFile(al, null, file, protocol);
+ return readAnnotationFile(al, null, file, sourceType);
}
public boolean readAnnotationFile(AlignmentI al, ColumnSelection colSel,
- String file, String protocol)
+ String file, DataSourceType sourceType)
{
BufferedReader in = null;
try
{
- if (protocol.equals(AppletFormatAdapter.FILE))
+ if (sourceType == DataSourceType.FILE)
{
in = new BufferedReader(new FileReader(file));
}
- else if (protocol.equals(AppletFormatAdapter.URL))
+ else if (sourceType == DataSourceType.URL)
{
URL url = new URL(file);
in = new BufferedReader(new InputStreamReader(url.openStream()));
}
- else if (protocol.equals(AppletFormatAdapter.PASTE))
+ else if (sourceType == DataSourceType.PASTE)
{
in = new BufferedReader(new StringReader(file));
}
- else if (protocol.equals(AppletFormatAdapter.CLASSLOADER))
+ else if (sourceType == DataSourceType.CLASSLOADER)
{
java.io.InputStream is = getClass().getResourceAsStream("/" + file);
if (is != null)
private static String GRAPHLINE = "GRAPHLINE", COMBINE = "COMBINE";
public boolean parseAnnotationFrom(AlignmentI al, ColumnSelection colSel,
- BufferedReader in)
- throws Exception
+ BufferedReader in) throws Exception
{
nlinesread = 0;
ArrayList<Object[]> combineAnnotation_calls = new ArrayList<Object[]>();
else if (token.equalsIgnoreCase(COMBINE))
{
// keep a record of current state and resolve groupRef at end
- combineAnnotation_calls.add(new Object[]
- { st, refSeq, groupRef });
+ combineAnnotation_calls
+ .add(new Object[] { st, refSeq, groupRef });
modified = true;
continue;
}
else if (token.equalsIgnoreCase(GRAPHLINE))
{
// resolve at end
- deferredAnnotation_calls.add(new Object[]
- { GRAPHLINE, st, refSeq, groupRef });
+ deferredAnnotation_calls.add(new Object[] { GRAPHLINE, st,
+ refSeq, groupRef });
modified = true;
continue;
}
(SequenceI) _deferred_args[2], // refSeq
(_deferred_args[3] == null) ? null : groupRefLookup
.get(_deferred_args[3]) // the reference
- // group, or null
+ // group, or null
);
}
}
(SequenceI) _combine_args[1], // refSeq
(_combine_args[2] == null) ? null : groupRefLookup
.get(_combine_args[2]) // the reference group,
- // or null
+ // or null
);
}
}
private void parseHideCols(ColumnSelection colSel, String nextToken)
{
- StringTokenizer inval = new StringTokenizer(nextToken,",");
+ StringTokenizer inval = new StringTokenizer(nextToken, ",");
while (inval.hasMoreTokens())
{
String range = inval.nextToken().trim();
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
}
}
if (hasSymbols
- && (token.equals("H") || token.equals("E")
- || token.equals("S") || token.equals(" ")))
+ && (token.length() == 1 && "()<>[]{}AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"
+ .contains(token)))
{
// Either this character represents a helix or sheet
// or an integer which can be displayed
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("line " + nlinesread + ": 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("colour"))
{
- sg.cs = ColourSchemeProperty.getColour(al, value);
+ sg.cs = ColourSchemeProperty.getColourScheme(al, value);
}
else if (key.equalsIgnoreCase("pidThreshold"))
{
else if (key.equalsIgnoreCase("consThreshold"))
{
sg.cs.setConservationInc(Integer.parseInt(value));
- Conservation c = new Conservation("Group",
- ResidueProperties.propHash, 3, sg.getSequences(null),
+ Conservation c = new Conservation("Group", sg.getSequences(null),
sg.getStartRes(), sg.getEndRes() + 1);
c.calculate();
}
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'));
+ Color idColour = ColorUtils.parseColourString(value);
+ sg.setIdColour(idColour == null ? Color.black : idColour);
}
else if (key.equalsIgnoreCase("hide"))
{
*/
public String printCSVAnnotations(AlignmentAnnotation[] annotations)
{
+ if (annotations == null)
+ {
+ return "";
+ }
StringBuffer sp = new StringBuffer();
for (int i = 0; i < annotations.length; i++)
{