3 import static org.testng.AssertJUnit.assertEquals;
4 import static org.testng.AssertJUnit.assertFalse;
5 import static org.testng.AssertJUnit.assertNull;
6 import static org.testng.AssertJUnit.assertSame;
7 import static org.testng.AssertJUnit.assertTrue;
9 import jalview.datamodel.Alignment;
10 import jalview.datamodel.AlignmentAnnotation;
11 import jalview.datamodel.AlignmentI;
12 import jalview.datamodel.PDBEntry;
13 import jalview.datamodel.Sequence;
14 import jalview.datamodel.SequenceI;
15 import jalview.io.AppletFormatAdapter;
17 import java.io.IOException;
18 import java.util.List;
20 import org.testng.annotations.Test;
22 public class PDBfileTest
24 @Test(groups ={ "Functional" })
25 public void testIsRna()
27 SequenceI seq = new Sequence("Seq1", "CGAU");
28 assertTrue(PDBfile.isRNA(seq));
30 seq.setSequence("CGAu");
31 assertFalse(PDBfile.isRNA(seq));
33 seq.setSequence("CGAT");
34 assertFalse(PDBfile.isRNA(seq));
36 seq.setSequence("GRSWYFLAVM");
37 assertFalse(PDBfile.isRNA(seq));
41 * Test the 'high level' outputs of parsing. More detailed tests in
46 @Test(groups ={ "Functional" })
47 public void testParse() throws IOException
50 * Constructor with file path performs parse()
52 PDBfile pf = new PDBfile(false, false, false, "examples/3W5V.pdb",
53 AppletFormatAdapter.FILE);
55 assertEquals("3W5V", pf.id);
56 // verify no alignment annotations created
57 assertNull(getAlignmentAnnotations(pf));
59 assertEquals(4, pf.chains.size());
60 assertEquals("A", pf.chains.get(0).id);
61 assertEquals("B", pf.chains.get(1).id);
62 assertEquals("C", pf.chains.get(2).id);
63 assertEquals("D", pf.chains.get(3).id);
65 PDBChain chainA = pf.chains.get(0);
66 assertEquals(0, chainA.seqstart); // not set
67 assertEquals(0, chainA.seqend); // not set
68 assertEquals(18, chainA.sequence.getStart());
69 assertEquals(314, chainA.sequence.getEnd());
70 assertTrue(chainA.sequence.getSequenceAsString().startsWith("KCSKKQEE"));
71 assertTrue(chainA.sequence.getSequenceAsString().endsWith("WNVEVY"));
72 assertEquals("3W5V|A", chainA.sequence.getName());
73 assertNull(chainA.sequence.getAnnotation());
74 assertEquals(1, chainA.sequence.getPDBId().size());
75 PDBEntry pdb = chainA.sequence.getPDBId().get(0);
76 assertEquals("A", pdb.getChainCode());
77 assertEquals("PDB", pdb.getType());
78 assertEquals("3W5V", pdb.getId());
80 PDBChain chainB = pf.chains.get(1);
81 assertEquals(1, chainB.sequence.getStart());
82 assertEquals(96, chainB.sequence.getEnd());
83 assertTrue(chainB.sequence.getSequenceAsString().startsWith("ATYNVK"));
84 assertTrue(chainB.sequence.getSequenceAsString().endsWith("KEEELT"));
85 assertEquals("3W5V|B", chainB.sequence.getName());
87 PDBChain chainC = pf.chains.get(2);
88 assertEquals(18, chainC.sequence.getStart());
89 assertEquals(314, chainC.sequence.getEnd());
90 assertTrue(chainC.sequence.getSequenceAsString().startsWith("KCSKKQEE"));
91 assertTrue(chainC.sequence.getSequenceAsString().endsWith("WNVEVY"));
92 assertEquals("3W5V|C", chainC.sequence.getName());
94 PDBChain chainD = pf.chains.get(3);
95 assertEquals(1, chainD.sequence.getStart());
96 assertEquals(96, chainD.sequence.getEnd());
97 assertTrue(chainD.sequence.getSequenceAsString().startsWith("ATYNVK"));
98 assertTrue(chainD.sequence.getSequenceAsString().endsWith("KEEELT"));
99 assertEquals("3W5V|D", chainD.sequence.getName());
102 * verify PDB-related data in parsed sequences
104 List<SequenceI> seqs = pf.getSeqs();
105 assertEquals(4, seqs.size());
106 assertEquals("3W5V|A", seqs.get(0).getName());
107 assertEquals("3W5V|B", seqs.get(1).getName());
108 assertEquals("3W5V|C", seqs.get(2).getName());
109 assertEquals("3W5V|D", seqs.get(3).getName());
110 assertEquals(1, seqs.get(0).getPDBId().size());
111 PDBEntry pdbe = seqs.get(0).getPDBId().get(0);
112 assertEquals("A", pdbe.getChainCode());
113 assertEquals("3W5V", pdbe.getId());
114 assertEquals(PDBEntry.Type.PDB.toString(), pdbe.getType());
118 * Test parsing, with annotations added to the alignment but no secondary
119 * structure prediction
121 * @throws IOException
123 @Test(groups ={ "Functional" })
124 public void testParse_withAnnotations_noSS() throws IOException
126 PDBfile pf = new PDBfile(true, false, false, "examples/3W5V.pdb",
127 AppletFormatAdapter.FILE);
129 AlignmentAnnotation[] anns = getAlignmentAnnotations(pf);
130 assertEquals(4, anns.length);
133 * Inspect temp factor annotation for chain A
135 AlignmentAnnotation chainAnnotation = anns[0];
136 assertEquals("Temperature Factor", chainAnnotation.label);
137 // PDBChain constructor changes PDB id to lower case (why?)
138 assertEquals("Temperature Factor for 3w5vA",
139 chainAnnotation.description);
140 assertSame(pf.getSeqs().get(0), chainAnnotation.sequenceRef);
141 assertEquals(AlignmentAnnotation.LINE_GRAPH, chainAnnotation.graph);
142 assertEquals(0f, chainAnnotation.graphMin, 0.001f);
143 assertEquals(40f, chainAnnotation.graphMax, 0.001f);
144 assertEquals(297, chainAnnotation.annotations.length);
145 assertEquals(40f, chainAnnotation.annotations[0].value, 0.001f);
148 * Chain B temp factor
150 chainAnnotation = anns[1];
151 assertEquals("Temperature Factor for 3w5vB",
152 chainAnnotation.description);
153 assertSame(pf.getSeqs().get(1), chainAnnotation.sequenceRef);
154 assertEquals(96, chainAnnotation.annotations.length);
157 * Chain C temp factor
159 chainAnnotation = anns[2];
160 assertEquals("Temperature Factor for 3w5vC",
161 chainAnnotation.description);
162 assertSame(pf.getSeqs().get(2), chainAnnotation.sequenceRef);
163 assertEquals(297, chainAnnotation.annotations.length);
166 * Chain D temp factor
168 chainAnnotation = anns[3];
169 assertEquals("Temperature Factor for 3w5vD",
170 chainAnnotation.description);
171 assertSame(pf.getSeqs().get(3), chainAnnotation.sequenceRef);
172 assertEquals(96, chainAnnotation.annotations.length);
176 * Test parsing including secondary structure annotation using JMol; this test
177 * for the case where flag to add annotations to alignment is set false
179 * @throws IOException
181 @Test(groups ={ "Functional" })
182 public void testParse_withJmol_noAnnotations() throws IOException
184 PDBfile pf = new PDBfile(false, true, false, "examples/3W5V.pdb",
185 AppletFormatAdapter.FILE);
188 * alignment annotations _are_ created anyway (in
189 * AlignSeq.replaceMatchingSeqsWith())
191 final AlignmentAnnotation[] anns = getAlignmentAnnotations(pf);
192 assertEquals(4, anns.length);
195 * no sequence annotations created - tempFactor annotation is not added
196 * unless the flag to 'addAlignmentAnnotations' is set true
198 for (PDBChain c : pf.chains)
200 assertNull(c.sequence.getAnnotation());
205 * Test parsing including secondary structure prediction and annotation using
208 * @throws IOException
210 @Test(groups ={ "Functional" })
211 public void testParse_withJmolAddAlignmentAnnotations()
214 PDBfile pf = new PDBfile(true, true, false, "examples/3W5V.pdb",
215 AppletFormatAdapter.FILE);
218 * Alignment annotations for TempFactor, SecStruct, per sequence (chain)
220 AlignmentAnnotation[] anns = getAlignmentAnnotations(pf);
221 assertEquals(8, anns.length);
224 * other tests have detailed assertions for Temp Factor annotations
226 assertEquals("Temperature Factor for 3w5vA", anns[1].description);
227 assertEquals("Temperature Factor for 3w5vB", anns[3].description);
228 assertEquals("Temperature Factor for 3w5vC", anns[5].description);
229 assertEquals("Temperature Factor for 3w5vD", anns[7].description);
232 * PDBFileWithJmol (unlike PDBChain!) leaves PDB id upper case
234 assertEquals("Secondary Structure for 3W5VA", anns[0].description);
235 assertEquals("Secondary Structure for 3W5VB", anns[2].description);
236 assertEquals("Secondary Structure for 3W5VC", anns[4].description);
237 assertEquals("Secondary Structure for 3W5VD", anns[6].description);
240 * Verify SS annotations are linked to respective sequences (chains)
242 assertSame(pf.getSeqs().get(0), anns[0].sequenceRef);
243 assertSame(pf.getSeqs().get(1), anns[2].sequenceRef);
244 assertSame(pf.getSeqs().get(2), anns[4].sequenceRef);
245 assertSame(pf.getSeqs().get(3), anns[6].sequenceRef);
248 * Verify a sample of SS predictions
250 for (int i = 0; i < 20; i++)
252 assertNull(anns[0].annotations[i]);
253 assertEquals("E", anns[0].annotations[20].displayCharacter);
254 assertEquals('E', anns[0].annotations[20].secondaryStructure);
255 assertEquals("E", anns[2].annotations[18].displayCharacter);
256 assertEquals("H", anns[2].annotations[23].displayCharacter);
261 * Placeholder for a test of parsing RNA structure with secondary structure
262 * prediction using the Annotate3D service
264 * @throws IOException
268 { "Functional" }, enabled = false)
269 public void testParse_withAnnotate3D() throws IOException
271 // TODO requires a mock for Annotate3D processing
272 // and/or run as an integration test
273 PDBfile pf = new PDBfile(true, true, true, "examples/2GIS.pdb",
274 AppletFormatAdapter.FILE);
277 * Helper method to extract parsed annotations from the PDBfile
282 private AlignmentAnnotation[] getAlignmentAnnotations(PDBfile pf)
284 AlignmentI al = new Alignment(pf.getSeqsAsArray());
285 pf.addAnnotations(al);
286 return al.getAlignmentAnnotation();