3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertFalse;
5 import static org.junit.Assert.assertNull;
6 import static org.junit.Assert.assertSame;
7 import static org.junit.Assert.assertTrue;
8 import jalview.datamodel.Alignment;
9 import jalview.datamodel.AlignmentAnnotation;
10 import jalview.datamodel.AlignmentI;
11 import jalview.datamodel.PDBEntry;
12 import jalview.datamodel.Sequence;
13 import jalview.datamodel.SequenceI;
14 import jalview.io.AppletFormatAdapter;
16 import java.io.IOException;
18 import org.junit.Ignore;
19 import org.junit.Test;
21 public class PDBfileTest
24 public void testIsRna()
26 SequenceI seq = new Sequence("Seq1", "CGAU");
27 assertTrue(PDBfile.isRNA(seq));
29 seq.setSequence("CGAu");
30 assertFalse(PDBfile.isRNA(seq));
32 seq.setSequence("CGAT");
33 assertFalse(PDBfile.isRNA(seq));
35 seq.setSequence("GRSWYFLAVM");
36 assertFalse(PDBfile.isRNA(seq));
40 * Test the 'high level' outputs of parsing. More detailed tests in
46 public void testParse() throws IOException
49 * Constructor with file path performs parse()
51 PDBfile pf = new PDBfile(false, false, false, "examples/3W5V.pdb",
52 AppletFormatAdapter.FILE);
54 assertEquals("3W5V", pf.id);
55 // verify no alignment annotations created
56 assertNull(getAlignmentAnnotations(pf));
58 assertEquals(4, pf.chains.size());
59 assertEquals("A", pf.chains.get(0).id);
60 assertEquals("B", pf.chains.get(1).id);
61 assertEquals("C", pf.chains.get(2).id);
62 assertEquals("D", pf.chains.get(3).id);
64 PDBChain chainA = pf.chains.get(0);
65 assertEquals(0, chainA.seqstart); // not set
66 assertEquals(0, chainA.seqend); // not set
67 assertEquals(18, chainA.sequence.getStart());
68 assertEquals(314, chainA.sequence.getEnd());
69 assertTrue(chainA.sequence.getSequenceAsString().startsWith("KCSKKQEE"));
70 assertTrue(chainA.sequence.getSequenceAsString().endsWith("WNVEVY"));
71 assertEquals("3W5V|A", chainA.sequence.getName());
72 assertNull(chainA.sequence.getAnnotation());
73 assertEquals(1, chainA.sequence.getPDBId().size());
74 PDBEntry pdb = chainA.sequence.getPDBId().get(0);
75 assertEquals("A", pdb.getChainCode());
76 assertEquals("PDB", pdb.getType());
77 assertEquals("3W5V", pdb.getId());
79 PDBChain chainB = pf.chains.get(1);
80 assertEquals(1, chainB.sequence.getStart());
81 assertEquals(96, chainB.sequence.getEnd());
82 assertTrue(chainB.sequence.getSequenceAsString().startsWith("ATYNVK"));
83 assertTrue(chainB.sequence.getSequenceAsString().endsWith("KEEELT"));
84 assertEquals("3W5V|B", chainB.sequence.getName());
86 PDBChain chainC = pf.chains.get(2);
87 assertEquals(18, chainC.sequence.getStart());
88 assertEquals(314, chainC.sequence.getEnd());
89 assertTrue(chainC.sequence.getSequenceAsString().startsWith("KCSKKQEE"));
90 assertTrue(chainC.sequence.getSequenceAsString().endsWith("WNVEVY"));
91 assertEquals("3W5V|C", chainC.sequence.getName());
93 PDBChain chainD = pf.chains.get(3);
94 assertEquals(1, chainD.sequence.getStart());
95 assertEquals(96, chainD.sequence.getEnd());
96 assertTrue(chainD.sequence.getSequenceAsString().startsWith("ATYNVK"));
97 assertTrue(chainD.sequence.getSequenceAsString().endsWith("KEEELT"));
98 assertEquals("3W5V|D", chainD.sequence.getName());
102 * Test parsing, with annotations added to the alignment but no secondary
103 * structure prediction
105 * @throws IOException
108 public void testParse_withAnnotations_noSS() throws IOException
110 PDBfile pf = new PDBfile(true, false, false, "examples/3W5V.pdb",
111 AppletFormatAdapter.FILE);
113 AlignmentAnnotation[] anns = getAlignmentAnnotations(pf);
114 assertEquals(4, anns.length);
117 * Inspect temp factor annotation for chain A
119 AlignmentAnnotation chainAnnotation = anns[0];
120 assertEquals("Temperature Factor", chainAnnotation.label);
121 // PDBChain constructor changes PDB id to lower case (why?)
122 assertEquals("Temperature Factor for 3w5vA",
123 chainAnnotation.description);
124 assertSame(pf.getSeqs().get(0), chainAnnotation.sequenceRef);
125 assertEquals(AlignmentAnnotation.LINE_GRAPH, chainAnnotation.graph);
126 assertEquals(0f, chainAnnotation.graphMin, 0.001f);
127 assertEquals(40f, chainAnnotation.graphMax, 0.001f);
128 assertEquals(297, chainAnnotation.annotations.length);
129 assertEquals(40f, chainAnnotation.annotations[0].value, 0.001f);
132 * Chain B temp factor
134 chainAnnotation = anns[1];
135 assertEquals("Temperature Factor for 3w5vB",
136 chainAnnotation.description);
137 assertSame(pf.getSeqs().get(1), chainAnnotation.sequenceRef);
138 assertEquals(96, chainAnnotation.annotations.length);
141 * Chain C temp factor
143 chainAnnotation = anns[2];
144 assertEquals("Temperature Factor for 3w5vC",
145 chainAnnotation.description);
146 assertSame(pf.getSeqs().get(2), chainAnnotation.sequenceRef);
147 assertEquals(297, chainAnnotation.annotations.length);
150 * Chain D temp factor
152 chainAnnotation = anns[3];
153 assertEquals("Temperature Factor for 3w5vD",
154 chainAnnotation.description);
155 assertSame(pf.getSeqs().get(3), chainAnnotation.sequenceRef);
156 assertEquals(96, chainAnnotation.annotations.length);
160 * Test parsing including secondary structure annotation using JMol; this test
161 * for the case where flag to add annotations to alignment is set false
163 * @throws IOException
166 public void testParse_withJmol_noAnnotations() throws IOException
168 PDBfile pf = new PDBfile(false, true, false, "examples/3W5V.pdb",
169 AppletFormatAdapter.FILE);
172 * alignment annotations _are_ created anyway (in
173 * AlignSeq.replaceMatchingSeqsWith())
175 final AlignmentAnnotation[] anns = getAlignmentAnnotations(pf);
176 assertEquals(4, anns.length);
179 * no sequence annotations created - tempFactor annotation is not added
180 * unless the flag to 'addAlignmentAnnotations' is set true
182 for (PDBChain c : pf.chains)
184 assertNull(c.sequence.getAnnotation());
189 * Test parsing including secondary structure prediction and annotation using
192 * @throws IOException
195 public void testParse_withJmolAddAlignmentAnnotations()
198 PDBfile pf = new PDBfile(true, true, false, "examples/3W5V.pdb",
199 AppletFormatAdapter.FILE);
202 * Alignment annotations for TempFactor, SecStruct, per sequence (chain)
204 AlignmentAnnotation[] anns = getAlignmentAnnotations(pf);
205 assertEquals(8, anns.length);
208 * other tests have detailed assertions for Temp Factor annotations
210 assertEquals("Temperature Factor for 3w5vA", anns[1].description);
211 assertEquals("Temperature Factor for 3w5vB", anns[3].description);
212 assertEquals("Temperature Factor for 3w5vC", anns[5].description);
213 assertEquals("Temperature Factor for 3w5vD", anns[7].description);
216 * PDBFileWithJmol (unlike PDBChain!) leaves PDB id upper case
218 assertEquals("Secondary Structure for 3W5VA", anns[0].description);
219 assertEquals("Secondary Structure for 3W5VB", anns[2].description);
220 assertEquals("Secondary Structure for 3W5VC", anns[4].description);
221 assertEquals("Secondary Structure for 3W5VD", anns[6].description);
224 * Verify SS annotations are linked to respective sequences (chains)
226 assertSame(pf.getSeqs().get(0), anns[0].sequenceRef);
227 assertSame(pf.getSeqs().get(1), anns[2].sequenceRef);
228 assertSame(pf.getSeqs().get(2), anns[4].sequenceRef);
229 assertSame(pf.getSeqs().get(3), anns[6].sequenceRef);
232 * Verify a sample of SS predictions
234 for (int i = 0; i < 20; i++)
236 assertNull(anns[0].annotations[i]);
237 assertEquals("E", anns[0].annotations[20].displayCharacter);
238 assertEquals('E', anns[0].annotations[20].secondaryStructure);
239 assertEquals("E", anns[2].annotations[18].displayCharacter);
240 assertEquals("H", anns[2].annotations[23].displayCharacter);
245 * Placeholder for a test of parsing RNA structure with secondary structure
246 * prediction using the Annotate3D service
248 * @throws IOException
252 public void testParse_withAnnotate3D() throws IOException
254 // TODO requires a mock for Annotate3D processing
255 // and/or run as an integration test
256 PDBfile pf = new PDBfile(true, true, true, "examples/2GIS.pdb",
257 AppletFormatAdapter.FILE);
260 * Helper method to extract parsed annotations from the PDBfile
265 private AlignmentAnnotation[] getAlignmentAnnotations(PDBfile pf)
267 AlignmentI al = new Alignment(pf.getSeqsAsArray());
268 pf.addAnnotations((Alignment) al);
269 return al.getAlignmentAnnotation();