3 import static org.testng.AssertJUnit.assertSame;
4 import static org.testng.AssertJUnit.assertEquals;
5 import static org.testng.AssertJUnit.assertFalse;
6 import static org.testng.AssertJUnit.assertTrue;
7 import org.testng.annotations.Test;
9 import java.util.Vector;
11 import jalview.analysis.AlignSeq;
12 import jalview.datamodel.AlignmentAnnotation;
13 import jalview.datamodel.Sequence;
14 import jalview.datamodel.SequenceFeature;
15 import jalview.datamodel.SequenceI;
16 import jalview.schemes.ColourSchemeI;
17 import jalview.schemes.TaylorColourScheme;
19 public class PDBChainTest
21 PDBChain c = new PDBChain("1GAQ", "A");
22 Atom a1 = new Atom(1f, 2f, 3f);
24 Atom a2 = new Atom(5f, 6f, 4f);
26 Atom a3 = new Atom(2f, 5f, 6f);
28 Atom a4 = new Atom(2f, 1f, 7f);
31 public void testGetNewlineString()
33 assertEquals(System.lineSeparator(), c.getNewlineString());
34 c.setNewlineString("gaga");
35 assertEquals("gaga", c.getNewlineString());
39 public void testPrint()
50 Vector<Bond> v = new Vector<Bond>();
51 v.add(new Bond(a1, a2));
52 v.add(new Bond(a2, a3));
53 v.add(new Bond(a3, a1));
56 String printed = c.print();
57 String nl = System.lineSeparator();
58 assertEquals("GLY 23 7" + nl + "GLU 34 7" + nl + "ASP 41 7" + nl,
63 * Test the method that constructs a Bond between two atoms and adds it to the
64 * chain's list of bonds
67 public void testMakeBond()
70 * Add a bond from a1 to a2
73 assertEquals(1, c.bonds.size());
74 Bond b1 = c.bonds.get(0);
75 assertSame(a1, b1.at1);
76 assertSame(a2, b1.at2);
77 assertEquals(1f, b1.start[0], 0.0001f);
78 assertEquals(2f, b1.start[1], 0.0001f);
79 assertEquals(3f, b1.start[2], 0.0001f);
80 assertEquals(5f, b1.end[0], 0.0001f);
81 assertEquals(6f, b1.end[1], 0.0001f);
82 assertEquals(4f, b1.end[2], 0.0001f);
85 * Add another bond from a2 to a1
88 assertEquals(2, c.bonds.size());
89 assertSame(b1, c.bonds.get(0));
90 Bond b2 = c.bonds.get(1);
91 assertSame(a2, b2.at1);
92 assertSame(a1, b2.at2);
93 assertEquals(5f, b2.start[0], 0.0001f);
94 assertEquals(6f, b2.start[1], 0.0001f);
95 assertEquals(4f, b2.start[2], 0.0001f);
96 assertEquals(1f, b2.end[0], 0.0001f);
97 assertEquals(2f, b2.end[1], 0.0001f);
98 assertEquals(3f, b2.end[2], 0.0001f);
102 public void testSetChainColours_colour()
106 c.setChainColours(Color.PINK);
107 assertEquals(2, c.bonds.size());
108 assertEquals(Color.PINK, c.bonds.get(0).startCol);
109 assertEquals(Color.PINK, c.bonds.get(0).endCol);
110 assertEquals(Color.PINK, c.bonds.get(1).startCol);
111 assertEquals(Color.PINK, c.bonds.get(1).endCol);
115 * Test setting bond start/end colours based on a colour scheme i.e. colour by
119 public void testSetChainColours_colourScheme()
121 Color alaColour = new Color(204, 255, 0);
122 Color glyColour = new Color(255, 153, 0);
125 a3.resName = "XXX"; // no colour defined
129 ColourSchemeI cs = new TaylorColourScheme();
130 c.setChainColours(cs);
132 Bond b = c.bonds.get(0);
133 assertEquals(alaColour, b.startCol);
134 assertEquals(glyColour, b.endCol);
137 assertEquals(glyColour, b.startCol);
138 assertEquals(alaColour, b.endCol);
139 // bond a2 to a3 - no colour found for a3
140 // exception handling defaults to gray
142 assertEquals(Color.gray, b.startCol);
143 assertEquals(Color.gray, b.endCol);
147 public void testGetChargeColour()
149 assertEquals(Color.red, PDBChain.getChargeColour("ASP"));
150 assertEquals(Color.red, PDBChain.getChargeColour("GLU"));
151 assertEquals(Color.blue, PDBChain.getChargeColour("LYS"));
152 assertEquals(Color.blue, PDBChain.getChargeColour("ARG"));
153 assertEquals(Color.yellow, PDBChain.getChargeColour("CYS"));
154 assertEquals(Color.lightGray, PDBChain.getChargeColour("ALA"));
155 assertEquals(Color.lightGray, PDBChain.getChargeColour(null));
159 * Test the method that sets bond start/end colours by residue charge property
162 public void testSetChargeColours()
164 a1.resName = "ASP"; // red
165 a2.resName = "LYS"; // blue
166 a3.resName = "CYS"; // yellow
167 a4.resName = "ALA"; // no colour (light gray)
171 c.setChargeColours();
172 assertEquals(3, c.bonds.size());
174 Bond b = c.bonds.get(0);
175 assertEquals(Color.red, b.startCol);
176 assertEquals(Color.blue, b.endCol);
179 assertEquals(Color.blue, b.startCol);
180 assertEquals(Color.yellow, b.endCol);
183 assertEquals(Color.yellow, b.startCol);
184 assertEquals(Color.lightGray, b.endCol);
188 * Test the method that converts the raw list of atoms to a list of residues
191 public void testMakeResidueList_noAnnotation()
193 Vector<Atom> atoms = new Vector<Atom>();
196 atoms.add(makeAtom(4, "N", "MET"));
197 atoms.add(makeAtom(4, "CA", "MET"));
198 atoms.add(makeAtom(4, "C", "MET"));
199 atoms.add(makeAtom(5, "O", "LYS"));
200 atoms.add(makeAtom(5, "N", "LYS"));
201 atoms.add(makeAtom(5, "CA", "LYS"));
202 atoms.add(makeAtom(6, "O", "LEU"));
203 atoms.add(makeAtom(6, "N", "LEU"));
204 atoms.add(makeAtom(6, "CA", "LEU"));
206 c.makeResidueList(false);
209 * check sequence constructed
211 assertEquals("MKL", c.sequence.getSequenceAsString());
213 assertEquals(3, c.residues.size());
216 * check sequence features
218 SequenceFeature[] sfs = c.sequence.getSequenceFeatures();
219 assertEquals(3, sfs.length);
220 assertEquals("RESNUM", sfs[0].type);
221 assertEquals("MET:4 1gaqA", sfs[0].description);
222 assertEquals(4, sfs[0].begin);
223 assertEquals(4, sfs[0].end);
224 assertEquals("RESNUM", sfs[0].type);
225 assertEquals("LYS:5 1gaqA", sfs[1].description);
226 assertEquals(5, sfs[1].begin);
227 assertEquals(5, sfs[1].end);
228 assertEquals("LEU:6 1gaqA", sfs[2].description);
229 assertEquals(6, sfs[2].begin);
230 assertEquals(6, sfs[2].end);
233 private Atom makeAtom(int resnum, String name, String resname)
235 Atom a = new Atom(1f, 2f, 3f);
236 a.resNumber = resnum;
237 a.resNumIns = String.valueOf(resnum);
245 * Test the method that converts the raw list of atoms to a list of residues,
246 * including parsing of tempFactor to an alignment annotation
249 public void testMakeResidueList_withTempFactor()
251 Vector<Atom> atoms = new Vector<Atom>();
253 atoms.add(makeAtom(4, "N", "MET"));
254 atoms.get(atoms.size()-1).tfactor = 1f;
255 atoms.add(makeAtom(4, "CA", "MET"));
256 atoms.get(atoms.size()-1).tfactor = 2f;
257 atoms.add(makeAtom(4, "C", "MET"));
258 atoms.get(atoms.size()-1).tfactor = 3f;
259 atoms.add(makeAtom(5, "O", "LYS"));
260 atoms.get(atoms.size()-1).tfactor = 7f;
261 atoms.add(makeAtom(5, "N", "LYS"));
262 atoms.get(atoms.size()-1).tfactor = 8f;
263 atoms.add(makeAtom(5, "CA", "LYS"));
264 atoms.get(atoms.size()-1).tfactor = 9f;
265 atoms.add(makeAtom(6, "O", "LEU"));
266 atoms.get(atoms.size()-1).tfactor = 4f;
267 atoms.add(makeAtom(6, "N", "LEU"));
268 atoms.get(atoms.size()-1).tfactor = 5f;
269 atoms.add(makeAtom(6, "CA", "LEU"));
270 atoms.get(atoms.size()-1).tfactor = 6f;
273 * make residues including temp factor annotation
275 c.makeResidueList(true);
278 * Verify annotations; note the tempFactor is read from the first atom in
279 * each residue i.e. we expect values 1, 7, 4 for the residues
281 AlignmentAnnotation[] ann = c.sequence.getAnnotation();
282 assertEquals(1, ann.length);
283 assertEquals("Temperature Factor", ann[0].label);
284 assertEquals("Temperature Factor for 1gaqA", ann[0].description);
285 assertSame(c.sequence, ann[0].sequenceRef);
286 assertEquals(AlignmentAnnotation.LINE_GRAPH, ann[0].graph);
287 assertEquals(0f, ann[0].graphMin, 0.001f);
288 assertEquals(7f, ann[0].graphMax, 0.001f);
289 assertEquals(3, ann[0].annotations.length);
290 assertEquals(1f, ann[0].annotations[0].value, 0.001f);
291 assertEquals(7f, ann[0].annotations[1].value, 0.001f);
292 assertEquals(4f, ann[0].annotations[2].value, 0.001f);
296 * Test the method that constructs bonds between successive residues' CA or P
300 public void testMakeCaBondList()
303 Vector<Atom> atoms = new Vector<Atom>();
305 atoms.add(makeAtom(4, "N", "MET"));
306 atoms.add(makeAtom(4, "CA", "MET"));
307 atoms.add(makeAtom(5, "CA", "ASP"));
308 atoms.add(makeAtom(5, "O", "ASP"));
309 atoms.add(makeAtom(6, "CA", "GLY"));
310 atoms.add(makeAtom(6, "N", "GLY"));
312 // have to make residue list first!
313 c.makeResidueList(false);
318 assertEquals(2, c.bonds.size());
319 Bond b = c.bonds.get(0);
320 assertSame(c.atoms.get(1), b.at1);
321 assertSame(c.atoms.get(2), b.at2);
323 assertSame(c.atoms.get(2), b.at1);
324 assertSame(c.atoms.get(4), b.at2);
326 // isNa flag is _not_ reset by this method!
331 public void testMakeCaBondList_nucleotide()
334 Vector<Atom> atoms = new Vector<Atom>();
336 atoms.add(makeAtom(4, "N", "G"));
337 atoms.add(makeAtom(4, "P", "G"));
338 atoms.add(makeAtom(5, "P", "C"));
339 atoms.add(makeAtom(5, "O", "C"));
340 atoms.add(makeAtom(6, "P", "T"));
341 atoms.add(makeAtom(6, "N", "T"));
343 // have to make residue list first!
344 c.makeResidueList(false);
345 assertEquals("GCT", c.sequence.getSequenceAsString());
348 assertEquals(2, c.bonds.size());
349 Bond b = c.bonds.get(0);
350 assertSame(c.atoms.get(1), b.at1);
351 assertSame(c.atoms.get(2), b.at2);
353 assertSame(c.atoms.get(2), b.at1);
354 assertSame(c.atoms.get(4), b.at2);
360 * Test the method that updates atoms with their alignment positions
363 public void testMakeExactMapping()
365 Vector<Atom> atoms = new Vector<Atom>();
367 atoms.add(makeAtom(4, "N", "MET"));
368 atoms.add(makeAtom(4, "CA", "MET"));
369 atoms.add(makeAtom(5, "CA", "ASP"));
370 atoms.add(makeAtom(5, "O", "ASP"));
371 atoms.add(makeAtom(6, "CA", "GLY"));
372 atoms.add(makeAtom(6, "N", "GLY"));
373 c.makeResidueList(false);
374 assertEquals("MDG", c.sequence.getSequenceAsString());
375 SequenceI s1 = new Sequence("Seq1", "MDG");
376 SequenceI s2 = new Sequence("Seq2", "MDG");
377 AlignSeq alignSeq = AlignSeq.doGlobalNWAlignment(s1, s2, AlignSeq.PEP);
378 SequenceI seq3 = new Sequence("Seq3", "--M-DG");
379 c.makeExactMapping(alignSeq, seq3);
382 for (Residue res : c.residues)
384 for (Atom a : res.atoms)
386 assertEquals(pos, a.alignmentMapping);