Clover icon

Coverage Report

  1. Project Clover database Thu Nov 7 2024 13:01:17 GMT
  2. Package jalview.io

File AnnotatedPDBFileInputTest.java

 

Code metrics

20
82
9
1
271
200
20
0.24
9.11
9
2.22

Classes

Class Line # Actions
AnnotatedPDBFileInputTest 49 82 20
0.837837883.8%
 

Contributing tests

This file is covered by 4 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 jalview.io;
22   
23    import static org.testng.AssertJUnit.assertEquals;
24    import static org.testng.AssertJUnit.assertNotNull;
25    import static org.testng.AssertJUnit.assertTrue;
26   
27    import java.io.File;
28    import java.util.List;
29   
30    import org.junit.Assert;
31    import org.testng.annotations.AfterClass;
32    import org.testng.annotations.BeforeClass;
33    import org.testng.annotations.BeforeMethod;
34    import org.testng.annotations.Test;
35   
36    import jalview.bin.Cache;
37    import jalview.datamodel.AlignmentAnnotation;
38    import jalview.datamodel.AlignmentI;
39    import jalview.datamodel.PDBEntry;
40    import jalview.datamodel.SequenceFeature;
41    import jalview.datamodel.SequenceI;
42    import jalview.datamodel.features.SequenceFeatures;
43    import jalview.gui.AlignFrame;
44    import jalview.gui.Desktop;
45    import jalview.gui.JvOptionPane;
46    import jalview.structure.StructureImportSettings;
47    import jalview.structure.StructureImportSettings.StructureParser;
48   
 
