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 = false, hasLabels = false, hasValues = false, 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 && row.annotations[j].secondaryStructure != ' ')
\r
216 text.append(comma + row.annotations[j].secondaryStructure);
\r
221 if (row.annotations[j].value != Float.NaN)
\r
223 text.append(comma + row.annotations[j].value);
\r
227 System.err.println("Skipping NaN - not valid value.");
\r
228 text.append(comma + 0f);// row.annotations[j].value);
\r
234 // TODO: labels are emitted after values for bar graphs.
\r
235 if // empty labels are allowed, so
\r
236 (row.annotations[j].displayCharacter != null
\r
237 && row.annotations[j].displayCharacter.length() > 0
\r
238 && !row.annotations[j].displayCharacter.equals(" "))
\r
240 text.append(comma + row.annotations[j].displayCharacter);
\r
246 if (row.annotations[j].description != null
\r
247 && row.annotations[j].description.length() > 0
\r
248 && !row.annotations[j].description
\r
249 .equals(row.annotations[j].displayCharacter))
\r
251 text.append(comma + row.annotations[j].description);
\r
255 if (color != null && !color.equals(row.annotations[j].colour))
\r
260 color = row.annotations[j].colour;
\r
262 if (row.annotations[j].colour != null
\r
263 && row.annotations[j].colour != java.awt.Color.black)
\r
267 + jalview.util.Format
\r
268 .getHexString(row.annotations[j].colour)
\r
276 if (row.hasScore())
\r
277 text.append("\t" + row.score);
\r
281 if (color != null && color != java.awt.Color.black && oneColour)
\r
283 colours.append("COLOUR\t" + row.label + "\t"
\r
284 + jalview.util.Format.getHexString(color) + "\n");
\r
286 if (row.scaleColLabel || row.showAllColLabels || row.centreColLabels)
\r
288 rowprops.append("ROWPROPERTIES\t"+row.label);
\r
289 rowprops.append("\tscaletofit="+row.scaleColLabel);
\r
290 rowprops.append("\tshowalllabs="+row.showAllColLabels);
\r
291 rowprops.append("\tcentrelabs="+row.centreColLabels);
\r
292 rowprops.append("\n");
\r
298 text.append(colours.toString());
\r
299 text.append(graphLine.toString());
\r
300 if (graphGroup.size() > 0)
\r
302 text.append("COMBINE\t");
\r
303 Enumeration en = graphGroup.elements();
\r
304 while (en.hasMoreElements())
\r
306 text.append(en.nextElement() + "\n");
\r
309 text.append(rowprops.toString());
\r
312 if (groups != null)
\r
314 printGroups(groups);
\r
317 if (properties != null)
\r
319 text.append("\n\nALIGNMENT");
\r
320 Enumeration en = properties.keys();
\r
321 while (en.hasMoreElements())
\r
323 String key = en.nextElement().toString();
\r
324 text.append("\t" + key + "=" + properties.get(key));
\r
326 // TODO: output alignment visualization settings here if required
\r
330 return text.toString();
\r
333 public void printGroups(Vector sequenceGroups)
\r
336 SequenceI seqrep = null;
\r
337 for (int i = 0; i < sequenceGroups.size(); i++)
\r
339 sg = (SequenceGroup) sequenceGroups.elementAt(i);
\r
340 if (!sg.hasSeqrep())
\r
342 text.append("SEQUENCE_GROUP\t" + sg.getName() + "\t"
\r
343 + (sg.getStartRes() + 1) + "\t" + (sg.getEndRes() + 1)
\r
349 seqrep = sg.getSeqrep();
\r
350 text.append("SEQUENCE_REF\t" + seqrep.getName() + "\n");
\r
351 text.append("SEQUENCE_GROUP\t" + sg.getName() + "\t"
\r
352 + (seqrep.findPosition(sg.getStartRes())) + "\t"
\r
353 + (seqrep.findPosition(sg.getEndRes())) + "\t" + "-1\t");
\r
355 for (int s = 0; s < sg.getSize(); s++)
\r
357 text.append(sg.getSequenceAt(s).getName() + "\t");
\r
360 text.append("\nPROPERTIES\t" + sg.getName() + "\t");
\r
362 if (sg.getDescription() != null)
\r
364 text.append("description=" + sg.getDescription() + "\t");
\r
368 text.append("colour=" + ColourSchemeProperty.getColourName(sg.cs)
\r
370 if (sg.cs.getThreshold() != 0)
\r
372 text.append("pidThreshold=" + sg.cs.getThreshold());
\r
374 if (sg.cs.conservationApplied())
\r
376 text.append("consThreshold=" + sg.cs.getConservationInc() + "\t");
\r
379 text.append("outlineColour="
\r
380 + jalview.util.Format.getHexString(sg.getOutlineColour())
\r
383 text.append("displayBoxes=" + sg.getDisplayBoxes() + "\t");
\r
384 text.append("displayText=" + sg.getDisplayText() + "\t");
\r
385 text.append("colourText=" + sg.getColourText() + "\t");
\r
386 text.append("showUnconserved=" + sg.getShowunconserved() + "\t");
\r
387 if (sg.textColour != java.awt.Color.black)
\r
389 text.append("textCol1="
\r
390 + jalview.util.Format.getHexString(sg.textColour) + "\t");
\r
392 if (sg.textColour2 != java.awt.Color.white)
\r
394 text.append("textCol2="
\r
395 + jalview.util.Format.getHexString(sg.textColour2) + "\t");
\r
397 if (sg.thresholdTextColour != 0)
\r
399 text.append("textColThreshold=" + sg.thresholdTextColour + "\t");
\r
401 if (sg.idColour != null)
\r
403 text.append("idColour="
\r
404 + jalview.util.Format.getHexString(sg.idColour) + "\t");
\r
406 if (sg.isHidereps())
\r
408 text.append("hide=true\t");
\r
410 if (sg.isHideCols())
\r
412 text.append("hidecols=true\t");
\r
414 if (seqrep != null)
\r
416 // terminate the last line and clear the sequence ref for the group
\r
417 text.append("\nSEQUENCE_REF");
\r
419 text.append("\n\n");
\r
424 SequenceI refSeq = null;
\r
426 String refSeqId = null;
\r
428 public boolean readAnnotationFile(AlignmentI al, String file,
\r
433 BufferedReader in = null;
\r
434 if (protocol.equals(AppletFormatAdapter.FILE))
\r
436 in = new BufferedReader(new FileReader(file));
\r
438 else if (protocol.equals(AppletFormatAdapter.URL))
\r
440 URL url = new URL(file);
\r
441 in = new BufferedReader(new InputStreamReader(url.openStream()));
\r
443 else if (protocol.equals(AppletFormatAdapter.PASTE))
\r
445 in = new BufferedReader(new StringReader(file));
\r
447 else if (protocol.equals(AppletFormatAdapter.CLASSLOADER))
\r
449 java.io.InputStream is = getClass().getResourceAsStream("/" + file);
\r
452 in = new BufferedReader(new java.io.InputStreamReader(is));
\r
456 String line, label, description, token;
\r
457 int graphStyle, index;
\r
458 int refSeqIndex = 1;
\r
459 int existingAnnotations = 0;
\r
460 if (al.getAlignmentAnnotation() != null)
\r
462 existingAnnotations = al.getAlignmentAnnotation().length;
\r
465 int alWidth = al.getWidth();
\r
467 StringTokenizer st;
\r
468 Annotation[] annotations;
\r
469 AlignmentAnnotation annotation = null;
\r
471 // First confirm this is an Annotation file
\r
472 boolean jvAnnotationFile = false;
\r
473 while ((line = in.readLine()) != null)
\r
475 if (line.indexOf("#") == 0)
\r
480 if (line.indexOf("JALVIEW_ANNOTATION") > -1)
\r
482 jvAnnotationFile = true;
\r
487 if (!jvAnnotationFile)
\r
493 while ((line = in.readLine()) != null)
\r
495 if (line.indexOf("#") == 0
\r
496 || line.indexOf("JALVIEW_ANNOTATION") > -1
\r
497 || line.length() == 0)
\r
502 st = new StringTokenizer(line, "\t");
\r
503 token = st.nextToken();
\r
504 if (token.equalsIgnoreCase("COLOUR"))
\r
506 // TODO: use graduated colour def'n here too
\r
507 colourAnnotations(al, st.nextToken(), st.nextToken());
\r
511 else if (token.equalsIgnoreCase("COMBINE"))
\r
513 combineAnnotations(al, st);
\r
516 else if (token.equalsIgnoreCase("ROWPROPERTIES"))
\r
518 addRowProperties(al, st);
\r
521 else if (token.equalsIgnoreCase("GRAPHLINE"))
\r
527 else if (token.equalsIgnoreCase("SEQUENCE_REF"))
\r
529 if (st.hasMoreTokens())
\r
531 refSeq = al.findName(refSeqId = st.nextToken());
\r
532 if (refSeq == null)
\r
538 refSeqIndex = Integer.parseInt(st.nextToken());
\r
539 if (refSeqIndex < 1)
\r
543 .println("WARNING: SEQUENCE_REF index must be > 0 in AnnotationFile");
\r
545 } catch (Exception ex)
\r
558 else if (token.equalsIgnoreCase("SEQUENCE_GROUP"))
\r
564 else if (token.equalsIgnoreCase("PROPERTIES"))
\r
566 addProperties(al, st);
\r
570 else if (token.equalsIgnoreCase("BELOW_ALIGNMENT"))
\r
572 setBelowAlignment(al, st);
\r
575 else if (token.equalsIgnoreCase("ALIGNMENT"))
\r
577 addAlignmentDetails(al, st);
\r
581 graphStyle = AlignmentAnnotation.getGraphValueFromString(token);
\r
582 label = st.nextToken();
\r
585 annotations = new Annotation[alWidth];
\r
586 description = null;
\r
587 float score = Float.NaN;
\r
589 if (st.hasMoreTokens())
\r
591 line = st.nextToken();
\r
593 if (line.indexOf("|") == -1)
\r
595 description = line;
\r
596 if (st.hasMoreTokens())
\r
597 line = st.nextToken();
\r
600 if (st.hasMoreTokens())
\r
602 // This must be the score
\r
603 score = Float.valueOf(st.nextToken()).floatValue();
\r
606 st = new StringTokenizer(line, "|", true);
\r
608 boolean emptyColumn = true;
\r
609 boolean onlyOneElement = (st.countTokens() == 1);
\r
611 while (st.hasMoreElements() && index < alWidth)
\r
613 token = st.nextToken().trim();
\r
615 if (onlyOneElement)
\r
619 score = Float.valueOf(token).floatValue();
\r
621 } catch (NumberFormatException ex)
\r
626 if (token.equals("|"))
\r
633 emptyColumn = true;
\r
637 annotations[index++] = parseAnnotation(token, graphStyle);
\r
638 emptyColumn = false;
\r
644 annotation = new AlignmentAnnotation(label, description,
\r
645 (index == 0) ? null : annotations, 0, 0, graphStyle);
\r
647 annotation.score = score;
\r
649 if (refSeq != null)
\r
651 annotation.belowAlignment = false;
\r
652 // make a copy of refSeq so we can find other matches in the alignment
\r
653 SequenceI referedSeq = refSeq;
\r
656 // copy before we do any mapping business.
\r
657 // TODO: verify that undo/redo with 1:many sequence associated
\r
658 // annotations can be undone correctly
\r
659 AlignmentAnnotation ann = new AlignmentAnnotation(annotation);
\r
661 .createSequenceMapping(referedSeq, refSeqIndex, false);
\r
662 annotation.adjustForAlignment();
\r
663 referedSeq.addAlignmentAnnotation(annotation);
\r
664 al.addAnnotation(annotation);
\r
665 al.setAnnotationIndex(annotation,
\r
666 al.getAlignmentAnnotation().length
\r
667 - existingAnnotations - 1);
\r
668 // and recover our virgin copy to use again if necessary.
\r
671 } while (refSeqId != null
\r
672 && (referedSeq = al.findName(referedSeq, refSeqId, true)) != null);
\r
676 al.addAnnotation(annotation);
\r
677 al.setAnnotationIndex(annotation,
\r
678 al.getAlignmentAnnotation().length - existingAnnotations
\r
683 } catch (Exception ex)
\r
685 ex.printStackTrace();
\r
686 System.out.println("Problem reading annotation file: " + ex);
\r
692 Annotation parseAnnotation(String string, int graphStyle)
\r
694 boolean hasSymbols = (graphStyle == AlignmentAnnotation.NO_GRAPH); // don't do the glyph test if we don't want secondary structure
\r
695 String desc = null, displayChar = null;
\r
696 char ss = ' '; // secondaryStructure
\r
698 boolean parsedValue = false, dcset = false;
\r
700 // find colour here
\r
701 java.awt.Color colour = null;
\r
702 int i = string.indexOf("[");
\r
703 int j = string.indexOf("]");
\r
704 if (i > -1 && j > -1)
\r
706 UserColourScheme ucs = new UserColourScheme();
\r
708 colour = ucs.getColourFromString(string.substring(i + 1, j));
\r
709 if ( i>0 && string.charAt(i-1)==',')
\r
711 // clip the preceding comma as well
\r
714 string = string.substring(0, i) + string.substring(j + 1);
\r
717 StringTokenizer st = new StringTokenizer(string, ",", true);
\r
719 boolean seenContent=false;
\r
720 while (st.hasMoreTokens())
\r
722 token = st.nextToken().trim();
\r
723 if (token.equals(","))
\r
725 if (!seenContent && parsedValue && !dcset)
\r
727 // allow the value below the bar/line to be empty
\r
731 seenContent = false;
\r
734 seenContent = true;
\r
741 displayChar = token;
\r
743 value = new Float(token).floatValue();
\r
744 parsedValue = true;
\r
746 } catch (NumberFormatException ex)
\r
751 if (hasSymbols && (token.equals("H") || token.equals("E")))
\r
753 // Either this character represents a helix or sheet
\r
754 // or an integer which can be displayed
\r
755 ss = token.charAt(0);
\r
756 if (displayChar.equals(token.substring(0, 1)))
\r
761 else if (desc == null)
\r
767 // if (!dcset && string.charAt(string.length() - 1) == ',')
\r
769 // displayChar = " "; // empty display char symbol.
\r
771 if (displayChar != null && displayChar.length() > 1 && desc != null
\r
772 && desc.length() == 1)
\r
774 String tmp = displayChar;
\r
775 displayChar = desc;
\r
779 * In principle, this code will ensure that the Annotation element generated
\r
780 * is renderable by any of the applet or application rendering code but
\r
781 * instead we check for null strings when the display character is rendered.
\r
782 * if (displayChar==null) { displayChar=""; }
\r
784 Annotation anot = new Annotation(displayChar, desc, ss, value);
\r
786 anot.colour = colour;
\r
791 void colourAnnotations(AlignmentI al, String label, String colour)
\r
793 UserColourScheme ucs = new UserColourScheme(colour);
\r
794 Annotation[] annotations;
\r
795 for (int i = 0; i < al.getAlignmentAnnotation().length; i++)
\r
797 if (al.getAlignmentAnnotation()[i].label.equalsIgnoreCase(label))
\r
799 annotations = al.getAlignmentAnnotation()[i].annotations;
\r
800 for (int j = 0; j < annotations.length; j++)
\r
802 if (annotations[j] != null)
\r
804 annotations[j].colour = ucs.findColour('A');
\r
811 void combineAnnotations(AlignmentI al, StringTokenizer st)
\r
813 int graphGroup = -1;
\r
814 String group = st.nextToken();
\r
815 // First make sure we are not overwriting the graphIndex
\r
816 for (int i = 0; i < al.getAlignmentAnnotation().length; i++)
\r
818 if (al.getAlignmentAnnotation()[i].label.equalsIgnoreCase(group))
\r
820 graphGroup = al.getAlignmentAnnotation()[i].graphGroup + 1;
\r
821 al.getAlignmentAnnotation()[i].graphGroup = graphGroup;
\r
826 // Now update groups
\r
827 while (st.hasMoreTokens())
\r
829 group = st.nextToken();
\r
830 for (int i = 0; i < al.getAlignmentAnnotation().length; i++)
\r
832 if (al.getAlignmentAnnotation()[i].label.equalsIgnoreCase(group))
\r
834 al.getAlignmentAnnotation()[i].graphGroup = graphGroup;
\r
841 void addLine(AlignmentI al, StringTokenizer st)
\r
843 String group = st.nextToken();
\r
844 AlignmentAnnotation annotation = null;
\r
846 for (int i = 0; i < al.getAlignmentAnnotation().length; i++)
\r
848 if (al.getAlignmentAnnotation()[i].label.equalsIgnoreCase(group))
\r
850 annotation = al.getAlignmentAnnotation()[i];
\r
855 if (annotation == null)
\r
859 float value = new Float(st.nextToken()).floatValue();
\r
860 String label = st.hasMoreTokens() ? st.nextToken() : null;
\r
861 java.awt.Color colour = null;
\r
862 if (st.hasMoreTokens())
\r
864 UserColourScheme ucs = new UserColourScheme(st.nextToken());
\r
865 colour = ucs.findColour('A');
\r
868 annotation.setThreshold(new GraphLine(value, label, colour));
\r
871 void addGroup(AlignmentI al, StringTokenizer st)
\r
873 SequenceGroup sg = new SequenceGroup();
\r
874 sg.setName(st.nextToken());
\r
878 rng = st.nextToken();
\r
879 if (rng.length() > 0 && !rng.startsWith("*"))
\r
881 sg.setStartRes(Integer.parseInt(rng) - 1);
\r
887 rng = st.nextToken();
\r
888 if (rng.length() > 0 && !rng.startsWith("*"))
\r
890 sg.setEndRes(Integer.parseInt(rng) - 1);
\r
894 sg.setEndRes(al.getWidth() - 1);
\r
896 } catch (Exception e)
\r
899 .println("Couldn't parse Group Start or End Field as '*' or a valid column or sequence index: '"
\r
900 + rng + "' - assuming alignment width for group.");
\r
901 // assume group is full width
\r
903 sg.setEndRes(al.getWidth() - 1);
\r
906 String index = st.nextToken();
\r
907 if (index.equals("-1"))
\r
909 while (st.hasMoreElements())
\r
911 sg.addSequence(al.findName(st.nextToken()), false);
\r
916 StringTokenizer st2 = new StringTokenizer(index, ",");
\r
918 while (st2.hasMoreTokens())
\r
920 String tmp = st2.nextToken();
\r
921 if (tmp.equals("*"))
\r
923 for (int i = 0; i < al.getHeight(); i++)
\r
925 sg.addSequence(al.getSequenceAt(i), false);
\r
928 else if (tmp.indexOf("-") >= 0)
\r
930 StringTokenizer st3 = new StringTokenizer(tmp, "-");
\r
932 int start = (Integer.parseInt(st3.nextToken()));
\r
933 int end = (Integer.parseInt(st3.nextToken()));
\r
937 for (int i = start; i <= end; i++)
\r
939 sg.addSequence(al.getSequenceAt(i - 1), false);
\r
946 .addSequence(al.getSequenceAt(Integer.parseInt(tmp) - 1),
\r
952 if (refSeq != null)
\r
954 sg.setStartRes(refSeq.findIndex(sg.getStartRes() + 1) - 1);
\r
955 sg.setEndRes(refSeq.findIndex(sg.getEndRes() + 1) - 1);
\r
956 sg.setSeqrep(refSeq);
\r
959 if (sg.getSize() > 0)
\r
965 void addRowProperties(AlignmentI al, StringTokenizer st)
\r
967 String label = st.nextToken(),keyValue,key,value;
\r
968 boolean scaletofit=false,centerlab=false,showalllabs=false;
\r
969 while (st.hasMoreTokens()) {
\r
970 keyValue=st.nextToken();
\r
971 key = keyValue.substring(0, keyValue.indexOf("="));
\r
972 value = keyValue.substring(keyValue.indexOf("=") + 1);
\r
973 if (key.equalsIgnoreCase("scaletofit")) {
\r
974 scaletofit = Boolean.valueOf(value).booleanValue();
\r
976 if (key.equalsIgnoreCase("showalllabs")) {
\r
977 showalllabs = Boolean.valueOf(value).booleanValue();
\r
979 if (key.equalsIgnoreCase("centrelabs")) {
\r
980 centerlab = Boolean.valueOf(value).booleanValue();
\r
982 AlignmentAnnotation[] alr = al.getAlignmentAnnotation();
\r
983 for (int i = 0; i < alr.length; i++)
\r
985 if (alr[i].label.equalsIgnoreCase(label))
\r
987 alr[i].centreColLabels = centerlab;
\r
988 alr[i].scaleColLabel = scaletofit;
\r
989 alr[i].showAllColLabels = showalllabs;
\r
994 void addProperties(AlignmentI al, StringTokenizer st)
\r
997 // So far we have only added groups to the annotationHash,
\r
998 // the idea is in the future properties can be added to
\r
999 // alignments, other annotations etc
\r
1000 if (al.getGroups() == null)
\r
1004 SequenceGroup sg = null;
\r
1006 String name = st.nextToken();
\r
1008 Vector groups = al.getGroups();
\r
1009 for (int i = 0; i < groups.size(); i++)
\r
1011 sg = (SequenceGroup) groups.elementAt(i);
\r
1012 if (sg.getName().equals(name))
\r
1024 String keyValue, key, value;
\r
1025 ColourSchemeI def = sg.cs;
\r
1027 while (st.hasMoreTokens())
\r
1029 keyValue = st.nextToken();
\r
1030 key = keyValue.substring(0, keyValue.indexOf("="));
\r
1031 value = keyValue.substring(keyValue.indexOf("=") + 1);
\r
1033 if (key.equalsIgnoreCase("description"))
\r
1035 sg.setDescription(value);
\r
1037 else if (key.equalsIgnoreCase("colour"))
\r
1039 sg.cs = ColourSchemeProperty.getColour(al, value);
\r
1041 else if (key.equalsIgnoreCase("pidThreshold"))
\r
1043 sg.cs.setThreshold(Integer.parseInt(value), true);
\r
1046 else if (key.equalsIgnoreCase("consThreshold"))
\r
1048 sg.cs.setConservationInc(Integer.parseInt(value));
\r
1049 Conservation c = new Conservation("Group",
\r
1050 ResidueProperties.propHash, 3, sg.getSequences(null), sg
\r
1051 .getStartRes(), sg.getEndRes() + 1);
\r
1054 c.verdict(false, 25);
\r
1056 sg.cs.setConservation(c);
\r
1059 else if (key.equalsIgnoreCase("outlineColour"))
\r
1061 sg.setOutlineColour(new UserColourScheme(value).findColour('A'));
\r
1063 else if (key.equalsIgnoreCase("displayBoxes"))
\r
1065 sg.setDisplayBoxes(Boolean.valueOf(value).booleanValue());
\r
1067 else if (key.equalsIgnoreCase("showUnconserved"))
\r
1069 sg.setShowunconserved(Boolean.valueOf(value).booleanValue());
\r
1071 else if (key.equalsIgnoreCase("displayText"))
\r
1073 sg.setDisplayText(Boolean.valueOf(value).booleanValue());
\r
1075 else if (key.equalsIgnoreCase("colourText"))
\r
1077 sg.setColourText(Boolean.valueOf(value).booleanValue());
\r
1079 else if (key.equalsIgnoreCase("textCol1"))
\r
1081 sg.textColour = new UserColourScheme(value).findColour('A');
\r
1083 else if (key.equalsIgnoreCase("textCol2"))
\r
1085 sg.textColour2 = new UserColourScheme(value).findColour('A');
\r
1087 else if (key.equalsIgnoreCase("textColThreshold"))
\r
1089 sg.thresholdTextColour = Integer.parseInt(value);
\r
1091 else if (key.equalsIgnoreCase("idColour"))
\r
1093 // consider warning if colour doesn't resolve to a real colour
\r
1094 sg.setIdColour((def = new UserColourScheme(value))
\r
1095 .findColour('A'));
\r
1097 else if (key.equalsIgnoreCase("hide"))
\r
1099 // see bug https://mantis.lifesci.dundee.ac.uk/view.php?id=25847
\r
1100 sg.setHidereps(true);
\r
1102 else if (key.equalsIgnoreCase("hidecols"))
\r
1104 // see bug https://mantis.lifesci.dundee.ac.uk/view.php?id=25847
\r
1105 sg.setHideCols(true);
\r
1107 sg.recalcConservation();
\r
1109 if (sg.cs == null)
\r
1116 void setBelowAlignment(AlignmentI al, StringTokenizer st)
\r
1119 AlignmentAnnotation aa;
\r
1120 while (st.hasMoreTokens())
\r
1122 token = st.nextToken();
\r
1123 for (int i = 0; i < al.getAlignmentAnnotation().length; i++)
\r
1125 aa = al.getAlignmentAnnotation()[i];
\r
1126 if (aa.sequenceRef == refSeq && aa.label.equals(token))
\r
1128 aa.belowAlignment = true;
\r
1134 void addAlignmentDetails(AlignmentI al, StringTokenizer st)
\r
1136 String keyValue, key, value;
\r
1137 while (st.hasMoreTokens())
\r
1139 keyValue = st.nextToken();
\r
1140 key = keyValue.substring(0, keyValue.indexOf("="));
\r
1141 value = keyValue.substring(keyValue.indexOf("=") + 1);
\r
1142 al.setProperty(key, value);
\r
1147 * Write annotations as a CSV file of the form 'label, value, value, ...' for
\r
1150 * @param annotations
\r
1151 * @return CSV file as a string.
\r
1153 public String printCSVAnnotations(AlignmentAnnotation[] annotations)
\r
1155 StringBuffer sp = new StringBuffer();
\r
1156 for (int i = 0; i < annotations.length; i++)
\r
1158 String atos = annotations[i].toString();
\r
1162 int cp = atos.indexOf("\n", p);
\r
1163 sp.append(annotations[i].label);
\r
1167 sp.append(atos.substring(p, cp + 1));
\r
1171 sp.append(atos.substring(p));
\r
1177 return sp.toString();
\r