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