3 import static org.testng.AssertJUnit.assertEquals;
4 import static org.testng.AssertJUnit.assertFalse;
5 import static org.testng.AssertJUnit.assertNull;
6 import static org.testng.AssertJUnit.assertSame;
7 import static org.testng.AssertJUnit.assertTrue;
9 import jalview.datamodel.DBRefEntry;
10 import jalview.datamodel.DBRefSource;
11 import jalview.datamodel.Mapping;
12 import jalview.datamodel.PDBEntry;
13 import jalview.datamodel.Sequence;
14 import jalview.datamodel.SequenceI;
16 import org.testng.annotations.Test;
18 public class DBRefUtilsTest
22 * Test the method that selects DBRefEntry items whose source is in a supplied
25 @Test(groups = { "Functional" })
26 public void testSelectRefs()
28 assertNull(DBRefUtils.selectRefs(null, null));
29 assertNull(DBRefUtils.selectRefs(null, DBRefSource.CODINGDBS));
31 DBRefEntry ref1 = new DBRefEntry("EMBL", "1.2", "A12345");
32 DBRefEntry ref2 = new DBRefEntry("UNIPROT", "1.2", "A12346");
33 // Source is converted to upper-case by this constructor!
34 DBRefEntry ref3 = new DBRefEntry("Uniprot", "1.2", "A12347");
35 DBRefEntry[] dbrefs = new DBRefEntry[] { ref1, ref2, ref3 };
36 String[] sources = new String[] { "EMBL", "UNIPROT" };
38 DBRefEntry[] selected = DBRefUtils.selectRefs(dbrefs, sources);
39 assertEquals(3, selected.length);
40 assertSame(ref1, selected[0]);
41 assertSame(ref2, selected[1]);
42 assertSame(ref3, selected[2]);
44 sources = new String[] { "EMBL" };
45 selected = DBRefUtils.selectRefs(dbrefs, sources);
46 assertEquals(1, selected.length);
47 assertSame(ref1, selected[0]);
49 sources = new String[] { "UNIPROT" };
50 selected = DBRefUtils.selectRefs(dbrefs, sources);
51 assertEquals(2, selected.length);
52 assertSame(ref2, selected[0]);
53 assertSame(ref3, selected[1]);
55 sources = new String[] { "Uniprot", "EMBLCDS" };
56 selected = DBRefUtils.selectRefs(dbrefs, sources);
61 * Test the method that converts (currently three) database names to a
62 * canonical name (not case-sensitive)
64 @Test(groups = { "Functional" })
65 public void testGetCanonicalName()
67 assertNull(DBRefUtils.getCanonicalName(null));
68 assertEquals("", DBRefUtils.getCanonicalName(""));
69 assertEquals("PDB", DBRefUtils.getCanonicalName("pdb"));
70 assertEquals("PDB", DBRefUtils.getCanonicalName("Pdb"));
71 assertEquals("UNIPROT",
72 DBRefUtils.getCanonicalName("uniprotkb/swiss-prot"));
73 assertEquals("UNIPROT", DBRefUtils.getCanonicalName("uniprotkb/trembl"));
74 assertEquals("UNIPROT",
75 DBRefUtils.getCanonicalName("UNIPROTKB/SWISS-PROT"));
76 assertEquals("UNIPROT", DBRefUtils.getCanonicalName("UNIPROTKB/TREMBL"));
77 assertEquals("UNIPROTKB/SWISS-CHEESE",
78 DBRefUtils.getCanonicalName("UNIPROTKB/SWISS-CHEESE"));
81 @Test(groups = { "Functional" })
82 public void testIsDasCoordinateSystem()
84 assertFalse(DBRefUtils.isDasCoordinateSystem(null, null));
85 assertFalse(DBRefUtils.isDasCoordinateSystem("pdbresnum", null));
86 assertFalse(DBRefUtils.isDasCoordinateSystem(null, new DBRefEntry(
89 assertTrue(DBRefUtils.isDasCoordinateSystem("pdbresnum",
90 new DBRefEntry("PDB", "v1", "a1")));
91 assertTrue(DBRefUtils.isDasCoordinateSystem("PDBRESNUM",
92 new DBRefEntry("PDB", "v1", "a1")));
93 // "pdb" is converted to upper-case in DBRefEntry constructor
94 assertTrue(DBRefUtils.isDasCoordinateSystem("pdbresnum",
95 new DBRefEntry("pdb", "v1", "a1")));
96 assertFalse(DBRefUtils.isDasCoordinateSystem("pdb", new DBRefEntry(
99 assertTrue(DBRefUtils.isDasCoordinateSystem("UNIPROT", new DBRefEntry(
100 "Uniprot", "v1", "a1")));
101 assertTrue(DBRefUtils.isDasCoordinateSystem("Uniprot", new DBRefEntry(
102 "UNIPROT", "v1", "a1")));
103 assertFalse(DBRefUtils.isDasCoordinateSystem("UNIPROTKB",
104 new DBRefEntry("pdb", "v1", "a1")));
106 assertTrue(DBRefUtils.isDasCoordinateSystem("EMBL", new DBRefEntry(
107 "EMBL", "v1", "a1")));
108 assertTrue(DBRefUtils.isDasCoordinateSystem("embl", new DBRefEntry(
109 "embl", "v1", "a1")));
113 * Test 'parsing' a DBRef - non PDB case
115 @Test(groups = { "Functional" })
116 public void testParseToDbRef()
118 SequenceI seq = new Sequence("Seq1", "ABCD");
119 DBRefEntry ref = DBRefUtils.parseToDbRef(seq, "EMBL", "1.2", "a7890");
120 DBRefEntry[] refs = seq.getDBRef();
121 assertEquals(1, refs.length);
122 assertSame(ref, refs[0]);
123 assertEquals("EMBL", ref.getSource());
124 assertEquals("1.2", ref.getVersion());
125 assertEquals("a7890", ref.getAccessionId());
126 assertNull(seq.getAllPDBEntries());
130 * Test 'parsing' a DBRef - Stockholm PDB format
132 @Test(groups = { "Functional" })
133 public void testParseToDbRef_PDB()
135 SequenceI seq = new Sequence("Seq1", "ABCD");
136 DBRefEntry ref = DBRefUtils.parseToDbRef(seq, "pdb", "1.2",
138 DBRefEntry[] refs = seq.getDBRef();
139 assertEquals(1, refs.length);
140 assertSame(ref, refs[0]);
141 assertEquals("PDB", ref.getSource());
142 assertEquals("1.2", ref.getVersion());
143 // DBRef id is pdbId + chain code
144 assertEquals("1WRIA", ref.getAccessionId());
145 assertEquals(1, seq.getAllPDBEntries().size());
146 PDBEntry pdbRef = seq.getAllPDBEntries().get(0);
147 assertEquals("1WRI", pdbRef.getId());
148 assertNull(pdbRef.getFile());
149 assertEquals("A", pdbRef.getChainCode());
150 assertEquals("PDB", pdbRef.getType());
154 * Test the method that searches for matches references - case when we are
155 * matching a reference with no mappings
157 @Test(groups = { "Functional" })
158 public void testSearchRefs_noMapping()
160 DBRefEntry target = new DBRefEntry("EMBL", "2", "A1234");
162 DBRefEntry ref1 = new DBRefEntry("EMBL", "1", "A1234"); // matches
163 // constructor changes embl to EMBL
164 DBRefEntry ref2 = new DBRefEntry("embl", "1", "A1234"); // matches
165 // constructor does not upper-case accession id
166 DBRefEntry ref3 = new DBRefEntry("EMBL", "1", "a1234"); // no match
167 DBRefEntry ref4 = new DBRefEntry("EMBLCDS", "1", "A1234"); // no match
168 // ref5 matches although it has a mapping - ignored
169 DBRefEntry ref5 = new DBRefEntry("EMBL", "1", "A1234");
170 ref5.setMap(new Mapping(new MapList(new int[] { 1, 1 }, new int[] { 1,
173 DBRefEntry[] matches = DBRefUtils.searchRefs(new DBRefEntry[] { ref1,
174 ref2, ref3, ref4, ref5 }, target);
175 assertEquals(3, matches.length);
176 assertSame(ref1, matches[0]);
177 assertSame(ref2, matches[1]);
178 assertSame(ref5, matches[2]);
182 * Test the method that searches for matches references - case when we are
183 * matching a reference with a mapping
185 @Test(groups = { "Functional" })
186 public void testSearchRefs_withMapping()
188 DBRefEntry target = new DBRefEntry("EMBL", "2", "A1234");
189 final Mapping map1 = new Mapping(new MapList(new int[] { 1, 1 },
190 new int[] { 1, 1 }, 1, 1));
193 // these all match target iff mappings match
194 DBRefEntry ref1 = new DBRefEntry("EMBL", "1", "A1234"); // no map: matches
195 DBRefEntry ref2 = new DBRefEntry("EMBL", "1", "A1234"); // =map: matches
196 final Mapping map2 = new Mapping(new MapList(new int[] { 1, 1 },
197 new int[] { 1, 1 }, 1, 1));
200 // different map: no match
201 DBRefEntry ref3 = new DBRefEntry("EMBL", "1", "A1234");
202 final Mapping map3 = new Mapping(new MapList(new int[] { 1, 1 },
203 new int[] { 1, 1 }, 2, 2));
206 DBRefEntry[] matches = DBRefUtils.searchRefs(new DBRefEntry[] { ref1,
207 ref2, ref3 }, target);
208 assertEquals(2, matches.length);
209 assertSame(ref1, matches[0]);
210 assertSame(ref2, matches[1]);