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[]
37 String[] sources = new String[]
38 { "EMBL", "UNIPROT" };
40 DBRefEntry[] selected = DBRefUtils.selectRefs(dbrefs, sources);
41 assertEquals(3, selected.length);
42 assertSame(ref1, selected[0]);
43 assertSame(ref2, selected[1]);
44 assertSame(ref3, selected[2]);
46 sources = new String[]
48 selected = DBRefUtils.selectRefs(dbrefs, sources);
49 assertEquals(1, selected.length);
50 assertSame(ref1, selected[0]);
52 sources = new String[]
54 selected = DBRefUtils.selectRefs(dbrefs, sources);
55 assertEquals(2, selected.length);
56 assertSame(ref2, selected[0]);
57 assertSame(ref3, selected[1]);
59 sources = new String[]
60 { "Uniprot", "EMBLCDS" };
61 selected = DBRefUtils.selectRefs(dbrefs, sources);
66 * Test the method that converts (currently three) database names to a
67 * canonical name (not case-sensitive)
69 @Test(groups ={ "Functional" })
70 public void testGetCanonicalName()
72 assertNull(DBRefUtils.getCanonicalName(null));
73 assertEquals("", DBRefUtils.getCanonicalName(""));
74 assertEquals("PDB", DBRefUtils.getCanonicalName("pdb"));
75 assertEquals("PDB", DBRefUtils.getCanonicalName("Pdb"));
76 assertEquals("UNIPROT",
77 DBRefUtils.getCanonicalName("uniprotkb/swiss-prot"));
78 assertEquals("UNIPROT", DBRefUtils.getCanonicalName("uniprotkb/trembl"));
79 assertEquals("UNIPROT",
80 DBRefUtils.getCanonicalName("UNIPROTKB/SWISS-PROT"));
81 assertEquals("UNIPROT", DBRefUtils.getCanonicalName("UNIPROTKB/TREMBL"));
82 assertEquals("UNIPROTKB/SWISS-CHEESE",
83 DBRefUtils.getCanonicalName("UNIPROTKB/SWISS-CHEESE"));
86 @Test(groups ={ "Functional" })
87 public void testIsDasCoordinateSystem()
89 assertFalse(DBRefUtils.isDasCoordinateSystem(null, null));
90 assertFalse(DBRefUtils.isDasCoordinateSystem("pdbresnum", null));
91 assertFalse(DBRefUtils.isDasCoordinateSystem(null, new DBRefEntry(
94 assertTrue(DBRefUtils.isDasCoordinateSystem("pdbresnum",
95 new DBRefEntry("PDB", "v1", "a1")));
96 assertTrue(DBRefUtils.isDasCoordinateSystem("PDBRESNUM",
97 new DBRefEntry("PDB", "v1", "a1")));
98 // "pdb" is converted to upper-case in DBRefEntry constructor
99 assertTrue(DBRefUtils.isDasCoordinateSystem("pdbresnum",
100 new DBRefEntry("pdb", "v1", "a1")));
101 assertFalse(DBRefUtils.isDasCoordinateSystem("pdb", new DBRefEntry(
102 "pdb", "v1", "a1")));
104 assertTrue(DBRefUtils.isDasCoordinateSystem("UNIPROT", new DBRefEntry(
105 "Uniprot", "v1", "a1")));
106 assertTrue(DBRefUtils.isDasCoordinateSystem("Uniprot", new DBRefEntry(
107 "UNIPROT", "v1", "a1")));
108 assertFalse(DBRefUtils.isDasCoordinateSystem("UNIPROTKB",
110 "pdb", "v1", "a1")));
112 assertTrue(DBRefUtils.isDasCoordinateSystem("EMBL", new DBRefEntry(
113 "EMBL", "v1", "a1")));
114 assertTrue(DBRefUtils.isDasCoordinateSystem("embl", new DBRefEntry(
115 "embl", "v1", "a1")));
119 * Test 'parsing' a DBRef - non PDB case
121 @Test(groups ={ "Functional" })
122 public void testParseToDbRef()
124 SequenceI seq = new Sequence("Seq1", "ABCD");
125 DBRefEntry ref = DBRefUtils.parseToDbRef(seq, "EMBL", "1.2", "a7890");
126 DBRefEntry[] refs = seq.getDBRef();
127 assertEquals(1, refs.length);
128 assertSame(ref, refs[0]);
129 assertEquals("EMBL", ref.getSource());
130 assertEquals("1.2", ref.getVersion());
131 assertEquals("a7890", ref.getAccessionId());
132 assertNull(seq.getAllPDBEntries());
136 * Test 'parsing' a DBRef - Stockholm PDB format
138 @Test(groups ={ "Functional" })
139 public void testParseToDbRef_PDB()
141 SequenceI seq = new Sequence("Seq1", "ABCD");
142 DBRefEntry ref = DBRefUtils.parseToDbRef(seq, "pdb", "1.2",
144 DBRefEntry[] refs = seq.getDBRef();
145 assertEquals(1, refs.length);
146 assertSame(ref, refs[0]);
147 assertEquals("PDB", ref.getSource());
148 assertEquals("1.2", ref.getVersion());
149 // DBRef id is pdbId + chain code
150 assertEquals("1WRIA", ref.getAccessionId());
151 assertEquals(1, seq.getAllPDBEntries().size());
152 PDBEntry pdbRef = seq.getAllPDBEntries().get(0);
153 assertEquals("1WRI", pdbRef.getId());
154 assertNull(pdbRef.getFile());
155 assertEquals("A", pdbRef.getChainCode());
156 assertEquals("PDB", pdbRef.getType());
160 * Test the method that searches for matches references - case when we are
161 * matching a reference with no mappings
163 @Test(groups ={ "Functional" })
164 public void testSearchRefs_noMapping()
166 DBRefEntry target = new DBRefEntry("EMBL", "2", "A1234");
168 DBRefEntry ref1 = new DBRefEntry("EMBL", "1", "A1234"); // matches
169 // constructor changes embl to EMBL
170 DBRefEntry ref2 = new DBRefEntry("embl", "1", "A1234"); // matches
171 // constructor does not upper-case accession id
172 DBRefEntry ref3 = new DBRefEntry("EMBL", "1", "a1234"); // no match
173 DBRefEntry ref4 = new DBRefEntry("EMBLCDS", "1", "A1234"); // no match
174 // ref5 matches although it has a mapping - ignored
175 DBRefEntry ref5 = new DBRefEntry("EMBL", "1", "A1234");
176 ref5.setMap(new Mapping(new MapList(new int[]
180 DBRefEntry[] matches = DBRefUtils.searchRefs(new DBRefEntry[]
181 { ref1, ref2, ref3, ref4, ref5 }, target);
182 assertEquals(3, matches.length);
183 assertSame(ref1, matches[0]);
184 assertSame(ref2, matches[1]);
185 assertSame(ref5, matches[2]);
189 * Test the method that searches for matches references - case when we are
190 * matching a reference with a mapping
192 @Test(groups ={ "Functional" })
193 public void testSearchRefs_withMapping()
195 DBRefEntry target = new DBRefEntry("EMBL", "2", "A1234");
196 final Mapping map1 = new Mapping(new MapList(new int[]
201 // these all match target iff mappings match
202 DBRefEntry ref1 = new DBRefEntry("EMBL", "1", "A1234"); // no map: matches
203 DBRefEntry ref2 = new DBRefEntry("EMBL", "1", "A1234"); // =map: matches
204 final Mapping map2 = new Mapping(new MapList(new int[]
209 // different map: no match
210 DBRefEntry ref3 = new DBRefEntry("EMBL", "1", "A1234");
211 final Mapping map3 = new Mapping(new MapList(new int[]
216 DBRefEntry[] matches = DBRefUtils.searchRefs(new DBRefEntry[]
217 { ref1, ref2, ref3 }, target);
218 assertEquals(2, matches.length);
219 assertSame(ref1, matches[0]);
220 assertSame(ref2, matches[1]);