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"));
101 @Test(groups = { "Functional" })
102 public void testIsDasCoordinateSystem()
104 assertFalse(DBRefUtils.isDasCoordinateSystem(null, null));
105 assertFalse(DBRefUtils.isDasCoordinateSystem("pdbresnum", null));
106 assertFalse(DBRefUtils.isDasCoordinateSystem(null, new DBRefEntry(
107 "PDB", "v1", "a1")));
109 assertTrue(DBRefUtils.isDasCoordinateSystem("pdbresnum",
110 new DBRefEntry("PDB", "v1", "a1")));
111 assertTrue(DBRefUtils.isDasCoordinateSystem("PDBRESNUM",
112 new DBRefEntry("PDB", "v1", "a1")));
113 // "pdb" is converted to upper-case in DBRefEntry constructor
114 assertTrue(DBRefUtils.isDasCoordinateSystem("pdbresnum",
115 new DBRefEntry("pdb", "v1", "a1")));
116 assertFalse(DBRefUtils.isDasCoordinateSystem("pdb", new DBRefEntry(
117 "pdb", "v1", "a1")));
119 assertTrue(DBRefUtils.isDasCoordinateSystem("UNIPROT", new DBRefEntry(
120 "Uniprot", "v1", "a1")));
121 assertTrue(DBRefUtils.isDasCoordinateSystem("Uniprot", new DBRefEntry(
122 "UNIPROT", "v1", "a1")));
123 assertFalse(DBRefUtils.isDasCoordinateSystem("UNIPROTKB",
124 new DBRefEntry("pdb", "v1", "a1")));
126 assertTrue(DBRefUtils.isDasCoordinateSystem("EMBL", new DBRefEntry(
127 "EMBL", "v1", "a1")));
128 assertTrue(DBRefUtils.isDasCoordinateSystem("embl", new DBRefEntry(
129 "embl", "v1", "a1")));
133 * Test 'parsing' a DBRef - non PDB case
135 @Test(groups = { "Functional" })
136 public void testParseToDbRef()
138 SequenceI seq = new Sequence("Seq1", "ABCD");
139 DBRefEntry ref = DBRefUtils.parseToDbRef(seq, "EMBL", "1.2", "a7890");
140 DBRefEntry[] refs = seq.getDBRef();
141 assertEquals(1, refs.length);
142 assertSame(ref, refs[0]);
143 assertEquals("EMBL", ref.getSource());
144 assertEquals("1.2", ref.getVersion());
145 assertEquals("a7890", ref.getAccessionId());
146 assertNull(seq.getAllPDBEntries());
150 * Test 'parsing' a DBRef - Stockholm PDB format
152 @Test(groups = { "Functional" })
153 public void testParseToDbRef_PDB()
155 SequenceI seq = new Sequence("Seq1", "ABCD");
156 DBRefEntry ref = DBRefUtils.parseToDbRef(seq, "pdb", "1.2",
158 DBRefEntry[] refs = seq.getDBRef();
159 assertEquals(1, refs.length);
160 assertSame(ref, refs[0]);
161 assertEquals("PDB", ref.getSource());
162 assertEquals("1.2", ref.getVersion());
163 // DBRef id is pdbId + chain code
164 assertEquals("1WRIA", ref.getAccessionId());
165 assertEquals(1, seq.getAllPDBEntries().size());
166 PDBEntry pdbRef = seq.getAllPDBEntries().get(0);
167 assertEquals("1WRI", pdbRef.getId());
168 assertNull(pdbRef.getFile());
169 assertEquals("A", pdbRef.getChainCode());
170 assertEquals("PDB", pdbRef.getType());
174 * Test the method that searches for matches references - case when we are
175 * matching a reference with no mappings
177 @Test(groups = { "Functional" })
178 public void testSearchRefs_noMapping()
180 DBRefEntry target = new DBRefEntry("EMBL", "2", "A1234");
182 DBRefEntry ref1 = new DBRefEntry("EMBL", "1", "A1234"); // matches
183 // constructor changes embl to EMBL
184 DBRefEntry ref2 = new DBRefEntry("embl", "1", "A1234"); // matches
185 // constructor does not upper-case accession id
186 DBRefEntry ref3 = new DBRefEntry("EMBL", "1", "a1234"); // no match
187 DBRefEntry ref4 = new DBRefEntry("EMBLCDS", "1", "A1234"); // no match
188 // ref5 matches although it has a mapping - ignored
189 DBRefEntry ref5 = new DBRefEntry("EMBL", "1", "A1234");
190 ref5.setMap(new Mapping(new MapList(new int[] { 1, 1 }, new int[] { 1,
193 DBRefEntry[] matches = DBRefUtils.searchRefs(new DBRefEntry[] { ref1,
194 ref2, ref3, ref4, ref5 }, target);
195 assertEquals(3, matches.length);
196 assertSame(ref1, matches[0]);
197 assertSame(ref2, matches[1]);
198 assertSame(ref5, matches[2]);
202 * Test the method that searches for matches references - case when we are
203 * matching a reference with a mapping
205 @Test(groups = { "Functional" })
206 public void testSearchRefs_withMapping()
208 DBRefEntry target = new DBRefEntry("EMBL", "2", "A1234");
209 final Mapping map1 = new Mapping(new MapList(new int[] { 1, 1 },
210 new int[] { 1, 1 }, 1, 1));
213 // these all match target iff mappings match
214 DBRefEntry ref1 = new DBRefEntry("EMBL", "1", "A1234"); // no map: matches
215 DBRefEntry ref2 = new DBRefEntry("EMBL", "1", "A1234"); // =map: matches
216 final Mapping map2 = new Mapping(new MapList(new int[] { 1, 1 },
217 new int[] { 1, 1 }, 1, 1));
220 // different map: no match
221 DBRefEntry ref3 = new DBRefEntry("EMBL", "1", "A1234");
222 final Mapping map3 = new Mapping(new MapList(new int[] { 1, 1 },
223 new int[] { 1, 1 }, 2, 2));
226 DBRefEntry[] matches = DBRefUtils.searchRefs(new DBRefEntry[] { ref1,
227 ref2, ref3 }, target);
228 assertEquals(2, matches.length);
229 assertSame(ref1, matches[0]);
230 assertSame(ref2, matches[1]);