From: tcofoegbu Date: Thu, 24 Sep 2015 13:31:50 +0000 (+0100) Subject: JAL-1896 bugfix to enabled Jalview restore clustal, RNA Helices and T-Coffee colour... X-Git-Tag: Release_2_10_0~392 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=c46a8d65c37cdae36a9aec981708c2bb0173ccaf;p=jalview.git JAL-1896 bugfix to enabled Jalview restore clustal, RNA Helices and T-Coffee colour schemes from BioJSON --- diff --git a/src/jalview/io/JSONFile.java b/src/jalview/io/JSONFile.java index 0c0f395..717ab8b 100644 --- a/src/jalview/io/JSONFile.java +++ b/src/jalview/io/JSONFile.java @@ -28,6 +28,7 @@ import jalview.api.ComplexAlignFile; import jalview.api.FeatureRenderer; import jalview.api.FeaturesDisplayedI; import jalview.bin.BuildDetails; +import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.Annotation; @@ -40,7 +41,7 @@ import jalview.datamodel.SequenceI; import jalview.json.binding.biojson.v1.AlignmentAnnotationPojo; import jalview.json.binding.biojson.v1.AlignmentPojo; 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; @@ -388,6 +389,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile @SuppressWarnings("unchecked") public JSONFile parse(Reader jsonAlignmentString) { + String jsColourScheme = null; try { JSONParser jsonParser = new JSONParser(); @@ -405,11 +407,10 @@ public class JSONFile extends AlignFile implements ComplexAlignFile if (jvSettingsJsonObj != null) { - String jsColourScheme = (String) jvSettingsJsonObj + jsColourScheme = (String) jvSettingsJsonObj .get("globalColorScheme"); Boolean showFeatures = Boolean.valueOf(jvSettingsJsonObj.get( "showSeqFeatures").toString()); - setColourScheme(getJalviewColorScheme(jsColourScheme)); setShowSeqFeatures(showFeatures); parseHiddenSeqRefsAsList(jvSettingsJsonObj); parseHiddenCols(jvSettingsJsonObj); @@ -435,6 +436,13 @@ public class JSONFile extends AlignFile implements ComplexAlignFile seqs.add(seq); seqMap.put(seqUniqueId, seq); } + + if (jsColourScheme != null) + { + setColourScheme(ColourSchemeMapper.getJalviewColourScheme( + jsColourScheme, + new Alignment(seqs.toArray(new SequenceI[0])))); + } parseFeatures(jsonSeqArray); for (Iterator seqGrpIter = seqGrpJsonArray.iterator(); seqGrpIter @@ -472,10 +480,11 @@ public class JSONFile extends AlignFile implements ComplexAlignFile } } } - ColourSchemeI grpColourScheme = getJalviewColorScheme(colourScheme); - SequenceGroup seqGrp = new SequenceGroup(grpSeqs, grpName, - grpColourScheme, displayBoxes, displayText, colourText, + 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); @@ -600,24 +609,6 @@ 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) - || cs.getJalviewName() - .equalsIgnoreCase(bioJsColourSchemeName)) - { - jalviewColor = cs.getJvColourScheme(); - break; - } - } - return jalviewColor; - } - public String getGlobalColorScheme() { return globalColorScheme; diff --git a/src/jalview/json/binding/biojson/v1/ColourSchemeMapper.java b/src/jalview/json/binding/biojson/v1/ColourSchemeMapper.java new file mode 100644 index 0000000..de4ba8d --- /dev/null +++ b/src/jalview/json/binding/biojson/v1/ColourSchemeMapper.java @@ -0,0 +1,92 @@ +/* + * 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.json.binding.biojson.v1; + +import jalview.datamodel.AnnotatedCollectionI; +import jalview.schemes.Blosum62ColourScheme; +import jalview.schemes.BuriedColourScheme; +import jalview.schemes.ClustalxColourScheme; +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.RNAHelicesColour; +import jalview.schemes.RNAInteractionColourScheme; +import jalview.schemes.StrandColourScheme; +import jalview.schemes.TCoffeeColourScheme; +import jalview.schemes.TaylorColourScheme; +import jalview.schemes.TurnColourScheme; +import jalview.schemes.ZappoColourScheme; + +public class ColourSchemeMapper +{ + public static ColourSchemeI getJalviewColourScheme( + String colourSchemeName, AnnotatedCollectionI annotCol) + { + switch (colourSchemeName.toUpperCase()) + { + case "ZAPPO": + return new ZappoColourScheme(); + case "TAYLOR": + return new TaylorColourScheme(); + case "NUCLEOTIDE": + return new NucleotideColourScheme(); + case "PURINE": + case "PURINE/PYRIMIDINE": + return new PurinePyrimidineColourScheme(); + case "HELIX": + case "HELIX PROPENSITY": + return new HelixColourScheme(); + case "TURN": + case "TURN PROPENSITY": + return new TurnColourScheme(); + case "STRAND": + case "STRAND PROPENSITY": + return new StrandColourScheme(); + case "BURIED": + case "BURIED INDEX": + return new BuriedColourScheme(); + case "HYDRO": + case "HYDROPHOBIC": + return new HydrophobicColourScheme(); + case "RNA INTERACTION TYPE": + return new RNAInteractionColourScheme(); + case "PID": + case "% IDENTITY": + return new PIDColourScheme(); + case "BLOSUM62": + return new Blosum62ColourScheme(); + case "T-COFFEE SCORES": + return (annotCol != null) ? new TCoffeeColourScheme(annotCol) : null; + case "RNA HELICES": + return (annotCol != null) ? new RNAHelicesColour(annotCol) : null; + case "CLUSTAL": + return (annotCol != null) ? new ClustalxColourScheme(annotCol, null) + : null; + case "USER DEFINED": + return null; + default: + return null; + } + } +} diff --git a/src/jalview/json/binding/biojson/v1/JalviewBioJsColorSchemeMapper.java b/src/jalview/json/binding/biojson/v1/JalviewBioJsColorSchemeMapper.java deleted file mode 100644 index e7a302e..0000000 --- a/src/jalview/json/binding/biojson/v1/JalviewBioJsColorSchemeMapper.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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.json.binding.biojson.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 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_PROPENSITY( - "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/test/jalview/io/JSONFileTest.java b/test/jalview/io/JSONFileTest.java index da2e64e..4371ff9 100644 --- a/test/jalview/io/JSONFileTest.java +++ b/test/jalview/io/JSONFileTest.java @@ -33,6 +33,7 @@ import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.gui.AlignFrame; +import jalview.json.binding.biojson.v1.ColourSchemeMapper; import jalview.schemes.ColourSchemeI; import jalview.schemes.ZappoColourScheme; @@ -124,9 +125,11 @@ public class JSONFileTest grpSeqs.add(seqs[2]); grpSeqs.add(seqs[3]); grpSeqs.add(seqs[4]); - ColourSchemeI scheme = JSONFile.getJalviewColorScheme("zappo"); SequenceGroup seqGrp = new SequenceGroup(grpSeqs, "JGroup:1883305585", - scheme, true, true, false, 21, 29); + null, true, true, false, 21, 29); + ColourSchemeI scheme = ColourSchemeMapper.getJalviewColourScheme( + "zappo", seqGrp); + seqGrp.cs = scheme; seqGrp.setShowNonconserved(false); seqGrp.setDescription(null); @@ -419,13 +422,14 @@ public class JSONFileTest + actualGrp.getStartRes()); System.out.println(expectedGrp.getEndRes() + " | " + actualGrp.getEndRes()); + System.out.println(expectedGrp.cs + " | " + actualGrp.cs); if (expectedGrp.getName().equals(actualGrp.getName()) && expectedGrp.getColourText() == actualGrp.getColourText() && expectedGrp.getDisplayBoxes() == actualGrp.getDisplayBoxes() && expectedGrp.getIgnoreGapsConsensus() == actualGrp .getIgnoreGapsConsensus() - && expectedGrp.cs.equals(actualGrp.cs) + && (expectedGrp.cs.getClass().equals(actualGrp.cs.getClass())) && expectedGrp.getSequences().size() == actualGrp .getSequences().size() && expectedGrp.getStartRes() == actualGrp.getStartRes()