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
77 * Prepare an annotation file given a set of annotations, groups, alignment
\r
78 * properties and views.
\r
80 * @param annotations
\r
84 * @return annotation file
\r
86 public String printAnnotations(AlignmentAnnotation[] annotations,
\r
87 Vector groups, Hashtable properties, ViewDef[] views)
\r
89 // TODO: resolve views issue : annotationFile could contain visible region,
\r
90 // or full data + hidden region specifications for a view.
\r
91 if (annotations != null)
\r
93 boolean oneColour = true;
\r
94 AlignmentAnnotation row;
\r
96 SequenceI refSeq = null;
\r
97 SequenceGroup refGroup = null;
\r
99 StringBuffer colours = new StringBuffer();
\r
100 StringBuffer graphLine = new StringBuffer();
\r
101 StringBuffer rowprops = new StringBuffer();
\r
102 Hashtable graphGroup = new Hashtable();
\r
104 java.awt.Color color;
\r
106 for (int i = 0; i < annotations.length; i++)
\r
108 row = annotations[i];
\r
110 if (!row.visible && !row.hasScore())
\r
118 if (row.sequenceRef == null)
\r
120 if (refSeq != null)
\r
122 text.append("\nSEQUENCE_REF\tALIGNMENT\n");
\r
130 if (refSeq == null || refSeq != row.sequenceRef)
\r
132 refSeq = row.sequenceRef;
\r
133 text.append("\nSEQUENCE_REF\t" + refSeq.getName() + "\n");
\r
136 // mark any group references for the row
\r
137 if (row.groupRef == null)
\r
140 if (refGroup != null)
\r
142 text.append("\nGROUP_REF\tALIGNMENT\n");
\r
149 if (refGroup == null || refGroup != row.groupRef)
\r
151 refGroup = row.groupRef;
\r
152 text.append("\nGROUP_REF\t" + refGroup.getName() + "\n");
\r
156 boolean hasGlyphs = row.hasIcons, hasLabels = row.hasText, hasValues = row.hasScore, hasText = false;
\r
157 // lookahead to check what the annotation row object actually contains.
\r
158 for (int j = 0; row.annotations != null
\r
159 && j < row.annotations.length
\r
160 && (!hasGlyphs || !hasLabels || !hasValues); j++)
\r
162 if (row.annotations[j] != null)
\r
164 hasLabels |= (row.annotations[j].displayCharacter != null
\r
165 && row.annotations[j].displayCharacter.length() > 0 && !row.annotations[j].displayCharacter
\r
167 hasGlyphs |= (row.annotations[j].secondaryStructure != 0 && row.annotations[j].secondaryStructure != ' ');
\r
168 hasValues |= (row.annotations[j].value != Float.NaN); // NaNs can't
\r
171 hasText |= (row.annotations[j].description != null && row.annotations[j].description
\r
176 if (row.graph == AlignmentAnnotation.NO_GRAPH)
\r
178 text.append("NO_GRAPH\t");
\r
179 hasValues = false; // only secondary structure
\r
180 // hasLabels = false; // and annotation description string.
\r
184 if (row.graph == AlignmentAnnotation.BAR_GRAPH)
\r
186 text.append("BAR_GRAPH\t");
\r
187 hasGlyphs = false; // no secondary structure
\r
190 else if (row.graph == AlignmentAnnotation.LINE_GRAPH)
\r
192 hasGlyphs = false; // no secondary structure
\r
193 text.append("LINE_GRAPH\t");
\r
196 if (row.getThreshold() != null)
\r
199 .append("GRAPHLINE\t"
\r
202 + row.getThreshold().value
\r
204 + row.getThreshold().label
\r
206 + jalview.util.Format.getHexString(row
\r
207 .getThreshold().colour) + "\n");
\r
210 if (row.graphGroup > -1)
\r
212 String key = String.valueOf(row.graphGroup);
\r
213 if (graphGroup.containsKey(key))
\r
215 graphGroup.put(key, graphGroup.get(key) + "\t" + row.label);
\r
219 graphGroup.put(key, row.label);
\r
224 text.append(row.label + "\t");
\r
225 if (row.description != null)
\r
227 text.append(row.description + "\t");
\r
229 for (int j = 0; row.annotations != null
\r
230 && j < row.annotations.length; j++)
\r
233 && jalview.util.Comparison.isGap(refSeq.getCharAt(j)))
\r
238 if (row.annotations[j] != null)
\r
241 if (hasGlyphs) // could be also hasGlyphs || ...
\r
244 text.append(comma);
\r
245 if (row.annotations[j].secondaryStructure != ' ')
\r
247 // only write out the field if its not whitespace.
\r
248 text.append(row.annotations[j].secondaryStructure);
\r
254 if (row.annotations[j].value != Float.NaN)
\r
256 text.append(comma + row.annotations[j].value);
\r
260 System.err.println("Skipping NaN - not valid value.");
\r
261 text.append(comma + 0f);// row.annotations[j].value);
\r
267 // TODO: labels are emitted after values for bar graphs.
\r
268 if // empty labels are allowed, so
\r
269 (row.annotations[j].displayCharacter != null
\r
270 && row.annotations[j].displayCharacter.length() > 0
\r
271 && !row.annotations[j].displayCharacter.equals(" "))
\r
273 text.append(comma + row.annotations[j].displayCharacter);
\r
279 if (row.annotations[j].description != null
\r
280 && row.annotations[j].description.length() > 0
\r
281 && !row.annotations[j].description
\r
282 .equals(row.annotations[j].displayCharacter))
\r
284 text.append(comma + row.annotations[j].description);
\r
288 if (color != null && !color.equals(row.annotations[j].colour))
\r
293 color = row.annotations[j].colour;
\r
295 if (row.annotations[j].colour != null
\r
296 && row.annotations[j].colour != java.awt.Color.black)
\r
300 + jalview.util.Format
\r
301 .getHexString(row.annotations[j].colour)
\r
309 if (row.hasScore())
\r
310 text.append("\t" + row.score);
\r
314 if (color != null && color != java.awt.Color.black && oneColour)
\r
316 colours.append("COLOUR\t" + row.label + "\t"
\r
317 + jalview.util.Format.getHexString(color) + "\n");
\r
319 if (row.scaleColLabel || row.showAllColLabels
\r
320 || row.centreColLabels)
\r
322 rowprops.append("ROWPROPERTIES\t" + row.label);
\r
323 rowprops.append("\tscaletofit=" + row.scaleColLabel);
\r
324 rowprops.append("\tshowalllabs=" + row.showAllColLabels);
\r
325 rowprops.append("\tcentrelabs=" + row.centreColLabels);
\r
326 rowprops.append("\n");
\r
332 text.append(colours.toString());
\r
333 text.append(graphLine.toString());
\r
334 if (graphGroup.size() > 0)
\r
336 text.append("COMBINE\t");
\r
337 Enumeration en = graphGroup.elements();
\r
338 while (en.hasMoreElements())
\r
340 text.append(en.nextElement() + "\n");
\r
343 text.append(rowprops.toString());
\r
346 if (groups != null)
\r
348 printGroups(groups);
\r
351 if (properties != null)
\r
353 text.append("\n\nALIGNMENT");
\r
354 Enumeration en = properties.keys();
\r
355 while (en.hasMoreElements())
\r
357 String key = en.nextElement().toString();
\r
358 text.append("\t" + key + "=" + properties.get(key));
\r
360 // TODO: output alignment visualization settings here if required
\r
364 return text.toString();
\r
367 public void printGroups(Vector sequenceGroups)
\r
370 SequenceI seqrep = null;
\r
371 for (int i = 0; i < sequenceGroups.size(); i++)
\r
373 sg = (SequenceGroup) sequenceGroups.elementAt(i);
\r
374 if (!sg.hasSeqrep())
\r
376 text.append("SEQUENCE_GROUP\t" + sg.getName() + "\t"
\r
377 + (sg.getStartRes() + 1) + "\t" + (sg.getEndRes() + 1)
\r
383 seqrep = sg.getSeqrep();
\r
384 text.append("SEQUENCE_REF\t" + seqrep.getName() + "\n");
\r
385 text.append("SEQUENCE_GROUP\t" + sg.getName() + "\t"
\r
386 + (seqrep.findPosition(sg.getStartRes())) + "\t"
\r
387 + (seqrep.findPosition(sg.getEndRes())) + "\t" + "-1\t");
\r
389 for (int s = 0; s < sg.getSize(); s++)
\r
391 text.append(sg.getSequenceAt(s).getName() + "\t");
\r
394 text.append("\nPROPERTIES\t" + sg.getName() + "\t");
\r
396 if (sg.getDescription() != null)
\r
398 text.append("description=" + sg.getDescription() + "\t");
\r
402 text.append("colour=" + ColourSchemeProperty.getColourName(sg.cs)
\r
404 if (sg.cs.getThreshold() != 0)
\r
406 text.append("pidThreshold=" + sg.cs.getThreshold());
\r
408 if (sg.cs.conservationApplied())
\r
410 text.append("consThreshold=" + sg.cs.getConservationInc() + "\t");
\r
413 text.append("outlineColour="
\r
414 + jalview.util.Format.getHexString(sg.getOutlineColour())
\r
417 text.append("displayBoxes=" + sg.getDisplayBoxes() + "\t");
\r
418 text.append("displayText=" + sg.getDisplayText() + "\t");
\r
419 text.append("colourText=" + sg.getColourText() + "\t");
\r
420 text.append("showUnconserved=" + sg.getShowunconserved() + "\t");
\r
421 if (sg.textColour != java.awt.Color.black)
\r
423 text.append("textCol1="
\r
424 + jalview.util.Format.getHexString(sg.textColour) + "\t");
\r
426 if (sg.textColour2 != java.awt.Color.white)
\r
428 text.append("textCol2="
\r
429 + jalview.util.Format.getHexString(sg.textColour2) + "\t");
\r
431 if (sg.thresholdTextColour != 0)
\r
433 text.append("textColThreshold=" + sg.thresholdTextColour + "\t");
\r
435 if (sg.idColour != null)
\r
437 text.append("idColour="
\r
438 + jalview.util.Format.getHexString(sg.idColour) + "\t");
\r
440 if (sg.isHidereps())
\r
442 text.append("hide=true\t");
\r
444 if (sg.isHideCols())
\r
446 text.append("hidecols=true\t");
\r
448 if (seqrep != null)
\r
450 // terminate the last line and clear the sequence ref for the group
\r
451 text.append("\nSEQUENCE_REF");
\r
453 text.append("\n\n");
\r
458 SequenceI refSeq = null;
\r
460 String refSeqId = null;
\r
462 public boolean readAnnotationFile(AlignmentI al, String file,
\r
465 String groupRef = null;
\r
466 Hashtable groupRefRows = new Hashtable();
\r
468 Hashtable autoAnnots = new Hashtable();
\r
471 BufferedReader in = null;
\r
472 if (protocol.equals(AppletFormatAdapter.FILE))
\r
474 in = new BufferedReader(new FileReader(file));
\r
476 else if (protocol.equals(AppletFormatAdapter.URL))
\r
478 URL url = new URL(file);
\r
479 in = new BufferedReader(new InputStreamReader(url.openStream()));
\r
481 else if (protocol.equals(AppletFormatAdapter.PASTE))
\r
483 in = new BufferedReader(new StringReader(file));
\r
485 else if (protocol.equals(AppletFormatAdapter.CLASSLOADER))
\r
487 java.io.InputStream is = getClass().getResourceAsStream("/" + file);
\r
490 in = new BufferedReader(new java.io.InputStreamReader(is));
\r
494 String line, label, description, token;
\r
495 int graphStyle, index;
\r
496 int refSeqIndex = 1;
\r
497 int existingAnnotations = 0;
\r
498 // when true - will add new rows regardless of whether they are duplicate
\r
499 // auto-annotation like consensus or conservation graphs
\r
500 boolean overrideAutoAnnot = false;
\r
501 if (al.getAlignmentAnnotation() != null)
\r
503 existingAnnotations = al.getAlignmentAnnotation().length;
\r
504 if (existingAnnotations > 0)
\r
506 AlignmentAnnotation[] aa = al.getAlignmentAnnotation();
\r
507 for (int aai = 0; aai < aa.length; aai++)
\r
509 if (aa[aai].autoCalculated)
\r
511 // make a note of the name and description
\r
512 autoAnnots.put(aa[aai].graph
\r
516 + aa[aai].description
\r
518 + (aa[aai].sequenceRef != null ? aa[aai].sequenceRef
\r
519 .getDisplayId(true) : ""), new Integer(1));
\r
525 int alWidth = al.getWidth();
\r
527 StringTokenizer st;
\r
528 Annotation[] annotations;
\r
529 AlignmentAnnotation annotation = null;
\r
531 // First confirm this is an Annotation file
\r
532 boolean jvAnnotationFile = false;
\r
533 while ((line = in.readLine()) != null)
\r
535 if (line.indexOf("#") == 0)
\r
540 if (line.indexOf("JALVIEW_ANNOTATION") > -1)
\r
542 jvAnnotationFile = true;
\r
547 if (!jvAnnotationFile)
\r
553 while ((line = in.readLine()) != null)
\r
555 if (line.indexOf("#") == 0
\r
556 || line.indexOf("JALVIEW_ANNOTATION") > -1
\r
557 || line.length() == 0)
\r
562 st = new StringTokenizer(line, "\t");
\r
563 token = st.nextToken();
\r
564 if (token.equalsIgnoreCase("COLOUR"))
\r
566 // TODO: use graduated colour def'n here too
\r
567 colourAnnotations(al, st.nextToken(), st.nextToken());
\r
571 else if (token.equalsIgnoreCase("COMBINE"))
\r
573 combineAnnotations(al, st);
\r
576 else if (token.equalsIgnoreCase("ROWPROPERTIES"))
\r
578 addRowProperties(al, st);
\r
581 else if (token.equalsIgnoreCase("GRAPHLINE"))
\r
587 else if (token.equalsIgnoreCase("SEQUENCE_REF"))
\r
589 if (st.hasMoreTokens())
\r
591 refSeq = al.findName(refSeqId = st.nextToken());
\r
592 if (refSeq == null)
\r
598 refSeqIndex = Integer.parseInt(st.nextToken());
\r
599 if (refSeqIndex < 1)
\r
603 .println("WARNING: SEQUENCE_REF index must be > 0 in AnnotationFile");
\r
605 } catch (Exception ex)
\r
617 else if (token.equalsIgnoreCase("GROUP_REF"))
\r
619 // Group references could be forward or backwards, so they are
\r
620 // resolved after the whole file is read in
\r
622 if (st.hasMoreTokens())
\r
624 groupRef = st.nextToken();
\r
625 if (groupRef.length() < 1)
\r
627 groupRef = null; // empty string
\r
631 if (groupRefRows.get(groupRef) == null)
\r
633 groupRefRows.put(groupRef, new Vector());
\r
639 else if (token.equalsIgnoreCase("SEQUENCE_GROUP"))
\r
645 else if (token.equalsIgnoreCase("PROPERTIES"))
\r
647 addProperties(al, st);
\r
651 else if (token.equalsIgnoreCase("BELOW_ALIGNMENT"))
\r
653 setBelowAlignment(al, st);
\r
656 else if (token.equalsIgnoreCase("ALIGNMENT"))
\r
658 addAlignmentDetails(al, st);
\r
662 // Parse out the annotation row
\r
663 graphStyle = AlignmentAnnotation.getGraphValueFromString(token);
\r
664 label = st.nextToken();
\r
667 annotations = new Annotation[alWidth];
\r
668 description = null;
\r
669 float score = Float.NaN;
\r
671 if (st.hasMoreTokens())
\r
673 line = st.nextToken();
\r
675 if (line.indexOf("|") == -1)
\r
677 description = line;
\r
678 if (st.hasMoreTokens())
\r
679 line = st.nextToken();
\r
682 if (st.hasMoreTokens())
\r
684 // This must be the score
\r
685 score = Float.valueOf(st.nextToken()).floatValue();
\r
688 st = new StringTokenizer(line, "|", true);
\r
690 boolean emptyColumn = true;
\r
691 boolean onlyOneElement = (st.countTokens() == 1);
\r
693 while (st.hasMoreElements() && index < alWidth)
\r
695 token = st.nextToken().trim();
\r
697 if (onlyOneElement)
\r
701 score = Float.valueOf(token).floatValue();
\r
703 } catch (NumberFormatException ex)
\r
708 if (token.equals("|"))
\r
715 emptyColumn = true;
\r
719 annotations[index++] = parseAnnotation(token, graphStyle);
\r
720 emptyColumn = false;
\r
726 annotation = new AlignmentAnnotation(label, description,
\r
727 (index == 0) ? null : annotations, 0, 0, graphStyle);
\r
729 annotation.score = score;
\r
730 if (!overrideAutoAnnot
\r
732 .containsKey(annotation.graph
\r
736 + annotation.description
\r
738 + (refSeq != null ? refSeq
\r
739 .getDisplayId(true) : "")))
\r
741 // skip - we've already got an automatic annotation of this type.
\r
744 // otherwise add it!
\r
745 if (refSeq != null)
\r
748 annotation.belowAlignment = false;
\r
749 // make a copy of refSeq so we can find other matches in the alignment
\r
750 SequenceI referedSeq = refSeq;
\r
753 // copy before we do any mapping business.
\r
754 // TODO: verify that undo/redo with 1:many sequence associated
\r
755 // annotations can be undone correctly
\r
756 AlignmentAnnotation ann = new AlignmentAnnotation(annotation);
\r
758 .createSequenceMapping(referedSeq, refSeqIndex, false);
\r
759 annotation.adjustForAlignment();
\r
760 referedSeq.addAlignmentAnnotation(annotation);
\r
761 al.addAnnotation(annotation);
\r
762 al.setAnnotationIndex(annotation,
\r
763 al.getAlignmentAnnotation().length
\r
764 - existingAnnotations - 1);
\r
765 if (groupRef != null)
\r
767 ((Vector) groupRefRows.get(groupRef)).addElement(annotation);
\r
769 // and recover our virgin copy to use again if necessary.
\r
772 } while (refSeqId != null
\r
773 && (referedSeq = al.findName(referedSeq, refSeqId, true)) != null);
\r
777 al.addAnnotation(annotation);
\r
778 al.setAnnotationIndex(annotation,
\r
779 al.getAlignmentAnnotation().length - existingAnnotations
\r
781 if (groupRef != null)
\r
783 ((Vector) groupRefRows.get(groupRef)).addElement(annotation);
\r
787 // Finally, resolve the groupRefs
\r
788 Enumeration en = groupRefRows.keys();
\r
789 SequenceGroup theGroup = null;
\r
791 while (en.hasMoreElements())
\r
793 groupRef = (String) en.nextElement();
\r
794 boolean matched = false;
\r
795 // Resolve group: TODO: add a getGroupByName method to alignments
\r
796 Vector grps = al.getGroups();
\r
797 for (int g = 0, gSize = grps.size(); g < gSize; g++)
\r
799 theGroup = (SequenceGroup) grps.elementAt(g);
\r
800 if (theGroup.getName().equals(groupRef))
\r
804 // TODO: specify and implement duplication of alignment annotation for multiple group references.
\r
806 .println("Ignoring 1:many group reference mappings for group name '"
\r
812 Vector rowset = (Vector) groupRefRows.get(groupRef);
\r
813 if (rowset != null && rowset.size() > 0)
\r
815 AlignmentAnnotation alan = null;
\r
816 for (int elm = 0, elmSize = rowset.size(); elm < elmSize; elm++)
\r
818 alan = (AlignmentAnnotation) rowset.elementAt(elm);
\r
819 alan.groupRef = theGroup;
\r
825 ((Vector) groupRefRows.get(groupRef)).removeAllElements();
\r
827 } catch (Exception ex)
\r
829 ex.printStackTrace();
\r
830 System.out.println("Problem reading annotation file: " + ex);
\r
836 Annotation parseAnnotation(String string, int graphStyle)
\r
838 boolean hasSymbols = (graphStyle == AlignmentAnnotation.NO_GRAPH); // don't
\r
847 String desc = null, displayChar = null;
\r
848 char ss = ' '; // secondaryStructure
\r
850 boolean parsedValue = false, dcset = false;
\r
852 // find colour here
\r
853 java.awt.Color colour = null;
\r
854 int i = string.indexOf("[");
\r
855 int j = string.indexOf("]");
\r
856 if (i > -1 && j > -1)
\r
858 UserColourScheme ucs = new UserColourScheme();
\r
860 colour = ucs.getColourFromString(string.substring(i + 1, j));
\r
861 if (i > 0 && string.charAt(i - 1) == ',')
\r
863 // clip the preceding comma as well
\r
866 string = string.substring(0, i) + string.substring(j + 1);
\r
869 StringTokenizer st = new StringTokenizer(string, ",", true);
\r
871 boolean seenContent = false;
\r
873 while (st.hasMoreTokens())
\r
876 token = st.nextToken().trim();
\r
877 if (token.equals(","))
\r
879 if (!seenContent && parsedValue && !dcset)
\r
881 // allow the value below the bar/line to be empty
\r
885 seenContent = false;
\r
890 seenContent = true;
\r
897 displayChar = token;
\r
899 value = new Float(token).floatValue();
\r
900 parsedValue = true;
\r
902 } catch (NumberFormatException ex)
\r
908 if (token.length() == 1)
\r
910 displayChar = token;
\r
914 && (token.equals("H") || token.equals("E") || token
\r
917 // Either this character represents a helix or sheet
\r
918 // or an integer which can be displayed
\r
919 ss = token.charAt(0);
\r
920 if (displayChar.equals(token.substring(0, 1)))
\r
925 else if (desc == null || (parsedValue && pass > 2))
\r
931 // if (!dcset && string.charAt(string.length() - 1) == ',')
\r
933 // displayChar = " "; // empty display char symbol.
\r
935 if (displayChar != null && desc != null && desc.length() == 1)
\r
937 if (displayChar.length() > 1)
\r
939 // switch desc and displayChar - legacy support
\r
940 String tmp = displayChar;
\r
941 displayChar = desc;
\r
946 if (displayChar.equals(desc))
\r
948 // duplicate label - hangover from the 'robust parser' above
\r
953 Annotation anot = new Annotation(displayChar, desc, ss, value);
\r
955 anot.colour = colour;
\r
960 void colourAnnotations(AlignmentI al, String label, String colour)
\r
962 UserColourScheme ucs = new UserColourScheme(colour);
\r
963 Annotation[] annotations;
\r
964 for (int i = 0; i < al.getAlignmentAnnotation().length; i++)
\r
966 if (al.getAlignmentAnnotation()[i].label.equalsIgnoreCase(label))
\r
968 annotations = al.getAlignmentAnnotation()[i].annotations;
\r
969 for (int j = 0; j < annotations.length; j++)
\r
971 if (annotations[j] != null)
\r
973 annotations[j].colour = ucs.findColour('A');
\r
980 void combineAnnotations(AlignmentI al, StringTokenizer st)
\r
982 int graphGroup = -1;
\r
983 String group = st.nextToken();
\r
984 // First make sure we are not overwriting the graphIndex
\r
985 for (int i = 0; i < al.getAlignmentAnnotation().length; i++)
\r
987 if (al.getAlignmentAnnotation()[i].label.equalsIgnoreCase(group))
\r
989 graphGroup = al.getAlignmentAnnotation()[i].graphGroup + 1;
\r
990 al.getAlignmentAnnotation()[i].graphGroup = graphGroup;
\r
995 // Now update groups
\r
996 while (st.hasMoreTokens())
\r
998 group = st.nextToken();
\r
999 for (int i = 0; i < al.getAlignmentAnnotation().length; i++)
\r
1001 if (al.getAlignmentAnnotation()[i].label.equalsIgnoreCase(group))
\r
1003 al.getAlignmentAnnotation()[i].graphGroup = graphGroup;
\r
1010 void addLine(AlignmentI al, StringTokenizer st)
\r
1012 String group = st.nextToken();
\r
1013 AlignmentAnnotation annotation = null;
\r
1015 for (int i = 0; i < al.getAlignmentAnnotation().length; i++)
\r
1017 if (al.getAlignmentAnnotation()[i].label.equalsIgnoreCase(group))
\r
1019 annotation = al.getAlignmentAnnotation()[i];
\r
1024 if (annotation == null)
\r
1028 float value = new Float(st.nextToken()).floatValue();
\r
1029 String label = st.hasMoreTokens() ? st.nextToken() : null;
\r
1030 java.awt.Color colour = null;
\r
1031 if (st.hasMoreTokens())
\r
1033 UserColourScheme ucs = new UserColourScheme(st.nextToken());
\r
1034 colour = ucs.findColour('A');
\r
1037 annotation.setThreshold(new GraphLine(value, label, colour));
\r
1040 void addGroup(AlignmentI al, StringTokenizer st)
\r
1042 SequenceGroup sg = new SequenceGroup();
\r
1043 sg.setName(st.nextToken());
\r
1047 rng = st.nextToken();
\r
1048 if (rng.length() > 0 && !rng.startsWith("*"))
\r
1050 sg.setStartRes(Integer.parseInt(rng) - 1);
\r
1054 sg.setStartRes(0);
\r
1056 rng = st.nextToken();
\r
1057 if (rng.length() > 0 && !rng.startsWith("*"))
\r
1059 sg.setEndRes(Integer.parseInt(rng) - 1);
\r
1063 sg.setEndRes(al.getWidth() - 1);
\r
1065 } catch (Exception e)
\r
1068 .println("Couldn't parse Group Start or End Field as '*' or a valid column or sequence index: '"
\r
1069 + rng + "' - assuming alignment width for group.");
\r
1070 // assume group is full width
\r
1071 sg.setStartRes(0);
\r
1072 sg.setEndRes(al.getWidth() - 1);
\r
1075 String index = st.nextToken();
\r
1076 if (index.equals("-1"))
\r
1078 while (st.hasMoreElements())
\r
1080 sg.addSequence(al.findName(st.nextToken()), false);
\r
1085 StringTokenizer st2 = new StringTokenizer(index, ",");
\r
1087 while (st2.hasMoreTokens())
\r
1089 String tmp = st2.nextToken();
\r
1090 if (tmp.equals("*"))
\r
1092 for (int i = 0; i < al.getHeight(); i++)
\r
1094 sg.addSequence(al.getSequenceAt(i), false);
\r
1097 else if (tmp.indexOf("-") >= 0)
\r
1099 StringTokenizer st3 = new StringTokenizer(tmp, "-");
\r
1101 int start = (Integer.parseInt(st3.nextToken()));
\r
1102 int end = (Integer.parseInt(st3.nextToken()));
\r
1106 for (int i = start; i <= end; i++)
\r
1108 sg.addSequence(al.getSequenceAt(i - 1), false);
\r
1115 .addSequence(al.getSequenceAt(Integer.parseInt(tmp) - 1),
\r
1121 if (refSeq != null)
\r
1123 sg.setStartRes(refSeq.findIndex(sg.getStartRes() + 1) - 1);
\r
1124 sg.setEndRes(refSeq.findIndex(sg.getEndRes() + 1) - 1);
\r
1125 sg.setSeqrep(refSeq);
\r
1128 if (sg.getSize() > 0)
\r
1134 void addRowProperties(AlignmentI al, StringTokenizer st)
\r
1136 String label = st.nextToken(), keyValue, key, value;
\r
1137 boolean scaletofit = false, centerlab = false, showalllabs = false;
\r
1138 while (st.hasMoreTokens())
\r
1140 keyValue = st.nextToken();
\r
1141 key = keyValue.substring(0, keyValue.indexOf("="));
\r
1142 value = keyValue.substring(keyValue.indexOf("=") + 1);
\r
1143 if (key.equalsIgnoreCase("scaletofit"))
\r
1145 scaletofit = Boolean.valueOf(value).booleanValue();
\r
1147 if (key.equalsIgnoreCase("showalllabs"))
\r
1149 showalllabs = Boolean.valueOf(value).booleanValue();
\r
1151 if (key.equalsIgnoreCase("centrelabs"))
\r
1153 centerlab = Boolean.valueOf(value).booleanValue();
\r
1155 AlignmentAnnotation[] alr = al.getAlignmentAnnotation();
\r
1156 for (int i = 0; i < alr.length; i++)
\r
1158 if (alr[i].label.equalsIgnoreCase(label))
\r
1160 alr[i].centreColLabels = centerlab;
\r
1161 alr[i].scaleColLabel = scaletofit;
\r
1162 alr[i].showAllColLabels = showalllabs;
\r
1168 void addProperties(AlignmentI al, StringTokenizer st)
\r
1171 // So far we have only added groups to the annotationHash,
\r
1172 // the idea is in the future properties can be added to
\r
1173 // alignments, other annotations etc
\r
1174 if (al.getGroups() == null)
\r
1178 SequenceGroup sg = null;
\r
1180 String name = st.nextToken();
\r
1182 Vector groups = al.getGroups();
\r
1183 for (int i = 0; i < groups.size(); i++)
\r
1185 sg = (SequenceGroup) groups.elementAt(i);
\r
1186 if (sg.getName().equals(name))
\r
1198 String keyValue, key, value;
\r
1199 ColourSchemeI def = sg.cs;
\r
1201 while (st.hasMoreTokens())
\r
1203 keyValue = st.nextToken();
\r
1204 key = keyValue.substring(0, keyValue.indexOf("="));
\r
1205 value = keyValue.substring(keyValue.indexOf("=") + 1);
\r
1207 if (key.equalsIgnoreCase("description"))
\r
1209 sg.setDescription(value);
\r
1211 else if (key.equalsIgnoreCase("colour"))
\r
1213 sg.cs = ColourSchemeProperty.getColour(al, value);
\r
1215 else if (key.equalsIgnoreCase("pidThreshold"))
\r
1217 sg.cs.setThreshold(Integer.parseInt(value), true);
\r
1220 else if (key.equalsIgnoreCase("consThreshold"))
\r
1222 sg.cs.setConservationInc(Integer.parseInt(value));
\r
1223 Conservation c = new Conservation("Group",
\r
1224 ResidueProperties.propHash, 3, sg.getSequences(null), sg
\r
1225 .getStartRes(), sg.getEndRes() + 1);
\r
1228 c.verdict(false, 25);
\r
1230 sg.cs.setConservation(c);
\r
1233 else if (key.equalsIgnoreCase("outlineColour"))
\r
1235 sg.setOutlineColour(new UserColourScheme(value).findColour('A'));
\r
1237 else if (key.equalsIgnoreCase("displayBoxes"))
\r
1239 sg.setDisplayBoxes(Boolean.valueOf(value).booleanValue());
\r
1241 else if (key.equalsIgnoreCase("showUnconserved"))
\r
1243 sg.setShowunconserved(Boolean.valueOf(value).booleanValue());
\r
1245 else if (key.equalsIgnoreCase("displayText"))
\r
1247 sg.setDisplayText(Boolean.valueOf(value).booleanValue());
\r
1249 else if (key.equalsIgnoreCase("colourText"))
\r
1251 sg.setColourText(Boolean.valueOf(value).booleanValue());
\r
1253 else if (key.equalsIgnoreCase("textCol1"))
\r
1255 sg.textColour = new UserColourScheme(value).findColour('A');
\r
1257 else if (key.equalsIgnoreCase("textCol2"))
\r
1259 sg.textColour2 = new UserColourScheme(value).findColour('A');
\r
1261 else if (key.equalsIgnoreCase("textColThreshold"))
\r
1263 sg.thresholdTextColour = Integer.parseInt(value);
\r
1265 else if (key.equalsIgnoreCase("idColour"))
\r
1267 // consider warning if colour doesn't resolve to a real colour
\r
1268 sg.setIdColour((def = new UserColourScheme(value))
\r
1269 .findColour('A'));
\r
1271 else if (key.equalsIgnoreCase("hide"))
\r
1273 // see bug https://mantis.lifesci.dundee.ac.uk/view.php?id=25847
\r
1274 sg.setHidereps(true);
\r
1276 else if (key.equalsIgnoreCase("hidecols"))
\r
1278 // see bug https://mantis.lifesci.dundee.ac.uk/view.php?id=25847
\r
1279 sg.setHideCols(true);
\r
1281 sg.recalcConservation();
\r
1283 if (sg.cs == null)
\r
1290 void setBelowAlignment(AlignmentI al, StringTokenizer st)
\r
1293 AlignmentAnnotation aa;
\r
1294 while (st.hasMoreTokens())
\r
1296 token = st.nextToken();
\r
1297 for (int i = 0; i < al.getAlignmentAnnotation().length; i++)
\r
1299 aa = al.getAlignmentAnnotation()[i];
\r
1300 if (aa.sequenceRef == refSeq && aa.label.equals(token))
\r
1302 aa.belowAlignment = true;
\r
1308 void addAlignmentDetails(AlignmentI al, StringTokenizer st)
\r
1310 String keyValue, key, value;
\r
1311 while (st.hasMoreTokens())
\r
1313 keyValue = st.nextToken();
\r
1314 key = keyValue.substring(0, keyValue.indexOf("="));
\r
1315 value = keyValue.substring(keyValue.indexOf("=") + 1);
\r
1316 al.setProperty(key, value);
\r
1321 * Write annotations as a CSV file of the form 'label, value, value, ...' for
\r
1324 * @param annotations
\r
1325 * @return CSV file as a string.
\r
1327 public String printCSVAnnotations(AlignmentAnnotation[] annotations)
\r
1329 StringBuffer sp = new StringBuffer();
\r
1330 for (int i = 0; i < annotations.length; i++)
\r
1332 String atos = annotations[i].toString();
\r
1336 int cp = atos.indexOf("\n", p);
\r
1337 sp.append(annotations[i].label);
\r
1341 sp.append(atos.substring(p, cp + 1));
\r
1345 sp.append(atos.substring(p));
\r
1351 return sp.toString();
\r