X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FJSONFile.java;h=27ebe5a538f5936e9ff58922b1e22dc8e9726ae5;hb=24680a271861e9309a2241c8884874656ac111b1;hp=6fe06eb9ed0472124bb9e97c3f3a83fb63c46436;hpb=dc1ad37588e94cbc9ebbfaab2e9e49407f464310;p=jalview.git diff --git a/src/jalview/io/JSONFile.java b/src/jalview/io/JSONFile.java index 6fe06eb..27ebe5a 100644 --- a/src/jalview/io/JSONFile.java +++ b/src/jalview/io/JSONFile.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9) - * Copyright (C) 2015 The Jalview Authors + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * @@ -26,6 +26,7 @@ import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; import jalview.api.ComplexAlignFile; import jalview.api.FeatureRenderer; +import jalview.api.FeatureSettingsModelI; import jalview.api.FeaturesDisplayedI; import jalview.bin.BuildDetails; import jalview.datamodel.AlignmentAnnotation; @@ -39,12 +40,15 @@ import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.json.binding.biojson.v1.AlignmentAnnotationPojo; import jalview.json.binding.biojson.v1.AlignmentPojo; +import jalview.json.binding.biojson.v1.AnnotationDisplaySettingPojo; import jalview.json.binding.biojson.v1.AnnotationPojo; import jalview.json.binding.biojson.v1.ColourSchemeMapper; import jalview.json.binding.biojson.v1.SequenceFeaturesPojo; import jalview.json.binding.biojson.v1.SequenceGrpPojo; import jalview.json.binding.biojson.v1.SequencePojo; -import jalview.schemes.ColourSchemeProperty; +import jalview.schemes.JalviewColourScheme; +import jalview.schemes.ResidueColourScheme; +import jalview.util.ColorUtils; import jalview.viewmodel.seqfeatures.FeaturesDisplayed; import java.awt.Color; @@ -68,10 +72,6 @@ public class JSONFile extends AlignFile implements ComplexAlignFile private String application = "Jalview"; - public static final String FILE_EXT = "json"; - - public static final String FILE_DESC = "JSON"; - private String globalColourScheme; private boolean showSeqFeatures; @@ -90,6 +90,8 @@ public class JSONFile extends AlignFile implements ComplexAlignFile private ArrayList hiddenSequences; + private final static String TCOFFEE_SCORE = "TCoffeeScore"; + public JSONFile() { super(); @@ -100,9 +102,10 @@ public class JSONFile extends AlignFile implements ComplexAlignFile super(source); } - public JSONFile(String inFile, String type) throws IOException + public JSONFile(String inFile, DataSourceType sourceType) + throws IOException { - super(inFile, type); + super(inFile, sourceType); } @Override @@ -113,7 +116,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile } @Override - public String print() + public String print(SequenceI[] sqs, boolean jvsuffix) { String jsonOutput = null; try @@ -166,7 +169,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile } int count = 0; - for (SequenceI seq : seqs) + for (SequenceI seq : sqs) { StringBuilder name = new StringBuilder(); name.append(seq.getName()).append("/").append(seq.getStart()) @@ -211,16 +214,22 @@ public class JSONFile extends AlignFile implements ComplexAlignFile } else { - if (globalColourScheme.equalsIgnoreCase("RNA Helices")) + // These color schemes require annotation, disable them if annotations + // are not exported + if (globalColourScheme + .equalsIgnoreCase(JalviewColourScheme.RNAHelices.toString()) + || globalColourScheme + .equalsIgnoreCase(JalviewColourScheme.TCoffee + .toString())) { - jsonAlignmentPojo.setGlobalColorScheme("None"); + jsonAlignmentPojo.setGlobalColorScheme(ResidueColourScheme.NONE); } } if (exportSettings.isExportFeatures()) { jsonAlignmentPojo - .setSeqFeatures(sequenceFeatureToJsonPojo(seqs, fr)); + .setSeqFeatures(sequenceFeatureToJsonPojo(sqs, fr)); } if (exportSettings.isExportGroups() && seqGroups != null @@ -230,8 +239,8 @@ public class JSONFile extends AlignFile implements ComplexAlignFile { SequenceGrpPojo seqGrpPojo = new SequenceGrpPojo(); seqGrpPojo.setGroupName(seqGrp.getName()); - seqGrpPojo.setColourScheme(ColourSchemeProperty - .getColourName(seqGrp.cs)); + seqGrpPojo.setColourScheme(seqGrp.getColourScheme() + .getSchemeName()); seqGrpPojo.setColourText(seqGrp.getColourText()); seqGrpPojo.setDescription(seqGrp.getDescription()); seqGrpPojo.setDisplayBoxes(seqGrp.getDisplayBoxes()); @@ -310,11 +319,16 @@ public class JSONFile extends AlignFile implements ComplexAlignFile } public List sequenceFeatureToJsonPojo( - List seqs, FeatureRenderer fr) + SequenceI[] sqs, FeatureRenderer fr) { displayedFeatures = (fr == null) ? null : fr.getFeaturesDisplayed(); List sequenceFeaturesPojo = new ArrayList(); - for (SequenceI seq : seqs) + if (sqs == null) + { + return sequenceFeaturesPojo; + } + + for (SequenceI seq : sqs) { SequenceI dataSetSequence = seq.getDatasetSequence(); SequenceFeature[] seqFeatures = (dataSetSequence == null) ? null @@ -367,6 +381,26 @@ public class JSONFile extends AlignFile implements ComplexAlignFile AlignmentAnnotationPojo alignAnnotPojo = new AlignmentAnnotationPojo(); alignAnnotPojo.setDescription(annot.description); alignAnnotPojo.setLabel(annot.label); + if (!Double.isNaN(annot.score)) + { + alignAnnotPojo.setScore(annot.score); + } + alignAnnotPojo.setCalcId(annot.getCalcId()); + alignAnnotPojo.setGraphType(annot.graph); + + AnnotationDisplaySettingPojo annotSetting = new AnnotationDisplaySettingPojo(); + annotSetting.setBelowAlignment(annot.belowAlignment); + annotSetting.setCentreColLabels(annot.centreColLabels); + annotSetting.setScaleColLabel(annot.scaleColLabel); + annotSetting.setShowAllColLabels(annot.showAllColLabels); + annotSetting.setVisible(annot.visible); + annotSetting.setHasIcon(annot.hasIcons); + alignAnnotPojo.setAnnotationSettings(annotSetting); + SequenceI refSeq = annot.sequenceRef; + if (refSeq != null) + { + alignAnnotPojo.setSequenceRef(String.valueOf(refSeq.hashCode())); + } for (Annotation annotation : annot.annotations) { AnnotationPojo annotationPojo = new AnnotationPojo(); @@ -376,12 +410,28 @@ public class JSONFile extends AlignFile implements ComplexAlignFile annotationPojo.setValue(annotation.value); annotationPojo .setSecondaryStructure(annotation.secondaryStructure); - annotationPojo.setDisplayCharacter(annotation.displayCharacter); + String displayChar = annotation.displayCharacter == null ? null + : annotation.displayCharacter; + // System.out.println("--------------------->[" + displayChar + "]"); + annotationPojo.setDisplayCharacter(displayChar); + if (annotation.colour != null) + { + annotationPojo.setColour(jalview.util.Format + .getHexString(annotation.colour)); + } alignAnnotPojo.getAnnotations().add(annotationPojo); } else { - alignAnnotPojo.getAnnotations().add(annotationPojo); + if (annot.getCalcId() != null + && annot.getCalcId().equalsIgnoreCase(TCOFFEE_SCORE)) + { + // do nothing + } + else + { + alignAnnotPojo.getAnnotations().add(annotationPojo); + } } } jsonAnnotations.add(alignAnnotPojo); @@ -439,7 +489,6 @@ public class JSONFile extends AlignFile implements ComplexAlignFile seqMap.put(seqUniqueId, seq); } - parseFeatures(jsonSeqArray); for (Iterator seqGrpIter = seqGrpJsonArray.iterator(); seqGrpIter @@ -478,10 +527,9 @@ public class JSONFile extends AlignFile implements ComplexAlignFile } } SequenceGroup seqGrp = new SequenceGroup(grpSeqs, grpName, null, - displayBoxes, displayText, colourText, - startRes, endRes); - seqGrp.cs = ColourSchemeMapper.getJalviewColourScheme(colourScheme, - seqGrp); + displayBoxes, displayText, colourText, startRes, endRes); + seqGrp.setColourScheme(ColourSchemeMapper.getJalviewColourScheme( + colourScheme, seqGrp)); seqGrp.setShowNonconserved(showNonconserved); seqGrp.setDescription(description); this.seqGroups.add(seqGrp); @@ -517,6 +565,12 @@ public class JSONFile extends AlignFile implements ComplexAlignFile : annot.get("displayCharacter").toString(); annotations[count] = new Annotation(displayChar, desc, ss, val); + if (annot.get("colour") != null) + { + Color color = ColorUtils.parseColourString(annot.get( + "colour").toString()); + annotations[count].colour = color; + } } ++count; } @@ -524,7 +578,64 @@ public class JSONFile extends AlignFile implements ComplexAlignFile AlignmentAnnotation alignAnnot = new AlignmentAnnotation(alAnnot .get("label").toString(), alAnnot.get("description") .toString(), annotations); + alignAnnot.graph = (alAnnot.get("graphType") == null) ? 0 : Integer + .valueOf(alAnnot.get("graphType").toString()); + + JSONObject diplaySettings = (JSONObject) alAnnot + .get("annotationSettings"); + if (diplaySettings != null) + { + + alignAnnot.scaleColLabel = (diplaySettings.get("scaleColLabel") == null) ? false + : Boolean.valueOf(diplaySettings.get("scaleColLabel") + .toString()); + alignAnnot.showAllColLabels = (diplaySettings + .get("showAllColLabels") == null) ? true : Boolean + .valueOf(diplaySettings.get("showAllColLabels") + .toString()); + alignAnnot.centreColLabels = (diplaySettings + .get("centreColLabels") == null) ? true + : Boolean.valueOf(diplaySettings.get("centreColLabels") + .toString()); + alignAnnot.belowAlignment = (diplaySettings.get("belowAlignment") == null) ? false + : Boolean.valueOf(diplaySettings.get("belowAlignment") + .toString()); + alignAnnot.visible = (diplaySettings.get("visible") == null) ? true + : Boolean.valueOf(diplaySettings.get("visible") + .toString()); + alignAnnot.hasIcons = (diplaySettings.get("hasIcon") == null) ? true + : Boolean.valueOf(diplaySettings.get("hasIcon") + .toString()); + + } + if (alAnnot.get("score") != null) + { + alignAnnot.score = Double + .valueOf(alAnnot.get("score").toString()); + } + + String calcId = (alAnnot.get("calcId") == null) ? "" : alAnnot.get( + "calcId").toString(); + alignAnnot.setCalcId(calcId); + String seqHash = (alAnnot.get("sequenceRef") != null) ? alAnnot + .get("sequenceRef").toString() : null; + + Sequence sequence = (seqHash != null) ? seqMap.get(seqHash) : null; + if (sequence != null) + { + alignAnnot.sequenceRef = sequence; + sequence.addAlignmentAnnotation(alignAnnot); + if (alignAnnot.label.equalsIgnoreCase("T-COFFEE")) + { + alignAnnot.createSequenceMapping(sequence, sequence.getStart(), + false); + sequence.addAlignmentAnnotation(alignAnnot); + alignAnnot.adjustForAlignment(); + } + } + alignAnnot.validateRangeAndDisplay(); this.annotations.add(alignAnnot); + } } catch (Exception e) { @@ -605,6 +716,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile } } + @Override public String getGlobalColourScheme() { return globalColourScheme; @@ -626,8 +738,13 @@ public class JSONFile extends AlignFile implements ComplexAlignFile this.displayedFeatures = displayedFeatures; } + @Override public void configureForView(AlignmentViewPanel avpanel) { + if (avpanel == null) + { + return; + } super.configureForView(avpanel); AlignViewportI viewport = avpanel.getAlignViewport(); AlignmentI alignment = viewport.getAlignment(); @@ -637,24 +754,23 @@ public class JSONFile extends AlignFile implements ComplexAlignFile fr = avpanel.cloneFeatureRenderer(); // Add non auto calculated annotation to AlignFile - for (AlignmentAnnotation annot : annots) + if (annots != null) { - if (annot != null && !annot.autoCalculated) + for (AlignmentAnnotation annot : annots) { - if (!annot.visible) + if (annot != null && !annot.autoCalculated) { - continue; + annotations.add(annot); } - annotations.add(annot); } } - globalColourScheme = ColourSchemeProperty.getColourName(viewport - .getGlobalColourScheme()); + globalColourScheme = viewport.getGlobalColourScheme().getSchemeName(); setDisplayedFeatures(viewport.getFeaturesDisplayed()); showSeqFeatures = viewport.isShowSequenceFeatures(); } + @Override public boolean isShowSeqFeatures() { return showSeqFeatures; @@ -675,6 +791,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile return hiddenColumns; } + @Override public ColumnSelection getColumnSelection() { return columnSelection; @@ -685,6 +802,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile this.columnSelection = columnSelection; } + @Override public SequenceI[] getHiddenSequences() { if (hiddenSequences == null || hiddenSequences.isEmpty()) @@ -764,4 +882,19 @@ public class JSONFile extends AlignFile implements ComplexAlignFile this.exportJalviewSettings = exportJalviewSettings; } } + + /** + * Returns a descriptor for suitable feature display settings with + *
    + *
  • ResNums or insertions features visible
  • + *
  • insertions features coloured red
  • + *
  • ResNum features coloured by label
  • + *
  • Insertions displayed above (on top of) ResNums
  • + *
+ */ + @Override + public FeatureSettingsModelI getFeatureColourScheme() + { + return new PDBFeatureSettings(); + } }