JAL-1641 updated applet version
[jalview.git] / src / jalview / io / JSONFile.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21
22 package jalview.io;
23
24 import java.awt.Color;
25 import java.io.IOException;
26 import java.util.ArrayList;
27 import java.util.Hashtable;
28 import java.util.Iterator;
29 import java.util.List;
30 import java.util.Vector;
31
32 import org.json.simple.JSONArray;
33 import org.json.simple.JSONObject;
34 import org.json.simple.parser.JSONParser;
35
36 import jalview.api.AlignViewControllerGuiI;
37 import jalview.api.AlignViewportI;
38 import jalview.api.FeatureRenderer;
39 import jalview.api.FeaturesDisplayedI;
40 import jalview.datamodel.AlignmentAnnotation;
41 import jalview.datamodel.Annotation;
42 import jalview.datamodel.HiddenSequences;
43 import jalview.datamodel.Sequence;
44 import jalview.datamodel.SequenceFeature;
45 import jalview.datamodel.SequenceGroup;
46 import jalview.datamodel.SequenceI;
47 import jalview.json.binding.v1.AlignmentAnnotationPojo;
48 import jalview.json.binding.v1.AlignmentPojo;
49 import jalview.json.binding.v1.AlignmentPojo.JalviewBioJsColorSchemeMapper;
50 import jalview.json.binding.v1.AnnotationPojo;
51 import jalview.json.binding.v1.SequenceFeaturesPojo;
52 import jalview.json.binding.v1.SequenceGrpPojo;
53 import jalview.json.binding.v1.SequencePojo;
54 import jalview.schemes.ColourSchemeI;
55 import jalview.schemes.ColourSchemeProperty;
56
57 public class JSONFile extends AlignFile
58 {
59   private ColourSchemeI colourScheme;
60
61   private String version = "2.9";
62
63   private String webstartUrl = "www.jalview.org/services/launchApp";
64
65   private String application = "Jalview";
66
67   public static final String FILE_EXT = "json";
68
69   public static final String FILE_DESC = "JSON";
70
71   private String globalColorScheme;
72
73   private boolean showSeqFeatures;
74
75   private Hashtable<String, Sequence> seqMap;
76
77   private FeaturesDisplayedI displayedFeatures;
78
79   private FeatureRenderer fr;
80
81   private JSONExportSettings jsonExportSettings;
82
83   private List<int[]> hiddenColumns;
84
85   private List<String> hiddenSeqRefs;
86
87   public JSONFile()
88   {
89     super();
90   }
91
92   public JSONFile(FileParse source) throws IOException
93   {
94     super(source);
95   }
96
97   public JSONFile(String inFile, String type) throws IOException
98   {
99     super(inFile, type);
100   }
101
102   @Override
103   public void parse() throws IOException
104   {
105     StringBuilder jsonStringBuilder = new StringBuilder();
106     String currentLine;
107     while ((currentLine = nextLine()) != null)
108     {
109       jsonStringBuilder.append(currentLine);
110     }
111     parse(jsonStringBuilder.toString());
112
113   }
114
115   @Override
116   public String print()
117   {
118     String jsonOutput = null;
119     try
120     {
121       if (getJsonExportSettings() == null)
122       {
123         jsonExportSettings = new JSONExportSettings();
124         jsonExportSettings.setExportAnnotations(true);
125         jsonExportSettings.setExportGroups(true);
126         jsonExportSettings.setExportJalviewSettings(true);
127         jsonExportSettings.setExportSequenceFeatures(true);
128       }
129
130       AlignmentPojo jsonAlignmentPojo = new AlignmentPojo();
131       if (getViewport() != null)
132       {
133         globalColorScheme = ColourSchemeProperty
134                 .getColourName(getViewport()
135                 .getGlobalColourScheme());
136         setDisplayedFeatures(getViewport().getFeaturesDisplayed());
137         showSeqFeatures = getViewport().isShowSequenceFeatures();
138         fr = getViewport().getFeatureRenderer();
139       }
140
141       int count = 0;
142       for (SequenceI seq : seqs)
143       {
144         StringBuilder name = new StringBuilder();
145         name.append(seq.getName()).append("/").append(seq.getStart())
146                 .append("-").append(seq.getEnd());
147         SequencePojo jsonSeqPojo = new SequencePojo();
148         jsonSeqPojo.setId(String.valueOf(seq.hashCode()));
149         jsonSeqPojo.setOrder(++count);
150         jsonSeqPojo.setEnd(seq.getEnd());
151         jsonSeqPojo.setStart(seq.getStart());
152         jsonSeqPojo.setName(name.toString());
153         jsonSeqPojo.setSeq(seq.getSequenceAsString());
154         jsonAlignmentPojo.getSeqs().add(jsonSeqPojo);
155       }
156
157       if (jsonExportSettings.isExportJalviewSettings())
158       {
159         jsonAlignmentPojo.setGlobalColorScheme(globalColorScheme);
160         jsonAlignmentPojo.getAppSettings().put("application", application);
161         jsonAlignmentPojo.getAppSettings().put("version", version);
162         jsonAlignmentPojo.getAppSettings().put("webStartUrl", webstartUrl);
163         jsonAlignmentPojo.getAppSettings().put("showSeqFeatures",
164                 String.valueOf(showSeqFeatures));
165
166         String[] hiddenSections = exportHiddenSections();
167         if (hiddenSections != null && getViewport().isIncludeHiddenRegion())
168         {
169           if (hiddenSections[0] != null)
170           {
171             jsonAlignmentPojo.getAppSettings().put("hiddenCols",
172                     String.valueOf(hiddenSections[0]));
173           }
174           if (hiddenSections[1] != null)
175           {
176             jsonAlignmentPojo.getAppSettings().put("hiddenSeqs",
177                     String.valueOf(hiddenSections[1]));
178           }
179         }
180       }
181
182       if (jsonExportSettings.isExportAnnotations())
183       {
184         jsonAlignmentPojo
185                 .setAlignAnnotation(annotationToJsonPojo(annotations));
186       }
187
188       if (jsonExportSettings.isExportSequenceFeatures())
189       {
190         jsonAlignmentPojo
191                 .setSeqFeatures(sequenceFeatureToJsonPojo(seqs, fr));
192       }
193
194       if (jsonExportSettings.isExportGroups() && seqGroups != null
195               && seqGroups.size() > 0)
196       {
197         for (SequenceGroup seqGrp : seqGroups)
198         {
199           SequenceGrpPojo seqGrpPojo = new SequenceGrpPojo();
200           seqGrpPojo.setGroupName(seqGrp.getName());
201           seqGrpPojo.setColourScheme(ColourSchemeProperty
202                   .getColourName(seqGrp.cs));
203           seqGrpPojo.setColourText(seqGrp.getColourText());
204           seqGrpPojo.setDescription(seqGrp.getDescription());
205           seqGrpPojo.setDisplayBoxes(seqGrp.getDisplayBoxes());
206           seqGrpPojo.setDisplayText(seqGrp.getDisplayText());
207           seqGrpPojo.setEndRes(seqGrp.getEndRes());
208           seqGrpPojo.setStartRes(seqGrp.getStartRes());
209           seqGrpPojo.setShowNonconserved(seqGrp.getShowNonconserved());
210           for (SequenceI seq : seqGrp.getSequences())
211           {
212             seqGrpPojo.getSeqsHash().add(String.valueOf(seq.hashCode()));
213           }
214           jsonAlignmentPojo.getSeqGroups().add(seqGrpPojo);
215         }
216       }
217       org.json.JSONObject generatedJSon = new org.json.JSONObject(
218               jsonAlignmentPojo);
219       jsonOutput = generatedJSon.toString();
220       return jsonOutput.replaceAll("xstart", "xStart").replaceAll("xend",
221               "xEnd");
222     } catch (Exception e)
223     {
224       e.printStackTrace();
225     }
226     return jsonOutput;
227   }
228
229   public String[] exportHiddenSections()
230   {
231     String[] hiddenSections = new String[2];
232     if (getViewport() == null)
233     {
234       return null;
235     }
236
237     System.out.println("--- Hidden Sections ---");
238     // hidden column business
239     if (getViewport().hasHiddenColumns())
240     {
241       System.out.print("Hidden Cols : ");
242       List<int[]> hiddenCols = getViewport().getColumnSelection()
243               .getHiddenColumns();
244       StringBuilder hiddenColsBuilder = new StringBuilder();
245       for (int[] range : hiddenCols)
246       {
247         hiddenColsBuilder.append(";").append(range[0]).append("-")
248                 .append(range[1]);
249       }
250
251       hiddenColsBuilder.deleteCharAt(0);
252       hiddenSections[0] = hiddenColsBuilder.toString();
253       System.out.println(hiddenSections[0]);
254     }
255
256     // hidden rows/seqs business
257     HiddenSequences hiddenSeqsObj = getViewport().getAlignment()
258             .getHiddenSequences();
259     if (hiddenSeqsObj == null || hiddenSeqsObj.hiddenSequences == null)
260     {
261       return hiddenSections;
262     }
263
264     SequenceI[] hiddenSeqs = hiddenSeqsObj.hiddenSequences;
265     System.out.print("Hidden Seqs : ");
266     // if(hiddenSeqs != null){
267     StringBuilder hiddenSeqsBuilder = new StringBuilder();
268     for (SequenceI hiddenSeq : hiddenSeqs)
269     {
270       if (hiddenSeq != null)
271       {
272         hiddenSeqsBuilder.append(";").append(hiddenSeq.hashCode());
273       }
274     }
275     if (hiddenSeqsBuilder.length() > 0)
276       {
277       hiddenSeqsBuilder.deleteCharAt(0);
278       }
279     hiddenSections[1] = hiddenSeqsBuilder.toString();
280     System.out.println(hiddenSections[1]);
281     // }
282
283     return hiddenSections;
284   }
285
286   public static List<SequenceFeaturesPojo> sequenceFeatureToJsonPojo(
287           List<SequenceI> seqs, FeatureRenderer fr)
288   {
289     FeaturesDisplayedI displayedFeatures = (fr == null) ? null : fr
290             .getFeaturesDisplayed();
291     List<SequenceFeaturesPojo> sequenceFeaturesPojo = new ArrayList<SequenceFeaturesPojo>();
292     for (SequenceI seq : seqs)
293     {
294       SequenceI dataSetSequence = seq.getDatasetSequence();
295       SequenceFeature[] seqFeatures = (dataSetSequence == null) ? null
296               : seq.getDatasetSequence().getSequenceFeatures();
297
298       seqFeatures = (seqFeatures == null) ? seq.getSequenceFeatures()
299               : seqFeatures;
300       if (seqFeatures == null)
301       {
302         continue;
303       }
304
305       for (SequenceFeature sf : seqFeatures)
306       {
307         if (displayedFeatures != null
308                 && displayedFeatures.isVisible(sf.getType()))
309         {
310           SequenceFeaturesPojo jsonFeature = new SequenceFeaturesPojo(
311                   String.valueOf(seq.hashCode()));
312           String featureColour = (fr == null) ? null : jalview.util.Format
313                   .getHexString(fr
314                   .findFeatureColour(Color.white, seq,
315                           seq.findIndex(sf.getBegin())));
316           jsonFeature.setXstart(seq.findIndex(sf.getBegin()) - 1);
317           jsonFeature.setXend(seq.findIndex(sf.getEnd()));
318           jsonFeature.setType(sf.getType());
319           jsonFeature.setDescription(sf.getDescription());
320           jsonFeature.setLinks(sf.links);
321           jsonFeature.setOtherDetails(sf.otherDetails);
322           jsonFeature.setScore(sf.getScore());
323           jsonFeature.setFillColor(featureColour);
324           jsonFeature.setFeatureGroup(sf.getFeatureGroup());
325           sequenceFeaturesPojo.add(jsonFeature);
326         }
327       }
328     }
329     return sequenceFeaturesPojo;
330   }
331
332   public static List<AlignmentAnnotationPojo> annotationToJsonPojo(
333           Vector<AlignmentAnnotation> annotations)
334   {
335     List<AlignmentAnnotationPojo> jsonAnnotations = new ArrayList<AlignmentAnnotationPojo>();
336     if (annotations == null)
337     {
338       return jsonAnnotations;
339     }
340     for (AlignmentAnnotation annot : annotations)
341     {
342       AlignmentAnnotationPojo alignAnnotPojo = new AlignmentAnnotationPojo();
343       alignAnnotPojo.setDescription(annot.description);
344       alignAnnotPojo.setLabel(annot.label);
345       for (Annotation annotation : annot.annotations)
346       {
347         AnnotationPojo annotationPojo = new AnnotationPojo();
348         if (annotation != null)
349         {
350           annotationPojo.setDescription(annotation.description);
351           annotationPojo.setValue(annotation.value);
352           annotationPojo
353                   .setSecondaryStructure(annotation.secondaryStructure);
354           annotationPojo.setDisplayCharacter(annotation.displayCharacter);
355           alignAnnotPojo.getAnnotations().add(annotationPojo);
356         }
357         else
358         {
359           alignAnnotPojo.getAnnotations().add(annotationPojo);
360         }
361       }
362       jsonAnnotations.add(alignAnnotPojo);
363     }
364     return jsonAnnotations;
365   }
366
367   @SuppressWarnings("unchecked")
368   public JSONFile parse(String jsonAlignmentString)
369   {
370     try
371     {
372       JSONParser jsonParser = new JSONParser();
373       JSONObject alignmentJsonObj = (JSONObject) jsonParser
374               .parse(jsonAlignmentString);
375       JSONArray seqJsonArray = (JSONArray) alignmentJsonObj.get("seqs");
376       JSONArray alAnnotJsonArray = (JSONArray) alignmentJsonObj
377               .get("alignAnnotation");
378       JSONArray jsonSeqArray = (JSONArray) alignmentJsonObj
379               .get("seqFeatures");
380       JSONArray seqGrpJsonArray = (JSONArray) alignmentJsonObj
381               .get("seqGroups");
382       JSONObject jvSettingsJsonObj = (JSONObject) alignmentJsonObj
383               .get("appSettings");
384
385       if (jvSettingsJsonObj != null)
386       {
387         String jsColourScheme = (String) jvSettingsJsonObj
388                 .get("globalColorScheme");
389         Boolean showFeatures = Boolean.valueOf(jvSettingsJsonObj.get(
390                 "showSeqFeatures").toString());
391         setColourScheme(getJalviewColorScheme(jsColourScheme));
392         setShowSeqFeatures(showFeatures);
393         parseHiddenSeqRefsAsList(jvSettingsJsonObj);
394         parseHiddenCols(jvSettingsJsonObj);
395       }
396
397       seqMap = new Hashtable<String, Sequence>();
398       for (Iterator<JSONObject> sequenceIter = seqJsonArray.iterator(); sequenceIter
399               .hasNext();)
400       {
401         JSONObject sequence = sequenceIter.next();
402         String sequcenceString = sequence.get("seq").toString();
403         String sequenceName = sequence.get("name").toString();
404         String seqUniqueId = sequence.get("id").toString();
405         int start = Integer.valueOf(sequence.get("start").toString());
406         int end = Integer.valueOf(sequence.get("end").toString());
407         Sequence seq = new Sequence(sequenceName, sequcenceString, start,
408                 end);
409         if (hiddenSeqRefs != null && hiddenSeqRefs.contains(seqUniqueId))
410         {
411           seq.setHidden(true);
412         }
413         seqs.add(seq);
414         seqMap.put(seqUniqueId, seq);
415       }
416       parseFeatures(jsonSeqArray);
417
418       for (Iterator<JSONObject> seqGrpIter = seqGrpJsonArray.iterator(); seqGrpIter
419               .hasNext();)
420       {
421         JSONObject seqGrpObj = seqGrpIter.next();
422         String grpName = seqGrpObj.get("groupName").toString();
423         String colourScheme = seqGrpObj.get("colourScheme").toString();
424         String description = (seqGrpObj.get("description") == null) ? null
425                 : seqGrpObj.get("description").toString();
426         boolean displayBoxes = Boolean.valueOf(seqGrpObj
427                 .get("displayBoxes").toString());
428         boolean displayText = Boolean.valueOf(seqGrpObj.get("displayText")
429                 .toString());
430         boolean colourText = Boolean.valueOf(seqGrpObj.get("colourText")
431                 .toString());
432         boolean showNonconserved = Boolean.valueOf(seqGrpObj.get(
433                 "showNonconserved").toString());
434         int startRes = Integer
435                 .valueOf(seqGrpObj.get("startRes").toString());
436         int endRes = Integer.valueOf(seqGrpObj.get("endRes").toString());
437         JSONArray seqsHashArray = (JSONArray) seqGrpObj.get("seqsHash");
438
439         ArrayList<SequenceI> grpSeqs = new ArrayList<SequenceI>();
440         if (seqsHashArray.size() > 0)
441         {
442           Iterator<String> seqHashIter = seqsHashArray.iterator();
443           while (seqHashIter.hasNext())
444           {
445             String seqHash = seqHashIter.next();
446             Sequence sequence = seqMap.get(seqHash);
447             if (sequence != null)
448             {
449               grpSeqs.add(sequence);
450             }
451           }
452         }
453         ColourSchemeI scheme = getJalviewColorScheme(colourScheme);
454         SequenceGroup seqGrp = new SequenceGroup(grpSeqs, grpName, scheme,
455                 displayBoxes, displayText, colourText, startRes, endRes);
456         seqGrp.setShowNonconserved(showNonconserved);
457         seqGrp.setDescription(description);
458         this.seqGroups.add(seqGrp);
459
460       }
461
462       for (Iterator<JSONObject> alAnnotIter = alAnnotJsonArray.iterator(); alAnnotIter
463               .hasNext();)
464       {
465         JSONObject alAnnot = alAnnotIter.next();
466         JSONArray annotJsonArray = (JSONArray) alAnnot.get("annotations");
467         Annotation[] annotations = new Annotation[annotJsonArray.size()];
468         int count = 0;
469         for (Iterator<JSONObject> annotIter = annotJsonArray.iterator(); annotIter
470                 .hasNext();)
471         {
472           JSONObject annot = annotIter.next();
473           if (annot == null)
474           {
475             annotations[count] = null;
476           }
477           else
478           {
479             float val = annot.get("value") == null ? null : Float
480                     .valueOf(annot.get("value").toString());
481             String desc = annot.get("description") == null ? null : annot
482                     .get("description").toString();
483
484             char ss = annot.get("secondaryStructure") == null ? ' '
485                     : annot.get("secondaryStructure").toString().charAt(0);
486             String displayChar = annot.get("displayCharacter").toString();
487
488             annotations[count] = new Annotation(displayChar, desc, ss, val);
489           }
490           ++count;
491         }
492
493         AlignmentAnnotation alignAnnot = new AlignmentAnnotation(alAnnot
494                 .get("label").toString(), alAnnot.get("description")
495                 .toString(), annotations);
496         this.annotations.add(alignAnnot);
497       }
498
499     } catch (Exception e)
500     {
501       e.printStackTrace();
502     }
503     return this;
504   }
505
506   public void parseHiddenSeqRefsAsList(JSONObject jvSettingsJson)
507   {
508     hiddenSeqRefs = new ArrayList<String>();
509     String hiddenSeqs = (String) jvSettingsJson.get("hiddenSeqs");
510     if(hiddenSeqs != null && !hiddenSeqs.isEmpty()){
511       String[] seqRefs = hiddenSeqs.split(";");
512       for(String seqRef : seqRefs){
513         hiddenSeqRefs.add(seqRef);
514       }
515     }
516   }
517
518   public void parseHiddenCols(JSONObject jvSettingsJson)
519   {
520     hiddenColumns = new ArrayList<int[]>();
521     String hiddenCols = (String) jvSettingsJson.get("hiddenCols");
522     if(hiddenCols != null && !hiddenCols.isEmpty()){
523       String[] rangeStrings = hiddenCols.split(";");
524       for(String rangeString : rangeStrings){
525         String[] range = rangeString.split("-");
526         hiddenColumns.add(new int[]
527         { Integer.valueOf(range[0]), Integer.valueOf(range[1]) });
528       }
529     }
530   }
531
532   @SuppressWarnings("unchecked")
533   private void parseFeatures(JSONArray jsonSeqFeatures)
534   {
535     if (jsonSeqFeatures != null)
536     {
537       for (Iterator<JSONObject> seqFeatureItr = jsonSeqFeatures.iterator(); seqFeatureItr
538               .hasNext();)
539       {
540         JSONObject jsonFeature = seqFeatureItr.next();
541         Long begin = (Long) jsonFeature.get("xStart");
542         Long end = (Long) jsonFeature.get("xEnd");
543         String type = (String) jsonFeature.get("type");
544         String featureGrp = (String) jsonFeature.get("featureGroup");
545         String descripiton = (String) jsonFeature.get("description");
546         String seqRef = (String) jsonFeature.get("sequenceRef");
547         Float score = Float.valueOf(jsonFeature.get("score").toString());
548         // Hashtable otherDetails = (Hashtable) jsonFeature
549         // .get("otherDetails");
550         // sequenceFeature.otherDetails = otherDetails;
551
552         Sequence seq = seqMap.get(seqRef);
553         SequenceFeature sequenceFeature = new SequenceFeature();
554         JSONArray linksJsonArray = (JSONArray) jsonFeature.get("links");
555         if (linksJsonArray != null && linksJsonArray.size() > 0)
556         {
557           Iterator<String> linkList = linksJsonArray.iterator();
558           while (linkList.hasNext())
559           {
560             String link = linkList.next();
561             sequenceFeature.addLink(link);
562           }
563         }
564         sequenceFeature.setFeatureGroup(featureGrp);
565         sequenceFeature.setScore(score);
566         sequenceFeature.setDescription(descripiton);
567         sequenceFeature.setType(type);
568         sequenceFeature.setBegin(seq.findPosition(begin.intValue()));
569         sequenceFeature.setEnd(seq.findPosition(end.intValue()) - 1);
570         seq.addSequenceFeature(sequenceFeature);
571       }
572     }
573   }
574
575   public static ColourSchemeI getJalviewColorScheme(
576           String bioJsColourSchemeName)
577   {
578     ColourSchemeI jalviewColor = null;
579     for (JalviewBioJsColorSchemeMapper cs : JalviewBioJsColorSchemeMapper
580             .values())
581     {
582       if (cs.getBioJsName().equalsIgnoreCase(bioJsColourSchemeName))
583       {
584         jalviewColor = cs.getJvColourScheme();
585         break;
586       }
587     }
588     return jalviewColor;
589   }
590
591   public void applySettingsToAlignmentView(AlignViewControllerGuiI avc)
592   {
593     avc.setShowSeqFeatures(isShowSeqFeatures());
594     avc.changeColour(getColourScheme());
595     avc.setMenusForViewport();
596     avc.hideColumns(hiddenColumns);
597     avc.syncHiddenSequences();
598   }
599
600   public String getGlobalColorScheme()
601   {
602     return globalColorScheme;
603   }
604
605   public void setGlobalColorScheme(String globalColorScheme)
606   {
607     this.globalColorScheme = globalColorScheme;
608   }
609
610   public ColourSchemeI getColourScheme()
611   {
612     return colourScheme;
613   }
614
615   public void setColourScheme(ColourSchemeI colourScheme)
616   {
617     this.colourScheme = colourScheme;
618   }
619
620   public FeaturesDisplayedI getDisplayedFeatures()
621   {
622     return displayedFeatures;
623   }
624
625   public void setDisplayedFeatures(FeaturesDisplayedI displayedFeatures)
626   {
627     this.displayedFeatures = displayedFeatures;
628   }
629
630   public JSONExportSettings getJsonExportSettings()
631   {
632     return jsonExportSettings;
633   }
634
635   public void setJsonExportSettings(JSONExportSettings jsonExportSettings)
636   {
637     this.jsonExportSettings = jsonExportSettings;
638   }
639
640   public static String getJSONData(AlignViewportI av)
641   {
642     JSONFile jsonFile = new JSONFile();
643     jsonFile.setViewport(av);
644     jsonFile.seqGroups = av.getAlignment().getGroups();
645     jsonFile.setDisplayedFeatures(av.getFeaturesDisplayed());
646
647     for (SequenceI seq : av.getAlignment().getSequences())
648     {
649       jsonFile.seqs.add(seq);
650     }
651   
652     // Add non auto calculated annotation to AlignFile
653     for (AlignmentAnnotation annot : av.getAlignment()
654             .getAlignmentAnnotation())
655     {
656       if (annot != null && !annot.autoCalculated)
657       {
658         if (annot.label.equals("PDB.CATempFactor"))
659         {
660           continue;
661         }
662         jsonFile.annotations.add(annot);
663       }
664     }
665     String jsonString = jsonFile.print();
666     return jsonString;
667   }
668
669   public boolean isShowSeqFeatures()
670   {
671     return showSeqFeatures;
672   }
673
674   public void setShowSeqFeatures(boolean showSeqFeatures)
675   {
676     this.showSeqFeatures = showSeqFeatures;
677   }
678
679   public Vector<AlignmentAnnotation> getAnnotations()
680   {
681     return annotations;
682   }
683
684   public List<int[]> getHiddenColumns()
685   {
686     return hiddenColumns;
687   }
688
689   public class JSONExportSettings
690   {
691     private boolean exportSequence;
692
693     private boolean exportSequenceFeatures;
694
695     private boolean exportAnnotations;
696
697     private boolean exportGroups;
698
699     private boolean exportJalviewSettings;
700
701     public boolean isExportSequence()
702     {
703       return exportSequence;
704     }
705
706     public void setExportSequence(boolean exportSequence)
707     {
708       this.exportSequence = exportSequence;
709     }
710
711     public boolean isExportSequenceFeatures()
712     {
713       return exportSequenceFeatures;
714     }
715
716     public void setExportSequenceFeatures(boolean exportSequenceFeatures)
717     {
718       this.exportSequenceFeatures = exportSequenceFeatures;
719     }
720
721     public boolean isExportAnnotations()
722     {
723       return exportAnnotations;
724     }
725
726     public void setExportAnnotations(boolean exportAnnotations)
727     {
728       this.exportAnnotations = exportAnnotations;
729     }
730
731     public boolean isExportGroups()
732     {
733       return exportGroups;
734     }
735
736     public void setExportGroups(boolean exportGroups)
737     {
738       this.exportGroups = exportGroups;
739     }
740
741     public boolean isExportJalviewSettings()
742     {
743       return exportJalviewSettings;
744     }
745
746     public void setExportJalviewSettings(boolean exportJalviewSettings)
747     {
748       this.exportJalviewSettings = exportJalviewSettings;
749     }
750   }
751 }