X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FJSONFile.java;h=5e2139e5d3734722ae905925d27ca759a3618871;hb=e0c1dde5b241a8ac5b8c960f1f55f0940da55788;hp=8d3caddc2e73bb70465de6c6fcd8e7c165c53f5c;hpb=91c77a3db54eb4a270b03bcf9a6d97255c1fce35;p=jalview.git diff --git a/src/jalview/io/JSONFile.java b/src/jalview/io/JSONFile.java index 8d3cadd..5e2139e 100644 --- a/src/jalview/io/JSONFile.java +++ b/src/jalview/io/JSONFile.java @@ -1,20 +1,41 @@ +/* + * 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.AlignViewControllerGuiI; import jalview.api.AlignViewportI; import jalview.api.FeatureRenderer; import jalview.api.FeaturesDisplayedI; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.Annotation; +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.json.binding.v1.AlignmentAnnotationPojo; import jalview.json.binding.v1.AlignmentPojo; +import jalview.json.binding.v1.AlignmentPojo.JalviewBioJsColorSchemeMapper; 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; @@ -37,9 +58,11 @@ public class JSONFile extends AlignFile { private ColourSchemeI colourScheme; - private String jalviewVersion; + private String version = "2.9"; + + private String webstartUrl = "www.jalview.org/services/launchApp"; - private String webStartLaunchServletUrl; + private String application = "Jalview"; public static final String FILE_EXT = "json"; @@ -129,17 +152,21 @@ public class JSONFile extends AlignFile if (jsonExportSettings.isExportJalviewSettings()) { - jalviewVersion = jalview.bin.Cache.getProperty("VERSION"); - webStartLaunchServletUrl = jalview.bin.Cache.getDefault( - "www.jalview.org", "http://www.jalview.org") - + "/services/launchApp"; - - JalviewSettingsPojo jvSettings = new JalviewSettingsPojo(); - jvSettings.setGlobalColorScheme(globalColorScheme); - jvSettings.setJalviewVersion(jalviewVersion); - jvSettings.setWebStartUrl(webStartLaunchServletUrl); - jvSettings.setShowSeqFeatures(showSeqFeatures); - jsonAlignmentPojo.setJalviewSettings(jvSettings); + jsonAlignmentPojo.setGlobalColorScheme(globalColorScheme); + jsonAlignmentPojo.getAppSettings().put("application", application); + jsonAlignmentPojo.getAppSettings().put("version", version); + jsonAlignmentPojo.getAppSettings().put("webStartUrl", webstartUrl); + jsonAlignmentPojo.getAppSettings().put("showSeqFeatures", + String.valueOf(showSeqFeatures)); + + String[] hiddenSections = exportHiddenSections(); + if (hiddenSections != null) + { + jsonAlignmentPojo.getAppSettings().put("hiddenCols", + String.valueOf(hiddenSections[0])); + jsonAlignmentPojo.getAppSettings().put("hiddenSeqs", + String.valueOf(hiddenSections[1])); + } } if (jsonExportSettings.isExportAnnotations()) @@ -178,7 +205,7 @@ public class JSONFile extends AlignFile jsonAlignmentPojo.getSeqGroups().add(seqGrpPojo); } } - com.json.JSONObject generatedJSon = new com.json.JSONObject( + org.json.JSONObject generatedJSon = new org.json.JSONObject( jsonAlignmentPojo); jsonOutput = generatedJSon.toString(); return jsonOutput.replaceAll("xstart", "xStart").replaceAll("xend", @@ -190,6 +217,60 @@ public class JSONFile extends AlignFile return jsonOutput; } + public String[] exportHiddenSections() + { + String[] hiddenSections = new String[2]; + if (getViewport() == null) + { + return null; + } + + System.out.println("--- Hidden Sections ---"); + // hidden column business + if (getViewport().hasHiddenColumns()) + { + System.out.print("Hidden Cols : "); + List hiddenCols = getViewport().getColumnSelection() + .getHiddenColumns(); + StringBuilder hiddenColsBuilder = new StringBuilder(); + for (int[] range : hiddenCols) + { + hiddenColsBuilder.append(";").append(range[0]).append("-") + .append(range[1]); + } + + hiddenColsBuilder.deleteCharAt(0); + hiddenSections[0] = hiddenColsBuilder.toString(); + System.out.println(hiddenSections[0]); + } + + // hidden rows/seqs business + HiddenSequences hiddenSeqsObj = getViewport().getAlignment() + .getHiddenSequences(); + if (hiddenSeqsObj == null) + { + return hiddenSections; + } + + SequenceI[] hiddenSeqs = hiddenSeqsObj.hiddenSequences; + System.out.print("Hidden Seqs : "); + 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(); + System.out.println(hiddenSections[1]); + return hiddenSections; + } + public static List sequenceFeatureToJsonPojo( List seqs, FeatureRenderer fr) { @@ -285,7 +366,7 @@ public class JSONFile extends AlignFile JSONArray seqGrpJsonArray = (JSONArray) alignmentJsonObj .get("seqGroups"); JSONObject jvSettingsJsonObj = (JSONObject) alignmentJsonObj - .get("jalviewSettings"); + .get("appSettings"); if (jvSettingsJsonObj != null) { @@ -380,7 +461,7 @@ public class JSONFile extends AlignFile String desc = annot.get("description") == null ? null : annot .get("description").toString(); - char ss = annot.get("secondaryStructure") == null ? null + char ss = annot.get("secondaryStructure") == null ? ' ' : annot.get("secondaryStructure").toString().charAt(0); String displayChar = annot.get("displayCharacter").toString(); @@ -462,7 +543,7 @@ public class JSONFile extends AlignFile return jalviewColor; } - public void applySettingsToAlignFrame(AlignFrame af) + public void applySettingsToAlignFrame(AlignViewControllerGuiI af) { af.setShowSeqFeatures(isShowSeqFeatures()); af.changeColour(getColourScheme()); @@ -548,6 +629,11 @@ public class JSONFile extends AlignFile this.showSeqFeatures = showSeqFeatures; } + public Vector getAnnotations() + { + return annotations; + } + public class JSONExportSettings { private boolean exportSequence;