2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.structures.models;
23 import static org.testng.Assert.assertEquals;
24 import static org.testng.Assert.assertFalse;
25 import static org.testng.Assert.assertNotNull;
26 import static org.testng.Assert.assertTrue;
28 import java.awt.Color;
29 import java.io.IOException;
30 import java.util.Arrays;
31 import java.util.BitSet;
32 import java.util.HashMap;
33 import java.util.List;
36 import org.testng.annotations.BeforeClass;
37 import org.testng.annotations.BeforeMethod;
38 import org.testng.annotations.Test;
40 import jalview.api.AlignmentViewPanel;
41 import jalview.api.SequenceRenderer;
42 import jalview.datamodel.Alignment;
43 import jalview.datamodel.AlignmentI;
44 import jalview.datamodel.ColumnSelection;
45 import jalview.datamodel.PDBEntry;
46 import jalview.datamodel.PDBEntry.Type;
47 import jalview.datamodel.Sequence;
48 import jalview.datamodel.SequenceI;
49 import jalview.ext.rbvi.chimera.ChimeraCommands;
50 import jalview.gui.AlignFrame;
51 import jalview.gui.JvOptionPane;
52 import jalview.gui.StructureViewer.ViewerType;
53 import jalview.io.DataSourceType;
54 import jalview.io.FileFormats;
55 import jalview.io.FileLoader;
56 import jalview.schemes.JalviewColourScheme;
57 import jalview.structure.AtomSpec;
58 import jalview.structure.AtomSpecModel;
59 import jalview.structure.StructureCommandI;
60 import jalview.structure.StructureCommandsI.AtomSpecType;
61 import jalview.structure.StructureMapping;
62 import jalview.structure.StructureSelectionManager;
63 import junit.extensions.PA;
66 * Unit tests for non-abstract methods of abstract base class
71 public class AAStructureBindingModelTest
74 @BeforeClass(alwaysRun = true)
75 public void setUpJvOptionPane()
77 JvOptionPane.setInteractiveMode(false);
78 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
82 * Scenario: Jalview has 4 sequences, corresponding to 1YCS (chains A and B), 3A6S|B, 1OOT|A
84 private static final String PDB_1 = "HEADER COMPLEX (ANTI-ONCOGENE/ANKYRIN REPEATS) 30-SEP-96 1YCS \n"
85 + "ATOM 2 CA VAL A 97 24.134 4.926 45.821 1.00 47.43 C \n"
86 + "ATOM 9 CA PRO A 98 25.135 8.584 46.217 1.00 41.60 C \n"
87 + "ATOM 16 CA SER A 99 28.243 9.596 44.271 1.00 39.63 C \n"
88 + "ATOM 22 CA GLN A 100 31.488 10.133 46.156 1.00 35.60 C \n"
89 // artificial jump in residue numbering to prove it is correctly
91 + "ATOM 31 CA LYS A 102 33.323 11.587 43.115 1.00 41.69 C \n"
92 + "ATOM 1857 CA GLU B 374 9.193 -16.005 95.870 1.00 54.22 C \n"
93 + "ATOM 1866 CA ILE B 375 7.101 -14.921 92.847 1.00 46.82 C \n"
94 + "ATOM 1874 CA VAL B 376 10.251 -13.625 91.155 1.00 47.80 C \n"
95 + "ATOM 1881 CA LYS B 377 11.767 -17.068 91.763 1.00 50.21 C \n"
96 + "ATOM 1890 CA PHE B 378 8.665 -18.948 90.632 1.00 44.85 C \n";
98 private static final String PDB_2 = "HEADER HYDROLASE 09-SEP-09 3A6S \n"
99 + "ATOM 2 CA MET B 1 15.366 -11.648 24.854 1.00 32.05 C \n"
100 + "ATOM 10 CA LYS B 2 16.846 -9.215 22.340 1.00 25.68 C \n"
101 + "ATOM 19 CA LYS B 3 15.412 -6.335 20.343 1.00 19.42 C \n"
102 + "ATOM 28 CA LEU B 4 15.629 -5.719 16.616 1.00 15.49 C \n"
103 + "ATOM 36 CA GLN B 5 14.412 -2.295 15.567 1.00 12.19 C \n";
105 private static final String PDB_3 = "HEADER STRUCTURAL GENOMICS 04-MAR-03 1OOT \n"
106 + "ATOM 2 CA SER A 7 29.427 3.330 -6.578 1.00 32.50 C \n"
107 + "ATOM 8 CA PRO A 8 29.975 3.340 -2.797 1.00 17.62 C \n"
108 + "ATOM 16 CA ALYS A 9 26.958 3.024 -0.410 0.50 8.78 C \n"
109 + "ATOM 33 CA ALA A 10 26.790 4.320 3.172 1.00 11.98 C \n"
110 + "ATOM 39 CA AVAL A 12 24.424 3.853 6.106 0.50 13.83 C \n";
113 * Multichain PDB with identical sequences imported - Binding should correctly
114 * recover chain mappings for each derived sequence
116 private static final String PDB_4_MC = "HEADER HYDROLASE 09-SEP-09 3A6S \n"
117 + "ATOM 2 CA MET A 1 15.366 -11.648 24.854 1.00 32.05 C \n"
118 + "ATOM 10 CA LYS A 2 16.846 -9.215 22.340 1.00 25.68 C \n"
119 + "ATOM 19 CA LYS A 3 15.412 -6.335 20.343 1.00 19.42 C \n"
120 + "ATOM 28 CA LEU A 4 15.629 -5.719 16.616 1.00 15.49 C \n"
121 + "ATOM 36 CA GLN A 5 14.412 -2.295 15.567 1.00 12.19 C \n"
122 + "ATOM 1030 CA MET B 1 18.869 -7.572 3.432 1.00 31.52 C \n"
123 + "ATOM 1038 CA LYS B 2 19.182 -10.025 6.313 1.00 26.41 C \n"
124 + "ATOM 1047 CA LYS B 3 17.107 -12.963 7.534 1.00 19.71 C \n"
125 + "ATOM 1056 CA LEU B 4 16.142 -13.579 11.164 1.00 14.81 C \n"
126 + "ATOM 1064 CA GLN B 5 14.648 -17.005 11.785 1.00 13.38 C \n";
128 // TODO: JAL-2227 - import mmCIF PISA assembly & identify master/copy chains
130 @Test(groups= {"Functional"})
131 public void testImportPDBPreservesChainMappings() throws IOException
133 AlignmentI importedAl = new jalview.io.FormatAdapter().readFile(
134 PDB_4_MC, DataSourceType.PASTE, FileFormats.getInstance()
135 .forName(jalview.io.FileFormat.PDB.toString()));
136 // ideally, we would match on the actual data for the 'File' handle for
138 // see JAL-623 - pasting is still not correctly handled...
139 PDBEntry importedPDB = new PDBEntry("3A6S", "", Type.PDB,
141 AAStructureBindingModel binder = new AAStructureBindingModel(
142 new StructureSelectionManager(), new PDBEntry[]
145 { importedAl.getSequencesArray() }, null)
149 public void updateColours(Object source)
154 public void releaseReferences(Object svl)
159 public String[] getStructureFiles()
165 public void highlightAtoms(List<AtomSpec> atoms)
170 public SequenceRenderer getSequenceRenderer(AlignmentViewPanel alignment)
176 protected List<String> executeCommand(StructureCommandI command,
183 protected String getModelIdForFile(String chainId)
189 protected ViewerType getViewerType()
194 String[][] chains = binder.getChains();
195 assertFalse(chains == null || chains[0] == null,
196 "No chains discovered by binding");
197 assertEquals(chains[0].length, 2);
198 assertEquals(chains[0][0], "A");
199 assertEquals(chains[0][1], "B");
201 AAStructureBindingModel testee;
203 AlignmentI al = null;
206 * Set up test conditions with three aligned sequences,
208 @BeforeMethod(alwaysRun = true)
211 SequenceI seq1a = new Sequence("1YCS|A", "-VPSQK");
212 SequenceI seq1b = new Sequence("1YCS|B", "EIVKF-");
213 SequenceI seq2 = new Sequence("3A6S", "MK-KLQ");
214 SequenceI seq3 = new Sequence("1OOT", "SPK-AV");
215 al = new Alignment(new SequenceI[] { seq1a, seq1b, seq2, seq3 });
219 * give pdb files the name generated by Jalview for PASTE source
221 PDBEntry[] pdbFiles = new PDBEntry[3];
222 pdbFiles[0] = new PDBEntry("1YCS", "A", Type.PDB, "INLINE1YCS");
223 pdbFiles[1] = new PDBEntry("3A6S", "B", Type.PDB, "INLINE3A6S");
224 pdbFiles[2] = new PDBEntry("1OOT", "A", Type.PDB, "INLINE1OOT");
225 SequenceI[][] seqs = new SequenceI[3][];
226 seqs[0] = new SequenceI[] { seq1a, seq1b };
227 seqs[1] = new SequenceI[] { seq2 };
228 seqs[2] = new SequenceI[] { seq3 };
229 StructureSelectionManager ssm = new StructureSelectionManager();
231 ssm.setMapping(new SequenceI[] { seq1a, seq1b }, null, PDB_1,
232 DataSourceType.PASTE, null);
233 ssm.setMapping(new SequenceI[] { seq2 }, null, PDB_2,
234 DataSourceType.PASTE, null);
235 ssm.setMapping(new SequenceI[] { seq3 }, null, PDB_3,
236 DataSourceType.PASTE, null);
238 testee = newBindingModel(pdbFiles, seqs, ssm, null);
242 * A helper method to construct the test target object
249 protected AAStructureBindingModel newBindingModel(PDBEntry[] pdbFiles,
251 StructureSelectionManager ssm, AlignmentViewPanel avp)
253 AAStructureBindingModel model = new AAStructureBindingModel(ssm,
254 pdbFiles, seqs, null)
257 public String[] getStructureFiles()
259 String[] files = new String[getPdbCount()];
260 for (int i = 0; i < this.getPdbCount(); i++)
262 files[i] = getPdbEntry(i).getFile();
268 public void updateColours(Object source)
273 public void releaseReferences(Object svl)
278 public void highlightAtoms(List<AtomSpec> atoms)
283 public SequenceRenderer getSequenceRenderer(
284 AlignmentViewPanel avp)
286 return avp == null ? null
287 : new jalview.gui.SequenceRenderer(
288 avp.getAlignViewport());
292 protected List<String> executeCommand(StructureCommandI command,
299 * for this test, let structure model ids be 0, 1, ...
300 * corresponding to first, second etc pdbfile
303 protected String getModelIdForFile(String pdbfile)
305 for (int i = 0; i < this.getPdbCount(); i++)
307 if (pdbfile.equals(this.getPdbEntry(i).getFile()))
309 return String.valueOf(i);
316 protected ViewerType getViewerType()
321 PA.setValue(model, "commandGenerator", new ChimeraCommands());
326 * Verify that the method determines that columns 2, 5 and 6 of the alignment
327 * are alignable in structure
329 @Test(groups = { "Functional" })
330 public void testFindSuperposableResidues()
333 * create a data bean to hold data per structure file
335 AAStructureBindingModel.SuperposeData[] structs = new AAStructureBindingModel.SuperposeData[testee.getStructureFiles().length];
336 for (int i = 0; i < structs.length; i++)
338 structs[i] = new AAStructureBindingModel.SuperposeData(al.getWidth(), "0");
341 * initialise BitSet of 'superposable columns' to true (would be false for
344 BitSet matched = new BitSet();
345 for (int i = 0; i < al.getWidth(); i++)
350 int refStructure = testee
351 .findSuperposableResidues(al, matched, structs);
353 assertEquals(refStructure, 0);
356 * only ungapped, structure-mapped columns are superposable
358 assertFalse(matched.get(0)); // gap in first sequence
359 assertTrue(matched.get(1));
360 assertFalse(matched.get(2)); // gap in third sequence
361 assertFalse(matched.get(3)); // gap in fourth sequence
362 assertTrue(matched.get(4));
363 assertTrue(matched.get(5)); // gap in second sequence
365 assertEquals(structs[0].pdbId, "1YCS");
366 assertEquals(structs[1].pdbId, "3A6S");
367 assertEquals(structs[2].pdbId, "1OOT");
368 assertEquals(structs[0].chain, "A"); // ? struct has chains A _and_ B
369 assertEquals(structs[1].chain, "B");
370 assertEquals(structs[2].chain, "A");
371 // the 0's for unsuperposable positions propagate down the columns:
372 assertEquals(Arrays.toString(structs[0].pdbResNo),
373 "[0, 97, 98, 99, 100, 102]");
374 assertEquals(Arrays.toString(structs[1].pdbResNo),
375 "[0, 2, 0, 3, 4, 5]");
376 assertEquals(Arrays.toString(structs[2].pdbResNo),
377 "[0, 8, 0, 0, 10, 12]");
380 @Test(groups = { "Functional" })
381 public void testFindSuperposableResidues_hiddenColumn()
383 AAStructureBindingModel.SuperposeData[] structs = new AAStructureBindingModel.SuperposeData[al.getHeight()];
384 for (int i = 0; i < structs.length; i++)
386 structs[i] = new AAStructureBindingModel.SuperposeData(al.getWidth(), "0");
389 * initialise BitSet of 'superposable columns' to true (would be false for
392 BitSet matched = new BitSet();
393 for (int i = 0; i < al.getWidth(); i++)
398 // treat column 5 of the alignment as hidden
401 int refStructure = testee
402 .findSuperposableResidues(al, matched, structs);
404 assertEquals(refStructure, 0);
406 // only ungapped, structure-mapped columns are not superposable
407 assertFalse(matched.get(0));
408 assertTrue(matched.get(1));
409 assertFalse(matched.get(2));
410 assertFalse(matched.get(3));
411 assertFalse(matched.get(4)); // superposable, but hidden, column
412 assertTrue(matched.get(5));
415 @Test(groups = { "Functional" })
416 public void testBuildColoursMap()
419 * load these sequences, coloured by Strand propensity,
420 * with columns 2-4 hidden
422 String fasta = ">seq1\nMHRSQSSSGG\n>seq2\nMVRSNGGSSS";
423 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(fasta,
424 DataSourceType.PASTE);
425 AlignmentI al = af.getViewport().getAlignment();
426 af.changeColour_actionPerformed(JalviewColourScheme.Strand.toString());
427 ColumnSelection cs = new ColumnSelection();
431 af.getViewport().setColumnSelection(cs);
432 af.hideSelColumns_actionPerformed(null);
433 SequenceI seq1 = al.getSequenceAt(0);
434 SequenceI seq2 = al.getSequenceAt(1);
435 SequenceI[][] seqs = new SequenceI[][] { { seq1 }, { seq2 } };
436 PDBEntry[] pdbFiles = new PDBEntry[2];
437 pdbFiles[0] = new PDBEntry("PDB1", "A", Type.PDB, "seq1.pdb");
438 pdbFiles[1] = new PDBEntry("PDB2", "B", Type.PDB, "seq2.pdb");
439 StructureSelectionManager ssm = new StructureSelectionManager();
442 * map residues 1-10 to residues 21-30 (atoms 105-150) in structures
444 HashMap<Integer, int[]> map = new HashMap<>();
445 for (int pos = 1; pos <= seq1.getLength(); pos++)
447 map.put(pos, new int[] { 20 + pos, 5 * (20 + pos) });
449 StructureMapping sm1 = new StructureMapping(seq1, "seq1.pdb", "pdb1",
451 ssm.addStructureMapping(sm1);
452 StructureMapping sm2 = new StructureMapping(seq2, "seq2.pdb", "pdb2",
454 ssm.addStructureMapping(sm2);
456 AAStructureBindingModel binding = newBindingModel(pdbFiles, seqs, ssm,
460 * method under test builds a map of structures residues by colour
461 * verify the map holds what it should
463 Map<Object, AtomSpecModel> colours = binding.buildColoursMap(ssm, seqs,
465 ChimeraCommands helper = new ChimeraCommands();
468 * M colour is #82827d (see strand.html help page)
469 * sequence residue 1 mapped to structure residue 21
471 Color mColor = new Color(0x82827d);
472 AtomSpecModel atomSpec = colours.get(mColor);
473 assertNotNull(atomSpec);
474 assertEquals(helper.getAtomSpec(atomSpec, AtomSpecType.RESIDUE_ONLY), "#0:21.A|#1:21.B");
477 * H colour is #60609f, seq1.2 mapped to structure 0 residue 22
479 Color hColor = new Color(0x60609f);
480 atomSpec = colours.get(hColor);
481 assertNotNull(atomSpec);
482 assertEquals(helper.getAtomSpec(atomSpec, AtomSpecType.RESIDUE_ONLY), "#0:22.A");
485 * V colour is #ffff00, seq2.2 mapped to structure 1 residue 22
487 Color vColor = new Color(0xffff00);
488 atomSpec = colours.get(vColor);
489 assertNotNull(atomSpec);
490 assertEquals(helper.getAtomSpec(atomSpec, AtomSpecType.RESIDUE_ONLY), "#1:22.B");
493 * hidden columns are Gray (128, 128, 128)
494 * sequence positions 3-5 mapped to structure residues 23-25
496 Color gray = new Color(128, 128, 128);
497 atomSpec = colours.get(gray);
498 assertNotNull(atomSpec);
499 assertEquals(helper.getAtomSpec(atomSpec, AtomSpecType.RESIDUE_ONLY), "#0:23-25.A|#1:23-25.B");
502 * S and G are both coloured #4949b6, structure residues 26-30
504 Color sgColour = new Color(0x4949b6);
505 atomSpec = colours.get(sgColour);
506 assertNotNull(atomSpec);
507 assertEquals(helper.getAtomSpec(atomSpec, AtomSpecType.RESIDUE_ONLY),
508 "#0:26-30.A|#1:26-30.B");