3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertFalse;
5 import static org.junit.Assert.assertSame;
6 import static org.junit.Assert.assertTrue;
9 import java.util.Vector;
11 import org.junit.Test;
13 import jalview.analysis.AlignSeq;
14 import jalview.datamodel.AlignmentAnnotation;
15 import jalview.datamodel.Sequence;
16 import jalview.datamodel.SequenceFeature;
17 import jalview.datamodel.SequenceI;
18 import jalview.schemes.ColourSchemeI;
19 import jalview.schemes.TaylorColourScheme;
21 public class PDBChainTest
23 PDBChain c = new PDBChain("1GAQ", "A");
24 Atom a1 = new Atom(1f, 2f, 3f);
26 Atom a2 = new Atom(5f, 6f, 4f);
28 Atom a3 = new Atom(2f, 5f, 6f);
30 Atom a4 = new Atom(2f, 1f, 7f);
33 public void testGetNewlineString()
35 assertEquals(System.lineSeparator(), c.getNewlineString());
36 c.setNewlineString("gaga");
37 assertEquals("gaga", c.getNewlineString());
41 public void testPrint()
52 Vector<Bond> v = new Vector<Bond>();
53 v.add(new Bond(a1, a2));
54 v.add(new Bond(a2, a3));
55 v.add(new Bond(a3, a1));
58 String printed = c.print();
59 String nl = System.lineSeparator();
60 assertEquals("GLY 23 7" + nl + "GLU 34 7" + nl + "ASP 41 7" + nl,
65 * Test the method that constructs a Bond between two atoms and adds it to the
66 * chain's list of bonds
69 public void testMakeBond()
72 * Add a bond from a1 to a2
75 assertEquals(1, c.bonds.size());
76 Bond b1 = c.bonds.get(0);
77 assertSame(a1, b1.at1);
78 assertSame(a2, b1.at2);
79 assertEquals(1f, b1.start[0], 0.0001f);
80 assertEquals(2f, b1.start[1], 0.0001f);
81 assertEquals(3f, b1.start[2], 0.0001f);
82 assertEquals(5f, b1.end[0], 0.0001f);
83 assertEquals(6f, b1.end[1], 0.0001f);
84 assertEquals(4f, b1.end[2], 0.0001f);
87 * Add another bond from a2 to a1
90 assertEquals(2, c.bonds.size());
91 assertSame(b1, c.bonds.get(0));
92 Bond b2 = c.bonds.get(1);
93 assertSame(a2, b2.at1);
94 assertSame(a1, b2.at2);
95 assertEquals(5f, b2.start[0], 0.0001f);
96 assertEquals(6f, b2.start[1], 0.0001f);
97 assertEquals(4f, b2.start[2], 0.0001f);
98 assertEquals(1f, b2.end[0], 0.0001f);
99 assertEquals(2f, b2.end[1], 0.0001f);
100 assertEquals(3f, b2.end[2], 0.0001f);
104 public void testSetChainColours_colour()
108 c.setChainColours(Color.PINK);
109 assertEquals(2, c.bonds.size());
110 assertEquals(Color.PINK, c.bonds.get(0).startCol);
111 assertEquals(Color.PINK, c.bonds.get(0).endCol);
112 assertEquals(Color.PINK, c.bonds.get(1).startCol);
113 assertEquals(Color.PINK, c.bonds.get(1).endCol);
117 * Test setting bond start/end colours based on a colour scheme i.e. colour by
121 public void testSetChainColours_colourScheme()
123 Color alaColour = new Color(204, 255, 0);
124 Color glyColour = new Color(255, 153, 0);
127 a3.resName = "XXX"; // no colour defined
131 ColourSchemeI cs = new TaylorColourScheme();
132 c.setChainColours(cs);
134 Bond b = c.bonds.get(0);
135 assertEquals(alaColour, b.startCol);
136 assertEquals(glyColour, b.endCol);
139 assertEquals(glyColour, b.startCol);
140 assertEquals(alaColour, b.endCol);
141 // bond a2 to a3 - no colour found for a3
142 // exception handling defaults to gray
144 assertEquals(Color.gray, b.startCol);
145 assertEquals(Color.gray, b.endCol);
149 public void testGetChargeColour()
151 assertEquals(Color.red, PDBChain.getChargeColour("ASP"));
152 assertEquals(Color.red, PDBChain.getChargeColour("GLU"));
153 assertEquals(Color.blue, PDBChain.getChargeColour("LYS"));
154 assertEquals(Color.blue, PDBChain.getChargeColour("ARG"));
155 assertEquals(Color.yellow, PDBChain.getChargeColour("CYS"));
156 assertEquals(Color.lightGray, PDBChain.getChargeColour("ALA"));
157 assertEquals(Color.lightGray, PDBChain.getChargeColour(null));
161 * Test the method that sets bond start/end colours by residue charge property
164 public void testSetChargeColours()
166 a1.resName = "ASP"; // red
167 a2.resName = "LYS"; // blue
168 a3.resName = "CYS"; // yellow
169 a4.resName = "ALA"; // no colour (light gray)
173 c.setChargeColours();
174 assertEquals(3, c.bonds.size());
176 Bond b = c.bonds.get(0);
177 assertEquals(Color.red, b.startCol);
178 assertEquals(Color.blue, b.endCol);
181 assertEquals(Color.blue, b.startCol);
182 assertEquals(Color.yellow, b.endCol);
185 assertEquals(Color.yellow, b.startCol);
186 assertEquals(Color.lightGray, b.endCol);
190 * Test the method that converts the raw list of atoms to a list of residues
193 public void testMakeResidueList_noAnnotation()
195 Vector<Atom> atoms = new Vector<Atom>();
198 atoms.add(makeAtom(4, "N", "MET"));
199 atoms.add(makeAtom(4, "CA", "MET"));
200 atoms.add(makeAtom(4, "C", "MET"));
201 atoms.add(makeAtom(5, "O", "LYS"));
202 atoms.add(makeAtom(5, "N", "LYS"));
203 atoms.add(makeAtom(5, "CA", "LYS"));
204 atoms.add(makeAtom(6, "O", "LEU"));
205 atoms.add(makeAtom(6, "N", "LEU"));
206 atoms.add(makeAtom(6, "CA", "LEU"));
208 c.makeResidueList(false);
211 * check sequence constructed
213 assertEquals("MKL", c.sequence.getSequenceAsString());
215 assertEquals(3, c.residues.size());
218 * check sequence features
220 SequenceFeature[] sfs = c.sequence.getSequenceFeatures();
221 assertEquals(3, sfs.length);
222 assertEquals("RESNUM", sfs[0].type);
223 assertEquals("MET:4 1gaqA", sfs[0].description);
224 assertEquals(4, sfs[0].begin);
225 assertEquals(4, sfs[0].end);
226 assertEquals("RESNUM", sfs[0].type);
227 assertEquals("LYS:5 1gaqA", sfs[1].description);
228 assertEquals(5, sfs[1].begin);
229 assertEquals(5, sfs[1].end);
230 assertEquals("LEU:6 1gaqA", sfs[2].description);
231 assertEquals(6, sfs[2].begin);
232 assertEquals(6, sfs[2].end);
235 private Atom makeAtom(int resnum, String name, String resname)
237 Atom a = new Atom(1f, 2f, 3f);
238 a.resNumber = resnum;
239 a.resNumIns = String.valueOf(resnum);
247 * Test the method that converts the raw list of atoms to a list of residues,
248 * including parsing of tempFactor to an alignment annotation
251 public void testMakeResidueList_withTempFactor()
253 Vector<Atom> atoms = new Vector<Atom>();
255 atoms.add(makeAtom(4, "N", "MET"));
256 atoms.get(atoms.size()-1).tfactor = 1f;
257 atoms.add(makeAtom(4, "CA", "MET"));
258 atoms.get(atoms.size()-1).tfactor = 2f;
259 atoms.add(makeAtom(4, "C", "MET"));
260 atoms.get(atoms.size()-1).tfactor = 3f;
261 atoms.add(makeAtom(5, "O", "LYS"));
262 atoms.get(atoms.size()-1).tfactor = 7f;
263 atoms.add(makeAtom(5, "N", "LYS"));
264 atoms.get(atoms.size()-1).tfactor = 8f;
265 atoms.add(makeAtom(5, "CA", "LYS"));
266 atoms.get(atoms.size()-1).tfactor = 9f;
267 atoms.add(makeAtom(6, "O", "LEU"));
268 atoms.get(atoms.size()-1).tfactor = 4f;
269 atoms.add(makeAtom(6, "N", "LEU"));
270 atoms.get(atoms.size()-1).tfactor = 5f;
271 atoms.add(makeAtom(6, "CA", "LEU"));
272 atoms.get(atoms.size()-1).tfactor = 6f;
275 * make residues including temp factor annotation
277 c.makeResidueList(true);
280 * Verify annotations; note the tempFactor is read from the first atom in
281 * each residue i.e. we expect values 1, 7, 4 for the residues
283 AlignmentAnnotation[] ann = c.sequence.getAnnotation();
284 assertEquals(1, ann.length);
285 assertEquals("Temperature Factor", ann[0].label);
286 assertEquals("Temperature Factor for 1gaqA", ann[0].description);
287 assertSame(c.sequence, ann[0].sequenceRef);
288 assertEquals(AlignmentAnnotation.LINE_GRAPH, ann[0].graph);
289 assertEquals(0f, ann[0].graphMin, 0.001f);
290 assertEquals(7f, ann[0].graphMax, 0.001f);
291 assertEquals(3, ann[0].annotations.length);
292 assertEquals(1f, ann[0].annotations[0].value, 0.001f);
293 assertEquals(7f, ann[0].annotations[1].value, 0.001f);
294 assertEquals(4f, ann[0].annotations[2].value, 0.001f);
298 * Test the method that constructs bonds between successive residues' CA or P
302 public void testMakeCaBondList()
305 Vector<Atom> atoms = new Vector<Atom>();
307 atoms.add(makeAtom(4, "N", "MET"));
308 atoms.add(makeAtom(4, "CA", "MET"));
309 atoms.add(makeAtom(5, "CA", "ASP"));
310 atoms.add(makeAtom(5, "O", "ASP"));
311 atoms.add(makeAtom(6, "CA", "GLY"));
312 atoms.add(makeAtom(6, "N", "GLY"));
314 // have to make residue list first!
315 c.makeResidueList(false);
320 assertEquals(2, c.bonds.size());
321 Bond b = c.bonds.get(0);
322 assertSame(c.atoms.get(1), b.at1);
323 assertSame(c.atoms.get(2), b.at2);
325 assertSame(c.atoms.get(2), b.at1);
326 assertSame(c.atoms.get(4), b.at2);
328 // isNa flag is _not_ reset by this method!
333 public void testMakeCaBondList_nucleotide()
336 Vector<Atom> atoms = new Vector<Atom>();
338 atoms.add(makeAtom(4, "N", "G"));
339 atoms.add(makeAtom(4, "P", "G"));
340 atoms.add(makeAtom(5, "P", "C"));
341 atoms.add(makeAtom(5, "O", "C"));
342 atoms.add(makeAtom(6, "P", "T"));
343 atoms.add(makeAtom(6, "N", "T"));
345 // have to make residue list first!
346 c.makeResidueList(false);
347 assertEquals("GCT", c.sequence.getSequenceAsString());
350 assertEquals(2, c.bonds.size());
351 Bond b = c.bonds.get(0);
352 assertSame(c.atoms.get(1), b.at1);
353 assertSame(c.atoms.get(2), b.at2);
355 assertSame(c.atoms.get(2), b.at1);
356 assertSame(c.atoms.get(4), b.at2);
362 * Test the method that updates atoms with their alignment positions
365 public void testMakeExactMapping()
367 Vector<Atom> atoms = new Vector<Atom>();
369 atoms.add(makeAtom(4, "N", "MET"));
370 atoms.add(makeAtom(4, "CA", "MET"));
371 atoms.add(makeAtom(5, "CA", "ASP"));
372 atoms.add(makeAtom(5, "O", "ASP"));
373 atoms.add(makeAtom(6, "CA", "GLY"));
374 atoms.add(makeAtom(6, "N", "GLY"));
375 c.makeResidueList(false);
376 assertEquals("MDG", c.sequence.getSequenceAsString());
377 SequenceI s1 = new Sequence("Seq1", "MDG");
378 SequenceI s2 = new Sequence("Seq2", "MDG");
379 AlignSeq alignSeq = AlignSeq.doGlobalNWAlignment(s1, s2, AlignSeq.PEP);
380 SequenceI seq3 = new Sequence("Seq3", "--M-DG");
381 c.makeExactMapping(alignSeq, seq3);
384 for (Residue res : c.residues)
386 for (Atom a : res.atoms)
388 assertEquals(pos, a.alignmentMapping);