From 4513bd826c54623c14aa8946a51a2382f64e98f3 Mon Sep 17 00:00:00 2001 From: tcofoegbu Date: Mon, 28 Sep 2015 11:14:04 +0100 Subject: [PATCH] JAL-1896 revised implementation to construct a ColourSchemeI instance after creating an alignment object rather than from within bioJSON parser --- src/jalview/api/ComplexAlignFile.java | 3 +- src/jalview/appletgui/CutAndPasteTransfer.java | 6 ++- src/jalview/gui/CutAndPasteTransfer.java | 6 ++- src/jalview/io/FileLoader.java | 7 +++- src/jalview/io/HtmlFile.java | 13 +++--- src/jalview/io/JSONFile.java | 39 +++++------------- .../binding/biojson/v1/ColourSchemeMapper.java | 42 ++++++++++++++------ test/jalview/io/JSONFileTest.java | 14 ++++--- 8 files changed, 70 insertions(+), 60 deletions(-) diff --git a/src/jalview/api/ComplexAlignFile.java b/src/jalview/api/ComplexAlignFile.java index 4ac08cf..2bf2782 100644 --- a/src/jalview/api/ComplexAlignFile.java +++ b/src/jalview/api/ComplexAlignFile.java @@ -22,7 +22,6 @@ package jalview.api; import jalview.datamodel.ColumnSelection; import jalview.datamodel.SequenceI; -import jalview.schemes.ColourSchemeI; /** * This interface should be implemented by complex file parser with the ability @@ -44,7 +43,7 @@ public interface ComplexAlignFile * * @return */ - public ColourSchemeI getColourScheme(); + public String getGlobalColourScheme(); /** * Retrieves the Column selection/hidden column from a complex file parser diff --git a/src/jalview/appletgui/CutAndPasteTransfer.java b/src/jalview/appletgui/CutAndPasteTransfer.java index 4590c54..1ee8393 100644 --- a/src/jalview/appletgui/CutAndPasteTransfer.java +++ b/src/jalview/appletgui/CutAndPasteTransfer.java @@ -33,6 +33,7 @@ import jalview.io.FileParse; import jalview.io.IdentifyFile; import jalview.io.NewickFile; import jalview.io.TCoffeeScoreFile; +import jalview.json.binding.biojson.v1.ColourSchemeMapper; import jalview.schemes.ColourSchemeI; import jalview.schemes.TCoffeeColourScheme; import jalview.util.MessageManager; @@ -259,11 +260,14 @@ public class CutAndPasteTransfer extends Panel implements ActionListener, .getHiddenSequences(); boolean showSeqFeatures = ((ComplexAlignFile) source) .isShowSeqFeatures(); - ColourSchemeI cs = ((ComplexAlignFile) source).getColourScheme(); + String colourSchemeName = ((ComplexAlignFile) source) + .getGlobalColourScheme(); af = new AlignFrame(al, hiddenSeqs, colSel, alignFrame.viewport.applet, "Cut & Paste input - " + format, false); af.getAlignViewport().setShowSequenceFeatures(showSeqFeatures); + ColourSchemeI cs = ColourSchemeMapper.getJalviewColourScheme( + colourSchemeName, al); af.changeColour(cs); } else diff --git a/src/jalview/gui/CutAndPasteTransfer.java b/src/jalview/gui/CutAndPasteTransfer.java index f5a8e1c..acc71f3 100644 --- a/src/jalview/gui/CutAndPasteTransfer.java +++ b/src/jalview/gui/CutAndPasteTransfer.java @@ -35,6 +35,7 @@ import jalview.io.IdentifyFile; import jalview.io.JalviewFileChooser; import jalview.io.JalviewFileView; import jalview.jbgui.GCutAndPasteTransfer; +import jalview.json.binding.biojson.v1.ColourSchemeMapper; import jalview.schemes.ColourSchemeI; import jalview.util.MessageManager; @@ -262,13 +263,16 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer .getHiddenSequences(); boolean showSeqFeatures = ((ComplexAlignFile) source) .isShowSeqFeatures(); - ColourSchemeI cs = ((ComplexAlignFile) source).getColourScheme(); + String colourSchemeName = ((ComplexAlignFile) source) + .getGlobalColourScheme(); FeaturesDisplayedI fd = ((ComplexAlignFile) source) .getDisplayedFeatures(); af = new AlignFrame(al, hiddenSeqs, colSel, AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); af.getViewport().setShowSequenceFeatures(showSeqFeatures); af.getViewport().setFeaturesDisplayed(fd); + ColourSchemeI cs = ColourSchemeMapper.getJalviewColourScheme( + colourSchemeName, al); af.changeColour(cs); } else diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index 9ff3ef9..9931f32 100755 --- a/src/jalview/io/FileLoader.java +++ b/src/jalview/io/FileLoader.java @@ -31,6 +31,7 @@ import jalview.gui.AlignFrame; import jalview.gui.AlignViewport; import jalview.gui.Desktop; import jalview.gui.Jalview2XML; +import jalview.json.binding.biojson.v1.ColourSchemeMapper; import jalview.schemes.ColourSchemeI; import jalview.structure.StructureSelectionManager; import jalview.util.MessageManager; @@ -375,8 +376,8 @@ public class FileLoader implements Runnable .getHiddenSequences(); boolean showSeqFeatures = ((ComplexAlignFile) source) .isShowSeqFeatures(); - ColourSchemeI cs = ((ComplexAlignFile) source) - .getColourScheme(); + String colourSchemeName = ((ComplexAlignFile) source) + .getGlobalColourScheme(); FeaturesDisplayedI fd = ((ComplexAlignFile) source) .getDisplayedFeatures(); alignFrame = new AlignFrame(al, hiddenSeqs, colSel, @@ -385,6 +386,8 @@ public class FileLoader implements Runnable alignFrame.getViewport().setShowSequenceFeatures( showSeqFeatures); alignFrame.getViewport().setFeaturesDisplayed(fd); + ColourSchemeI cs = ColourSchemeMapper.getJalviewColourScheme( + colourSchemeName, al); alignFrame.changeColour(cs); } else diff --git a/src/jalview/io/HtmlFile.java b/src/jalview/io/HtmlFile.java index 06c2717..954d12e 100644 --- a/src/jalview/io/HtmlFile.java +++ b/src/jalview/io/HtmlFile.java @@ -25,7 +25,6 @@ import jalview.api.ComplexAlignFile; import jalview.api.FeaturesDisplayedI; import jalview.datamodel.ColumnSelection; import jalview.datamodel.SequenceI; -import jalview.schemes.ColourSchemeI; import java.io.IOException; import java.io.StringReader; @@ -40,7 +39,7 @@ public class HtmlFile extends AlignFile implements ComplexAlignFile public static final String FILE_DESC = "HTML"; - private ColourSchemeI colourScheme; + private String globalColourScheme; private boolean showSeqFeatures; @@ -108,7 +107,7 @@ public class HtmlFile extends AlignFile implements ComplexAlignFile this.seqGroups = jsonFile.getSeqGroups(); this.annotations = jsonFile.getAnnotations(); this.showSeqFeatures = jsonFile.isShowSeqFeatures(); - this.colourScheme = jsonFile.getColourScheme(); + this.globalColourScheme = jsonFile.getGlobalColourScheme(); this.hiddenSequences = jsonFile.getHiddenSequences(); this.columnSelection = jsonFile.getColumnSelection(); this.displayedFeatures = jsonFile.getDisplayedFeatures(); @@ -135,14 +134,14 @@ public class HtmlFile extends AlignFile implements ComplexAlignFile this.showSeqFeatures = showSeqFeatures; } - public ColourSchemeI getColourScheme() + public String getGlobalColourScheme() { - return colourScheme; + return globalColourScheme; } - public void setColourScheme(ColourSchemeI colourScheme) + public void setColourScheme(String globalColourScheme) { - this.colourScheme = colourScheme; + this.globalColourScheme = globalColourScheme; } public ColumnSelection getColumnSelection() diff --git a/src/jalview/io/JSONFile.java b/src/jalview/io/JSONFile.java index 717ab8b..8725556 100644 --- a/src/jalview/io/JSONFile.java +++ b/src/jalview/io/JSONFile.java @@ -28,7 +28,6 @@ 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; @@ -45,7 +44,6 @@ 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.viewmodel.seqfeatures.FeaturesDisplayed; @@ -64,8 +62,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"; @@ -76,7 +72,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile public static final String FILE_DESC = "JSON"; - private String globalColorScheme; + private String globalColourScheme; private boolean showSeqFeatures; @@ -184,7 +180,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); @@ -389,7 +385,6 @@ public class JSONFile extends AlignFile implements ComplexAlignFile @SuppressWarnings("unchecked") public JSONFile parse(Reader jsonAlignmentString) { - String jsColourScheme = null; try { JSONParser jsonParser = new JSONParser(); @@ -407,7 +402,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile if (jvSettingsJsonObj != null) { - jsColourScheme = (String) jvSettingsJsonObj + globalColourScheme = (String) jvSettingsJsonObj .get("globalColorScheme"); Boolean showFeatures = Boolean.valueOf(jvSettingsJsonObj.get( "showSeqFeatures").toString()); @@ -437,12 +432,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile 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 @@ -529,7 +519,6 @@ public class JSONFile extends AlignFile implements ComplexAlignFile .toString(), annotations); this.annotations.add(alignAnnot); } - } catch (Exception e) { e.printStackTrace(); @@ -609,24 +598,14 @@ public class JSONFile extends AlignFile implements ComplexAlignFile } } - public String getGlobalColorScheme() - { - return globalColorScheme; - } - - public void setGlobalColorScheme(String globalColorScheme) - { - this.globalColorScheme = globalColorScheme; - } - - public ColourSchemeI getColourScheme() + public String getGlobalColourScheme() { - return colourScheme; + return globalColourScheme; } - public void setColourScheme(ColourSchemeI colourScheme) + public void setGlobalColorScheme(String globalColourScheme) { - this.colourScheme = colourScheme; + this.globalColourScheme = globalColourScheme; } @Override @@ -662,7 +641,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile annotations.add(annot); } } - globalColorScheme = ColourSchemeProperty.getColourName(viewport + globalColourScheme = ColourSchemeProperty.getColourName(viewport .getGlobalColourScheme()); setDisplayedFeatures(viewport.getFeaturesDisplayed()); showSeqFeatures = viewport.isShowSequenceFeatures(); diff --git a/src/jalview/json/binding/biojson/v1/ColourSchemeMapper.java b/src/jalview/json/binding/biojson/v1/ColourSchemeMapper.java index de4ba8d..aeab34c 100644 --- a/src/jalview/json/binding/biojson/v1/ColourSchemeMapper.java +++ b/src/jalview/json/binding/biojson/v1/ColourSchemeMapper.java @@ -40,42 +40,60 @@ import jalview.schemes.ZappoColourScheme; public class ColourSchemeMapper { + private static ColourSchemeI csZappo, csTaylor, csNucleotide, csPurine, + csHelix, csTurn, csStrand, csBuried, csHydro, + csRNAInteractionType, csPID, csBlosum62 = null; + static + { + csZappo = new ZappoColourScheme(); + csTaylor = new TaylorColourScheme(); + csNucleotide = new NucleotideColourScheme(); + csPurine = new PurinePyrimidineColourScheme(); + csHelix = new HelixColourScheme(); + csTurn = new TurnColourScheme(); + csStrand = new StrandColourScheme(); + csBuried = new BuriedColourScheme(); + csHydro = new HydrophobicColourScheme(); + csRNAInteractionType = new RNAInteractionColourScheme(); + csPID = new PIDColourScheme(); + csBlosum62 = new Blosum62ColourScheme(); + } public static ColourSchemeI getJalviewColourScheme( String colourSchemeName, AnnotatedCollectionI annotCol) { switch (colourSchemeName.toUpperCase()) { case "ZAPPO": - return new ZappoColourScheme(); + return csZappo; case "TAYLOR": - return new TaylorColourScheme(); + return csTaylor; case "NUCLEOTIDE": - return new NucleotideColourScheme(); + return csNucleotide; case "PURINE": case "PURINE/PYRIMIDINE": - return new PurinePyrimidineColourScheme(); + return csPurine; case "HELIX": case "HELIX PROPENSITY": - return new HelixColourScheme(); + return csHelix; case "TURN": case "TURN PROPENSITY": - return new TurnColourScheme(); + return csTurn; case "STRAND": case "STRAND PROPENSITY": - return new StrandColourScheme(); + return csStrand; case "BURIED": case "BURIED INDEX": - return new BuriedColourScheme(); + return csBuried; case "HYDRO": case "HYDROPHOBIC": - return new HydrophobicColourScheme(); + return csHydro; case "RNA INTERACTION TYPE": - return new RNAInteractionColourScheme(); + return csRNAInteractionType; case "PID": case "% IDENTITY": - return new PIDColourScheme(); + return csPID; case "BLOSUM62": - return new Blosum62ColourScheme(); + return csBlosum62; case "T-COFFEE SCORES": return (annotCol != null) ? new TCoffeeColourScheme(annotCol) : null; case "RNA HELICES": diff --git a/test/jalview/io/JSONFileTest.java b/test/jalview/io/JSONFileTest.java index 4371ff9..4c2757f 100644 --- a/test/jalview/io/JSONFileTest.java +++ b/test/jalview/io/JSONFileTest.java @@ -35,7 +35,6 @@ import jalview.datamodel.SequenceI; import jalview.gui.AlignFrame; import jalview.json.binding.biojson.v1.ColourSchemeMapper; import jalview.schemes.ColourSchemeI; -import jalview.schemes.ZappoColourScheme; import java.io.IOException; import java.util.ArrayList; @@ -235,7 +234,10 @@ public class JSONFileTest jf.getColumnSelection(), AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); af.getViewport().setShowSequenceFeatures(jf.isShowSeqFeatures()); - af.changeColour(jf.getColourScheme()); + String colourSchemeName = jf.getGlobalColourScheme(); + ColourSchemeI cs = ColourSchemeMapper.getJalviewColourScheme( + colourSchemeName, alignment); + af.changeColour(cs); af.getViewport().setFeaturesDisplayed(jf.getDisplayedFeatures()); formatAdapter = new AppletFormatAdapter(af.alignPanel, exportSettings); @@ -318,11 +320,13 @@ public class JSONFileTest @Test(groups = { "Functional" }) public void colorSchemeTest() { - Assert.assertNotNull(testJsonFile.getColourScheme(), + Assert.assertNotNull(testJsonFile.getGlobalColourScheme(), "Colourscheme is null, parsing failed!"); - Assert.assertTrue( - testJsonFile.getColourScheme() instanceof ZappoColourScheme, + Assert.assertEquals(testJsonFile.getGlobalColourScheme(), "Zappo", "Zappo colour scheme expected!"); + // Assert.assertTrue( + // testJsonFile.getGlobalColourScheme() instanceof ZappoColourScheme, + // "Zappo colour scheme expected!"); } @Test(groups = { "Functional" }) -- 1.7.10.2