Clover icon

Coverage Report

  1. Project Clover database Thu Aug 13 2020 12:04:21 BST
  2. Package jalview.ws.dbsources

File UniprotTest.java

 

Code metrics

0
127
6
1
306
219
6
0.05
21.17
6
1

Classes

Class Line # Actions
UniprotTest 46 127 6
1.0100%
 

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 jalview.ws.dbsources;
22   
23    import static org.testng.AssertJUnit.assertEquals;
24    import static org.testng.AssertJUnit.assertNotNull;
25    import static org.testng.AssertJUnit.assertNull;
26    import static org.testng.AssertJUnit.assertTrue;
27   
28    import jalview.datamodel.SequenceI;
29    import jalview.gui.JvOptionPane;
30    import jalview.xml.binding.uniprot.DbReferenceType;
31    import jalview.xml.binding.uniprot.Entry;
32    import jalview.xml.binding.uniprot.FeatureType;
33    import jalview.xml.binding.uniprot.LocationType;
34    import jalview.xml.binding.uniprot.PositionType;
35   
36    import java.io.ByteArrayInputStream;
37    import java.io.InputStream;
38    import java.io.UnsupportedEncodingException;
39    import java.math.BigInteger;
40    import java.util.List;
41   
42    import org.testng.Assert;
43    import org.testng.annotations.BeforeClass;
44    import org.testng.annotations.Test;
45   
 
