X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FJSONFile.java;h=5d9c80414aabe4bcb03595edda377c0da04a268a;hb=3d0101179759ef157b088ea135423cd909512d9f;hp=e38812c6d9e294206a0fbf2ff34369d5f3edbb16;hpb=7431a6e01992d55b94a0b4113e19ef65932ca723;p=jalview.git diff --git a/src/jalview/io/JSONFile.java b/src/jalview/io/JSONFile.java index e38812c..5d9c804 100644 --- a/src/jalview/io/JSONFile.java +++ b/src/jalview/io/JSONFile.java @@ -1,27 +1,61 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ + package jalview.io; +import jalview.api.AlignExportSettingI; +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; +import jalview.datamodel.AlignmentI; import jalview.datamodel.Annotation; +import jalview.datamodel.HiddenColumns; +import jalview.datamodel.HiddenSequences; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; -import jalview.gui.AlignFrame; -import jalview.gui.Desktop; -import jalview.json.binding.v1.AlignmentAnnotationPojo; -import jalview.json.binding.v1.AlignmentPojo; -import jalview.json.binding.v1.AnnotationPojo; -import jalview.json.binding.v1.JalviewSettingsPojo; -import jalview.json.binding.v1.JalviewSettingsPojo.JalviewBioJsColorSchemeMapper; -import jalview.json.binding.v1.SequenceFeaturesPojo; -import jalview.json.binding.v1.SequenceGrpPojo; -import jalview.json.binding.v1.SequencePojo; -import jalview.schemes.ColourSchemeI; +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.renderer.seqfeatures.FeatureColourFinder; import jalview.schemes.ColourSchemeProperty; -import jalview.viewmodel.AlignmentViewport; +import jalview.schemes.JalviewColourScheme; +import jalview.schemes.ResidueColourScheme; +import jalview.util.ColorUtils; +import jalview.viewmodel.seqfeatures.FeaturesDisplayed; +import java.awt.Color; import java.io.IOException; +import java.io.Reader; import java.util.ArrayList; import java.util.Hashtable; import java.util.Iterator; @@ -32,21 +66,15 @@ import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; -public class JSONFile extends AlignFile +public class JSONFile extends AlignFile implements ComplexAlignFile { - private static ColourSchemeI colourScheme; - - private static boolean seqFeaturesEnabled; - - private String jalviewVersion; + private static String version = new BuildDetails().getVersion(); - private String webStartLaunchServletUrl = "http://www.jalview.org/services/launchApp"; + private String webstartUrl = "http://www.jalview.org/services/launchApp"; - public static final String FILE_EXT = "json"; + private String application = "Jalview"; - public static final String FILE_DESC = "JSON"; - - private String globalColorScheme; + private String globalColourScheme; private boolean showSeqFeatures; @@ -54,9 +82,15 @@ public class JSONFile extends AlignFile private FeaturesDisplayedI displayedFeatures; - private AlignmentViewport av; + private FeatureRenderer fr; + + private HiddenColumns hiddenColumns; - private JSONExportSettings jsonExportSettings; + private List hiddenSeqRefs; + + private ArrayList hiddenSequences; + + private final static String TCOFFEE_SCORE = "TCoffeeScore"; public JSONFile() { @@ -68,58 +102,80 @@ public class JSONFile extends AlignFile 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 public void parse() throws IOException { - StringBuilder jsonStringBuilder = new StringBuilder(); - String currentLine; - while ((currentLine = nextLine()) != null) - { - jsonStringBuilder.append(currentLine); - } - parse(jsonStringBuilder.toString()); + parse(getReader()); } @Override - public String print() + public String print(SequenceI[] sqs, boolean jvsuffix) { + String jsonOutput = null; try { - if (getJsonExportSettings() == null) - { - jsonExportSettings = new JSONExportSettings(); - jsonExportSettings.setExportAnnotations(true); - jsonExportSettings.setExportGroups(true); - jsonExportSettings.setExportJalviewSettings(true); - jsonExportSettings.setExportSequenceFeatures(true); - } - AlignmentPojo jsonAlignmentPojo = new AlignmentPojo(); - if (Desktop.getCurrentAlignFrame() != null) + AlignExportSettingI exportSettings = getExportSettings(); + + // if no export settings were supplied use the following with all values + // defaulting to true + if (exportSettings == null) { - globalColorScheme = ColourSchemeProperty.getColourName(Desktop - .getCurrentAlignFrame().getViewport() - .getGlobalColourScheme()); - this.av = Desktop.getCurrentAlignFrame().getCurrentView(); - setDisplayedFeatures(av.getFeaturesDisplayed()); - showSeqFeatures = Desktop.getCurrentAlignFrame().showSeqFeatures - .isSelected(); + exportSettings = new AlignExportSettingI() + { + @Override + public boolean isExportHiddenSequences() + { + return true; + } + + @Override + public boolean isExportHiddenColumns() + { + return true; + } + + @Override + public boolean isExportGroups() + { + return true; + } + + @Override + public boolean isExportFeatures() + { + return true; + } + + @Override + public boolean isExportAnnotations() + { + return true; + } + + @Override + public boolean isCancelled() + { + return false; + } + }; } int count = 0; - for (SequenceI seq : seqs) + for (SequenceI seq : sqs) { StringBuilder name = new StringBuilder(); name.append(seq.getName()).append("/").append(seq.getStart()) .append("-").append(seq.getEnd()); SequencePojo jsonSeqPojo = new SequencePojo(); - jsonSeqPojo.setId(seq.getName() + "_" + seq.hashCode()); + jsonSeqPojo.setId(String.valueOf(seq.hashCode())); jsonSeqPojo.setOrder(++count); jsonSeqPojo.setEnd(seq.getEnd()); jsonSeqPojo.setStart(seq.getStart()); @@ -127,30 +183,55 @@ public class JSONFile extends AlignFile jsonSeqPojo.setSeq(seq.getSequenceAsString()); jsonAlignmentPojo.getSeqs().add(jsonSeqPojo); } - - if (jsonExportSettings.isExportJalviewSettings()) + jsonAlignmentPojo.setGlobalColorScheme(globalColourScheme); + jsonAlignmentPojo.getAppSettings().put("application", application); + jsonAlignmentPojo.getAppSettings().put("version", version); + jsonAlignmentPojo.getAppSettings().put("webStartUrl", webstartUrl); + jsonAlignmentPojo.getAppSettings().put("showSeqFeatures", + String.valueOf(showSeqFeatures)); + + String[] hiddenSections = getHiddenSections(); + if (hiddenSections != null) { - JalviewSettingsPojo jvSettings = new JalviewSettingsPojo(); - jvSettings.setGlobalColorScheme(globalColorScheme); - jvSettings.setJalviewVersion(jalviewVersion); - jvSettings.setWebStartUrl(webStartLaunchServletUrl); - jvSettings.setShowSeqFeatures(showSeqFeatures); - jsonAlignmentPojo.setJalviewSettings(jvSettings); + if (hiddenSections[0] != null + && exportSettings.isExportHiddenColumns()) + { + jsonAlignmentPojo.getAppSettings().put("hiddenCols", + String.valueOf(hiddenSections[0])); + } + if (hiddenSections[1] != null + && exportSettings.isExportHiddenSequences()) + { + jsonAlignmentPojo.getAppSettings().put("hiddenSeqs", + String.valueOf(hiddenSections[1])); + } } - if (jsonExportSettings.isExportAnnotations()) + if (exportSettings.isExportAnnotations()) { jsonAlignmentPojo .setAlignAnnotation(annotationToJsonPojo(annotations)); } + else + { + // 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(ResidueColourScheme.NONE); + } + } - if (jsonExportSettings.isExportSequenceFeatures()) + if (exportSettings.isExportFeatures()) { - jsonAlignmentPojo.setSeqFeatures(sequenceFeatureToJsonPojo(seqs, - getDisplayedFeatures())); + jsonAlignmentPojo + .setSeqFeatures(sequenceFeatureToJsonPojo(sqs, fr)); } - if (jsonExportSettings.isExportGroups() && seqGroups != null + if (exportSettings.isExportGroups() && seqGroups != null && seqGroups.size() > 0) { for (SequenceGroup seqGrp : seqGroups) @@ -158,7 +239,7 @@ public class JSONFile extends AlignFile SequenceGrpPojo seqGrpPojo = new SequenceGrpPojo(); seqGrpPojo.setGroupName(seqGrp.getName()); seqGrpPojo.setColourScheme(ColourSchemeProperty - .getColourName(seqGrp.cs)); + .getColourName(seqGrp.getColourScheme())); seqGrpPojo.setColourText(seqGrp.getColourText()); seqGrpPojo.setDescription(seqGrp.getDescription()); seqGrpPojo.setDisplayBoxes(seqGrp.getDisplayBoxes()); @@ -168,34 +249,85 @@ public class JSONFile extends AlignFile seqGrpPojo.setShowNonconserved(seqGrp.getShowNonconserved()); for (SequenceI seq : seqGrp.getSequences()) { - seqGrpPojo.getSeqsHash().add( - seq.getName() + "_" + seq.hashCode()); + seqGrpPojo.getSequenceRefs() + .add(String.valueOf(seq.hashCode())); } jsonAlignmentPojo.getSeqGroups().add(seqGrpPojo); } } - com.json.JSONObject generatedJSon = new com.json.JSONObject( + org.json.JSONObject generatedJSon = new org.json.JSONObject( jsonAlignmentPojo); - String jsonOutput = generatedJSon.toString(); + jsonOutput = generatedJSon.toString(); return jsonOutput.replaceAll("xstart", "xStart").replaceAll("xend", "xEnd"); } catch (Exception e) { e.printStackTrace(); - throw e; } + return jsonOutput; } - public static List sequenceFeatureToJsonPojo( - List seqs, FeaturesDisplayedI displayedFeatures) + public String[] getHiddenSections() { - List sequenceFeaturesPojo = new ArrayList(); - for (SequenceI seq : seqs) + String[] hiddenSections = new String[2]; + if (getViewport() == null) + { + return null; + } + + // hidden column business + if (getViewport().hasHiddenColumns()) + { + hiddenSections[0] = getViewport().getAlignment().getHiddenColumns() + .regionsToString(";", "-"); + } + + // hidden rows/seqs business + HiddenSequences hiddenSeqsObj = getViewport().getAlignment() + .getHiddenSequences(); + if (hiddenSeqsObj == null || hiddenSeqsObj.hiddenSequences == null) + { + return hiddenSections; + } + + SequenceI[] hiddenSeqs = hiddenSeqsObj.hiddenSequences; + StringBuilder hiddenSeqsBuilder = new StringBuilder(); + for (SequenceI hiddenSeq : hiddenSeqs) + { + if (hiddenSeq != null) + { + hiddenSeqsBuilder.append(";").append(hiddenSeq.hashCode()); + } + } + if (hiddenSeqsBuilder.length() > 0) + { + hiddenSeqsBuilder.deleteCharAt(0); + } + hiddenSections[1] = hiddenSeqsBuilder.toString(); + + return hiddenSections; + } + + public List sequenceFeatureToJsonPojo( + SequenceI[] sqs, FeatureRenderer fr) + { + displayedFeatures = (fr == null) ? null : fr.getFeaturesDisplayed(); + List sequenceFeaturesPojo = new ArrayList<>(); + if (sqs == null) + { + return sequenceFeaturesPojo; + } + + FeatureColourFinder finder = new FeatureColourFinder(fr); + + for (SequenceI seq : sqs) { SequenceI dataSetSequence = seq.getDatasetSequence(); SequenceFeature[] seqFeatures = (dataSetSequence == null) ? null : seq.getDatasetSequence().getSequenceFeatures(); + seqFeatures = (seqFeatures == null) ? seq.getSequenceFeatures() + : seqFeatures; if (seqFeatures == null) { continue; @@ -207,7 +339,12 @@ public class JSONFile extends AlignFile && displayedFeatures.isVisible(sf.getType())) { SequenceFeaturesPojo jsonFeature = new SequenceFeaturesPojo( - seq.getName() + "_" + seq.hashCode()); + String.valueOf(seq.hashCode())); + + String featureColour = (fr == null) ? null + : jalview.util.Format.getHexString( + finder.findFeatureColour(Color.white, seq, + seq.findIndex(sf.getBegin()))); jsonFeature.setXstart(seq.findIndex(sf.getBegin()) - 1); jsonFeature.setXend(seq.findIndex(sf.getEnd())); jsonFeature.setType(sf.getType()); @@ -215,6 +352,7 @@ public class JSONFile extends AlignFile jsonFeature.setLinks(sf.links); jsonFeature.setOtherDetails(sf.otherDetails); jsonFeature.setScore(sf.getScore()); + jsonFeature.setFillColor(featureColour); jsonFeature.setFeatureGroup(sf.getFeatureGroup()); sequenceFeaturesPojo.add(jsonFeature); } @@ -226,7 +364,7 @@ public class JSONFile extends AlignFile public static List annotationToJsonPojo( Vector annotations) { - List jsonAnnotations = new ArrayList(); + List jsonAnnotations = new ArrayList<>(); if (annotations == null) { return jsonAnnotations; @@ -236,6 +374,26 @@ public class JSONFile extends AlignFile 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(); @@ -245,12 +403,28 @@ public class JSONFile extends AlignFile 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); @@ -259,7 +433,7 @@ public class JSONFile extends AlignFile } @SuppressWarnings("unchecked") - public JSONFile parse(String jsonAlignmentString) + public JSONFile parse(Reader jsonAlignmentString) { try { @@ -274,21 +448,23 @@ public class JSONFile extends AlignFile JSONArray seqGrpJsonArray = (JSONArray) alignmentJsonObj .get("seqGroups"); JSONObject jvSettingsJsonObj = (JSONObject) alignmentJsonObj - .get("jalviewSettings"); + .get("appSettings"); if (jvSettingsJsonObj != null) { - String jsColourScheme = (String) jvSettingsJsonObj + globalColourScheme = (String) jvSettingsJsonObj .get("globalColorScheme"); - Boolean showFeatures = Boolean.valueOf(jvSettingsJsonObj.get( - "showSeqFeatures").toString()); - setColourScheme(getJalviewColorScheme(jsColourScheme)); - JSONFile.setSeqFeaturesEnabled(showFeatures); + Boolean showFeatures = Boolean.valueOf( + jvSettingsJsonObj.get("showSeqFeatures").toString()); + setShowSeqFeatures(showFeatures); + parseHiddenSeqRefsAsList(jvSettingsJsonObj); + parseHiddenCols(jvSettingsJsonObj); } - seqMap = new Hashtable(); - for (Iterator sequenceIter = seqJsonArray.iterator(); sequenceIter - .hasNext();) + hiddenSequences = new ArrayList<>(); + seqMap = new Hashtable<>(); + for (Iterator sequenceIter = seqJsonArray + .iterator(); sequenceIter.hasNext();) { JSONObject sequence = sequenceIter.next(); String sequcenceString = sequence.get("seq").toString(); @@ -298,36 +474,41 @@ public class JSONFile extends AlignFile int end = Integer.valueOf(sequence.get("end").toString()); Sequence seq = new Sequence(sequenceName, sequcenceString, start, end); + if (hiddenSeqRefs != null && hiddenSeqRefs.contains(seqUniqueId)) + { + hiddenSequences.add(seq); + } seqs.add(seq); seqMap.put(seqUniqueId, seq); } + parseFeatures(jsonSeqArray); - for (Iterator seqGrpIter = seqGrpJsonArray.iterator(); seqGrpIter - .hasNext();) + for (Iterator seqGrpIter = seqGrpJsonArray + .iterator(); seqGrpIter.hasNext();) { JSONObject seqGrpObj = seqGrpIter.next(); String grpName = seqGrpObj.get("groupName").toString(); String colourScheme = seqGrpObj.get("colourScheme").toString(); String description = (seqGrpObj.get("description") == null) ? null : seqGrpObj.get("description").toString(); - boolean displayBoxes = Boolean.valueOf(seqGrpObj - .get("displayBoxes").toString()); - boolean displayText = Boolean.valueOf(seqGrpObj.get("displayText") - .toString()); - boolean colourText = Boolean.valueOf(seqGrpObj.get("colourText") - .toString()); - boolean showNonconserved = Boolean.valueOf(seqGrpObj.get( - "showNonconserved").toString()); + boolean displayBoxes = Boolean + .valueOf(seqGrpObj.get("displayBoxes").toString()); + boolean displayText = Boolean + .valueOf(seqGrpObj.get("displayText").toString()); + boolean colourText = Boolean + .valueOf(seqGrpObj.get("colourText").toString()); + boolean showNonconserved = Boolean + .valueOf(seqGrpObj.get("showNonconserved").toString()); int startRes = Integer .valueOf(seqGrpObj.get("startRes").toString()); int endRes = Integer.valueOf(seqGrpObj.get("endRes").toString()); - JSONArray seqsHashArray = (JSONArray) seqGrpObj.get("seqsHash"); + JSONArray sequenceRefs = (JSONArray) seqGrpObj.get("sequenceRefs"); - ArrayList grpSeqs = new ArrayList(); - if (seqsHashArray.size() > 0) + ArrayList grpSeqs = new ArrayList<>(); + if (sequenceRefs.size() > 0) { - Iterator seqHashIter = seqsHashArray.iterator(); + Iterator seqHashIter = sequenceRefs.iterator(); while (seqHashIter.hasNext()) { String seqHash = seqHashIter.next(); @@ -338,24 +519,25 @@ public class JSONFile extends AlignFile } } } - ColourSchemeI scheme = getJalviewColorScheme(colourScheme); - SequenceGroup seqGrp = new SequenceGroup(grpSeqs, grpName, scheme, + SequenceGroup seqGrp = new SequenceGroup(grpSeqs, grpName, null, displayBoxes, displayText, colourText, startRes, endRes); + seqGrp.setColourScheme(ColourSchemeMapper + .getJalviewColourScheme(colourScheme, seqGrp)); seqGrp.setShowNonconserved(showNonconserved); seqGrp.setDescription(description); this.seqGroups.add(seqGrp); } - for (Iterator alAnnotIter = alAnnotJsonArray.iterator(); alAnnotIter - .hasNext();) + for (Iterator alAnnotIter = alAnnotJsonArray + .iterator(); alAnnotIter.hasNext();) { JSONObject alAnnot = alAnnotIter.next(); JSONArray annotJsonArray = (JSONArray) alAnnot.get("annotations"); Annotation[] annotations = new Annotation[annotJsonArray.size()]; int count = 0; - for (Iterator annotIter = annotJsonArray.iterator(); annotIter - .hasNext();) + for (Iterator annotIter = annotJsonArray + .iterator(); annotIter.hasNext();) { JSONObject annot = annotIter.next(); if (annot == null) @@ -364,26 +546,96 @@ public class JSONFile extends AlignFile } else { - float val = annot.get("value") == null ? null : Float - .valueOf(annot.get("value").toString()); - String desc = annot.get("description") == null ? null : annot - .get("description").toString(); - - char ss = annot.get("secondaryStructure") == null ? null - : annot.get("secondaryStructure").toString().charAt(0); - String displayChar = annot.get("displayCharacter").toString(); + float val = annot.get("value") == null ? null + : Float.valueOf(annot.get("value").toString()); + String desc = annot.get("description") == null ? null + : annot.get("description").toString(); + 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 = ColorUtils + .parseColourString(annot.get("colour").toString()); + annotations[count].colour = color; + } } ++count; } - AlignmentAnnotation alignAnnot = new AlignmentAnnotation(alAnnot - .get("label").toString(), alAnnot.get("description") - .toString(), annotations); + 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(); @@ -391,14 +643,44 @@ public class JSONFile extends AlignFile return this; } + public void parseHiddenSeqRefsAsList(JSONObject jvSettingsJson) + { + hiddenSeqRefs = new ArrayList<>(); + String hiddenSeqs = (String) jvSettingsJson.get("hiddenSeqs"); + if (hiddenSeqs != null && !hiddenSeqs.isEmpty()) + { + String[] seqRefs = hiddenSeqs.split(";"); + for (String seqRef : seqRefs) + { + hiddenSeqRefs.add(seqRef); + } + } + } + + public void parseHiddenCols(JSONObject jvSettingsJson) + { + String hiddenCols = (String) jvSettingsJson.get("hiddenCols"); + if (hiddenCols != null && !hiddenCols.isEmpty()) + { + hiddenColumns = new HiddenColumns(); + String[] rangeStrings = hiddenCols.split(";"); + for (String rangeString : rangeStrings) + { + String[] range = rangeString.split("-"); + hiddenColumns.hideColumns(Integer.valueOf(range[0]), + Integer.valueOf(range[1])); + } + } + } @SuppressWarnings("unchecked") private void parseFeatures(JSONArray jsonSeqFeatures) { if (jsonSeqFeatures != null) { - for (Iterator seqFeatureItr = jsonSeqFeatures.iterator(); seqFeatureItr - .hasNext();) + displayedFeatures = new FeaturesDisplayed(); + for (Iterator seqFeatureItr = jsonSeqFeatures + .iterator(); seqFeatureItr.hasNext();) { JSONObject jsonFeature = seqFeatureItr.next(); Long begin = (Long) jsonFeature.get("xStart"); @@ -408,9 +690,6 @@ public class JSONFile extends AlignFile String descripiton = (String) jsonFeature.get("description"); String seqRef = (String) jsonFeature.get("sequenceRef"); Float score = Float.valueOf(jsonFeature.get("score").toString()); - // Hashtable otherDetails = (Hashtable) jsonFeature - // .get("otherDetails"); - // sequenceFeature.otherDetails = otherDetails; Sequence seq = seqMap.get(seqRef); SequenceFeature sequenceFeature = new SequenceFeature(); @@ -431,80 +710,109 @@ public class JSONFile extends AlignFile sequenceFeature.setBegin(seq.findPosition(begin.intValue())); sequenceFeature.setEnd(seq.findPosition(end.intValue()) - 1); seq.addSequenceFeature(sequenceFeature); + displayedFeatures.setVisible(type); } } } - public ColourSchemeI getJalviewColorScheme(String bioJsColourSchemeName) + @Override + public String getGlobalColourScheme() { - ColourSchemeI jalviewColor = null; - for (JalviewBioJsColorSchemeMapper cs : JalviewBioJsColorSchemeMapper - .values()) - { - if (cs.getBioJsName().equalsIgnoreCase(bioJsColourSchemeName)) - { - jalviewColor = cs.getJvColourScheme(); - break; - } - } - return jalviewColor; + return globalColourScheme; } - public void LoadAlignmentFeatures(AlignFrame af) + public void setGlobalColorScheme(String globalColourScheme) { - af.setShowSeqFeatures(JSONFile.isSeqFeaturesEnabled()); - af.changeColour(getColourScheme()); - af.setMenusForViewport(); + this.globalColourScheme = globalColourScheme; } - public String getGlobalColorScheme() + @Override + public FeaturesDisplayedI getDisplayedFeatures() { - return globalColorScheme; + return displayedFeatures; } - public void setGlobalColorScheme(String globalColorScheme) + public void setDisplayedFeatures(FeaturesDisplayedI displayedFeatures) { - this.globalColorScheme = globalColorScheme; + this.displayedFeatures = displayedFeatures; } - public static ColourSchemeI getColourScheme() + @Override + public void configureForView(AlignmentViewPanel avpanel) { - return colourScheme; + if (avpanel == null) + { + return; + } + super.configureForView(avpanel); + AlignViewportI viewport = avpanel.getAlignViewport(); + AlignmentI alignment = viewport.getAlignment(); + AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation(); + + seqGroups = alignment.getGroups(); + fr = avpanel.cloneFeatureRenderer(); + + // Add non auto calculated annotation to AlignFile + if (annots != null) + { + for (AlignmentAnnotation annot : annots) + { + if (annot != null && !annot.autoCalculated) + { + annotations.add(annot); + } + } + } + globalColourScheme = ColourSchemeProperty + .getColourName(viewport.getGlobalColourScheme()); + setDisplayedFeatures(viewport.getFeaturesDisplayed()); + showSeqFeatures = viewport.isShowSequenceFeatures(); + } - public static void setColourScheme(ColourSchemeI colourScheme) + @Override + public boolean isShowSeqFeatures() { - JSONFile.colourScheme = colourScheme; + return showSeqFeatures; } - public static boolean isSeqFeaturesEnabled() + public void setShowSeqFeatures(boolean showSeqFeatures) { - return seqFeaturesEnabled; + this.showSeqFeatures = showSeqFeatures; } - public static void setSeqFeaturesEnabled(boolean seqFeaturesEnabled) + public Vector getAnnotations() { - JSONFile.seqFeaturesEnabled = seqFeaturesEnabled; + return annotations; } - public FeaturesDisplayedI getDisplayedFeatures() + @Override + public HiddenColumns getHiddenColumns() { - return displayedFeatures; + return hiddenColumns; } - public void setDisplayedFeatures(FeaturesDisplayedI displayedFeatures) + public void setHiddenColumns(HiddenColumns hidden) { - this.displayedFeatures = displayedFeatures; + this.hiddenColumns = hidden; } - public JSONExportSettings getJsonExportSettings() + @Override + public SequenceI[] getHiddenSequences() { - return jsonExportSettings; + if (hiddenSequences == null || hiddenSequences.isEmpty()) + { + return new SequenceI[] {}; + } + synchronized (hiddenSequences) + { + return hiddenSequences.toArray(new SequenceI[hiddenSequences.size()]); + } } - public void setJsonExportSettings(JSONExportSettings jsonExportSettings) + public void setHiddenSequences(ArrayList hiddenSequences) { - this.jsonExportSettings = jsonExportSettings; + this.hiddenSequences = hiddenSequences; } public class JSONExportSettings @@ -569,4 +877,19 @@ public class JSONFile extends AlignFile 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(); + } }