");
phyre2InfoBuilder
.append("Phyre2 Template Info |
");
if (aRange != null && !aRange.isEmpty())
{
phyre2InfoBuilder.append("").append("Aligned range")
.append(" | ").append(aRange).append(" |
");
}
if (coverage != null && !coverage.isEmpty())
{
phyre2InfoBuilder.append("").append("Coverage")
.append(" | ").append(coverage).append(" |
");
}
if (confidence != null && !confidence.isEmpty())
{
phyre2InfoBuilder.append("").append("Confidence")
.append(" | ").append(confidence).append(" |
");
}
if (pid != null && !pid.isEmpty())
{
phyre2InfoBuilder.append("").append("%.i.d")
.append(" | ").append(pid).append(" |
");
}
if (otherInfo != null && !otherInfo.isEmpty())
{
phyre2InfoBuilder.append("").append("Other information")
.append(" | ").append(otherInfo).append(" |
");
}
phyre2InfoBuilder.append("
");
return phyre2InfoBuilder.toString();
}
private String resolveAbsolute(String relURI)
{
if (relURI.indexOf(":/") > -1 || relURI.startsWith("/")
|| "".equals(baseUri) || relURI.startsWith(baseUri))
{
return relURI;
}
return baseUri + relURI;
}
private void parseHideCols(ColumnSelection colSel, String nextToken)
{
StringTokenizer inval = new StringTokenizer(nextToken, ",");
while (inval.hasMoreTokens())
{
String range = inval.nextToken().trim();
int from, to = range.indexOf("-");
if (to == -1)
{
from = to = Integer.parseInt(range);
if (from >= 0)
{
colSel.hideColumns(from, to);
}
}
else
{
from = Integer.parseInt(range.substring(0, to));
if (to < range.length() - 1)
{
to = Integer.parseInt(range.substring(to + 1));
}
else
{
to = from;
}
if (from > 0 && to >= from)
{
colSel.hideColumns(from, to);
}
}
}
}
private Object autoAnnotsKey(AlignmentAnnotation annotation,
SequenceI refSeq, String groupRef)
{
return annotation.graph + "\t" + annotation.label + "\t"
+ annotation.description + "\t"
+ (refSeq != null ? refSeq.getDisplayId(true) : "");
}
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
String desc = null, displayChar = null;
char ss = ' '; // secondaryStructure
float value = 0;
boolean parsedValue = false, dcset = false;
// find colour here
java.awt.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));
if (i > 0 && string.charAt(i - 1) == ',')
{
// clip the preceding comma as well
i--;
}
string = string.substring(0, i) + string.substring(j + 1);
}
StringTokenizer st = new StringTokenizer(string, ",", true);
String token;
boolean seenContent = false;
int pass = 0;
while (st.hasMoreTokens())
{
pass++;
token = st.nextToken().trim();
if (token.equals(","))
{
if (!seenContent && parsedValue && !dcset)
{
// allow the value below the bar/line to be empty
dcset = true;
displayChar = " ";
}
seenContent = false;
continue;
}
else
{
seenContent = true;
}
if (!parsedValue)
{
try
{
displayChar = token;
// foo
value = new Float(token).floatValue();
parsedValue = true;
continue;
} catch (NumberFormatException ex)
{
}
}
else
{
if (token.length() == 1)
{
displayChar = token;
}
}
if (hasSymbols
&& (token.length() == 1 && "()<>[]{}AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"
.contains(token)))
{
// Either this character represents a helix or sheet
// or an integer which can be displayed
ss = token.charAt(0);
if (displayChar.equals(token.substring(0, 1)))
{
displayChar = "";
}
}
else if (desc == null || (parsedValue && pass > 2))
{
desc = token;
}
}
// if (!dcset && string.charAt(string.length() - 1) == ',')
// {
// displayChar = " "; // empty display char symbol.
// }
if (displayChar != null && desc != null && desc.length() == 1)
{
if (displayChar.length() > 1)
{
// switch desc and displayChar - legacy support
String tmp = displayChar;
displayChar = desc;
desc = tmp;
}
else
{
if (displayChar.equals(desc))
{
// duplicate label - hangover from the 'robust parser' above
desc = null;
}
}
}
Annotation anot = new Annotation(displayChar, desc, ss, value);
anot.colour = colour;
return anot;
}
void colourAnnotations(AlignmentI al, String label, String colour)
{
UserColourScheme ucs = new UserColourScheme(colour);
Annotation[] annotations;
for (int i = 0; i < al.getAlignmentAnnotation().length; i++)
{
if (al.getAlignmentAnnotation()[i].label.equalsIgnoreCase(label))
{
annotations = al.getAlignmentAnnotation()[i].annotations;
for (int j = 0; j < annotations.length; j++)
{
if (annotations[j] != null)
{
annotations[j].colour = ucs.findColour('A');
}
}
}
}
}
void combineAnnotations(AlignmentI al, int combineCount,
StringTokenizer st, SequenceI seqRef, SequenceGroup groupRef)
{
String group = st.nextToken();
// First make sure we are not overwriting the graphIndex
int graphGroup = 0;
if (al.getAlignmentAnnotation() != null)
{
for (int i = 0; i < al.getAlignmentAnnotation().length; i++)
{
AlignmentAnnotation aa = al.getAlignmentAnnotation()[i];
if (aa.graphGroup > graphGroup)
{
// try to number graphGroups in order of occurence.
graphGroup = aa.graphGroup + 1;
}
if (aa.sequenceRef == seqRef && aa.groupRef == groupRef
&& aa.label.equalsIgnoreCase(group))
{
if (aa.graphGroup > -1)
{
graphGroup = aa.graphGroup;
}
else
{
if (graphGroup <= combineCount)
{
graphGroup = combineCount + 1;
}
aa.graphGroup = graphGroup;
}
break;
}
}
// Now update groups
while (st.hasMoreTokens())
{
group = st.nextToken();
for (int i = 0; i < al.getAlignmentAnnotation().length; i++)
{
AlignmentAnnotation aa = al.getAlignmentAnnotation()[i];
if (aa.sequenceRef == seqRef && aa.groupRef == groupRef
&& aa.label.equalsIgnoreCase(group))
{
aa.graphGroup = graphGroup;
break;
}
}
}
}
else
{
System.err
.println("Couldn't combine annotations. None are added to alignment yet!");
}
}
void addLine(AlignmentI al, StringTokenizer st, SequenceI seqRef,
SequenceGroup groupRef)
{
String group = st.nextToken();
AlignmentAnnotation annotation = null, alannot[] = al
.getAlignmentAnnotation();
float value = new Float(st.nextToken()).floatValue();
String label = st.hasMoreTokens() ? st.nextToken() : null;
java.awt.Color colour = null;
if (st.hasMoreTokens())
{
UserColourScheme ucs = new UserColourScheme(st.nextToken());
colour = ucs.findColour('A');
}
if (alannot != null)
{
for (int i = 0; i < alannot.length; i++)
{
if (alannot[i].label.equalsIgnoreCase(group)
&& (seqRef == null || alannot[i].sequenceRef == seqRef)
&& (groupRef == null || alannot[i].groupRef == groupRef))
{
alannot[i].setThreshold(new GraphLine(value, label, colour));
}
}
}
if (annotation == null)
{
return;
}
}
void addGroup(AlignmentI al, StringTokenizer st)
{
SequenceGroup sg = new SequenceGroup();
sg.setName(st.nextToken());
String rng = "";
try
{
rng = st.nextToken();
if (rng.length() > 0 && !rng.startsWith("*"))
{
sg.setStartRes(Integer.parseInt(rng) - 1);
}
else
{
sg.setStartRes(0);
}
rng = st.nextToken();
if (rng.length() > 0 && !rng.startsWith("*"))
{
sg.setEndRes(Integer.parseInt(rng) - 1);
}
else
{
sg.setEndRes(al.getWidth() - 1);
}
} catch (Exception e)
{
System.err
.println("Couldn't parse Group Start or End Field as '*' or a valid column or sequence index: '"
+ rng + "' - assuming alignment width for group.");
// assume group is full width
sg.setStartRes(0);
sg.setEndRes(al.getWidth() - 1);
}
String index = st.nextToken();
if (index.equals("-1"))
{
while (st.hasMoreElements())
{
sg.addSequence(al.findName(st.nextToken()), false);
}
}
else
{
StringTokenizer st2 = new StringTokenizer(index, ",");
while (st2.hasMoreTokens())
{
String tmp = st2.nextToken();
if (tmp.equals("*"))
{
for (int i = 0; i < al.getHeight(); i++)
{
sg.addSequence(al.getSequenceAt(i), false);
}
}
else if (tmp.indexOf("-") >= 0)
{
StringTokenizer st3 = new StringTokenizer(tmp, "-");
int start = (Integer.parseInt(st3.nextToken()));
int end = (Integer.parseInt(st3.nextToken()));
if (end > start)
{
for (int i = start; i <= end; i++)
{
sg.addSequence(al.getSequenceAt(i - 1), false);
}
}
}
else
{
sg.addSequence(al.getSequenceAt(Integer.parseInt(tmp) - 1), false);
}
}
}
if (refSeq != null)
{
sg.setStartRes(refSeq.findIndex(sg.getStartRes() + 1) - 1);
sg.setEndRes(refSeq.findIndex(sg.getEndRes() + 1) - 1);
sg.setSeqrep(refSeq);
}
if (sg.getSize() > 0)
{
al.addGroup(sg);
}
}
void addRowProperties(AlignmentI al, StringTokenizer st)
{
String label = st.nextToken(), keyValue, key, value;
boolean scaletofit = false, centerlab = false, showalllabs = false;
while (st.hasMoreTokens())
{
keyValue = st.nextToken();
key = keyValue.substring(0, keyValue.indexOf("="));
value = keyValue.substring(keyValue.indexOf("=") + 1);
if (key.equalsIgnoreCase("scaletofit"))
{
scaletofit = Boolean.valueOf(value).booleanValue();
}
if (key.equalsIgnoreCase("showalllabs"))
{
showalllabs = Boolean.valueOf(value).booleanValue();
}
if (key.equalsIgnoreCase("centrelabs"))
{
centerlab = Boolean.valueOf(value).booleanValue();
}
AlignmentAnnotation[] alr = al.getAlignmentAnnotation();
if (alr != null)
{
for (int i = 0; i < alr.length; i++)
{
if (alr[i].label.equalsIgnoreCase(label))
{
alr[i].centreColLabels = centerlab;
alr[i].scaleColLabel = scaletofit;
alr[i].showAllColLabels = showalllabs;
}
}
}
}
}
void addProperties(AlignmentI al, StringTokenizer st)
{
// So far we have only added groups to the annotationHash,
// the idea is in the future properties can be added to
// alignments, other annotations etc
if (al.getGroups() == null)
{
return;
}
String name = st.nextToken();
SequenceGroup sg = null;
for (SequenceGroup _sg : al.getGroups())
{
if ((sg = _sg).getName().equals(name))
{
break;
}
else
{
sg = null;
}
}
if (sg != null)
{
String keyValue, key, value;
ColourSchemeI def = sg.cs;
sg.cs = null;
while (st.hasMoreTokens())
{
keyValue = st.nextToken();
key = keyValue.substring(0, keyValue.indexOf("="));
value = keyValue.substring(keyValue.indexOf("=") + 1);
if (key.equalsIgnoreCase("description"))
{
sg.setDescription(value);
}
else if (key.equalsIgnoreCase("colour"))
{
sg.cs = ColourSchemeProperty.getColour(al, value);
}
else if (key.equalsIgnoreCase("pidThreshold"))
{
sg.cs.setThreshold(Integer.parseInt(value), true);
}
else if (key.equalsIgnoreCase("consThreshold"))
{
sg.cs.setConservationInc(Integer.parseInt(value));
Conservation c = new Conservation("Group", sg.getSequences(null),
sg.getStartRes(), sg.getEndRes() + 1);
c.calculate();
c.verdict(false, 25); // TODO: refer to conservation percent threshold
sg.cs.setConservation(c);
}
else if (key.equalsIgnoreCase("outlineColour"))
{
sg.setOutlineColour(new UserColourScheme(value).findColour('A'));
}
else if (key.equalsIgnoreCase("displayBoxes"))
{
sg.setDisplayBoxes(Boolean.valueOf(value).booleanValue());
}
else if (key.equalsIgnoreCase("showUnconserved"))
{
sg.setShowNonconserved(Boolean.valueOf(value).booleanValue());
}
else if (key.equalsIgnoreCase("displayText"))
{
sg.setDisplayText(Boolean.valueOf(value).booleanValue());
}
else if (key.equalsIgnoreCase("colourText"))
{
sg.setColourText(Boolean.valueOf(value).booleanValue());
}
else if (key.equalsIgnoreCase("textCol1"))
{
sg.textColour = new UserColourScheme(value).findColour('A');
}
else if (key.equalsIgnoreCase("textCol2"))
{
sg.textColour2 = new UserColourScheme(value).findColour('A');
}
else if (key.equalsIgnoreCase("textColThreshold"))
{
sg.thresholdTextColour = Integer.parseInt(value);
}
else if (key.equalsIgnoreCase("idColour"))
{
// consider warning if colour doesn't resolve to a real colour
sg.setIdColour((def = new UserColourScheme(value))
.findColour('A'));
}
else if (key.equalsIgnoreCase("hide"))
{
// see bug https://mantis.lifesci.dundee.ac.uk/view.php?id=25847
sg.setHidereps(true);
}
else if (key.equalsIgnoreCase("hidecols"))
{
// see bug https://mantis.lifesci.dundee.ac.uk/view.php?id=25847
sg.setHideCols(true);
}
sg.recalcConservation();
}
if (sg.cs == null)
{
sg.cs = def;
}
}
}
void setBelowAlignment(AlignmentI al, StringTokenizer st)
{
String token;
AlignmentAnnotation aa, ala[] = al.getAlignmentAnnotation();
if (ala == null)
{
System.err
.print("Warning - no annotation to set below for sequence associated annotation:");
}
while (st.hasMoreTokens())
{
token = st.nextToken();
if (ala == null)
{
System.err.print(" " + token);
}
else
{
for (int i = 0; i < al.getAlignmentAnnotation().length; i++)
{
aa = al.getAlignmentAnnotation()[i];
if (aa.sequenceRef == refSeq && aa.label.equals(token))
{
aa.belowAlignment = true;
}
}
}
}
if (ala == null)
{
System.err.print("\n");
}
}
void addAlignmentDetails(AlignmentI al, StringTokenizer st)
{
String keyValue, key, value;
while (st.hasMoreTokens())
{
keyValue = st.nextToken();
key = keyValue.substring(0, keyValue.indexOf("="));
value = keyValue.substring(keyValue.indexOf("=") + 1);
al.setProperty(key, value);
}
}
/**
* Write annotations as a CSV file of the form 'label, value, value, ...' for
* each row.
*
* @param annotations
* @return CSV file as a string.
*/
public String printCSVAnnotations(AlignmentAnnotation[] annotations)
{
if (annotations == null)
{
return "";
}
StringBuffer sp = new StringBuffer();
for (int i = 0; i < annotations.length; i++)
{
String atos = annotations[i].toString();
int p = 0;
do
{
int cp = atos.indexOf("\n", p);
sp.append(annotations[i].label);
sp.append(",");
if (cp > p)
{
sp.append(atos.substring(p, cp + 1));
}
else
{
sp.append(atos.substring(p));
sp.append(newline);
}
p = cp + 1;
} while (p > 0);
}
return sp.toString();
}
public String printAnnotationsForView(AlignViewportI viewport)
{
return printAnnotations(viewport.isShowAnnotation() ? viewport
.getAlignment().getAlignmentAnnotation() : null, viewport
.getAlignment().getGroups(), viewport.getAlignment()
.getProperties(), viewport.getColumnSelection(),
viewport.getAlignment(), null);
}
public String printAnnotationsForAlignment(AlignmentI al)
{
return printAnnotations(al.getAlignmentAnnotation(), al.getGroups(),
al.getProperties(), null, al, null);
}
}