From 22a631d0234218b52b7adeeb28deee5e12026075 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Mon, 1 May 2017 16:44:23 +0100 Subject: [PATCH] JAL-2489 JAL-2371 reinstate calls to ColourSchemeProperty.getColourName() to handle null case --- examples/testdata/example_annot_file.jva | 2 +- src/jalview/io/AnnotationFile.java | 30 +++++++------ src/jalview/io/JSONFile.java | 9 ++-- test/jalview/io/AnnotationFileIOTest.java | 1 + test/jalview/io/JSONFileTest.java | 66 ++++++++++++++++++++++++++--- 5 files changed, 82 insertions(+), 26 deletions(-) diff --git a/examples/testdata/example_annot_file.jva b/examples/testdata/example_annot_file.jva index 794f42b..1779247 100644 --- a/examples/testdata/example_annot_file.jva +++ b/examples/testdata/example_annot_file.jva @@ -18,5 +18,5 @@ SEQUENCE_GROUP Group_A 30 50 * SEQUENCE_GROUP Group_B 1 351 2-5 SEQUENCE_GROUP Group_C 12 14 -1 seq1 seq2 seq3 PROPERTIES Group_A description=This is the description colour=Helix Propensity pidThreshold=0 outlineColour=red displayBoxes=true displayText=false colourText=false textCol1=black textCol2=black textColThreshold=0 -PROPERTIES Group_B outlineColour=red +PROPERTIES Group_B outlineColour=red colour=None PROPERTIES Group_C colour=Clustal diff --git a/src/jalview/io/AnnotationFile.java b/src/jalview/io/AnnotationFile.java index 9a4071d..ef903e3 100755 --- a/src/jalview/io/AnnotationFile.java +++ b/src/jalview/io/AnnotationFile.java @@ -109,23 +109,24 @@ public class AnnotationFile */ public class ViewDef { - public String viewname; + // TODO this class is not used - remove? + public final String viewname; - public HiddenSequences hidseqs; + public final HiddenSequences hidseqs; - public ColumnSelection hiddencols; + public final ColumnSelection hiddencols; - public Vector visibleGroups; + // public final Vector visibleGroups; - public Hashtable hiddenRepSeqs; + public final Hashtable hiddenRepSeqs; - public ViewDef(String viewname, HiddenSequences hidseqs, - ColumnSelection hiddencols, Hashtable hiddenRepSeqs) + public ViewDef(String vname, HiddenSequences hseqs, + ColumnSelection hcols, Hashtable hRepSeqs) { - this.viewname = viewname; - this.hidseqs = hidseqs; - this.hiddencols = hiddencols; - this.hiddenRepSeqs = hiddenRepSeqs; + this.viewname = vname; + this.hidseqs = hseqs; + this.hiddencols = hcols; + this.hiddenRepSeqs = hRepSeqs; } } @@ -151,7 +152,7 @@ public class AnnotationFile } if (list == null) { - list = view.visibleGroups; + // list = view.visibleGroups; } if (cs == null) { @@ -536,7 +537,7 @@ public class AnnotationFile return false; } - public void printGroups(List list) + protected void printGroups(List list) { SequenceI seqrep = null; for (SequenceGroup sg : list) @@ -582,7 +583,8 @@ public class AnnotationFile if (sg.cs != null) { text.append("colour="); - text.append(sg.cs.toString()); + text.append(ColourSchemeProperty.getColourName(sg.cs + .getColourScheme())); text.append("\t"); if (sg.cs.getThreshold() != 0) { diff --git a/src/jalview/io/JSONFile.java b/src/jalview/io/JSONFile.java index 583bbc0..20148b4 100644 --- a/src/jalview/io/JSONFile.java +++ b/src/jalview/io/JSONFile.java @@ -47,6 +47,7 @@ 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.schemes.JalviewColourScheme; import jalview.schemes.ResidueColourScheme; import jalview.util.ColorUtils; @@ -240,8 +241,8 @@ public class JSONFile extends AlignFile implements ComplexAlignFile { SequenceGrpPojo seqGrpPojo = new SequenceGrpPojo(); seqGrpPojo.setGroupName(seqGrp.getName()); - seqGrpPojo.setColourScheme(seqGrp.getColourScheme() - .getSchemeName()); + seqGrpPojo.setColourScheme(ColourSchemeProperty + .getColourName(seqGrp.getColourScheme())); seqGrpPojo.setColourText(seqGrp.getColourText()); seqGrpPojo.setDescription(seqGrp.getDescription()); seqGrpPojo.setDisplayBoxes(seqGrp.getDisplayBoxes()); @@ -767,8 +768,8 @@ public class JSONFile extends AlignFile implements ComplexAlignFile } } } - globalColourScheme = (viewport.getGlobalColourScheme() == null) ? ResidueColourScheme.NONE - : viewport.getGlobalColourScheme().getSchemeName(); + globalColourScheme = ColourSchemeProperty.getColourName(viewport + .getGlobalColourScheme()); setDisplayedFeatures(viewport.getFeaturesDisplayed()); showSeqFeatures = viewport.isShowSequenceFeatures(); diff --git a/test/jalview/io/AnnotationFileIOTest.java b/test/jalview/io/AnnotationFileIOTest.java index 885c673..c3aa13e 100644 --- a/test/jalview/io/AnnotationFileIOTest.java +++ b/test/jalview/io/AnnotationFileIOTest.java @@ -124,6 +124,7 @@ public class AnnotationFileIOTest DataSourceType.FILE)); AnnotationFile aff = new AnnotationFile(); + // ViewDef is not used by Jalview ViewDef v = aff.new ViewDef(null, al.getHiddenSequences(), cs, new Hashtable()); String anfileout = new AnnotationFile().printAnnotations( diff --git a/test/jalview/io/JSONFileTest.java b/test/jalview/io/JSONFileTest.java index 4e4abe9..acde68d 100644 --- a/test/jalview/io/JSONFileTest.java +++ b/test/jalview/io/JSONFileTest.java @@ -130,13 +130,14 @@ public class JSONFileTest expectedSeqs.put(seq.getName(), seq); } - // create and add sequence groups - ArrayList grpSeqs = new ArrayList(); + // create and add a sequence group + List grpSeqs = new ArrayList(); grpSeqs.add(seqs[1]); grpSeqs.add(seqs[2]); grpSeqs.add(seqs[3]); grpSeqs.add(seqs[4]); - SequenceGroup seqGrp = new SequenceGroup(grpSeqs, "JGroup:1883305585", + SequenceGroup seqGrp = new SequenceGroup(grpSeqs, + "JGroup:1883305585", null, true, true, false, 21, 29); ColourSchemeI scheme = ColourSchemeMapper.getJalviewColourScheme( "zappo", seqGrp); @@ -340,11 +341,12 @@ public class JSONFileTest "Zappo colour scheme expected!"); } - @Test(groups = { "Functional" }) /** - * Test for bug JAL-2489, NPE when exporting BioJSON with global colour scheme set as 'None' + * Test for bug JAL-2489, NPE when exporting BioJSON with global colour + * scheme, and a group colour scheme, set as 'None' */ - public void testBioJSONRoundTripWithGlobalColourSchemeSetAsNone() + @Test(groups = { "Functional" }) + public void testBioJSONRoundTripWithColourSchemeNone() { AppletFormatAdapter formatAdapter = new AppletFormatAdapter(); @@ -359,7 +361,14 @@ public class JSONFileTest bioJsonFile.getHiddenSequences(), bioJsonFile.getColumnSelection(), AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); - // Change colour scheme to 'None' and perform round trip + + /* + * Create a group on the alignment; + * Change global and group colour scheme to 'None' and perform round trip + */ + SequenceGroup sg = new SequenceGroup(); + sg.addSequence(_alignment.getSequenceAt(0), false); + sg.setColourScheme(null); ColourSchemeI cs = ColourSchemeMapper.getJalviewColourScheme( ResidueColourScheme.NONE, _alignment); alignFrame.changeColour(cs); @@ -556,4 +565,47 @@ public class JSONFileTest // System.out.println(">>>>>>>>>>>>>> features matched : " + matched); return matched; } + + /** + * Test group roundtrip with null (None) group colour scheme + * + * @throws IOException + */ + @Test(groups = { "Functional" }) + public void testGrpParsed_colourNone() throws IOException + { + AlignmentI copy = new Alignment(testAlignment); + SequenceGroup sg = testAlignment.getGroups().get(0); + SequenceGroup copySg = new SequenceGroup(new ArrayList(), + sg.getName(), + null, sg.getDisplayBoxes(), sg.getDisplayText(), + sg.getColourText(), sg.getStartRes(), sg.getEndRes()); + for (SequenceI seq : sg.getSequences()) + { + int seqIndex = testAlignment.findIndex(seq); + copySg.addSequence(copy.getSequenceAt(seqIndex), false); + } + copy.addGroup(copySg); + + AlignFrame af = new AlignFrame(copy, copy.getWidth(), copy.getHeight()); + AppletFormatAdapter formatAdapter = new AppletFormatAdapter( + af.alignPanel); + String jsonOutput = formatAdapter.formatSequences(FileFormat.Json, + copy, false); + formatAdapter = new AppletFormatAdapter(); + AlignmentI newAlignment = formatAdapter.readFile(jsonOutput, + DataSourceType.PASTE, FileFormat.Json); + + Assert.assertNotNull(newAlignment.getGroups()); + for (SequenceGroup seqGrp : newAlignment.getGroups()) + { + SequenceGroup expectedGrp = expectedGrps.get(seqGrp.getName()); + AssertJUnit.assertTrue( + "Failed SequenceGroup Test for >>> " + seqGrp.getName(), + isGroupMatched(expectedGrp, seqGrp)); + passedCount++; + } + AssertJUnit.assertEquals("Some SequenceGroups did not pass the test", + TEST_GRP_HEIGHT, passedCount); + } } -- 1.7.10.2