2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.datamodel;
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertFalse;
25 import static org.testng.AssertJUnit.assertSame;
26 import static org.testng.AssertJUnit.assertTrue;
28 import jalview.gui.JvOptionPane;
29 import jalview.util.MapList;
31 import org.testng.annotations.BeforeClass;
32 import org.testng.annotations.Test;
34 public class DBRefEntryTest
37 @BeforeClass(alwaysRun = true)
38 public void setUpJvOptionPane()
40 JvOptionPane.setInteractiveMode(false);
41 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
45 * Tests for the method that compares equality of reference (but not mapping)
47 @Test(groups = { "Functional" })
48 public void testEqualRef()
50 DBRefEntry ref1 = new DBRefEntry("UNIPROT", "1", "V71633");
51 assertTrue(ref1.equalRef(ref1));
52 assertFalse(ref1.equalRef(null));
54 // comparison is not case sensitive
55 DBRefEntry ref2 = new DBRefEntry("uniprot", "1", "v71633");
56 assertTrue(ref1.equalRef(ref2));
57 assertTrue(ref2.equalRef(ref1));
59 // source, version and accessionid must match
60 assertFalse(ref1.equalRef(new DBRefEntry("UNIPRO", "1", "V71633")));
61 assertFalse(ref1.equalRef(new DBRefEntry("UNIPROT", "2", "V71633")));
62 assertFalse(ref1.equalRef(new DBRefEntry("UNIPROT", "1", "V71632")));
64 // presence of or differences in mappings are ignored
66 new Mapping(new MapList(new int[]
67 { 1, 3 }, new int[] { 1, 1 }, 3, 1)));
68 assertTrue(ref1.equalRef(ref2));
69 assertTrue(ref2.equalRef(ref1));
71 new Mapping(new MapList(new int[]
72 { 1, 6 }, new int[] { 1, 2 }, 3, 1)));
73 assertTrue(ref1.equalRef(ref2));
74 assertTrue(ref2.equalRef(ref1));
78 * Tests for the method that may update a DBRefEntry from another with a
79 * mapping or 'real' version
81 @Test(groups = { "Functional" })
82 public void testUpdateFrom()
84 DBRefEntry ref1 = new DBRefEntry("UNIPROT", "1", "V71633");
86 assertFalse(ref1.updateFrom(null));
89 * equivalent other dbref
91 DBRefEntry ref2 = new DBRefEntry("uniprot", "1", "v71633");
92 assertTrue(ref1.updateFrom(ref2));
93 assertEquals("UNIPROT", ref1.getSource()); // unchanged
94 assertEquals("V71633", ref1.getAccessionId()); // unchanged
97 * ref1 has no mapping, acquires mapping from ref2
99 Mapping map = new Mapping(
100 new MapList(new int[]
101 { 1, 3 }, new int[] { 1, 1 }, 3, 1));
103 assertTrue(ref1.updateFrom(ref2));
104 assertSame(map, ref1.getMap()); // null mapping updated
107 * ref1 has a mapping, does not acquire mapping from ref2
109 ref2.setMap(new Mapping(map));
110 assertTrue(ref1.updateFrom(ref2));
111 assertSame(map, ref1.getMap()); // non-null mapping not updated
114 * ref2 has a different source, accession or version
116 ref2.setSource("pdb");
117 assertFalse(ref1.updateFrom(ref2));
118 ref2.setSource(ref1.getSource());
119 ref2.setAccessionId("P12345");
120 assertFalse(ref1.updateFrom(ref2));
121 ref2.setAccessionId(ref1.getAccessionId());
122 ref1.setVersion("2");
123 assertFalse(ref1.updateFrom(ref2));
126 * a non-null version supersedes "0" or "source:0"
128 ref2.setVersion(null);
129 assertFalse(ref1.updateFrom(ref2));
130 assertEquals("2", ref1.getVersion());
131 ref2.setVersion("3");
132 ref1.setVersion("0");
133 assertTrue(ref1.updateFrom(ref2));
134 assertEquals("3", ref1.getVersion());
135 ref1.setVersion("UNIPROT:0");
136 assertTrue(ref1.updateFrom(ref2));
137 assertEquals("3", ref1.getVersion());
140 * canonical == false superseded by canonical == true
142 ref1.setCanonical(false);
143 ref2.setCanonical(true);
144 assertTrue(ref1.updateFrom(ref2));
145 assertTrue(ref1.isCanonical());
148 * canonical == true NOT superseded by canonical == false
150 ref1.setCanonical(true);
151 ref2.setCanonical(false);
152 assertFalse(ref1.updateFrom(ref2));
155 * version "source:n" with n>0 is not superseded
157 ref1.setVersion("UNIPROT:1");
158 assertFalse(ref1.updateFrom(ref2));
159 assertEquals("UNIPROT:1", ref1.getVersion());
162 * version "10" is not superseded
164 ref1.setVersion("10");
165 assertFalse(ref1.updateFrom(ref2));
166 assertEquals("10", ref1.getVersion());
169 @Test(groups = { "Functional" })
170 public void testIsPrimaryCandidate()
172 DBRefEntry dbr = new DBRefEntry(DBRefSource.UNIPROT, "", "Q12345");
173 assertTrue(dbr.isPrimaryCandidate());
179 new Mapping(null, new int[]
180 { 1, 3 }, new int[] { 1, 3 }, 1, 1));
181 assertTrue(dbr.isPrimaryCandidate());
184 * 1:1 mapping of identical split ranges - not ok
187 new Mapping(null, new int[]
188 { 1, 3, 6, 9 }, new int[] { 1, 3, 6, 9 }, 1, 1));
189 assertFalse(dbr.isPrimaryCandidate());
192 * 1:1 mapping of different ranges - not ok
195 new Mapping(null, new int[]
196 { 1, 4 }, new int[] { 2, 5 }, 1, 1));
197 assertFalse(dbr.isPrimaryCandidate());
200 * 1:1 mapping of 'isoform' ranges - not ok
203 new Mapping(null, new int[]
204 { 1, 2, 6, 9 }, new int[] { 1, 3, 7, 9 }, 1, 1));
205 assertFalse(dbr.isPrimaryCandidate());
207 assertTrue(dbr.isPrimaryCandidate());
210 * Version string is prefixed with another dbref source string (fail)
212 dbr.setVersion(DBRefSource.EMBL + ":0");
213 assertFalse(dbr.isPrimaryCandidate());
216 * Version string is alphanumeric
218 dbr.setVersion("0.1.b");
219 assertTrue(dbr.isPrimaryCandidate());
222 * null version string can't be primary ref
224 dbr.setVersion(null);
225 assertFalse(dbr.isPrimaryCandidate());
227 assertTrue(dbr.isPrimaryCandidate());
230 * 1:1 mapping and sequenceRef (fail)
233 new Mapping(new Sequence("foo", "ASDF"), new int[]
234 { 1, 3 }, new int[] { 1, 3 }, 1, 1));
235 assertFalse(dbr.isPrimaryCandidate());
241 new Mapping(null, new int[]
242 { 1, 3 }, new int[] { 1, 3 }, 1, 3));
243 assertFalse(dbr.isPrimaryCandidate());
246 * 2:2 mapping with shift (expected fail, but maybe use case for a pass)
249 new Mapping(null, new int[]
250 { 1, 4 }, new int[] { 1, 4 }, 2, 2));
251 assertFalse(dbr.isPrimaryCandidate());