Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package mc_view

File PDBfileTest.java

 

Code metrics

2
121
9
1
336
197
10
0.08
13.44
9
1.11

Classes

Class Line # Actions
PDBfileTest 47 121 10 2
0.984848598.5%
 

Contributing tests

This file is covered by 5 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package mc_view;
22   
23    import static org.testng.AssertJUnit.assertEquals;
24    import static org.testng.AssertJUnit.assertFalse;
25    import static org.testng.AssertJUnit.assertNull;
26    import static org.testng.AssertJUnit.assertSame;
27    import static org.testng.AssertJUnit.assertTrue;
28   
29    import jalview.bin.Cache;
30    import jalview.datamodel.Alignment;
31    import jalview.datamodel.AlignmentAnnotation;
32    import jalview.datamodel.AlignmentI;
33    import jalview.datamodel.PDBEntry;
34    import jalview.datamodel.Sequence;
35    import jalview.datamodel.SequenceI;
36    import jalview.gui.JvOptionPane;
37    import jalview.io.DataSourceType;
38    import jalview.structure.StructureImportSettings;
39   
40    import java.io.IOException;
41    import java.util.List;
42   
43    import org.testng.annotations.BeforeClass;
44    import org.testng.annotations.BeforeMethod;
45    import org.testng.annotations.Test;
46   
 
