1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.util; |
22 |
|
|
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; |
28 |
|
|
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; |
35 |
|
import jalview.gui.JvOptionPane; |
36 |
|
|
37 |
|
import java.util.List; |
38 |
|
|
39 |
|
import org.testng.annotations.BeforeClass; |
40 |
|
import org.testng.annotations.Test; |
41 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (140) |
Complexity: 10 |
Complexity Density: 0.08 |
|
42 |
|
public class DBRefUtilsTest |
43 |
|
{ |
44 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
45 |
1 |
@BeforeClass(alwaysRun = true)... |
46 |
|
public void setUpJvOptionPane() |
47 |
|
{ |
48 |
1 |
JvOptionPane.setInteractiveMode(false); |
49 |
1 |
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
50 |
|
} |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (30) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
56 |
1 |
@Test(groups = { "Functional" })... |
57 |
|
public void testSelectRefs() |
58 |
|
{ |
59 |
1 |
assertNull(DBRefUtils.selectRefs(null, null)); |
60 |
1 |
assertNull(DBRefUtils.selectRefs(null, DBRefSource.CODINGDBS)); |
61 |
|
|
62 |
1 |
DBRefEntry ref1 = new DBRefEntry("EMBL", "1.2", "A12345"); |
63 |
1 |
DBRefEntry ref2 = new DBRefEntry("UNIPROT", "1.2", "A12346"); |
64 |
|
|
65 |
1 |
DBRefEntry ref3 = new DBRefEntry("Uniprot", "1.2", "A12347"); |
66 |
1 |
DBRefEntry[] dbrefs = new DBRefEntry[] { ref1, ref2, ref3 }; |
67 |
1 |
String[] sources = new String[] { "EMBL", "UNIPROT" }; |
68 |
|
|
69 |
1 |
DBRefEntry[] selected = DBRefUtils.selectRefs(dbrefs, sources); |
70 |
1 |
assertEquals(3, selected.length); |
71 |
1 |
assertSame(ref1, selected[0]); |
72 |
1 |
assertSame(ref2, selected[1]); |
73 |
1 |
assertSame(ref3, selected[2]); |
74 |
|
|
75 |
1 |
sources = new String[] { "EMBL" }; |
76 |
1 |
selected = DBRefUtils.selectRefs(dbrefs, sources); |
77 |
1 |
assertEquals(1, selected.length); |
78 |
1 |
assertSame(ref1, selected[0]); |
79 |
|
|
80 |
1 |
sources = new String[] { "UNIPROT" }; |
81 |
1 |
selected = DBRefUtils.selectRefs(dbrefs, sources); |
82 |
1 |
assertEquals(2, selected.length); |
83 |
1 |
assertSame(ref2, selected[0]); |
84 |
1 |
assertSame(ref3, selected[1]); |
85 |
|
|
86 |
1 |
sources = new String[] { "EMBLCDS" }; |
87 |
1 |
selected = DBRefUtils.selectRefs(dbrefs, sources); |
88 |
1 |
assertNull(selected); |
89 |
|
|
90 |
1 |
sources = new String[] { "embl", "uniprot" }; |
91 |
1 |
selected = DBRefUtils.selectRefs(dbrefs, sources); |
92 |
1 |
assertEquals(3, selected.length); |
93 |
1 |
assertSame(ref1, selected[0]); |
94 |
1 |
assertSame(ref2, selected[1]); |
95 |
1 |
assertSame(ref3, selected[2]); |
96 |
|
} |
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
102 |
1 |
@Test(groups = { "Functional" })... |
103 |
|
public void testGetCanonicalName() |
104 |
|
{ |
105 |
1 |
assertNull(DBRefUtils.getCanonicalName(null)); |
106 |
1 |
assertEquals("", DBRefUtils.getCanonicalName("")); |
107 |
1 |
assertEquals("PDB", DBRefUtils.getCanonicalName("pdb")); |
108 |
1 |
assertEquals("PDB", DBRefUtils.getCanonicalName("Pdb")); |
109 |
1 |
assertEquals("UNIPROT", |
110 |
|
DBRefUtils.getCanonicalName("uniprotkb/swiss-prot")); |
111 |
1 |
assertEquals("UNIPROT", DBRefUtils.getCanonicalName("uniprotkb/trembl")); |
112 |
1 |
assertEquals("UNIPROT", |
113 |
|
DBRefUtils.getCanonicalName("UNIPROTKB/SWISS-PROT")); |
114 |
1 |
assertEquals("UNIPROT", DBRefUtils.getCanonicalName("UNIPROTKB/TREMBL")); |
115 |
1 |
assertEquals("UNIPROTKB/SWISS-CHEESE", |
116 |
|
DBRefUtils.getCanonicalName("UNIPROTKB/SWISS-CHEESE")); |
117 |
1 |
assertEquals("ENSEMBL", DBRefUtils.getCanonicalName("Ensembl")); |
118 |
|
|
119 |
|
|
120 |
1 |
assertEquals("PFAM", DBRefUtils.getCanonicalName("PFAM")); |
121 |
1 |
assertEquals("pfam", DBRefUtils.getCanonicalName("pfam")); |
122 |
|
|
123 |
|
} |
124 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
125 |
1 |
@Test(groups = { "Functional" })... |
126 |
|
public void testIsDasCoordinateSystem() |
127 |
|
{ |
128 |
1 |
assertFalse(DBRefUtils.isDasCoordinateSystem(null, null)); |
129 |
1 |
assertFalse(DBRefUtils.isDasCoordinateSystem("pdbresnum", null)); |
130 |
1 |
assertFalse(DBRefUtils.isDasCoordinateSystem(null, new DBRefEntry( |
131 |
|
"PDB", "v1", "a1"))); |
132 |
|
|
133 |
1 |
assertTrue(DBRefUtils.isDasCoordinateSystem("pdbresnum", |
134 |
|
new DBRefEntry("PDB", "v1", "a1"))); |
135 |
1 |
assertTrue(DBRefUtils.isDasCoordinateSystem("PDBRESNUM", |
136 |
|
new DBRefEntry("PDB", "v1", "a1"))); |
137 |
|
|
138 |
1 |
assertTrue(DBRefUtils.isDasCoordinateSystem("pdbresnum", |
139 |
|
new DBRefEntry("pdb", "v1", "a1"))); |
140 |
1 |
assertFalse(DBRefUtils.isDasCoordinateSystem("pdb", new DBRefEntry( |
141 |
|
"pdb", "v1", "a1"))); |
142 |
|
|
143 |
1 |
assertTrue(DBRefUtils.isDasCoordinateSystem("UNIPROT", new DBRefEntry( |
144 |
|
"Uniprot", "v1", "a1"))); |
145 |
1 |
assertTrue(DBRefUtils.isDasCoordinateSystem("Uniprot", new DBRefEntry( |
146 |
|
"UNIPROT", "v1", "a1"))); |
147 |
1 |
assertFalse(DBRefUtils.isDasCoordinateSystem("UNIPROTKB", |
148 |
|
new DBRefEntry("pdb", "v1", "a1"))); |
149 |
|
|
150 |
1 |
assertTrue(DBRefUtils.isDasCoordinateSystem("EMBL", new DBRefEntry( |
151 |
|
"EMBL", "v1", "a1"))); |
152 |
1 |
assertTrue(DBRefUtils.isDasCoordinateSystem("embl", new DBRefEntry( |
153 |
|
"embl", "v1", "a1"))); |
154 |
|
} |
155 |
|
|
156 |
|
|
157 |
|
|
158 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
159 |
1 |
@Test(groups = { "Functional" })... |
160 |
|
public void testParseToDbRef() |
161 |
|
{ |
162 |
1 |
SequenceI seq = new Sequence("Seq1", "ABCD"); |
163 |
1 |
DBRefEntry ref = DBRefUtils.parseToDbRef(seq, "EMBL", "1.2", "a7890"); |
164 |
1 |
DBRefEntry[] refs = seq.getDBRefs(); |
165 |
1 |
assertEquals(1, refs.length); |
166 |
1 |
assertSame(ref, refs[0]); |
167 |
1 |
assertEquals("EMBL", ref.getSource()); |
168 |
1 |
assertEquals("1.2", ref.getVersion()); |
169 |
1 |
assertEquals("a7890", ref.getAccessionId()); |
170 |
1 |
assertTrue(seq.getAllPDBEntries().isEmpty()); |
171 |
|
} |
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
176 |
1 |
@Test(groups = { "Functional" })... |
177 |
|
public void testParseToDbRef_PDB() |
178 |
|
{ |
179 |
1 |
SequenceI seq = new Sequence("Seq1", "ABCD"); |
180 |
1 |
DBRefEntry ref = DBRefUtils.parseToDbRef(seq, "pdb", "1.2", |
181 |
|
"1WRI A; 7-80;"); |
182 |
|
|
183 |
|
|
184 |
|
|
185 |
1 |
DBRefEntry[] refs = seq.getDBRefs(); |
186 |
1 |
assertEquals(1, refs.length); |
187 |
1 |
assertSame(ref, refs[0]); |
188 |
1 |
assertEquals("PDB", ref.getSource()); |
189 |
1 |
assertEquals("1.2", ref.getVersion()); |
190 |
|
|
191 |
1 |
assertEquals("1WRIA", ref.getAccessionId()); |
192 |
1 |
assertEquals(1, seq.getAllPDBEntries().size()); |
193 |
1 |
PDBEntry pdbRef = seq.getAllPDBEntries().get(0); |
194 |
1 |
assertEquals("1WRI", pdbRef.getId()); |
195 |
1 |
assertNull(pdbRef.getFile()); |
196 |
1 |
assertEquals("A", pdbRef.getChainCode()); |
197 |
1 |
assertEquals("PDB", pdbRef.getType()); |
198 |
|
} |
199 |
|
|
200 |
|
|
201 |
|
|
202 |
|
|
203 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
204 |
1 |
@Test(groups = { "Functional" })... |
205 |
|
public void testSearchRefs_noMapping() |
206 |
|
{ |
207 |
1 |
DBRefEntry target = new DBRefEntry("EMBL", "2", "A1234"); |
208 |
|
|
209 |
1 |
DBRefEntry ref1 = new DBRefEntry("EMBL", "1", "A1234"); |
210 |
|
|
211 |
1 |
DBRefEntry ref2 = new DBRefEntry("embl", "1", "A1234"); |
212 |
|
|
213 |
1 |
DBRefEntry ref3 = new DBRefEntry("EMBL", "1", "a1234"); |
214 |
1 |
DBRefEntry ref4 = new DBRefEntry("EMBLCDS", "1", "A1234"); |
215 |
|
|
216 |
1 |
DBRefEntry ref5 = new DBRefEntry("EMBL", "1", "A1234"); |
217 |
1 |
ref5.setMap(new Mapping(new MapList(new int[] { 1, 1 }, new int[] { 1, |
218 |
|
1 }, 1, 1))); |
219 |
|
|
220 |
1 |
List<DBRefEntry> matches = DBRefUtils.searchRefs(new DBRefEntry[] { |
221 |
|
ref1, ref2, ref3, ref4, ref5 }, target); |
222 |
1 |
assertEquals(3, matches.size()); |
223 |
1 |
assertSame(ref1, matches.get(0)); |
224 |
1 |
assertSame(ref2, matches.get(1)); |
225 |
1 |
assertSame(ref5, matches.get(2)); |
226 |
|
} |
227 |
|
|
228 |
|
|
229 |
|
|
230 |
|
|
231 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
232 |
1 |
@Test(groups = { "Functional" })... |
233 |
|
public void testSearchRefs_withMapping() |
234 |
|
{ |
235 |
1 |
DBRefEntry target = new DBRefEntry("EMBL", "2", "A1234"); |
236 |
1 |
final Mapping map1 = new Mapping(new MapList(new int[] { 1, 1 }, |
237 |
|
new int[] { 1, 1 }, 1, 1)); |
238 |
1 |
target.setMap(map1); |
239 |
|
|
240 |
|
|
241 |
1 |
DBRefEntry ref1 = new DBRefEntry("EMBL", "1", "A1234"); |
242 |
1 |
DBRefEntry ref2 = new DBRefEntry("EMBL", "1", "A1234"); |
243 |
1 |
final Mapping map2 = new Mapping(new MapList(new int[] { 1, 1 }, |
244 |
|
new int[] { 1, 1 }, 1, 1)); |
245 |
1 |
ref2.setMap(map2); |
246 |
|
|
247 |
|
|
248 |
1 |
DBRefEntry ref3 = new DBRefEntry("EMBL", "1", "A1234"); |
249 |
1 |
final Mapping map3 = new Mapping(new MapList(new int[] { 1, 1 }, |
250 |
|
new int[] { 1, 1 }, 2, 2)); |
251 |
1 |
ref3.setMap(map3); |
252 |
|
|
253 |
1 |
List<DBRefEntry> matches = DBRefUtils.searchRefs(new DBRefEntry[] { |
254 |
|
ref1, ref2, ref3 }, target); |
255 |
1 |
assertEquals(2, matches.size()); |
256 |
1 |
assertSame(ref1, matches.get(0)); |
257 |
1 |
assertSame(ref2, matches.get(1)); |
258 |
|
} |
259 |
|
|
260 |
|
|
261 |
|
|
262 |
|
|
263 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
264 |
1 |
@Test(groups = { "Functional" })... |
265 |
|
public void testSearchRefs_accessionid() |
266 |
|
{ |
267 |
|
|
268 |
1 |
DBRefEntry ref1 = new DBRefEntry("Uniprot", "1", "A1234"); |
269 |
1 |
DBRefEntry ref2 = new DBRefEntry("embl", "1", "A1234"); |
270 |
|
|
271 |
1 |
DBRefEntry ref3 = new DBRefEntry("EMBL", "1", "a1234"); |
272 |
1 |
DBRefEntry ref4 = new DBRefEntry("EMBLCDS", "1", "A1235"); |
273 |
|
|
274 |
1 |
DBRefEntry ref5 = new DBRefEntry("EMBL", "1", "A1234"); |
275 |
1 |
ref5.setMap(new Mapping(new MapList(new int[] { 1, 1 }, new int[] { 1, |
276 |
|
1 }, 1, 1))); |
277 |
|
|
278 |
1 |
DBRefEntry[] dbrefs = new DBRefEntry[] { ref1, ref2, ref3, ref4, ref5 }; |
279 |
1 |
List<DBRefEntry> matches = DBRefUtils.searchRefs(dbrefs, "A1234"); |
280 |
1 |
assertEquals(3, matches.size()); |
281 |
1 |
assertSame(ref1, matches.get(0)); |
282 |
1 |
assertSame(ref2, matches.get(1)); |
283 |
1 |
assertSame(ref5, matches.get(2)); |
284 |
|
} |
285 |
|
|
286 |
|
|
287 |
|
|
288 |
|
|
289 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
290 |
1 |
@Test(groups = { "Functional" })... |
291 |
|
public void testSearchRefs_wildcardAccessionid() |
292 |
|
{ |
293 |
1 |
DBRefEntry target = new DBRefEntry("EMBL", "2", null); |
294 |
|
|
295 |
1 |
DBRefEntry ref1 = new DBRefEntry("EMBL", "1", "A1234"); |
296 |
|
|
297 |
1 |
DBRefEntry ref2 = new DBRefEntry("embl", "1", "A1235"); |
298 |
|
|
299 |
1 |
DBRefEntry ref3 = new DBRefEntry("EMBL", "1", "A1236"); |
300 |
1 |
DBRefEntry ref4 = new DBRefEntry("EMBLCDS", "1", "A1234"); |
301 |
|
|
302 |
1 |
DBRefEntry ref5 = new DBRefEntry("EMBL", "1", "A1237"); |
303 |
1 |
ref5.setMap(new Mapping(new MapList(new int[] { 1, 1 }, new int[] { 1, |
304 |
|
1 }, 1, 1))); |
305 |
|
|
306 |
1 |
List<DBRefEntry> matches = DBRefUtils.searchRefs(new DBRefEntry[] { |
307 |
|
ref1, ref2, ref3, ref4, ref5 }, target); |
308 |
1 |
assertEquals(4, matches.size()); |
309 |
1 |
assertSame(ref1, matches.get(0)); |
310 |
1 |
assertSame(ref2, matches.get(1)); |
311 |
1 |
assertSame(ref3, matches.get(2)); |
312 |
1 |
assertSame(ref5, matches.get(3)); |
313 |
|
} |
314 |
|
} |