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.Test;
21 public class PDBChainTest
23 PDBChain c = new PDBChain("1GAQ", "A");
25 Atom a1 = new Atom(1f, 2f, 3f);
27 Atom a2 = new Atom(5f, 6f, 4f);
29 Atom a3 = new Atom(2f, 5f, 6f);
31 Atom a4 = new Atom(2f, 1f, 7f);
34 public void testGetNewlineString()
36 assertEquals(System.lineSeparator(), c.getNewlineString());
37 c.setNewlineString("gaga");
38 assertEquals("gaga", c.getNewlineString());
42 public void testPrint()
53 Vector<Bond> v = new Vector<Bond>();
54 v.add(new Bond(a1, a2));
55 v.add(new Bond(a2, a3));
56 v.add(new Bond(a3, a1));
59 String printed = c.print();
60 String nl = System.lineSeparator();
61 assertEquals("GLY 23 7" + nl + "GLU 34 7" + nl + "ASP 41 7" + nl,
66 * Test the method that constructs a Bond between two atoms and adds it to the
67 * chain's list of bonds
70 public void testMakeBond()
73 * Add a bond from a1 to a2
76 assertEquals(1, c.bonds.size());
77 Bond b1 = c.bonds.get(0);
78 assertSame(a1, b1.at1);
79 assertSame(a2, b1.at2);
80 assertEquals(1f, b1.start[0], 0.0001f);
81 assertEquals(2f, b1.start[1], 0.0001f);
82 assertEquals(3f, b1.start[2], 0.0001f);
83 assertEquals(5f, b1.end[0], 0.0001f);
84 assertEquals(6f, b1.end[1], 0.0001f);
85 assertEquals(4f, b1.end[2], 0.0001f);
88 * Add another bond from a2 to a1
91 assertEquals(2, c.bonds.size());
92 assertSame(b1, c.bonds.get(0));
93 Bond b2 = c.bonds.get(1);
94 assertSame(a2, b2.at1);
95 assertSame(a1, b2.at2);
96 assertEquals(5f, b2.start[0], 0.0001f);
97 assertEquals(6f, b2.start[1], 0.0001f);
98 assertEquals(4f, b2.start[2], 0.0001f);
99 assertEquals(1f, b2.end[0], 0.0001f);
100 assertEquals(2f, b2.end[1], 0.0001f);
101 assertEquals(3f, b2.end[2], 0.0001f);
105 public void testSetChainColours_colour()
109 c.setChainColours(Color.PINK);
110 assertEquals(2, c.bonds.size());
111 assertEquals(Color.PINK, c.bonds.get(0).startCol);
112 assertEquals(Color.PINK, c.bonds.get(0).endCol);
113 assertEquals(Color.PINK, c.bonds.get(1).startCol);
114 assertEquals(Color.PINK, c.bonds.get(1).endCol);
118 * Test setting bond start/end colours based on a colour scheme i.e. colour by
122 public void testSetChainColours_colourScheme()
124 Color alaColour = new Color(204, 255, 0);
125 Color glyColour = new Color(255, 153, 0);
128 a3.resName = "XXX"; // no colour defined
132 ColourSchemeI cs = new TaylorColourScheme();
133 c.setChainColours(cs);
135 Bond b = c.bonds.get(0);
136 assertEquals(alaColour, b.startCol);
137 assertEquals(glyColour, b.endCol);
140 assertEquals(glyColour, b.startCol);
141 assertEquals(alaColour, b.endCol);
142 // bond a2 to a3 - no colour found for a3
143 // exception handling defaults to gray
145 assertEquals(Color.gray, b.startCol);
146 assertEquals(Color.gray, b.endCol);
150 public void testGetChargeColour()
152 assertEquals(Color.red, PDBChain.getChargeColour("ASP"));
153 assertEquals(Color.red, PDBChain.getChargeColour("GLU"));
154 assertEquals(Color.blue, PDBChain.getChargeColour("LYS"));
155 assertEquals(Color.blue, PDBChain.getChargeColour("ARG"));
156 assertEquals(Color.yellow, PDBChain.getChargeColour("CYS"));
157 assertEquals(Color.lightGray, PDBChain.getChargeColour("ALA"));
158 assertEquals(Color.lightGray, PDBChain.getChargeColour(null));
162 * Test the method that sets bond start/end colours by residue charge property
165 public void testSetChargeColours()
167 a1.resName = "ASP"; // red
168 a2.resName = "LYS"; // blue
169 a3.resName = "CYS"; // yellow
170 a4.resName = "ALA"; // no colour (light gray)
174 c.setChargeColours();
175 assertEquals(3, c.bonds.size());
177 Bond b = c.bonds.get(0);
178 assertEquals(Color.red, b.startCol);
179 assertEquals(Color.blue, b.endCol);
182 assertEquals(Color.blue, b.startCol);
183 assertEquals(Color.yellow, b.endCol);
186 assertEquals(Color.yellow, b.startCol);
187 assertEquals(Color.lightGray, b.endCol);
191 * Test the method that converts the raw list of atoms to a list of residues
194 public void testMakeResidueList_noAnnotation()
196 Vector<Atom> atoms = new Vector<Atom>();
199 atoms.add(makeAtom(4, "N", "MET"));
200 atoms.add(makeAtom(4, "CA", "MET"));
201 atoms.add(makeAtom(4, "C", "MET"));
202 atoms.add(makeAtom(5, "O", "LYS"));
203 atoms.add(makeAtom(5, "N", "LYS"));
204 atoms.add(makeAtom(5, "CA", "LYS"));
205 atoms.add(makeAtom(6, "O", "LEU"));
206 atoms.add(makeAtom(6, "N", "LEU"));
207 atoms.add(makeAtom(6, "CA", "LEU"));
209 c.makeResidueList(false);
212 * check sequence constructed
214 assertEquals("MKL", c.sequence.getSequenceAsString());
216 assertEquals(3, c.residues.size());
219 * check sequence features
221 SequenceFeature[] sfs = c.sequence.getSequenceFeatures();
222 assertEquals(3, sfs.length);
223 assertEquals("RESNUM", sfs[0].type);
224 assertEquals("MET:4 1gaqA", sfs[0].description);
225 assertEquals(4, sfs[0].begin);
226 assertEquals(4, sfs[0].end);
227 assertEquals("RESNUM", sfs[0].type);
228 assertEquals("LYS:5 1gaqA", sfs[1].description);
229 assertEquals(5, sfs[1].begin);
230 assertEquals(5, sfs[1].end);
231 assertEquals("LEU:6 1gaqA", sfs[2].description);
232 assertEquals(6, sfs[2].begin);
233 assertEquals(6, sfs[2].end);
236 private Atom makeAtom(int resnum, String name, String resname)
238 Atom a = new Atom(1f, 2f, 3f);
239 a.resNumber = resnum;
240 a.resNumIns = String.valueOf(resnum);
248 * Test the method that converts the raw list of atoms to a list of residues,
249 * including parsing of tempFactor to an alignment annotation
252 public void testMakeResidueList_withTempFactor()
254 Vector<Atom> atoms = new Vector<Atom>();
256 atoms.add(makeAtom(4, "N", "MET"));
257 atoms.get(atoms.size()-1).tfactor = 1f;
258 atoms.add(makeAtom(4, "CA", "MET"));
259 atoms.get(atoms.size()-1).tfactor = 2f;
260 atoms.add(makeAtom(4, "C", "MET"));
261 atoms.get(atoms.size()-1).tfactor = 3f;
262 atoms.add(makeAtom(5, "O", "LYS"));
263 atoms.get(atoms.size()-1).tfactor = 7f;
264 atoms.add(makeAtom(5, "N", "LYS"));
265 atoms.get(atoms.size()-1).tfactor = 8f;
266 atoms.add(makeAtom(5, "CA", "LYS"));
267 atoms.get(atoms.size()-1).tfactor = 9f;
268 atoms.add(makeAtom(6, "O", "LEU"));
269 atoms.get(atoms.size()-1).tfactor = 4f;
270 atoms.add(makeAtom(6, "N", "LEU"));
271 atoms.get(atoms.size()-1).tfactor = 5f;
272 atoms.add(makeAtom(6, "CA", "LEU"));
273 atoms.get(atoms.size()-1).tfactor = 6f;
276 * make residues including temp factor annotation
278 c.makeResidueList(true);
281 * Verify annotations; note the tempFactor is read from the first atom in
282 * each residue i.e. we expect values 1, 7, 4 for the residues
284 AlignmentAnnotation[] ann = c.sequence.getAnnotation();
285 assertEquals(1, ann.length);
286 assertEquals("Temperature Factor", ann[0].label);
287 assertEquals("Temperature Factor for 1gaqA", ann[0].description);
288 assertSame(c.sequence, ann[0].sequenceRef);
289 assertEquals(AlignmentAnnotation.LINE_GRAPH, ann[0].graph);
290 assertEquals(0f, ann[0].graphMin, 0.001f);
291 assertEquals(7f, ann[0].graphMax, 0.001f);
292 assertEquals(3, ann[0].annotations.length);
293 assertEquals(1f, ann[0].annotations[0].value, 0.001f);
294 assertEquals(7f, ann[0].annotations[1].value, 0.001f);
295 assertEquals(4f, ann[0].annotations[2].value, 0.001f);
299 * Test the method that constructs bonds between successive residues' CA or P
303 public void testMakeCaBondList()
306 Vector<Atom> atoms = new Vector<Atom>();
308 atoms.add(makeAtom(4, "N", "MET"));
309 atoms.add(makeAtom(4, "CA", "MET"));
310 atoms.add(makeAtom(5, "CA", "ASP"));
311 atoms.add(makeAtom(5, "O", "ASP"));
312 atoms.add(makeAtom(6, "CA", "GLY"));
313 atoms.add(makeAtom(6, "N", "GLY"));
315 // have to make residue list first!
316 c.makeResidueList(false);
321 assertEquals(2, c.bonds.size());
322 Bond b = c.bonds.get(0);
323 assertSame(c.atoms.get(1), b.at1);
324 assertSame(c.atoms.get(2), b.at2);
326 assertSame(c.atoms.get(2), b.at1);
327 assertSame(c.atoms.get(4), b.at2);
329 // isNa flag is _not_ reset by this method!
334 public void testMakeCaBondList_nucleotide()
337 Vector<Atom> atoms = new Vector<Atom>();
339 atoms.add(makeAtom(4, "N", "G"));
340 atoms.add(makeAtom(4, "P", "G"));
341 atoms.add(makeAtom(5, "P", "C"));
342 atoms.add(makeAtom(5, "O", "C"));
343 atoms.add(makeAtom(6, "P", "T"));
344 atoms.add(makeAtom(6, "N", "T"));
346 // have to make residue list first!
347 c.makeResidueList(false);
348 assertEquals("GCT", c.sequence.getSequenceAsString());
351 assertEquals(2, c.bonds.size());
352 Bond b = c.bonds.get(0);
353 assertSame(c.atoms.get(1), b.at1);
354 assertSame(c.atoms.get(2), b.at2);
356 assertSame(c.atoms.get(2), b.at1);
357 assertSame(c.atoms.get(4), b.at2);
363 * Test the method that updates atoms with their alignment positions
366 public void testMakeExactMapping()
368 Vector<Atom> atoms = new Vector<Atom>();
370 atoms.add(makeAtom(4, "N", "MET"));
371 atoms.add(makeAtom(4, "CA", "MET"));
372 atoms.add(makeAtom(5, "CA", "ASP"));
373 atoms.add(makeAtom(5, "O", "ASP"));
374 atoms.add(makeAtom(6, "CA", "GLY"));
375 atoms.add(makeAtom(6, "N", "GLY"));
376 c.makeResidueList(false);
377 assertEquals("MDG", c.sequence.getSequenceAsString());
378 SequenceI s1 = new Sequence("Seq1", "MDG");
379 SequenceI s2 = new Sequence("Seq2", "MDG");
380 AlignSeq alignSeq = AlignSeq.doGlobalNWAlignment(s1, s2, AlignSeq.PEP);
381 SequenceI seq3 = new Sequence("Seq3", "--M-DG");
382 c.makeExactMapping(alignSeq, seq3);
385 for (Residue res : c.residues)
387 for (Atom a : res.atoms)
389 assertEquals(pos, a.alignmentMapping);