X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fio%2FJSONFile.java;h=94e498d9465f402342e91495af5270ddbf85fc45;hb=refs%2Fheads%2Ffeatures%2FJAL-2094_colourInterface;hp=87255560200c77d24de557dce5fcf22ceaa8fec7;hpb=4513bd826c54623c14aa8946a51a2382f64e98f3;p=jalview.git diff --git a/src/jalview/io/JSONFile.java b/src/jalview/io/JSONFile.java index 8725556..94e498d 100644 --- a/src/jalview/io/JSONFile.java +++ b/src/jalview/io/JSONFile.java @@ -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.Colour; import jalview.schemes.ColourSchemeProperty; +import jalview.schemes.UserColourScheme; import jalview.viewmodel.seqfeatures.FeaturesDisplayed; import java.awt.Color; @@ -90,6 +94,8 @@ public class JSONFile extends AlignFile implements ComplexAlignFile private ArrayList hiddenSequences; + private final static String TCOFFEE_SCORE = "TCoffeeScore"; + public JSONFile() { super(); @@ -209,6 +215,16 @@ public class JSONFile extends AlignFile implements ComplexAlignFile jsonAlignmentPojo .setAlignAnnotation(annotationToJsonPojo(annotations)); } + else + { + // These color schemes require annotation, disable them if annotations + // are not exported + if (globalColourScheme.equalsIgnoreCase("RNA Helices") + || globalColourScheme.equalsIgnoreCase("T-COFFEE SCORES")) + { + jsonAlignmentPojo.setGlobalColorScheme("None"); + } + } if (exportSettings.isExportFeatures()) { @@ -329,7 +345,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile String.valueOf(seq.hashCode())); String featureColour = (fr == null) ? null : jalview.util.Format - .getHexString(fr.findFeatureColour(Color.white, seq, + .getHexString(fr.findFeatureColour(Colour.white, seq, seq.findIndex(sf.getBegin()))); jsonFeature.setXstart(seq.findIndex(sf.getBegin()) - 1); jsonFeature.setXend(seq.findIndex(sf.getEnd())); @@ -360,6 +376,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(); @@ -369,12 +405,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); @@ -432,7 +484,6 @@ public class JSONFile extends AlignFile implements ComplexAlignFile seqMap.put(seqUniqueId, seq); } - parseFeatures(jsonSeqArray); for (Iterator seqGrpIter = seqGrpJsonArray.iterator(); seqGrpIter @@ -471,8 +522,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile } } SequenceGroup seqGrp = new SequenceGroup(grpSeqs, grpName, null, - displayBoxes, displayText, colourText, - startRes, endRes); + displayBoxes, displayText, colourText, startRes, endRes); seqGrp.cs = ColourSchemeMapper.getJalviewColourScheme(colourScheme, seqGrp); seqGrp.setShowNonconserved(showNonconserved); @@ -510,6 +560,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 = UserColourScheme.getColourFromString(annot.get( + "colour").toString()); + annotations[count].colour = color; + } } ++count; } @@ -517,7 +573,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) { @@ -598,6 +711,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile } } + @Override public String getGlobalColourScheme() { return globalColourScheme; @@ -619,8 +733,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(); @@ -630,15 +749,14 @@ 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 @@ -648,6 +766,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile } + @Override public boolean isShowSeqFeatures() { return showSeqFeatures; @@ -668,6 +787,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile return hiddenColumns; } + @Override public ColumnSelection getColumnSelection() { return columnSelection; @@ -678,6 +798,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile this.columnSelection = columnSelection; } + @Override public SequenceI[] getHiddenSequences() { if (hiddenSequences == null || hiddenSequences.isEmpty()) @@ -757,4 +878,19 @@ public class JSONFile extends AlignFile implements ComplexAlignFile this.exportJalviewSettings = exportJalviewSettings; } } + + /** + * Returns a descriptor for suitable feature display settings with + * + */ + @Override + public FeatureSettingsModelI getFeatureColourScheme() + { + return new PDBFeatureSettings(); + } }