46    public class UniprotTest
47    {
48   
 
49  1 toggle @BeforeClass(alwaysRun = true)
50    public void setUpJvOptionPane()
51    {
52  1 JvOptionPane.setInteractiveMode(false);
53  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
54    }
55   
56    // adapted from http://www.uniprot.org/uniprot/A9CKP4.xml
57    private static final String UNIPROT_XML = "<?xml version='1.0' encoding='UTF-8'?>"
58    + "<uniprot xmlns=\"http://uniprot.org/uniprot\">"
59    + "<entry dataset=\"TrEMBL\" created=\"2008-01-15\" modified=\"2015-03-04\" version=\"38\">"
60    + "<accession>A9CKP4</accession>"
61    + "<accession>A9CKP5</accession>"
62    + "<name>A9CKP4_AGRT5</name>"
63    + "<name>A9CKP4_AGRT6</name>"
64    + "<protein><recommendedName><fullName>Mitogen-activated protein kinase 13</fullName></recommendedName></protein>"
65    + "<dbReference type=\"PDB\" id=\"2FSQ\"><property type=\"method\" value=\"X-ray\"/><property type=\"resolution\" value=\"1.40\"/></dbReference>"
66    + "<dbReference type=\"PDBsum\" id=\"2FSR\"/>"
67    + "<dbReference type=\"EMBL\" id=\"AE007869\"><property type=\"protein sequence ID\" value=\"AAK85932.1\"/><property type=\"molecule type\" value=\"Genomic_DNA\"/></dbReference>"
68    + "<feature type=\"signal peptide\" evidence=\"7\"><location><begin position=\"1\"/><end position=\"18\"/></location></feature>"
69    + "<feature type=\"propeptide\" description=\"Activation peptide\" id=\"PRO_0000027399\" evidence=\"9 16 17 18\"><location><begin position=\"19\"/><end position=\"20\"/></location></feature>"
70    + "<feature type=\"chain\" description=\"Granzyme B\" id=\"PRO_0000027400\"><location><begin position=\"21\"/><end position=\"247\"/></location></feature>"
71    + "<feature type=\"sequence variant\"><original>M</original><variation>L</variation><location><position position=\"41\"/></location></feature>"
72    + "<feature type=\"sequence variant\" description=\"Pathogenic\"><original>M</original><variation>L</variation><location><position position=\"41\"/></location></feature>"
73    + "<feature type=\"sequence variant\" description=\"Pathogenic\"><original>M</original><location><position position=\"41\"/></location></feature>"
74    + "<feature type=\"sequence variant\" description=\"Foo\"><variation>L</variation><variation>LMV</variation><original>M</original><location><position position=\"42\"/></location></feature>"
75    + "<feature type=\"sequence variant\" description=\"Foo\"><variation>LL</variation><variation>LMV</variation><original>ML</original><location><begin position=\"42\"/><end position=\"43\"/></location></feature>"
76    + "<feature type=\"sequence variant\" description=\"Foo Too\"><variation>LL</variation><variation>LMVK</variation><original>MLML</original><location><begin position=\"42\"/><end position=\"45\"/></location></feature>"
77    + "<sequence length=\"10\" mass=\"27410\" checksum=\"8CB760AACF88FE6C\" modified=\"2008-01-15\" version=\"1\">MHAPL VSKDL</sequence></entry>"
78    + "</uniprot>";
79   
80    /**
81    * Test the method that unmarshals XML to a Uniprot model
82    *
83    * @throws UnsupportedEncodingException
84    */
 
85  1 toggle @Test(groups = { "Functional" })
86    public void testGetUniprotEntries() throws UnsupportedEncodingException
87    {
88  1 Uniprot u = new Uniprot();
89  1 InputStream is = new ByteArrayInputStream(UNIPROT_XML.getBytes());
90  1 List<Entry> entries = u.getUniprotEntries(is);
91  1 assertEquals(1, entries.size());
92  1 Entry entry = entries.get(0);
93  1 assertEquals(2, entry.getName().size());
94  1 assertEquals("A9CKP4_AGRT5", entry.getName().get(0));
95  1 assertEquals("A9CKP4_AGRT6", entry.getName().get(1));
96  1 assertEquals(2, entry.getAccession().size());
97  1 assertEquals("A9CKP4", entry.getAccession().get(0));
98  1 assertEquals("A9CKP5", entry.getAccession().get(1));
99   
100  1 assertEquals("MHAPL VSKDL", entry.getSequence().getValue());
101   
102  1 assertEquals("Mitogen-activated protein kinase 13", entry.getProtein()
103    .getRecommendedName().getFullName().getValue());
104   
105    /*
106    * Check sequence features
107    */
108  1 List<FeatureType> features = entry.getFeature();
109  1 assertEquals(9, features.size());
110  1 FeatureType sf = features.get(0);
111  1 assertEquals("signal peptide", sf.getType());
112  1 assertNull(sf.getDescription());
113  1 assertNull(sf.getStatus());
114  1 assertNull(sf.getLocation().getPosition());
115  1 assertEquals(1, sf.getLocation().getBegin().getPosition().intValue());
116  1 assertEquals(18, sf.getLocation().getEnd().getPosition().intValue());
117  1 sf = features.get(1);
118  1 assertEquals("propeptide", sf.getType());
119  1 assertEquals("Activation peptide", sf.getDescription());
120  1 assertNull(sf.getLocation().getPosition());
121  1 assertEquals(19, sf.getLocation().getBegin().getPosition().intValue());
122  1 assertEquals(20, sf.getLocation().getEnd().getPosition().intValue());
123  1 sf = features.get(2);
124  1 assertEquals("chain", sf.getType());
125  1 assertEquals("Granzyme B", sf.getDescription());
126  1 assertNull(sf.getLocation().getPosition());
127  1 assertEquals(21, sf.getLocation().getBegin().getPosition().intValue());
128  1 assertEquals(247, sf.getLocation().getEnd().getPosition().intValue());
129   
130  1 sf = features.get(3);
131  1 assertEquals("sequence variant", sf.getType());
132  1 assertNull(sf.getDescription());
133  1 assertEquals(41,
134    sf.getLocation().getPosition().getPosition().intValue());
135  1 assertNull(sf.getLocation().getBegin());
136  1 assertNull(sf.getLocation().getEnd());
137   
138  1 sf = features.get(4);
139  1 assertEquals("sequence variant", sf.getType());
140  1 assertEquals("Pathogenic", sf.getDescription());
141  1 assertEquals(41,
142    sf.getLocation().getPosition().getPosition().intValue());
143  1 assertNull(sf.getLocation().getBegin());
144  1 assertNull(sf.getLocation().getEnd());
145   
146  1 sf = features.get(5);
147  1 assertEquals("sequence variant", sf.getType());
148  1 assertEquals("Pathogenic", sf.getDescription());
149  1 assertEquals(41,
150    sf.getLocation().getPosition().getPosition().intValue());
151  1 assertNull(sf.getLocation().getBegin());
152  1 assertNull(sf.getLocation().getEnd());
153   
154  1 sf = features.get(6);
155  1 assertEquals("sequence variant", sf.getType());
156  1 assertEquals("Foo",
157    sf.getDescription());
158  1 assertEquals(42,
159    sf.getLocation().getPosition().getPosition().intValue());
160  1 assertNull(sf.getLocation().getBegin());
161  1 assertNull(sf.getLocation().getEnd());
162  1 Assert.assertEquals(Uniprot.getDescription(sf),
163    "<html>p.Met42Leu" + "<br/>&nbsp;&nbsp;"
164    + "p.Met42LeuMetVal Foo</html>");
165   
166  1 sf = features.get(7);
167  1 assertNull(sf.getLocation().getPosition());
168  1 assertEquals(42, sf.getLocation().getBegin().getPosition().intValue());
169  1 assertEquals(43, sf.getLocation().getEnd().getPosition().intValue());
170  1 Assert.assertEquals(Uniprot.getDescription(sf),
171    "<html>p.MetLeu42LeuLeu" + "<br/>&nbsp;&nbsp;"
172    + "p.MetLeu42LeuMetVal Foo</html>");
173   
174  1 sf = features.get(8);
175  1 assertNull(sf.getLocation().getPosition());
176  1 assertEquals(42, sf.getLocation().getBegin().getPosition().intValue());
177  1 assertEquals(45, sf.getLocation().getEnd().getPosition().intValue());
178  1 Assert.assertEquals(Uniprot.getDescription(sf),
179    "<html>p.MLML42LeuLeu" + "<br/>&nbsp;&nbsp;"
180    + "p.MLML42LMVK Foo Too</html>");
181   
182    /*
183    * Check cross-references
184    */
185  1 List<DbReferenceType> xrefs = entry.getDbReference();
186  1 assertEquals(3, xrefs.size());
187   
188  1 DbReferenceType xref = xrefs.get(0);
189  1 assertEquals("2FSQ", xref.getId());
190  1 assertEquals("PDB", xref.getType());
191  1 assertEquals("X-ray",
192    Uniprot.getProperty(xref.getProperty(), "method"));
193  1 assertEquals("1.40",
194    Uniprot.getProperty(xref.getProperty(), "resolution"));
195   
196  1 xref = xrefs.get(1);
197  1 assertEquals("2FSR", xref.getId());
198  1 assertEquals("PDBsum", xref.getType());
199  1 assertTrue(xref.getProperty().isEmpty());
200   
201  1 xref = xrefs.get(2);
202  1 assertEquals("AE007869", xref.getId());
203  1 assertEquals("EMBL", xref.getType());
204  1 assertEquals("AAK85932.1",
205    Uniprot.getProperty(xref.getProperty(), "protein sequence ID"));
206  1 assertEquals("Genomic_DNA",
207    Uniprot.getProperty(xref.getProperty(), "molecule type"));
208    }
209   
 
210  1 toggle @Test(groups = { "Functional" })
211    public void testGetUniprotSequence() throws UnsupportedEncodingException
212    {
213  1 InputStream is = new ByteArrayInputStream(UNIPROT_XML.getBytes());
214  1 Entry entry = new Uniprot().getUniprotEntries(
215    is).get(0);
216  1 SequenceI seq = new Uniprot().uniprotEntryToSequence(entry);
217  1 assertNotNull(seq);
218  1 assertEquals(6, seq.getDBRefs().size()); // 2*Uniprot, PDB, PDBsum, 2*EMBL
219  1 assertEquals(seq.getSequenceAsString(),
220    seq.createDatasetSequence().getSequenceAsString());
221    }
222   
223    /**
224    * Test the method that formats the sequence id
225    *
226    * @throws UnsupportedEncodingException
227    */
 
228  1 toggle @Test(groups = { "Functional" })
229    public void testGetUniprotEntryId() throws UnsupportedEncodingException
230    {
231  1 InputStream is = new ByteArrayInputStream(UNIPROT_XML.getBytes());
232  1 Entry entry = new Uniprot().getUniprotEntries(is).get(0);
233   
234    /*
235    * name formatted with Uniprot Entry name
236    */
237  1 String expectedName = "A9CKP4_AGRT5|A9CKP4_AGRT6";
238  1 assertEquals(expectedName,
239    Uniprot.getUniprotEntryId(entry));
240    }
241   
242    /**
243    * Test the method that formats the sequence description
244    *
245    * @throws UnsupportedEncodingException
246    */
 
247  1 toggle @Test(groups = { "Functional" })
248    public void testGetUniprotEntryDescription()
249    throws UnsupportedEncodingException
250    {
251  1 InputStream is = new ByteArrayInputStream(UNIPROT_XML.getBytes());
252  1 Entry entry = new Uniprot().getUniprotEntries(is).get(0);
253   
254  1 assertEquals("Mitogen-activated protein kinase 13",
255    Uniprot.getUniprotEntryDescription(entry));
256    }
257   
 
258  1 toggle @Test(groups = { "Functional" })
259    public void testGetDescription()
260    {
261  1 FeatureType ft = new FeatureType();
262  1 assertEquals("", Uniprot.getDescription(ft));
263   
264  1 ft.setDescription("Hello");
265  1 assertEquals("Hello", Uniprot.getDescription(ft));
266   
267  1 ft.setLocation(new LocationType());
268  1 ft.getLocation().setPosition(new PositionType());
269  1 ft.getLocation().getPosition().setPosition(BigInteger.valueOf(23));
270  1 ft.setOriginal("K");
271  1 ft.getVariation().add("y");
272  1 assertEquals("p.Lys23Tyr Hello", Uniprot.getDescription(ft));
273   
274    // multiple variants generate an html description over more than one line
275  1 ft.getVariation().add("W");
276  1 assertEquals("<html>p.Lys23Tyr<br/>&nbsp;&nbsp;p.Lys23Trp Hello</html>",
277    Uniprot.getDescription(ft));
278   
279    /*
280    * indel cases
281    * up to 3 bases (original or variant) are shown using 3 letter code
282    */
283  1 ft.getVariation().clear();
284  1 ft.getVariation().add("KWE");
285  1 ft.setOriginal("KLS");
286  1 assertEquals("p.LysLeuSer23LysTrpGlu Hello",
287    Uniprot.getDescription(ft));
288   
289    // adding a fourth original base switches to single letter code
290  1 ft.setOriginal("KLST");
291  1 assertEquals("p.KLST23LysTrpGlu Hello", Uniprot.getDescription(ft));
292   
293    // adding a fourth variant switches to single letter code
294  1 ft.getVariation().clear();
295  1 ft.getVariation().add("KWES");
296  1 assertEquals("p.KLST23KWES Hello", Uniprot.getDescription(ft));
297   
298  1 ft.getVariation().clear();
299  1 ft.getVariation().add("z"); // unknown variant - fails gracefully
300  1 ft.setOriginal("K");
301  1 assertEquals("p.Lys23z Hello", Uniprot.getDescription(ft));
302   
303  1 ft.getVariation().clear(); // variant missing - is ignored
304  1 assertEquals("Hello", Uniprot.getDescription(ft));
305    }
306    }