Merge remote-tracking branch 'origin/develop' into features/JAL-2388OverviewWindow
authorkiramt <k.mourao@dundee.ac.uk>
Wed, 26 Apr 2017 13:36:03 +0000 (14:36 +0100)
committerkiramt <k.mourao@dundee.ac.uk>
Wed, 26 Apr 2017 13:36:03 +0000 (14:36 +0100)
src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java
src/jalview/io/JSONFile.java
test/jalview/io/JSONFileTest.java

index 3ae7593..870c4fe 100644 (file)
@@ -172,8 +172,6 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
       if (getSsm() != null)
       {
         getSsm().addStructureViewerListener(this);
-        // ssm.addSelectionListener(this);
-        refreshGUI();
       }
       return true;
     } catch (Exception q)
index 8dbede6..5a00755 100644 (file)
@@ -766,7 +766,8 @@ public class JSONFile extends AlignFile implements ComplexAlignFile
         }
       }
     }
-    globalColourScheme = viewport.getGlobalColourScheme().getSchemeName();
+    globalColourScheme = (viewport.getGlobalColourScheme() == null) ? ResidueColourScheme.NONE
+            : viewport.getGlobalColourScheme().getSchemeName();
     setDisplayedFeatures(viewport.getFeaturesDisplayed());
     showSeqFeatures = viewport.isShowSequenceFeatures();
 
index 1917097..1081223 100644 (file)
@@ -36,6 +36,7 @@ import jalview.gui.AlignFrame;
 import jalview.gui.JvOptionPane;
 import jalview.json.binding.biojson.v1.ColourSchemeMapper;
 import jalview.schemes.ColourSchemeI;
+import jalview.schemes.ResidueColourScheme;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -90,6 +91,8 @@ public class JSONFileTest
 
   private JSONFile jf;
 
+  private AlignExportSettingI exportSettings;
+
   @BeforeTest(alwaysRun = true)
   public void setup() throws Exception
   {
@@ -193,7 +196,7 @@ public class JSONFileTest
     TEST_ANOT_HEIGHT = expectedAnnots.size();
     TEST_CS_HEIGHT = expectedColSel.getHiddenRegions().size();
 
-    AlignExportSettingI exportSettings = new AlignExportSettingI()
+    exportSettings = new AlignExportSettingI()
     {
       @Override
       public boolean isExportHiddenSequences()
@@ -338,6 +341,50 @@ public class JSONFileTest
   }
 
   @Test(groups = { "Functional" })
+  /**
+   * Test for bug JAL-2489, NPE when exporting BioJSON with global colour scheme set as 'None'
+   */
+  public void testBioJSONRoundTripWithGlobalColourSchemeSetAsNone()
+  {
+    AppletFormatAdapter formatAdapter = new AppletFormatAdapter();
+
+    Alignment _alignment;
+    try
+    {
+      // load example BioJSON file
+      _alignment = (Alignment) formatAdapter.readFile(TEST_JSON_FILE,
+              DataSourceType.FILE, FileFormat.Json);
+      JSONFile bioJsonFile = (JSONFile) formatAdapter.getAlignFile();
+      AlignFrame alignFrame = new AlignFrame(_alignment,
+              bioJsonFile.getHiddenSequences(),
+              bioJsonFile.getColumnSelection(), AlignFrame.DEFAULT_WIDTH,
+              AlignFrame.DEFAULT_HEIGHT);
+      // Change colour scheme to 'None' and perform round trip
+      ColourSchemeI cs = ColourSchemeMapper.getJalviewColourScheme(
+              ResidueColourScheme.NONE, _alignment);
+      alignFrame.changeColour(cs);
+      alignFrame.getViewport().setFeaturesDisplayed(
+              bioJsonFile.getDisplayedFeatures());
+      formatAdapter = new AppletFormatAdapter(alignFrame.alignPanel,
+              exportSettings);
+      // export BioJSON string
+      String jsonOutput = formatAdapter.formatSequences(FileFormat.Json,
+              alignFrame.alignPanel.getAlignment(), false);
+      // read back Alignment from BioJSON string
+      formatAdapter = new AppletFormatAdapter();
+      formatAdapter.readFile(jsonOutput, DataSourceType.PASTE,
+              FileFormat.Json);
+      // assert 'None' colour scheme is retained after round trip
+      JSONFile _bioJsonFile = (JSONFile) formatAdapter.getAlignFile();
+      Assert.assertEquals(_bioJsonFile.getGlobalColourScheme(),
+              ResidueColourScheme.NONE);
+    } catch (IOException e)
+    {
+      e.printStackTrace();
+    }
+  }
+
+  @Test(groups = { "Functional" })
   public void isShowSeqFeaturesSet()
   {
     Assert.assertTrue(testJsonFile.isShowSeqFeatures(),