X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fext%2Frbvi%2Fchimera%2FChimeraCommandsTest.java;fp=test%2Fjalview%2Fext%2Frbvi%2Fchimera%2FChimeraCommandsTest.java;h=fb442e31e8f8bf02b4442335cffbd928bb53d425;hb=4762b29420ed4df01b55a8afe5ab05467aaf41a9;hp=ffb886c243252d9ca59f41a5791e28443410f5e8;hpb=29c183b0d0de9f6f9f94d2b528d10e20b1891684;p=jalview.git diff --git a/test/jalview/ext/rbvi/chimera/ChimeraCommandsTest.java b/test/jalview/ext/rbvi/chimera/ChimeraCommandsTest.java index ffb886c..fb442e3 100644 --- a/test/jalview/ext/rbvi/chimera/ChimeraCommandsTest.java +++ b/test/jalview/ext/rbvi/chimera/ChimeraCommandsTest.java @@ -20,17 +20,16 @@ */ package jalview.ext.rbvi.chimera; -import static org.testng.AssertJUnit.assertEquals; -import static org.testng.AssertJUnit.assertTrue; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; import jalview.gui.JvOptionPane; import java.awt.Color; -import java.util.Arrays; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.SortedMap; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -46,58 +45,10 @@ public class ChimeraCommandsTest } @Test(groups = { "Functional" }) - public void testAddColourRange() - { - Map>>> map = new LinkedHashMap>>>(); - ChimeraCommands.addColourRange(map, Color.pink, 1, 2, 4, "A"); - ChimeraCommands.addColourRange(map, Color.pink, 1, 8, 8, "A"); - ChimeraCommands.addColourRange(map, Color.pink, 1, 5, 7, "B"); - ChimeraCommands.addColourRange(map, Color.red, 1, 3, 5, "A"); - ChimeraCommands.addColourRange(map, Color.red, 0, 1, 4, "B"); - ChimeraCommands.addColourRange(map, Color.orange, 0, 5, 9, "C"); - - // three colours mapped - assertEquals(3, map.keySet().size()); - - // Red has two models, Pink and Orange one each - assertEquals(2, map.get(Color.red).keySet().size()); - assertEquals(1, map.get(Color.orange).keySet().size()); - assertEquals(1, map.get(Color.pink).keySet().size()); - - // pink model 1 has two chains, red.0 / red.1 / orange.0 one each - assertEquals(2, map.get(Color.pink).get(1).keySet().size()); - assertEquals(1, map.get(Color.red).get(0).keySet().size()); - assertEquals(1, map.get(Color.red).get(1).keySet().size()); - assertEquals(1, map.get(Color.orange).get(0).keySet().size()); - - // inspect positions - List posList = map.get(Color.pink).get(1).get("A"); - assertEquals(2, posList.size()); - assertTrue(Arrays.equals(new int[] { 2, 4 }, posList.get(0))); - assertTrue(Arrays.equals(new int[] { 8, 8 }, posList.get(1))); - - posList = map.get(Color.pink).get(1).get("B"); - assertEquals(1, posList.size()); - assertTrue(Arrays.equals(new int[] { 5, 7 }, posList.get(0))); - - posList = map.get(Color.red).get(0).get("B"); - assertEquals(1, posList.size()); - assertTrue(Arrays.equals(new int[] { 1, 4 }, posList.get(0))); - - posList = map.get(Color.red).get(1).get("A"); - assertEquals(1, posList.size()); - assertTrue(Arrays.equals(new int[] { 3, 5 }, posList.get(0))); - - posList = map.get(Color.orange).get(0).get("C"); - assertEquals(1, posList.size()); - assertTrue(Arrays.equals(new int[] { 5, 9 }, posList.get(0))); - } - - @Test(groups = { "Functional" }) public void testBuildColourCommands() { - Map>>> map = new LinkedHashMap>>>(); + Map map = new LinkedHashMap(); ChimeraCommands.addColourRange(map, Color.blue, 0, 2, 5, "A"); ChimeraCommands.addColourRange(map, Color.blue, 0, 7, 7, "B"); ChimeraCommands.addColourRange(map, Color.blue, 0, 9, 23, "A"); @@ -106,13 +57,96 @@ public class ChimeraCommandsTest ChimeraCommands.addColourRange(map, Color.yellow, 1, 8, 8, "A"); ChimeraCommands.addColourRange(map, Color.yellow, 1, 3, 5, "A"); ChimeraCommands.addColourRange(map, Color.red, 0, 3, 5, "A"); + ChimeraCommands.addColourRange(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, and positions as - // added + // they were added; within colour, by model, by chain, ranges in start order String command = ChimeraCommands.buildColourCommands(map).get(0); assertEquals( - "color #0000ff #0:2-5.A,9-23.A,7.B|#1:1.A,4-7.B; color #ffff00 #1:8.A,3-5.A; color #ff0000 #0:3-5.A", - command); + 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.addColourRange(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.addColourRange(featureValues, "X", 0, 3, 9, "A"); + // same feature value, contiguous range + ChimeraCommands.addColourRange(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.addColourRange(featureValues, "X", 0, 21, 25, "B"); + // same feature value and chain, different model + ChimeraCommands.addColourRange(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.addColourRange(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.addColourRange(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_"); } }