JAL-1670 JAL-2018 updated unit test for added example feature
[jalview.git] / test / jalview / ws / dbsources / UniprotTest.java
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.assertNull;
25
26 import jalview.datamodel.PDBEntry;
27 import jalview.datamodel.SequenceFeature;
28 import jalview.datamodel.UniprotEntry;
29
30 import java.io.Reader;
31 import java.io.StringReader;
32 import java.util.Vector;
33
34 import org.testng.annotations.Test;
35
36 public class UniprotTest
37 {
38   // adapted from http://www.uniprot.org/uniprot/A9CKP4.xml
39   private static final String UNIPROT_XML = "<?xml version='1.0' encoding='UTF-8'?>"
40           + "<uniprot>"
41           + "<entry dataset=\"TrEMBL\" created=\"2008-01-15\" modified=\"2015-03-04\" version=\"38\">"
42           + "<accession>A9CKP4</accession>"
43           + "<accession>A9CKP5</accession>"
44           + "<name>A9CKP4_AGRT5</name>"
45           + "<name>A9CKP4_AGRT6</name>"
46           + "<protein><recommendedName><fullName>Mitogen-activated protein kinase 13</fullName><fullName>Henry</fullName></recommendedName></protein>"
47           + "<dbReference type=\"PDB\" id=\"2FSQ\"><property type=\"method\" value=\"X-ray\"/><property type=\"resolution\" value=\"1.40\"/></dbReference>"
48           + "<dbReference type=\"PDBsum\" id=\"2FSR\"/>"
49           + "<feature type=\"signal peptide\" evidence=\"7\"><location><begin position=\"1\"/><end position=\"18\"/></location></feature>"
50           + "<feature type=\"propeptide\" description=\"Activation peptide\" id=\"PRO_0000027399\" evidence=\"9 16 17 18\"><location><begin position=\"19\"/><end position=\"20\"/></location></feature>"
51           + "<feature type=\"chain\" description=\"Granzyme B\" id=\"PRO_0000027400\"><location><begin position=\"21\"/><end position=\"247\"/></location></feature>"
52           + "<sequence length=\"10\" mass=\"27410\" checksum=\"8CB760AACF88FE6C\" modified=\"2008-01-15\" version=\"1\">MHAPL VSKDL</sequence></entry>"
53           + "</uniprot>";
54
55   /**
56    * Test the method that unmarshals XML to a Uniprot model
57    */
58   @Test(groups = { "Functional" })
59   public void testGetUniprotEntries()
60   {
61     Uniprot u = new Uniprot();
62     Reader reader = new StringReader(UNIPROT_XML);
63     Vector<UniprotEntry> entries = u.getUniprotEntries(reader);
64     assertEquals(1, entries.size());
65     UniprotEntry entry = entries.get(0);
66     assertEquals(2, entry.getName().size());
67     assertEquals("A9CKP4_AGRT5", entry.getName().get(0));
68     assertEquals("A9CKP4_AGRT6", entry.getName().get(1));
69     assertEquals(2, entry.getAccession().size());
70     assertEquals("A9CKP4", entry.getAccession().get(0));
71     assertEquals("A9CKP5", entry.getAccession().get(1));
72
73     /*
74      * UniprotSequence drops any space characters
75      */
76     assertEquals("MHAPLVSKDL", entry.getUniprotSequence().getContent());
77
78     assertEquals(2, entry.getProtein().getName().size());
79     assertEquals("Mitogen-activated protein kinase 13", entry.getProtein()
80             .getName().get(0));
81     assertEquals("Henry", entry.getProtein().getName().get(1));
82
83     /*
84      * Check sequence features
85      */
86     Vector<SequenceFeature> features = entry.getFeature();
87     assertEquals(3, features.size());
88     SequenceFeature sf = features.get(0);
89     assertEquals("signal peptide", sf.getType());
90     assertNull(sf.getDescription());
91     assertNull(sf.getStatus());
92     assertEquals(1, sf.getPosition());
93     assertEquals(1, sf.getBegin());
94     assertEquals(18, sf.getEnd());
95     sf = features.get(1);
96     assertEquals("propeptide", sf.getType());
97     assertEquals("Activation peptide", sf.getDescription());
98     assertEquals(19, sf.getPosition());
99     assertEquals(19, sf.getBegin());
100     assertEquals(20, sf.getEnd());
101     sf = features.get(2);
102     assertEquals("chain", sf.getType());
103     assertEquals("Granzyme B", sf.getDescription());
104     assertEquals(21, sf.getPosition());
105     assertEquals(21, sf.getBegin());
106     assertEquals(247, sf.getEnd());
107
108     /*
109      * Check cross-references
110      */
111     Vector<PDBEntry> xrefs = entry.getDbReference();
112     assertEquals(2, xrefs.size());
113
114     PDBEntry xref = xrefs.get(0);
115     assertEquals("2FSQ", xref.getId());
116     assertEquals("PDB", xref.getType());
117     assertEquals(2, xref.getProperty().size());
118     assertEquals("X-ray", xref.getProperty().get("method"));
119     assertEquals("1.40", xref.getProperty().get("resolution"));
120
121     xref = xrefs.get(1);
122     assertEquals("2FSR", xref.getId());
123     assertEquals("PDBsum", xref.getType());
124     assertNull(xref.getProperty());
125   }
126
127   /**
128    * Test the method that formats the sequence id
129    */
130   @Test(groups = { "Functional" })
131   public void testGetUniprotEntryId()
132   {
133     UniprotEntry entry = new Uniprot().getUniprotEntries(
134             new StringReader(UNIPROT_XML)).get(0);
135
136     /*
137      * name formatted as source | accession ids | names
138      * source database converted to Jalview canonical name
139      */
140     String expectedName = "UNIPROT|A9CKP4|A9CKP5|A9CKP4_AGRT5|A9CKP4_AGRT6";
141     assertEquals(expectedName, Uniprot.getUniprotEntryId(entry));
142   }
143
144   /**
145    * Test the method that formats the sequence description
146    */
147   @Test(groups = { "Functional" })
148   public void testGetUniprotEntryDescription()
149   {
150     UniprotEntry entry = new Uniprot().getUniprotEntries(
151             new StringReader(UNIPROT_XML)).get(0);
152   
153     /*
154      * recommended names concatenated with space separator
155      */
156     String expectedDescription = "Mitogen-activated protein kinase 13 Henry";
157     assertEquals(expectedDescription,
158             Uniprot.getUniprotEntryDescription(entry));
159   }
160 }