Clover icon

Coverage Report

  1. Project Clover database Thu Aug 13 2020 12:04:21 BST
  2. Package jalview.io

File JSONFile.java

 

Coverage histogram

../../img/srcFileCovDistChart8.png
20% of files have more coverage

Code metrics

138
308
35
2
850
710
120
0.39
8.8
17.5
3.43

Classes

Class Line # Actions
JSONFile 69 298 110
0.832971883.3%
JSONFile.JSONExportSettings 773 10 10
0.00%
 

Contributing tests

This file is covered by 7 tests. .

Source view

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 jalview.api.AlignExportSettingsI;
25    import jalview.api.AlignViewportI;
26    import jalview.api.AlignmentViewPanel;
27    import jalview.api.ComplexAlignFile;
28    import jalview.api.FeatureRenderer;
29    import jalview.api.FeatureSettingsModelI;
30    import jalview.api.FeaturesDisplayedI;
31    import jalview.bin.BuildDetails;
32    import jalview.datamodel.AlignExportSettingsAdapter;
33    import jalview.datamodel.AlignmentAnnotation;
34    import jalview.datamodel.AlignmentI;
35    import jalview.datamodel.Annotation;
36    import jalview.datamodel.HiddenColumns;
37    import jalview.datamodel.HiddenSequences;
38    import jalview.datamodel.Sequence;
39    import jalview.datamodel.SequenceFeature;
40    import jalview.datamodel.SequenceGroup;
41    import jalview.datamodel.SequenceI;
42    import jalview.json.binding.biojson.v1.AlignmentAnnotationPojo;
43    import jalview.json.binding.biojson.v1.AlignmentPojo;
44    import jalview.json.binding.biojson.v1.AnnotationDisplaySettingPojo;
45    import jalview.json.binding.biojson.v1.AnnotationPojo;
46    import jalview.json.binding.biojson.v1.ColourSchemeMapper;
47    import jalview.json.binding.biojson.v1.SequenceFeaturesPojo;
48    import jalview.json.binding.biojson.v1.SequenceGrpPojo;
49    import jalview.json.binding.biojson.v1.SequencePojo;
50    import jalview.renderer.seqfeatures.FeatureColourFinder;
51    import jalview.schemes.ColourSchemeProperty;
52    import jalview.schemes.JalviewColourScheme;
53    import jalview.schemes.ResidueColourScheme;
54    import jalview.util.ColorUtils;
55    import jalview.util.Format;
56    import jalview.util.JSONUtils;
57    import jalview.viewmodel.seqfeatures.FeaturesDisplayed;
58   
59    import java.awt.Color;
60    import java.io.IOException;
61    import java.io.Reader;
62    import java.util.ArrayList;
63    import java.util.Hashtable;
64    import java.util.Iterator;
65    import java.util.List;
66    import java.util.Map;
67    import java.util.Vector;
68   
 
