3 import static org.testng.AssertJUnit.assertEquals;
4 import static org.testng.AssertJUnit.assertFalse;
5 import static org.testng.AssertJUnit.assertSame;
6 import static org.testng.AssertJUnit.assertTrue;
8 import jalview.analysis.AlignSeq;
9 import jalview.datamodel.AlignmentAnnotation;
10 import jalview.datamodel.Sequence;
11 import jalview.datamodel.SequenceFeature;
12 import jalview.datamodel.SequenceI;
13 import jalview.schemes.ColourSchemeI;
14 import jalview.schemes.TaylorColourScheme;
16 import java.awt.Color;
17 import java.util.Vector;
19 import org.testng.annotations.BeforeMethod;
20 import org.testng.annotations.Test;
22 public class PDBChainTest
26 final Atom a1 = new Atom(1f, 2f, 3f);
28 final Atom a2 = new Atom(5f, 6f, 4f);
30 final Atom a3 = new Atom(2f, 5f, 6f);
32 final Atom a4 = new Atom(2f, 1f, 7f);
37 System.out.println("setup");
38 c = new PDBChain("1GAQ", "A");
41 @Test(groups ={ "Functional" })
42 public void testGetNewlineString()
44 assertEquals(System.lineSeparator(), c.getNewlineString());
45 c.setNewlineString("gaga");
46 assertEquals("gaga", c.getNewlineString());
49 @Test(groups ={ "Functional" })
50 public void testPrint()
61 Vector<Bond> v = new Vector<Bond>();
62 v.add(new Bond(a1, a2));
63 v.add(new Bond(a2, a3));
64 v.add(new Bond(a3, a1));
67 String printed = c.print();
68 String nl = System.lineSeparator();
69 assertEquals("GLY 23 7" + nl + "GLU 34 7" + nl + "ASP 41 7" + nl,
74 * Test the method that constructs a Bond between two atoms and adds it to the
75 * chain's list of bonds
77 @Test(groups ={ "Functional" })
78 public void testMakeBond()
81 * Add a bond from a1 to a2
84 assertEquals(1, c.bonds.size());
85 Bond b1 = c.bonds.get(0);
86 assertSame(a1, b1.at1);
87 assertSame(a2, b1.at2);
88 assertEquals(1f, b1.start[0], 0.0001f);
89 assertEquals(2f, b1.start[1], 0.0001f);
90 assertEquals(3f, b1.start[2], 0.0001f);
91 assertEquals(5f, b1.end[0], 0.0001f);
92 assertEquals(6f, b1.end[1], 0.0001f);
93 assertEquals(4f, b1.end[2], 0.0001f);
96 * Add another bond from a2 to a1
99 assertEquals(2, c.bonds.size());
100 assertSame(b1, c.bonds.get(0));
101 Bond b2 = c.bonds.get(1);
102 assertSame(a2, b2.at1);
103 assertSame(a1, b2.at2);
104 assertEquals(5f, b2.start[0], 0.0001f);
105 assertEquals(6f, b2.start[1], 0.0001f);
106 assertEquals(4f, b2.start[2], 0.0001f);
107 assertEquals(1f, b2.end[0], 0.0001f);
108 assertEquals(2f, b2.end[1], 0.0001f);
109 assertEquals(3f, b2.end[2], 0.0001f);
112 @Test(groups ={ "Functional" })
113 public void testSetChainColours_colour()
117 c.setChainColours(Color.PINK);
118 assertEquals(2, c.bonds.size());
119 assertEquals(Color.PINK, c.bonds.get(0).startCol);
120 assertEquals(Color.PINK, c.bonds.get(0).endCol);
121 assertEquals(Color.PINK, c.bonds.get(1).startCol);
122 assertEquals(Color.PINK, c.bonds.get(1).endCol);
126 * Test setting bond start/end colours based on a colour scheme i.e. colour by
129 @Test(groups ={ "Functional" })
130 public void testSetChainColours_colourScheme()
132 Color alaColour = new Color(204, 255, 0);
133 Color glyColour = new Color(255, 153, 0);
136 a3.resName = "XXX"; // no colour defined
140 ColourSchemeI cs = new TaylorColourScheme();
141 c.setChainColours(cs);
143 Bond b = c.bonds.get(0);
144 assertEquals(alaColour, b.startCol);
145 assertEquals(glyColour, b.endCol);
148 assertEquals(glyColour, b.startCol);
149 assertEquals(alaColour, b.endCol);
150 // bond a2 to a3 - no colour found for a3
151 // exception handling defaults to gray
153 assertEquals(Color.gray, b.startCol);
154 assertEquals(Color.gray, b.endCol);
157 @Test(groups ={ "Functional" })
158 public void testGetChargeColour()
160 assertEquals(Color.red, PDBChain.getChargeColour("ASP"));
161 assertEquals(Color.red, PDBChain.getChargeColour("GLU"));
162 assertEquals(Color.blue, PDBChain.getChargeColour("LYS"));
163 assertEquals(Color.blue, PDBChain.getChargeColour("ARG"));
164 assertEquals(Color.yellow, PDBChain.getChargeColour("CYS"));
165 assertEquals(Color.lightGray, PDBChain.getChargeColour("ALA"));
166 assertEquals(Color.lightGray, PDBChain.getChargeColour(null));
170 * Test the method that sets bond start/end colours by residue charge property
172 @Test(groups ={ "Functional" })
173 public void testSetChargeColours()
175 a1.resName = "ASP"; // red
176 a2.resName = "LYS"; // blue
177 a3.resName = "CYS"; // yellow
178 a4.resName = "ALA"; // no colour (light gray)
182 c.setChargeColours();
183 assertEquals(3, c.bonds.size());
185 Bond b = c.bonds.get(0);
186 assertEquals(Color.red, b.startCol);
187 assertEquals(Color.blue, b.endCol);
190 assertEquals(Color.blue, b.startCol);
191 assertEquals(Color.yellow, b.endCol);
194 assertEquals(Color.yellow, b.startCol);
195 assertEquals(Color.lightGray, b.endCol);
199 * Test the method that converts the raw list of atoms to a list of residues
201 @Test(groups ={ "Functional" })
202 public void testMakeResidueList_noAnnotation()
204 Vector<Atom> atoms = new Vector<Atom>();
207 atoms.add(makeAtom(4, "N", "MET"));
208 atoms.add(makeAtom(4, "CA", "MET"));
209 atoms.add(makeAtom(4, "C", "MET"));
210 atoms.add(makeAtom(5, "O", "LYS"));
211 atoms.add(makeAtom(5, "N", "LYS"));
212 atoms.add(makeAtom(5, "CA", "LYS"));
213 atoms.add(makeAtom(6, "O", "LEU"));
214 atoms.add(makeAtom(6, "N", "LEU"));
215 atoms.add(makeAtom(6, "CA", "LEU"));
217 c.makeResidueList(false);
220 * check sequence constructed
222 assertEquals("MKL", c.sequence.getSequenceAsString());
224 assertEquals(3, c.residues.size());
227 * check sequence features
229 SequenceFeature[] sfs = c.sequence.getSequenceFeatures();
230 assertEquals(3, sfs.length);
231 assertEquals("RESNUM", sfs[0].type);
232 assertEquals("MET:4 1gaqA", sfs[0].description);
233 assertEquals(4, sfs[0].begin);
234 assertEquals(4, sfs[0].end);
235 assertEquals("RESNUM", sfs[0].type);
236 assertEquals("LYS:5 1gaqA", sfs[1].description);
237 assertEquals(5, sfs[1].begin);
238 assertEquals(5, sfs[1].end);
239 assertEquals("LEU:6 1gaqA", sfs[2].description);
240 assertEquals(6, sfs[2].begin);
241 assertEquals(6, sfs[2].end);
244 private Atom makeAtom(int resnum, String name, String resname)
246 Atom a = new Atom(1f, 2f, 3f);
247 a.resNumber = resnum;
248 a.resNumIns = String.valueOf(resnum);
256 * Test the method that converts the raw list of atoms to a list of residues,
257 * including parsing of tempFactor to an alignment annotation
259 @Test(groups ={ "Functional" })
260 public void testMakeResidueList_withTempFactor()
262 Vector<Atom> atoms = new Vector<Atom>();
264 atoms.add(makeAtom(4, "N", "MET"));
265 atoms.get(atoms.size()-1).tfactor = 1f;
266 atoms.add(makeAtom(4, "CA", "MET"));
267 atoms.get(atoms.size()-1).tfactor = 2f;
268 atoms.add(makeAtom(4, "C", "MET"));
269 atoms.get(atoms.size()-1).tfactor = 3f;
270 atoms.add(makeAtom(5, "O", "LYS"));
271 atoms.get(atoms.size()-1).tfactor = 7f;
272 atoms.add(makeAtom(5, "N", "LYS"));
273 atoms.get(atoms.size()-1).tfactor = 8f;
274 atoms.add(makeAtom(5, "CA", "LYS"));
275 atoms.get(atoms.size()-1).tfactor = 9f;
276 atoms.add(makeAtom(6, "O", "LEU"));
277 atoms.get(atoms.size()-1).tfactor = 4f;
278 atoms.add(makeAtom(6, "N", "LEU"));
279 atoms.get(atoms.size()-1).tfactor = 5f;
280 atoms.add(makeAtom(6, "CA", "LEU"));
281 atoms.get(atoms.size()-1).tfactor = 6f;
284 * make residues including temp factor annotation
286 c.makeResidueList(true);
289 * Verify annotations; note the tempFactor is read from the first atom in
290 * each residue i.e. we expect values 1, 7, 4 for the residues
292 AlignmentAnnotation[] ann = c.sequence.getAnnotation();
293 assertEquals(1, ann.length);
294 assertEquals("Temperature Factor", ann[0].label);
295 assertEquals("Temperature Factor for 1gaqA", ann[0].description);
296 assertSame(c.sequence, ann[0].sequenceRef);
297 assertEquals(AlignmentAnnotation.LINE_GRAPH, ann[0].graph);
298 assertEquals(0f, ann[0].graphMin, 0.001f);
299 assertEquals(7f, ann[0].graphMax, 0.001f);
300 assertEquals(3, ann[0].annotations.length);
301 assertEquals(1f, ann[0].annotations[0].value, 0.001f);
302 assertEquals(7f, ann[0].annotations[1].value, 0.001f);
303 assertEquals(4f, ann[0].annotations[2].value, 0.001f);
307 * Test the method that constructs bonds between successive residues' CA or P
310 @Test(groups ={ "Functional" })
311 public void testMakeCaBondList()
314 Vector<Atom> atoms = new Vector<Atom>();
316 atoms.add(makeAtom(4, "N", "MET"));
317 atoms.add(makeAtom(4, "CA", "MET"));
318 atoms.add(makeAtom(5, "CA", "ASP"));
319 atoms.add(makeAtom(5, "O", "ASP"));
320 atoms.add(makeAtom(6, "CA", "GLY"));
321 atoms.add(makeAtom(6, "N", "GLY"));
323 // have to make residue list first!
324 c.makeResidueList(false);
329 assertEquals(2, c.bonds.size());
330 Bond b = c.bonds.get(0);
331 assertSame(c.atoms.get(1), b.at1);
332 assertSame(c.atoms.get(2), b.at2);
334 assertSame(c.atoms.get(2), b.at1);
335 assertSame(c.atoms.get(4), b.at2);
337 // isNa flag is _not_ reset by this method!
341 @Test(groups ={ "Functional" })
342 public void testMakeCaBondList_nucleotide()
345 Vector<Atom> atoms = new Vector<Atom>();
347 atoms.add(makeAtom(4, "N", "G"));
348 atoms.add(makeAtom(4, "P", "G"));
349 atoms.add(makeAtom(5, "P", "C"));
350 atoms.add(makeAtom(5, "O", "C"));
351 atoms.add(makeAtom(6, "P", "T"));
352 atoms.add(makeAtom(6, "N", "T"));
354 // have to make residue list first!
355 c.makeResidueList(false);
356 assertEquals("GCT", c.sequence.getSequenceAsString());
359 assertEquals(2, c.bonds.size());
360 Bond b = c.bonds.get(0);
361 assertSame(c.atoms.get(1), b.at1);
362 assertSame(c.atoms.get(2), b.at2);
364 assertSame(c.atoms.get(2), b.at1);
365 assertSame(c.atoms.get(4), b.at2);
371 * Test the method that updates atoms with their alignment positions
373 @Test(groups ={ "Functional" })
374 public void testMakeExactMapping()
376 Vector<Atom> atoms = new Vector<Atom>();
378 atoms.add(makeAtom(4, "N", "MET"));
379 atoms.add(makeAtom(4, "CA", "MET"));
380 atoms.add(makeAtom(5, "CA", "ASP"));
381 atoms.add(makeAtom(5, "O", "ASP"));
382 atoms.add(makeAtom(6, "CA", "GLY"));
383 atoms.add(makeAtom(6, "N", "GLY"));
384 c.makeResidueList(false);
385 assertEquals("MDG", c.sequence.getSequenceAsString());
386 SequenceI s1 = new Sequence("Seq1", "MDG");
387 SequenceI s2 = new Sequence("Seq2", "MDG");
388 AlignSeq alignSeq = AlignSeq.doGlobalNWAlignment(s1, s2, AlignSeq.PEP);
389 SequenceI seq3 = new Sequence("Seq3", "--M-DG");
390 c.makeExactMapping(alignSeq, seq3);
393 for (Residue res : c.residues)
395 for (Atom a : res.atoms)
397 assertEquals(pos, a.alignmentMapping);