X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FJSONFile.java;h=9402562897a29f2b82022ccff009204041dd8cd3;hb=838e4f91d4a53dd315640dbc9ff6ef7a815ee576;hp=8c790cc7ac520859164b0e208fa6a3f07bbc578c;hpb=c7d9dbc9b92889077b91bcdb052032fe33fb269e;p=jalview.git diff --git a/src/jalview/io/JSONFile.java b/src/jalview/io/JSONFile.java index 8c790cc..9402562 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-Rel$$) - * Copyright (C) $$Year-Rel$$ The Jalview Authors + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9.0b1) + * Copyright (C) 2015 The Jalview Authors * * This file is part of Jalview. * @@ -39,13 +39,14 @@ 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.JalviewBioJsColorSchemeMapper; +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.ColourSchemeI; import jalview.schemes.ColourSchemeProperty; +import jalview.schemes.UserColourScheme; import jalview.viewmodel.seqfeatures.FeaturesDisplayed; import java.awt.Color; @@ -63,8 +64,6 @@ import org.json.simple.parser.JSONParser; public class JSONFile extends AlignFile implements ComplexAlignFile { - private ColourSchemeI colourScheme; - private static String version = new BuildDetails().getVersion(); private String webstartUrl = "http://www.jalview.org/services/launchApp"; @@ -75,7 +74,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile public static final String FILE_DESC = "JSON"; - private String globalColorScheme; + private String globalColourScheme; private boolean showSeqFeatures; @@ -93,6 +92,8 @@ public class JSONFile extends AlignFile implements ComplexAlignFile private ArrayList hiddenSequences; + private final static String TCOFFEE_SCORE = "TCoffeeScore"; + public JSONFile() { super(); @@ -159,6 +160,12 @@ public class JSONFile extends AlignFile implements ComplexAlignFile { return true; } + + @Override + public boolean isCancelled() + { + return false; + } }; } @@ -177,7 +184,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile jsonSeqPojo.setSeq(seq.getSequenceAsString()); jsonAlignmentPojo.getSeqs().add(jsonSeqPojo); } - jsonAlignmentPojo.setGlobalColorScheme(globalColorScheme); + jsonAlignmentPojo.setGlobalColorScheme(globalColourScheme); jsonAlignmentPojo.getAppSettings().put("application", application); jsonAlignmentPojo.getAppSettings().put("version", version); jsonAlignmentPojo.getAppSettings().put("webStartUrl", webstartUrl); @@ -206,6 +213,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()) { @@ -357,6 +374,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(); @@ -366,12 +403,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); @@ -399,11 +452,10 @@ public class JSONFile extends AlignFile implements ComplexAlignFile if (jvSettingsJsonObj != null) { - String jsColourScheme = (String) jvSettingsJsonObj + globalColourScheme = (String) jvSettingsJsonObj .get("globalColorScheme"); Boolean showFeatures = Boolean.valueOf(jvSettingsJsonObj.get( "showSeqFeatures").toString()); - setColourScheme(getJalviewColorScheme(jsColourScheme)); setShowSeqFeatures(showFeatures); parseHiddenSeqRefsAsList(jvSettingsJsonObj); parseHiddenCols(jvSettingsJsonObj); @@ -429,6 +481,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile seqs.add(seq); seqMap.put(seqUniqueId, seq); } + parseFeatures(jsonSeqArray); for (Iterator seqGrpIter = seqGrpJsonArray.iterator(); seqGrpIter @@ -466,10 +519,10 @@ public class JSONFile extends AlignFile implements ComplexAlignFile } } } - ColourSchemeI grpColourScheme = getJalviewColorScheme(colourScheme); - SequenceGroup seqGrp = new SequenceGroup(grpSeqs, grpName, - grpColourScheme, displayBoxes, displayText, colourText, - startRes, endRes); + SequenceGroup seqGrp = new SequenceGroup(grpSeqs, grpName, null, + displayBoxes, displayText, colourText, startRes, endRes); + seqGrp.cs = ColourSchemeMapper.getJalviewColourScheme(colourScheme, + seqGrp); seqGrp.setShowNonconserved(showNonconserved); seqGrp.setDescription(description); this.seqGroups.add(seqGrp); @@ -497,13 +550,20 @@ public class JSONFile extends AlignFile implements ComplexAlignFile .valueOf(annot.get("value").toString()); String desc = annot.get("description") == null ? null : annot .get("description").toString(); - - char ss = annot.get("secondaryStructure") == null ? ' ' : annot + char ss = annot.get("secondaryStructure") == null + || annot.get("secondaryStructure").toString() + .equalsIgnoreCase("u0000") ? ' ' : annot .get("secondaryStructure").toString().charAt(0); String displayChar = annot.get("displayCharacter") == null ? "" : 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; } @@ -511,9 +571,65 @@ 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) { e.printStackTrace(); @@ -593,40 +709,14 @@ public class JSONFile extends AlignFile implements ComplexAlignFile } } - public static ColourSchemeI getJalviewColorScheme( - String bioJsColourSchemeName) - { - ColourSchemeI jalviewColor = null; - for (JalviewBioJsColorSchemeMapper cs : JalviewBioJsColorSchemeMapper - .values()) - { - if (cs.getBioJsName().equalsIgnoreCase(bioJsColourSchemeName)) - { - jalviewColor = cs.getJvColourScheme(); - break; - } - } - return jalviewColor; - } - - public String getGlobalColorScheme() - { - return globalColorScheme; - } - - public void setGlobalColorScheme(String globalColorScheme) + public String getGlobalColourScheme() { - this.globalColorScheme = globalColorScheme; + return globalColourScheme; } - public ColourSchemeI getColourScheme() + public void setGlobalColorScheme(String globalColourScheme) { - return colourScheme; - } - - public void setColourScheme(ColourSchemeI colourScheme) - { - this.colourScheme = colourScheme; + this.globalColourScheme = globalColourScheme; } @Override @@ -655,14 +745,10 @@ public class JSONFile extends AlignFile implements ComplexAlignFile { if (annot != null && !annot.autoCalculated) { - if (!annot.visible) - { - continue; - } annotations.add(annot); } } - globalColorScheme = ColourSchemeProperty.getColourName(viewport + globalColourScheme = ColourSchemeProperty.getColourName(viewport .getGlobalColourScheme()); setDisplayedFeatures(viewport.getFeaturesDisplayed()); showSeqFeatures = viewport.isShowSequenceFeatures();