2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.ws.dbsources;
23 import static org.testng.Assert.assertFalse;
24 import static org.testng.AssertJUnit.assertEquals;
25 import static org.testng.AssertJUnit.assertNotNull;
26 import static org.testng.AssertJUnit.assertNull;
27 import static org.testng.AssertJUnit.assertTrue;
29 import jalview.datamodel.DBRefEntry;
30 import jalview.datamodel.DBRefSource;
31 import jalview.datamodel.SequenceI;
32 import jalview.gui.JvOptionPane;
33 import jalview.util.DBRefUtils;
34 import jalview.xml.binding.uniprot.DbReferenceType;
35 import jalview.xml.binding.uniprot.Entry;
36 import jalview.xml.binding.uniprot.FeatureType;
37 import jalview.xml.binding.uniprot.LocationType;
38 import jalview.xml.binding.uniprot.PositionType;
40 import java.io.ByteArrayInputStream;
41 import java.io.InputStream;
42 import java.io.UnsupportedEncodingException;
43 import java.math.BigInteger;
44 import java.util.List;
46 import org.testng.Assert;
47 import org.testng.annotations.BeforeClass;
48 import org.testng.annotations.Test;
50 public class UniprotTest
53 @BeforeClass(alwaysRun = true)
54 public void setUpJvOptionPane()
56 JvOptionPane.setInteractiveMode(false);
57 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
60 // adapted from http://www.uniprot.org/uniprot/A9CKP4.xml
61 private static final String UNIPROT_XML = "<?xml version='1.0' encoding='UTF-8'?>"
62 + "<uniprot xmlns=\"http://uniprot.org/uniprot\">"
63 + "<entry dataset=\"TrEMBL\" created=\"2008-01-15\" modified=\"2015-03-04\" version=\"38\">"
64 + "<accession>A9CKP4</accession>"
65 + "<accession>A9CKP5</accession>"
66 + "<name>A9CKP4_AGRT5</name>"
67 + "<name>A9CKP4_AGRT6</name>"
68 + "<protein><recommendedName><fullName>Mitogen-activated protein kinase 13</fullName></recommendedName></protein>"
69 + "<dbReference type=\"PDB\" id=\"2FSQ\"><property type=\"method\" value=\"X-ray\"/><property type=\"resolution\" value=\"1.40\"/></dbReference>"
70 + "<dbReference type=\"PDBsum\" id=\"2FSR\"/>"
71 + "<dbReference type=\"EMBL\" id=\"AE007869\"><property type=\"protein sequence ID\" value=\"AAK85932.1\"/><property type=\"molecule type\" value=\"Genomic_DNA\"/></dbReference>"
72 + "<feature type=\"signal peptide\" evidence=\"7\"><location><begin position=\"1\"/><end position=\"18\"/></location></feature>"
73 + "<feature type=\"propeptide\" description=\"Activation peptide\" id=\"PRO_0000027399\" evidence=\"9 16 17 18\"><location><begin position=\"19\"/><end position=\"20\"/></location></feature>"
74 + "<feature type=\"chain\" description=\"Granzyme B\" id=\"PRO_0000027400\"><location><begin position=\"21\"/><end position=\"247\"/></location></feature>"
75 + "<feature type=\"sequence variant\"><original>M</original><variation>L</variation><location><position position=\"41\"/></location></feature>"
76 + "<feature type=\"sequence variant\" description=\"Pathogenic\"><original>M</original><variation>L</variation><location><position position=\"41\"/></location></feature>"
77 + "<feature type=\"sequence variant\" description=\"Pathogenic\"><original>M</original><location><position position=\"41\"/></location></feature>"
78 + "<feature type=\"sequence variant\" description=\"Foo\"><variation>L</variation><variation>LMV</variation><original>M</original><location><position position=\"42\"/></location></feature>"
79 + "<feature type=\"sequence variant\" description=\"Foo\"><variation>LL</variation><variation>LMV</variation><original>ML</original><location><begin position=\"42\"/><end position=\"43\"/></location></feature>"
80 + "<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>"
81 + "<sequence length=\"10\" mass=\"27410\" checksum=\"8CB760AACF88FE6C\" modified=\"2008-01-15\" version=\"1\">MHAPL VSKDL</sequence></entry>"
85 * Test the method that unmarshals XML to a Uniprot model
87 * @throws UnsupportedEncodingException
89 @Test(groups = { "Functional" })
90 public void testGetUniprotEntries() throws UnsupportedEncodingException
92 Uniprot u = new Uniprot();
93 InputStream is = new ByteArrayInputStream(UNIPROT_XML.getBytes());
94 List<Entry> entries = u.getUniprotEntries(is);
95 assertEquals(1, entries.size());
96 Entry entry = entries.get(0);
97 assertEquals(2, entry.getName().size());
98 assertEquals("A9CKP4_AGRT5", entry.getName().get(0));
99 assertEquals("A9CKP4_AGRT6", entry.getName().get(1));
100 assertEquals(2, entry.getAccession().size());
101 assertEquals("A9CKP4", entry.getAccession().get(0));
102 assertEquals("A9CKP5", entry.getAccession().get(1));
104 assertEquals("MHAPL VSKDL", entry.getSequence().getValue());
106 assertEquals("Mitogen-activated protein kinase 13", entry.getProtein()
107 .getRecommendedName().getFullName().getValue());
110 * Check sequence features
112 List<FeatureType> features = entry.getFeature();
113 assertEquals(9, features.size());
114 FeatureType sf = features.get(0);
115 assertEquals("signal peptide", sf.getType());
116 assertNull(sf.getDescription());
117 assertNull(sf.getStatus());
118 assertNull(sf.getLocation().getPosition());
119 assertEquals(1, sf.getLocation().getBegin().getPosition().intValue());
120 assertEquals(18, sf.getLocation().getEnd().getPosition().intValue());
121 sf = features.get(1);
122 assertEquals("propeptide", sf.getType());
123 assertEquals("Activation peptide", sf.getDescription());
124 assertNull(sf.getLocation().getPosition());
125 assertEquals(19, sf.getLocation().getBegin().getPosition().intValue());
126 assertEquals(20, sf.getLocation().getEnd().getPosition().intValue());
127 sf = features.get(2);
128 assertEquals("chain", sf.getType());
129 assertEquals("Granzyme B", sf.getDescription());
130 assertNull(sf.getLocation().getPosition());
131 assertEquals(21, sf.getLocation().getBegin().getPosition().intValue());
132 assertEquals(247, sf.getLocation().getEnd().getPosition().intValue());
134 sf = features.get(3);
135 assertEquals("sequence variant", sf.getType());
136 assertNull(sf.getDescription());
138 sf.getLocation().getPosition().getPosition().intValue());
139 assertNull(sf.getLocation().getBegin());
140 assertNull(sf.getLocation().getEnd());
142 sf = features.get(4);
143 assertEquals("sequence variant", sf.getType());
144 assertEquals("Pathogenic", sf.getDescription());
146 sf.getLocation().getPosition().getPosition().intValue());
147 assertNull(sf.getLocation().getBegin());
148 assertNull(sf.getLocation().getEnd());
150 sf = features.get(5);
151 assertEquals("sequence variant", sf.getType());
152 assertEquals("Pathogenic", sf.getDescription());
154 sf.getLocation().getPosition().getPosition().intValue());
155 assertNull(sf.getLocation().getBegin());
156 assertNull(sf.getLocation().getEnd());
158 sf = features.get(6);
159 assertEquals("sequence variant", sf.getType());
161 sf.getDescription());
163 sf.getLocation().getPosition().getPosition().intValue());
164 assertNull(sf.getLocation().getBegin());
165 assertNull(sf.getLocation().getEnd());
166 Assert.assertEquals(Uniprot.getDescription(sf),
167 "<html>p.Met42Leu" + "<br/> "
168 + "p.Met42LeuMetVal Foo</html>");
170 sf = features.get(7);
171 assertNull(sf.getLocation().getPosition());
172 assertEquals(42, sf.getLocation().getBegin().getPosition().intValue());
173 assertEquals(43, sf.getLocation().getEnd().getPosition().intValue());
174 Assert.assertEquals(Uniprot.getDescription(sf),
175 "<html>p.MetLeu42LeuLeu" + "<br/> "
176 + "p.MetLeu42LeuMetVal Foo</html>");
178 sf = features.get(8);
179 assertNull(sf.getLocation().getPosition());
180 assertEquals(42, sf.getLocation().getBegin().getPosition().intValue());
181 assertEquals(45, sf.getLocation().getEnd().getPosition().intValue());
182 Assert.assertEquals(Uniprot.getDescription(sf),
183 "<html>p.MLML42LeuLeu" + "<br/> "
184 + "p.MLML42LMVK Foo Too</html>");
187 * Check cross-references
189 List<DbReferenceType> xrefs = entry.getDbReference();
190 assertEquals(3, xrefs.size());
192 DbReferenceType xref = xrefs.get(0);
193 assertEquals("2FSQ", xref.getId());
194 assertEquals("PDB", xref.getType());
195 assertEquals("X-ray",
196 Uniprot.getProperty(xref.getProperty(), "method"));
198 Uniprot.getProperty(xref.getProperty(), "resolution"));
201 assertEquals("2FSR", xref.getId());
202 assertEquals("PDBsum", xref.getType());
203 assertTrue(xref.getProperty().isEmpty());
206 assertEquals("AE007869", xref.getId());
207 assertEquals("EMBL", xref.getType());
208 assertEquals("AAK85932.1",
209 Uniprot.getProperty(xref.getProperty(), "protein sequence ID"));
210 assertEquals("Genomic_DNA",
211 Uniprot.getProperty(xref.getProperty(), "molecule type"));
214 @Test(groups = { "Functional" })
215 public void testGetUniprotSequence() throws UnsupportedEncodingException
217 InputStream is = new ByteArrayInputStream(UNIPROT_XML.getBytes());
218 Entry entry = new Uniprot().getUniprotEntries(
220 SequenceI seq = new Uniprot().uniprotEntryToSequence(entry);
222 assertEquals(6, seq.getDBRefs().size()); // 2*Uniprot, PDB, PDBsum, 2*EMBL
223 assertEquals(seq.getSequenceAsString(),
224 seq.createDatasetSequence().getSequenceAsString());
225 assertEquals(2,seq.getPrimaryDBRefs().size());
226 List<DBRefEntry> res = DBRefUtils.searchRefs(seq.getPrimaryDBRefs(), "A9CKP4");
227 assertEquals(1,res.size());
228 assertTrue(res.get(0).isCanonical());
229 res = DBRefUtils.searchRefsForSource(seq.getDBRefs(), DBRefSource.UNIPROT);
230 assertEquals(2,res.size());
232 * NB this test fragile - relies on ordering being preserved
234 assertTrue(res.get(0).isCanonical());
235 assertFalse(res.get(1).isCanonical());
239 * Test the method that formats the sequence id
241 * @throws UnsupportedEncodingException
243 @Test(groups = { "Functional" })
244 public void testGetUniprotEntryId() throws UnsupportedEncodingException
246 InputStream is = new ByteArrayInputStream(UNIPROT_XML.getBytes());
247 Entry entry = new Uniprot().getUniprotEntries(is).get(0);
250 * name formatted with Uniprot Entry name
252 String expectedName = "A9CKP4_AGRT5|A9CKP4_AGRT6";
253 assertEquals(expectedName,
254 Uniprot.getUniprotEntryId(entry));
258 * Test the method that formats the sequence description
260 * @throws UnsupportedEncodingException
262 @Test(groups = { "Functional" })
263 public void testGetUniprotEntryDescription()
264 throws UnsupportedEncodingException
266 InputStream is = new ByteArrayInputStream(UNIPROT_XML.getBytes());
267 Entry entry = new Uniprot().getUniprotEntries(is).get(0);
269 assertEquals("Mitogen-activated protein kinase 13",
270 Uniprot.getUniprotEntryDescription(entry));
273 @Test(groups = { "Functional" })
274 public void testGetDescription()
276 FeatureType ft = new FeatureType();
277 assertEquals("", Uniprot.getDescription(ft));
279 ft.setDescription("Hello");
280 assertEquals("Hello", Uniprot.getDescription(ft));
282 ft.setLocation(new LocationType());
283 ft.getLocation().setPosition(new PositionType());
284 ft.getLocation().getPosition().setPosition(BigInteger.valueOf(23));
286 ft.getVariation().add("y");
287 assertEquals("p.Lys23Tyr Hello", Uniprot.getDescription(ft));
289 // multiple variants generate an html description over more than one line
290 ft.getVariation().add("W");
291 assertEquals("<html>p.Lys23Tyr<br/> p.Lys23Trp Hello</html>",
292 Uniprot.getDescription(ft));
296 * up to 3 bases (original or variant) are shown using 3 letter code
298 ft.getVariation().clear();
299 ft.getVariation().add("KWE");
300 ft.setOriginal("KLS");
301 assertEquals("p.LysLeuSer23LysTrpGlu Hello",
302 Uniprot.getDescription(ft));
304 // adding a fourth original base switches to single letter code
305 ft.setOriginal("KLST");
306 assertEquals("p.KLST23LysTrpGlu Hello", Uniprot.getDescription(ft));
308 // adding a fourth variant switches to single letter code
309 ft.getVariation().clear();
310 ft.getVariation().add("KWES");
311 assertEquals("p.KLST23KWES Hello", Uniprot.getDescription(ft));
313 ft.getVariation().clear();
314 ft.getVariation().add("z"); // unknown variant - fails gracefully
316 assertEquals("p.Lys23z Hello", Uniprot.getDescription(ft));
318 ft.getVariation().clear(); // variant missing - is ignored
319 assertEquals("Hello", Uniprot.getDescription(ft));