2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
\r
3 * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
25 import jalview.analysis.*;
\r
26 import jalview.datamodel.*;
\r
27 import jalview.schemes.*;
\r
29 public class AnnotationFile
\r
31 StringBuffer text = new StringBuffer("JALVIEW_ANNOTATION\n"
\r
32 + "# Created: " + new java.util.Date() + "\n\n");
\r
35 * convenience method for pre-2.4 feature files which have no view, hidden
\r
36 * columns or hidden row keywords.
\r
38 * @param annotations
\r
41 * @return feature file as a string.
\r
43 public String printAnnotations(AlignmentAnnotation[] annotations,
\r
44 Vector groups, Hashtable properties)
\r
46 return printAnnotations(annotations, groups, properties, null);
\r
51 * hold all the information about a particular view definition read from or
\r
52 * written out in an annotations file.
\r
54 public class ViewDef
\r
56 public String viewname;
\r
58 public HiddenSequences hidseqs;
\r
60 public ColumnSelection hiddencols;
\r
62 public Vector visibleGroups;
\r
64 public Hashtable hiddenRepSeqs;
\r
66 public ViewDef(String viewname, HiddenSequences hidseqs,
\r
67 ColumnSelection hiddencols, Hashtable hiddenRepSeqs)
\r
69 this.viewname = viewname;
\r
70 this.hidseqs = hidseqs;
\r
71 this.hiddencols = hiddencols;
\r
72 this.hiddenRepSeqs = hiddenRepSeqs;
\r
76 public String printAnnotations(AlignmentAnnotation[] annotations,
\r
77 Vector groups, Hashtable properties, ViewDef[] views)
\r
79 if (annotations != null)
\r
81 boolean oneColour = true;
\r
82 AlignmentAnnotation row;
\r
84 SequenceI refSeq = null;
\r
86 StringBuffer colours = new StringBuffer();
\r
87 StringBuffer graphLine = new StringBuffer();
\r
89 Hashtable graphGroup = new Hashtable();
\r
91 java.awt.Color color;
\r
93 for (int i = 0; i < annotations.length; i++)
\r
95 row = annotations[i];
\r
97 if (!row.visible && !row.hasScore())
\r
105 if (row.sequenceRef == null)
\r
107 if (refSeq != null)
\r
109 text.append("\nSEQUENCE_REF\tALIGNMENT\n");
\r
115 else if (refSeq == null || refSeq != row.sequenceRef)
\r
117 refSeq = row.sequenceRef;
\r
118 text.append("\nSEQUENCE_REF\t" + refSeq.getName() + "\n");
\r
120 boolean hasGlyphs = false, hasLabels = false, hasValues = false, hasText = false;
\r
121 // lookahead to check what the annotation row object actually contains.
\r
122 for (int j = 0; row.annotations != null
\r
123 && j < row.annotations.length
\r
124 && (!hasGlyphs || !hasLabels || !hasValues); j++)
\r
126 if (row.annotations[j] != null)
\r
128 hasLabels |= (row.annotations[j].displayCharacter != null
\r
129 && row.annotations[j].displayCharacter.length() > 0 && !row.annotations[j].displayCharacter
\r
131 hasGlyphs |= (row.annotations[j].secondaryStructure != 0 && row.annotations[j].secondaryStructure != ' ');
\r
132 hasValues |= (row.annotations[j].value != Float.NaN); // NaNs can't
\r
135 hasText |= (row.annotations[j].description != null && row.annotations[j].description
\r
140 if (row.graph == AlignmentAnnotation.NO_GRAPH)
\r
142 text.append("NO_GRAPH\t");
\r
143 hasValues = false; // only secondary structure
\r
144 hasLabels = false; // and annotation description string.
\r
148 if (row.graph == AlignmentAnnotation.BAR_GRAPH)
\r
150 text.append("BAR_GRAPH\t");
\r
151 hasGlyphs = false; // no secondary structure
\r
154 else if (row.graph == AlignmentAnnotation.LINE_GRAPH)
\r
156 hasGlyphs = false; // no secondary structure
\r
157 text.append("LINE_GRAPH\t");
\r
160 if (row.getThreshold() != null)
\r
163 .append("GRAPHLINE\t"
\r
166 + row.getThreshold().value
\r
168 + row.getThreshold().label
\r
170 + jalview.util.Format.getHexString(row
\r
171 .getThreshold().colour) + "\n");
\r
174 if (row.graphGroup > -1)
\r
176 String key = String.valueOf(row.graphGroup);
\r
177 if (graphGroup.containsKey(key))
\r
179 graphGroup.put(key, graphGroup.get(key) + "\t" + row.label);
\r
183 graphGroup.put(key, row.label);
\r
188 text.append(row.label + "\t");
\r
189 if (row.description != null)
\r
191 text.append(row.description + "\t");
\r
193 for (int j = 0; row.annotations != null
\r
194 && j < row.annotations.length; j++)
\r
197 && jalview.util.Comparison.isGap(refSeq.getCharAt(j)))
\r
202 if (row.annotations[j] != null)
\r
205 if (hasGlyphs && row.annotations[j].secondaryStructure != ' ')
\r
208 text.append(comma + row.annotations[j].secondaryStructure);
\r
213 if (row.annotations[j].value != Float.NaN)
\r
215 text.append(comma + row.annotations[j].value);
\r
219 System.err.println("Skipping NaN - not valid value.");
\r
220 text.append(comma + 0f);// row.annotations[j].value);
\r
226 // TODO: labels are emitted after values for bar graphs.
\r
227 text.append(comma);
\r
228 if // empty labels are allowed, so
\r
229 (row.annotations[j].displayCharacter != null
\r
230 && row.annotations[j].displayCharacter.length() > 0
\r
231 && !row.annotations[j].displayCharacter.equals(" "))
\r
233 text.append(comma + row.annotations[j].displayCharacter);
\r
239 if (row.annotations[j].description != null
\r
240 && row.annotations[j].description.length() > 0
\r
241 && !row.annotations[j].description
\r
242 .equals(row.annotations[j].displayCharacter))
\r
244 text.append(comma + row.annotations[j].description);
\r
248 if (color != null && !color.equals(row.annotations[j].colour))
\r
253 color = row.annotations[j].colour;
\r
255 if (row.annotations[j].colour != null
\r
256 && row.annotations[j].colour != java.awt.Color.black)
\r
260 + jalview.util.Format
\r
261 .getHexString(row.annotations[j].colour)
\r
269 if (row.hasScore())
\r
270 text.append("\t" + row.score);
\r
274 if (color != null && color != java.awt.Color.black && oneColour)
\r
276 colours.append("COLOUR\t" + row.label + "\t"
\r
277 + jalview.util.Format.getHexString(color) + "\n");
\r
284 text.append(colours.toString());
\r
285 text.append(graphLine.toString());
\r
286 if (graphGroup.size() > 0)
\r
288 text.append("COMBINE\t");
\r
289 Enumeration en = graphGroup.elements();
\r
290 while (en.hasMoreElements())
\r
292 text.append(en.nextElement() + "\n");
\r
297 if (groups != null)
\r
299 printGroups(groups);
\r
302 if (properties != null)
\r
304 text.append("\n\nALIGNMENT");
\r
305 Enumeration en = properties.keys();
\r
306 while (en.hasMoreElements())
\r
308 String key = en.nextElement().toString();
\r
309 text.append("\t" + key + "=" + properties.get(key));
\r
311 // TODO: output alignment visualization settings here if required
\r
315 return text.toString();
\r
318 public void printGroups(Vector sequenceGroups)
\r
321 SequenceI seqrep = null;
\r
322 for (int i = 0; i < sequenceGroups.size(); i++)
\r
324 sg = (SequenceGroup) sequenceGroups.elementAt(i);
\r
325 if (!sg.hasSeqrep())
\r
327 text.append("SEQUENCE_GROUP\t" + sg.getName() + "\t"
\r
328 + (sg.getStartRes() + 1) + "\t" + (sg.getEndRes() + 1)
\r
334 seqrep = sg.getSeqrep();
\r
335 text.append("SEQUENCE_REF\t" + seqrep.getName() + "\n");
\r
336 text.append("SEQUENCE_GROUP\t" + sg.getName() + "\t"
\r
337 + (seqrep.findPosition(sg.getStartRes())) + "\t"
\r
338 + (seqrep.findPosition(sg.getEndRes())) + "\t" + "-1\t");
\r
340 for (int s = 0; s < sg.getSize(); s++)
\r
342 text.append(sg.getSequenceAt(s).getName() + "\t");
\r
345 text.append("\nPROPERTIES\t" + sg.getName() + "\t");
\r
347 if (sg.getDescription() != null)
\r
349 text.append("description=" + sg.getDescription() + "\t");
\r
353 text.append("colour=" + ColourSchemeProperty.getColourName(sg.cs)
\r
355 if (sg.cs.getThreshold() != 0)
\r
357 text.append("pidThreshold=" + sg.cs.getThreshold());
\r
359 if (sg.cs.conservationApplied())
\r
361 text.append("consThreshold=" + sg.cs.getConservationInc() + "\t");
\r
364 text.append("outlineColour="
\r
365 + jalview.util.Format.getHexString(sg.getOutlineColour())
\r
368 text.append("displayBoxes=" + sg.getDisplayBoxes() + "\t");
\r
369 text.append("displayText=" + sg.getDisplayText() + "\t");
\r
370 text.append("colourText=" + sg.getColourText() + "\t");
\r
371 text.append("showUnconserved=" + sg.getShowunconserved() + "\t");
\r
372 if (sg.textColour != java.awt.Color.black)
\r
374 text.append("textCol1="
\r
375 + jalview.util.Format.getHexString(sg.textColour) + "\t");
\r
377 if (sg.textColour2 != java.awt.Color.white)
\r
379 text.append("textCol2="
\r
380 + jalview.util.Format.getHexString(sg.textColour2) + "\t");
\r
382 if (sg.thresholdTextColour != 0)
\r
384 text.append("textColThreshold=" + sg.thresholdTextColour + "\t");
\r
386 if (sg.idColour != null)
\r
388 text.append("idColour="
\r
389 + jalview.util.Format.getHexString(sg.idColour) + "\t");
\r
391 if (sg.isHidereps())
\r
393 text.append("hide=true\t");
\r
395 if (sg.isHideCols())
\r
397 text.append("hidecols=true\t");
\r
399 if (seqrep != null)
\r
401 // terminate the last line and clear the sequence ref for the group
\r
402 text.append("\nSEQUENCE_REF");
\r
404 text.append("\n\n");
\r
409 SequenceI refSeq = null;
\r
411 String refSeqId = null;
\r
413 public boolean readAnnotationFile(AlignmentI al, String file,
\r
418 BufferedReader in = null;
\r
419 if (protocol.equals(AppletFormatAdapter.FILE))
\r
421 in = new BufferedReader(new FileReader(file));
\r
423 else if (protocol.equals(AppletFormatAdapter.URL))
\r
425 URL url = new URL(file);
\r
426 in = new BufferedReader(new InputStreamReader(url.openStream()));
\r
428 else if (protocol.equals(AppletFormatAdapter.PASTE))
\r
430 in = new BufferedReader(new StringReader(file));
\r
432 else if (protocol.equals(AppletFormatAdapter.CLASSLOADER))
\r
434 java.io.InputStream is = getClass().getResourceAsStream("/" + file);
\r
437 in = new BufferedReader(new java.io.InputStreamReader(is));
\r
441 String line, label, description, token;
\r
442 int graphStyle, index;
\r
443 int refSeqIndex = 1;
\r
444 int existingAnnotations = 0;
\r
445 if (al.getAlignmentAnnotation() != null)
\r
447 existingAnnotations = al.getAlignmentAnnotation().length;
\r
450 int alWidth = al.getWidth();
\r
452 StringTokenizer st;
\r
453 Annotation[] annotations;
\r
454 AlignmentAnnotation annotation = null;
\r
456 // First confirm this is an Annotation file
\r
457 boolean jvAnnotationFile = false;
\r
458 while ((line = in.readLine()) != null)
\r
460 if (line.indexOf("#") == 0)
\r
465 if (line.indexOf("JALVIEW_ANNOTATION") > -1)
\r
467 jvAnnotationFile = true;
\r
472 if (!jvAnnotationFile)
\r
478 while ((line = in.readLine()) != null)
\r
480 if (line.indexOf("#") == 0
\r
481 || line.indexOf("JALVIEW_ANNOTATION") > -1
\r
482 || line.length() == 0)
\r
487 st = new StringTokenizer(line, "\t");
\r
488 token = st.nextToken();
\r
489 if (token.equalsIgnoreCase("COLOUR"))
\r
491 // TODO: use graduated colour def'n here too
\r
492 colourAnnotations(al, st.nextToken(), st.nextToken());
\r
496 else if (token.equalsIgnoreCase("COMBINE"))
\r
498 combineAnnotations(al, st);
\r
502 else if (token.equalsIgnoreCase("GRAPHLINE"))
\r
508 else if (token.equalsIgnoreCase("SEQUENCE_REF"))
\r
510 if (st.hasMoreTokens())
\r
512 refSeq = al.findName(refSeqId = st.nextToken());
\r
513 if (refSeq == null)
\r
519 refSeqIndex = Integer.parseInt(st.nextToken());
\r
520 if (refSeqIndex < 1)
\r
524 .println("WARNING: SEQUENCE_REF index must be > 0 in AnnotationFile");
\r
526 } catch (Exception ex)
\r
539 else if (token.equalsIgnoreCase("SEQUENCE_GROUP"))
\r
545 else if (token.equalsIgnoreCase("PROPERTIES"))
\r
547 addProperties(al, st);
\r
551 else if (token.equalsIgnoreCase("BELOW_ALIGNMENT"))
\r
553 setBelowAlignment(al, st);
\r
556 else if (token.equalsIgnoreCase("ALIGNMENT"))
\r
558 addAlignmentDetails(al, st);
\r
562 graphStyle = AlignmentAnnotation.getGraphValueFromString(token);
\r
563 label = st.nextToken();
\r
566 annotations = new Annotation[alWidth];
\r
567 description = null;
\r
568 float score = Float.NaN;
\r
570 if (st.hasMoreTokens())
\r
572 line = st.nextToken();
\r
574 if (line.indexOf("|") == -1)
\r
576 description = line;
\r
577 if (st.hasMoreTokens())
\r
578 line = st.nextToken();
\r
581 if (st.hasMoreTokens())
\r
583 // This must be the score
\r
584 score = Float.valueOf(st.nextToken()).floatValue();
\r
587 st = new StringTokenizer(line, "|", true);
\r
589 boolean emptyColumn = true;
\r
590 boolean onlyOneElement = (st.countTokens() == 1);
\r
592 while (st.hasMoreElements() && index < alWidth)
\r
594 token = st.nextToken().trim();
\r
596 if (onlyOneElement)
\r
600 score = Float.valueOf(token).floatValue();
\r
602 } catch (NumberFormatException ex)
\r
607 if (token.equals("|"))
\r
614 emptyColumn = true;
\r
618 annotations[index++] = parseAnnotation(token);
\r
619 emptyColumn = false;
\r
625 annotation = new AlignmentAnnotation(label, description,
\r
626 (index == 0) ? null : annotations, 0, 0, graphStyle);
\r
628 annotation.score = score;
\r
630 if (refSeq != null)
\r
632 annotation.belowAlignment = false;
\r
633 // make a copy of refSeq so we can find other matches in the alignment
\r
634 SequenceI referedSeq = refSeq;
\r
637 // copy before we do any mapping business.
\r
638 // TODO: verify that undo/redo with 1:many sequence associated
\r
639 // annotations can be undone correctly
\r
640 AlignmentAnnotation ann = new AlignmentAnnotation(annotation);
\r
642 .createSequenceMapping(referedSeq, refSeqIndex, false);
\r
643 annotation.adjustForAlignment();
\r
644 referedSeq.addAlignmentAnnotation(annotation);
\r
645 al.addAnnotation(annotation);
\r
646 al.setAnnotationIndex(annotation,
\r
647 al.getAlignmentAnnotation().length
\r
648 - existingAnnotations - 1);
\r
649 // and recover our virgin copy to use again if necessary.
\r
652 } while (refSeqId != null
\r
653 && (referedSeq = al.findName(referedSeq, refSeqId, true)) != null);
\r
657 al.addAnnotation(annotation);
\r
658 al.setAnnotationIndex(annotation,
\r
659 al.getAlignmentAnnotation().length - existingAnnotations
\r
664 } catch (Exception ex)
\r
666 ex.printStackTrace();
\r
667 System.out.println("Problem reading annotation file: " + ex);
\r
673 Annotation parseAnnotation(String string)
\r
675 String desc = null, displayChar = null;
\r
676 char ss = ' '; // secondaryStructure
\r
678 boolean parsedValue = false, dcset = false;
\r
680 // find colour here
\r
681 java.awt.Color colour = null;
\r
682 int i = string.indexOf("[");
\r
683 int j = string.indexOf("]");
\r
684 if (i > -1 && j > -1)
\r
686 UserColourScheme ucs = new UserColourScheme();
\r
688 colour = ucs.getColourFromString(string.substring(i + 1, j));
\r
690 string = string.substring(0, i) + string.substring(j + 1);
\r
693 StringTokenizer st = new StringTokenizer(string, ",");
\r
695 while (st.hasMoreTokens())
\r
697 token = st.nextToken().trim();
\r
698 if (token.length() == 0)
\r
700 if (parsedValue && !dcset)
\r
702 // allow the value below the bar/line to be empty
\r
713 displayChar = token;
\r
714 value = new Float(token).floatValue();
\r
715 parsedValue = true;
\r
717 } catch (NumberFormatException ex)
\r
722 if (token.equals("H") || token.equals("E"))
\r
724 // Either this character represents a helix or sheet
\r
725 // or an integer which can be displayed
\r
726 ss = token.charAt(0);
\r
727 if (displayChar.equals(token.substring(0, 1)))
\r
732 else if (desc == null)
\r
738 if (!dcset && string.charAt(string.length() - 1) == ',')
\r
740 displayChar = " "; // empty display char symbol.
\r
742 if (displayChar != null && displayChar.length() > 1 && desc != null
\r
743 && desc.length() == 1)
\r
745 String tmp = displayChar;
\r
746 displayChar = desc;
\r
750 * In principle, this code will ensure that the Annotation element generated
\r
751 * is renderable by any of the applet or application rendering code but
\r
752 * instead we check for null strings when the display character is rendered.
\r
753 * if (displayChar==null) { displayChar=""; }
\r
755 Annotation anot = new Annotation(displayChar, desc, ss, value);
\r
757 anot.colour = colour;
\r
762 void colourAnnotations(AlignmentI al, String label, String colour)
\r
764 UserColourScheme ucs = new UserColourScheme(colour);
\r
765 Annotation[] annotations;
\r
766 for (int i = 0; i < al.getAlignmentAnnotation().length; i++)
\r
768 if (al.getAlignmentAnnotation()[i].label.equalsIgnoreCase(label))
\r
770 annotations = al.getAlignmentAnnotation()[i].annotations;
\r
771 for (int j = 0; j < annotations.length; j++)
\r
773 if (annotations[j] != null)
\r
775 annotations[j].colour = ucs.findColour('A');
\r
782 void combineAnnotations(AlignmentI al, StringTokenizer st)
\r
784 int graphGroup = -1;
\r
785 String group = st.nextToken();
\r
786 // First make sure we are not overwriting the graphIndex
\r
787 for (int i = 0; i < al.getAlignmentAnnotation().length; i++)
\r
789 if (al.getAlignmentAnnotation()[i].label.equalsIgnoreCase(group))
\r
791 graphGroup = al.getAlignmentAnnotation()[i].graphGroup + 1;
\r
792 al.getAlignmentAnnotation()[i].graphGroup = graphGroup;
\r
797 // Now update groups
\r
798 while (st.hasMoreTokens())
\r
800 group = st.nextToken();
\r
801 for (int i = 0; i < al.getAlignmentAnnotation().length; i++)
\r
803 if (al.getAlignmentAnnotation()[i].label.equalsIgnoreCase(group))
\r
805 al.getAlignmentAnnotation()[i].graphGroup = graphGroup;
\r
812 void addLine(AlignmentI al, StringTokenizer st)
\r
814 String group = st.nextToken();
\r
815 AlignmentAnnotation annotation = null;
\r
817 for (int i = 0; i < al.getAlignmentAnnotation().length; i++)
\r
819 if (al.getAlignmentAnnotation()[i].label.equalsIgnoreCase(group))
\r
821 annotation = al.getAlignmentAnnotation()[i];
\r
826 if (annotation == null)
\r
830 float value = new Float(st.nextToken()).floatValue();
\r
831 String label = st.hasMoreTokens() ? st.nextToken() : null;
\r
832 java.awt.Color colour = null;
\r
833 if (st.hasMoreTokens())
\r
835 UserColourScheme ucs = new UserColourScheme(st.nextToken());
\r
836 colour = ucs.findColour('A');
\r
839 annotation.setThreshold(new GraphLine(value, label, colour));
\r
842 void addGroup(AlignmentI al, StringTokenizer st)
\r
844 SequenceGroup sg = new SequenceGroup();
\r
845 sg.setName(st.nextToken());
\r
849 rng = st.nextToken();
\r
850 if (rng.length() > 0 && !rng.startsWith("*"))
\r
852 sg.setStartRes(Integer.parseInt(rng) - 1);
\r
858 rng = st.nextToken();
\r
859 if (rng.length() > 0 && !rng.startsWith("*"))
\r
861 sg.setEndRes(Integer.parseInt(rng) - 1);
\r
865 sg.setEndRes(al.getWidth() - 1);
\r
867 } catch (Exception e)
\r
870 .println("Couldn't parse Group Start or End Field as '*' or a valid column or sequence index: '"
\r
871 + rng + "' - assuming alignment width for group.");
\r
872 // assume group is full width
\r
874 sg.setEndRes(al.getWidth() - 1);
\r
877 String index = st.nextToken();
\r
878 if (index.equals("-1"))
\r
880 while (st.hasMoreElements())
\r
882 sg.addSequence(al.findName(st.nextToken()), false);
\r
887 StringTokenizer st2 = new StringTokenizer(index, ",");
\r
889 while (st2.hasMoreTokens())
\r
891 String tmp = st2.nextToken();
\r
892 if (tmp.equals("*"))
\r
894 for (int i = 0; i < al.getHeight(); i++)
\r
896 sg.addSequence(al.getSequenceAt(i), false);
\r
899 else if (tmp.indexOf("-") >= 0)
\r
901 StringTokenizer st3 = new StringTokenizer(tmp, "-");
\r
903 int start = (Integer.parseInt(st3.nextToken()));
\r
904 int end = (Integer.parseInt(st3.nextToken()));
\r
908 for (int i = start; i <= end; i++)
\r
910 sg.addSequence(al.getSequenceAt(i - 1), false);
\r
917 .addSequence(al.getSequenceAt(Integer.parseInt(tmp) - 1),
\r
923 if (refSeq != null)
\r
925 sg.setStartRes(refSeq.findIndex(sg.getStartRes() + 1) - 1);
\r
926 sg.setEndRes(refSeq.findIndex(sg.getEndRes() + 1) - 1);
\r
927 sg.setSeqrep(refSeq);
\r
930 if (sg.getSize() > 0)
\r
936 void addProperties(AlignmentI al, StringTokenizer st)
\r
939 // So far we have only added groups to the annotationHash,
\r
940 // the idea is in the future properties can be added to
\r
941 // alignments, other annotations etc
\r
942 if (al.getGroups() == null)
\r
946 SequenceGroup sg = null;
\r
948 String name = st.nextToken();
\r
950 Vector groups = al.getGroups();
\r
951 for (int i = 0; i < groups.size(); i++)
\r
953 sg = (SequenceGroup) groups.elementAt(i);
\r
954 if (sg.getName().equals(name))
\r
966 String keyValue, key, value;
\r
967 ColourSchemeI def = sg.cs;
\r
969 while (st.hasMoreTokens())
\r
971 keyValue = st.nextToken();
\r
972 key = keyValue.substring(0, keyValue.indexOf("="));
\r
973 value = keyValue.substring(keyValue.indexOf("=") + 1);
\r
975 if (key.equalsIgnoreCase("description"))
\r
977 sg.setDescription(value);
\r
979 else if (key.equalsIgnoreCase("colour"))
\r
981 sg.cs = ColourSchemeProperty.getColour(al, value);
\r
983 else if (key.equalsIgnoreCase("pidThreshold"))
\r
985 sg.cs.setThreshold(Integer.parseInt(value), true);
\r
988 else if (key.equalsIgnoreCase("consThreshold"))
\r
990 sg.cs.setConservationInc(Integer.parseInt(value));
\r
991 Conservation c = new Conservation("Group",
\r
992 ResidueProperties.propHash, 3, sg.getSequences(null), sg
\r
993 .getStartRes(), sg.getEndRes() + 1);
\r
996 c.verdict(false, 25);
\r
998 sg.cs.setConservation(c);
\r
1001 else if (key.equalsIgnoreCase("outlineColour"))
\r
1003 sg.setOutlineColour(new UserColourScheme(value).findColour('A'));
\r
1005 else if (key.equalsIgnoreCase("displayBoxes"))
\r
1007 sg.setDisplayBoxes(Boolean.valueOf(value).booleanValue());
\r
1009 else if (key.equalsIgnoreCase("showUnconserved"))
\r
1011 sg.setShowunconserved(Boolean.valueOf(value).booleanValue());
\r
1013 else if (key.equalsIgnoreCase("displayText"))
\r
1015 sg.setDisplayText(Boolean.valueOf(value).booleanValue());
\r
1017 else if (key.equalsIgnoreCase("colourText"))
\r
1019 sg.setColourText(Boolean.valueOf(value).booleanValue());
\r
1021 else if (key.equalsIgnoreCase("textCol1"))
\r
1023 sg.textColour = new UserColourScheme(value).findColour('A');
\r
1025 else if (key.equalsIgnoreCase("textCol2"))
\r
1027 sg.textColour2 = new UserColourScheme(value).findColour('A');
\r
1029 else if (key.equalsIgnoreCase("textColThreshold"))
\r
1031 sg.thresholdTextColour = Integer.parseInt(value);
\r
1033 else if (key.equalsIgnoreCase("idColour"))
\r
1035 // consider warning if colour doesn't resolve to a real colour
\r
1036 sg.setIdColour((def = new UserColourScheme(value))
\r
1037 .findColour('A'));
\r
1039 else if (key.equalsIgnoreCase("hide"))
\r
1041 // see bug https://mantis.lifesci.dundee.ac.uk/view.php?id=25847
\r
1042 sg.setHidereps(true);
\r
1044 else if (key.equalsIgnoreCase("hidecols"))
\r
1046 // see bug https://mantis.lifesci.dundee.ac.uk/view.php?id=25847
\r
1047 sg.setHideCols(true);
\r
1049 sg.recalcConservation();
\r
1051 if (sg.cs == null)
\r
1058 void setBelowAlignment(AlignmentI al, StringTokenizer st)
\r
1061 AlignmentAnnotation aa;
\r
1062 while (st.hasMoreTokens())
\r
1064 token = st.nextToken();
\r
1065 for (int i = 0; i < al.getAlignmentAnnotation().length; i++)
\r
1067 aa = al.getAlignmentAnnotation()[i];
\r
1068 if (aa.sequenceRef == refSeq && aa.label.equals(token))
\r
1070 aa.belowAlignment = true;
\r
1076 void addAlignmentDetails(AlignmentI al, StringTokenizer st)
\r
1078 String keyValue, key, value;
\r
1079 while (st.hasMoreTokens())
\r
1081 keyValue = st.nextToken();
\r
1082 key = keyValue.substring(0, keyValue.indexOf("="));
\r
1083 value = keyValue.substring(keyValue.indexOf("=") + 1);
\r
1084 al.setProperty(key, value);
\r
1089 * Write annotations as a CSV file of the form 'label, value, value, ...' for
\r
1092 * @param annotations
\r
1093 * @return CSV file as a string.
\r
1095 public String printCSVAnnotations(AlignmentAnnotation[] annotations)
\r
1097 StringBuffer sp = new StringBuffer();
\r
1098 for (int i = 0; i < annotations.length; i++)
\r
1100 String atos = annotations[i].toString();
\r
1104 int cp = atos.indexOf("\n", p);
\r
1105 sp.append(annotations[i].label);
\r
1109 sp.append(atos.substring(p, cp + 1));
\r
1113 sp.append(atos.substring(p));
\r
1119 return sp.toString();
\r