From 245733144fbe63d71454b0a00ebc21e84458bab2 Mon Sep 17 00:00:00 2001 From: tcofoegbu Date: Thu, 4 Jun 2015 10:04:47 +0100 Subject: [PATCH] JAL-1641 updated json schema to make it more generic in order to accomodate more dynamic parameters --- src/jalview/io/BioJsHTMLOutput.java | 2 +- src/jalview/io/JSONFile.java | 90 +++++++++-- src/jalview/json/binding/v1/AlignmentPojo.java | 99 +++++++++++- src/jalview/json/binding/v1/AppSettingsPojo.java | 91 +++++++++++ .../json/binding/v1/JalviewSettingsPojo.java | 158 -------------------- 5 files changed, 262 insertions(+), 178 deletions(-) create mode 100644 src/jalview/json/binding/v1/AppSettingsPojo.java delete mode 100644 src/jalview/json/binding/v1/JalviewSettingsPojo.java diff --git a/src/jalview/io/BioJsHTMLOutput.java b/src/jalview/io/BioJsHTMLOutput.java index 3a3b665..ff55400 100644 --- a/src/jalview/io/BioJsHTMLOutput.java +++ b/src/jalview/io/BioJsHTMLOutput.java @@ -35,7 +35,7 @@ public class BioJsHTMLOutput public static final String BJS_TEMPLATE_GIT_REPO = jalview.bin.Cache .getDefault( "biojs_template_git_repo", - "https://raw.githubusercontent.com/tcofoegbu/bjs-template/master/package.json");; + "https://raw.githubusercontent.com/tcofoegbu/bjs-template/master/package.json"); public BioJsHTMLOutput(AlignmentPanel ap, FeatureRenderer fr1) diff --git a/src/jalview/io/JSONFile.java b/src/jalview/io/JSONFile.java index 30383f3..5e2139e 100644 --- a/src/jalview/io/JSONFile.java +++ b/src/jalview/io/JSONFile.java @@ -27,15 +27,15 @@ 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.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; @@ -58,9 +58,11 @@ public class JSONFile extends AlignFile { private ColourSchemeI colourScheme; - private String jalviewVersion; + private String version = "2.9"; - private String webStartLaunchServletUrl; + private String webstartUrl = "www.jalview.org/services/launchApp"; + + private String application = "Jalview"; public static final String FILE_EXT = "json"; @@ -150,15 +152,21 @@ public class JSONFile extends AlignFile if (jsonExportSettings.isExportJalviewSettings()) { - jalviewVersion = ""; - webStartLaunchServletUrl = "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()) @@ -209,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) { @@ -304,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) { diff --git a/src/jalview/json/binding/v1/AlignmentPojo.java b/src/jalview/json/binding/v1/AlignmentPojo.java index b3189c0..9f129f7 100644 --- a/src/jalview/json/binding/v1/AlignmentPojo.java +++ b/src/jalview/json/binding/v1/AlignmentPojo.java @@ -1,6 +1,21 @@ package jalview.json.binding.v1; +import jalview.schemes.Blosum62ColourScheme; +import jalview.schemes.BuriedColourScheme; +import jalview.schemes.ColourSchemeI; +import jalview.schemes.HelixColourScheme; +import jalview.schemes.HydrophobicColourScheme; +import jalview.schemes.NucleotideColourScheme; +import jalview.schemes.PIDColourScheme; +import jalview.schemes.PurinePyrimidineColourScheme; +import jalview.schemes.RNAInteractionColourScheme; +import jalview.schemes.StrandColourScheme; +import jalview.schemes.TaylorColourScheme; +import jalview.schemes.TurnColourScheme; +import jalview.schemes.ZappoColourScheme; + import java.util.ArrayList; +import java.util.HashMap; import java.util.List; public class AlignmentPojo @@ -15,7 +30,7 @@ public class AlignmentPojo private List seqFeatures = new ArrayList(); - private JalviewSettingsPojo jalviewSettings; + HashMap appSettings = new HashMap(); public AlignmentPojo() { @@ -31,14 +46,14 @@ public class AlignmentPojo this.seqs = seqs; } - public JalviewSettingsPojo getJalviewSettings() + public HashMap getAppSettings() { - return jalviewSettings; + return appSettings; } - public void setJalviewSettings(JalviewSettingsPojo jalviewSettings) + public void setAppSettings(HashMap appSettings) { - this.jalviewSettings = jalviewSettings; + this.appSettings = appSettings; } public List getAlignAnnotation() @@ -76,4 +91,78 @@ public class AlignmentPojo { return svid; } + + public void setGlobalColorScheme(String globalColorScheme) + { + for (JalviewBioJsColorSchemeMapper cs : JalviewBioJsColorSchemeMapper + .values()) + { + if (cs.getJalviewName().equals(globalColorScheme)) + { + // this.globalColorScheme = cs.getBioJsName(); + this.appSettings.put("globalColorScheme", cs.getBioJsName()); + break; + } + } + } + + public enum JalviewBioJsColorSchemeMapper + { + USER_DEFINED("User Defined", "user defined", null), NONE("None", "foo", + null), CLUSTAL("Clustal", "clustal", null), ZAPPO("Zappo", + "zappo", new ZappoColourScheme()), TAYLOR("Taylor", "taylor", + new TaylorColourScheme()), NUCLEOTIDE("Nucleotide", + "nucleotide", new NucleotideColourScheme()), PURINE_PYRIMIDINE( + "Purine/Pyrimidine", "purine", + new PurinePyrimidineColourScheme()), HELIX_PROPENCITY( + "Helix Propensity", "helix", new HelixColourScheme()), TURN_PROPENSITY( + "Turn Propensity", "turn", new TurnColourScheme()), STRAND_PROPENSITY( + "Strand Propensity", "strand", new StrandColourScheme()), BURIED_INDEX( + "Buried Index", "buried", new BuriedColourScheme()), HYDROPHOBIC( + "Hydrophobic", "hydro", new HydrophobicColourScheme()), + + // The color types below are not yet supported by BioJs MSA viewer + T_COFFE_SCORES("T-Coffee Scores", "T-Coffee Scores", null), RNA_INT_TYPE( + "RNA Interaction type", "RNA Interaction type", + new RNAInteractionColourScheme()), BLOSUM62("Blosum62", + "Blosum62", new Blosum62ColourScheme()), RNA_HELICES( + "RNA Helices", "RNA Helices", null), PERCENTAGE_IDENTITY( + "% Identity", "pid", new PIDColourScheme()); + + private String jalviewName; + + private String bioJsName; + + private ColourSchemeI jvColourScheme; + + private JalviewBioJsColorSchemeMapper(String jalviewName, + String bioJsName, ColourSchemeI jvColourScheme) + { + this.jalviewName = jalviewName; + this.bioJsName = bioJsName; + this.setJvColourScheme(jvColourScheme); + } + + public String getJalviewName() + { + return jalviewName; + } + + public String getBioJsName() + { + return bioJsName; + } + + public ColourSchemeI getJvColourScheme() + { + return jvColourScheme; + } + + public void setJvColourScheme(ColourSchemeI jvColourScheme) + { + this.jvColourScheme = jvColourScheme; + } + + } + } diff --git a/src/jalview/json/binding/v1/AppSettingsPojo.java b/src/jalview/json/binding/v1/AppSettingsPojo.java new file mode 100644 index 0000000..cfc9347 --- /dev/null +++ b/src/jalview/json/binding/v1/AppSettingsPojo.java @@ -0,0 +1,91 @@ +package jalview.json.binding.v1; + + +public class AppSettingsPojo +{ + // private String globalColorScheme = "none"; + + + + public AppSettingsPojo() + { + + } + + // + // + // public void setGlobalColorScheme(String globalColorScheme) + // { + // for (JalviewBioJsColorSchemeMapper cs : JalviewBioJsColorSchemeMapper + // .values()) + // { + // if (cs.getJalviewName().equals(globalColorScheme)) + // { + // // this.globalColorScheme = cs.getBioJsName(); + // this.settings.put("globalColorScheme", cs.getBioJsName()); + // break; + // } + // } + // } + // + // public enum JalviewBioJsColorSchemeMapper + // { + // USER_DEFINED("User Defined", "user defined", null), NONE("None", "foo", + // null), CLUSTAL("Clustal", "clustal", null), ZAPPO("Zappo", + // "zappo", new ZappoColourScheme()), TAYLOR("Taylor", "taylor", + // new TaylorColourScheme()), NUCLEOTIDE("Nucleotide", + // "nucleotide", new NucleotideColourScheme()), PURINE_PYRIMIDINE( + // "Purine/Pyrimidine", "purine", + // new PurinePyrimidineColourScheme()), HELIX_PROPENCITY( + // "Helix Propensity", "helix", new HelixColourScheme()), TURN_PROPENSITY( + // "Turn Propensity", "turn", new TurnColourScheme()), STRAND_PROPENSITY( + // "Strand Propensity", "strand", new StrandColourScheme()), BURIED_INDEX( + // "Buried Index", "buried", new BuriedColourScheme()), HYDROPHOBIC( + // "Hydrophobic", "hydro", new HydrophobicColourScheme()), + // + // // The color types below are not yet supported by BioJs MSA viewer + // T_COFFE_SCORES("T-Coffee Scores", "T-Coffee Scores", null), RNA_INT_TYPE( + // "RNA Interaction type", "RNA Interaction type", + // new RNAInteractionColourScheme()), BLOSUM62("Blosum62", + // "Blosum62", new Blosum62ColourScheme()), RNA_HELICES( + // "RNA Helices", "RNA Helices", null), PERCENTAGE_IDENTITY( + // "% Identity", "pid", new PIDColourScheme()); + // + // private String jalviewName; + // + // private String bioJsName; + // + // private ColourSchemeI jvColourScheme; + // + // private JalviewBioJsColorSchemeMapper(String jalviewName, + // String bioJsName, ColourSchemeI jvColourScheme) + // { + // this.jalviewName = jalviewName; + // this.bioJsName = bioJsName; + // this.setJvColourScheme(jvColourScheme); + // } + // + // public String getJalviewName() + // { + // return jalviewName; + // } + // + // public String getBioJsName() + // { + // return bioJsName; + // } + // + // public ColourSchemeI getJvColourScheme() + // { + // return jvColourScheme; + // } + // + // public void setJvColourScheme(ColourSchemeI jvColourScheme) + // { + // this.jvColourScheme = jvColourScheme; + // } + // + // } + + +} diff --git a/src/jalview/json/binding/v1/JalviewSettingsPojo.java b/src/jalview/json/binding/v1/JalviewSettingsPojo.java deleted file mode 100644 index 595234c..0000000 --- a/src/jalview/json/binding/v1/JalviewSettingsPojo.java +++ /dev/null @@ -1,158 +0,0 @@ -package jalview.json.binding.v1; - -import jalview.schemes.Blosum62ColourScheme; -import jalview.schemes.BuriedColourScheme; -import jalview.schemes.ColourSchemeI; -import jalview.schemes.HelixColourScheme; -import jalview.schemes.HydrophobicColourScheme; -import jalview.schemes.NucleotideColourScheme; -import jalview.schemes.PIDColourScheme; -import jalview.schemes.PurinePyrimidineColourScheme; -import jalview.schemes.RNAInteractionColourScheme; -import jalview.schemes.StrandColourScheme; -import jalview.schemes.TaylorColourScheme; -import jalview.schemes.TurnColourScheme; -import jalview.schemes.ZappoColourScheme; - -public class JalviewSettingsPojo -{ - private String svid = "1.0"; - - private String globalColorScheme = "none"; - - private String jalviewVersion; - - private String webStartUrl; - - private boolean showSeqFeatures; - - private boolean wrapModeEnabled; - - public JalviewSettingsPojo() - { - - } - - public String getGlobalColorScheme() - { - return globalColorScheme; - } - - public void setGlobalColorScheme(String globalColorScheme) - { - for (JalviewBioJsColorSchemeMapper cs : JalviewBioJsColorSchemeMapper - .values()) - { - if (cs.getJalviewName().equals(globalColorScheme)) - { - this.globalColorScheme = cs.getBioJsName(); - break; - } - } - } - - public String getJalviewVersion() - { - return jalviewVersion; - } - - public void setJalviewVersion(String jalviewVersion) - { - this.jalviewVersion = jalviewVersion; - } - - public String getWebStartUrl() - { - return webStartUrl; - } - - public void setWebStartUrl(String webStartUrl) - { - this.webStartUrl = webStartUrl; - } - - public boolean isShowSeqFeatures() - { - return showSeqFeatures; - } - - public void setShowSeqFeatures(boolean showSeqFeatures) - { - this.showSeqFeatures = showSeqFeatures; - } - - public boolean isWrapModeEnabled() - { - return wrapModeEnabled; - } - - public void setWrapModeEnabled(boolean wrapModeEnabled) - { - this.wrapModeEnabled = wrapModeEnabled; - } - - public enum JalviewBioJsColorSchemeMapper - { - USER_DEFINED("User Defined", "user defined", null), NONE("None", "foo", - null), CLUSTAL("Clustal", "clustal", null), ZAPPO("Zappo", - "zappo", new ZappoColourScheme()), TAYLOR("Taylor", "taylor", - new TaylorColourScheme()), NUCLEOTIDE("Nucleotide", - "nucleotide", new NucleotideColourScheme()), PURINE_PYRIMIDINE( - "Purine/Pyrimidine", "purine", - new PurinePyrimidineColourScheme()), HELIX_PROPENCITY( - "Helix Propensity", "helix", new HelixColourScheme()), TURN_PROPENSITY( - "Turn Propensity", "turn", new TurnColourScheme()), STRAND_PROPENSITY( - "Strand Propensity", "strand", new StrandColourScheme()), BURIED_INDEX( - "Buried Index", "buried", new BuriedColourScheme()), HYDROPHOBIC( - "Hydrophobic", "hydro", new HydrophobicColourScheme()), - - // The color types below are not yet supported by BioJs MSA viewer - T_COFFE_SCORES("T-Coffee Scores", "T-Coffee Scores", null), RNA_INT_TYPE( - "RNA Interaction type", "RNA Interaction type", - new RNAInteractionColourScheme()), BLOSUM62("Blosum62", - "Blosum62", new Blosum62ColourScheme()), RNA_HELICES( - "RNA Helices", "RNA Helices", null), PERCENTAGE_IDENTITY( - "% Identity", "pid", new PIDColourScheme()); - - private String jalviewName; - - private String bioJsName; - - private ColourSchemeI jvColourScheme; - - private JalviewBioJsColorSchemeMapper(String jalviewName, - String bioJsName, ColourSchemeI jvColourScheme) - { - this.jalviewName = jalviewName; - this.bioJsName = bioJsName; - this.setJvColourScheme(jvColourScheme); - } - - public String getJalviewName() - { - return jalviewName; - } - - public String getBioJsName() - { - return bioJsName; - } - - public ColourSchemeI getJvColourScheme() - { - return jvColourScheme; - } - - public void setJvColourScheme(ColourSchemeI jvColourScheme) - { - this.jvColourScheme = jvColourScheme; - } - - } - - public String getSvid() - { - return svid; - } - -} -- 1.7.10.2