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.assertNotNull;
26 import static org.testng.AssertJUnit.assertNull;
27 import static org.testng.AssertJUnit.assertSame;
28 import static org.testng.AssertJUnit.assertTrue;
29 import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals;
31 import jalview.datamodel.PDBEntry.Type;
32 import jalview.util.MapList;
34 import java.util.ArrayList;
35 import java.util.Arrays;
36 import java.util.List;
37 import java.util.Vector;
39 import org.testng.Assert;
40 import org.testng.annotations.BeforeMethod;
41 import org.testng.annotations.Test;
43 public class SequenceTest
47 @BeforeMethod(alwaysRun = true)
50 seq = new Sequence("FER1", "AKPNGVL");
53 @Test(groups = { "Functional" })
54 public void testInsertGapsAndGapmaps()
56 SequenceI aseq = seq.deriveSequence();
57 aseq.insertCharAt(2, 3, '-');
58 aseq.insertCharAt(6, 3, '-');
59 assertEquals("Gap insertions not correct", "AK---P---NGVL",
60 aseq.getSequenceAsString());
61 List<int[]> gapInt = aseq.getInsertions();
62 assertEquals("Gap interval 1 start wrong", 2, gapInt.get(0)[0]);
63 assertEquals("Gap interval 1 end wrong", 4, gapInt.get(0)[1]);
64 assertEquals("Gap interval 2 start wrong", 6, gapInt.get(1)[0]);
65 assertEquals("Gap interval 2 end wrong", 8, gapInt.get(1)[1]);
68 @Test(groups = { "Functional" })
69 public void testGetAnnotation()
71 // initial state returns null not an empty array
72 assertNull(seq.getAnnotation());
73 AlignmentAnnotation ann = addAnnotation("label1", "desc1", "calcId1",
75 AlignmentAnnotation[] anns = seq.getAnnotation();
76 assertEquals(1, anns.length);
77 assertSame(ann, anns[0]);
79 // removing all annotations reverts array to null
80 seq.removeAlignmentAnnotation(ann);
81 assertNull(seq.getAnnotation());
84 @Test(groups = { "Functional" })
85 public void testGetAnnotation_forLabel()
87 AlignmentAnnotation ann1 = addAnnotation("label1", "desc1", "calcId1",
89 AlignmentAnnotation ann2 = addAnnotation("label2", "desc2", "calcId2",
91 AlignmentAnnotation ann3 = addAnnotation("label1", "desc3", "calcId3",
93 AlignmentAnnotation[] anns = seq.getAnnotation("label1");
94 assertEquals(2, anns.length);
95 assertSame(ann1, anns[0]);
96 assertSame(ann3, anns[1]);
99 private AlignmentAnnotation addAnnotation(String label,
100 String description, String calcId, float value)
102 final AlignmentAnnotation annotation = new AlignmentAnnotation(label,
104 annotation.setCalcId(calcId);
105 seq.addAlignmentAnnotation(annotation);
109 @Test(groups = { "Functional" })
110 public void testGetAlignmentAnnotations_forCalcIdAndLabel()
112 AlignmentAnnotation ann1 = addAnnotation("label1", "desc1", "calcId1",
114 AlignmentAnnotation ann2 = addAnnotation("label2", "desc2", "calcId2",
116 AlignmentAnnotation ann3 = addAnnotation("label2", "desc3", "calcId3",
118 AlignmentAnnotation ann4 = addAnnotation("label2", "desc3", "calcId2",
120 AlignmentAnnotation ann5 = addAnnotation("label5", "desc3", null, 1f);
121 AlignmentAnnotation ann6 = addAnnotation(null, "desc3", "calcId3", 1f);
122 List<AlignmentAnnotation> anns = seq.getAlignmentAnnotations("calcId2",
124 assertEquals(2, anns.size());
125 assertSame(ann2, anns.get(0));
126 assertSame(ann4, anns.get(1));
128 assertTrue(seq.getAlignmentAnnotations("calcId2", "label3").isEmpty());
129 assertTrue(seq.getAlignmentAnnotations("calcId3", "label5").isEmpty());
130 assertTrue(seq.getAlignmentAnnotations("calcId2", null).isEmpty());
131 assertTrue(seq.getAlignmentAnnotations(null, "label3").isEmpty());
132 assertTrue(seq.getAlignmentAnnotations(null, null).isEmpty());
136 * Tests for addAlignmentAnnotation. Note this method has the side-effect of
137 * setting the sequenceRef on the annotation. Adding the same annotation twice
140 @Test(groups = { "Functional" })
141 public void testAddAlignmentAnnotation()
143 assertNull(seq.getAnnotation());
144 final AlignmentAnnotation annotation = new AlignmentAnnotation("a",
146 assertNull(annotation.sequenceRef);
147 seq.addAlignmentAnnotation(annotation);
148 assertSame(seq, annotation.sequenceRef);
149 AlignmentAnnotation[] anns = seq.getAnnotation();
150 assertEquals(1, anns.length);
151 assertSame(annotation, anns[0]);
153 // re-adding does nothing
154 seq.addAlignmentAnnotation(annotation);
155 anns = seq.getAnnotation();
156 assertEquals(1, anns.length);
157 assertSame(annotation, anns[0]);
159 // an identical but different annotation can be added
160 final AlignmentAnnotation annotation2 = new AlignmentAnnotation("a",
162 seq.addAlignmentAnnotation(annotation2);
163 anns = seq.getAnnotation();
164 assertEquals(2, anns.length);
165 assertSame(annotation, anns[0]);
166 assertSame(annotation2, anns[1]);
169 @Test(groups = { "Functional" })
170 public void testGetStartGetEnd()
172 SequenceI sq = new Sequence("test", "ABCDEF");
173 assertEquals(1, sq.getStart());
174 assertEquals(6, sq.getEnd());
176 sq = new Sequence("test", "--AB-C-DEF--");
177 assertEquals(1, sq.getStart());
178 assertEquals(6, sq.getEnd());
180 sq = new Sequence("test", "----");
181 assertEquals(1, sq.getStart());
182 assertEquals(0, sq.getEnd()); // ??
186 * Tests for the method that returns an alignment column position (base 1) for
187 * a given sequence position (base 1).
189 @Test(groups = { "Functional" })
190 public void testFindIndex()
192 SequenceI sq = new Sequence("test", "ABCDEF");
193 assertEquals(0, sq.findIndex(0));
194 assertEquals(1, sq.findIndex(1));
195 assertEquals(5, sq.findIndex(5));
196 assertEquals(6, sq.findIndex(6));
197 assertEquals(6, sq.findIndex(9));
199 sq = new Sequence("test", "-A--B-C-D-E-F--");
200 assertEquals(2, sq.findIndex(1));
201 assertEquals(5, sq.findIndex(2));
202 assertEquals(7, sq.findIndex(3));
204 // before start returns 0
205 assertEquals(0, sq.findIndex(0));
206 assertEquals(0, sq.findIndex(-1));
208 // beyond end returns last residue column
209 assertEquals(13, sq.findIndex(99));
214 * Tests for the method that returns a dataset sequence position (base 1) for
215 * an aligned column position (base 0).
217 @Test(groups = { "Functional" })
218 public void testFindPosition()
220 SequenceI sq = new Sequence("test", "ABCDEF");
221 assertEquals(1, sq.findPosition(0));
222 assertEquals(6, sq.findPosition(5));
223 // assertEquals(-1, seq.findPosition(6)); // fails
225 sq = new Sequence("test", "AB-C-D--");
226 assertEquals(1, sq.findPosition(0));
227 assertEquals(2, sq.findPosition(1));
228 // gap position 'finds' residue to the right (not the left as per javadoc)
229 assertEquals(3, sq.findPosition(2));
230 assertEquals(3, sq.findPosition(3));
231 assertEquals(4, sq.findPosition(4));
232 assertEquals(4, sq.findPosition(5));
233 // returns 1 more than sequence length if off the end ?!?
234 assertEquals(5, sq.findPosition(6));
235 assertEquals(5, sq.findPosition(7));
237 sq = new Sequence("test", "--AB-C-DEF--");
238 assertEquals(1, sq.findPosition(0));
239 assertEquals(1, sq.findPosition(1));
240 assertEquals(1, sq.findPosition(2));
241 assertEquals(2, sq.findPosition(3));
242 assertEquals(3, sq.findPosition(4));
243 assertEquals(3, sq.findPosition(5));
244 assertEquals(4, sq.findPosition(6));
245 assertEquals(4, sq.findPosition(7));
246 assertEquals(5, sq.findPosition(8));
247 assertEquals(6, sq.findPosition(9));
248 assertEquals(7, sq.findPosition(10));
249 assertEquals(7, sq.findPosition(11));
252 @Test(groups = { "Functional" })
253 public void testDeleteChars()
255 SequenceI sq = new Sequence("test", "ABCDEF");
256 assertEquals(1, sq.getStart());
257 assertEquals(6, sq.getEnd());
258 sq.deleteChars(2, 3);
259 assertEquals("ABDEF", sq.getSequenceAsString());
260 assertEquals(1, sq.getStart());
261 assertEquals(5, sq.getEnd());
263 sq = new Sequence("test", "ABCDEF");
264 sq.deleteChars(0, 2);
265 assertEquals("CDEF", sq.getSequenceAsString());
266 assertEquals(3, sq.getStart());
267 assertEquals(6, sq.getEnd());
270 @Test(groups = { "Functional" })
271 public void testInsertCharAt()
273 // non-static methods:
274 SequenceI sq = new Sequence("test", "ABCDEF");
275 sq.insertCharAt(0, 'z');
276 assertEquals("zABCDEF", sq.getSequenceAsString());
277 sq.insertCharAt(2, 2, 'x');
278 assertEquals("zAxxBCDEF", sq.getSequenceAsString());
280 // for static method see StringUtilsTest
284 * Test the method that returns an array of aligned sequence positions where
285 * the array index is the data sequence position (both base 0).
287 @Test(groups = { "Functional" })
288 public void testGapMap()
290 SequenceI sq = new Sequence("test", "-A--B-CD-E--F-");
291 sq.createDatasetSequence();
292 assertEquals("[1, 4, 6, 7, 9, 12]", Arrays.toString(sq.gapMap()));
296 * Test the method that gets sequence features, either from the sequence or
299 @Test(groups = { "Functional" })
300 public void testGetSequenceFeatures()
302 SequenceI sq = new Sequence("test", "GATCAT");
303 sq.createDatasetSequence();
305 assertNull(sq.getSequenceFeatures());
308 * SequenceFeature on sequence
310 SequenceFeature sf = new SequenceFeature();
311 sq.addSequenceFeature(sf);
312 SequenceFeature[] sfs = sq.getSequenceFeatures();
313 assertEquals(1, sfs.length);
314 assertSame(sf, sfs[0]);
318 * SequenceFeature on sequence and dataset sequence; returns that on
321 * Note JAL-2046: spurious: we have no use case for this at the moment.
322 * This test also buggy - as sf2.equals(sf), no new feature is added
324 SequenceFeature sf2 = new SequenceFeature();
325 sq.getDatasetSequence().addSequenceFeature(sf2);
326 sfs = sq.getSequenceFeatures();
327 assertEquals(1, sfs.length);
328 assertSame(sf, sfs[0]);
331 * SequenceFeature on dataset sequence only
332 * Note JAL-2046: spurious: we have no use case for setting a non-dataset sequence's feature array to null at the moment.
334 sq.setSequenceFeatures(null);
335 assertNull(sq.getDatasetSequence().getSequenceFeatures());
338 * Corrupt case - no SequenceFeature, dataset's dataset is the original
339 * sequence. Test shows no infinite loop results.
341 sq.getDatasetSequence().setSequenceFeatures(null);
343 * is there a usecase for this ? setDatasetSequence should throw an error if
344 * this actually occurs.
346 sq.getDatasetSequence().setDatasetSequence(sq); // loop!
347 assertNull(sq.getSequenceFeatures());
351 * Test the method that returns an array, indexed by sequence position, whose
352 * entries are the residue positions at the sequence position (or to the right
355 @Test(groups = { "Functional" })
356 public void testFindPositionMap()
359 * Note: Javadoc for findPosition says it returns the residue position to
360 * the left of a gapped position; in fact it returns the position to the
361 * right. Also it returns a non-existent residue position for a gap beyond
364 Sequence sq = new Sequence("TestSeq", "AB.C-D E.");
365 int[] map = sq.findPositionMap();
366 assertEquals(Arrays.toString(new int[] { 1, 2, 3, 3, 4, 4, 5, 5, 6 }),
367 Arrays.toString(map));
371 * Test for getSubsequence
373 @Test(groups = { "Functional" })
374 public void testGetSubsequence()
376 SequenceI sq = new Sequence("TestSeq", "ABCDEFG");
377 sq.createDatasetSequence();
379 // positions are base 0, end position is exclusive
380 SequenceI subseq = sq.getSubSequence(2, 4);
382 assertEquals("CD", subseq.getSequenceAsString());
383 // start/end are base 1 positions
384 assertEquals(3, subseq.getStart());
385 assertEquals(4, subseq.getEnd());
386 // subsequence shares the full dataset sequence
387 assertSame(sq.getDatasetSequence(), subseq.getDatasetSequence());
391 * Test for deriveSequence applied to a sequence with a dataset
393 @Test(groups = { "Functional" })
394 public void testDeriveSequence_existingDataset()
396 Sequence sq = new Sequence("Seq1", "CD");
397 sq.setDatasetSequence(new Sequence("Seq1", "ABCDEF"));
398 sq.getDatasetSequence().addSequenceFeature(
399 new SequenceFeature("", "", 1, 2, 0f, null));
403 sq.setDescription("Test sequence description..");
404 sq.setVamsasId("TestVamsasId");
405 sq.setSourceDBRef(new DBRefEntry("PDB", "version0", "1TST"));
407 sq.addDBRef(new DBRefEntry("PDB", "version1", "1Tst"));
408 sq.addDBRef(new DBRefEntry("PDB", "version2", "2Tst"));
409 sq.addDBRef(new DBRefEntry("PDB", "version3", "3Tst"));
410 sq.addDBRef(new DBRefEntry("PDB", "version4", "4Tst"));
412 sq.addPDBId(new PDBEntry("1PDB", "A", Type.PDB, "filePath/test1"));
413 sq.addPDBId(new PDBEntry("1PDB", "B", Type.PDB, "filePath/test1"));
414 sq.addPDBId(new PDBEntry("2PDB", "A", Type.MMCIF, "filePath/test2"));
415 sq.addPDBId(new PDBEntry("2PDB", "B", Type.MMCIF, "filePath/test2"));
417 sq.getDatasetSequence().addDBRef(
418 new DBRefEntry("PDB", "version1", "1Tst"));
419 sq.getDatasetSequence().addDBRef(
420 new DBRefEntry("PDB", "version2", "2Tst"));
421 sq.getDatasetSequence().addDBRef(
422 new DBRefEntry("PDB", "version3", "3Tst"));
423 sq.getDatasetSequence().addDBRef(
424 new DBRefEntry("PDB", "version4", "4Tst"));
426 sq.getDatasetSequence().addPDBId(
427 new PDBEntry("1PDB", "A", Type.PDB, "filePath/test1"));
428 sq.getDatasetSequence().addPDBId(
429 new PDBEntry("1PDB", "B", Type.PDB, "filePath/test1"));
430 sq.getDatasetSequence().addPDBId(
431 new PDBEntry("2PDB", "A", Type.MMCIF, "filePath/test2"));
432 sq.getDatasetSequence().addPDBId(
433 new PDBEntry("2PDB", "B", Type.MMCIF, "filePath/test2"));
435 ArrayList<Annotation> annotsList = new ArrayList<Annotation>();
436 System.out.println(">>>>>> " + sq.getSequenceAsString().length());
437 annotsList.add(new Annotation("A", "A", 'X', 0.1f));
438 annotsList.add(new Annotation("A", "A", 'X', 0.1f));
439 Annotation[] annots = annotsList.toArray(new Annotation[0]);
440 sq.addAlignmentAnnotation(new AlignmentAnnotation("Test annot",
441 "Test annot description", annots));
442 sq.getDatasetSequence().addAlignmentAnnotation(
443 new AlignmentAnnotation("Test annot", "Test annot description",
445 Assert.assertEquals(sq.getDescription(), "Test sequence description..");
446 Assert.assertEquals(sq.getDBRefs().length, 4);
447 Assert.assertEquals(sq.getAllPDBEntries().size(), 4);
448 Assert.assertNotNull(sq.getAnnotation());
449 Assert.assertEquals(sq.getAnnotation()[0].annotations.length, 2);
450 Assert.assertEquals(sq.getDatasetSequence().getDBRefs().length, 4);
451 Assert.assertEquals(sq.getDatasetSequence().getAllPDBEntries().size(),
453 Assert.assertNotNull(sq.getDatasetSequence().getAnnotation());
455 Sequence derived = (Sequence) sq.deriveSequence();
457 Assert.assertEquals(derived.getDescription(),
458 "Test sequence description..");
459 Assert.assertEquals(derived.getDBRefs().length, 4);
460 Assert.assertEquals(derived.getAllPDBEntries().size(), 4);
461 Assert.assertNotNull(derived.getAnnotation());
462 Assert.assertEquals(derived.getAnnotation()[0].annotations.length, 2);
463 Assert.assertEquals(derived.getDatasetSequence().getDBRefs().length, 4);
464 Assert.assertEquals(derived.getDatasetSequence().getAllPDBEntries()
466 Assert.assertNotNull(derived.getDatasetSequence().getAnnotation());
468 assertEquals("CD", derived.getSequenceAsString());
469 assertSame(sq.getDatasetSequence(), derived.getDatasetSequence());
471 assertNull(sq.sequenceFeatures);
472 assertNull(derived.sequenceFeatures);
473 // derived sequence should access dataset sequence features
474 assertNotNull(sq.getSequenceFeatures());
475 assertArrayEquals(sq.getSequenceFeatures(),
476 derived.getSequenceFeatures());
480 * Test for deriveSequence applied to an ungapped sequence with no dataset
482 @Test(groups = { "Functional" })
483 public void testDeriveSequence_noDatasetUngapped()
485 SequenceI sq = new Sequence("Seq1", "ABCDEF");
486 assertEquals(1, sq.getStart());
487 assertEquals(6, sq.getEnd());
488 SequenceI derived = sq.deriveSequence();
489 assertEquals("ABCDEF", derived.getSequenceAsString());
490 assertEquals("ABCDEF", derived.getDatasetSequence()
491 .getSequenceAsString());
495 * Test for deriveSequence applied to a gapped sequence with no dataset
497 @Test(groups = { "Functional" })
498 public void testDeriveSequence_noDatasetGapped()
500 SequenceI sq = new Sequence("Seq1", "AB-C.D EF");
501 assertEquals(1, sq.getStart());
502 assertEquals(6, sq.getEnd());
503 assertNull(sq.getDatasetSequence());
504 SequenceI derived = sq.deriveSequence();
505 assertEquals("AB-C.D EF", derived.getSequenceAsString());
506 assertEquals("ABCDEF", derived.getDatasetSequence()
507 .getSequenceAsString());
510 @Test(groups = { "Functional" })
511 public void testCopyConstructor_noDataset()
513 SequenceI seq1 = new Sequence("Seq1", "AB-C.D EF");
514 seq1.setDescription("description");
515 seq1.addAlignmentAnnotation(new AlignmentAnnotation("label", "desc",
517 seq1.addSequenceFeature(new SequenceFeature("type", "desc", 22, 33,
519 seq1.addPDBId(new PDBEntry("1A70", "B", Type.PDB, "File"));
520 seq1.addDBRef(new DBRefEntry("EMBL", "1.2", "AZ12345"));
522 SequenceI copy = new Sequence(seq1);
524 assertNull(copy.getDatasetSequence());
526 verifyCopiedSequence(seq1, copy);
528 // copy has a copy of the DBRefEntry
529 // this is murky - DBrefs are only copied for dataset sequences
530 // where the test for 'dataset sequence' is 'dataset is null'
531 // but that doesn't distinguish it from an aligned sequence
532 // which has not yet generated a dataset sequence
533 // NB getDBRef looks inside dataset sequence if not null
534 DBRefEntry[] dbrefs = copy.getDBRefs();
535 assertEquals(1, dbrefs.length);
536 assertFalse(dbrefs[0] == seq1.getDBRefs()[0]);
537 assertTrue(dbrefs[0].equals(seq1.getDBRefs()[0]));
540 @Test(groups = { "Functional" })
541 public void testCopyConstructor_withDataset()
543 SequenceI seq1 = new Sequence("Seq1", "AB-C.D EF");
544 seq1.createDatasetSequence();
545 seq1.setDescription("description");
546 seq1.addAlignmentAnnotation(new AlignmentAnnotation("label", "desc",
548 // JAL-2046 - what is the contract for using a derived sequence's
549 // addSequenceFeature ?
550 seq1.addSequenceFeature(new SequenceFeature("type", "desc", 22, 33,
552 seq1.addPDBId(new PDBEntry("1A70", "B", Type.PDB, "File"));
553 // here we add DBRef to the dataset sequence:
554 seq1.getDatasetSequence().addDBRef(
555 new DBRefEntry("EMBL", "1.2", "AZ12345"));
557 SequenceI copy = new Sequence(seq1);
559 assertNotNull(copy.getDatasetSequence());
560 assertSame(copy.getDatasetSequence(), seq1.getDatasetSequence());
562 verifyCopiedSequence(seq1, copy);
564 // getDBRef looks inside dataset sequence and this is shared,
565 // so holds the same dbref objects
566 DBRefEntry[] dbrefs = copy.getDBRefs();
567 assertEquals(1, dbrefs.length);
568 assertSame(dbrefs[0], seq1.getDBRefs()[0]);
572 * Helper to make assertions about a copied sequence
577 protected void verifyCopiedSequence(SequenceI seq1, SequenceI copy)
579 // verify basic properties:
580 assertEquals(copy.getName(), seq1.getName());
581 assertEquals(copy.getDescription(), seq1.getDescription());
582 assertEquals(copy.getStart(), seq1.getStart());
583 assertEquals(copy.getEnd(), seq1.getEnd());
584 assertEquals(copy.getSequenceAsString(), seq1.getSequenceAsString());
586 // copy has a copy of the annotation:
587 AlignmentAnnotation[] anns = copy.getAnnotation();
588 assertEquals(1, anns.length);
589 assertFalse(anns[0] == seq1.getAnnotation()[0]);
590 assertEquals(anns[0].label, seq1.getAnnotation()[0].label);
591 assertEquals(anns[0].description, seq1.getAnnotation()[0].description);
592 assertEquals(anns[0].score, seq1.getAnnotation()[0].score);
594 // copy has a copy of the sequence feature:
595 SequenceFeature[] sfs = copy.getSequenceFeatures();
596 assertEquals(1, sfs.length);
597 if (seq1.getDatasetSequence()!=null && copy.getDatasetSequence()==seq1.getDatasetSequence()) {
598 assertTrue(sfs[0] == seq1.getSequenceFeatures()[0]);
600 assertFalse(sfs[0] == seq1.getSequenceFeatures()[0]);
602 assertTrue(sfs[0].equals(seq1.getSequenceFeatures()[0]));
604 // copy has a copy of the PDB entry
605 Vector<PDBEntry> pdbs = copy.getAllPDBEntries();
606 assertEquals(1, pdbs.size());
607 assertFalse(pdbs.get(0) == seq1.getAllPDBEntries().get(0));
608 assertTrue(pdbs.get(0).equals(seq1.getAllPDBEntries().get(0)));
611 @Test(groups = "Functional")
612 public void testGetCharAt()
614 SequenceI sq = new Sequence("", "abcde");
615 assertEquals('a', sq.getCharAt(0));
616 assertEquals('e', sq.getCharAt(4));
617 assertEquals(' ', sq.getCharAt(5));
618 assertEquals(' ', sq.getCharAt(-1));
622 * Tests for adding (or updating) dbrefs
624 * @see DBRefEntry#updateFrom(DBRefEntry)
626 @Test(groups = { "Functional" })
627 public void testAddDBRef()
629 SequenceI sq = new Sequence("", "abcde");
630 assertNull(sq.getDBRefs());
631 DBRefEntry dbref = new DBRefEntry("Uniprot", "1", "P00340");
633 assertEquals(1, sq.getDBRefs().length);
634 assertSame(dbref, sq.getDBRefs()[0]);
637 * change of version - new entry
639 DBRefEntry dbref2 = new DBRefEntry("Uniprot", "2", "P00340");
641 assertEquals(2, sq.getDBRefs().length);
642 assertSame(dbref, sq.getDBRefs()[0]);
643 assertSame(dbref2, sq.getDBRefs()[1]);
646 * matches existing entry - not added
648 sq.addDBRef(new DBRefEntry("UNIPROT", "1", "p00340"));
649 assertEquals(2, sq.getDBRefs().length);
652 * different source = new entry
654 DBRefEntry dbref3 = new DBRefEntry("UniRef", "1", "p00340");
656 assertEquals(3, sq.getDBRefs().length);
657 assertSame(dbref3, sq.getDBRefs()[2]);
660 * different ref = new entry
662 DBRefEntry dbref4 = new DBRefEntry("UniRef", "1", "p00341");
664 assertEquals(4, sq.getDBRefs().length);
665 assertSame(dbref4, sq.getDBRefs()[3]);
668 * matching ref with a mapping - map updated
670 DBRefEntry dbref5 = new DBRefEntry("UniRef", "1", "p00341");
671 Mapping map = new Mapping(new MapList(new int[] { 1, 3 }, new int[] {
675 assertEquals(4, sq.getDBRefs().length);
676 assertSame(dbref4, sq.getDBRefs()[3]);
677 assertSame(map, dbref4.getMap());
680 * 'real' version replaces "0" version
682 dbref2.setVersion("0");
683 DBRefEntry dbref6 = new DBRefEntry(dbref2.getSource(), "3",
684 dbref2.getAccessionId());
686 assertEquals(4, sq.getDBRefs().length);
687 assertSame(dbref2, sq.getDBRefs()[1]);
688 assertEquals("3", dbref2.getVersion());
691 * 'real' version replaces "source:0" version
693 dbref3.setVersion("Uniprot:0");
694 DBRefEntry dbref7 = new DBRefEntry(dbref3.getSource(), "3",
695 dbref3.getAccessionId());
697 assertEquals(4, sq.getDBRefs().length);
698 assertSame(dbref3, sq.getDBRefs()[2]);
699 assertEquals("3", dbref2.getVersion());