69    public class JSONFile extends AlignFile implements ComplexAlignFile
70    {
71    private static String version = new BuildDetails().getVersion();
72   
73    private String webstartUrl = "http://www.jalview.org/services/launchApp";
74   
75    private String application = "Jalview";
76   
77    private String globalColourScheme;
78   
79    private boolean showSeqFeatures;
80   
81    private Hashtable<String, Sequence> seqMap;
82   
83    private FeaturesDisplayedI displayedFeatures;
84   
85    private FeatureRenderer fr;
86   
87    private HiddenColumns hiddenColumns;
88   
89    private List<String> hiddenSeqRefs;
90   
91    private ArrayList<SequenceI> hiddenSequences;
92   
93    private final static String TCOFFEE_SCORE = "TCoffeeScore";
94   
 
95  5 toggle public JSONFile()
96    {
97  5 super();
98    }
99   
 
100  6 toggle public JSONFile(FileParse source) throws IOException
101    {
102  6 super(source);
103    }
104   
 
105  0 toggle public JSONFile(String inFile, DataSourceType sourceType)
106    throws IOException
107    {
108  0 super(inFile, sourceType);
109    }
110   
 
111  6 toggle @Override
112    public void parse() throws IOException
113    {
114  6 parse(getReader());
115   
116    }
117   
 
118  5 toggle @Override
119    public String print(SequenceI[] sqs, boolean jvsuffix)
120    {
121  5 String jsonOutput = null;
122  5 try
123    {
124  5 AlignmentPojo jsonAlignmentPojo = new AlignmentPojo();
125  5 AlignExportSettingsI exportSettings = getExportSettings();
126   
127    /*
128    * if no export settings were supplied, provide an 'export all' setting
129    */
130  5 if (exportSettings == null)
131    {
132  2 exportSettings = new AlignExportSettingsAdapter(true);
133    }
134   
135  5 int count = 0;
136  5 for (SequenceI seq : sqs)
137    {
138  45 StringBuilder name = new StringBuilder();
139  45 name.append(seq.getName()).append("/").append(seq.getStart())
140    .append("-").append(seq.getEnd());
141  45 SequencePojo jsonSeqPojo = new SequencePojo();
142  45 jsonSeqPojo.setId(String.valueOf(seq.hashCode()));
143  45 jsonSeqPojo.setOrder(++count);
144  45 jsonSeqPojo.setEnd(seq.getEnd());
145  45 jsonSeqPojo.setStart(seq.getStart());
146  45 jsonSeqPojo.setName(name.toString());
147  45 jsonSeqPojo.setSeq(seq.getSequenceAsString());
148  45 jsonAlignmentPojo.getSeqs().add(jsonSeqPojo);
149    }
150  5 jsonAlignmentPojo.setGlobalColorScheme(globalColourScheme);
151  5 jsonAlignmentPojo.getAppSettings().put("application", application);
152  5 jsonAlignmentPojo.getAppSettings().put("version", version);
153  5 jsonAlignmentPojo.getAppSettings().put("webStartUrl", webstartUrl);
154  5 jsonAlignmentPojo.getAppSettings().put("showSeqFeatures",
155    String.valueOf(showSeqFeatures));
156   
157  5 String[] hiddenSections = getHiddenSections();
158  5 if (hiddenSections != null)
159    {
160  4 if (hiddenSections[0] != null
161    && exportSettings.isExportHiddenColumns())
162    {
163  2 jsonAlignmentPojo.getAppSettings().put("hiddenCols",
164    String.valueOf(hiddenSections[0]));
165    }
166  4 if (hiddenSections[1] != null
167    && exportSettings.isExportHiddenSequences())
168    {
169  2 jsonAlignmentPojo.getAppSettings().put("hiddenSeqs",
170    String.valueOf(hiddenSections[1]));
171    }
172    }
173   
174  5 if (exportSettings.isExportAnnotations())
175    {
176  5 jsonAlignmentPojo
177    .setAlignAnnotation(annotationToJsonPojo(annotations));
178    }
179    else
180    {
181    // These color schemes require annotation, disable them if annotations
182    // are not exported
183  0 if (globalColourScheme
184    .equalsIgnoreCase(JalviewColourScheme.RNAHelices.toString())
185    || globalColourScheme.equalsIgnoreCase(
186    JalviewColourScheme.TCoffee.toString()))
187    {
188  0 jsonAlignmentPojo.setGlobalColorScheme(ResidueColourScheme.NONE);
189    }
190    }
191   
192  5 if (exportSettings.isExportFeatures())
193    {
194  5 jsonAlignmentPojo.setSeqFeatures(sequenceFeatureToJsonPojo(sqs));
195    }
196   
197  5 if (exportSettings.isExportGroups() && seqGroups != null
198    && seqGroups.size() > 0)
199    {
200  3 for (SequenceGroup seqGrp : seqGroups)
201    {
202  3 SequenceGrpPojo seqGrpPojo = new SequenceGrpPojo();
203  3 seqGrpPojo.setGroupName(seqGrp.getName());
204  3 seqGrpPojo.setColourScheme(ColourSchemeProperty
205    .getColourName(seqGrp.getColourScheme()));
206  3 seqGrpPojo.setColourText(seqGrp.getColourText());
207  3 seqGrpPojo.setDescription(seqGrp.getDescription());
208  3 seqGrpPojo.setDisplayBoxes(seqGrp.getDisplayBoxes());
209  3 seqGrpPojo.setDisplayText(seqGrp.getDisplayText());
210  3 seqGrpPojo.setEndRes(seqGrp.getEndRes());
211  3 seqGrpPojo.setStartRes(seqGrp.getStartRes());
212  3 seqGrpPojo.setShowNonconserved(seqGrp.getShowNonconserved());
213  3 for (SequenceI seq : seqGrp.getSequences())
214    {
215  12 seqGrpPojo.getSequenceRefs()
216    .add(String.valueOf(seq.hashCode()));
217    }
218  3 jsonAlignmentPojo.getSeqGroups().add(seqGrpPojo);
219    }
220    }
221   
222  5 jsonOutput = JSONUtils.stringify(jsonAlignmentPojo);
223  5 return jsonOutput.replaceAll("xstart", "xStart").replaceAll("xend",
224    "xEnd");
225    } catch (Exception e)
226    {
227  0 e.printStackTrace();
228    }
229  0 return jsonOutput;
230    }
231   
 
232  5 toggle public String[] getHiddenSections()
233    {
234  5 String[] hiddenSections = new String[2];
235  5 if (getViewport() == null)
236    {
237  1 return null;
238    }
239   
240    // hidden column business
241  4 if (getViewport().hasHiddenColumns())
242    {
243  2 hiddenSections[0] = getViewport().getAlignment().getHiddenColumns()
244    .regionsToString(";", "-");
245    }
246   
247    // hidden rows/seqs business
248  4 HiddenSequences hiddenSeqsObj = getViewport().getAlignment()
249    .getHiddenSequences();
250  4 if (hiddenSeqsObj == null || hiddenSeqsObj.hiddenSequences == null)
251    {
252  2 return hiddenSections;
253    }
254   
255  2 SequenceI[] hiddenSeqs = hiddenSeqsObj.hiddenSequences;
256  2 StringBuilder hiddenSeqsBuilder = new StringBuilder();
257  2 for (SequenceI hiddenSeq : hiddenSeqs)
258    {
259  12 if (hiddenSeq != null)
260    {
261  2 hiddenSeqsBuilder.append(";").append(hiddenSeq.hashCode());
262    }
263    }
264  2 if (hiddenSeqsBuilder.length() > 0)
265    {
266  2 hiddenSeqsBuilder.deleteCharAt(0);
267    }
268  2 hiddenSections[1] = hiddenSeqsBuilder.toString();
269   
270  2 return hiddenSections;
271    }
272   
 
273  5 toggle protected List<SequenceFeaturesPojo> sequenceFeatureToJsonPojo(
274    SequenceI[] sqs)
275    {
276  5 displayedFeatures = (fr == null) ? null : fr.getFeaturesDisplayed();
277  5 List<SequenceFeaturesPojo> sequenceFeaturesPojo = new ArrayList<>();
278  5 if (sqs == null)
279    {
280  0 return sequenceFeaturesPojo;
281    }
282   
283  5 FeatureColourFinder finder = new FeatureColourFinder(fr);
284   
285  5 String[] visibleFeatureTypes = displayedFeatures == null ? null
286    : displayedFeatures.getVisibleFeatures().toArray(
287    new String[displayedFeatures.getVisibleFeatureCount()]);
288   
289  5 for (SequenceI seq : sqs)
290    {
291    /*
292    * get all features currently visible (and any non-positional features)
293    */
294  45 List<SequenceFeature> seqFeatures = seq.getFeatures().getAllFeatures(
295    visibleFeatureTypes);
296  45 for (SequenceFeature sf : seqFeatures)
297    {
298  12 SequenceFeaturesPojo jsonFeature = new SequenceFeaturesPojo(
299    String.valueOf(seq.hashCode()));
300   
301  12 String featureColour = (fr == null) ? null : Format
302    .getHexString(finder.findFeatureColour(Color.white, seq,
303    seq.findIndex(sf.getBegin())));
304  12 int xStart = sf.getBegin() == 0 ? 0
305    : seq.findIndex(sf.getBegin()) - 1;
306  12 int xEnd = sf.getEnd() == 0 ? 0 : seq.findIndex(sf.getEnd());
307  12 jsonFeature.setXstart(xStart);
308  12 jsonFeature.setXend(xEnd);
309  12 jsonFeature.setType(sf.getType());
310  12 jsonFeature.setDescription(sf.getDescription());
311  12 jsonFeature.setLinks(sf.links);
312  12 jsonFeature.setOtherDetails(sf.otherDetails);
313  12 jsonFeature.setScore(sf.getScore());
314  12 jsonFeature.setFillColor(featureColour);
315  12 jsonFeature.setFeatureGroup(sf.getFeatureGroup());
316  12 sequenceFeaturesPojo.add(jsonFeature);
317    }
318    }
319  5 return sequenceFeaturesPojo;
320    }
321   
 
322  5 toggle public static List<AlignmentAnnotationPojo> annotationToJsonPojo(
323    Vector<AlignmentAnnotation> annotations)
324    {
325  5 List<AlignmentAnnotationPojo> jsonAnnotations = new ArrayList<>();
326  5 if (annotations == null)
327    {
328  0 return jsonAnnotations;
329    }
330  5 for (AlignmentAnnotation annot : annotations)
331    {
332  2 AlignmentAnnotationPojo alignAnnotPojo = new AlignmentAnnotationPojo();
333  2 alignAnnotPojo.setDescription(annot.description);
334  2 alignAnnotPojo.setLabel(annot.label);
335  2 if (!Double.isNaN(annot.score))
336    {
337  0 alignAnnotPojo.setScore(annot.score);
338    }
339  2 alignAnnotPojo.setCalcId(annot.getCalcId());
340  2 alignAnnotPojo.setGraphType(annot.graph);
341   
342  2 AnnotationDisplaySettingPojo annotSetting = new AnnotationDisplaySettingPojo();
343  2 annotSetting.setBelowAlignment(annot.belowAlignment);
344  2 annotSetting.setCentreColLabels(annot.centreColLabels);
345  2 annotSetting.setScaleColLabel(annot.scaleColLabel);
346  2 annotSetting.setShowAllColLabels(annot.showAllColLabels);
347  2 annotSetting.setVisible(annot.visible);
348  2 annotSetting.setHasIcon(annot.hasIcons);
349  2 alignAnnotPojo.setAnnotationSettings(annotSetting);
350  2 SequenceI refSeq = annot.sequenceRef;
351  2 if (refSeq != null)
352    {
353  0 alignAnnotPojo.setSequenceRef(String.valueOf(refSeq.hashCode()));
354    }
355  2 for (Annotation annotation : annot.annotations)
356    {
357  70 AnnotationPojo annotationPojo = new AnnotationPojo();
358  70 if (annotation != null)
359    {
360  70 annotationPojo.setDescription(annotation.description);
361  70 annotationPojo.setValue(annotation.value);
362  70 annotationPojo
363    .setSecondaryStructure(annotation.secondaryStructure);
364  70 String displayChar = annotation.displayCharacter == null ? null
365    : annotation.displayCharacter;
366    // System.out.println("--------------------->[" + displayChar + "]");
367  70 annotationPojo.setDisplayCharacter(displayChar);
368  70 if (annotation.colour != null)
369    {
370  0 annotationPojo.setColour(
371    jalview.util.Format.getHexString(annotation.colour));
372    }
373  70 alignAnnotPojo.getAnnotations().add(annotationPojo);
374    }
375    else
376    {
377  0 if (annot.getCalcId() != null
378    && annot.getCalcId().equalsIgnoreCase(TCOFFEE_SCORE))
379    {
380    // do nothing
381    }
382    else
383    {
384  0 alignAnnotPojo.getAnnotations().add(annotationPojo);
385    }
386    }
387    }
388  2 jsonAnnotations.add(alignAnnotPojo);
389    }
390  5 return jsonAnnotations;
391    }
392   
 
393  6 toggle @SuppressWarnings("unchecked")
394    public JSONFile parse(Reader jsonAlignmentString)
395    {
396  6 try
397    {
398  6 Map<String, Object> alignmentJsonObj = (Map<String, Object>) JSONUtils.parse(jsonAlignmentString);
399  6 List<Object> seqJsonArray = (List<Object>) alignmentJsonObj.get("seqs");
400  6 List<Object> alAnnotJsonArray = (List<Object>) alignmentJsonObj
401    .get("alignAnnotation");
402  6 List<Object> jsonSeqArray = (List<Object>) alignmentJsonObj
403    .get("seqFeatures");
404  6 List<Object> seqGrpJsonArray = (List<Object>) alignmentJsonObj
405    .get("seqGroups");
406  6 Map<String, Object> jvSettingsJsonObj = (Map<String, Object>) alignmentJsonObj
407    .get("appSettings");
408   
409  6 if (jvSettingsJsonObj != null)
410    {
411  6 globalColourScheme = (String) jvSettingsJsonObj
412    .get("globalColorScheme");
413  6 Boolean showFeatures = Boolean.valueOf(
414    jvSettingsJsonObj.get("showSeqFeatures").toString());
415  6 setShowSeqFeatures(showFeatures);
416  6 parseHiddenSeqRefsAsList(jvSettingsJsonObj);
417  6 parseHiddenCols(jvSettingsJsonObj);
418    }
419   
420  6 hiddenSequences = new ArrayList<>();
421  6 seqMap = new Hashtable<>();
422  48 for (Iterator<Object> sequenceIter = seqJsonArray.iterator(); sequenceIter.hasNext();)
423    {
424  42 Map<String, Object> sequence = (Map<String, Object>) sequenceIter.next();
425  42 String sequcenceString = sequence.get("seq").toString();
426  42 String sequenceName = sequence.get("name").toString();
427  42 String seqUniqueId = sequence.get("id").toString();
428  42 int start = Integer.valueOf(sequence.get("start").toString());
429  42 int end = Integer.valueOf(sequence.get("end").toString());
430  42 Sequence seq = new Sequence(sequenceName, sequcenceString, start,
431    end);
432  42 if (hiddenSeqRefs != null && hiddenSeqRefs.contains(seqUniqueId))
433    {
434  2 hiddenSequences.add(seq);
435    }
436  42 seqs.add(seq);
437  42 seqMap.put(seqUniqueId, seq);
438    }
439   
440  6 parseFeatures(jsonSeqArray);
441   
442  11 for (Iterator<Object> seqGrpIter = seqGrpJsonArray.iterator(); seqGrpIter.hasNext();)
443    {
444  5 Map<String, Object> seqGrpObj = (Map<String, Object>)seqGrpIter.next();
445  5 String grpName = seqGrpObj.get("groupName").toString();
446  5 String colourScheme = seqGrpObj.get("colourScheme").toString();
447  5 String description = (seqGrpObj.get("description") == null) ? null
448    : seqGrpObj.get("description").toString();
449  5 boolean displayBoxes = Boolean
450    .valueOf(seqGrpObj.get("displayBoxes").toString());
451  5 boolean displayText = Boolean
452    .valueOf(seqGrpObj.get("displayText").toString());
453  5 boolean colourText = Boolean
454    .valueOf(seqGrpObj.get("colourText").toString());
455  5 boolean showNonconserved = Boolean
456    .valueOf(seqGrpObj.get("showNonconserved").toString());
457  5 int startRes = Integer
458    .valueOf(seqGrpObj.get("startRes").toString());
459  5 int endRes = Integer.valueOf(seqGrpObj.get("endRes").toString());
460  5 List<Object> sequenceRefs = (List<Object>) seqGrpObj.get("sequenceRefs");
461   
462  5 ArrayList<SequenceI> grpSeqs = new ArrayList<>();
463  5 if (sequenceRefs.size() > 0)
464    {
465  5 Iterator<Object> seqHashIter = sequenceRefs.iterator();
466  25 while (seqHashIter.hasNext())
467    {
468  20 Sequence sequence = seqMap.get(seqHashIter.next());
469  20 if (sequence != null)
470    {
471  20 grpSeqs.add(sequence);
472    }
473    }
474    }
475  5 SequenceGroup seqGrp = new SequenceGroup(grpSeqs, grpName, null,
476    displayBoxes, displayText, colourText, startRes, endRes);
477  5 seqGrp.setColourScheme(ColourSchemeMapper
478    .getJalviewColourScheme(colourScheme, seqGrp));
479  5 seqGrp.setShowNonconserved(showNonconserved);
480  5 seqGrp.setDescription(description);
481  5 this.seqGroups.add(seqGrp);
482   
483    }
484   
485  10 for (Iterator<Object> alAnnotIter = alAnnotJsonArray.iterator(); alAnnotIter.hasNext();)
486    {
487  4 Map<String, Object> alAnnot = (Map<String, Object>) alAnnotIter.next();
488  4 List<Object> annotJsonArray = (List<Object>) alAnnot.get("annotations");
489  4 Annotation[] annotations = new Annotation[annotJsonArray.size()];
490  4 int count = 0;
491  144 for (Iterator<Object> annotIter = annotJsonArray.iterator(); annotIter.hasNext();)
492    {
493  140 Map<String, Object> annot = (Map<String, Object>) annotIter.next();
494  140 if (annot == null)
495    {
496  0 annotations[count] = null;
497    }
498    else
499    {
500  140 float val = annot.get("value") == null ? null
501    : Float.valueOf(annot.get("value").toString());
502  140 String desc = annot.get("description") == null ? null
503    : annot.get("description").toString();
504  140 char ss = annot.get("secondaryStructure") == null
505    || annot.get("secondaryStructure").toString()
506    .equalsIgnoreCase("u0000") ? ' '
507    : annot.get("secondaryStructure")
508    .toString().charAt(0);
509  140 String displayChar = annot.get("displayCharacter") == null ? ""
510    : annot.get("displayCharacter").toString();
511   
512  140 annotations[count] = new Annotation(displayChar, desc, ss, val);
513  140 if (annot.get("colour") != null)
514    {
515  0 Color color = ColorUtils
516    .parseColourString(annot.get("colour").toString());
517  0 annotations[count].colour = color;
518    }
519    }
520  140 ++count;
521    }
522   
523  4 AlignmentAnnotation alignAnnot = new AlignmentAnnotation(
524    alAnnot.get("label").toString(),
525    alAnnot.get("description").toString(), annotations);
526  4 alignAnnot.graph = (alAnnot.get("graphType") == null) ? 0
527    : Integer.valueOf(alAnnot.get("graphType").toString());
528   
529  4 Map<String, Object> diplaySettings = (Map<String, Object>) alAnnot
530    .get("annotationSettings");
531  4 if (diplaySettings != null)
532    {
533   
534  2 alignAnnot.scaleColLabel = (diplaySettings
535    .get("scaleColLabel") == null) ? false
536    : Boolean.valueOf(diplaySettings
537    .get("scaleColLabel").toString());
538  2 alignAnnot.showAllColLabels = (diplaySettings
539    .get("showAllColLabels") == null) ? true
540    : Boolean.valueOf(diplaySettings
541    .get("showAllColLabels").toString());
542  2 alignAnnot.centreColLabels = (diplaySettings
543    .get("centreColLabels") == null) ? true
544    : Boolean.valueOf(diplaySettings
545    .get("centreColLabels").toString());
546  2 alignAnnot.belowAlignment = (diplaySettings
547    .get("belowAlignment") == null) ? false
548    : Boolean.valueOf(diplaySettings
549    .get("belowAlignment").toString());
550  2 alignAnnot.visible = (diplaySettings.get("visible") == null)
551    ? true
552    : Boolean.valueOf(
553    diplaySettings.get("visible").toString());
554  2 alignAnnot.hasIcons = (diplaySettings.get("hasIcon") == null)
555    ? true
556    : Boolean.valueOf(
557    diplaySettings.get("hasIcon").toString());
558   
559    }
560  4 if (alAnnot.get("score") != null)
561    {
562  2 alignAnnot.score = Double
563    .valueOf(alAnnot.get("score").toString());
564    }
565   
566  4 String calcId = (alAnnot.get("calcId") == null) ? ""
567    : alAnnot.get("calcId").toString();
568  4 alignAnnot.setCalcId(calcId);
569  4 String seqHash = (alAnnot.get("sequenceRef") != null)
570    ? alAnnot.get("sequenceRef").toString()
571    : null;
572   
573  4 Sequence sequence = (seqHash != null) ? seqMap.get(seqHash) : null;
574  4 if (sequence != null)
575    {
576  0 alignAnnot.sequenceRef = sequence;
577  0 sequence.addAlignmentAnnotation(alignAnnot);
578  0 if (alignAnnot.label.equalsIgnoreCase("T-COFFEE"))
579    {
580  0 alignAnnot.createSequenceMapping(sequence, sequence.getStart(),
581    false);
582  0 sequence.addAlignmentAnnotation(alignAnnot);
583  0 alignAnnot.adjustForAlignment();
584    }
585    }
586  4 alignAnnot.validateRangeAndDisplay();
587  4 this.annotations.add(alignAnnot);
588   
589    }
590    } catch (Exception e)
591    {
592  0 e.printStackTrace();
593    }
594  6 return this;
595    }
596   
 
597  6 toggle public void parseHiddenSeqRefsAsList(Map<String, Object> jvSettingsJson)
598    {
599  6 hiddenSeqRefs = new ArrayList<>();
600  6 String hiddenSeqs = (String) jvSettingsJson.get("hiddenSeqs");
601  6 if (hiddenSeqs != null && !hiddenSeqs.isEmpty())
602    {
603  4 String[] seqRefs = hiddenSeqs.split(";");
604  8 for (int i = 0, n = seqRefs.length; i < n; i++)
605    {
606  4 hiddenSeqRefs.add(seqRefs[i]);
607    }
608    }
609    }
610   
 
611  6 toggle public void parseHiddenCols(Map<String, Object> jvSettingsJson)
612    {
613  6 String hiddenCols = (String) jvSettingsJson.get("hiddenCols");
614  6 if (hiddenCols != null && !hiddenCols.isEmpty())
615    {
616  4 hiddenColumns = new HiddenColumns();
617  4 String[] rangeStrings = hiddenCols.split(";");
618  12 for (int i = 0, n = rangeStrings.length; i < n; i++)
619    {
620  8 String[] range = rangeStrings[i].split("-");
621  8 hiddenColumns.hideColumns(Integer.valueOf(range[0]),
622    Integer.valueOf(range[1]));
623    }
624    }
625    }
626   
 
627  6 toggle @SuppressWarnings("unchecked")
628    private void parseFeatures(List<Object> jsonSeqFeatures)
629    {
630  6 if (jsonSeqFeatures != null)
631    {
632  6 displayedFeatures = new FeaturesDisplayed();
633  6 for (Object o : jsonSeqFeatures)
634    {
635  20 Map<String, Object> jsonFeature = (Map<String, Object>) o;
636  20 Long begin = (Long) jsonFeature.get("xStart");
637  20 Long end = (Long) jsonFeature.get("xEnd");
638  20 String type = (String) jsonFeature.get("type");
639  20 String featureGrp = (String) jsonFeature.get("featureGroup");
640  20 String description = (String) jsonFeature.get("description");
641  20 String seqRef = (String) jsonFeature.get("sequenceRef");
642  20 Float score = Float.valueOf(jsonFeature.get("score").toString());
643   
644  20 Sequence seq = seqMap.get(seqRef);
645   
646    /*
647    * begin/end of 0 is for a non-positional feature
648    */
649  20 int featureBegin = begin.intValue() == 0 ? 0 : seq
650    .findPosition(begin.intValue());
651  20 int featureEnd = end.intValue() == 0 ? 0 : seq.findPosition(end
652    .intValue()) - 1;
653   
654  20 SequenceFeature sequenceFeature = new SequenceFeature(type,
655    description, featureBegin, featureEnd, score, featureGrp);
656   
657  20 List<Object> linksJsonArray = (List<Object>) jsonFeature.get("links");
658  20 if (linksJsonArray != null && linksJsonArray.size() > 0)
659    {
660  0 Iterator<Object> linkList = linksJsonArray.iterator();
661  0 while (linkList.hasNext())
662    {
663  0 sequenceFeature.addLink((String) linkList.next());
664    }
665    }
666   
667  20 seq.addSequenceFeature(sequenceFeature);
668  20 displayedFeatures.setVisible(type);
669    }
670    }
671    }
672   
 
673  4 toggle @Override
674    public String getGlobalColourScheme()
675    {
676  4 return globalColourScheme;
677    }
678   
 
679  0 toggle public void setGlobalColorScheme(String globalColourScheme)
680    {
681  0 this.globalColourScheme = globalColourScheme;
682    }
683   
 
684  2 toggle @Override
685    public FeaturesDisplayedI getDisplayedFeatures()
686    {
687  2 return displayedFeatures;
688    }
689   
 
690  4 toggle public void setDisplayedFeatures(FeaturesDisplayedI displayedFeatures)
691    {
692  4 this.displayedFeatures = displayedFeatures;
693    }
694   
 
695  5 toggle @Override
696    public void configureForView(AlignmentViewPanel avpanel)
697    {
698  5 if (avpanel == null)
699    {
700  1 return;
701    }
702  4 super.configureForView(avpanel);
703  4 AlignViewportI viewport = avpanel.getAlignViewport();
704  4 AlignmentI alignment = viewport.getAlignment();
705  4 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
706   
707  4 seqGroups = alignment.getGroups();
708  4 fr = avpanel.cloneFeatureRenderer();
709   
710    // Add non auto calculated annotation to AlignFile
711  4 if (annots != null)
712    {
713  4 for (AlignmentAnnotation annot : annots)
714    {
715  18 if (annot != null && !annot.autoCalculated)
716    {
717  2 annotations.add(annot);
718    }
719    }
720    }
721  4 globalColourScheme = ColourSchemeProperty
722    .getColourName(viewport.getGlobalColourScheme());
723  4 setDisplayedFeatures(viewport.getFeaturesDisplayed());
724  4 showSeqFeatures = viewport.isShowSequenceFeatures();
725   
726    }
727   
 
728  2 toggle @Override
729    public boolean isShowSeqFeatures()
730    {
731  2 return showSeqFeatures;
732    }
733   
 
734  6 toggle public void setShowSeqFeatures(boolean showSeqFeatures)
735    {
736  6 this.showSeqFeatures = showSeqFeatures;
737    }
738   
 
739  0 toggle public Vector<AlignmentAnnotation> getAnnotations()
740    {
741  0 return annotations;
742    }
743   
 
744  3 toggle @Override
745    public HiddenColumns getHiddenColumns()
746    {
747  3 return hiddenColumns;
748    }
749   
 
750  0 toggle public void setHiddenColumns(HiddenColumns hidden)
751    {
752  0 this.hiddenColumns = hidden;
753    }
754   
 
755  4 toggle @Override
756    public SequenceI[] getHiddenSequences()
757    {
758  4 if (hiddenSequences == null || hiddenSequences.isEmpty())
759    {
760  1 return new SequenceI[] {};
761    }
762  3 synchronized (hiddenSequences)
763    {
764  3 return hiddenSequences.toArray(new SequenceI[hiddenSequences.size()]);
765    }
766    }
767   
 
768  0 toggle public void setHiddenSequences(ArrayList<SequenceI> hiddenSequences)
769    {
770  0 this.hiddenSequences = hiddenSequences;
771    }
772   
 
773    public class JSONExportSettings
774    {
775    private boolean exportSequence;
776   
777    private boolean exportSequenceFeatures;
778   
779    private boolean exportAnnotations;
780   
781    private boolean exportGroups;
782   
783    private boolean exportJalviewSettings;
784   
 
785  0 toggle public boolean isExportSequence()
786    {
787  0 return exportSequence;
788    }
789   
 
790  0 toggle public void setExportSequence(boolean exportSequence)
791    {
792  0 this.exportSequence = exportSequence;
793    }
794   
 
795  0 toggle public boolean isExportSequenceFeatures()
796    {
797  0 return exportSequenceFeatures;
798    }
799   
 
800  0 toggle public void setExportSequenceFeatures(boolean exportSequenceFeatures)
801    {
802  0 this.exportSequenceFeatures = exportSequenceFeatures;
803    }
804   
 
805  0 toggle public boolean isExportAnnotations()
806    {
807  0 return exportAnnotations;
808    }
809   
 
810  0 toggle public void setExportAnnotations(boolean exportAnnotations)
811    {
812  0 this.exportAnnotations = exportAnnotations;
813    }
814   
 
815  0 toggle public boolean isExportGroups()
816    {
817  0 return exportGroups;
818    }
819   
 
820  0 toggle public void setExportGroups(boolean exportGroups)
821    {
822  0 this.exportGroups = exportGroups;
823    }
824   
 
825  0 toggle public boolean isExportJalviewSettings()
826    {
827  0 return exportJalviewSettings;
828    }
829   
 
830  0 toggle public void setExportJalviewSettings(boolean exportJalviewSettings)
831    {
832  0 this.exportJalviewSettings = exportJalviewSettings;
833    }
834    }
835   
836    /**
837    * Returns a descriptor for suitable feature display settings with
838    * <ul>
839    * <li>ResNums or insertions features visible</li>
840    * <li>insertions features coloured red</li>
841    * <li>ResNum features coloured by label</li>
842    * <li>Insertions displayed above (on top of) ResNums</li>
843    * </ul>
844    */
 
845  0 toggle @Override
846    public FeatureSettingsModelI getFeatureColourScheme()
847    {
848  0 return new PDBFeatureSettings();
849    }
850    }