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.
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertFalse;
25 import static org.testng.AssertJUnit.assertNull;
26 import static org.testng.AssertJUnit.assertSame;
27 import static org.testng.AssertJUnit.assertTrue;
29 import jalview.datamodel.DBRefEntry;
30 import jalview.datamodel.DBRefSource;
31 import jalview.datamodel.Mapping;
32 import jalview.datamodel.PDBEntry;
33 import jalview.datamodel.Sequence;
34 import jalview.datamodel.SequenceI;
35 import jalview.gui.JvOptionPane;
37 import java.util.List;
39 import org.testng.annotations.BeforeClass;
40 import org.testng.annotations.Test;
42 public class DBRefUtilsTest
45 @BeforeClass(alwaysRun = true)
46 public void setUpJvOptionPane()
48 JvOptionPane.setInteractiveMode(false);
49 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
53 * Test the method that selects DBRefEntry items whose source is in a supplied
56 @Test(groups = { "Functional" })
57 public void testSelectRefs()
59 assertNull(DBRefUtils.selectRefs(null, null));
60 assertNull(DBRefUtils.selectRefs(null, DBRefSource.CODINGDBS));
62 DBRefEntry ref1 = new DBRefEntry("EMBL", "1.2", "A12345");
63 DBRefEntry ref2 = new DBRefEntry("UNIPROT", "1.2", "A12346");
64 // Source is converted to upper-case by this constructor!
65 DBRefEntry ref3 = new DBRefEntry("Uniprot", "1.2", "A12347");
66 DBRefEntry[] dbrefs = new DBRefEntry[] { ref1, ref2, ref3 };
67 String[] sources = new String[] { "EMBL", "UNIPROT" };
69 DBRefEntry[] selected = DBRefUtils.selectRefs(dbrefs, sources);
70 assertEquals(3, selected.length);
71 assertSame(ref1, selected[0]);
72 assertSame(ref2, selected[1]);
73 assertSame(ref3, selected[2]);
75 sources = new String[] { "EMBL" };
76 selected = DBRefUtils.selectRefs(dbrefs, sources);
77 assertEquals(1, selected.length);
78 assertSame(ref1, selected[0]);
80 sources = new String[] { "UNIPROT" };
81 selected = DBRefUtils.selectRefs(dbrefs, sources);
82 assertEquals(2, selected.length);
83 assertSame(ref2, selected[0]);
84 assertSame(ref3, selected[1]);
86 sources = new String[] { "EMBLCDS" };
87 selected = DBRefUtils.selectRefs(dbrefs, sources);
90 sources = new String[] { "embl", "uniprot" };
91 selected = DBRefUtils.selectRefs(dbrefs, sources);
92 assertEquals(3, selected.length);
93 assertSame(ref1, selected[0]);
94 assertSame(ref2, selected[1]);
95 assertSame(ref3, selected[2]);
99 * Test the method that converts (currently three) database names to a
100 * canonical name (not case-sensitive)
102 @Test(groups = { "Functional" })
103 public void testGetCanonicalName()
105 assertNull(DBRefUtils.getCanonicalName(null));
106 assertEquals("", DBRefUtils.getCanonicalName(""));
107 assertEquals("PDB", DBRefUtils.getCanonicalName("pdb"));
108 assertEquals("PDB", DBRefUtils.getCanonicalName("Pdb"));
109 assertEquals("UNIPROT",
110 DBRefUtils.getCanonicalName("uniprotkb/swiss-prot"));
111 assertEquals("UNIPROT", DBRefUtils.getCanonicalName("uniprotkb/trembl"));
112 assertEquals("UNIPROT",
113 DBRefUtils.getCanonicalName("UNIPROTKB/SWISS-PROT"));
114 assertEquals("UNIPROT", DBRefUtils.getCanonicalName("UNIPROTKB/TREMBL"));
115 assertEquals("UNIPROTKB/SWISS-CHEESE",
116 DBRefUtils.getCanonicalName("UNIPROTKB/SWISS-CHEESE"));
117 assertEquals("ENSEMBL", DBRefUtils.getCanonicalName("Ensembl"));
119 // these are not 'known' to Jalview
120 assertEquals("PFAM", DBRefUtils.getCanonicalName("PFAM"));
121 assertEquals("pfam", DBRefUtils.getCanonicalName("pfam"));
125 @Test(groups = { "Functional" })
126 public void testIsDasCoordinateSystem()
128 assertFalse(DBRefUtils.isDasCoordinateSystem(null, null));
129 assertFalse(DBRefUtils.isDasCoordinateSystem("pdbresnum", null));
130 assertFalse(DBRefUtils.isDasCoordinateSystem(null, new DBRefEntry(
131 "PDB", "v1", "a1")));
133 assertTrue(DBRefUtils.isDasCoordinateSystem("pdbresnum",
134 new DBRefEntry("PDB", "v1", "a1")));
135 assertTrue(DBRefUtils.isDasCoordinateSystem("PDBRESNUM",
136 new DBRefEntry("PDB", "v1", "a1")));
137 // "pdb" is converted to upper-case in DBRefEntry constructor
138 assertTrue(DBRefUtils.isDasCoordinateSystem("pdbresnum",
139 new DBRefEntry("pdb", "v1", "a1")));
140 assertFalse(DBRefUtils.isDasCoordinateSystem("pdb", new DBRefEntry(
141 "pdb", "v1", "a1")));
143 assertTrue(DBRefUtils.isDasCoordinateSystem("UNIPROT", new DBRefEntry(
144 "Uniprot", "v1", "a1")));
145 assertTrue(DBRefUtils.isDasCoordinateSystem("Uniprot", new DBRefEntry(
146 "UNIPROT", "v1", "a1")));
147 assertFalse(DBRefUtils.isDasCoordinateSystem("UNIPROTKB",
148 new DBRefEntry("pdb", "v1", "a1")));
150 assertTrue(DBRefUtils.isDasCoordinateSystem("EMBL", new DBRefEntry(
151 "EMBL", "v1", "a1")));
152 assertTrue(DBRefUtils.isDasCoordinateSystem("embl", new DBRefEntry(
153 "embl", "v1", "a1")));
157 * Test 'parsing' a DBRef - non PDB case
159 @Test(groups = { "Functional" })
160 public void testParseToDbRef()
162 SequenceI seq = new Sequence("Seq1", "ABCD");
163 DBRefEntry ref = DBRefUtils.parseToDbRef(seq, "EMBL", "1.2", "a7890");
164 DBRefEntry[] refs = seq.getDBRefs();
165 assertEquals(1, refs.length);
166 assertSame(ref, refs[0]);
167 assertEquals("EMBL", ref.getSource());
168 assertEquals("1.2", ref.getVersion());
169 assertEquals("a7890", ref.getAccessionId());
170 assertTrue(seq.getAllPDBEntries().isEmpty());
174 * Test 'parsing' a DBRef - Stockholm PDB format
176 @Test(groups = { "Functional" })
177 public void testParseToDbRef_PDB()
179 SequenceI seq = new Sequence("Seq1", "ABCD");
180 DBRefEntry ref = DBRefUtils.parseToDbRef(seq, "pdb", "1.2",
182 // TODO: correct PDBEntry and PDB DBRef accessions need to be generated for
183 // PDB ref in Stockholm
185 DBRefEntry[] refs = seq.getDBRefs();
186 assertEquals(1, refs.length);
187 assertSame(ref, refs[0]);
188 assertEquals("PDB", ref.getSource());
189 assertEquals("1.2", ref.getVersion());
190 // DBRef id is pdbId + chain code
191 assertEquals("1WRIA", ref.getAccessionId());
192 assertEquals(1, seq.getAllPDBEntries().size());
193 PDBEntry pdbRef = seq.getAllPDBEntries().get(0);
194 assertEquals("1WRI", pdbRef.getId());
195 assertNull(pdbRef.getFile());
196 assertEquals("A", pdbRef.getChainCode());
197 assertEquals("PDB", pdbRef.getType());
201 * Test the method that searches for matches references - case when we are
202 * matching a reference with no mappings
204 @Test(groups = { "Functional" })
205 public void testSearchRefs_noMapping()
207 DBRefEntry target = new DBRefEntry("EMBL", "2", "A1234");
209 DBRefEntry ref1 = new DBRefEntry("EMBL", "1", "A1234"); // matches
210 // constructor changes embl to EMBL
211 DBRefEntry ref2 = new DBRefEntry("embl", "1", "A1234"); // matches
212 // constructor does not upper-case accession id
213 DBRefEntry ref3 = new DBRefEntry("EMBL", "1", "a1234"); // no match
214 DBRefEntry ref4 = new DBRefEntry("EMBLCDS", "1", "A1234"); // no match
215 // ref5 matches although it has a mapping - ignored
216 DBRefEntry ref5 = new DBRefEntry("EMBL", "1", "A1234");
217 ref5.setMap(new Mapping(new MapList(new int[] { 1, 1 }, new int[] { 1,
220 List<DBRefEntry> matches = DBRefUtils.searchRefs(new DBRefEntry[] {
221 ref1, ref2, ref3, ref4, ref5 }, target);
222 assertEquals(3, matches.size());
223 assertSame(ref1, matches.get(0));
224 assertSame(ref2, matches.get(1));
225 assertSame(ref5, matches.get(2));
229 * Test the method that searches for matches references - case when we are
230 * matching a reference with a mapping
232 @Test(groups = { "Functional" })
233 public void testSearchRefs_withMapping()
235 DBRefEntry target = new DBRefEntry("EMBL", "2", "A1234");
236 final Mapping map1 = new Mapping(new MapList(new int[] { 1, 1 },
237 new int[] { 1, 1 }, 1, 1));
240 // these all match target iff mappings match
241 DBRefEntry ref1 = new DBRefEntry("EMBL", "1", "A1234"); // no map: matches
242 DBRefEntry ref2 = new DBRefEntry("EMBL", "1", "A1234"); // =map: matches
243 final Mapping map2 = new Mapping(new MapList(new int[] { 1, 1 },
244 new int[] { 1, 1 }, 1, 1));
247 // different map: no match
248 DBRefEntry ref3 = new DBRefEntry("EMBL", "1", "A1234");
249 final Mapping map3 = new Mapping(new MapList(new int[] { 1, 1 },
250 new int[] { 1, 1 }, 2, 2));
253 List<DBRefEntry> matches = DBRefUtils.searchRefs(new DBRefEntry[] {
254 ref1, ref2, ref3 }, target);
255 assertEquals(2, matches.size());
256 assertSame(ref1, matches.get(0));
257 assertSame(ref2, matches.get(1));
261 * Test the method that searches for matching references based on accession id
264 @Test(groups = { "Functional" })
265 public void testSearchRefs_accessionid()
268 DBRefEntry ref1 = new DBRefEntry("Uniprot", "1", "A1234"); // matches
269 DBRefEntry ref2 = new DBRefEntry("embl", "1", "A1234"); // matches
270 // constructor does not upper-case accession id
271 DBRefEntry ref3 = new DBRefEntry("EMBL", "1", "a1234"); // no match
272 DBRefEntry ref4 = new DBRefEntry("EMBLCDS", "1", "A1235"); // no match
273 // ref5 matches although it has a mapping - ignored
274 DBRefEntry ref5 = new DBRefEntry("EMBL", "1", "A1234");
275 ref5.setMap(new Mapping(new MapList(new int[] { 1, 1 }, new int[] { 1,
278 DBRefEntry[] dbrefs = new DBRefEntry[] { ref1, ref2, ref3, ref4, ref5 };
279 List<DBRefEntry> matches = DBRefUtils.searchRefs(dbrefs, "A1234");
280 assertEquals(3, matches.size());
281 assertSame(ref1, matches.get(0));
282 assertSame(ref2, matches.get(1));
283 assertSame(ref5, matches.get(2));
287 * Test the method that searches for matches references - case when we are
288 * matching a reference with null (any) accession id
290 @Test(groups = { "Functional" })
291 public void testSearchRefs_wildcardAccessionid()
293 DBRefEntry target = new DBRefEntry("EMBL", "2", null);
295 DBRefEntry ref1 = new DBRefEntry("EMBL", "1", "A1234"); // matches
296 // constructor changes embl to EMBL
297 DBRefEntry ref2 = new DBRefEntry("embl", "1", "A1235"); // matches
298 // constructor does not upper-case accession id
299 DBRefEntry ref3 = new DBRefEntry("EMBL", "1", "A1236"); // matches
300 DBRefEntry ref4 = new DBRefEntry("EMBLCDS", "1", "A1234"); // no match
301 // ref5 matches although it has a mapping - ignored
302 DBRefEntry ref5 = new DBRefEntry("EMBL", "1", "A1237");
303 ref5.setMap(new Mapping(new MapList(new int[] { 1, 1 }, new int[] { 1,
306 List<DBRefEntry> matches = DBRefUtils.searchRefs(new DBRefEntry[] {
307 ref1, ref2, ref3, ref4, ref5 }, target);
308 assertEquals(4, matches.size());
309 assertSame(ref1, matches.get(0));
310 assertSame(ref2, matches.get(1));
311 assertSame(ref3, matches.get(2));
312 assertSame(ref5, matches.get(3));