properties + colours
[jalview.git] / src / jalview / io / AnnotationFile.java
1 /*\r
2  * Jalview - A Sequence Alignment Editor and Viewer\r
3  * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
4  *\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
9  *\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
14  *\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
18  */\r
19 \r
20 package jalview.io;\r
21 \r
22 import java.io.*;\r
23 import java.net.*;\r
24 import java.util.*;\r
25 \r
26 import jalview.analysis.*;\r
27 import jalview.datamodel.*;\r
28 import jalview.schemes.*;\r
29 \r
30 public class AnnotationFile\r
31 {\r
32   StringBuffer text = new StringBuffer(\r
33       "JALVIEW_ANNOTATION\n"\r
34       + "# Created: "\r
35       + new java.util.Date() + "\n\n");\r
36 \r
37   public String printAnnotations(AlignmentAnnotation[] annotations,\r
38                                  Vector groups,\r
39                                  Hashtable properties)\r
40   {\r
41     if (annotations != null)\r
42     {\r
43       AlignmentAnnotation row;\r
44       String comma;\r
45       SequenceI refSeq = null;\r
46 \r
47       StringBuffer colours = new StringBuffer();\r
48       StringBuffer graphLine = new StringBuffer();\r
49 \r
50       Hashtable graphGroup = new Hashtable();\r
51 \r
52       java.awt.Color color;\r
53 \r
54       for (int i = 0; i < annotations.length; i++)\r
55       {\r
56         row = annotations[i];\r
57 \r
58         if (!row.visible)\r
59         {\r
60           continue;\r
61         }\r
62 \r
63         color = null;\r
64 \r
65         if (row.sequenceRef == null)\r
66         {\r
67           if (refSeq != null)\r
68           {\r
69             text.append("\nSEQUENCE_REF\tALIGNMENT\n");\r
70           }\r
71 \r
72           refSeq = null;\r
73         }\r
74 \r
75         else if (refSeq == null || refSeq != row.sequenceRef)\r
76         {\r
77           refSeq = row.sequenceRef;\r
78           text.append("\nSEQUENCE_REF\t" + refSeq.getName() + "\n");\r
79         }\r
80 \r
81         if (row.graph == AlignmentAnnotation.NO_GRAPH)\r
82         {\r
83           text.append("NO_GRAPH\t");\r
84         }\r
85         else\r
86         {\r
87           if (row.graph == AlignmentAnnotation.BAR_GRAPH)\r
88           {\r
89             text.append("BAR_GRAPH\t");\r
90           }\r
91           else if (row.graph == AlignmentAnnotation.LINE_GRAPH)\r
92           {\r
93             text.append("LINE_GRAPH\t");\r
94           }\r
95 \r
96           if (row.getThreshold() != null)\r
97           {\r
98             graphLine.append("GRAPHLINE\t"\r
99                              + row.label + "\t"\r
100                              + row.getThreshold().value + "\t"\r
101                              + row.getThreshold().label + "\t"\r
102                              + jalview.util.Format.getHexString(\r
103                                  row.getThreshold().colour) + "\n"\r
104                 );\r
105           }\r
106 \r
107           if (row.graphGroup > -1)\r
108           {\r
109             String key = String.valueOf(row.graphGroup);\r
110             if (graphGroup.containsKey(key))\r
111             {\r
112               graphGroup.put(key, graphGroup.get(key)\r
113                              + "\t" + row.label);\r
114             }\r
115             else\r
116             {\r
117               graphGroup.put(key, row.label);\r
118             }\r
119           }\r
120         }\r
121 \r
122         text.append(row.label + "\t");\r
123         if (row.description != null)\r
124         {\r
125           text.append(row.description + "\t");\r
126         }\r
127 \r
128         for (int j = 0; j < row.annotations.length; j++)\r
129         {\r
130           if (refSeq != null &&\r
131               jalview.util.Comparison.isGap(refSeq.getCharAt(j)))\r
132           {\r
133             continue;\r
134           }\r
135 \r
136           if (row.annotations[j] != null)\r
137           {\r
138             comma = "";\r
139             if (row.annotations[j].secondaryStructure != ' ')\r
140             {\r
141               text.append(comma + row.annotations[j].secondaryStructure);\r
142               comma = ",";\r
143             }\r
144             if (row.annotations[j].displayCharacter!=null\r
145                 && row.annotations[j].displayCharacter.length() > 0\r
146                 && !row.annotations[j].displayCharacter.equals(" "))\r
147             {\r
148               text.append(comma + row.annotations[j].displayCharacter);\r
149               comma = ",";\r
150             }\r
151 \r
152             if (row.annotations[j] != null)\r
153             {\r
154               color = row.annotations[j].colour;\r
155               if (row.annotations[j].value != 0f)\r
156               {\r
157                 text.append(comma + row.annotations[j].value);\r
158               }\r
159             }\r
160 \r
161             if(row.annotations[j].colour!=null\r
162                && row.annotations[j].colour!=java.awt.Color.black)\r
163             {\r
164               text.append(comma+"["+\r
165                           jalview.util.Format.getHexString(\r
166                           row.annotations[j].colour)+"]");\r
167             }\r
168           }\r
169           text.append("|");\r
170         }\r
171 \r
172         if(!Float.isNaN(row.score))\r
173           text.append("\t"+row.score);\r
174 \r
175         text.append("\n");\r
176 \r
177         if (color != null && color != java.awt.Color.black)\r
178         {\r
179           colours.append("COLOUR\t"\r
180                          + row.label + "\t"\r
181                          + jalview.util.Format.getHexString(color) + "\n");\r
182         }\r
183 \r
184       }\r
185 \r
186       text.append("\n");\r
187 \r
188       text.append(colours.toString());\r
189       text.append(graphLine.toString());\r
190       if (graphGroup.size() > 0)\r
191       {\r
192         text.append("COMBINE\t");\r
193         Enumeration en = graphGroup.elements();\r
194         while (en.hasMoreElements())\r
195         {\r
196           text.append(en.nextElement() + "\n");\r
197         }\r
198       }\r
199     }\r
200 \r
201     if (groups != null)\r
202     {\r
203       printGroups(groups);\r
204     }\r
205 \r
206     if(properties!=null)\r
207     {\r
208       text.append("\n\nALIGNMENT");\r
209       Enumeration en = properties.keys();\r
210       while(en.hasMoreElements())\r
211       {\r
212         String key = en.nextElement().toString();\r
213         text.append("\t"+key+"="+properties.get(key));\r
214       }\r
215 \r
216     }\r
217 \r
218     return text.toString();\r
219   }\r
220 \r
221   public void printGroups(Vector sequenceGroups)\r
222   {\r
223     SequenceGroup sg;\r
224     for (int i = 0; i < sequenceGroups.size(); i++)\r
225     {\r
226       sg = (SequenceGroup) sequenceGroups.elementAt(i);\r
227       text.append("SEQUENCE_GROUP\t"\r
228                   + sg.getName() + "\t"\r
229                   + (sg.getStartRes() + 1) + "\t"\r
230                   + (sg.getEndRes() + 1) + "\t" + "-1\t");\r
231       for (int s = 0; s < sg.getSize(); s++)\r
232       {\r
233         text.append(sg.getSequenceAt(s).getName() + "\t");\r
234       }\r
235 \r
236       text.append("\nPROPERTIES\t" + sg.getName() + "\t");\r
237 \r
238       if (sg.getDescription() != null)\r
239       {\r
240         text.append("description=" + sg.getDescription() + "\t");\r
241       }\r
242       if (sg.cs != null)\r
243       {\r
244         text.append("colour=" + ColourSchemeProperty.getColourName(sg.cs) +\r
245                     "\t");\r
246         if (sg.cs.getThreshold() != 0)\r
247         {\r
248           text.append("pidThreshold=" + sg.cs.getThreshold());\r
249         }\r
250         if (sg.cs.conservationApplied())\r
251         {\r
252           text.append("consThreshold=" + sg.cs.getConservationInc() + "\t");\r
253         }\r
254       }\r
255       text.append("outlineColour=" +\r
256                   jalview.util.Format.getHexString(sg.getOutlineColour()) +\r
257                   "\t");\r
258 \r
259       text.append("displayBoxes=" + sg.getDisplayBoxes() + "\t");\r
260       text.append("displayText=" + sg.getDisplayText() + "\t");\r
261       text.append("colourText=" + sg.getColourText() + "\t");\r
262 \r
263       if (sg.textColour != java.awt.Color.black)\r
264       {\r
265         text.append("textCol1=" +\r
266                     jalview.util.Format.getHexString(sg.textColour) + "\t");\r
267       }\r
268       if (sg.textColour2 != java.awt.Color.white)\r
269       {\r
270         text.append("textCol2=" +\r
271                     jalview.util.Format.getHexString(sg.textColour2) + "\t");\r
272       }\r
273       if (sg.thresholdTextColour != 0)\r
274       {\r
275         text.append("textColThreshold=" + sg.thresholdTextColour);\r
276       }\r
277 \r
278       text.append("\n\n");\r
279 \r
280     }\r
281   }\r
282 \r
283   SequenceI refSeq = null;\r
284   public boolean readAnnotationFile(AlignmentI al,\r
285                                     String file,\r
286                                     String protocol)\r
287   {\r
288     try\r
289     {\r
290       BufferedReader in = null;\r
291       if (protocol.equals(AppletFormatAdapter.FILE))\r
292       {\r
293         in = new BufferedReader(new FileReader(file));\r
294       }\r
295       else if (protocol.equals(AppletFormatAdapter.URL))\r
296       {\r
297         URL url = new URL(file);\r
298         in = new BufferedReader(new InputStreamReader(url.openStream()));\r
299       }\r
300       else if (protocol.equals(AppletFormatAdapter.PASTE))\r
301       {\r
302         in = new BufferedReader(new StringReader(file));\r
303       }\r
304       else if (protocol.equals(AppletFormatAdapter.CLASSLOADER))\r
305       {\r
306         java.io.InputStream is = getClass().getResourceAsStream("/" + file);\r
307         if (is != null)\r
308         {\r
309           in = new BufferedReader(new java.io.InputStreamReader(is));\r
310         }\r
311       }\r
312 \r
313       String line, label, description, token;\r
314       int graphStyle, index;\r
315       int refSeqIndex = 1;\r
316       int existingAnnotations = 0;\r
317       if (al.getAlignmentAnnotation() != null)\r
318       {\r
319         existingAnnotations = al.getAlignmentAnnotation().length;\r
320       }\r
321 \r
322       int alWidth = al.getWidth();\r
323 \r
324       StringTokenizer st;\r
325       Annotation[] annotations;\r
326       AlignmentAnnotation annotation = null;\r
327 \r
328       // First confirm this is an Annotation file\r
329       boolean jvAnnotationFile = false;\r
330       while ( (line = in.readLine()) != null)\r
331       {\r
332         if (line.indexOf("#") == 0)\r
333         {\r
334           continue;\r
335         }\r
336 \r
337         if (line.indexOf("JALVIEW_ANNOTATION") > -1)\r
338         {\r
339           jvAnnotationFile = true;\r
340           break;\r
341         }\r
342       }\r
343 \r
344       if (!jvAnnotationFile)\r
345       {\r
346         in.close();\r
347         return false;\r
348       }\r
349 \r
350       while ( (line = in.readLine()) != null)\r
351       {\r
352         if (line.indexOf("#") == 0\r
353             || line.indexOf("JALVIEW_ANNOTATION") > -1\r
354             || line.length() == 0)\r
355         {\r
356           continue;\r
357         }\r
358 \r
359         st = new StringTokenizer(line, "\t");\r
360         token = st.nextToken();\r
361         if (token.equalsIgnoreCase("COLOUR"))\r
362         {\r
363           colourAnnotations(al, st.nextToken(), st.nextToken());\r
364           continue;\r
365         }\r
366 \r
367         else if (token.equalsIgnoreCase("COMBINE"))\r
368         {\r
369           combineAnnotations(al, st);\r
370           continue;\r
371         }\r
372 \r
373         else if (token.equalsIgnoreCase("GRAPHLINE"))\r
374         {\r
375           addLine(al, st);\r
376           continue;\r
377         }\r
378 \r
379         else if (token.equalsIgnoreCase("SEQUENCE_REF"))\r
380         {\r
381           refSeq = al.findName(st.nextToken());\r
382           try\r
383           {\r
384             refSeqIndex = Integer.parseInt(st.nextToken());\r
385             if (refSeqIndex < 1)\r
386             {\r
387               refSeqIndex = 1;\r
388               System.out.println(\r
389                   "WARNING: SEQUENCE_REF index must be > 0 in AnnotationFile");\r
390             }\r
391           }\r
392           catch (Exception ex)\r
393           {\r
394             refSeqIndex = 1;\r
395           }\r
396 \r
397           continue ;\r
398         }\r
399 \r
400         else if (token.equalsIgnoreCase("SEQUENCE_GROUP"))\r
401         {\r
402           addGroup(al, st);\r
403           continue;\r
404         }\r
405 \r
406         else if (token.equalsIgnoreCase("PROPERTIES"))\r
407         {\r
408           addProperties(al, st);\r
409           continue;\r
410         }\r
411 \r
412         else if( token.equalsIgnoreCase("BELOW_ALIGNMENT"))\r
413         {\r
414           setBelowAlignment(al, st);\r
415           continue;\r
416         }\r
417         else if( token.equalsIgnoreCase("ALIGNMENT"))\r
418         {\r
419           addAlignmentDetails(al, st);\r
420           continue;\r
421         }\r
422 \r
423         graphStyle = AlignmentAnnotation.getGraphValueFromString(token);\r
424         label = st.nextToken();\r
425 \r
426 \r
427         index = 0;\r
428         annotations = new Annotation[alWidth];\r
429         description = null;\r
430         float score = Float.NaN;\r
431 \r
432         if(st.hasMoreTokens())\r
433         {\r
434           line = st.nextToken();\r
435 \r
436           if (line.indexOf("|") ==-1)\r
437           {\r
438             description = line;\r
439             if (st.hasMoreTokens())\r
440               line = st.nextToken();\r
441           }\r
442 \r
443           if(st.hasMoreTokens())\r
444           {\r
445             //This must be the score\r
446             score = Float.valueOf(st.nextToken()).floatValue();\r
447           }\r
448 \r
449           st = new StringTokenizer(line, "|", true);\r
450 \r
451 \r
452           boolean emptyColumn = true;\r
453           boolean onlyOneElement = (st.countTokens()==1);\r
454 \r
455           while (st.hasMoreElements() && index < alWidth)\r
456           {\r
457             token = st.nextToken().trim();\r
458 \r
459             if(onlyOneElement)\r
460             {\r
461               try\r
462               {\r
463                 score = Float.valueOf(token).floatValue();\r
464                 break;\r
465               }\r
466               catch(NumberFormatException ex){}\r
467             }\r
468 \r
469             if (token.equals("|"))\r
470             {\r
471               if (emptyColumn)\r
472               {\r
473                 index++;\r
474               }\r
475 \r
476               emptyColumn = true;\r
477             }\r
478             else\r
479             {\r
480               annotations[index++] = parseAnnotation(token);\r
481               emptyColumn = false;\r
482             }\r
483           }\r
484 \r
485         }\r
486 \r
487         annotation = new AlignmentAnnotation(label,\r
488                                              description,\r
489                                              annotations,\r
490                                              0,\r
491                                              0,\r
492                                              graphStyle);\r
493 \r
494         annotation.score = score;\r
495 \r
496         if (refSeq != null)\r
497         {\r
498           annotation.belowAlignment=false;\r
499           annotation.createSequenceMapping(refSeq, refSeqIndex, false);\r
500           annotation.adjustForAlignment();\r
501           refSeq.addAlignmentAnnotation(annotation);\r
502         }\r
503 \r
504         al.addAnnotation(annotation);\r
505 \r
506         al.setAnnotationIndex(annotation,\r
507                               al.getAlignmentAnnotation().length - existingAnnotations -\r
508                               1);\r
509       }\r
510 \r
511     }\r
512     catch (Exception ex)\r
513     {\r
514       ex.printStackTrace();\r
515       System.out.println("Problem reading annotation file: " + ex);\r
516       return false;\r
517     }\r
518     return true;\r
519   }\r
520 \r
521   Annotation parseAnnotation(String string)\r
522   {\r
523     String desc = null, displayChar = null;\r
524     char ss = ' '; // secondaryStructure\r
525     float value = 0;\r
526     boolean parsedValue = false;\r
527 \r
528     //find colour here\r
529     java.awt.Color colour = null;\r
530     int i=string.indexOf("[");\r
531     int j=string.indexOf("]");\r
532     if(i>-1 && j>-1)\r
533     {\r
534       UserColourScheme ucs = new UserColourScheme();\r
535 \r
536       colour = ucs.getColourFromString(string.substring(i+1,j));\r
537 \r
538       string = string.substring(0,i)+string.substring(j+1);\r
539     }\r
540 \r
541     StringTokenizer st = new StringTokenizer(string, ",");\r
542     String token;\r
543     while (st.hasMoreTokens())\r
544     {\r
545       token = st.nextToken().trim();\r
546       if (token.length() == 0)\r
547       {\r
548         continue;\r
549       }\r
550 \r
551       if (!parsedValue)\r
552       {\r
553         try\r
554         {\r
555           displayChar = token;\r
556           value = new Float(token).floatValue();\r
557           parsedValue = true;\r
558           continue;\r
559         }\r
560         catch (NumberFormatException ex)\r
561         {}\r
562       }\r
563 \r
564       if (token.equals("H") || token.equals("E"))\r
565       {\r
566         // Either this character represents a helix or sheet\r
567         // or an integer which can be displayed\r
568         ss = token.charAt(0);\r
569         if (displayChar.equals(token.substring(0, 1)))\r
570         {\r
571           displayChar = "";\r
572         }\r
573       }\r
574       else if (desc == null)\r
575       {\r
576         desc = token;\r
577       }\r
578 \r
579     }\r
580 \r
581     if (displayChar.length() > 1\r
582         &&  desc!=null\r
583         && desc.length() == 1)\r
584     {\r
585       String tmp = displayChar;\r
586       displayChar = desc;\r
587       desc = tmp;\r
588     }\r
589 \r
590     Annotation anot = new Annotation(displayChar, desc, ss, value);\r
591 \r
592     anot.colour = colour;\r
593 \r
594     return anot;\r
595   }\r
596 \r
597   void colourAnnotations(AlignmentI al, String label, String colour)\r
598   {\r
599     UserColourScheme ucs = new UserColourScheme(colour);\r
600     Annotation[] annotations;\r
601     for (int i = 0; i < al.getAlignmentAnnotation().length; i++)\r
602     {\r
603       if (al.getAlignmentAnnotation()[i].label.equalsIgnoreCase(label))\r
604       {\r
605         annotations = al.getAlignmentAnnotation()[i].annotations;\r
606         for (int j = 0; j < annotations.length; j++)\r
607         {\r
608           if (annotations[j] != null)\r
609           {\r
610             annotations[j].colour = ucs.findColour('A');\r
611           }\r
612         }\r
613       }\r
614     }\r
615   }\r
616 \r
617   void combineAnnotations(AlignmentI al, StringTokenizer st)\r
618   {\r
619     int graphGroup = -1;\r
620     String group = st.nextToken();\r
621     //First make sure we are not overwriting the graphIndex\r
622     for (int i = 0; i < al.getAlignmentAnnotation().length; i++)\r
623     {\r
624       if (al.getAlignmentAnnotation()[i].label.equalsIgnoreCase(group))\r
625       {\r
626         graphGroup = al.getAlignmentAnnotation()[i].graphGroup + 1;\r
627         al.getAlignmentAnnotation()[i].graphGroup = graphGroup;\r
628         break;\r
629       }\r
630     }\r
631 \r
632     //Now update groups\r
633     while (st.hasMoreTokens())\r
634     {\r
635       group = st.nextToken();\r
636       for (int i = 0; i < al.getAlignmentAnnotation().length; i++)\r
637       {\r
638         if (al.getAlignmentAnnotation()[i].label.equalsIgnoreCase(group))\r
639         {\r
640           al.getAlignmentAnnotation()[i].graphGroup = graphGroup;\r
641           break;\r
642         }\r
643       }\r
644     }\r
645   }\r
646 \r
647   void addLine(AlignmentI al, StringTokenizer st)\r
648   {\r
649     String group = st.nextToken();\r
650     AlignmentAnnotation annotation = null;\r
651 \r
652     for (int i = 0; i < al.getAlignmentAnnotation().length; i++)\r
653     {\r
654       if (al.getAlignmentAnnotation()[i].label.equalsIgnoreCase(group))\r
655       {\r
656         annotation = al.getAlignmentAnnotation()[i];\r
657         break;\r
658       }\r
659     }\r
660 \r
661     if (annotation == null)\r
662     {\r
663       return;\r
664     }\r
665     float value = new Float(st.nextToken()).floatValue();\r
666     String label = st.hasMoreTokens() ? st.nextToken() : null;\r
667     java.awt.Color colour = null;\r
668     if (st.hasMoreTokens())\r
669     {\r
670       UserColourScheme ucs = new UserColourScheme(st.nextToken());\r
671       colour = ucs.findColour('A');\r
672     }\r
673 \r
674     annotation.setThreshold(new GraphLine(value, label, colour));\r
675   }\r
676 \r
677   void addGroup(AlignmentI al, StringTokenizer st)\r
678   {\r
679     SequenceGroup sg = new SequenceGroup();\r
680     sg.setName(st.nextToken());\r
681     sg.setStartRes(Integer.parseInt(st.nextToken()) - 1);\r
682     sg.setEndRes(Integer.parseInt(st.nextToken()) - 1);\r
683 \r
684     String index = st.nextToken();\r
685     if (index.equals("-1"))\r
686     {\r
687       while (st.hasMoreElements())\r
688       {\r
689         sg.addSequence(al.findName(st.nextToken()), false);\r
690       }\r
691     }\r
692     else\r
693     {\r
694       StringTokenizer st2 = new StringTokenizer(index, ",");\r
695 \r
696       while (st2.hasMoreTokens())\r
697       {\r
698         String tmp = st2.nextToken();\r
699         if (tmp.equals("*"))\r
700         {\r
701           for (int i = 0; i < al.getHeight(); i++)\r
702           {\r
703             sg.addSequence(al.getSequenceAt(i), false);\r
704           }\r
705         }\r
706         else if (tmp.indexOf("-") >= 0)\r
707         {\r
708           StringTokenizer st3 = new StringTokenizer(tmp, "-");\r
709 \r
710           int start = (Integer.parseInt(st3.nextToken()));\r
711           int end = (Integer.parseInt(st3.nextToken()));\r
712 \r
713           if (end > start)\r
714           {\r
715             for (int i = start; i <= end; i++)\r
716             {\r
717               sg.addSequence(al.getSequenceAt(i - 1), false);\r
718             }\r
719           }\r
720         }\r
721         else\r
722         {\r
723           sg.addSequence(al.getSequenceAt(Integer.parseInt(tmp) - 1), false);\r
724         }\r
725       }\r
726     }\r
727 \r
728 \r
729 \r
730     if (refSeq != null)\r
731     {\r
732       sg.setStartRes(refSeq.findIndex(sg.getStartRes() + 1) - 1);\r
733       sg.setEndRes(refSeq.findIndex(sg.getEndRes() + 1) - 1);\r
734     }\r
735 \r
736     if (sg.getSize() > 0)\r
737     {\r
738       al.addGroup(sg);\r
739     }\r
740   }\r
741 \r
742   void addProperties(AlignmentI al, StringTokenizer st)\r
743   {\r
744 \r
745     //So far we have only added groups to the annotationHash,\r
746     //the idea is in the future properties can be added to\r
747     //alignments, other annotations etc\r
748     if (al.getGroups() == null)\r
749     {\r
750       return;\r
751     }\r
752     SequenceGroup sg = null;\r
753 \r
754     String name = st.nextToken();\r
755 \r
756     Vector groups = al.getGroups();\r
757     for (int i = 0; i < groups.size(); i++)\r
758     {\r
759       sg = (SequenceGroup) groups.elementAt(i);\r
760       if (sg.getName().equals(name))\r
761       {\r
762         break;\r
763       }\r
764       else\r
765       {\r
766         sg = null;\r
767       }\r
768     }\r
769 \r
770     if (sg != null)\r
771     {\r
772       String keyValue, key, value;\r
773       while (st.hasMoreTokens())\r
774       {\r
775         keyValue = st.nextToken();\r
776         key = keyValue.substring(0, keyValue.indexOf("="));\r
777         value = keyValue.substring(keyValue.indexOf("=") + 1);\r
778 \r
779         if (key.equalsIgnoreCase("description"))\r
780         {\r
781           sg.setDescription(value);\r
782         }\r
783         else if (key.equalsIgnoreCase("colour"))\r
784         {\r
785           sg.cs = ColourSchemeProperty.getColour(al, value);\r
786         }\r
787         else if (key.equalsIgnoreCase("pidThreshold"))\r
788         {\r
789           sg.cs.setThreshold(Integer.parseInt(value), true);\r
790 \r
791         }\r
792         else if (key.equalsIgnoreCase("consThreshold"))\r
793         {\r
794           sg.cs.setConservationInc(Integer.parseInt(value));\r
795           Conservation c = new Conservation("Group",\r
796                                             ResidueProperties.propHash, 3,\r
797                                             sg.getSequences(null),\r
798                                             sg.getStartRes(),\r
799                                             sg.getEndRes() + 1);\r
800 \r
801           c.calculate();\r
802           c.verdict(false, 25);\r
803 \r
804           sg.cs.setConservation(c);\r
805 \r
806         }\r
807         else if (key.equalsIgnoreCase("outlineColour"))\r
808         {\r
809           sg.setOutlineColour(new UserColourScheme(value).findColour('A'));\r
810         }\r
811         else if (key.equalsIgnoreCase("displayBoxes"))\r
812         {\r
813           sg.setDisplayBoxes(Boolean.valueOf(value).booleanValue());\r
814         }\r
815         else if (key.equalsIgnoreCase("displayText"))\r
816         {\r
817           sg.setDisplayText(Boolean.valueOf(value).booleanValue());\r
818         }\r
819         else if (key.equalsIgnoreCase("colourText"))\r
820         {\r
821           sg.setColourText(Boolean.valueOf(value).booleanValue());\r
822         }\r
823         else if (key.equalsIgnoreCase("textCol1"))\r
824         {\r
825           sg.textColour = new UserColourScheme(value).findColour('A');\r
826         }\r
827         else if (key.equalsIgnoreCase("textCol2"))\r
828         {\r
829           sg.textColour2 = new UserColourScheme(value).findColour('A');\r
830         }\r
831         else if (key.equalsIgnoreCase("textColThreshold"))\r
832         {\r
833           sg.thresholdTextColour = Integer.parseInt(value);\r
834         }\r
835 \r
836         sg.recalcConservation();\r
837       }\r
838     }\r
839   }\r
840 \r
841   void setBelowAlignment(AlignmentI al, StringTokenizer st)\r
842   {\r
843     String token;\r
844     AlignmentAnnotation aa;\r
845     while(st.hasMoreTokens())\r
846     {\r
847       token = st.nextToken();\r
848       for(int i=0; i<al.getAlignmentAnnotation().length; i++)\r
849       {\r
850         aa = al.getAlignmentAnnotation()[i];\r
851         if(aa.sequenceRef==refSeq && aa.label.equals(token))\r
852         {\r
853           aa.belowAlignment = true;\r
854         }\r
855       }\r
856     }\r
857   }\r
858 \r
859   void addAlignmentDetails(AlignmentI al, StringTokenizer st)\r
860   {\r
861     String keyValue, key, value;\r
862     while (st.hasMoreTokens())\r
863     {\r
864       keyValue = st.nextToken();\r
865       key = keyValue.substring(0, keyValue.indexOf("="));\r
866       value = keyValue.substring(keyValue.indexOf("=") + 1);\r
867       al.setProperty(key,value);\r
868     }\r
869   }\r
870 }\r