1 package jalview.ext.rbvi.chimera;
3 import static org.testng.Assert.assertEquals;
4 import static org.testng.Assert.assertNotNull;
6 import jalview.datamodel.PDBEntry;
7 import jalview.datamodel.SequenceI;
8 import jalview.gui.AlignFrame;
9 import jalview.gui.AlignViewport;
10 import jalview.gui.ChimeraViewFrame;
11 import jalview.gui.JalviewChimeraBindingModel;
12 import jalview.io.DataSourceType;
13 import jalview.io.FileLoader;
14 import jalview.structure.StructureMapping;
15 import jalview.structure.StructureSelectionManager;
17 import java.util.Arrays;
18 import java.util.HashMap;
19 import java.util.List;
22 import org.testng.annotations.BeforeTest;
23 import org.testng.annotations.Test;
25 import ext.edu.ucsf.rbvi.strucviz2.ChimeraModel;
26 import ext.edu.ucsf.rbvi.strucviz2.StructureManager.ModelType;
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 String cmd = testee.buildShowStructuresCommand(av, true);
59 assertEquals(cmd, "~display; ribbon; focus");
60 cmd = testee.buildShowStructuresCommand(av, false);
61 assertEquals(cmd, "~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, "~display; ribbon; ~ribbon #0:.B; ~ribbon #1:.C");
122 * show alignment only, no chains hidden
124 chainsToHide.clear();
125 testee.setShowAlignmentOnly(true);
126 cmd = testee.buildShowStructuresCommand(av, false);
128 "~display; ~ribbon; ribbon #0:1-50.A,60-97.A|#1:2-97.B");
131 * now with a chain hidden
133 chainsToHide.add("4ZHO:C");
134 cmd = testee.buildShowStructuresCommand(av, false);
135 String expected = "~display; ~ribbon; ribbon #0:1-50.A,60-97.A|#1:2-97.B; ~ribbon #1:.C";
136 assertEquals(cmd, expected);
139 * hide columns in the mapped region - should not change the command (yet)
141 int fromCol = seq1.findIndex(60); // structure residue 10
142 int toCol = seq1.findIndex(70); // structure residue 20
143 av.hideColumns(fromCol - 1, toCol - 1);
144 cmd = testee.buildShowStructuresCommand(av, false);
145 assertEquals(cmd, expected);
148 * select 'hide hidden columns'
149 * command should now exclude these in both mapped sequences
151 testee.setHideHiddenRegions(true);
152 cmd = testee.buildShowStructuresCommand(av, false);
153 expected = "~display; ~ribbon; ribbon #0:1-9.A,21-50.A,60-97.A|#1:2-10.B,22-97.B; ~ribbon #1:.C";
154 assertEquals(cmd, expected);
157 * deselect 'show alignment only'
158 * hide hidden columns is now ignored
160 testee.setShowAlignmentOnly(false);
161 cmd = testee.buildShowStructuresCommand(av, false);
162 assertEquals(cmd, "~display; ribbon; ~ribbon #1:.C");