Clover icon

Coverage Report

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

File PDBSequenceFetcherTest.java

 

Code metrics

8
46
7
2
182
132
11
0.24
6.57
3.5
1.57

Classes

Class Line # Actions
PDBSequenceFetcherTest 43 43 10
0.00%
PDBSequenceFetcherTest.TestRetrieveObject 113 3 1
0.00%
 

Contributing tests

No tests hitting this source file were found.

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.ws;
22   
23    import static org.testng.Assert.assertEquals;
24    import static org.testng.AssertJUnit.assertTrue;
25   
26    import jalview.bin.Cache;
27    import jalview.datamodel.AlignmentI;
28    import jalview.datamodel.SequenceFeature;
29    import jalview.datamodel.SequenceI;
30    import jalview.gui.JvOptionPane;
31    import jalview.structure.StructureImportSettings;
32    import jalview.structure.StructureImportSettings.StructureParser;
33    import jalview.ws.seqfetcher.DbSourceProxy;
34   
35    import java.util.Arrays;
36    import java.util.List;
37   
38    import org.testng.Assert;
39    import org.testng.annotations.BeforeClass;
40    import org.testng.annotations.BeforeMethod;
41    import org.testng.annotations.Test;
42   
 
43    public class PDBSequenceFetcherTest
44    {
45   
 
46  0 toggle @BeforeClass(alwaysRun = true)
47    public void setUpJvOptionPane()
48    {
49  0 JvOptionPane.setInteractiveMode(false);
50  0 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
51    }
52   
53    SequenceFetcher sf;
54   
 
55  0 toggle @BeforeMethod(alwaysRun = true)
56    public void setUp() throws Exception
57    {
58  0 Cache.loadProperties("test/jalview/io/testProps.jvprops");
59    // ensure 'add annotation from structure' is selected
60  0 Cache.applicationProperties.setProperty("STRUCT_FROM_PDB",
61    Boolean.TRUE.toString());
62  0 Cache.applicationProperties.setProperty("ADD_SS_ANN",
63    Boolean.TRUE.toString());
64   
65  0 sf = new SequenceFetcher();
66    }
67   
68    /**
69    * Test that RNA structure can be added by a call to the RNAML service.
70    *
71    * Note this test depends on http://arn-ibmc.in2p3.fr/api/compute/2d which is
72    * not always reliable.
73    *
74    * @throws Exception
75    */
 
76  0 toggle @Test(groups = { "Network" }, enabled = true)
77    public void testRnaSeqRetrieve() throws Exception
78    {
79  0 Cache.applicationProperties.setProperty("PDB_DOWNLOAD_FORMAT", "PDB");
80  0 List<DbSourceProxy> sps = sf.getSourceProxy("PDB");
81  0 AlignmentI response = sps.get(0).getSequenceRecords("2GIS");
82  0 assertTrue(response != null);
83  0 assertTrue(response.getHeight() == 1);
84  0 for (SequenceI sq : response.getSequences())
85    {
86  0 assertTrue("No annotation transfered to sequence.",
87    sq.getAnnotation().length > 0);
88  0 assertTrue("No PDBEntry on sequence.",
89    sq.getAllPDBEntries().size() > 0);
90  0 assertTrue(
91    "No RNA annotation on sequence, possibly http://arn-ibmc.in2p3.fr/api/compute/2d not available?",
92    sq.getRNA() != null);
93    }
94    }
95   
 
96  0 toggle @Test(groups = { "Network" }, enabled = true)
97    public void testPdbSeqRetrieve() throws Exception
98    {
99  0 StructureImportSettings.setDefaultStructureFileFormat("PDB");
100  0 StructureImportSettings
101    .setDefaultPDBFileParser(StructureParser.JALVIEW_PARSER);
102   
103  0 testRetrieveProteinSeqFromPDB();
104    }
105   
 
106  0 toggle @Test(groups = { "Network" }, enabled = true)
107    public void testmmCifSeqRetrieve() throws Exception
108    {
109  0 StructureImportSettings.setDefaultStructureFileFormat("mmCIF");
110  0 testRetrieveProteinSeqFromPDB();
111    }
112   
 
113    private class TestRetrieveObject
114    {
115    String id;
116   
117    int expectedHeight;
118   
 
119  0 toggle public TestRetrieveObject(String id, int expectedHeight)
120    {
121  0 super();
122  0 this.id = id;
123  0 this.expectedHeight = expectedHeight;
124    }
125   
126    }
127   
128    private List<TestRetrieveObject> toRetrieve = Arrays.asList(
129    new TestRetrieveObject("1QIP", 4),
130    new TestRetrieveObject("4IM2", 1));
131   
 
132  0 toggle private void testRetrieveProteinSeqFromPDB() throws Exception
133    {
134  0 List<DbSourceProxy> sps = sf.getSourceProxy("PDB");
135  0 StringBuilder errors = new StringBuilder();
136  0 for (TestRetrieveObject str : toRetrieve)
137    {
138  0 AlignmentI response = sps.get(0).getSequenceRecords(str.id);
139  0 assertTrue("No aligment for " + str.id, response != null);
140  0 assertEquals(response.getHeight(), str.expectedHeight,
141    "Number of chains for " + str.id);
142  0 for (SequenceI sq : response.getSequences())
143    {
144  0 assertTrue("No annotation transfered to sequence " + sq.getName(),
145    sq.getAnnotation().length > 0);
146  0 assertTrue("No PDBEntry on sequence " + sq.getName(),
147    sq.getAllPDBEntries().size() > 0);
148    // FIXME: should test that all residues extracted as sequences from
149    // chains in structure have a mapping to data in the structure
150  0 List<SequenceFeature> prev = null;
151  0 int lastp = -1;
152  0 for (int col = 1; col <= sq.getLength(); col++)
153    {
154  0 List<SequenceFeature> sf = sq.findFeatures(col, col, "RESNUM");
155  0 if (sf.size() != 1)
156    {
157  0 errors.append(str.id + ": "
158    + "Expected one feature at column (position): "
159    + (col - 1) + " (" + sq.findPosition(col - 1) + ")"
160    + ": saw " + sf.size());
161  0 errors.append("\n");
162  0 if (prev != null)
163    {
164  0 errors.append("Last Feature was at position " + lastp + ": "
165    + prev.get(0).toString());
166  0 errors.append("\n");
167    }
168    }
169    else
170    {
171  0 prev = sf;
172  0 lastp = sq.findPosition(col - 1);
173    }
174    }
175    }
176    }
177  0 if (errors.length() > 0)
178    {
179  0 Assert.fail(errors.toString());
180    }
181    }
182    }