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 * Prepare an annotation file given a set of annotations, groups, alignment properties and views.
\r
77 * @param annotations
\r
81 * @return annotation file
\r
83 public String printAnnotations(AlignmentAnnotation[] annotations,
\r
84 Vector groups, Hashtable properties, ViewDef[] views)
\r
86 // TODO: resolve views issue : annotationFile could contain visible region, or full data + hidden region specifications for a view.
\r
87 if (annotations != null)
\r
89 boolean oneColour = true;
\r
90 AlignmentAnnotation row;
\r
92 SequenceI refSeq = null;
\r
94 StringBuffer colours = new StringBuffer();
\r
95 StringBuffer graphLine = new StringBuffer();
\r
96 StringBuffer rowprops = new StringBuffer();
\r
97 Hashtable graphGroup = new Hashtable();
\r
99 java.awt.Color color;
\r
101 for (int i = 0; i < annotations.length; i++)
\r
103 row = annotations[i];
\r
105 if (!row.visible && !row.hasScore())
\r
113 if (row.sequenceRef == null)
\r
115 if (refSeq != null)
\r
117 text.append("\nSEQUENCE_REF\tALIGNMENT\n");
\r
123 else if (refSeq == null || refSeq != row.sequenceRef)
\r
125 refSeq = row.sequenceRef;
\r
126 text.append("\nSEQUENCE_REF\t" + refSeq.getName() + "\n");
\r
128 boolean hasGlyphs = row.hasIcons, hasLabels = row.hasText, hasValues = row.hasScore, hasText = false;
\r
129 // lookahead to check what the annotation row object actually contains.
\r
130 for (int j = 0; row.annotations != null
\r
131 && j < row.annotations.length
\r
132 && (!hasGlyphs || !hasLabels || !hasValues); j++)
\r
134 if (row.annotations[j] != null)
\r
136 hasLabels |= (row.annotations[j].displayCharacter != null
\r
137 && row.annotations[j].displayCharacter.length() > 0 && !row.annotations[j].displayCharacter
\r
139 hasGlyphs |= (row.annotations[j].secondaryStructure != 0 && row.annotations[j].secondaryStructure != ' ');
\r
140 hasValues |= (row.annotations[j].value != Float.NaN); // NaNs can't
\r
143 hasText |= (row.annotations[j].description != null && row.annotations[j].description
\r
148 if (row.graph == AlignmentAnnotation.NO_GRAPH)
\r
150 text.append("NO_GRAPH\t");
\r
151 hasValues = false; // only secondary structure
\r
152 // hasLabels = false; // and annotation description string.
\r
156 if (row.graph == AlignmentAnnotation.BAR_GRAPH)
\r
158 text.append("BAR_GRAPH\t");
\r
159 hasGlyphs = false; // no secondary structure
\r
162 else if (row.graph == AlignmentAnnotation.LINE_GRAPH)
\r
164 hasGlyphs = false; // no secondary structure
\r
165 text.append("LINE_GRAPH\t");
\r
168 if (row.getThreshold() != null)
\r
171 .append("GRAPHLINE\t"
\r
174 + row.getThreshold().value
\r
176 + row.getThreshold().label
\r
178 + jalview.util.Format.getHexString(row
\r
179 .getThreshold().colour) + "\n");
\r
182 if (row.graphGroup > -1)
\r
184 String key = String.valueOf(row.graphGroup);
\r
185 if (graphGroup.containsKey(key))
\r
187 graphGroup.put(key, graphGroup.get(key) + "\t" + row.label);
\r
191 graphGroup.put(key, row.label);
\r
196 text.append(row.label + "\t");
\r
197 if (row.description != null)
\r
199 text.append(row.description + "\t");
\r
201 for (int j = 0; row.annotations != null
\r
202 && j < row.annotations.length; j++)
\r
205 && jalview.util.Comparison.isGap(refSeq.getCharAt(j)))
\r
210 if (row.annotations[j] != null)
\r
213 if (hasGlyphs) // could be also hasGlyphs || ...
\r
216 text.append(comma);
\r
217 if (row.annotations[j].secondaryStructure != ' ')
\r
219 // only write out the field if its not whitespace.
\r
220 text.append(row.annotations[j].secondaryStructure);
\r
226 if (row.annotations[j].value != Float.NaN)
\r
228 text.append(comma + row.annotations[j].value);
\r
232 System.err.println("Skipping NaN - not valid value.");
\r
233 text.append(comma + 0f);// row.annotations[j].value);
\r
239 // TODO: labels are emitted after values for bar graphs.
\r
240 if // empty labels are allowed, so
\r
241 (row.annotations[j].displayCharacter != null
\r
242 && row.annotations[j].displayCharacter.length() > 0
\r
243 && !row.annotations[j].displayCharacter.equals(" "))
\r
245 text.append(comma + row.annotations[j].displayCharacter);
\r
251 if (row.annotations[j].description != null
\r
252 && row.annotations[j].description.length() > 0
\r
253 && !row.annotations[j].description
\r
254 .equals(row.annotations[j].displayCharacter))
\r
256 text.append(comma + row.annotations[j].description);
\r
260 if (color != null && !color.equals(row.annotations[j].colour))
\r
265 color = row.annotations[j].colour;
\r
267 if (row.annotations[j].colour != null
\r
268 && row.annotations[j].colour != java.awt.Color.black)
\r
272 + jalview.util.Format
\r
273 .getHexString(row.annotations[j].colour)
\r
281 if (row.hasScore())
\r
282 text.append("\t" + row.score);
\r
286 if (color != null && color != java.awt.Color.black && oneColour)
\r
288 colours.append("COLOUR\t" + row.label + "\t"
\r
289 + jalview.util.Format.getHexString(color) + "\n");
\r
291 if (row.scaleColLabel || row.showAllColLabels || row.centreColLabels)
\r
293 rowprops.append("ROWPROPERTIES\t"+row.label);
\r
294 rowprops.append("\tscaletofit="+row.scaleColLabel);
\r
295 rowprops.append("\tshowalllabs="+row.showAllColLabels);
\r
296 rowprops.append("\tcentrelabs="+row.centreColLabels);
\r
297 rowprops.append("\n");
\r
303 text.append(colours.toString());
\r
304 text.append(graphLine.toString());
\r
305 if (graphGroup.size() > 0)
\r
307 text.append("COMBINE\t");
\r
308 Enumeration en = graphGroup.elements();
\r
309 while (en.hasMoreElements())
\r
311 text.append(en.nextElement() + "\n");
\r
314 text.append(rowprops.toString());
\r
317 if (groups != null)
\r
319 printGroups(groups);
\r
322 if (properties != null)
\r
324 text.append("\n\nALIGNMENT");
\r
325 Enumeration en = properties.keys();
\r
326 while (en.hasMoreElements())
\r
328 String key = en.nextElement().toString();
\r
329 text.append("\t" + key + "=" + properties.get(key));
\r
331 // TODO: output alignment visualization settings here if required
\r
335 return text.toString();
\r
338 public void printGroups(Vector sequenceGroups)
\r
341 SequenceI seqrep = null;
\r
342 for (int i = 0; i < sequenceGroups.size(); i++)
\r
344 sg = (SequenceGroup) sequenceGroups.elementAt(i);
\r
345 if (!sg.hasSeqrep())
\r
347 text.append("SEQUENCE_GROUP\t" + sg.getName() + "\t"
\r
348 + (sg.getStartRes() + 1) + "\t" + (sg.getEndRes() + 1)
\r
354 seqrep = sg.getSeqrep();
\r
355 text.append("SEQUENCE_REF\t" + seqrep.getName() + "\n");
\r
356 text.append("SEQUENCE_GROUP\t" + sg.getName() + "\t"
\r
357 + (seqrep.findPosition(sg.getStartRes())) + "\t"
\r
358 + (seqrep.findPosition(sg.getEndRes())) + "\t" + "-1\t");
\r
360 for (int s = 0; s < sg.getSize(); s++)
\r
362 text.append(sg.getSequenceAt(s).getName() + "\t");
\r
365 text.append("\nPROPERTIES\t" + sg.getName() + "\t");
\r
367 if (sg.getDescription() != null)
\r
369 text.append("description=" + sg.getDescription() + "\t");
\r
373 text.append("colour=" + ColourSchemeProperty.getColourName(sg.cs)
\r
375 if (sg.cs.getThreshold() != 0)
\r
377 text.append("pidThreshold=" + sg.cs.getThreshold());
\r
379 if (sg.cs.conservationApplied())
\r
381 text.append("consThreshold=" + sg.cs.getConservationInc() + "\t");
\r
384 text.append("outlineColour="
\r
385 + jalview.util.Format.getHexString(sg.getOutlineColour())
\r
388 text.append("displayBoxes=" + sg.getDisplayBoxes() + "\t");
\r
389 text.append("displayText=" + sg.getDisplayText() + "\t");
\r
390 text.append("colourText=" + sg.getColourText() + "\t");
\r
391 text.append("showUnconserved=" + sg.getShowunconserved() + "\t");
\r
392 if (sg.textColour != java.awt.Color.black)
\r
394 text.append("textCol1="
\r
395 + jalview.util.Format.getHexString(sg.textColour) + "\t");
\r
397 if (sg.textColour2 != java.awt.Color.white)
\r
399 text.append("textCol2="
\r
400 + jalview.util.Format.getHexString(sg.textColour2) + "\t");
\r
402 if (sg.thresholdTextColour != 0)
\r
404 text.append("textColThreshold=" + sg.thresholdTextColour + "\t");
\r
406 if (sg.idColour != null)
\r
408 text.append("idColour="
\r
409 + jalview.util.Format.getHexString(sg.idColour) + "\t");
\r
411 if (sg.isHidereps())
\r
413 text.append("hide=true\t");
\r
415 if (sg.isHideCols())
\r
417 text.append("hidecols=true\t");
\r
419 if (seqrep != null)
\r
421 // terminate the last line and clear the sequence ref for the group
\r
422 text.append("\nSEQUENCE_REF");
\r
424 text.append("\n\n");
\r
429 SequenceI refSeq = null;
\r
431 String refSeqId = null;
\r
433 public boolean readAnnotationFile(AlignmentI al, String file,
\r
438 BufferedReader in = null;
\r
439 if (protocol.equals(AppletFormatAdapter.FILE))
\r
441 in = new BufferedReader(new FileReader(file));
\r
443 else if (protocol.equals(AppletFormatAdapter.URL))
\r
445 URL url = new URL(file);
\r
446 in = new BufferedReader(new InputStreamReader(url.openStream()));
\r
448 else if (protocol.equals(AppletFormatAdapter.PASTE))
\r
450 in = new BufferedReader(new StringReader(file));
\r
452 else if (protocol.equals(AppletFormatAdapter.CLASSLOADER))
\r
454 java.io.InputStream is = getClass().getResourceAsStream("/" + file);
\r
457 in = new BufferedReader(new java.io.InputStreamReader(is));
\r
461 String line, label, description, token;
\r
462 int graphStyle, index;
\r
463 int refSeqIndex = 1;
\r
464 int existingAnnotations = 0;
\r
465 if (al.getAlignmentAnnotation() != null)
\r
467 existingAnnotations = al.getAlignmentAnnotation().length;
\r
470 int alWidth = al.getWidth();
\r
472 StringTokenizer st;
\r
473 Annotation[] annotations;
\r
474 AlignmentAnnotation annotation = null;
\r
476 // First confirm this is an Annotation file
\r
477 boolean jvAnnotationFile = false;
\r
478 while ((line = in.readLine()) != null)
\r
480 if (line.indexOf("#") == 0)
\r
485 if (line.indexOf("JALVIEW_ANNOTATION") > -1)
\r
487 jvAnnotationFile = true;
\r
492 if (!jvAnnotationFile)
\r
498 while ((line = in.readLine()) != null)
\r
500 if (line.indexOf("#") == 0
\r
501 || line.indexOf("JALVIEW_ANNOTATION") > -1
\r
502 || line.length() == 0)
\r
507 st = new StringTokenizer(line, "\t");
\r
508 token = st.nextToken();
\r
509 if (token.equalsIgnoreCase("COLOUR"))
\r
511 // TODO: use graduated colour def'n here too
\r
512 colourAnnotations(al, st.nextToken(), st.nextToken());
\r
516 else if (token.equalsIgnoreCase("COMBINE"))
\r
518 combineAnnotations(al, st);
\r
521 else if (token.equalsIgnoreCase("ROWPROPERTIES"))
\r
523 addRowProperties(al, st);
\r
526 else if (token.equalsIgnoreCase("GRAPHLINE"))
\r
532 else if (token.equalsIgnoreCase("SEQUENCE_REF"))
\r
534 if (st.hasMoreTokens())
\r
536 refSeq = al.findName(refSeqId = st.nextToken());
\r
537 if (refSeq == null)
\r
543 refSeqIndex = Integer.parseInt(st.nextToken());
\r
544 if (refSeqIndex < 1)
\r
548 .println("WARNING: SEQUENCE_REF index must be > 0 in AnnotationFile");
\r
550 } catch (Exception ex)
\r
563 else if (token.equalsIgnoreCase("SEQUENCE_GROUP"))
\r
569 else if (token.equalsIgnoreCase("PROPERTIES"))
\r
571 addProperties(al, st);
\r
575 else if (token.equalsIgnoreCase("BELOW_ALIGNMENT"))
\r
577 setBelowAlignment(al, st);
\r
580 else if (token.equalsIgnoreCase("ALIGNMENT"))
\r
582 addAlignmentDetails(al, st);
\r
586 graphStyle = AlignmentAnnotation.getGraphValueFromString(token);
\r
587 label = st.nextToken();
\r
590 annotations = new Annotation[alWidth];
\r
591 description = null;
\r
592 float score = Float.NaN;
\r
594 if (st.hasMoreTokens())
\r
596 line = st.nextToken();
\r
598 if (line.indexOf("|") == -1)
\r
600 description = line;
\r
601 if (st.hasMoreTokens())
\r
602 line = st.nextToken();
\r
605 if (st.hasMoreTokens())
\r
607 // This must be the score
\r
608 score = Float.valueOf(st.nextToken()).floatValue();
\r
611 st = new StringTokenizer(line, "|", true);
\r
613 boolean emptyColumn = true;
\r
614 boolean onlyOneElement = (st.countTokens() == 1);
\r
616 while (st.hasMoreElements() && index < alWidth)
\r
618 token = st.nextToken().trim();
\r
620 if (onlyOneElement)
\r
624 score = Float.valueOf(token).floatValue();
\r
626 } catch (NumberFormatException ex)
\r
631 if (token.equals("|"))
\r
638 emptyColumn = true;
\r
642 annotations[index++] = parseAnnotation(token, graphStyle);
\r
643 emptyColumn = false;
\r
649 annotation = new AlignmentAnnotation(label, description,
\r
650 (index == 0) ? null : annotations, 0, 0, graphStyle);
\r
652 annotation.score = score;
\r
654 if (refSeq != null)
\r
656 annotation.belowAlignment = false;
\r
657 // make a copy of refSeq so we can find other matches in the alignment
\r
658 SequenceI referedSeq = refSeq;
\r
661 // copy before we do any mapping business.
\r
662 // TODO: verify that undo/redo with 1:many sequence associated
\r
663 // annotations can be undone correctly
\r
664 AlignmentAnnotation ann = new AlignmentAnnotation(annotation);
\r
666 .createSequenceMapping(referedSeq, refSeqIndex, false);
\r
667 annotation.adjustForAlignment();
\r
668 referedSeq.addAlignmentAnnotation(annotation);
\r
669 al.addAnnotation(annotation);
\r
670 al.setAnnotationIndex(annotation,
\r
671 al.getAlignmentAnnotation().length
\r
672 - existingAnnotations - 1);
\r
673 // and recover our virgin copy to use again if necessary.
\r
676 } while (refSeqId != null
\r
677 && (referedSeq = al.findName(referedSeq, refSeqId, true)) != null);
\r
681 al.addAnnotation(annotation);
\r
682 al.setAnnotationIndex(annotation,
\r
683 al.getAlignmentAnnotation().length - existingAnnotations
\r
688 } catch (Exception ex)
\r
690 ex.printStackTrace();
\r
691 System.out.println("Problem reading annotation file: " + ex);
\r
697 Annotation parseAnnotation(String string, int graphStyle)
\r
699 boolean hasSymbols = (graphStyle == AlignmentAnnotation.NO_GRAPH); // don't do the glyph test if we don't want secondary structure
\r
700 String desc = null, displayChar = null;
\r
701 char ss = ' '; // secondaryStructure
\r
703 boolean parsedValue = false, dcset = false;
\r
705 // find colour here
\r
706 java.awt.Color colour = null;
\r
707 int i = string.indexOf("[");
\r
708 int j = string.indexOf("]");
\r
709 if (i > -1 && j > -1)
\r
711 UserColourScheme ucs = new UserColourScheme();
\r
713 colour = ucs.getColourFromString(string.substring(i + 1, j));
\r
714 if ( i>0 && string.charAt(i-1)==',')
\r
716 // clip the preceding comma as well
\r
719 string = string.substring(0, i) + string.substring(j + 1);
\r
722 StringTokenizer st = new StringTokenizer(string, ",", true);
\r
724 boolean seenContent=false;
\r
726 while (st.hasMoreTokens())
\r
729 token = st.nextToken().trim();
\r
730 if (token.equals(","))
\r
732 if (!seenContent && parsedValue && !dcset)
\r
734 // allow the value below the bar/line to be empty
\r
738 seenContent = false;
\r
741 seenContent = true;
\r
748 displayChar = token;
\r
750 value = new Float(token).floatValue();
\r
751 parsedValue = true;
\r
753 } catch (NumberFormatException ex)
\r
757 if (token.length()==1)
\r
759 displayChar = token;
\r
762 if (hasSymbols && (token.equals("H") || token.equals("E") || token.equals(" ")))
\r
764 // Either this character represents a helix or sheet
\r
765 // or an integer which can be displayed
\r
766 ss = token.charAt(0);
\r
767 if (displayChar.equals(token.substring(0, 1)))
\r
772 else if (desc == null || (parsedValue && pass>2))
\r
778 // if (!dcset && string.charAt(string.length() - 1) == ',')
\r
780 // displayChar = " "; // empty display char symbol.
\r
782 if (displayChar != null && desc!=null && desc.length()==1)
\r
784 if (displayChar.length() > 1)
\r
786 // switch desc and displayChar - legacy support
\r
787 String tmp = displayChar;
\r
788 displayChar = desc;
\r
791 if (displayChar.equals(desc)) {
\r
792 // duplicate label - hangover from the 'robust parser' above
\r
797 Annotation anot = new Annotation(displayChar, desc, ss, value);
\r
799 anot.colour = colour;
\r
804 void colourAnnotations(AlignmentI al, String label, String colour)
\r
806 UserColourScheme ucs = new UserColourScheme(colour);
\r
807 Annotation[] annotations;
\r
808 for (int i = 0; i < al.getAlignmentAnnotation().length; i++)
\r
810 if (al.getAlignmentAnnotation()[i].label.equalsIgnoreCase(label))
\r
812 annotations = al.getAlignmentAnnotation()[i].annotations;
\r
813 for (int j = 0; j < annotations.length; j++)
\r
815 if (annotations[j] != null)
\r
817 annotations[j].colour = ucs.findColour('A');
\r
824 void combineAnnotations(AlignmentI al, StringTokenizer st)
\r
826 int graphGroup = -1;
\r
827 String group = st.nextToken();
\r
828 // First make sure we are not overwriting the graphIndex
\r
829 for (int i = 0; i < al.getAlignmentAnnotation().length; i++)
\r
831 if (al.getAlignmentAnnotation()[i].label.equalsIgnoreCase(group))
\r
833 graphGroup = al.getAlignmentAnnotation()[i].graphGroup + 1;
\r
834 al.getAlignmentAnnotation()[i].graphGroup = graphGroup;
\r
839 // Now update groups
\r
840 while (st.hasMoreTokens())
\r
842 group = st.nextToken();
\r
843 for (int i = 0; i < al.getAlignmentAnnotation().length; i++)
\r
845 if (al.getAlignmentAnnotation()[i].label.equalsIgnoreCase(group))
\r
847 al.getAlignmentAnnotation()[i].graphGroup = graphGroup;
\r
854 void addLine(AlignmentI al, StringTokenizer st)
\r
856 String group = st.nextToken();
\r
857 AlignmentAnnotation annotation = null;
\r
859 for (int i = 0; i < al.getAlignmentAnnotation().length; i++)
\r
861 if (al.getAlignmentAnnotation()[i].label.equalsIgnoreCase(group))
\r
863 annotation = al.getAlignmentAnnotation()[i];
\r
868 if (annotation == null)
\r
872 float value = new Float(st.nextToken()).floatValue();
\r
873 String label = st.hasMoreTokens() ? st.nextToken() : null;
\r
874 java.awt.Color colour = null;
\r
875 if (st.hasMoreTokens())
\r
877 UserColourScheme ucs = new UserColourScheme(st.nextToken());
\r
878 colour = ucs.findColour('A');
\r
881 annotation.setThreshold(new GraphLine(value, label, colour));
\r
884 void addGroup(AlignmentI al, StringTokenizer st)
\r
886 SequenceGroup sg = new SequenceGroup();
\r
887 sg.setName(st.nextToken());
\r
891 rng = st.nextToken();
\r
892 if (rng.length() > 0 && !rng.startsWith("*"))
\r
894 sg.setStartRes(Integer.parseInt(rng) - 1);
\r
900 rng = st.nextToken();
\r
901 if (rng.length() > 0 && !rng.startsWith("*"))
\r
903 sg.setEndRes(Integer.parseInt(rng) - 1);
\r
907 sg.setEndRes(al.getWidth() - 1);
\r
909 } catch (Exception e)
\r
912 .println("Couldn't parse Group Start or End Field as '*' or a valid column or sequence index: '"
\r
913 + rng + "' - assuming alignment width for group.");
\r
914 // assume group is full width
\r
916 sg.setEndRes(al.getWidth() - 1);
\r
919 String index = st.nextToken();
\r
920 if (index.equals("-1"))
\r
922 while (st.hasMoreElements())
\r
924 sg.addSequence(al.findName(st.nextToken()), false);
\r
929 StringTokenizer st2 = new StringTokenizer(index, ",");
\r
931 while (st2.hasMoreTokens())
\r
933 String tmp = st2.nextToken();
\r
934 if (tmp.equals("*"))
\r
936 for (int i = 0; i < al.getHeight(); i++)
\r
938 sg.addSequence(al.getSequenceAt(i), false);
\r
941 else if (tmp.indexOf("-") >= 0)
\r
943 StringTokenizer st3 = new StringTokenizer(tmp, "-");
\r
945 int start = (Integer.parseInt(st3.nextToken()));
\r
946 int end = (Integer.parseInt(st3.nextToken()));
\r
950 for (int i = start; i <= end; i++)
\r
952 sg.addSequence(al.getSequenceAt(i - 1), false);
\r
959 .addSequence(al.getSequenceAt(Integer.parseInt(tmp) - 1),
\r
965 if (refSeq != null)
\r
967 sg.setStartRes(refSeq.findIndex(sg.getStartRes() + 1) - 1);
\r
968 sg.setEndRes(refSeq.findIndex(sg.getEndRes() + 1) - 1);
\r
969 sg.setSeqrep(refSeq);
\r
972 if (sg.getSize() > 0)
\r
978 void addRowProperties(AlignmentI al, StringTokenizer st)
\r
980 String label = st.nextToken(),keyValue,key,value;
\r
981 boolean scaletofit=false,centerlab=false,showalllabs=false;
\r
982 while (st.hasMoreTokens()) {
\r
983 keyValue=st.nextToken();
\r
984 key = keyValue.substring(0, keyValue.indexOf("="));
\r
985 value = keyValue.substring(keyValue.indexOf("=") + 1);
\r
986 if (key.equalsIgnoreCase("scaletofit")) {
\r
987 scaletofit = Boolean.valueOf(value).booleanValue();
\r
989 if (key.equalsIgnoreCase("showalllabs")) {
\r
990 showalllabs = Boolean.valueOf(value).booleanValue();
\r
992 if (key.equalsIgnoreCase("centrelabs")) {
\r
993 centerlab = Boolean.valueOf(value).booleanValue();
\r
995 AlignmentAnnotation[] alr = al.getAlignmentAnnotation();
\r
996 for (int i = 0; i < alr.length; i++)
\r
998 if (alr[i].label.equalsIgnoreCase(label))
\r
1000 alr[i].centreColLabels = centerlab;
\r
1001 alr[i].scaleColLabel = scaletofit;
\r
1002 alr[i].showAllColLabels = showalllabs;
\r
1007 void addProperties(AlignmentI al, StringTokenizer st)
\r
1010 // So far we have only added groups to the annotationHash,
\r
1011 // the idea is in the future properties can be added to
\r
1012 // alignments, other annotations etc
\r
1013 if (al.getGroups() == null)
\r
1017 SequenceGroup sg = null;
\r
1019 String name = st.nextToken();
\r
1021 Vector groups = al.getGroups();
\r
1022 for (int i = 0; i < groups.size(); i++)
\r
1024 sg = (SequenceGroup) groups.elementAt(i);
\r
1025 if (sg.getName().equals(name))
\r
1037 String keyValue, key, value;
\r
1038 ColourSchemeI def = sg.cs;
\r
1040 while (st.hasMoreTokens())
\r
1042 keyValue = st.nextToken();
\r
1043 key = keyValue.substring(0, keyValue.indexOf("="));
\r
1044 value = keyValue.substring(keyValue.indexOf("=") + 1);
\r
1046 if (key.equalsIgnoreCase("description"))
\r
1048 sg.setDescription(value);
\r
1050 else if (key.equalsIgnoreCase("colour"))
\r
1052 sg.cs = ColourSchemeProperty.getColour(al, value);
\r
1054 else if (key.equalsIgnoreCase("pidThreshold"))
\r
1056 sg.cs.setThreshold(Integer.parseInt(value), true);
\r
1059 else if (key.equalsIgnoreCase("consThreshold"))
\r
1061 sg.cs.setConservationInc(Integer.parseInt(value));
\r
1062 Conservation c = new Conservation("Group",
\r
1063 ResidueProperties.propHash, 3, sg.getSequences(null), sg
\r
1064 .getStartRes(), sg.getEndRes() + 1);
\r
1067 c.verdict(false, 25);
\r
1069 sg.cs.setConservation(c);
\r
1072 else if (key.equalsIgnoreCase("outlineColour"))
\r
1074 sg.setOutlineColour(new UserColourScheme(value).findColour('A'));
\r
1076 else if (key.equalsIgnoreCase("displayBoxes"))
\r
1078 sg.setDisplayBoxes(Boolean.valueOf(value).booleanValue());
\r
1080 else if (key.equalsIgnoreCase("showUnconserved"))
\r
1082 sg.setShowunconserved(Boolean.valueOf(value).booleanValue());
\r
1084 else if (key.equalsIgnoreCase("displayText"))
\r
1086 sg.setDisplayText(Boolean.valueOf(value).booleanValue());
\r
1088 else if (key.equalsIgnoreCase("colourText"))
\r
1090 sg.setColourText(Boolean.valueOf(value).booleanValue());
\r
1092 else if (key.equalsIgnoreCase("textCol1"))
\r
1094 sg.textColour = new UserColourScheme(value).findColour('A');
\r
1096 else if (key.equalsIgnoreCase("textCol2"))
\r
1098 sg.textColour2 = new UserColourScheme(value).findColour('A');
\r
1100 else if (key.equalsIgnoreCase("textColThreshold"))
\r
1102 sg.thresholdTextColour = Integer.parseInt(value);
\r
1104 else if (key.equalsIgnoreCase("idColour"))
\r
1106 // consider warning if colour doesn't resolve to a real colour
\r
1107 sg.setIdColour((def = new UserColourScheme(value))
\r
1108 .findColour('A'));
\r
1110 else if (key.equalsIgnoreCase("hide"))
\r
1112 // see bug https://mantis.lifesci.dundee.ac.uk/view.php?id=25847
\r
1113 sg.setHidereps(true);
\r
1115 else if (key.equalsIgnoreCase("hidecols"))
\r
1117 // see bug https://mantis.lifesci.dundee.ac.uk/view.php?id=25847
\r
1118 sg.setHideCols(true);
\r
1120 sg.recalcConservation();
\r
1122 if (sg.cs == null)
\r
1129 void setBelowAlignment(AlignmentI al, StringTokenizer st)
\r
1132 AlignmentAnnotation aa;
\r
1133 while (st.hasMoreTokens())
\r
1135 token = st.nextToken();
\r
1136 for (int i = 0; i < al.getAlignmentAnnotation().length; i++)
\r
1138 aa = al.getAlignmentAnnotation()[i];
\r
1139 if (aa.sequenceRef == refSeq && aa.label.equals(token))
\r
1141 aa.belowAlignment = true;
\r
1147 void addAlignmentDetails(AlignmentI al, StringTokenizer st)
\r
1149 String keyValue, key, value;
\r
1150 while (st.hasMoreTokens())
\r
1152 keyValue = st.nextToken();
\r
1153 key = keyValue.substring(0, keyValue.indexOf("="));
\r
1154 value = keyValue.substring(keyValue.indexOf("=") + 1);
\r
1155 al.setProperty(key, value);
\r
1160 * Write annotations as a CSV file of the form 'label, value, value, ...' for
\r
1163 * @param annotations
\r
1164 * @return CSV file as a string.
\r
1166 public String printCSVAnnotations(AlignmentAnnotation[] annotations)
\r
1168 StringBuffer sp = new StringBuffer();
\r
1169 for (int i = 0; i < annotations.length; i++)
\r
1171 String atos = annotations[i].toString();
\r
1175 int cp = atos.indexOf("\n", p);
\r
1176 sp.append(annotations[i].label);
\r
1180 sp.append(atos.substring(p, cp + 1));
\r
1184 sp.append(atos.substring(p));
\r
1190 return sp.toString();
\r