49    public class AnnotatedPDBFileInputTest
50    {
51   
 
52  1 toggle @BeforeClass(alwaysRun = true)
53    public void setUpJvOptionPane()
54    {
55  1 JvOptionPane.setInteractiveMode(false);
56  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
57    }
58   
59    AlignmentI al;
60   
61    String pdbId;
62   
63    /**
64    * Ensure 'process secondary structure from PDB and add annotations' are set
65    * in preferences, and load PDB example file 1gaq
66    *
67    * @throws Exception
68    */
 
69  4 toggle @BeforeMethod(alwaysRun = true)
70    public void setup() throws Exception
71    {
72  4 Cache.applicationProperties.setProperty("STRUCT_FROM_PDB",
73    Boolean.TRUE.toString());
74  4 Cache.applicationProperties.setProperty("ADD_SS_ANN",
75    Boolean.TRUE.toString());
76  4 FileLoader loader = new FileLoader(false);
77  4 AlignFrame af = loader.LoadFileWaitTillLoaded("examples/1gaq.txt",
78    DataSourceType.FILE);
79  4 al = af.getViewport().getAlignment();
80  4 pdbId = al.getSequenceAt(0).getDatasetSequence().getAllPDBEntries()
81    .get(0).getId();
82  4 StructureImportSettings.setDefaultStructureFileFormat("PDB");
83    // StructureImportSettings
84    // .setDefaultPDBFileParser(StructureParser.JALVIEW_PARSER);
85    }
86   
 
87  1 toggle @Test(groups = { "Functional" })
88    public void checkNoDuplicates()
89    {
90    // not strictly a requirement, but strange things may happen if multiple
91    // instances of the same annotation are placed in the alignment annotation
92    // vector
93  1 assertNotNull(al.getAlignmentAnnotation());
94    // verify that all sequence annotation is doubly referenced
95  1 AlignmentAnnotation[] avec = al.getAlignmentAnnotation();
96  11 for (int p = 0; p < avec.length; p++)
97    {
98  55 for (int q = p + 1; q < avec.length; q++)
99    {
100  45 assertTrue("Found a duplicate annotation row " + avec[p].label,
101    avec[p] != avec[q]);
102    }
103    }
104    }
105   
 
106  0 toggle @Test(groups = { "Functional" }, enabled = false)
107    public void checkPDBannotationSource()
108    {
109  0 Assert.fail(
110    "This test is incorrect - does not verify that JmolParser's annotation rows can be recognised as generated by the Jmol parser.");
111  0 for (SequenceI asq : al.getSequences())
112    {
113  0 for (AlignmentAnnotation aa : asq.getAnnotation())
114    {
115   
116  0 System.out.println("CalcId: " + aa.getCalcId());
117  0 if (StructureImportSettings.getDefaultPDBFileParser()
118    .equals(StructureParser.JALVIEW_PARSER))
119    {
120  0 assertTrue(mc_view.PDBfile.isCalcIdForFile(aa, pdbId));
121    }
122    }
123    }
124    }
125   
126    /**
127    * Check sequence features have been added
128    */
 
129  1 toggle @Test(groups = { "Functional" })
130    public void checkPDBSequenceFeatures()
131    {
132    /*
133    * 1GAQ/A
134    */
135  1 List<SequenceFeature> sf = al.getSequenceAt(0).getSequenceFeatures();
136  1 SequenceFeatures.sortFeatures(sf, true);
137  1 assertEquals(296, sf.size());
138  1 assertEquals("RESNUM", sf.get(0).getType());
139  1 assertEquals("GLU: 19 1gaqA", sf.get(0).getDescription());
140  1 assertEquals("RESNUM", sf.get(295).getType());
141  1 assertEquals("TYR: 314 1gaqA", sf.get(295).getDescription());
142   
143    /*
144    * 1GAQ/B
145    */
146  1 sf = al.getSequenceAt(1).getSequenceFeatures();
147  1 SequenceFeatures.sortFeatures(sf, true);
148  1 assertEquals(98, sf.size());
149  1 assertEquals("RESNUM", sf.get(0).getType());
150  1 assertEquals("ALA: 1 1gaqB", sf.get(0).getDescription());
151  1 assertEquals("RESNUM", sf.get(97).getType());
152  1 assertEquals("ALA: 98 1gaqB", sf.get(97).getDescription());
153   
154    /*
155    * 1GAQ/C
156    */
157  1 sf = al.getSequenceAt(2).getSequenceFeatures();
158  1 SequenceFeatures.sortFeatures(sf, true);
159  1 assertEquals(296, sf.size());
160  1 assertEquals("RESNUM", sf.get(0).getType());
161  1 assertEquals("GLU: 19 1gaqC", sf.get(0).getDescription());
162  1 assertEquals("RESNUM", sf.get(295).getType());
163  1 assertEquals("TYR: 314 1gaqC", sf.get(295).getDescription());
164    }
165   
 
166  1 toggle @Test(groups = { "Functional" })
167    public void checkAnnotationWiring()
168    {
169  1 assertTrue(al.getAlignmentAnnotation() != null);
170    // verify that all sequence annotation is doubly referenced
171  1 for (AlignmentAnnotation aa : al.getAlignmentAnnotation())
172    {
173  10 if (aa.sequenceRef != null)
174    {
175  6 assertTrue(al.getSequences().contains(aa.sequenceRef));
176  6 assertNotNull(aa.sequenceRef.getAnnotation());
177  6 boolean found = false;
178  6 for (AlignmentAnnotation sqan : aa.sequenceRef.getAnnotation())
179    {
180  9 if (sqan == aa)
181    {
182  6 found = true;
183  6 break;
184    }
185    }
186  6 assertTrue("Couldn't find sequence associated annotation "
187    + aa.label
188    + " on the sequence it is associated with.\nSequence associated editing will fail.",
189    found);
190    }
191    }
192    }
193   
194    /**
195    * @throws java.lang.Exception
196    */
 
197  1 toggle @BeforeClass(alwaysRun = true)
198    public static void setUpBeforeClass() throws Exception
199    {
200  1 jalview.bin.Jalview
201    .main(new String[]
202    { "--props", "test/jalview/io/testProps.jvprops" });
203    }
204   
205    /**
206    * @throws java.lang.Exception
207    */
 
208  1 toggle @AfterClass(alwaysRun = true)
209    public static void tearDownAfterClass() throws Exception
210    {
211  1 if (Desktop.instance != null)
212  1 Desktop.instance.closeAll_actionPerformed(null);
213    }
214   
 
215  1 toggle @Test(groups = { "Functional" })
216    public void testJalviewProjectRelocationAnnotation() throws Exception
217    {
218   
219  1 String inFile = "examples/1gaq.txt";
220  1 String tfile = File.createTempFile("JalviewTest", ".jvp")
221    .getAbsolutePath();
222  1 AlignFrame af = new jalview.io.FileLoader()
223    .LoadFileWaitTillLoaded(inFile, DataSourceType.FILE);
224  1 assertTrue("Didn't read input file " + inFile, af != null);
225  1 af.saveAlignment(tfile, FileFormat.Jalview);
226  1 assertTrue("Failed to store as a project.",
227    af.isSaveAlignmentSuccessful());
228  1 af.closeMenuItem_actionPerformed(true);
229  1 af = null;
230  1 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile,
231    DataSourceType.FILE);
232  1 assertTrue("Failed to import new project", af != null);
233  1 for (SequenceI asq : af.getViewport().getAlignment().getSequences())
234    {
235  3 SequenceI sq = asq;
236  6 while (sq.getDatasetSequence() != null)
237    {
238  3 sq = sq.getDatasetSequence();
239    }
240  3 assertNotNull(sq.getAllPDBEntries());
241  3 assertEquals("Expected only one PDB ID", 1,
242    sq.getAllPDBEntries().size());
243  3 for (PDBEntry pdbentry : sq.getAllPDBEntries())
244    {
245  3 System.err.println(
246    "PDB Entry " + pdbentry.getId() + " " + pdbentry.getFile());
247  3 boolean exists = false, found = false;
248  3 for (AlignmentAnnotation ana : sq.getAnnotation())
249    {
250  6 System.err.println("CalcId " + ana.getCalcId());
251  6 if (ana.getCalcId() != null
252    && mc_view.PDBfile.isCalcIdHandled(ana.getCalcId()))
253    {
254  0 exists = true;
255  0 if (mc_view.PDBfile.isCalcIdForFile(ana, pdbentry.getId()))
256    {
257  0 found = true;
258    }
259    }
260    }
261  3 if (exists)
262    {
263  0 assertTrue(
264    "Couldn't find any annotation for " + pdbentry.getId()
265    + " (file handle " + pdbentry.getFile() + ")",
266    found);
267    }
268    }
269    }
270    }
271    }