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;
36 import org.testng.annotations.Test;
38 public class DBRefUtilsTest
42 * Test the method that selects DBRefEntry items whose source is in a supplied
45 @Test(groups = { "Functional" })
46 public void testSelectRefs()
48 assertNull(DBRefUtils.selectRefs(null, null));
49 assertNull(DBRefUtils.selectRefs(null, DBRefSource.CODINGDBS));
51 DBRefEntry ref1 = new DBRefEntry("EMBL", "1.2", "A12345");
52 DBRefEntry ref2 = new DBRefEntry("UNIPROT", "1.2", "A12346");
53 // Source is converted to upper-case by this constructor!
54 DBRefEntry ref3 = new DBRefEntry("Uniprot", "1.2", "A12347");
55 DBRefEntry[] dbrefs = new DBRefEntry[] { ref1, ref2, ref3 };
56 String[] sources = new String[] { "EMBL", "UNIPROT" };
58 DBRefEntry[] selected = DBRefUtils.selectRefs(dbrefs, sources);
59 assertEquals(3, selected.length);
60 assertSame(ref1, selected[0]);
61 assertSame(ref2, selected[1]);
62 assertSame(ref3, selected[2]);
64 sources = new String[] { "EMBL" };
65 selected = DBRefUtils.selectRefs(dbrefs, sources);
66 assertEquals(1, selected.length);
67 assertSame(ref1, selected[0]);
69 sources = new String[] { "UNIPROT" };
70 selected = DBRefUtils.selectRefs(dbrefs, sources);
71 assertEquals(2, selected.length);
72 assertSame(ref2, selected[0]);
73 assertSame(ref3, selected[1]);
75 sources = new String[] { "Uniprot", "EMBLCDS" };
76 selected = DBRefUtils.selectRefs(dbrefs, sources);
81 * Test the method that converts (currently three) database names to a
82 * canonical name (not case-sensitive)
84 @Test(groups = { "Functional" })
85 public void testGetCanonicalName()
87 assertNull(DBRefUtils.getCanonicalName(null));
88 assertEquals("", DBRefUtils.getCanonicalName(""));
89 assertEquals("PDB", DBRefUtils.getCanonicalName("pdb"));
90 assertEquals("PDB", DBRefUtils.getCanonicalName("Pdb"));
91 assertEquals("UNIPROT",
92 DBRefUtils.getCanonicalName("uniprotkb/swiss-prot"));
93 assertEquals("UNIPROT", DBRefUtils.getCanonicalName("uniprotkb/trembl"));
94 assertEquals("UNIPROT",
95 DBRefUtils.getCanonicalName("UNIPROTKB/SWISS-PROT"));
96 assertEquals("UNIPROT", DBRefUtils.getCanonicalName("UNIPROTKB/TREMBL"));
97 assertEquals("UNIPROTKB/SWISS-CHEESE",
98 DBRefUtils.getCanonicalName("UNIPROTKB/SWISS-CHEESE"));
99 assertEquals("ENSEMBL", DBRefUtils.getCanonicalName("Ensembl"));
102 @Test(groups = { "Functional" })
103 public void testIsDasCoordinateSystem()
105 assertFalse(DBRefUtils.isDasCoordinateSystem(null, null));
106 assertFalse(DBRefUtils.isDasCoordinateSystem("pdbresnum", null));
107 assertFalse(DBRefUtils.isDasCoordinateSystem(null, new DBRefEntry(
108 "PDB", "v1", "a1")));
110 assertTrue(DBRefUtils.isDasCoordinateSystem("pdbresnum",
111 new DBRefEntry("PDB", "v1", "a1")));
112 assertTrue(DBRefUtils.isDasCoordinateSystem("PDBRESNUM",
113 new DBRefEntry("PDB", "v1", "a1")));
114 // "pdb" is converted to upper-case in DBRefEntry constructor
115 assertTrue(DBRefUtils.isDasCoordinateSystem("pdbresnum",
116 new DBRefEntry("pdb", "v1", "a1")));
117 assertFalse(DBRefUtils.isDasCoordinateSystem("pdb", new DBRefEntry(
118 "pdb", "v1", "a1")));
120 assertTrue(DBRefUtils.isDasCoordinateSystem("UNIPROT", new DBRefEntry(
121 "Uniprot", "v1", "a1")));
122 assertTrue(DBRefUtils.isDasCoordinateSystem("Uniprot", new DBRefEntry(
123 "UNIPROT", "v1", "a1")));
124 assertFalse(DBRefUtils.isDasCoordinateSystem("UNIPROTKB",
125 new DBRefEntry("pdb", "v1", "a1")));
127 assertTrue(DBRefUtils.isDasCoordinateSystem("EMBL", new DBRefEntry(
128 "EMBL", "v1", "a1")));
129 assertTrue(DBRefUtils.isDasCoordinateSystem("embl", new DBRefEntry(
130 "embl", "v1", "a1")));
134 * Test 'parsing' a DBRef - non PDB case
136 @Test(groups = { "Functional" })
137 public void testParseToDbRef()
139 SequenceI seq = new Sequence("Seq1", "ABCD");
140 DBRefEntry ref = DBRefUtils.parseToDbRef(seq, "EMBL", "1.2", "a7890");
141 DBRefEntry[] refs = seq.getDBRefs();
142 assertEquals(1, refs.length);
143 assertSame(ref, refs[0]);
144 assertEquals("EMBL", ref.getSource());
145 assertEquals("1.2", ref.getVersion());
146 assertEquals("a7890", ref.getAccessionId());
147 assertTrue(seq.getAllPDBEntries().isEmpty());
151 * Test 'parsing' a DBRef - Stockholm PDB format
153 @Test(groups = { "Functional" })
154 public void testParseToDbRef_PDB()
156 SequenceI seq = new Sequence("Seq1", "ABCD");
157 DBRefEntry ref = DBRefUtils.parseToDbRef(seq, "pdb", "1.2",
159 DBRefEntry[] refs = seq.getDBRefs();
160 assertEquals(1, refs.length);
161 assertSame(ref, refs[0]);
162 assertEquals("PDB", ref.getSource());
163 assertEquals("1.2", ref.getVersion());
164 // DBRef id is pdbId + chain code
165 assertEquals("1WRIA", ref.getAccessionId());
166 assertEquals(1, seq.getAllPDBEntries().size());
167 PDBEntry pdbRef = seq.getAllPDBEntries().get(0);
168 assertEquals("1WRI", pdbRef.getId());
169 assertNull(pdbRef.getFile());
170 assertEquals("A", pdbRef.getChainCode());
171 assertEquals("PDB", pdbRef.getType());
175 * Test the method that searches for matches references - case when we are
176 * matching a reference with no mappings
178 @Test(groups = { "Functional" })
179 public void testSearchRefs_noMapping()
181 DBRefEntry target = new DBRefEntry("EMBL", "2", "A1234");
183 DBRefEntry ref1 = new DBRefEntry("EMBL", "1", "A1234"); // matches
184 // constructor changes embl to EMBL
185 DBRefEntry ref2 = new DBRefEntry("embl", "1", "A1234"); // matches
186 // constructor does not upper-case accession id
187 DBRefEntry ref3 = new DBRefEntry("EMBL", "1", "a1234"); // no match
188 DBRefEntry ref4 = new DBRefEntry("EMBLCDS", "1", "A1234"); // no match
189 // ref5 matches although it has a mapping - ignored
190 DBRefEntry ref5 = new DBRefEntry("EMBL", "1", "A1234");
191 ref5.setMap(new Mapping(new MapList(new int[] { 1, 1 }, new int[] { 1,
194 DBRefEntry[] matches = DBRefUtils.searchRefs(new DBRefEntry[] { ref1,
195 ref2, ref3, ref4, ref5 }, target);
196 assertEquals(3, matches.length);
197 assertSame(ref1, matches[0]);
198 assertSame(ref2, matches[1]);
199 assertSame(ref5, matches[2]);
203 * Test the method that searches for matches references - case when we are
204 * matching a reference with a mapping
206 @Test(groups = { "Functional" })
207 public void testSearchRefs_withMapping()
209 DBRefEntry target = new DBRefEntry("EMBL", "2", "A1234");
210 final Mapping map1 = new Mapping(new MapList(new int[] { 1, 1 },
211 new int[] { 1, 1 }, 1, 1));
214 // these all match target iff mappings match
215 DBRefEntry ref1 = new DBRefEntry("EMBL", "1", "A1234"); // no map: matches
216 DBRefEntry ref2 = new DBRefEntry("EMBL", "1", "A1234"); // =map: matches
217 final Mapping map2 = new Mapping(new MapList(new int[] { 1, 1 },
218 new int[] { 1, 1 }, 1, 1));
221 // different map: no match
222 DBRefEntry ref3 = new DBRefEntry("EMBL", "1", "A1234");
223 final Mapping map3 = new Mapping(new MapList(new int[] { 1, 1 },
224 new int[] { 1, 1 }, 2, 2));
227 DBRefEntry[] matches = DBRefUtils.searchRefs(new DBRefEntry[] { ref1,
228 ref2, ref3 }, target);
229 assertEquals(2, matches.length);
230 assertSame(ref1, matches[0]);
231 assertSame(ref2, matches[1]);
235 * Test the method that searches for matching references based on accession id
238 @Test(groups = { "Functional" })
239 public void testSearchRefs_accessionid()
242 DBRefEntry ref1 = new DBRefEntry("Uniprot", "1", "A1234"); // matches
243 DBRefEntry ref2 = new DBRefEntry("embl", "1", "A1234"); // matches
244 // constructor does not upper-case accession id
245 DBRefEntry ref3 = new DBRefEntry("EMBL", "1", "a1234"); // no match
246 DBRefEntry ref4 = new DBRefEntry("EMBLCDS", "1", "A1235"); // no match
247 // ref5 matches although it has a mapping - ignored
248 DBRefEntry ref5 = new DBRefEntry("EMBL", "1", "A1234");
249 ref5.setMap(new Mapping(new MapList(new int[] { 1, 1 }, new int[] { 1,
252 DBRefEntry[] matches = DBRefUtils.searchRefs(new DBRefEntry[] { ref1,
253 ref2, ref3, ref4, ref5 }, "A1234");
254 assertEquals(3, matches.length);
255 assertSame(ref1, matches[0]);
256 assertSame(ref2, matches[1]);
257 assertSame(ref5, matches[2]);