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.
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertFalse;
25 import static org.testng.AssertJUnit.assertSame;
26 import static org.testng.AssertJUnit.assertTrue;
28 import jalview.analysis.AlignSeq;
29 import jalview.datamodel.AlignmentAnnotation;
30 import jalview.datamodel.Sequence;
31 import jalview.datamodel.SequenceFeature;
32 import jalview.datamodel.SequenceI;
33 import jalview.gui.JvOptionPane;
34 import jalview.schemes.ColourSchemeI;
35 import jalview.schemes.TaylorColourScheme;
36 import jalview.structure.StructureImportSettings;
38 import java.awt.Color;
39 import java.util.Vector;
41 import org.testng.annotations.BeforeClass;
42 import org.testng.annotations.BeforeMethod;
43 import org.testng.annotations.Test;
45 public class PDBChainTest
48 @BeforeClass(alwaysRun = true)
49 public void setUpJvOptionPane()
51 JvOptionPane.setInteractiveMode(false);
52 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
57 final Atom a1 = new Atom(1f, 2f, 3f);
59 final Atom a2 = new Atom(5f, 6f, 4f);
61 final Atom a3 = new Atom(2f, 5f, 6f);
63 final Atom a4 = new Atom(2f, 1f, 7f);
65 @BeforeMethod(alwaysRun = true)
68 System.out.println("setup");
69 StructureImportSettings.setShowSeqFeatures(true);
70 c = new PDBChain("1GAQ", "A");
73 @Test(groups = { "Functional" })
74 public void testGetNewlineString()
76 assertEquals(System.lineSeparator(), c.getNewlineString());
77 c.setNewlineString("gaga");
78 assertEquals("gaga", c.getNewlineString());
81 @Test(groups = { "Functional" })
82 public void testPrint()
93 Vector<Bond> v = new Vector<Bond>();
94 v.add(new Bond(a1, a2));
95 v.add(new Bond(a2, a3));
96 v.add(new Bond(a3, a1));
99 String printed = c.print();
100 String nl = System.lineSeparator();
101 assertEquals("GLY 23 7" + nl + "GLU 34 7" + nl + "ASP 41 7" + nl,
106 * Test the method that constructs a Bond between two atoms and adds it to the
107 * chain's list of bonds
109 @Test(groups = { "Functional" })
110 public void testMakeBond()
113 * Add a bond from a1 to a2
116 assertEquals(1, c.bonds.size());
117 Bond b1 = c.bonds.get(0);
118 assertSame(a1, b1.at1);
119 assertSame(a2, b1.at2);
120 assertEquals(1f, b1.start[0], 0.0001f);
121 assertEquals(2f, b1.start[1], 0.0001f);
122 assertEquals(3f, b1.start[2], 0.0001f);
123 assertEquals(5f, b1.end[0], 0.0001f);
124 assertEquals(6f, b1.end[1], 0.0001f);
125 assertEquals(4f, b1.end[2], 0.0001f);
128 * Add another bond from a2 to a1
131 assertEquals(2, c.bonds.size());
132 assertSame(b1, c.bonds.get(0));
133 Bond b2 = c.bonds.get(1);
134 assertSame(a2, b2.at1);
135 assertSame(a1, b2.at2);
136 assertEquals(5f, b2.start[0], 0.0001f);
137 assertEquals(6f, b2.start[1], 0.0001f);
138 assertEquals(4f, b2.start[2], 0.0001f);
139 assertEquals(1f, b2.end[0], 0.0001f);
140 assertEquals(2f, b2.end[1], 0.0001f);
141 assertEquals(3f, b2.end[2], 0.0001f);
144 @Test(groups = { "Functional" })
145 public void testSetChainColours_colour()
149 c.setChainColours(Color.PINK);
150 assertEquals(2, c.bonds.size());
151 assertEquals(Color.PINK, c.bonds.get(0).startCol);
152 assertEquals(Color.PINK, c.bonds.get(0).endCol);
153 assertEquals(Color.PINK, c.bonds.get(1).startCol);
154 assertEquals(Color.PINK, c.bonds.get(1).endCol);
158 * Test setting bond start/end colours based on a colour scheme i.e. colour by
161 @Test(groups = { "Functional" })
162 public void testSetChainColours_colourScheme()
164 Color alaColour = new Color(204, 255, 0);
165 Color glyColour = new Color(255, 153, 0);
168 a3.resName = "XXX"; // no colour defined
172 ColourSchemeI cs = new TaylorColourScheme();
173 c.setChainColours(cs);
175 Bond b = c.bonds.get(0);
176 assertEquals(alaColour, b.startCol);
177 assertEquals(glyColour, b.endCol);
180 assertEquals(glyColour, b.startCol);
181 assertEquals(alaColour, b.endCol);
182 // bond a2 to a3 - no colour found for a3
183 // exception handling defaults to gray
185 assertEquals(Color.gray, b.startCol);
186 assertEquals(Color.gray, b.endCol);
189 @Test(groups = { "Functional" })
190 public void testGetChargeColour()
192 assertEquals(Color.red, PDBChain.getChargeColour("ASP"));
193 assertEquals(Color.red, PDBChain.getChargeColour("GLU"));
194 assertEquals(Color.blue, PDBChain.getChargeColour("LYS"));
195 assertEquals(Color.blue, PDBChain.getChargeColour("ARG"));
196 assertEquals(Color.yellow, PDBChain.getChargeColour("CYS"));
197 assertEquals(Color.lightGray, PDBChain.getChargeColour("ALA"));
198 assertEquals(Color.lightGray, PDBChain.getChargeColour(null));
202 * Test the method that sets bond start/end colours by residue charge property
204 @Test(groups = { "Functional" })
205 public void testSetChargeColours()
207 a1.resName = "ASP"; // red
208 a2.resName = "LYS"; // blue
209 a3.resName = "CYS"; // yellow
210 a4.resName = "ALA"; // no colour (light gray)
214 c.setChargeColours();
215 assertEquals(3, c.bonds.size());
217 Bond b = c.bonds.get(0);
218 assertEquals(Color.red, b.startCol);
219 assertEquals(Color.blue, b.endCol);
222 assertEquals(Color.blue, b.startCol);
223 assertEquals(Color.yellow, b.endCol);
226 assertEquals(Color.yellow, b.startCol);
227 assertEquals(Color.lightGray, b.endCol);
231 * Test the method that converts the raw list of atoms to a list of residues
233 @Test(groups = { "Functional" })
234 public void testMakeResidueList_noAnnotation()
236 Vector<Atom> atoms = new Vector<Atom>();
239 atoms.add(makeAtom(4, "N", "MET"));
240 atoms.add(makeAtom(4, "CA", "MET"));
241 atoms.add(makeAtom(4, "C", "MET"));
242 atoms.add(makeAtom(5, "O", "LYS"));
243 atoms.add(makeAtom(5, "N", "LYS"));
244 atoms.add(makeAtom(5, "CA", "LYS"));
245 atoms.add(makeAtom(6, "O", "LEU"));
246 atoms.add(makeAtom(6, "N", "LEU"));
247 atoms.add(makeAtom(6, "CA", "LEU"));
249 c.makeResidueList(false);
252 * check sequence constructed
254 assertEquals("MKL", c.sequence.getSequenceAsString());
256 assertEquals(3, c.residues.size());
259 * check sequence features
261 SequenceFeature[] sfs = c.sequence.getSequenceFeatures();
262 assertEquals(3, sfs.length);
263 assertEquals("RESNUM", sfs[0].type);
264 assertEquals("MET:4 1gaqA", sfs[0].description);
265 assertEquals(4, sfs[0].begin);
266 assertEquals(4, sfs[0].end);
267 assertEquals("RESNUM", sfs[0].type);
268 assertEquals("LYS:5 1gaqA", sfs[1].description);
269 assertEquals(5, sfs[1].begin);
270 assertEquals(5, sfs[1].end);
271 assertEquals("LEU:6 1gaqA", sfs[2].description);
272 assertEquals(6, sfs[2].begin);
273 assertEquals(6, sfs[2].end);
276 private Atom makeAtom(int resnum, String name, String resname)
278 Atom a = new Atom(1f, 2f, 3f);
279 a.resNumber = resnum;
280 a.resNumIns = String.valueOf(resnum);
288 * Test the method that converts the raw list of atoms to a list of residues,
289 * including parsing of tempFactor to an alignment annotation
291 @Test(groups = { "Functional" })
292 public void testMakeResidueList_withTempFactor()
294 Vector<Atom> atoms = new Vector<Atom>();
296 atoms.add(makeAtom(4, "N", "MET"));
297 atoms.get(atoms.size() - 1).tfactor = 1f;
298 atoms.add(makeAtom(4, "CA", "MET"));
299 atoms.get(atoms.size() - 1).tfactor = 2f;
300 atoms.add(makeAtom(4, "C", "MET"));
301 atoms.get(atoms.size() - 1).tfactor = 3f;
302 atoms.add(makeAtom(5, "O", "LYS"));
303 atoms.get(atoms.size() - 1).tfactor = 7f;
304 atoms.add(makeAtom(5, "N", "LYS"));
305 atoms.get(atoms.size() - 1).tfactor = 8f;
306 atoms.add(makeAtom(5, "CA", "LYS"));
307 atoms.get(atoms.size() - 1).tfactor = 9f;
308 atoms.add(makeAtom(6, "O", "LEU"));
309 atoms.get(atoms.size() - 1).tfactor = 4f;
310 atoms.add(makeAtom(6, "N", "LEU"));
311 atoms.get(atoms.size() - 1).tfactor = 5f;
312 atoms.add(makeAtom(6, "CA", "LEU"));
313 atoms.get(atoms.size() - 1).tfactor = 6f;
316 * make residues including temp factor annotation
318 c.makeResidueList(true);
321 * Verify annotations; note the tempFactor is read from the first atom in
322 * each residue i.e. we expect values 1, 7, 4 for the residues
324 AlignmentAnnotation[] ann = c.sequence.getAnnotation();
325 assertEquals(1, ann.length);
326 assertEquals("Temperature Factor", ann[0].label);
327 assertEquals("Temperature Factor for 1gaqA", ann[0].description);
328 assertSame(c.sequence, ann[0].sequenceRef);
329 assertEquals(AlignmentAnnotation.LINE_GRAPH, ann[0].graph);
330 assertEquals(0f, ann[0].graphMin, 0.001f);
331 assertEquals(7f, ann[0].graphMax, 0.001f);
332 assertEquals(3, ann[0].annotations.length);
333 assertEquals(1f, ann[0].annotations[0].value, 0.001f);
334 assertEquals(7f, ann[0].annotations[1].value, 0.001f);
335 assertEquals(4f, ann[0].annotations[2].value, 0.001f);
339 * Test the method that constructs bonds between successive residues' CA or P
342 @Test(groups = { "Functional" })
343 public void testMakeCaBondList()
346 Vector<Atom> atoms = new Vector<Atom>();
348 atoms.add(makeAtom(4, "N", "MET"));
349 atoms.add(makeAtom(4, "CA", "MET"));
350 atoms.add(makeAtom(5, "CA", "ASP"));
351 atoms.add(makeAtom(5, "O", "ASP"));
352 atoms.add(makeAtom(6, "CA", "GLY"));
353 atoms.add(makeAtom(6, "N", "GLY"));
355 // have to make residue list first!
356 c.makeResidueList(false);
361 assertEquals(2, c.bonds.size());
362 Bond b = c.bonds.get(0);
363 assertSame(c.atoms.get(1), b.at1);
364 assertSame(c.atoms.get(2), b.at2);
366 assertSame(c.atoms.get(2), b.at1);
367 assertSame(c.atoms.get(4), b.at2);
369 // isNa flag is _not_ reset by this method!
373 @Test(groups = { "Functional" })
374 public void testMakeCaBondList_nucleotide()
377 Vector<Atom> atoms = new Vector<Atom>();
379 atoms.add(makeAtom(4, "N", "G"));
380 atoms.add(makeAtom(4, "P", "G"));
381 atoms.add(makeAtom(5, "P", "C"));
382 atoms.add(makeAtom(5, "O", "C"));
383 atoms.add(makeAtom(6, "P", "T"));
384 atoms.add(makeAtom(6, "N", "T"));
386 // have to make residue list first!
387 c.makeResidueList(false);
388 assertEquals("GCT", c.sequence.getSequenceAsString());
391 assertEquals(2, c.bonds.size());
392 Bond b = c.bonds.get(0);
393 assertSame(c.atoms.get(1), b.at1);
394 assertSame(c.atoms.get(2), b.at2);
396 assertSame(c.atoms.get(2), b.at1);
397 assertSame(c.atoms.get(4), b.at2);
403 * Test the method that updates atoms with their alignment positions
405 @Test(groups = { "Functional" })
406 public void testMakeExactMapping()
408 Vector<Atom> atoms = new Vector<Atom>();
410 atoms.add(makeAtom(4, "N", "MET"));
411 atoms.add(makeAtom(4, "CA", "MET"));
412 atoms.add(makeAtom(5, "CA", "ASP"));
413 atoms.add(makeAtom(5, "O", "ASP"));
414 atoms.add(makeAtom(6, "CA", "GLY"));
415 atoms.add(makeAtom(6, "N", "GLY"));
416 c.makeResidueList(false);
417 assertEquals("MDG", c.sequence.getSequenceAsString());
418 SequenceI s1 = new Sequence("Seq1", "MDG");
419 SequenceI s2 = new Sequence("Seq2", "MDG");
420 AlignSeq alignSeq = AlignSeq.doGlobalNWAlignment(s1, s2, AlignSeq.PEP);
421 SequenceI seq3 = new Sequence("Seq3", "--M-DG");
422 c.makeExactMapping(alignSeq, seq3);
425 for (Residue res : c.residues)
427 for (Atom a : res.atoms)
429 assertEquals(pos, a.alignmentMapping);