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.asList(new DBRefEntry[] { ref1, ref2, ref3 }); |
67 |
1 |
String[] sources = new String[] { "EMBL", "UNIPROT" }; |
68 |
|
|
69 |
1 |
List<DBRefEntry> selected = DBRefUtils.selectRefs(dbrefs, sources); |
70 |
1 |
assertEquals(3, selected.size()); |
71 |
1 |
assertSame(ref1, selected.get(0)); |
72 |
1 |
assertSame(ref2, selected.get(1)); |
73 |
1 |
assertSame(ref3, selected.get(2)); |
74 |
|
|
75 |
1 |
sources = new String[] { "EMBL" }; |
76 |
1 |
selected = DBRefUtils.selectRefs(dbrefs, sources); |
77 |
1 |
assertEquals(1, selected.size()); |
78 |
1 |
assertSame(ref1, selected.get(0)); |
79 |
|
|
80 |
1 |
sources = new String[] { "UNIPROT" }; |
81 |
1 |
selected = DBRefUtils.selectRefs(dbrefs, sources); |
82 |
1 |
assertEquals(2, selected.size()); |
83 |
1 |
assertSame(ref2, selected.get(0)); |
84 |
1 |
assertSame(ref3, selected.get(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.size()); |
93 |
1 |
assertSame(ref1, selected.get(0)); |
94 |
1 |
assertSame(ref2, selected.get(1)); |
95 |
1 |
assertSame(ref3, selected.get(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 |
|
|
125 |
|
|
126 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
127 |
1 |
@Test(groups = { "Functional" })... |
128 |
|
public void testParseToDbRef() |
129 |
|
{ |
130 |
1 |
SequenceI seq = new Sequence("Seq1", "ABCD"); |
131 |
1 |
DBRefEntry ref = DBRefUtils.parseToDbRef(seq, "EMBL", "1.2", "a7890"); |
132 |
1 |
List<DBRefEntry> refs = seq.getDBRefs(); |
133 |
1 |
assertEquals(1, refs.size()); |
134 |
1 |
assertSame(ref, refs.get(0)); |
135 |
1 |
assertEquals("EMBL", ref.getSource()); |
136 |
1 |
assertEquals("1.2", ref.getVersion()); |
137 |
1 |
assertEquals("a7890", ref.getAccessionId()); |
138 |
1 |
assertTrue(seq.getAllPDBEntries().isEmpty()); |
139 |
1 |
SequenceI seq2 = new Sequence("Seq2", "ABCD"); |
140 |
|
|
141 |
1 |
DBRefEntry ref2 = DBRefUtils.parseToDbRef(seq2, "EMBL", "1.2", |
142 |
|
" a7890"); |
143 |
1 |
assertEquals(ref, ref2); |
144 |
|
} |
145 |
|
|
146 |
|
|
147 |
|
|
148 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
149 |
1 |
@Test(groups = { "Functional" })... |
150 |
|
public void testParseToDbRef_PDB() |
151 |
|
{ |
152 |
1 |
SequenceI seq = new Sequence("Seq1", "ABCD"); |
153 |
1 |
DBRefEntry ref = DBRefUtils.parseToDbRef(seq, "pdb", "1.2", |
154 |
|
"1WRI A; 7-80;"); |
155 |
|
|
156 |
|
|
157 |
|
|
158 |
1 |
List<DBRefEntry> refs = seq.getDBRefs(); |
159 |
1 |
assertEquals(1, refs.size()); |
160 |
1 |
assertSame(ref, refs.get(0)); |
161 |
1 |
assertEquals("PDB", ref.getSource()); |
162 |
1 |
assertEquals("1.2", ref.getVersion()); |
163 |
|
|
164 |
1 |
assertEquals("1WRIA", ref.getAccessionId()); |
165 |
1 |
assertEquals(1, seq.getAllPDBEntries().size()); |
166 |
1 |
PDBEntry pdbRef = seq.getAllPDBEntries().get(0); |
167 |
1 |
assertEquals("1WRI", pdbRef.getId()); |
168 |
1 |
assertNull(pdbRef.getFile()); |
169 |
1 |
assertEquals("A", pdbRef.getChainCode()); |
170 |
1 |
assertEquals("PDB", pdbRef.getType()); |
171 |
|
} |
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
177 |
1 |
@Test(groups = { "Functional" })... |
178 |
|
public void testSearchRefs_noMapping() |
179 |
|
{ |
180 |
1 |
DBRefEntry target = new DBRefEntry("EMBL", "2", "A1234"); |
181 |
|
|
182 |
1 |
DBRefEntry ref1 = new DBRefEntry("EMBL", "1", "A1234"); |
183 |
|
|
184 |
1 |
DBRefEntry ref2 = new DBRefEntry("embl", "1", "A1234"); |
185 |
|
|
186 |
1 |
DBRefEntry ref3 = new DBRefEntry("EMBL", "1", "a1234"); |
187 |
1 |
DBRefEntry ref4 = new DBRefEntry("EMBLCDS", "1", "A1234"); |
188 |
|
|
189 |
1 |
DBRefEntry ref5 = new DBRefEntry("EMBL", "1", "A1234"); |
190 |
1 |
ref5.setMap(new Mapping(new MapList(new int[] { 1, 1 }, new int[] { 1, |
191 |
|
1 }, 1, 1))); |
192 |
|
|
193 |
1 |
List<DBRefEntry> matches = DBRefUtils.searchRefs( |
194 |
|
Arrays.asList(new DBRefEntry[] { |
195 |
|
ref1, ref2, ref3, ref4, ref5 }), target, DBRefUtils.SEARCH_MODE_FULL); |
196 |
1 |
assertEquals(3, matches.size()); |
197 |
1 |
assertSame(ref1, matches.get(0)); |
198 |
1 |
assertSame(ref2, matches.get(1)); |
199 |
1 |
assertSame(ref5, matches.get(2)); |
200 |
|
} |
201 |
|
|
202 |
|
|
203 |
|
|
204 |
|
|
205 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
206 |
1 |
@Test(groups = { "Functional" })... |
207 |
|
public void testSearchRefs_withMapping() |
208 |
|
{ |
209 |
1 |
DBRefEntry target = new DBRefEntry("EMBL", "2", "A1234"); |
210 |
1 |
final Mapping map1 = new Mapping(new MapList(new int[] { 1, 1 }, |
211 |
|
new int[] { 1, 1 }, 1, 1)); |
212 |
1 |
target.setMap(map1); |
213 |
|
|
214 |
|
|
215 |
1 |
DBRefEntry ref1 = new DBRefEntry("EMBL", "1", "A1234"); |
216 |
1 |
DBRefEntry ref2 = new DBRefEntry("EMBL", "1", "A1234"); |
217 |
1 |
final Mapping map2 = new Mapping(new MapList(new int[] { 1, 1 }, |
218 |
|
new int[] { 1, 1 }, 1, 1)); |
219 |
1 |
ref2.setMap(map2); |
220 |
|
|
221 |
|
|
222 |
1 |
DBRefEntry ref3 = new DBRefEntry("EMBL", "1", "A1234"); |
223 |
1 |
final Mapping map3 = new Mapping(new MapList(new int[] { 1, 1 }, |
224 |
|
new int[] { 1, 1 }, 2, 2)); |
225 |
1 |
ref3.setMap(map3); |
226 |
|
|
227 |
1 |
List<DBRefEntry> matches = DBRefUtils.searchRefs( |
228 |
|
Arrays.asList(new DBRefEntry[] { |
229 |
|
ref1, ref2, ref3 }), target, DBRefUtils.SEARCH_MODE_FULL); |
230 |
1 |
assertEquals(2, matches.size()); |
231 |
1 |
assertSame(ref1, matches.get(0)); |
232 |
1 |
assertSame(ref2, matches.get(1)); |
233 |
|
} |
234 |
|
|
235 |
|
|
236 |
|
|
237 |
|
|
238 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
239 |
1 |
@Test(groups = { "Functional" })... |
240 |
|
public void testSearchRefs_accessionid() |
241 |
|
{ |
242 |
|
|
243 |
1 |
DBRefEntry ref1 = new DBRefEntry("Uniprot", "1", "A1234"); |
244 |
1 |
DBRefEntry ref2 = new DBRefEntry("embl", "1", "A1234"); |
245 |
|
|
246 |
1 |
DBRefEntry ref3 = new DBRefEntry("EMBL", "1", "a1234"); |
247 |
1 |
DBRefEntry ref4 = new DBRefEntry("EMBLCDS", "1", "A1235"); |
248 |
|
|
249 |
1 |
DBRefEntry ref5 = new DBRefEntry("EMBL", "1", "A1234"); |
250 |
1 |
ref5.setMap(new Mapping(new MapList(new int[] { 1, 1 }, new int[] { 1, |
251 |
|
1 }, 1, 1))); |
252 |
|
|
253 |
1 |
List<DBRefEntry> dbrefs = Arrays.asList(new DBRefEntry[] { |
254 |
|
ref1, ref2, ref3, ref4, ref5 }); |
255 |
1 |
List<DBRefEntry> matches = DBRefUtils.searchRefs(dbrefs, "A1234"); |
256 |
1 |
assertEquals(3, matches.size()); |
257 |
1 |
assertSame(ref1, matches.get(0)); |
258 |
1 |
assertSame(ref2, matches.get(1)); |
259 |
1 |
assertSame(ref5, matches.get(2)); |
260 |
|
} |
261 |
|
|
262 |
|
|
263 |
|
|
264 |
|
|
265 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
266 |
1 |
@Test(groups = { "Functional" })... |
267 |
|
public void testSearchRefs_wildcardAccessionid() |
268 |
|
{ |
269 |
1 |
DBRefEntry target = new DBRefEntry("EMBL", "2", null); |
270 |
|
|
271 |
1 |
DBRefEntry ref1 = new DBRefEntry("EMBL", "1", "A1234"); |
272 |
|
|
273 |
1 |
DBRefEntry ref2 = new DBRefEntry("embl", "1", "A1235"); |
274 |
|
|
275 |
1 |
DBRefEntry ref3 = new DBRefEntry("EMBL", "1", "A1236"); |
276 |
1 |
DBRefEntry ref4 = new DBRefEntry("EMBLCDS", "1", "A1234"); |
277 |
|
|
278 |
1 |
DBRefEntry ref5 = new DBRefEntry("EMBL", "1", "A1237"); |
279 |
1 |
ref5.setMap(new Mapping(new MapList(new int[] { 1, 1 }, new int[] { 1, |
280 |
|
1 }, 1, 1))); |
281 |
|
|
282 |
1 |
List<DBRefEntry> matches = DBRefUtils.searchRefs( |
283 |
|
Arrays.asList(new DBRefEntry[] { |
284 |
|
ref1, ref2, ref3, ref4, ref5 }), target, DBRefUtils.SEARCH_MODE_FULL); |
285 |
1 |
assertEquals(4, matches.size()); |
286 |
1 |
assertSame(ref1, matches.get(0)); |
287 |
1 |
assertSame(ref2, matches.get(1)); |
288 |
1 |
assertSame(ref3, matches.get(2)); |
289 |
1 |
assertSame(ref5, matches.get(3)); |
290 |
|
} |
291 |
|
} |