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
88 StringBuffer rowprops = 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
279 if (row.scaleColLabel || row.showAllColLabels || row.centreColLabels)
\r
281 rowprops.append("ROWPROPERTIES\t"+row.label);
\r
282 rowprops.append("\tscaletofit="+row.scaleColLabel);
\r
283 rowprops.append("\tshowalllabs="+row.showAllColLabels);
\r
284 rowprops.append("\tcentrelabs="+row.centreColLabels);
\r
285 rowprops.append("\n");
\r
291 text.append(colours.toString());
\r
292 text.append(graphLine.toString());
\r
293 if (graphGroup.size() > 0)
\r
295 text.append("COMBINE\t");
\r
296 Enumeration en = graphGroup.elements();
\r
297 while (en.hasMoreElements())
\r
299 text.append(en.nextElement() + "\n");
\r
302 text.append(rowprops);
\r
305 if (groups != null)
\r
307 printGroups(groups);
\r
310 if (properties != null)
\r
312 text.append("\n\nALIGNMENT");
\r
313 Enumeration en = properties.keys();
\r
314 while (en.hasMoreElements())
\r
316 String key = en.nextElement().toString();
\r
317 text.append("\t" + key + "=" + properties.get(key));
\r
319 // TODO: output alignment visualization settings here if required
\r
323 return text.toString();
\r
326 public void printGroups(Vector sequenceGroups)
\r
329 SequenceI seqrep = null;
\r
330 for (int i = 0; i < sequenceGroups.size(); i++)
\r
332 sg = (SequenceGroup) sequenceGroups.elementAt(i);
\r
333 if (!sg.hasSeqrep())
\r
335 text.append("SEQUENCE_GROUP\t" + sg.getName() + "\t"
\r
336 + (sg.getStartRes() + 1) + "\t" + (sg.getEndRes() + 1)
\r
342 seqrep = sg.getSeqrep();
\r
343 text.append("SEQUENCE_REF\t" + seqrep.getName() + "\n");
\r
344 text.append("SEQUENCE_GROUP\t" + sg.getName() + "\t"
\r
345 + (seqrep.findPosition(sg.getStartRes())) + "\t"
\r
346 + (seqrep.findPosition(sg.getEndRes())) + "\t" + "-1\t");
\r
348 for (int s = 0; s < sg.getSize(); s++)
\r
350 text.append(sg.getSequenceAt(s).getName() + "\t");
\r
353 text.append("\nPROPERTIES\t" + sg.getName() + "\t");
\r
355 if (sg.getDescription() != null)
\r
357 text.append("description=" + sg.getDescription() + "\t");
\r
361 text.append("colour=" + ColourSchemeProperty.getColourName(sg.cs)
\r
363 if (sg.cs.getThreshold() != 0)
\r
365 text.append("pidThreshold=" + sg.cs.getThreshold());
\r
367 if (sg.cs.conservationApplied())
\r
369 text.append("consThreshold=" + sg.cs.getConservationInc() + "\t");
\r
372 text.append("outlineColour="
\r
373 + jalview.util.Format.getHexString(sg.getOutlineColour())
\r
376 text.append("displayBoxes=" + sg.getDisplayBoxes() + "\t");
\r
377 text.append("displayText=" + sg.getDisplayText() + "\t");
\r
378 text.append("colourText=" + sg.getColourText() + "\t");
\r
379 text.append("showUnconserved=" + sg.getShowunconserved() + "\t");
\r
380 if (sg.textColour != java.awt.Color.black)
\r
382 text.append("textCol1="
\r
383 + jalview.util.Format.getHexString(sg.textColour) + "\t");
\r
385 if (sg.textColour2 != java.awt.Color.white)
\r
387 text.append("textCol2="
\r
388 + jalview.util.Format.getHexString(sg.textColour2) + "\t");
\r
390 if (sg.thresholdTextColour != 0)
\r
392 text.append("textColThreshold=" + sg.thresholdTextColour + "\t");
\r
394 if (sg.idColour != null)
\r
396 text.append("idColour="
\r
397 + jalview.util.Format.getHexString(sg.idColour) + "\t");
\r
399 if (sg.isHidereps())
\r
401 text.append("hide=true\t");
\r
403 if (sg.isHideCols())
\r
405 text.append("hidecols=true\t");
\r
407 if (seqrep != null)
\r
409 // terminate the last line and clear the sequence ref for the group
\r
410 text.append("\nSEQUENCE_REF");
\r
412 text.append("\n\n");
\r
417 SequenceI refSeq = null;
\r
419 String refSeqId = null;
\r
421 public boolean readAnnotationFile(AlignmentI al, String file,
\r
426 BufferedReader in = null;
\r
427 if (protocol.equals(AppletFormatAdapter.FILE))
\r
429 in = new BufferedReader(new FileReader(file));
\r
431 else if (protocol.equals(AppletFormatAdapter.URL))
\r
433 URL url = new URL(file);
\r
434 in = new BufferedReader(new InputStreamReader(url.openStream()));
\r
436 else if (protocol.equals(AppletFormatAdapter.PASTE))
\r
438 in = new BufferedReader(new StringReader(file));
\r
440 else if (protocol.equals(AppletFormatAdapter.CLASSLOADER))
\r
442 java.io.InputStream is = getClass().getResourceAsStream("/" + file);
\r
445 in = new BufferedReader(new java.io.InputStreamReader(is));
\r
449 String line, label, description, token;
\r
450 int graphStyle, index;
\r
451 int refSeqIndex = 1;
\r
452 int existingAnnotations = 0;
\r
453 if (al.getAlignmentAnnotation() != null)
\r
455 existingAnnotations = al.getAlignmentAnnotation().length;
\r
458 int alWidth = al.getWidth();
\r
460 StringTokenizer st;
\r
461 Annotation[] annotations;
\r
462 AlignmentAnnotation annotation = null;
\r
464 // First confirm this is an Annotation file
\r
465 boolean jvAnnotationFile = false;
\r
466 while ((line = in.readLine()) != null)
\r
468 if (line.indexOf("#") == 0)
\r
473 if (line.indexOf("JALVIEW_ANNOTATION") > -1)
\r
475 jvAnnotationFile = true;
\r
480 if (!jvAnnotationFile)
\r
486 while ((line = in.readLine()) != null)
\r
488 if (line.indexOf("#") == 0
\r
489 || line.indexOf("JALVIEW_ANNOTATION") > -1
\r
490 || line.length() == 0)
\r
495 st = new StringTokenizer(line, "\t");
\r
496 token = st.nextToken();
\r
497 if (token.equalsIgnoreCase("COLOUR"))
\r
499 // TODO: use graduated colour def'n here too
\r
500 colourAnnotations(al, st.nextToken(), st.nextToken());
\r
504 else if (token.equalsIgnoreCase("COMBINE"))
\r
506 combineAnnotations(al, st);
\r
509 else if (token.equalsIgnoreCase("ROWPROPERTIES"))
\r
511 addRowProperties(al, st);
\r
514 else if (token.equalsIgnoreCase("GRAPHLINE"))
\r
520 else if (token.equalsIgnoreCase("SEQUENCE_REF"))
\r
522 if (st.hasMoreTokens())
\r
524 refSeq = al.findName(refSeqId = st.nextToken());
\r
525 if (refSeq == null)
\r
531 refSeqIndex = Integer.parseInt(st.nextToken());
\r
532 if (refSeqIndex < 1)
\r
536 .println("WARNING: SEQUENCE_REF index must be > 0 in AnnotationFile");
\r
538 } catch (Exception ex)
\r
551 else if (token.equalsIgnoreCase("SEQUENCE_GROUP"))
\r
557 else if (token.equalsIgnoreCase("PROPERTIES"))
\r
559 addProperties(al, st);
\r
563 else if (token.equalsIgnoreCase("BELOW_ALIGNMENT"))
\r
565 setBelowAlignment(al, st);
\r
568 else if (token.equalsIgnoreCase("ALIGNMENT"))
\r
570 addAlignmentDetails(al, st);
\r
574 graphStyle = AlignmentAnnotation.getGraphValueFromString(token);
\r
575 label = st.nextToken();
\r
578 annotations = new Annotation[alWidth];
\r
579 description = null;
\r
580 float score = Float.NaN;
\r
582 if (st.hasMoreTokens())
\r
584 line = st.nextToken();
\r
586 if (line.indexOf("|") == -1)
\r
588 description = line;
\r
589 if (st.hasMoreTokens())
\r
590 line = st.nextToken();
\r
593 if (st.hasMoreTokens())
\r
595 // This must be the score
\r
596 score = Float.valueOf(st.nextToken()).floatValue();
\r
599 st = new StringTokenizer(line, "|", true);
\r
601 boolean emptyColumn = true;
\r
602 boolean onlyOneElement = (st.countTokens() == 1);
\r
604 while (st.hasMoreElements() && index < alWidth)
\r
606 token = st.nextToken().trim();
\r
608 if (onlyOneElement)
\r
612 score = Float.valueOf(token).floatValue();
\r
614 } catch (NumberFormatException ex)
\r
619 if (token.equals("|"))
\r
626 emptyColumn = true;
\r
630 annotations[index++] = parseAnnotation(token);
\r
631 emptyColumn = false;
\r
637 annotation = new AlignmentAnnotation(label, description,
\r
638 (index == 0) ? null : annotations, 0, 0, graphStyle);
\r
640 annotation.score = score;
\r
642 if (refSeq != null)
\r
644 annotation.belowAlignment = false;
\r
645 // make a copy of refSeq so we can find other matches in the alignment
\r
646 SequenceI referedSeq = refSeq;
\r
649 // copy before we do any mapping business.
\r
650 // TODO: verify that undo/redo with 1:many sequence associated
\r
651 // annotations can be undone correctly
\r
652 AlignmentAnnotation ann = new AlignmentAnnotation(annotation);
\r
654 .createSequenceMapping(referedSeq, refSeqIndex, false);
\r
655 annotation.adjustForAlignment();
\r
656 referedSeq.addAlignmentAnnotation(annotation);
\r
657 al.addAnnotation(annotation);
\r
658 al.setAnnotationIndex(annotation,
\r
659 al.getAlignmentAnnotation().length
\r
660 - existingAnnotations - 1);
\r
661 // and recover our virgin copy to use again if necessary.
\r
664 } while (refSeqId != null
\r
665 && (referedSeq = al.findName(referedSeq, refSeqId, true)) != null);
\r
669 al.addAnnotation(annotation);
\r
670 al.setAnnotationIndex(annotation,
\r
671 al.getAlignmentAnnotation().length - existingAnnotations
\r
676 } catch (Exception ex)
\r
678 ex.printStackTrace();
\r
679 System.out.println("Problem reading annotation file: " + ex);
\r
685 Annotation parseAnnotation(String string)
\r
687 String desc = null, displayChar = null;
\r
688 char ss = ' '; // secondaryStructure
\r
690 boolean parsedValue = false, dcset = false;
\r
692 // find colour here
\r
693 java.awt.Color colour = null;
\r
694 int i = string.indexOf("[");
\r
695 int j = string.indexOf("]");
\r
696 if (i > -1 && j > -1)
\r
698 UserColourScheme ucs = new UserColourScheme();
\r
700 colour = ucs.getColourFromString(string.substring(i + 1, j));
\r
702 string = string.substring(0, i) + string.substring(j + 1);
\r
705 StringTokenizer st = new StringTokenizer(string, ",");
\r
707 while (st.hasMoreTokens())
\r
709 token = st.nextToken().trim();
\r
710 if (token.length() == 0)
\r
712 if (parsedValue && !dcset)
\r
714 // allow the value below the bar/line to be empty
\r
725 displayChar = token;
\r
726 value = new Float(token).floatValue();
\r
727 parsedValue = true;
\r
729 } catch (NumberFormatException ex)
\r
734 if (token.equals("H") || token.equals("E"))
\r
736 // Either this character represents a helix or sheet
\r
737 // or an integer which can be displayed
\r
738 ss = token.charAt(0);
\r
739 if (displayChar.equals(token.substring(0, 1)))
\r
744 else if (desc == null)
\r
750 if (!dcset && string.charAt(string.length() - 1) == ',')
\r
752 displayChar = " "; // empty display char symbol.
\r
754 if (displayChar != null && displayChar.length() > 1 && desc != null
\r
755 && desc.length() == 1)
\r
757 String tmp = displayChar;
\r
758 displayChar = desc;
\r
762 * In principle, this code will ensure that the Annotation element generated
\r
763 * is renderable by any of the applet or application rendering code but
\r
764 * instead we check for null strings when the display character is rendered.
\r
765 * if (displayChar==null) { displayChar=""; }
\r
767 Annotation anot = new Annotation(displayChar, desc, ss, value);
\r
769 anot.colour = colour;
\r
774 void colourAnnotations(AlignmentI al, String label, String colour)
\r
776 UserColourScheme ucs = new UserColourScheme(colour);
\r
777 Annotation[] annotations;
\r
778 for (int i = 0; i < al.getAlignmentAnnotation().length; i++)
\r
780 if (al.getAlignmentAnnotation()[i].label.equalsIgnoreCase(label))
\r
782 annotations = al.getAlignmentAnnotation()[i].annotations;
\r
783 for (int j = 0; j < annotations.length; j++)
\r
785 if (annotations[j] != null)
\r
787 annotations[j].colour = ucs.findColour('A');
\r
794 void combineAnnotations(AlignmentI al, StringTokenizer st)
\r
796 int graphGroup = -1;
\r
797 String group = st.nextToken();
\r
798 // First make sure we are not overwriting the graphIndex
\r
799 for (int i = 0; i < al.getAlignmentAnnotation().length; i++)
\r
801 if (al.getAlignmentAnnotation()[i].label.equalsIgnoreCase(group))
\r
803 graphGroup = al.getAlignmentAnnotation()[i].graphGroup + 1;
\r
804 al.getAlignmentAnnotation()[i].graphGroup = graphGroup;
\r
809 // Now update groups
\r
810 while (st.hasMoreTokens())
\r
812 group = st.nextToken();
\r
813 for (int i = 0; i < al.getAlignmentAnnotation().length; i++)
\r
815 if (al.getAlignmentAnnotation()[i].label.equalsIgnoreCase(group))
\r
817 al.getAlignmentAnnotation()[i].graphGroup = graphGroup;
\r
824 void addLine(AlignmentI al, StringTokenizer st)
\r
826 String group = st.nextToken();
\r
827 AlignmentAnnotation annotation = null;
\r
829 for (int i = 0; i < al.getAlignmentAnnotation().length; i++)
\r
831 if (al.getAlignmentAnnotation()[i].label.equalsIgnoreCase(group))
\r
833 annotation = al.getAlignmentAnnotation()[i];
\r
838 if (annotation == null)
\r
842 float value = new Float(st.nextToken()).floatValue();
\r
843 String label = st.hasMoreTokens() ? st.nextToken() : null;
\r
844 java.awt.Color colour = null;
\r
845 if (st.hasMoreTokens())
\r
847 UserColourScheme ucs = new UserColourScheme(st.nextToken());
\r
848 colour = ucs.findColour('A');
\r
851 annotation.setThreshold(new GraphLine(value, label, colour));
\r
854 void addGroup(AlignmentI al, StringTokenizer st)
\r
856 SequenceGroup sg = new SequenceGroup();
\r
857 sg.setName(st.nextToken());
\r
861 rng = st.nextToken();
\r
862 if (rng.length() > 0 && !rng.startsWith("*"))
\r
864 sg.setStartRes(Integer.parseInt(rng) - 1);
\r
870 rng = st.nextToken();
\r
871 if (rng.length() > 0 && !rng.startsWith("*"))
\r
873 sg.setEndRes(Integer.parseInt(rng) - 1);
\r
877 sg.setEndRes(al.getWidth() - 1);
\r
879 } catch (Exception e)
\r
882 .println("Couldn't parse Group Start or End Field as '*' or a valid column or sequence index: '"
\r
883 + rng + "' - assuming alignment width for group.");
\r
884 // assume group is full width
\r
886 sg.setEndRes(al.getWidth() - 1);
\r
889 String index = st.nextToken();
\r
890 if (index.equals("-1"))
\r
892 while (st.hasMoreElements())
\r
894 sg.addSequence(al.findName(st.nextToken()), false);
\r
899 StringTokenizer st2 = new StringTokenizer(index, ",");
\r
901 while (st2.hasMoreTokens())
\r
903 String tmp = st2.nextToken();
\r
904 if (tmp.equals("*"))
\r
906 for (int i = 0; i < al.getHeight(); i++)
\r
908 sg.addSequence(al.getSequenceAt(i), false);
\r
911 else if (tmp.indexOf("-") >= 0)
\r
913 StringTokenizer st3 = new StringTokenizer(tmp, "-");
\r
915 int start = (Integer.parseInt(st3.nextToken()));
\r
916 int end = (Integer.parseInt(st3.nextToken()));
\r
920 for (int i = start; i <= end; i++)
\r
922 sg.addSequence(al.getSequenceAt(i - 1), false);
\r
929 .addSequence(al.getSequenceAt(Integer.parseInt(tmp) - 1),
\r
935 if (refSeq != null)
\r
937 sg.setStartRes(refSeq.findIndex(sg.getStartRes() + 1) - 1);
\r
938 sg.setEndRes(refSeq.findIndex(sg.getEndRes() + 1) - 1);
\r
939 sg.setSeqrep(refSeq);
\r
942 if (sg.getSize() > 0)
\r
948 void addRowProperties(AlignmentI al, StringTokenizer st)
\r
950 String label = st.nextToken(),keyValue,key,value;
\r
951 boolean scaletofit=false,centerlab=false,showalllabs=false;
\r
952 while (st.hasMoreTokens()) {
\r
953 keyValue=st.nextToken();
\r
954 key = keyValue.substring(0, keyValue.indexOf("="));
\r
955 value = keyValue.substring(keyValue.indexOf("=") + 1);
\r
956 if (key.equalsIgnoreCase("scaletofit")) {
\r
957 scaletofit = Boolean.valueOf(value).booleanValue();
\r
959 if (key.equalsIgnoreCase("showalllabs")) {
\r
960 showalllabs = Boolean.valueOf(value).booleanValue();
\r
962 if (key.equalsIgnoreCase("centrelabs")) {
\r
963 centerlab = Boolean.valueOf(value).booleanValue();
\r
965 AlignmentAnnotation[] alr = al.getAlignmentAnnotation();
\r
966 for (int i = 0; i < alr.length; i++)
\r
968 if (alr[i].label.equalsIgnoreCase(label))
\r
970 alr[i].centreColLabels = centerlab;
\r
971 alr[i].scaleColLabel = scaletofit;
\r
972 alr[i].showAllColLabels = showalllabs;
\r
977 void addProperties(AlignmentI al, StringTokenizer st)
\r
980 // So far we have only added groups to the annotationHash,
\r
981 // the idea is in the future properties can be added to
\r
982 // alignments, other annotations etc
\r
983 if (al.getGroups() == null)
\r
987 SequenceGroup sg = null;
\r
989 String name = st.nextToken();
\r
991 Vector groups = al.getGroups();
\r
992 for (int i = 0; i < groups.size(); i++)
\r
994 sg = (SequenceGroup) groups.elementAt(i);
\r
995 if (sg.getName().equals(name))
\r
1007 String keyValue, key, value;
\r
1008 ColourSchemeI def = sg.cs;
\r
1010 while (st.hasMoreTokens())
\r
1012 keyValue = st.nextToken();
\r
1013 key = keyValue.substring(0, keyValue.indexOf("="));
\r
1014 value = keyValue.substring(keyValue.indexOf("=") + 1);
\r
1016 if (key.equalsIgnoreCase("description"))
\r
1018 sg.setDescription(value);
\r
1020 else if (key.equalsIgnoreCase("colour"))
\r
1022 sg.cs = ColourSchemeProperty.getColour(al, value);
\r
1024 else if (key.equalsIgnoreCase("pidThreshold"))
\r
1026 sg.cs.setThreshold(Integer.parseInt(value), true);
\r
1029 else if (key.equalsIgnoreCase("consThreshold"))
\r
1031 sg.cs.setConservationInc(Integer.parseInt(value));
\r
1032 Conservation c = new Conservation("Group",
\r
1033 ResidueProperties.propHash, 3, sg.getSequences(null), sg
\r
1034 .getStartRes(), sg.getEndRes() + 1);
\r
1037 c.verdict(false, 25);
\r
1039 sg.cs.setConservation(c);
\r
1042 else if (key.equalsIgnoreCase("outlineColour"))
\r
1044 sg.setOutlineColour(new UserColourScheme(value).findColour('A'));
\r
1046 else if (key.equalsIgnoreCase("displayBoxes"))
\r
1048 sg.setDisplayBoxes(Boolean.valueOf(value).booleanValue());
\r
1050 else if (key.equalsIgnoreCase("showUnconserved"))
\r
1052 sg.setShowunconserved(Boolean.valueOf(value).booleanValue());
\r
1054 else if (key.equalsIgnoreCase("displayText"))
\r
1056 sg.setDisplayText(Boolean.valueOf(value).booleanValue());
\r
1058 else if (key.equalsIgnoreCase("colourText"))
\r
1060 sg.setColourText(Boolean.valueOf(value).booleanValue());
\r
1062 else if (key.equalsIgnoreCase("textCol1"))
\r
1064 sg.textColour = new UserColourScheme(value).findColour('A');
\r
1066 else if (key.equalsIgnoreCase("textCol2"))
\r
1068 sg.textColour2 = new UserColourScheme(value).findColour('A');
\r
1070 else if (key.equalsIgnoreCase("textColThreshold"))
\r
1072 sg.thresholdTextColour = Integer.parseInt(value);
\r
1074 else if (key.equalsIgnoreCase("idColour"))
\r
1076 // consider warning if colour doesn't resolve to a real colour
\r
1077 sg.setIdColour((def = new UserColourScheme(value))
\r
1078 .findColour('A'));
\r
1080 else if (key.equalsIgnoreCase("hide"))
\r
1082 // see bug https://mantis.lifesci.dundee.ac.uk/view.php?id=25847
\r
1083 sg.setHidereps(true);
\r
1085 else if (key.equalsIgnoreCase("hidecols"))
\r
1087 // see bug https://mantis.lifesci.dundee.ac.uk/view.php?id=25847
\r
1088 sg.setHideCols(true);
\r
1090 sg.recalcConservation();
\r
1092 if (sg.cs == null)
\r
1099 void setBelowAlignment(AlignmentI al, StringTokenizer st)
\r
1102 AlignmentAnnotation aa;
\r
1103 while (st.hasMoreTokens())
\r
1105 token = st.nextToken();
\r
1106 for (int i = 0; i < al.getAlignmentAnnotation().length; i++)
\r
1108 aa = al.getAlignmentAnnotation()[i];
\r
1109 if (aa.sequenceRef == refSeq && aa.label.equals(token))
\r
1111 aa.belowAlignment = true;
\r
1117 void addAlignmentDetails(AlignmentI al, StringTokenizer st)
\r
1119 String keyValue, key, value;
\r
1120 while (st.hasMoreTokens())
\r
1122 keyValue = st.nextToken();
\r
1123 key = keyValue.substring(0, keyValue.indexOf("="));
\r
1124 value = keyValue.substring(keyValue.indexOf("=") + 1);
\r
1125 al.setProperty(key, value);
\r
1130 * Write annotations as a CSV file of the form 'label, value, value, ...' for
\r
1133 * @param annotations
\r
1134 * @return CSV file as a string.
\r
1136 public String printCSVAnnotations(AlignmentAnnotation[] annotations)
\r
1138 StringBuffer sp = new StringBuffer();
\r
1139 for (int i = 0; i < annotations.length; i++)
\r
1141 String atos = annotations[i].toString();
\r
1145 int cp = atos.indexOf("\n", p);
\r
1146 sp.append(annotations[i].label);
\r
1150 sp.append(atos.substring(p, cp + 1));
\r
1154 sp.append(atos.substring(p));
\r
1160 return sp.toString();
\r