Clover icon

Coverage Report

  1. Project Clover database Wed Nov 13 2024 18:27:33 GMT
  2. Package jalview.io

File JSONFile.java

 

Coverage histogram

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

Code metrics

138
308
35
2
864
723
120
0.39
8.8
17.5
3.43

Classes

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