3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertFalse;
5 import static org.junit.Assert.assertNull;
6 import static org.junit.Assert.assertSame;
7 import static org.junit.Assert.assertTrue;
8 import jalview.datamodel.DBRefEntry;
9 import jalview.datamodel.DBRefSource;
10 import jalview.datamodel.Mapping;
11 import jalview.datamodel.PDBEntry;
12 import jalview.datamodel.Sequence;
13 import jalview.datamodel.SequenceI;
15 import org.junit.Test;
17 public class DBRefUtilsTest
21 * Test the method that selects DBRefEntry items whose source is in a supplied
25 public void testSelectRefs()
27 assertNull(DBRefUtils.selectRefs(null, null));
28 assertNull(DBRefUtils.selectRefs(null, DBRefSource.CODINGDBS));
30 DBRefEntry ref1 = new DBRefEntry("EMBL", "1.2", "A12345");
31 DBRefEntry ref2 = new DBRefEntry("UNIPROT", "1.2", "A12346");
32 // Source is converted to upper-case by this constructor!
33 DBRefEntry ref3 = new DBRefEntry("Uniprot", "1.2", "A12347");
34 DBRefEntry[] dbrefs = new DBRefEntry[]
36 String[] sources = new String[]
37 { "EMBL", "UNIPROT" };
39 DBRefEntry[] selected = DBRefUtils.selectRefs(dbrefs, sources);
40 assertEquals(3, selected.length);
41 assertSame(ref1, selected[0]);
42 assertSame(ref2, selected[1]);
43 assertSame(ref3, selected[2]);
45 sources = new String[]
47 selected = DBRefUtils.selectRefs(dbrefs, sources);
48 assertEquals(1, selected.length);
49 assertSame(ref1, selected[0]);
51 sources = new String[]
53 selected = DBRefUtils.selectRefs(dbrefs, sources);
54 assertEquals(2, selected.length);
55 assertSame(ref2, selected[0]);
56 assertSame(ref3, selected[1]);
58 sources = new String[]
59 { "Uniprot", "EMBLCDS" };
60 selected = DBRefUtils.selectRefs(dbrefs, sources);
65 * Test the method that converts (currently three) database names to a
66 * canonical name (not case-sensitive)
69 public void testGetCanonicalName()
71 assertNull(DBRefUtils.getCanonicalName(null));
72 assertEquals("", DBRefUtils.getCanonicalName(""));
73 assertEquals("PDB", DBRefUtils.getCanonicalName("pdb"));
74 assertEquals("PDB", DBRefUtils.getCanonicalName("Pdb"));
75 assertEquals("UNIPROT",
76 DBRefUtils.getCanonicalName("uniprotkb/swiss-prot"));
77 assertEquals("UNIPROT", DBRefUtils.getCanonicalName("uniprotkb/trembl"));
78 assertEquals("UNIPROT",
79 DBRefUtils.getCanonicalName("UNIPROTKB/SWISS-PROT"));
80 assertEquals("UNIPROT", DBRefUtils.getCanonicalName("UNIPROTKB/TREMBL"));
81 assertEquals("UNIPROTKB/SWISS-CHEESE",
82 DBRefUtils.getCanonicalName("UNIPROTKB/SWISS-CHEESE"));
86 public void testIsDasCoordinateSystem()
88 assertFalse(DBRefUtils.isDasCoordinateSystem(null, null));
89 assertFalse(DBRefUtils.isDasCoordinateSystem("pdbresnum", null));
90 assertFalse(DBRefUtils.isDasCoordinateSystem(null, new DBRefEntry(
93 assertTrue(DBRefUtils.isDasCoordinateSystem("pdbresnum",
94 new DBRefEntry("PDB", "v1", "a1")));
95 assertTrue(DBRefUtils.isDasCoordinateSystem("PDBRESNUM",
96 new DBRefEntry("PDB", "v1", "a1")));
97 // "pdb" is converted to upper-case in DBRefEntry constructor
98 assertTrue(DBRefUtils.isDasCoordinateSystem("pdbresnum",
99 new DBRefEntry("pdb", "v1", "a1")));
100 assertFalse(DBRefUtils.isDasCoordinateSystem("pdb", new DBRefEntry(
101 "pdb", "v1", "a1")));
103 assertTrue(DBRefUtils.isDasCoordinateSystem("UNIPROT", new DBRefEntry(
104 "Uniprot", "v1", "a1")));
105 assertTrue(DBRefUtils.isDasCoordinateSystem("Uniprot", new DBRefEntry(
106 "UNIPROT", "v1", "a1")));
107 assertFalse(DBRefUtils.isDasCoordinateSystem("UNIPROTKB",
109 "pdb", "v1", "a1")));
111 assertTrue(DBRefUtils.isDasCoordinateSystem("EMBL", new DBRefEntry(
112 "EMBL", "v1", "a1")));
113 assertTrue(DBRefUtils.isDasCoordinateSystem("embl", new DBRefEntry(
114 "embl", "v1", "a1")));
118 * Test 'parsing' a DBRef - non PDB case
121 public void testParseToDbRef()
123 SequenceI seq = new Sequence("Seq1", "ABCD");
124 DBRefEntry ref = DBRefUtils.parseToDbRef(seq, "EMBL", "1.2", "a7890");
125 DBRefEntry[] refs = seq.getDBRef();
126 assertEquals(1, refs.length);
127 assertSame(ref, refs[0]);
128 assertEquals("EMBL", ref.getSource());
129 assertEquals("1.2", ref.getVersion());
130 assertEquals("a7890", ref.getAccessionId());
131 assertNull(seq.getPDBId());
135 * Test 'parsing' a DBRef - Stockholm PDB format
138 public void testParseToDbRef_PDB()
140 SequenceI seq = new Sequence("Seq1", "ABCD");
141 DBRefEntry ref = DBRefUtils.parseToDbRef(seq, "pdb", "1.2",
143 DBRefEntry[] refs = seq.getDBRef();
144 assertEquals(1, refs.length);
145 assertSame(ref, refs[0]);
146 assertEquals("PDB", ref.getSource());
147 assertEquals("1.2", ref.getVersion());
148 // DBRef id is pdbId + chain code
149 assertEquals("1WRIA", ref.getAccessionId());
150 assertEquals(1, seq.getPDBId().size());
151 PDBEntry pdbRef = seq.getPDBId().get(0);
152 assertEquals("1WRI", pdbRef.getId());
153 assertNull(pdbRef.getFile());
154 assertEquals("A", pdbRef.getChainCode());
155 assertEquals("PDB", pdbRef.getType());
159 * Test the method that searches for matches references - case when we are
160 * matching a reference with no mappings
163 public void testSearchRefs_noMapping()
165 DBRefEntry target = new DBRefEntry("EMBL", "2", "A1234");
167 DBRefEntry ref1 = new DBRefEntry("EMBL", "1", "A1234"); // matches
168 // constructor changes embl to EMBL
169 DBRefEntry ref2 = new DBRefEntry("embl", "1", "A1234"); // matches
170 // constructor does not upper-case accession id
171 DBRefEntry ref3 = new DBRefEntry("EMBL", "1", "a1234"); // no match
172 DBRefEntry ref4 = new DBRefEntry("EMBLCDS", "1", "A1234"); // no match
173 // ref5 matches although it has a mapping - ignored
174 DBRefEntry ref5 = new DBRefEntry("EMBL", "1", "A1234");
175 ref5.setMap(new Mapping(new MapList(new int[]
179 DBRefEntry[] matches = DBRefUtils.searchRefs(new DBRefEntry[]
180 { ref1, ref2, ref3, ref4, ref5 }, target);
181 assertEquals(3, matches.length);
182 assertSame(ref1, matches[0]);
183 assertSame(ref2, matches[1]);
184 assertSame(ref5, matches[2]);
188 * Test the method that searches for matches references - case when we are
189 * matching a reference with a mapping
192 public void testSearchRefs_withMapping()
194 DBRefEntry target = new DBRefEntry("EMBL", "2", "A1234");
195 final Mapping map1 = new Mapping(new MapList(new int[]
200 // these all match target iff mappings match
201 DBRefEntry ref1 = new DBRefEntry("EMBL", "1", "A1234"); // no map: matches
202 DBRefEntry ref2 = new DBRefEntry("EMBL", "1", "A1234"); // =map: matches
203 final Mapping map2 = new Mapping(new MapList(new int[]
208 // different map: no match
209 DBRefEntry ref3 = new DBRefEntry("EMBL", "1", "A1234");
210 final Mapping map3 = new Mapping(new MapList(new int[]
215 DBRefEntry[] matches = DBRefUtils.searchRefs(new DBRefEntry[]
216 { ref1, ref2, ref3 }, target);
217 assertEquals(2, matches.length);
218 assertSame(ref1, matches[0]);
219 assertSame(ref2, matches[1]);