added help and documentation for annotation editing.
[jalview.git] / src / jalview / gui / Jalview2XML.java
1 /*\r
2  * Jalview - A Sequence Alignment Editor and Viewer\r
3  * Copyright (C) 2005 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 package jalview.gui;\r
20 \r
21 import jalview.binding.*;\r
22 \r
23 import jalview.io.*;\r
24 \r
25 import jalview.schemes.*;\r
26 \r
27 import java.io.*;\r
28 \r
29 import java.net.*;\r
30 \r
31 import java.util.*;\r
32 import java.util.jar.*;\r
33 \r
34 import javax.swing.*;\r
35 \r
36 \r
37 /**\r
38  * DOCUMENT ME!\r
39  *\r
40  * @author $author$\r
41  * @version $Revision$\r
42  */\r
43 public class Jalview2XML\r
44 {\r
45     // SAVES SEVERAL ALIGNEMENT WINDOWS TO SAME JARFILE\r
46     public static void SaveState(File statefile)\r
47     {\r
48         long creation = System.currentTimeMillis();\r
49         JInternalFrame[] frames = Desktop.desktop.getAllFrames();\r
50 \r
51         if (frames == null)\r
52         {\r
53             return;\r
54         }\r
55 \r
56         try\r
57         {\r
58             FileOutputStream fos = new FileOutputStream(statefile);\r
59             JarOutputStream jout = new JarOutputStream(fos);\r
60 \r
61             //NOTE UTF-8 MUST BE USED FOR WRITING UNICODE CHARS\r
62             ////////////////////////////////////////////////////\r
63             PrintWriter out = new PrintWriter(new OutputStreamWriter(jout,\r
64                         "UTF-8"));\r
65 \r
66             Vector shortNames = new Vector();\r
67 \r
68             //REVERSE ORDER\r
69             for (int i = frames.length - 1; i > -1; i--)\r
70             {\r
71                 if (frames[i] instanceof AlignFrame)\r
72                 {\r
73                     AlignFrame af = (AlignFrame) frames[i];\r
74 \r
75                     String shortName = af.getTitle();\r
76 \r
77                     if (shortName.indexOf(File.separatorChar) > -1)\r
78                     {\r
79                         shortName = shortName.substring(shortName.lastIndexOf(\r
80                                     File.separatorChar) + 1);\r
81                     }\r
82 \r
83                     int count = 1;\r
84 \r
85                     while (shortNames.contains(shortName))\r
86                     {\r
87                         if (shortName.endsWith("_" + (count - 1)))\r
88                         {\r
89                             shortName = shortName.substring(0,\r
90                                     shortName.lastIndexOf("_"));\r
91                         }\r
92 \r
93                         shortName = shortName.concat("_" + count);\r
94                         count++;\r
95                     }\r
96 \r
97                     shortNames.addElement(shortName);\r
98 \r
99                     if (!shortName.endsWith(".xml"))\r
100                     {\r
101                         shortName = shortName + ".xml";\r
102                     }\r
103 \r
104                     SaveState(af, creation, shortName, jout, out);\r
105                 }\r
106             }\r
107 \r
108             out.close();\r
109             jout.close();\r
110         }\r
111         catch (Exception ex)\r
112         {\r
113             ex.printStackTrace();\r
114         }\r
115     }\r
116 \r
117     // USE THIS METHOD TO SAVE A SINGLE ALIGNMENT WINDOW\r
118     public static void SaveAlignment(AlignFrame af, String jarFile,\r
119         String fileName)\r
120     {\r
121         try\r
122         {\r
123             FileOutputStream fos = new FileOutputStream(jarFile);\r
124             JarOutputStream jout = new JarOutputStream(fos);\r
125 \r
126             //NOTE UTF-8 MUST BE USED FOR WRITING UNICODE CHARS\r
127             ////////////////////////////////////////////////////\r
128             PrintWriter out = new PrintWriter(new OutputStreamWriter(jout,\r
129                         "UTF-8"));\r
130 \r
131             SaveState(af, System.currentTimeMillis(), fileName, jout, out);\r
132             out.close();\r
133             jout.close();\r
134         }\r
135         catch (Exception ex)\r
136         {\r
137         }\r
138     }\r
139 \r
140     /**\r
141      * DOCUMENT ME!\r
142      *\r
143      * @param af DOCUMENT ME!\r
144      * @param timeStamp DOCUMENT ME!\r
145      * @param fileName DOCUMENT ME!\r
146      * @param jout DOCUMENT ME!\r
147      * @param out DOCUMENT ME!\r
148      */\r
149     public static void SaveState(AlignFrame af, long timeStamp,\r
150         String fileName, JarOutputStream jout, PrintWriter out)\r
151     {\r
152         Vector seqids = new Vector();\r
153         Vector userColours = new Vector();\r
154 \r
155         AlignViewport av = af.viewport;\r
156 \r
157         JalviewModel object = new JalviewModel();\r
158         object.setVamsasModel(new VamsasModel());\r
159 \r
160         object.setCreationDate(new java.util.Date(timeStamp));\r
161         object.setVersion(jalview.bin.Cache.getProperty("VERSION"));\r
162 \r
163         jalview.datamodel.AlignmentI jal = af.viewport.alignment;\r
164 \r
165         SequenceSet vamsasSet = new SequenceSet();\r
166         Sequence vamsasSeq;\r
167         JalviewModelSequence jms = new JalviewModelSequence();\r
168 \r
169         vamsasSet.setGapChar(jal.getGapCharacter() + "");\r
170 \r
171         JSeq jseq;\r
172 \r
173         //SAVE SEQUENCES\r
174         int id = 0;\r
175 \r
176         for (int i = 0; i < jal.getHeight(); i++)\r
177         {\r
178             seqids.add(jal.getSequenceAt(i));\r
179 \r
180             vamsasSeq = new Sequence();\r
181             vamsasSeq.setId(id + "");\r
182             vamsasSeq.setName(jal.getSequenceAt(i).getName());\r
183             vamsasSeq.setSequence(jal.getSequenceAt(i).getSequence());\r
184 \r
185             jseq = new JSeq();\r
186             jseq.setStart(jal.getSequenceAt(i).getStart());\r
187             jseq.setEnd(jal.getSequenceAt(i).getEnd());\r
188 \r
189             jseq.setColour(jal.getSequenceAt(i).getColor().getRGB());\r
190 \r
191             jseq.setId(id);\r
192 \r
193             jms.addJSeq(jseq);\r
194             vamsasSet.addSequence(vamsasSeq);\r
195             id++;\r
196         }\r
197 \r
198         //SAVE TREES\r
199         ///////////////////////////////////\r
200         if (af.viewport.currentTree != null)\r
201         {\r
202             // FIND ANY ASSOCIATED TREES\r
203             JInternalFrame[] frames = Desktop.desktop.getAllFrames();\r
204 \r
205             for (int t = 0; t < frames.length; t++)\r
206             {\r
207                 if (frames[t] instanceof TreePanel)\r
208                 {\r
209                     TreePanel tp = (TreePanel) frames[t];\r
210 \r
211                     if (tp.treeCanvas.av.alignment == jal)\r
212                     {\r
213                         Tree tree = new Tree();\r
214                         tree.setTitle(tp.getTitle());\r
215                         tree.setCurrentTree((af.viewport.currentTree == tp.getTree()));\r
216                         tree.setNewick(tp.getTree().toString());\r
217                         tree.setThreshold(tp.treeCanvas.threshold);\r
218 \r
219                         tree.setFitToWindow(tp.fitToWindow.getState());\r
220                         tree.setFontSize(tp.treeCanvas.fontSize);\r
221                         tree.setMarkUnlinked(tp.placeholdersMenu.getState());\r
222                         tree.setShowBootstrap(tp.bootstrapMenu.getState());\r
223                         tree.setShowDistances(tp.distanceMenu.getState());\r
224 \r
225                         tree.setHeight(tp.getHeight());\r
226                         tree.setWidth(tp.getWidth());\r
227                         tree.setXpos(tp.getX());\r
228                         tree.setYpos(tp.getY());\r
229 \r
230                         jms.addTree(tree);\r
231                     }\r
232                 }\r
233             }\r
234         }\r
235 \r
236         //SAVE ANNOTATIONS\r
237         if (jal.getAlignmentAnnotation() != null)\r
238         {\r
239             jalview.datamodel.AlignmentAnnotation[] aa = jal.getAlignmentAnnotation();\r
240 \r
241             for (int i = 0; i < aa.length; i++)\r
242             {\r
243                 if (aa[i].label.equals("Quality") ||\r
244                         aa[i].label.equals("Conservation") ||\r
245                         aa[i].label.equals("Consensus"))\r
246                 {\r
247                     continue;\r
248                 }\r
249 \r
250                 Annotation an = new Annotation();\r
251                 an.setDescription(aa[i].description);\r
252                 an.setGraph(aa[i].isGraph);\r
253                 an.setLabel(aa[i].label);\r
254 \r
255                 AnnotationElement ae;\r
256 \r
257                 for (int a = 0; a < aa[i].annotations.length; a++)\r
258                 {\r
259                     if ((aa[i] == null) || (aa[i].annotations[a] == null))\r
260                     {\r
261                         continue;\r
262                     }\r
263 \r
264                     ae = new AnnotationElement();\r
265                     ae.setDescription(aa[i].annotations[a].description);\r
266                     ae.setDisplayCharacter(aa[i].annotations[a].displayCharacter);\r
267                     ae.setValue(aa[i].annotations[a].value);\r
268                     ae.setPosition(a);\r
269                     ae.setSecondaryStructure(aa[i].annotations[a].secondaryStructure +\r
270                         "");\r
271                     an.addAnnotationElement(ae);\r
272                 }\r
273 \r
274                 vamsasSet.addAnnotation(an);\r
275             }\r
276         }\r
277 \r
278         //SAVE GROUPS\r
279         if (jal.getGroups() != null)\r
280         {\r
281             JGroup[] groups = new JGroup[jal.getGroups().size()];\r
282 \r
283             for (int i = 0; i < groups.length; i++)\r
284             {\r
285                 groups[i] = new JGroup();\r
286 \r
287                 jalview.datamodel.SequenceGroup sg = (jalview.datamodel.SequenceGroup) jal.getGroups()\r
288                                                                                           .elementAt(i);\r
289                 groups[i].setStart(sg.getStartRes());\r
290                 groups[i].setEnd(sg.getEndRes());\r
291                 groups[i].setName(sg.getName());\r
292 \r
293                 if (sg.cs instanceof ConservationColourScheme)\r
294                 {\r
295                     groups[i].setConsThreshold(((ConservationColourScheme) sg.cs).inc);\r
296                 }\r
297 \r
298                 if (sg.cs instanceof ResidueColourScheme)\r
299                 {\r
300                     groups[i].setPidThreshold(((ResidueColourScheme) sg.cs).getThreshold());\r
301                 }\r
302                 else if (sg.cs instanceof ScoreColourScheme)\r
303                 {\r
304                     groups[i].setPidThreshold(((ScoreColourScheme) sg.cs).getThreshold());\r
305                 }\r
306 \r
307                 if (sg.cs instanceof jalview.schemes.UserColourScheme)\r
308                 {\r
309                     groups[i].setColour(SetUserColourScheme(sg.cs, userColours,\r
310                             jms));\r
311                 }\r
312                 else\r
313                 {\r
314                     groups[i].setColour(ColourSchemeProperty.getColourName(\r
315                             sg.cs));\r
316                 }\r
317 \r
318                 groups[i].setOutlineColour(sg.getOutlineColour().getRGB());\r
319                 groups[i].setDisplayBoxes(sg.getDisplayBoxes());\r
320                 groups[i].setDisplayText(sg.getDisplayText());\r
321                 groups[i].setColourText(sg.getColourText());\r
322 \r
323                 for (int s = 0; s < sg.getSize(); s++)\r
324                 {\r
325                     jalview.datamodel.Sequence seq = (jalview.datamodel.Sequence) sg.getSequenceAt(s);\r
326                     int index = seqids.indexOf(seq);\r
327                     groups[i].addSeq(index);\r
328                 }\r
329             }\r
330 \r
331             jms.setJGroup(groups);\r
332         }\r
333 \r
334         ///////////SAVE VIEWPORT\r
335         Viewport view = new Viewport();\r
336         view.setTitle(af.getTitle());\r
337         view.setXpos(af.getX());\r
338         view.setYpos(af.getY());\r
339         view.setWidth(af.getWidth());\r
340         view.setHeight(af.getHeight());\r
341         view.setStartRes(av.startRes);\r
342         view.setStartSeq(av.startSeq);\r
343 \r
344         if (av.getGlobalColourScheme() instanceof jalview.schemes.UserColourScheme)\r
345         {\r
346             view.setBgColour(SetUserColourScheme(av.getGlobalColourScheme(),\r
347                     userColours, jms));\r
348         }\r
349         else\r
350         {\r
351             view.setBgColour(ColourSchemeProperty.getColourName(\r
352                     av.getGlobalColourScheme()));\r
353         }\r
354 \r
355         ColourSchemeI cs = av.getGlobalColourScheme();\r
356 \r
357         if (cs instanceof ConservationColourScheme)\r
358         {\r
359             view.setConsThreshold(((ConservationColourScheme) cs).inc);\r
360         }\r
361 \r
362         if (cs instanceof ResidueColourScheme)\r
363         {\r
364             view.setPidThreshold(((ResidueColourScheme) cs).getThreshold());\r
365         }\r
366         else if (cs instanceof ScoreColourScheme)\r
367         {\r
368             view.setPidThreshold(((ScoreColourScheme) cs).getThreshold());\r
369         }\r
370 \r
371         view.setConservationSelected(av.getConservationSelected());\r
372         view.setPidSelected(av.getAbovePIDThreshold());\r
373         view.setFontName(av.font.getFontName());\r
374         view.setFontSize(av.font.getSize());\r
375         view.setFontStyle(av.font.getStyle());\r
376         view.setRenderGaps(av.renderGaps);\r
377         view.setShowAnnotation(av.getShowAnnotation());\r
378         view.setShowBoxes(av.getShowBoxes());\r
379         view.setShowColourText(av.getColourText());\r
380         view.setShowConservation(av.showConservation);\r
381         view.setShowFullId(av.getShowFullId());\r
382         view.setShowIdentity(av.showIdentity);\r
383         view.setShowQuality(av.showQuality);\r
384         view.setShowSequenceFeatures(av.showSequenceFeatures);\r
385         view.setShowText(av.getShowText());\r
386         view.setWrapAlignment(av.getWrapAlignment());\r
387 \r
388         jms.addViewport(view);\r
389 \r
390         object.setJalviewModelSequence(jms);\r
391         object.getVamsasModel().addSequenceSet(vamsasSet);\r
392 \r
393         try\r
394         {\r
395             if (!fileName.endsWith(".xml"))\r
396             {\r
397                 fileName = fileName + ".xml";\r
398             }\r
399 \r
400             JarEntry entry = new JarEntry(fileName);\r
401             jout.putNextEntry(entry);\r
402 \r
403             object.marshal(out);\r
404         }\r
405         catch (Exception ex)\r
406         {\r
407             ex.printStackTrace();\r
408         }\r
409     }\r
410 \r
411     static String SetUserColourScheme(jalview.schemes.ColourSchemeI cs,\r
412         Vector userColours, JalviewModelSequence jms)\r
413     {\r
414         String id = null;\r
415         jalview.schemes.UserColourScheme ucs = (jalview.schemes.UserColourScheme) cs;\r
416 \r
417         if (!userColours.contains(ucs))\r
418         {\r
419             userColours.add(ucs);\r
420 \r
421             java.awt.Color[] colours = ucs.getColours();\r
422             jalview.binding.UserColours uc = new jalview.binding.UserColours();\r
423             jalview.binding.UserColourScheme jbucs = new jalview.binding.UserColourScheme();\r
424 \r
425             for (int i = 0; i < colours.length; i++)\r
426             {\r
427                 jalview.binding.Colour col = new jalview.binding.Colour();\r
428                 col.setRGB(jalview.util.Format.getHexString(colours[i]));\r
429                 jbucs.addColour(col);\r
430             }\r
431 \r
432             id = "ucs" + userColours.indexOf(ucs);\r
433             uc.setId(id);\r
434             uc.setUserColourScheme(jbucs);\r
435             jms.addUserColours(uc);\r
436         }\r
437 \r
438         return id;\r
439     }\r
440 \r
441     static jalview.schemes.UserColourScheme GetUserColourScheme(\r
442         JalviewModelSequence jms, String id)\r
443     {\r
444         UserColours[] uc = jms.getUserColours();\r
445         UserColours colours = null;\r
446 \r
447         for (int i = 0; i < uc.length; i++)\r
448         {\r
449             if (uc[i].getId().equals(id))\r
450             {\r
451                 colours = uc[i];\r
452 \r
453                 break;\r
454             }\r
455         }\r
456 \r
457         int csize = colours.getUserColourScheme().getColourCount();\r
458         java.awt.Color[] newColours = new java.awt.Color[csize];\r
459 \r
460         for (int i = 0; i < csize; i++)\r
461         {\r
462             newColours[i] = new java.awt.Color(Integer.parseInt(\r
463                         colours.getUserColourScheme().getColour(i).getRGB(), 16));\r
464         }\r
465 \r
466         return new jalview.schemes.UserColourScheme(newColours);\r
467     }\r
468 \r
469     /**\r
470      * DOCUMENT ME!\r
471      *\r
472      * @param file DOCUMENT ME!\r
473      */\r
474     public static AlignFrame LoadJalviewAlign(String file)\r
475     {\r
476         JalviewModel object = new JalviewModel();\r
477         jalview.gui.AlignFrame af = null;\r
478 \r
479         try\r
480         {\r
481             //UNMARSHALLER SEEMS TO CLOSE JARINPUTSTREAM, MOST ANNOYING\r
482             URL url = null;\r
483 \r
484             if (file.startsWith("http://"))\r
485             {\r
486                 url = new URL(file);\r
487             }\r
488 \r
489             JarInputStream jin = null;\r
490             JarEntry jarentry = null;\r
491             int entryCount = 1;\r
492 \r
493             do\r
494             {\r
495                 if (url != null)\r
496                 {\r
497                     jin = new JarInputStream(url.openStream());\r
498                 }\r
499                 else\r
500                 {\r
501                     jin = new JarInputStream(new FileInputStream(file));\r
502                 }\r
503 \r
504                 for (int i = 0; i < entryCount; i++)\r
505                 {\r
506                     jarentry = jin.getNextJarEntry();\r
507                 }\r
508 \r
509                 if (jarentry != null)\r
510                 {\r
511                     InputStreamReader in = new InputStreamReader(jin, "UTF-8");\r
512                     object = (JalviewModel) object.unmarshal(in);\r
513                     af = LoadFromObject(object);\r
514                     entryCount++;\r
515                 }\r
516             }\r
517             while (jarentry != null);\r
518         }\r
519         catch (Exception ex)\r
520         {\r
521             System.err.println("Exception whilst loading jalview XML file : " +\r
522                 ex + "\n");\r
523              JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
524                                       "Couldn't locate " + file,\r
525                                       "URL not found",\r
526                                       JOptionPane.WARNING_MESSAGE);\r
527 \r
528         }\r
529 \r
530         return af;\r
531     }\r
532 \r
533     static AlignFrame LoadFromObject(JalviewModel object)\r
534     {\r
535         Vector seqids = new Vector();\r
536         SequenceSet vamsasSet = object.getVamsasModel().getSequenceSet(0);\r
537         Sequence[] vamsasSeq = vamsasSet.getSequence();\r
538 \r
539         JalviewModelSequence jms = object.getJalviewModelSequence();\r
540 \r
541         //////////////////////////////////\r
542         //LOAD SEQUENCES\r
543         jalview.datamodel.Sequence[] jseqs = new jalview.datamodel.Sequence[vamsasSeq.length];\r
544         JSeq[] JSEQ = object.getJalviewModelSequence().getJSeq();\r
545 \r
546         for (int i = 0; i < vamsasSeq.length; i++)\r
547         {\r
548             jseqs[i] = new jalview.datamodel.Sequence(vamsasSeq[i].getName(),\r
549                     vamsasSeq[i].getSequence());\r
550 \r
551             jseqs[i].setStart(JSEQ[i].getStart());\r
552             jseqs[i].setEnd(JSEQ[i].getEnd());\r
553             jseqs[i].setColor(new java.awt.Color(JSEQ[i].getColour()));\r
554             seqids.add(jseqs[i]);\r
555         }\r
556 \r
557         /////////////////////////////////\r
558         jalview.datamodel.Alignment al = new jalview.datamodel.Alignment(jseqs);\r
559 \r
560         /////////////////////////////////\r
561         //////////////////////////////////\r
562         //LOAD ANNOTATIONS\r
563         if (vamsasSet.getAnnotation() != null)\r
564         {\r
565             Annotation[] an = vamsasSet.getAnnotation();\r
566 \r
567             for (int i = 0; i < an.length; i++)\r
568             {\r
569                 AnnotationElement[] ae = an[i].getAnnotationElement();\r
570                 jalview.datamodel.Annotation[] anot = new jalview.datamodel.Annotation[al.getWidth()];\r
571 \r
572                 for (int aa = 0; aa < ae.length; aa++)\r
573                 {\r
574                     anot[ae[aa].getPosition()] = new jalview.datamodel.Annotation(ae[aa].getDisplayCharacter(),\r
575                             ae[aa].getDescription(),\r
576                             ae[aa].getSecondaryStructure().charAt(0),\r
577                             ae[aa].getValue());\r
578                 }\r
579 \r
580                 jalview.datamodel.AlignmentAnnotation jaa = null;\r
581 \r
582                 if (an[i].getGraph())\r
583                 {\r
584                     jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),\r
585                             an[i].getDescription(), anot, 0, 0, 1);\r
586                 }\r
587                 else\r
588                 {\r
589                     jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),\r
590                             an[i].getDescription(), anot);\r
591                 }\r
592 \r
593                 al.addAnnotation(jaa);\r
594             }\r
595         }\r
596 \r
597         /////////////////////////////////\r
598         // LOAD VIEWPORT\r
599         Viewport[] views = jms.getViewport();\r
600         Viewport view = views[0]; // DEAL WITH MULTIPLE VIEWPORTS LATER\r
601 \r
602         AlignFrame af = new AlignFrame(al);\r
603 \r
604         //  af.changeColour() );\r
605         /////////////////////////\r
606         //LOAD GROUPS\r
607         if (jms.getJGroupCount() > 0)\r
608         {\r
609             JGroup[] groups = jms.getJGroup();\r
610 \r
611             for (int i = 0; i < groups.length; i++)\r
612             {\r
613                 ColourSchemeI cs = null;\r
614 \r
615                 if (groups[i].getColour() != null)\r
616                 {\r
617                     if (groups[i].getColour().startsWith("ucs"))\r
618                     {\r
619                         cs = GetUserColourScheme(jms, groups[i].getColour());\r
620                     }\r
621                     else\r
622                     {\r
623                         cs = ColourSchemeProperty.getColour(al,\r
624                                 groups[i].getColour());\r
625                     }\r
626 \r
627                     if (cs instanceof ResidueColourScheme)\r
628                     {\r
629                         ((ResidueColourScheme) cs).setThreshold(groups[i].getPidThreshold());\r
630                     }\r
631                     else if (cs instanceof ScoreColourScheme)\r
632                     {\r
633                         ((ScoreColourScheme) cs).setThreshold(groups[i].getPidThreshold());\r
634                     }\r
635                 }\r
636 \r
637                 Vector seqs = new Vector();\r
638                 int[] ids = groups[i].getSeq();\r
639 \r
640                 for (int s = 0; s < ids.length; s++)\r
641                 {\r
642                     seqs.addElement((jalview.datamodel.SequenceI) seqids.elementAt(\r
643                             ids[s]));\r
644                 }\r
645 \r
646                 jalview.datamodel.SequenceGroup sg = new jalview.datamodel.SequenceGroup(seqs,\r
647                         groups[i].getName(), cs, groups[i].getDisplayBoxes(),\r
648                         groups[i].getDisplayText(), groups[i].getColourText(),\r
649                         groups[i].getStart(), groups[i].getEnd());\r
650 \r
651                 sg.setOutlineColour(new java.awt.Color(\r
652                         groups[i].getOutlineColour()));\r
653 \r
654                 if (groups[i].getConsThreshold() != 0)\r
655                 {\r
656                     jalview.analysis.Conservation c = new jalview.analysis.Conservation("All",\r
657                             ResidueProperties.propHash, 3, sg.sequences, 0,\r
658                             sg.getWidth() - 1);\r
659                     c.calculate();\r
660                     c.verdict(false, 25);\r
661                     cs = new ConservationColourScheme(c, cs);\r
662                     sg.cs = cs;\r
663                 }\r
664 \r
665                 al.addGroup(sg);\r
666             }\r
667         }\r
668 \r
669         Desktop.addInternalFrame(af, view.getTitle(),\r
670             AlignFrame.NEW_WINDOW_WIDTH, AlignFrame.NEW_WINDOW_HEIGHT);\r
671         af.setBounds(view.getXpos(), view.getYpos(), view.getWidth(),\r
672             view.getHeight());\r
673         af.viewport.setStartRes(view.getStartRes());\r
674         af.viewport.setStartSeq(view.getStartSeq());\r
675         af.viewport.showConservation = view.getShowConservation();\r
676         af.viewport.showQuality = view.getShowQuality();\r
677         af.viewport.showIdentity = view.getShowIdentity();\r
678         af.viewport.setAbovePIDThreshold(view.getPidSelected());\r
679         af.abovePIDThreshold.setSelected(view.getPidSelected());\r
680         af.viewport.setColourText(view.getShowColourText());\r
681         af.colourTextMenuItem.setSelected(view.getShowColourText());\r
682         af.viewport.setConservationSelected(view.getConservationSelected());\r
683         af.conservationMenuItem.setSelected(view.getConservationSelected());\r
684 \r
685         af.viewport.setShowFullId(view.getShowFullId());\r
686         af.fullSeqId.setSelected(view.getShowFullId());\r
687 \r
688         af.viewport.setFont(new java.awt.Font(view.getFontName(),\r
689                 view.getFontStyle(), view.getFontSize()));\r
690         af.alignPanel.fontChanged();\r
691 \r
692         af.viewport.setRenderGaps(view.getRenderGaps());\r
693         af.renderGapsMenuItem.setSelected(view.getRenderGaps());\r
694 \r
695         af.viewport.setWrapAlignment(view.getWrapAlignment());\r
696         af.wrapMenuItem.setSelected(view.getWrapAlignment());\r
697 \r
698         if (view.getWrapAlignment())\r
699         {\r
700             af.alignPanel.setWrapAlignment(view.getWrapAlignment());\r
701         }\r
702         else\r
703         {\r
704             af.annotationPanelMenuItem.setState(view.getShowAnnotation());\r
705             af.viewport.setShowAnnotation(view.getShowAnnotation());\r
706             af.alignPanel.setAnnotationVisible(view.getShowAnnotation());\r
707         }\r
708 \r
709         af.viewport.setShowBoxes(view.getShowBoxes());\r
710         af.viewBoxesMenuItem.setSelected(view.getShowBoxes());\r
711         af.viewport.setShowText(view.getShowText());\r
712         af.viewTextMenuItem.setSelected(view.getShowText());\r
713 \r
714         ColourSchemeI cs = null;\r
715 \r
716         if (view.getBgColour() != null)\r
717         {\r
718             if (view.getBgColour().startsWith("ucs"))\r
719             {\r
720                 cs = GetUserColourScheme(jms, view.getBgColour());\r
721             }\r
722             else\r
723             {\r
724                 cs = ColourSchemeProperty.getColour(al, view.getBgColour());\r
725             }\r
726 \r
727             if (cs instanceof ConservationColourScheme)\r
728             {\r
729                 ((ConservationColourScheme) cs).inc = view.getConsThreshold();\r
730             }\r
731 \r
732             if (cs instanceof ResidueColourScheme)\r
733             {\r
734                 ((ResidueColourScheme) cs).setThreshold(view.getPidThreshold());\r
735             }\r
736             else if (cs instanceof ScoreColourScheme)\r
737             {\r
738                 ((ScoreColourScheme) cs).setThreshold(view.getPidThreshold());\r
739             }\r
740         }\r
741 \r
742         af.viewport.setGlobalColourScheme(cs);\r
743 \r
744         af.viewport.setColourAppliesToAllGroups(false);\r
745         af.changeColour(af.viewport.getGlobalColourScheme());\r
746         af.viewport.setColourAppliesToAllGroups(true);\r
747 \r
748         if (view.getShowSequenceFeatures())\r
749         {\r
750             af.viewport.showSequenceFeatures = true;\r
751             af.sequenceFeatures.setSelected(true);\r
752             new SequenceFeatureFetcher(al, af.alignPanel);\r
753             al.featuresAdded = true;\r
754         }\r
755 \r
756         //LOAD TREES\r
757         ///////////////////////////////////////\r
758         if (jms.getTreeCount() > 0)\r
759         {\r
760             try\r
761             {\r
762                 for (int t = 0; t < jms.getTreeCount(); t++)\r
763                 {\r
764                     Tree tree = jms.getTree(t);\r
765 \r
766                     TreePanel tp = af.ShowNewickTree(new jalview.io.NewickFile(\r
767                                 tree.getNewick()), tree.getTitle());\r
768 \r
769                     tp.setBounds(tree.getXpos(), tree.getYpos(),\r
770                         tree.getWidth(), tree.getHeight());\r
771 \r
772                     tp.fitToWindow.setState(tree.getFitToWindow());\r
773                     tp.fitToWindow_actionPerformed(null);\r
774                     tp.treeCanvas.fontSize = tree.getFontSize();\r
775                     tp.fontSize.setText("Font Size - " + tree.getFontSize());\r
776                     tp.placeholdersMenu.setState(tree.getMarkUnlinked());\r
777                     tp.placeholdersMenu_actionPerformed(null);\r
778                     tp.bootstrapMenu.setState(tree.getShowBootstrap());\r
779                     tp.bootstrapMenu_actionPerformed(null);\r
780                     tp.distanceMenu.setState(tree.getShowDistances());\r
781                     tp.distanceMenu_actionPerformed(null);\r
782                     tp.treeCanvas.threshold = tree.getThreshold();\r
783 \r
784                     if (tree.getCurrentTree())\r
785                       af.viewport.setCurrentTree(tp.getTree());\r
786                 }\r
787             }\r
788             catch (Exception ex)\r
789             {\r
790                 ex.printStackTrace();\r
791             }\r
792         }\r
793         return af;\r
794     }\r
795 }\r