47    public class PDBfileTest
48    {
49   
 
50  1 toggle @BeforeClass(alwaysRun = true)
51    public void setUpJvOptionPane()
52    {
53  1 JvOptionPane.setInteractiveMode(false);
54  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
55    }
56   
 
57  1 toggle @Test(groups = { "Functional" })
58    public void testIsRna()
59    {
60  1 SequenceI seq = new Sequence("Seq1", "CGAU");
61  1 assertTrue(PDBfile.isRNA(seq));
62   
63  1 seq.setSequence("CGAu");
64  1 assertFalse(PDBfile.isRNA(seq));
65   
66  1 seq.setSequence("CGAT");
67  1 assertFalse(PDBfile.isRNA(seq));
68   
69  1 seq.setSequence("GRSWYFLAVM");
70  1 assertFalse(PDBfile.isRNA(seq));
71    }
72   
73    /**
74    * Test the 'high level' outputs of parsing. More detailed tests in
75    * PDBChainTest.
76    *
77    * @throws IOException
78    */
 
79  1 toggle @Test(groups = { "Functional" })
80    public void testParse() throws IOException
81    {
82    /*
83    * Constructor with file path performs parse()
84    */
85  1 PDBfile pf = new PDBfile(false, false, false, "examples/3W5V.pdb",
86    DataSourceType.FILE);
87   
88  1 assertEquals("3W5V", pf.getId());
89    // verify no alignment annotations created
90  1 assertNull(getAlignmentAnnotations(pf));
91   
92  1 assertEquals(4, pf.getChains().size());
93  1 assertEquals("A", pf.getChains().get(0).id);
94  1 assertEquals("B", pf.getChains().get(1).id);
95  1 assertEquals("C", pf.getChains().get(2).id);
96  1 assertEquals("D", pf.getChains().get(3).id);
97   
98  1 PDBChain chainA = pf.getChains().get(0);
99  1 SequenceI seqA = pf.getSeqs().get(0);
100   
101  1 assertEquals(0, chainA.seqstart); // not set
102  1 assertEquals(0, chainA.seqend); // not set
103  1 assertEquals(18, chainA.sequence.getStart());
104  1 assertEquals(314, chainA.sequence.getEnd());
105  1 assertTrue(chainA.sequence.getSequenceAsString().startsWith("KCSKKQEE"));
106  1 assertTrue(chainA.sequence.getSequenceAsString().endsWith("WNVEVY"));
107  1 assertEquals("3W5V|A", chainA.sequence.getName());
108  1 assertNull(chainA.sequence.getAnnotation());
109  1 assertEquals(1, seqA.getAllPDBEntries().size());
110  1 PDBEntry pdb = seqA.getAllPDBEntries().get(0);
111  1 assertEquals("A", pdb.getChainCode());
112  1 assertEquals("PDB", pdb.getType());
113  1 assertEquals("3W5V", pdb.getId());
114   
115  1 PDBChain chainB = pf.getChains().get(1);
116  1 assertEquals(1, chainB.sequence.getStart());
117  1 assertEquals(96, chainB.sequence.getEnd());
118  1 assertTrue(chainB.sequence.getSequenceAsString().startsWith("ATYNVK"));
119  1 assertTrue(chainB.sequence.getSequenceAsString().endsWith("KEEELT"));
120  1 assertEquals("3W5V|B", chainB.sequence.getName());
121   
122  1 PDBChain chainC = pf.getChains().get(2);
123  1 assertEquals(18, chainC.sequence.getStart());
124  1 assertEquals(314, chainC.sequence.getEnd());
125  1 assertTrue(chainC.sequence.getSequenceAsString().startsWith("KCSKKQEE"));
126  1 assertTrue(chainC.sequence.getSequenceAsString().endsWith("WNVEVY"));
127  1 assertEquals("3W5V|C", chainC.sequence.getName());
128   
129  1 PDBChain chainD = pf.getChains().get(3);
130  1 assertEquals(1, chainD.sequence.getStart());
131  1 assertEquals(96, chainD.sequence.getEnd());
132  1 assertTrue(chainD.sequence.getSequenceAsString().startsWith("ATYNVK"));
133  1 assertTrue(chainD.sequence.getSequenceAsString().endsWith("KEEELT"));
134  1 assertEquals("3W5V|D", chainD.sequence.getName());
135   
136    /*
137    * verify PDB-related data in parsed sequences
138    */
139  1 List<SequenceI> seqs = pf.getSeqs();
140  1 assertEquals(4, seqs.size());
141  1 assertEquals("3W5V|A", seqs.get(0).getName());
142  1 assertEquals("3W5V|B", seqs.get(1).getName());
143  1 assertEquals("3W5V|C", seqs.get(2).getName());
144  1 assertEquals("3W5V|D", seqs.get(3).getName());
145  1 assertEquals(1, seqs.get(0).getAllPDBEntries().size());
146  1 PDBEntry pdbe = seqs.get(0).getAllPDBEntries().get(0);
147  1 assertEquals("A", pdbe.getChainCode());
148  1 assertEquals("3W5V", pdbe.getId());
149  1 assertEquals(PDBEntry.Type.PDB.toString(), pdbe.getType());
150    }
151   
152    /**
153    * Test parsing, with annotations added to the alignment but no secondary
154    * structure prediction
155    *
156    * @throws IOException
157    */
 
158  1 toggle @Test(groups = { "Functional" })
159    public void testParse_withAnnotations_noSS() throws IOException
160    {
161  1 PDBfile pf = new PDBfile(true, false, false, "examples/3W5V.pdb",
162    DataSourceType.FILE);
163   
164  1 AlignmentAnnotation[] anns = getAlignmentAnnotations(pf);
165  1 assertEquals(4, anns.length);
166   
167    /*
168    * Inspect temp factor annotation for chain A
169    */
170  1 AlignmentAnnotation chainAnnotation = anns[0];
171  1 assertEquals("Temperature Factor", chainAnnotation.label);
172    // PDBChain constructor changes PDB id to lower case (why?)
173  1 assertEquals("Temperature Factor for 3w5vA",
174    chainAnnotation.description);
175  1 assertSame(pf.getSeqs().get(0), chainAnnotation.sequenceRef);
176  1 assertEquals(AlignmentAnnotation.LINE_GRAPH, chainAnnotation.graph);
177  1 assertEquals(0f, chainAnnotation.graphMin, 0.001f);
178  1 assertEquals(40f, chainAnnotation.graphMax, 0.001f);
179  1 assertEquals(297, chainAnnotation.annotations.length);
180  1 assertEquals(40f, chainAnnotation.annotations[0].value, 0.001f);
181   
182    /*
183    * Chain B temp factor
184    */
185  1 chainAnnotation = anns[1];
186  1 assertEquals("Temperature Factor for 3w5vB",
187    chainAnnotation.description);
188  1 assertSame(pf.getSeqs().get(1), chainAnnotation.sequenceRef);
189  1 assertEquals(96, chainAnnotation.annotations.length);
190   
191    /*
192    * Chain C temp factor
193    */
194  1 chainAnnotation = anns[2];
195  1 assertEquals("Temperature Factor for 3w5vC",
196    chainAnnotation.description);
197  1 assertSame(pf.getSeqs().get(2), chainAnnotation.sequenceRef);
198  1 assertEquals(297, chainAnnotation.annotations.length);
199   
200    /*
201    * Chain D temp factor
202    */
203  1 chainAnnotation = anns[3];
204  1 assertEquals("Temperature Factor for 3w5vD",
205    chainAnnotation.description);
206  1 assertSame(pf.getSeqs().get(3), chainAnnotation.sequenceRef);
207  1 assertEquals(96, chainAnnotation.annotations.length);
208    }
209   
210    /**
211    * Test parsing including secondary structure annotation using JMol; this test
212    * for the case where flag to add annotations to alignment is set false
213    *
214    * @throws IOException
215    */
 
216  1 toggle @Test(groups = { "Functional" })
217    public void testParse_withJmol_noAnnotations() throws IOException
218    {
219  1 PDBfile pf = new PDBfile(false, true, false, "examples/3W5V.pdb",
220    DataSourceType.FILE);
221   
222    /*
223    * alignment annotations _are_ created anyway (in
224    * AlignSeq.replaceMatchingSeqsWith())
225    */
226  1 final AlignmentAnnotation[] anns = getAlignmentAnnotations(pf);
227  1 assertEquals(4, anns.length);
228   
229    /*
230    * no sequence annotations created - tempFactor annotation is not added
231    * unless the flag to 'addAlignmentAnnotations' is set true
232    */
233  1 for (PDBChain c : pf.getChains())
234    {
235  4 assertNull(c.sequence.getAnnotation());
236    }
237    }
238   
239    /**
240    * Test parsing including secondary structure prediction and annotation using
241    * JMol
242    *
243    * @throws IOException
244    */
 
245  1 toggle @Test(groups = { "Functional" })
246    public void testParse_withJmolAddAlignmentAnnotations()
247    throws IOException
248    {
249  1 PDBfile pf = new PDBfile(true, true, false, "examples/3W5V.pdb",
250    DataSourceType.FILE);
251   
252    /*
253    * Alignment annotations for TempFactor, SecStruct, per sequence (chain)
254    */
255  1 AlignmentAnnotation[] anns = getAlignmentAnnotations(pf);
256  1 assertEquals(8, anns.length);
257   
258    /*
259    * other tests have detailed assertions for Temp Factor annotations
260    */
261  1 assertEquals("Temperature Factor for 3w5vA", anns[1].description);
262  1 assertEquals("Temperature Factor for 3w5vB", anns[3].description);
263  1 assertEquals("Temperature Factor for 3w5vC", anns[5].description);
264  1 assertEquals("Temperature Factor for 3w5vD", anns[7].description);
265   
266    /*
267    * PDBFileWithJmol (unlike PDBChain!) leaves PDB id upper case
268    */
269  1 assertEquals("Secondary Structure for 3w5vA", anns[0].description);
270  1 assertEquals("Secondary Structure for 3w5vB", anns[2].description);
271  1 assertEquals("Secondary Structure for 3w5vC", anns[4].description);
272  1 assertEquals("Secondary Structure for 3w5vD", anns[6].description);
273   
274    /*
275    * Verify SS annotations are linked to respective sequences (chains)
276    */
277  1 assertSame(pf.getSeqs().get(0), anns[0].sequenceRef);
278  1 assertSame(pf.getSeqs().get(1), anns[2].sequenceRef);
279  1 assertSame(pf.getSeqs().get(2), anns[4].sequenceRef);
280  1 assertSame(pf.getSeqs().get(3), anns[6].sequenceRef);
281   
282    /*
283    * Verify a sample of SS predictions
284    */
285  21 for (int i = 0; i < 20; i++)
286    {
287  20 assertNull(anns[0].annotations[i]);
288  20 assertEquals("E", anns[0].annotations[20].displayCharacter);
289  20 assertEquals('E', anns[0].annotations[20].secondaryStructure);
290  20 assertEquals("E", anns[2].annotations[18].displayCharacter);
291  20 assertEquals("H", anns[2].annotations[23].displayCharacter);
292    }
293    }
294   
295    /**
296    * Placeholder for a test of parsing RNA structure with secondary structure
297    * prediction using the Annotate3D service
298    *
299    * @throws IOException
300    */
301   
 
302  0 toggle @Test(groups = { "Functional" }, enabled = false)
303    public void testParse_withAnnotate3D() throws IOException
304    {
305    // TODO requires a mock for Annotate3D processing
306    // and/or run as an integration test
307  0 PDBfile pf = new PDBfile(true, true, true, "examples/2GIS.pdb",
308    DataSourceType.FILE);
309    }
310   
311    /**
312    * Helper method to extract parsed annotations from the PDBfile
313    *
314    * @param pf
315    * @return
316    */
 
317  4 toggle private AlignmentAnnotation[] getAlignmentAnnotations(PDBfile pf)
318    {
319  4 AlignmentI al = new Alignment(pf.getSeqsAsArray());
320  4 pf.addAnnotations(al);
321  4 return al.getAlignmentAnnotation();
322    }
323   
 
324  5 toggle @BeforeMethod(alwaysRun = true)
325    public void setUp()
326    {
327  5 Cache.loadProperties("test/jalview/io/testProps.jvprops");
328  5 Cache.applicationProperties.setProperty("STRUCT_FROM_PDB",
329    Boolean.TRUE.toString());
330  5 Cache.applicationProperties.setProperty("ADD_TEMPFACT_ANN",
331    Boolean.TRUE.toString());
332  5 Cache.applicationProperties.setProperty("ADD_SS_ANN",
333    Boolean.TRUE.toString());
334  5 StructureImportSettings.setDefaultStructureFileFormat("PDB");
335    }
336    }