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 testIsProtein()
72 assertTrue(new Sequence("prot","ASDFASDFASDF").isProtein());
74 assertFalse(new Sequence("prot","ACGTACGTACGT").isProtein());
76 SequenceI sq = new Sequence("prot","ACGUACGUACGU");
77 assertFalse(sq.isProtein());
78 // change sequence, should trigger an update of cached result
79 sq.setSequence("ASDFASDFADSF");
80 assertTrue(sq.isProtein());
82 @Test(groups = { "Functional" })
83 public void testGetAnnotation()
85 // initial state returns null not an empty array
86 assertNull(seq.getAnnotation());
87 AlignmentAnnotation ann = addAnnotation("label1", "desc1", "calcId1",
89 AlignmentAnnotation[] anns = seq.getAnnotation();
90 assertEquals(1, anns.length);
91 assertSame(ann, anns[0]);
93 // removing all annotations reverts array to null
94 seq.removeAlignmentAnnotation(ann);
95 assertNull(seq.getAnnotation());
98 @Test(groups = { "Functional" })
99 public void testGetAnnotation_forLabel()
101 AlignmentAnnotation ann1 = addAnnotation("label1", "desc1", "calcId1",
103 AlignmentAnnotation ann2 = addAnnotation("label2", "desc2", "calcId2",
105 AlignmentAnnotation ann3 = addAnnotation("label1", "desc3", "calcId3",
107 AlignmentAnnotation[] anns = seq.getAnnotation("label1");
108 assertEquals(2, anns.length);
109 assertSame(ann1, anns[0]);
110 assertSame(ann3, anns[1]);
113 private AlignmentAnnotation addAnnotation(String label,
114 String description, String calcId, float value)
116 final AlignmentAnnotation annotation = new AlignmentAnnotation(label,
118 annotation.setCalcId(calcId);
119 seq.addAlignmentAnnotation(annotation);
123 @Test(groups = { "Functional" })
124 public void testGetAlignmentAnnotations_forCalcIdAndLabel()
126 AlignmentAnnotation ann1 = addAnnotation("label1", "desc1", "calcId1",
128 AlignmentAnnotation ann2 = addAnnotation("label2", "desc2", "calcId2",
130 AlignmentAnnotation ann3 = addAnnotation("label2", "desc3", "calcId3",
132 AlignmentAnnotation ann4 = addAnnotation("label2", "desc3", "calcId2",
134 AlignmentAnnotation ann5 = addAnnotation("label5", "desc3", null, 1f);
135 AlignmentAnnotation ann6 = addAnnotation(null, "desc3", "calcId3", 1f);
136 List<AlignmentAnnotation> anns = seq.getAlignmentAnnotations("calcId2",
138 assertEquals(2, anns.size());
139 assertSame(ann2, anns.get(0));
140 assertSame(ann4, anns.get(1));
142 assertTrue(seq.getAlignmentAnnotations("calcId2", "label3").isEmpty());
143 assertTrue(seq.getAlignmentAnnotations("calcId3", "label5").isEmpty());
144 assertTrue(seq.getAlignmentAnnotations("calcId2", null).isEmpty());
145 assertTrue(seq.getAlignmentAnnotations(null, "label3").isEmpty());
146 assertTrue(seq.getAlignmentAnnotations(null, null).isEmpty());
150 * Tests for addAlignmentAnnotation. Note this method has the side-effect of
151 * setting the sequenceRef on the annotation. Adding the same annotation twice
154 @Test(groups = { "Functional" })
155 public void testAddAlignmentAnnotation()
157 assertNull(seq.getAnnotation());
158 final AlignmentAnnotation annotation = new AlignmentAnnotation("a",
160 assertNull(annotation.sequenceRef);
161 seq.addAlignmentAnnotation(annotation);
162 assertSame(seq, annotation.sequenceRef);
163 AlignmentAnnotation[] anns = seq.getAnnotation();
164 assertEquals(1, anns.length);
165 assertSame(annotation, anns[0]);
167 // re-adding does nothing
168 seq.addAlignmentAnnotation(annotation);
169 anns = seq.getAnnotation();
170 assertEquals(1, anns.length);
171 assertSame(annotation, anns[0]);
173 // an identical but different annotation can be added
174 final AlignmentAnnotation annotation2 = new AlignmentAnnotation("a",
176 seq.addAlignmentAnnotation(annotation2);
177 anns = seq.getAnnotation();
178 assertEquals(2, anns.length);
179 assertSame(annotation, anns[0]);
180 assertSame(annotation2, anns[1]);
183 @Test(groups = { "Functional" })
184 public void testGetStartGetEnd()
186 SequenceI sq = new Sequence("test", "ABCDEF");
187 assertEquals(1, sq.getStart());
188 assertEquals(6, sq.getEnd());
190 sq = new Sequence("test", "--AB-C-DEF--");
191 assertEquals(1, sq.getStart());
192 assertEquals(6, sq.getEnd());
194 sq = new Sequence("test", "----");
195 assertEquals(1, sq.getStart());
196 assertEquals(0, sq.getEnd()); // ??
200 * Tests for the method that returns an alignment column position (base 1) for
201 * a given sequence position (base 1).
203 @Test(groups = { "Functional" })
204 public void testFindIndex()
206 SequenceI sq = new Sequence("test", "ABCDEF");
207 assertEquals(0, sq.findIndex(0));
208 assertEquals(1, sq.findIndex(1));
209 assertEquals(5, sq.findIndex(5));
210 assertEquals(6, sq.findIndex(6));
211 assertEquals(6, sq.findIndex(9));
213 sq = new Sequence("test", "-A--B-C-D-E-F--");
214 assertEquals(2, sq.findIndex(1));
215 assertEquals(5, sq.findIndex(2));
216 assertEquals(7, sq.findIndex(3));
218 // before start returns 0
219 assertEquals(0, sq.findIndex(0));
220 assertEquals(0, sq.findIndex(-1));
222 // beyond end returns last residue column
223 assertEquals(13, sq.findIndex(99));
228 * Tests for the method that returns a dataset sequence position (base 1) for
229 * an aligned column position (base 0).
231 @Test(groups = { "Functional" })
232 public void testFindPosition()
234 SequenceI sq = new Sequence("test", "ABCDEF");
235 assertEquals(1, sq.findPosition(0));
236 assertEquals(6, sq.findPosition(5));
237 // assertEquals(-1, seq.findPosition(6)); // fails
239 sq = new Sequence("test", "AB-C-D--");
240 assertEquals(1, sq.findPosition(0));
241 assertEquals(2, sq.findPosition(1));
242 // gap position 'finds' residue to the right (not the left as per javadoc)
243 assertEquals(3, sq.findPosition(2));
244 assertEquals(3, sq.findPosition(3));
245 assertEquals(4, sq.findPosition(4));
246 assertEquals(4, sq.findPosition(5));
247 // returns 1 more than sequence length if off the end ?!?
248 assertEquals(5, sq.findPosition(6));
249 assertEquals(5, sq.findPosition(7));
251 sq = new Sequence("test", "--AB-C-DEF--");
252 assertEquals(1, sq.findPosition(0));
253 assertEquals(1, sq.findPosition(1));
254 assertEquals(1, sq.findPosition(2));
255 assertEquals(2, sq.findPosition(3));
256 assertEquals(3, sq.findPosition(4));
257 assertEquals(3, sq.findPosition(5));
258 assertEquals(4, sq.findPosition(6));
259 assertEquals(4, sq.findPosition(7));
260 assertEquals(5, sq.findPosition(8));
261 assertEquals(6, sq.findPosition(9));
262 assertEquals(7, sq.findPosition(10));
263 assertEquals(7, sq.findPosition(11));
266 @Test(groups = { "Functional" })
267 public void testDeleteChars()
269 SequenceI sq = new Sequence("test", "ABCDEF");
270 assertEquals(1, sq.getStart());
271 assertEquals(6, sq.getEnd());
272 sq.deleteChars(2, 3);
273 assertEquals("ABDEF", sq.getSequenceAsString());
274 assertEquals(1, sq.getStart());
275 assertEquals(5, sq.getEnd());
277 sq = new Sequence("test", "ABCDEF");
278 sq.deleteChars(0, 2);
279 assertEquals("CDEF", sq.getSequenceAsString());
280 assertEquals(3, sq.getStart());
281 assertEquals(6, sq.getEnd());
284 @Test(groups = { "Functional" })
285 public void testInsertCharAt()
287 // non-static methods:
288 SequenceI sq = new Sequence("test", "ABCDEF");
289 sq.insertCharAt(0, 'z');
290 assertEquals("zABCDEF", sq.getSequenceAsString());
291 sq.insertCharAt(2, 2, 'x');
292 assertEquals("zAxxBCDEF", sq.getSequenceAsString());
294 // for static method see StringUtilsTest
298 * Test the method that returns an array of aligned sequence positions where
299 * the array index is the data sequence position (both base 0).
301 @Test(groups = { "Functional" })
302 public void testGapMap()
304 SequenceI sq = new Sequence("test", "-A--B-CD-E--F-");
305 sq.createDatasetSequence();
306 assertEquals("[1, 4, 6, 7, 9, 12]", Arrays.toString(sq.gapMap()));
310 * Test the method that gets sequence features, either from the sequence or
313 @Test(groups = { "Functional" })
314 public void testGetSequenceFeatures()
316 SequenceI sq = new Sequence("test", "GATCAT");
317 sq.createDatasetSequence();
319 assertNull(sq.getSequenceFeatures());
322 * SequenceFeature on sequence
324 SequenceFeature sf = new SequenceFeature();
325 sq.addSequenceFeature(sf);
326 SequenceFeature[] sfs = sq.getSequenceFeatures();
327 assertEquals(1, sfs.length);
328 assertSame(sf, sfs[0]);
332 * SequenceFeature on sequence and dataset sequence; returns that on
335 * Note JAL-2046: spurious: we have no use case for this at the moment.
336 * This test also buggy - as sf2.equals(sf), no new feature is added
338 SequenceFeature sf2 = new SequenceFeature();
339 sq.getDatasetSequence().addSequenceFeature(sf2);
340 sfs = sq.getSequenceFeatures();
341 assertEquals(1, sfs.length);
342 assertSame(sf, sfs[0]);
345 * SequenceFeature on dataset sequence only
346 * Note JAL-2046: spurious: we have no use case for setting a non-dataset sequence's feature array to null at the moment.
348 sq.setSequenceFeatures(null);
349 assertNull(sq.getDatasetSequence().getSequenceFeatures());
352 * Corrupt case - no SequenceFeature, dataset's dataset is the original
353 * sequence. Test shows no infinite loop results.
355 sq.getDatasetSequence().setSequenceFeatures(null);
357 * is there a usecase for this ? setDatasetSequence should throw an error if
358 * this actually occurs.
360 sq.getDatasetSequence().setDatasetSequence(sq); // loop!
361 assertNull(sq.getSequenceFeatures());
365 * Test the method that returns an array, indexed by sequence position, whose
366 * entries are the residue positions at the sequence position (or to the right
369 @Test(groups = { "Functional" })
370 public void testFindPositionMap()
373 * Note: Javadoc for findPosition says it returns the residue position to
374 * the left of a gapped position; in fact it returns the position to the
375 * right. Also it returns a non-existent residue position for a gap beyond
378 Sequence sq = new Sequence("TestSeq", "AB.C-D E.");
379 int[] map = sq.findPositionMap();
380 assertEquals(Arrays.toString(new int[] { 1, 2, 3, 3, 4, 4, 5, 5, 6 }),
381 Arrays.toString(map));
385 * Test for getSubsequence
387 @Test(groups = { "Functional" })
388 public void testGetSubsequence()
390 SequenceI sq = new Sequence("TestSeq", "ABCDEFG");
391 sq.createDatasetSequence();
393 // positions are base 0, end position is exclusive
394 SequenceI subseq = sq.getSubSequence(2, 4);
396 assertEquals("CD", subseq.getSequenceAsString());
397 // start/end are base 1 positions
398 assertEquals(3, subseq.getStart());
399 assertEquals(4, subseq.getEnd());
400 // subsequence shares the full dataset sequence
401 assertSame(sq.getDatasetSequence(), subseq.getDatasetSequence());
405 * test createDatasetSequence behaves to doc
407 @Test(groups = { "Functional" })
408 public void testCreateDatasetSequence()
410 SequenceI sq = new Sequence("my","ASDASD");
411 assertNull(sq.getDatasetSequence());
412 SequenceI rds = sq.createDatasetSequence();
414 assertNull(rds.getDatasetSequence());
415 assertEquals(sq.getDatasetSequence(), rds);
419 * Test for deriveSequence applied to a sequence with a dataset
421 @Test(groups = { "Functional" })
422 public void testDeriveSequence_existingDataset()
424 Sequence sq = new Sequence("Seq1", "CD");
425 sq.setDatasetSequence(new Sequence("Seq1", "ABCDEF"));
426 sq.getDatasetSequence().addSequenceFeature(
427 new SequenceFeature("", "", 1, 2, 0f, null));
431 sq.setDescription("Test sequence description..");
432 sq.setVamsasId("TestVamsasId");
433 sq.setSourceDBRef(new DBRefEntry("PDB", "version0", "1TST"));
435 sq.addDBRef(new DBRefEntry("PDB", "version1", "1Tst"));
436 sq.addDBRef(new DBRefEntry("PDB", "version2", "2Tst"));
437 sq.addDBRef(new DBRefEntry("PDB", "version3", "3Tst"));
438 sq.addDBRef(new DBRefEntry("PDB", "version4", "4Tst"));
440 sq.addPDBId(new PDBEntry("1PDB", "A", Type.PDB, "filePath/test1"));
441 sq.addPDBId(new PDBEntry("1PDB", "B", Type.PDB, "filePath/test1"));
442 sq.addPDBId(new PDBEntry("2PDB", "A", Type.MMCIF, "filePath/test2"));
443 sq.addPDBId(new PDBEntry("2PDB", "B", Type.MMCIF, "filePath/test2"));
445 sq.getDatasetSequence().addDBRef(
446 new DBRefEntry("PDB", "version1", "1Tst"));
447 sq.getDatasetSequence().addDBRef(
448 new DBRefEntry("PDB", "version2", "2Tst"));
449 sq.getDatasetSequence().addDBRef(
450 new DBRefEntry("PDB", "version3", "3Tst"));
451 sq.getDatasetSequence().addDBRef(
452 new DBRefEntry("PDB", "version4", "4Tst"));
454 sq.getDatasetSequence().addPDBId(
455 new PDBEntry("1PDB", "A", Type.PDB, "filePath/test1"));
456 sq.getDatasetSequence().addPDBId(
457 new PDBEntry("1PDB", "B", Type.PDB, "filePath/test1"));
458 sq.getDatasetSequence().addPDBId(
459 new PDBEntry("2PDB", "A", Type.MMCIF, "filePath/test2"));
460 sq.getDatasetSequence().addPDBId(
461 new PDBEntry("2PDB", "B", Type.MMCIF, "filePath/test2"));
463 ArrayList<Annotation> annotsList = new ArrayList<Annotation>();
464 System.out.println(">>>>>> " + sq.getSequenceAsString().length());
465 annotsList.add(new Annotation("A", "A", 'X', 0.1f));
466 annotsList.add(new Annotation("A", "A", 'X', 0.1f));
467 Annotation[] annots = annotsList.toArray(new Annotation[0]);
468 sq.addAlignmentAnnotation(new AlignmentAnnotation("Test annot",
469 "Test annot description", annots));
470 sq.getDatasetSequence().addAlignmentAnnotation(
471 new AlignmentAnnotation("Test annot", "Test annot description",
473 Assert.assertEquals(sq.getDescription(), "Test sequence description..");
474 Assert.assertEquals(sq.getDBRefs().length, 4);
475 Assert.assertEquals(sq.getAllPDBEntries().size(), 4);
476 Assert.assertNotNull(sq.getAnnotation());
477 Assert.assertEquals(sq.getAnnotation()[0].annotations.length, 2);
478 Assert.assertEquals(sq.getDatasetSequence().getDBRefs().length, 4);
479 Assert.assertEquals(sq.getDatasetSequence().getAllPDBEntries().size(),
481 Assert.assertNotNull(sq.getDatasetSequence().getAnnotation());
483 Sequence derived = (Sequence) sq.deriveSequence();
485 Assert.assertEquals(derived.getDescription(),
486 "Test sequence description..");
487 Assert.assertEquals(derived.getDBRefs().length, 4);
488 Assert.assertEquals(derived.getAllPDBEntries().size(), 4);
489 Assert.assertNotNull(derived.getAnnotation());
490 Assert.assertEquals(derived.getAnnotation()[0].annotations.length, 2);
491 Assert.assertEquals(derived.getDatasetSequence().getDBRefs().length, 4);
492 Assert.assertEquals(derived.getDatasetSequence().getAllPDBEntries()
494 Assert.assertNotNull(derived.getDatasetSequence().getAnnotation());
496 assertEquals("CD", derived.getSequenceAsString());
497 assertSame(sq.getDatasetSequence(), derived.getDatasetSequence());
499 assertNull(sq.sequenceFeatures);
500 assertNull(derived.sequenceFeatures);
501 // derived sequence should access dataset sequence features
502 assertNotNull(sq.getSequenceFeatures());
503 assertArrayEquals(sq.getSequenceFeatures(),
504 derived.getSequenceFeatures());
508 * Test for deriveSequence applied to an ungapped sequence with no dataset
510 @Test(groups = { "Functional" })
511 public void testDeriveSequence_noDatasetUngapped()
513 SequenceI sq = new Sequence("Seq1", "ABCDEF");
514 assertEquals(1, sq.getStart());
515 assertEquals(6, sq.getEnd());
516 SequenceI derived = sq.deriveSequence();
517 assertEquals("ABCDEF", derived.getSequenceAsString());
518 assertEquals("ABCDEF", derived.getDatasetSequence()
519 .getSequenceAsString());
523 * Test for deriveSequence applied to a gapped sequence with no dataset
525 @Test(groups = { "Functional" })
526 public void testDeriveSequence_noDatasetGapped()
528 SequenceI sq = new Sequence("Seq1", "AB-C.D EF");
529 assertEquals(1, sq.getStart());
530 assertEquals(6, sq.getEnd());
531 assertNull(sq.getDatasetSequence());
532 SequenceI derived = sq.deriveSequence();
533 assertEquals("AB-C.D EF", derived.getSequenceAsString());
534 assertEquals("ABCDEF", derived.getDatasetSequence()
535 .getSequenceAsString());
538 @Test(groups = { "Functional" })
539 public void testCopyConstructor_noDataset()
541 SequenceI seq1 = new Sequence("Seq1", "AB-C.D EF");
542 seq1.setDescription("description");
543 seq1.addAlignmentAnnotation(new AlignmentAnnotation("label", "desc",
545 seq1.addSequenceFeature(new SequenceFeature("type", "desc", 22, 33,
547 seq1.addPDBId(new PDBEntry("1A70", "B", Type.PDB, "File"));
548 seq1.addDBRef(new DBRefEntry("EMBL", "1.2", "AZ12345"));
550 SequenceI copy = new Sequence(seq1);
552 assertNull(copy.getDatasetSequence());
554 verifyCopiedSequence(seq1, copy);
556 // copy has a copy of the DBRefEntry
557 // this is murky - DBrefs are only copied for dataset sequences
558 // where the test for 'dataset sequence' is 'dataset is null'
559 // but that doesn't distinguish it from an aligned sequence
560 // which has not yet generated a dataset sequence
561 // NB getDBRef looks inside dataset sequence if not null
562 DBRefEntry[] dbrefs = copy.getDBRefs();
563 assertEquals(1, dbrefs.length);
564 assertFalse(dbrefs[0] == seq1.getDBRefs()[0]);
565 assertTrue(dbrefs[0].equals(seq1.getDBRefs()[0]));
568 @Test(groups = { "Functional" })
569 public void testCopyConstructor_withDataset()
571 SequenceI seq1 = new Sequence("Seq1", "AB-C.D EF");
572 seq1.createDatasetSequence();
573 seq1.setDescription("description");
574 seq1.addAlignmentAnnotation(new AlignmentAnnotation("label", "desc",
576 // JAL-2046 - what is the contract for using a derived sequence's
577 // addSequenceFeature ?
578 seq1.addSequenceFeature(new SequenceFeature("type", "desc", 22, 33,
580 seq1.addPDBId(new PDBEntry("1A70", "B", Type.PDB, "File"));
581 // here we add DBRef to the dataset sequence:
582 seq1.getDatasetSequence().addDBRef(
583 new DBRefEntry("EMBL", "1.2", "AZ12345"));
585 SequenceI copy = new Sequence(seq1);
587 assertNotNull(copy.getDatasetSequence());
588 assertSame(copy.getDatasetSequence(), seq1.getDatasetSequence());
590 verifyCopiedSequence(seq1, copy);
592 // getDBRef looks inside dataset sequence and this is shared,
593 // so holds the same dbref objects
594 DBRefEntry[] dbrefs = copy.getDBRefs();
595 assertEquals(1, dbrefs.length);
596 assertSame(dbrefs[0], seq1.getDBRefs()[0]);
600 * Helper to make assertions about a copied sequence
605 protected void verifyCopiedSequence(SequenceI seq1, SequenceI copy)
607 // verify basic properties:
608 assertEquals(copy.getName(), seq1.getName());
609 assertEquals(copy.getDescription(), seq1.getDescription());
610 assertEquals(copy.getStart(), seq1.getStart());
611 assertEquals(copy.getEnd(), seq1.getEnd());
612 assertEquals(copy.getSequenceAsString(), seq1.getSequenceAsString());
614 // copy has a copy of the annotation:
615 AlignmentAnnotation[] anns = copy.getAnnotation();
616 assertEquals(1, anns.length);
617 assertFalse(anns[0] == seq1.getAnnotation()[0]);
618 assertEquals(anns[0].label, seq1.getAnnotation()[0].label);
619 assertEquals(anns[0].description, seq1.getAnnotation()[0].description);
620 assertEquals(anns[0].score, seq1.getAnnotation()[0].score);
622 // copy has a copy of the sequence feature:
623 SequenceFeature[] sfs = copy.getSequenceFeatures();
624 assertEquals(1, sfs.length);
625 if (seq1.getDatasetSequence()!=null && copy.getDatasetSequence()==seq1.getDatasetSequence()) {
626 assertTrue(sfs[0] == seq1.getSequenceFeatures()[0]);
628 assertFalse(sfs[0] == seq1.getSequenceFeatures()[0]);
630 assertTrue(sfs[0].equals(seq1.getSequenceFeatures()[0]));
632 // copy has a copy of the PDB entry
633 Vector<PDBEntry> pdbs = copy.getAllPDBEntries();
634 assertEquals(1, pdbs.size());
635 assertFalse(pdbs.get(0) == seq1.getAllPDBEntries().get(0));
636 assertTrue(pdbs.get(0).equals(seq1.getAllPDBEntries().get(0)));
639 @Test(groups = "Functional")
640 public void testGetCharAt()
642 SequenceI sq = new Sequence("", "abcde");
643 assertEquals('a', sq.getCharAt(0));
644 assertEquals('e', sq.getCharAt(4));
645 assertEquals(' ', sq.getCharAt(5));
646 assertEquals(' ', sq.getCharAt(-1));
650 * Tests for adding (or updating) dbrefs
652 * @see DBRefEntry#updateFrom(DBRefEntry)
654 @Test(groups = { "Functional" })
655 public void testAddDBRef()
657 SequenceI sq = new Sequence("", "abcde");
658 assertNull(sq.getDBRefs());
659 DBRefEntry dbref = new DBRefEntry("Uniprot", "1", "P00340");
661 assertEquals(1, sq.getDBRefs().length);
662 assertSame(dbref, sq.getDBRefs()[0]);
665 * change of version - new entry
667 DBRefEntry dbref2 = new DBRefEntry("Uniprot", "2", "P00340");
669 assertEquals(2, sq.getDBRefs().length);
670 assertSame(dbref, sq.getDBRefs()[0]);
671 assertSame(dbref2, sq.getDBRefs()[1]);
674 * matches existing entry - not added
676 sq.addDBRef(new DBRefEntry("UNIPROT", "1", "p00340"));
677 assertEquals(2, sq.getDBRefs().length);
680 * different source = new entry
682 DBRefEntry dbref3 = new DBRefEntry("UniRef", "1", "p00340");
684 assertEquals(3, sq.getDBRefs().length);
685 assertSame(dbref3, sq.getDBRefs()[2]);
688 * different ref = new entry
690 DBRefEntry dbref4 = new DBRefEntry("UniRef", "1", "p00341");
692 assertEquals(4, sq.getDBRefs().length);
693 assertSame(dbref4, sq.getDBRefs()[3]);
696 * matching ref with a mapping - map updated
698 DBRefEntry dbref5 = new DBRefEntry("UniRef", "1", "p00341");
699 Mapping map = new Mapping(new MapList(new int[] { 1, 3 }, new int[] {
703 assertEquals(4, sq.getDBRefs().length);
704 assertSame(dbref4, sq.getDBRefs()[3]);
705 assertSame(map, dbref4.getMap());
708 * 'real' version replaces "0" version
710 dbref2.setVersion("0");
711 DBRefEntry dbref6 = new DBRefEntry(dbref2.getSource(), "3",
712 dbref2.getAccessionId());
714 assertEquals(4, sq.getDBRefs().length);
715 assertSame(dbref2, sq.getDBRefs()[1]);
716 assertEquals("3", dbref2.getVersion());
719 * 'real' version replaces "source:0" version
721 dbref3.setVersion("Uniprot:0");
722 DBRefEntry dbref7 = new DBRefEntry(dbref3.getSource(), "3",
723 dbref3.getAccessionId());
725 assertEquals(4, sq.getDBRefs().length);
726 assertSame(dbref3, sq.getDBRefs()[2]);
727 assertEquals("3", dbref2.getVersion());