1 package jalview.ext.rbvi.chimera;
3 import static org.testng.Assert.assertEquals;
4 import static org.testng.Assert.assertNotNull;
6 import java.util.Arrays;
7 import java.util.HashMap;
11 import org.testng.annotations.BeforeTest;
12 import org.testng.annotations.Test;
14 import ext.edu.ucsf.rbvi.strucviz2.ChimeraModel;
15 import ext.edu.ucsf.rbvi.strucviz2.StructureManager.ModelType;
16 import jalview.datamodel.PDBEntry;
17 import jalview.datamodel.SequenceI;
18 import jalview.gui.AlignFrame;
19 import jalview.gui.AlignViewport;
20 import jalview.gui.ChimeraViewFrame;
21 import jalview.gui.JalviewChimeraBindingModel;
22 import jalview.io.DataSourceType;
23 import jalview.io.FileLoader;
24 import jalview.structure.StructureCommandI;
25 import jalview.structure.StructureMapping;
26 import jalview.structure.StructureSelectionManager;
27 import junit.extensions.PA;
29 public class JalviewChimeraBindingTest
31 private AlignFrame af;
33 @BeforeTest(alwaysRun = true)
36 af = new FileLoader().LoadFileWaitTillLoaded("examples/uniref50.fa",
40 @Test(groups = "Functional")
41 public void testBuildShowStructuresCommand()
43 AlignViewport av = af.getViewport();
44 PDBEntry[] pdbs = new PDBEntry[] {};
45 StructureSelectionManager ssm = new StructureSelectionManager();
46 SequenceI seq1 = av.getAlignment().findSequenceMatch("FER1_SPIOL")[0];
48 SequenceI seq2 = av.getAlignment().findSequenceMatch("FER2_ARATH")[0];
50 SequenceI[][] seqs = new SequenceI[][] { { seq1 }, { seq2 } };
51 JalviewChimeraBindingModel testee = new JalviewChimeraBindingModel(
52 new ChimeraViewFrame(),
53 ssm, pdbs, seqs, null);
56 * with no structures mapped
58 StructureCommandI cmd = testee.buildShowStructuresCommand(av, true);
59 assertEquals(cmd.getCommand(), "~display; ribbon; focus");
60 cmd = testee.buildShowStructuresCommand(av, false);
61 assertEquals(cmd.getCommand(), "~display; ribbon");
64 * stub out a structure with chains A and B
66 Map<String, List<ChimeraModel>> chimeraMaps = (Map<String, List<ChimeraModel>>) PA
67 .getValue(testee, "chimeraMaps");
68 ChimeraModel model0 = new ChimeraModel("1A70", ModelType.PDB_MODEL, 0,
70 chimeraMaps.put("1a70.pdb", Arrays.asList(model0));
71 ChimeraModel model1 = new ChimeraModel("4ZHO", ModelType.PDB_MODEL, 1,
73 chimeraMaps.put("4zho.pdb", Arrays.asList(model1));
75 Map<String, String> chainFiles = (Map<String, String>) PA
76 .getValue(testee, "chainFile");
77 chainFiles.put("1A70:A", "1a70.pdb");
78 chainFiles.put("1A70:B", "1a70.pdb");
79 chainFiles.put("4ZHO:B", "4zho.pdb");
80 chainFiles.put("4ZHO:C", "4zho.pdb");
83 * map FER1_SPIOL residues 51-100 to residues 1-50 (atoms 1-250) in 1A70
84 * and residues 110-147 to structure residues 60-97
85 * (in fact there is no gap, added here for test purposes)
87 HashMap<Integer, int[]> map = new HashMap<>();
88 for (int pos = 51; pos <= 100; pos++)
90 map.put(pos, new int[] { pos - 50, 5 * (pos - 50) });
92 for (int pos = 110; pos <= 147; pos++)
94 map.put(pos, new int[] { pos - 50, 5 * (pos - 50) });
96 StructureMapping sm1 = new StructureMapping(seq1, "1a70.pdb", "1A70",
98 ssm.addStructureMapping(sm1);
101 * map FER2_ARATH residues 53-148 to residues 2-97 in 4ZHO
103 map = new HashMap<>();
104 for (int pos = 53; pos <= 148; pos++)
106 map.put(pos, new int[] { pos - 51, 5 * (pos - 51) });
108 StructureMapping sm2 = new StructureMapping(seq2, "4zho.pdb", "4ZHO",
110 ssm.addStructureMapping(sm2);
113 * select chain A only (hide chain B)
115 List<String> chainsToHide = (List<String>) PA.getValue(testee, "chainsToHide");
116 chainsToHide.add("1A70:B");
117 chainsToHide.add("4ZHO:C");
118 cmd = testee.buildShowStructuresCommand(av, false);
119 assertEquals(cmd.getCommand(),
120 "~display; ribbon; ~ribbon #0:.B; ~ribbon #1:.C");
123 * show alignment only, no chains hidden
125 chainsToHide.clear();
126 testee.setShowAlignmentOnly(true);
127 cmd = testee.buildShowStructuresCommand(av, false);
130 "~display; ~ribbon; ribbon #0:1-50.A,60-97.A|#1:2-97.B");
133 * now with a chain hidden
135 chainsToHide.add("4ZHO:C");
136 cmd = testee.buildShowStructuresCommand(av, false);
137 String expected = "~display; ~ribbon; ribbon #0:1-50.A,60-97.A|#1:2-97.B; ~ribbon #1:.C";
138 assertEquals(cmd.getCommand(), expected);
141 * hide columns in the mapped region - should not change the command (yet)
143 int fromCol = seq1.findIndex(60); // structure residue 10
144 int toCol = seq1.findIndex(70); // structure residue 20
145 av.hideColumns(fromCol - 1, toCol - 1);
146 cmd = testee.buildShowStructuresCommand(av, false);
147 assertEquals(cmd.getCommand(), expected);
150 * select 'hide hidden columns'
151 * command should now exclude these in both mapped sequences
153 testee.setHideHiddenRegions(true);
154 cmd = testee.buildShowStructuresCommand(av, false);
155 expected = "~display; ~ribbon; ribbon #0:1-9.A,21-50.A,60-97.A|#1:2-10.B,22-97.B; ~ribbon #1:.C";
156 assertEquals(cmd.getCommand(), expected);
159 * deselect 'show alignment only'
160 * hide hidden columns is now ignored
162 testee.setShowAlignmentOnly(false);
163 cmd = testee.buildShowStructuresCommand(av, false);
164 assertEquals(cmd.getCommand(), "~display; ribbon; ~ribbon #1:.C");