/* * 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.ext.rbvi.chimera; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; import jalview.gui.JvOptionPane; import java.awt.Color; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; public class ChimeraCommandsTest { @BeforeClass(alwaysRun = true) public void setUpJvOptionPane() { JvOptionPane.setInteractiveMode(false); JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); } @Test(groups = { "Functional" }) public void testBuildColourCommands() { Map map = new LinkedHashMap(); ChimeraCommands.addRange(map, Color.blue, 0, 2, 5, "A"); ChimeraCommands.addRange(map, Color.blue, 0, 7, 7, "B"); ChimeraCommands.addRange(map, Color.blue, 0, 9, 23, "A"); ChimeraCommands.addRange(map, Color.blue, 1, 1, 1, "A"); ChimeraCommands.addRange(map, Color.blue, 1, 4, 7, "B"); ChimeraCommands.addRange(map, Color.yellow, 1, 8, 8, "A"); ChimeraCommands.addRange(map, Color.yellow, 1, 3, 5, "A"); ChimeraCommands.addRange(map, Color.red, 0, 3, 5, "A"); ChimeraCommands.addRange(map, Color.red, 0, 6, 9, "A"); // Colours should appear in the Chimera command in the order in which // they were added; within colour, by model, by chain, ranges in start order String command = ChimeraCommands.buildColourCommands(map).get(0); assertEquals( command, "color #0000ff #0:2-5.A,9-23.A,7.B|#1:1.A,4-7.B; color #ffff00 #1:3-5.A,8.A; color #ff0000 #0:3-9.A"); } @Test(groups = { "Functional" }) public void testBuildSetAttributeCommands() { /* * make a map of { featureType, {featureValue, {residue range specification } } } */ Map> featuresMap = new LinkedHashMap>(); Map featureValues = new HashMap(); /* * start with just one feature/value... */ featuresMap.put("chain", featureValues); ChimeraCommands.addRange(featureValues, "X", 0, 8, 20, "A"); List commands = ChimeraCommands .buildSetAttributeCommands(featuresMap); assertEquals(1, commands.size()); /* * feature name gets a jv_ namespace prefix * feature value is quoted in case it contains spaces */ assertEquals(commands.get(0), "setattr r jv_chain \"X\" #0:8-20.A"); // add same feature value, overlapping range ChimeraCommands.addRange(featureValues, "X", 0, 3, 9, "A"); // same feature value, contiguous range ChimeraCommands.addRange(featureValues, "X", 0, 21, 25, "A"); commands = ChimeraCommands.buildSetAttributeCommands(featuresMap); assertEquals(1, commands.size()); assertEquals(commands.get(0), "setattr r jv_chain \"X\" #0:3-25.A"); // same feature value and model, different chain ChimeraCommands.addRange(featureValues, "X", 0, 21, 25, "B"); // same feature value and chain, different model ChimeraCommands.addRange(featureValues, "X", 1, 26, 30, "A"); commands = ChimeraCommands.buildSetAttributeCommands(featuresMap); assertEquals(1, commands.size()); assertEquals(commands.get(0), "setattr r jv_chain \"X\" #0:3-25.A,21-25.B|#1:26-30.A"); // same feature, different value ChimeraCommands.addRange(featureValues, "Y", 0, 40, 50, "A"); commands = ChimeraCommands.buildSetAttributeCommands(featuresMap); assertEquals(2, commands.size()); // commands are ordered by feature type but not by value // so use contains to test for the expected command: assertTrue(commands .contains("setattr r jv_chain \"X\" #0:3-25.A,21-25.B|#1:26-30.A")); assertTrue(commands.contains("setattr r jv_chain \"Y\" #0:40-50.A")); featuresMap.clear(); featureValues.clear(); featuresMap.put("side-chain binding!", featureValues); ChimeraCommands.addRange(featureValues, "metal ion!", 0, 7, 15, "A"); // feature names are sanitised to change space or hyphen to underscore commands = ChimeraCommands.buildSetAttributeCommands(featuresMap); assertTrue(commands .contains("setattr r jv_side_chain_binding_ \"metal ion!\" #0:7-15.A")); } /** * Tests for the method that prefixes and sanitises a feature name so it can * be used as a valid, namespaced attribute name in Chimera */ @Test(groups = { "Functional" }) public void testMakeAttributeName() { assertEquals(ChimeraCommands.makeAttributeName(null), "jv_"); assertEquals(ChimeraCommands.makeAttributeName(""), "jv_"); assertEquals(ChimeraCommands.makeAttributeName("helix"), "jv_helix"); assertEquals(ChimeraCommands.makeAttributeName("Hello World 24"), "jv_Hello_World_24"); assertEquals( ChimeraCommands.makeAttributeName("!this is-a_very*{odd(name"), "jv__this_is_a_very__odd_name"); // name ending in color gets underscore appended assertEquals(ChimeraCommands.makeAttributeName("helixColor"), "jv_helixColor_"); } }