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 * in situ change of sequence doesn't change hashcode :-O
83 * (sequence should not expose internal implementation)
85 for (int i = 0; i < sq.getSequence().length; i++)
87 sq.getSequence()[i] = "acgtu".charAt(i % 5);
89 assertTrue(sq.isProtein()); // but it isn't
92 @Test(groups = { "Functional" })
93 public void testGetAnnotation()
95 // initial state returns null not an empty array
96 assertNull(seq.getAnnotation());
97 AlignmentAnnotation ann = addAnnotation("label1", "desc1", "calcId1",
99 AlignmentAnnotation[] anns = seq.getAnnotation();
100 assertEquals(1, anns.length);
101 assertSame(ann, anns[0]);
103 // removing all annotations reverts array to null
104 seq.removeAlignmentAnnotation(ann);
105 assertNull(seq.getAnnotation());
108 @Test(groups = { "Functional" })
109 public void testGetAnnotation_forLabel()
111 AlignmentAnnotation ann1 = addAnnotation("label1", "desc1", "calcId1",
113 addAnnotation("label2", "desc2", "calcId2", 1f);
114 AlignmentAnnotation ann3 = addAnnotation("label1", "desc3", "calcId3",
116 AlignmentAnnotation[] anns = seq.getAnnotation("label1");
117 assertEquals(2, anns.length);
118 assertSame(ann1, anns[0]);
119 assertSame(ann3, anns[1]);
122 private AlignmentAnnotation addAnnotation(String label,
123 String description, String calcId, float value)
125 final AlignmentAnnotation annotation = new AlignmentAnnotation(label,
127 annotation.setCalcId(calcId);
128 seq.addAlignmentAnnotation(annotation);
132 @Test(groups = { "Functional" })
133 public void testGetAlignmentAnnotations_forCalcIdAndLabel()
135 addAnnotation("label1", "desc1", "calcId1", 1f);
136 AlignmentAnnotation ann2 = addAnnotation("label2", "desc2", "calcId2",
138 addAnnotation("label2", "desc3", "calcId3", 1f);
139 AlignmentAnnotation ann4 = addAnnotation("label2", "desc3", "calcId2",
141 addAnnotation("label5", "desc3", null, 1f);
142 addAnnotation(null, "desc3", "calcId3", 1f);
144 List<AlignmentAnnotation> anns = seq.getAlignmentAnnotations("calcId2",
146 assertEquals(2, anns.size());
147 assertSame(ann2, anns.get(0));
148 assertSame(ann4, anns.get(1));
150 assertTrue(seq.getAlignmentAnnotations("calcId2", "label3").isEmpty());
151 assertTrue(seq.getAlignmentAnnotations("calcId3", "label5").isEmpty());
152 assertTrue(seq.getAlignmentAnnotations("calcId2", null).isEmpty());
153 assertTrue(seq.getAlignmentAnnotations(null, "label3").isEmpty());
154 assertTrue(seq.getAlignmentAnnotations(null, null).isEmpty());
158 * Tests for addAlignmentAnnotation. Note this method has the side-effect of
159 * setting the sequenceRef on the annotation. Adding the same annotation twice
162 @Test(groups = { "Functional" })
163 public void testAddAlignmentAnnotation()
165 assertNull(seq.getAnnotation());
166 final AlignmentAnnotation annotation = new AlignmentAnnotation("a",
168 assertNull(annotation.sequenceRef);
169 seq.addAlignmentAnnotation(annotation);
170 assertSame(seq, annotation.sequenceRef);
171 AlignmentAnnotation[] anns = seq.getAnnotation();
172 assertEquals(1, anns.length);
173 assertSame(annotation, anns[0]);
175 // re-adding does nothing
176 seq.addAlignmentAnnotation(annotation);
177 anns = seq.getAnnotation();
178 assertEquals(1, anns.length);
179 assertSame(annotation, anns[0]);
181 // an identical but different annotation can be added
182 final AlignmentAnnotation annotation2 = new AlignmentAnnotation("a",
184 seq.addAlignmentAnnotation(annotation2);
185 anns = seq.getAnnotation();
186 assertEquals(2, anns.length);
187 assertSame(annotation, anns[0]);
188 assertSame(annotation2, anns[1]);
191 @Test(groups = { "Functional" })
192 public void testGetStartGetEnd()
194 SequenceI sq = new Sequence("test", "ABCDEF");
195 assertEquals(1, sq.getStart());
196 assertEquals(6, sq.getEnd());
198 sq = new Sequence("test", "--AB-C-DEF--");
199 assertEquals(1, sq.getStart());
200 assertEquals(6, sq.getEnd());
202 sq = new Sequence("test", "----");
203 assertEquals(1, sq.getStart());
204 assertEquals(0, sq.getEnd()); // ??
208 * Tests for the method that returns an alignment column position (base 1) for
209 * a given sequence position (base 1).
211 @Test(groups = { "Functional" })
212 public void testFindIndex()
214 SequenceI sq = new Sequence("test", "ABCDEF");
215 assertEquals(0, sq.findIndex(0));
216 assertEquals(1, sq.findIndex(1));
217 assertEquals(5, sq.findIndex(5));
218 assertEquals(6, sq.findIndex(6));
219 assertEquals(6, sq.findIndex(9));
221 sq = new Sequence("test", "-A--B-C-D-E-F--");
222 assertEquals(2, sq.findIndex(1));
223 assertEquals(5, sq.findIndex(2));
224 assertEquals(7, sq.findIndex(3));
226 // before start returns 0
227 assertEquals(0, sq.findIndex(0));
228 assertEquals(0, sq.findIndex(-1));
230 // beyond end returns last residue column
231 assertEquals(13, sq.findIndex(99));
236 * Tests for the method that returns a dataset sequence position (base 1) for
237 * an aligned column position (base 0).
239 @Test(groups = { "Functional" })
240 public void testFindPosition()
242 SequenceI sq = new Sequence("test", "ABCDEF");
243 assertEquals(1, sq.findPosition(0));
244 assertEquals(6, sq.findPosition(5));
245 // assertEquals(-1, seq.findPosition(6)); // fails
247 sq = new Sequence("test", "AB-C-D--");
248 assertEquals(1, sq.findPosition(0));
249 assertEquals(2, sq.findPosition(1));
250 // gap position 'finds' residue to the right (not the left as per javadoc)
251 assertEquals(3, sq.findPosition(2));
252 assertEquals(3, sq.findPosition(3));
253 assertEquals(4, sq.findPosition(4));
254 assertEquals(4, sq.findPosition(5));
255 // returns 1 more than sequence length if off the end ?!?
256 assertEquals(5, sq.findPosition(6));
257 assertEquals(5, sq.findPosition(7));
259 sq = new Sequence("test", "--AB-C-DEF--");
260 assertEquals(1, sq.findPosition(0));
261 assertEquals(1, sq.findPosition(1));
262 assertEquals(1, sq.findPosition(2));
263 assertEquals(2, sq.findPosition(3));
264 assertEquals(3, sq.findPosition(4));
265 assertEquals(3, sq.findPosition(5));
266 assertEquals(4, sq.findPosition(6));
267 assertEquals(4, sq.findPosition(7));
268 assertEquals(5, sq.findPosition(8));
269 assertEquals(6, sq.findPosition(9));
270 assertEquals(7, sq.findPosition(10));
271 assertEquals(7, sq.findPosition(11));
274 @Test(groups = { "Functional" })
275 public void testDeleteChars()
277 SequenceI sq = new Sequence("test", "ABCDEF");
278 assertEquals(1, sq.getStart());
279 assertEquals(6, sq.getEnd());
280 sq.deleteChars(2, 3);
281 assertEquals("ABDEF", sq.getSequenceAsString());
282 assertEquals(1, sq.getStart());
283 assertEquals(5, sq.getEnd());
285 sq = new Sequence("test", "ABCDEF");
286 sq.deleteChars(0, 2);
287 assertEquals("CDEF", sq.getSequenceAsString());
288 assertEquals(3, sq.getStart());
289 assertEquals(6, sq.getEnd());
292 @Test(groups = { "Functional" })
293 public void testInsertCharAt()
295 // non-static methods:
296 SequenceI sq = new Sequence("test", "ABCDEF");
297 sq.insertCharAt(0, 'z');
298 assertEquals("zABCDEF", sq.getSequenceAsString());
299 sq.insertCharAt(2, 2, 'x');
300 assertEquals("zAxxBCDEF", sq.getSequenceAsString());
302 // for static method see StringUtilsTest
306 * Test the method that returns an array of aligned sequence positions where
307 * the array index is the data sequence position (both base 0).
309 @Test(groups = { "Functional" })
310 public void testGapMap()
312 SequenceI sq = new Sequence("test", "-A--B-CD-E--F-");
313 sq.createDatasetSequence();
314 assertEquals("[1, 4, 6, 7, 9, 12]", Arrays.toString(sq.gapMap()));
318 * Test the method that gets sequence features, either from the sequence or
321 @Test(groups = { "Functional" })
322 public void testGetSequenceFeatures()
324 SequenceI sq = new Sequence("test", "GATCAT");
325 sq.createDatasetSequence();
327 assertNull(sq.getSequenceFeatures());
330 * SequenceFeature on sequence
332 SequenceFeature sf = new SequenceFeature();
333 sq.addSequenceFeature(sf);
334 SequenceFeature[] sfs = sq.getSequenceFeatures();
335 assertEquals(1, sfs.length);
336 assertSame(sf, sfs[0]);
340 * SequenceFeature on sequence and dataset sequence; returns that on
343 * Note JAL-2046: spurious: we have no use case for this at the moment.
344 * This test also buggy - as sf2.equals(sf), no new feature is added
346 SequenceFeature sf2 = new SequenceFeature();
347 sq.getDatasetSequence().addSequenceFeature(sf2);
348 sfs = sq.getSequenceFeatures();
349 assertEquals(1, sfs.length);
350 assertSame(sf, sfs[0]);
353 * SequenceFeature on dataset sequence only
354 * Note JAL-2046: spurious: we have no use case for setting a non-dataset sequence's feature array to null at the moment.
356 sq.setSequenceFeatures(null);
357 assertNull(sq.getDatasetSequence().getSequenceFeatures());
360 * Corrupt case - no SequenceFeature, dataset's dataset is the original
361 * sequence. Test shows no infinite loop results.
363 sq.getDatasetSequence().setSequenceFeatures(null);
365 * is there a usecase for this ? setDatasetSequence should throw an error if
366 * this actually occurs.
368 sq.getDatasetSequence().setDatasetSequence(sq); // loop!
369 assertNull(sq.getSequenceFeatures());
373 * Test the method that returns an array, indexed by sequence position, whose
374 * entries are the residue positions at the sequence position (or to the right
377 @Test(groups = { "Functional" })
378 public void testFindPositionMap()
381 * Note: Javadoc for findPosition says it returns the residue position to
382 * the left of a gapped position; in fact it returns the position to the
383 * right. Also it returns a non-existent residue position for a gap beyond
386 Sequence sq = new Sequence("TestSeq", "AB.C-D E.");
387 int[] map = sq.findPositionMap();
388 assertEquals(Arrays.toString(new int[] { 1, 2, 3, 3, 4, 4, 5, 5, 6 }),
389 Arrays.toString(map));
393 * Test for getSubsequence
395 @Test(groups = { "Functional" })
396 public void testGetSubsequence()
398 SequenceI sq = new Sequence("TestSeq", "ABCDEFG");
399 sq.createDatasetSequence();
401 // positions are base 0, end position is exclusive
402 SequenceI subseq = sq.getSubSequence(2, 4);
404 assertEquals("CD", subseq.getSequenceAsString());
405 // start/end are base 1 positions
406 assertEquals(3, subseq.getStart());
407 assertEquals(4, subseq.getEnd());
408 // subsequence shares the full dataset sequence
409 assertSame(sq.getDatasetSequence(), subseq.getDatasetSequence());
413 * test createDatasetSequence behaves to doc
415 @Test(groups = { "Functional" })
416 public void testCreateDatasetSequence()
418 SequenceI sq = new Sequence("my","ASDASD");
419 assertNull(sq.getDatasetSequence());
420 SequenceI rds = sq.createDatasetSequence();
422 assertNull(rds.getDatasetSequence());
423 assertEquals(sq.getDatasetSequence(), rds);
427 * Test for deriveSequence applied to a sequence with a dataset
429 @Test(groups = { "Functional" })
430 public void testDeriveSequence_existingDataset()
432 Sequence sq = new Sequence("Seq1", "CD");
433 sq.setDatasetSequence(new Sequence("Seq1", "ABCDEF"));
434 sq.getDatasetSequence().addSequenceFeature(
435 new SequenceFeature("", "", 1, 2, 0f, null));
439 sq.setDescription("Test sequence description..");
440 sq.setVamsasId("TestVamsasId");
441 sq.setSourceDBRef(new DBRefEntry("PDB", "version0", "1TST"));
443 sq.addDBRef(new DBRefEntry("PDB", "version1", "1Tst"));
444 sq.addDBRef(new DBRefEntry("PDB", "version2", "2Tst"));
445 sq.addDBRef(new DBRefEntry("PDB", "version3", "3Tst"));
446 sq.addDBRef(new DBRefEntry("PDB", "version4", "4Tst"));
448 sq.addPDBId(new PDBEntry("1PDB", "A", Type.PDB, "filePath/test1"));
449 sq.addPDBId(new PDBEntry("1PDB", "B", Type.PDB, "filePath/test1"));
450 sq.addPDBId(new PDBEntry("2PDB", "A", Type.MMCIF, "filePath/test2"));
451 sq.addPDBId(new PDBEntry("2PDB", "B", Type.MMCIF, "filePath/test2"));
453 sq.getDatasetSequence().addDBRef(
454 new DBRefEntry("PDB", "version1", "1Tst"));
455 sq.getDatasetSequence().addDBRef(
456 new DBRefEntry("PDB", "version2", "2Tst"));
457 sq.getDatasetSequence().addDBRef(
458 new DBRefEntry("PDB", "version3", "3Tst"));
459 sq.getDatasetSequence().addDBRef(
460 new DBRefEntry("PDB", "version4", "4Tst"));
462 sq.getDatasetSequence().addPDBId(
463 new PDBEntry("1PDB", "A", Type.PDB, "filePath/test1"));
464 sq.getDatasetSequence().addPDBId(
465 new PDBEntry("1PDB", "B", Type.PDB, "filePath/test1"));
466 sq.getDatasetSequence().addPDBId(
467 new PDBEntry("2PDB", "A", Type.MMCIF, "filePath/test2"));
468 sq.getDatasetSequence().addPDBId(
469 new PDBEntry("2PDB", "B", Type.MMCIF, "filePath/test2"));
471 ArrayList<Annotation> annotsList = new ArrayList<Annotation>();
472 System.out.println(">>>>>> " + sq.getSequenceAsString().length());
473 annotsList.add(new Annotation("A", "A", 'X', 0.1f));
474 annotsList.add(new Annotation("A", "A", 'X', 0.1f));
475 Annotation[] annots = annotsList.toArray(new Annotation[0]);
476 sq.addAlignmentAnnotation(new AlignmentAnnotation("Test annot",
477 "Test annot description", annots));
478 sq.getDatasetSequence().addAlignmentAnnotation(
479 new AlignmentAnnotation("Test annot", "Test annot description",
481 Assert.assertEquals(sq.getDescription(), "Test sequence description..");
482 Assert.assertEquals(sq.getDBRefs().length, 4);
483 Assert.assertEquals(sq.getAllPDBEntries().size(), 4);
484 Assert.assertNotNull(sq.getAnnotation());
485 Assert.assertEquals(sq.getAnnotation()[0].annotations.length, 2);
486 Assert.assertEquals(sq.getDatasetSequence().getDBRefs().length, 4);
487 Assert.assertEquals(sq.getDatasetSequence().getAllPDBEntries().size(),
489 Assert.assertNotNull(sq.getDatasetSequence().getAnnotation());
491 Sequence derived = (Sequence) sq.deriveSequence();
493 Assert.assertEquals(derived.getDescription(),
494 "Test sequence description..");
495 Assert.assertEquals(derived.getDBRefs().length, 4);
496 Assert.assertEquals(derived.getAllPDBEntries().size(), 4);
497 Assert.assertNotNull(derived.getAnnotation());
498 Assert.assertEquals(derived.getAnnotation()[0].annotations.length, 2);
499 Assert.assertEquals(derived.getDatasetSequence().getDBRefs().length, 4);
500 Assert.assertEquals(derived.getDatasetSequence().getAllPDBEntries()
502 Assert.assertNotNull(derived.getDatasetSequence().getAnnotation());
504 assertEquals("CD", derived.getSequenceAsString());
505 assertSame(sq.getDatasetSequence(), derived.getDatasetSequence());
507 assertNull(sq.sequenceFeatures);
508 assertNull(derived.sequenceFeatures);
509 // derived sequence should access dataset sequence features
510 assertNotNull(sq.getSequenceFeatures());
511 assertArrayEquals(sq.getSequenceFeatures(),
512 derived.getSequenceFeatures());
516 * Test for deriveSequence applied to an ungapped sequence with no dataset
518 @Test(groups = { "Functional" })
519 public void testDeriveSequence_noDatasetUngapped()
521 SequenceI sq = new Sequence("Seq1", "ABCDEF");
522 assertEquals(1, sq.getStart());
523 assertEquals(6, sq.getEnd());
524 SequenceI derived = sq.deriveSequence();
525 assertEquals("ABCDEF", derived.getSequenceAsString());
526 assertEquals("ABCDEF", derived.getDatasetSequence()
527 .getSequenceAsString());
531 * Test for deriveSequence applied to a gapped sequence with no dataset
533 @Test(groups = { "Functional" })
534 public void testDeriveSequence_noDatasetGapped()
536 SequenceI sq = new Sequence("Seq1", "AB-C.D EF");
537 assertEquals(1, sq.getStart());
538 assertEquals(6, sq.getEnd());
539 assertNull(sq.getDatasetSequence());
540 SequenceI derived = sq.deriveSequence();
541 assertEquals("AB-C.D EF", derived.getSequenceAsString());
542 assertEquals("ABCDEF", derived.getDatasetSequence()
543 .getSequenceAsString());
546 @Test(groups = { "Functional" })
547 public void testCopyConstructor_noDataset()
549 SequenceI seq1 = new Sequence("Seq1", "AB-C.D EF");
550 seq1.setDescription("description");
551 seq1.addAlignmentAnnotation(new AlignmentAnnotation("label", "desc",
553 seq1.addSequenceFeature(new SequenceFeature("type", "desc", 22, 33,
555 seq1.addPDBId(new PDBEntry("1A70", "B", Type.PDB, "File"));
556 seq1.addDBRef(new DBRefEntry("EMBL", "1.2", "AZ12345"));
558 SequenceI copy = new Sequence(seq1);
560 assertNull(copy.getDatasetSequence());
562 verifyCopiedSequence(seq1, copy);
564 // copy has a copy of the DBRefEntry
565 // this is murky - DBrefs are only copied for dataset sequences
566 // where the test for 'dataset sequence' is 'dataset is null'
567 // but that doesn't distinguish it from an aligned sequence
568 // which has not yet generated a dataset sequence
569 // NB getDBRef looks inside dataset sequence if not null
570 DBRefEntry[] dbrefs = copy.getDBRefs();
571 assertEquals(1, dbrefs.length);
572 assertFalse(dbrefs[0] == seq1.getDBRefs()[0]);
573 assertTrue(dbrefs[0].equals(seq1.getDBRefs()[0]));
576 @Test(groups = { "Functional" })
577 public void testCopyConstructor_withDataset()
579 SequenceI seq1 = new Sequence("Seq1", "AB-C.D EF");
580 seq1.createDatasetSequence();
581 seq1.setDescription("description");
582 seq1.addAlignmentAnnotation(new AlignmentAnnotation("label", "desc",
584 // JAL-2046 - what is the contract for using a derived sequence's
585 // addSequenceFeature ?
586 seq1.addSequenceFeature(new SequenceFeature("type", "desc", 22, 33,
588 seq1.addPDBId(new PDBEntry("1A70", "B", Type.PDB, "File"));
589 // here we add DBRef to the dataset sequence:
590 seq1.getDatasetSequence().addDBRef(
591 new DBRefEntry("EMBL", "1.2", "AZ12345"));
593 SequenceI copy = new Sequence(seq1);
595 assertNotNull(copy.getDatasetSequence());
596 assertSame(copy.getDatasetSequence(), seq1.getDatasetSequence());
598 verifyCopiedSequence(seq1, copy);
600 // getDBRef looks inside dataset sequence and this is shared,
601 // so holds the same dbref objects
602 DBRefEntry[] dbrefs = copy.getDBRefs();
603 assertEquals(1, dbrefs.length);
604 assertSame(dbrefs[0], seq1.getDBRefs()[0]);
608 * Helper to make assertions about a copied sequence
613 protected void verifyCopiedSequence(SequenceI seq1, SequenceI copy)
615 // verify basic properties:
616 assertEquals(copy.getName(), seq1.getName());
617 assertEquals(copy.getDescription(), seq1.getDescription());
618 assertEquals(copy.getStart(), seq1.getStart());
619 assertEquals(copy.getEnd(), seq1.getEnd());
620 assertEquals(copy.getSequenceAsString(), seq1.getSequenceAsString());
622 // copy has a copy of the annotation:
623 AlignmentAnnotation[] anns = copy.getAnnotation();
624 assertEquals(1, anns.length);
625 assertFalse(anns[0] == seq1.getAnnotation()[0]);
626 assertEquals(anns[0].label, seq1.getAnnotation()[0].label);
627 assertEquals(anns[0].description, seq1.getAnnotation()[0].description);
628 assertEquals(anns[0].score, seq1.getAnnotation()[0].score);
630 // copy has a copy of the sequence feature:
631 SequenceFeature[] sfs = copy.getSequenceFeatures();
632 assertEquals(1, sfs.length);
633 if (seq1.getDatasetSequence()!=null && copy.getDatasetSequence()==seq1.getDatasetSequence()) {
634 assertTrue(sfs[0] == seq1.getSequenceFeatures()[0]);
636 assertFalse(sfs[0] == seq1.getSequenceFeatures()[0]);
638 assertTrue(sfs[0].equals(seq1.getSequenceFeatures()[0]));
640 // copy has a copy of the PDB entry
641 Vector<PDBEntry> pdbs = copy.getAllPDBEntries();
642 assertEquals(1, pdbs.size());
643 assertFalse(pdbs.get(0) == seq1.getAllPDBEntries().get(0));
644 assertTrue(pdbs.get(0).equals(seq1.getAllPDBEntries().get(0)));
647 @Test(groups = "Functional")
648 public void testGetCharAt()
650 SequenceI sq = new Sequence("", "abcde");
651 assertEquals('a', sq.getCharAt(0));
652 assertEquals('e', sq.getCharAt(4));
653 assertEquals(' ', sq.getCharAt(5));
654 assertEquals(' ', sq.getCharAt(-1));
658 * Tests for adding (or updating) dbrefs
660 * @see DBRefEntry#updateFrom(DBRefEntry)
662 @Test(groups = { "Functional" })
663 public void testAddDBRef()
665 SequenceI sq = new Sequence("", "abcde");
666 assertNull(sq.getDBRefs());
667 DBRefEntry dbref = new DBRefEntry("Uniprot", "1", "P00340");
669 assertEquals(1, sq.getDBRefs().length);
670 assertSame(dbref, sq.getDBRefs()[0]);
673 * change of version - new entry
675 DBRefEntry dbref2 = new DBRefEntry("Uniprot", "2", "P00340");
677 assertEquals(2, sq.getDBRefs().length);
678 assertSame(dbref, sq.getDBRefs()[0]);
679 assertSame(dbref2, sq.getDBRefs()[1]);
682 * matches existing entry - not added
684 sq.addDBRef(new DBRefEntry("UNIPROT", "1", "p00340"));
685 assertEquals(2, sq.getDBRefs().length);
688 * different source = new entry
690 DBRefEntry dbref3 = new DBRefEntry("UniRef", "1", "p00340");
692 assertEquals(3, sq.getDBRefs().length);
693 assertSame(dbref3, sq.getDBRefs()[2]);
696 * different ref = new entry
698 DBRefEntry dbref4 = new DBRefEntry("UniRef", "1", "p00341");
700 assertEquals(4, sq.getDBRefs().length);
701 assertSame(dbref4, sq.getDBRefs()[3]);
704 * matching ref with a mapping - map updated
706 DBRefEntry dbref5 = new DBRefEntry("UniRef", "1", "p00341");
707 Mapping map = new Mapping(new MapList(new int[] { 1, 3 }, new int[] {
711 assertEquals(4, sq.getDBRefs().length);
712 assertSame(dbref4, sq.getDBRefs()[3]);
713 assertSame(map, dbref4.getMap());
716 * 'real' version replaces "0" version
718 dbref2.setVersion("0");
719 DBRefEntry dbref6 = new DBRefEntry(dbref2.getSource(), "3",
720 dbref2.getAccessionId());
722 assertEquals(4, sq.getDBRefs().length);
723 assertSame(dbref2, sq.getDBRefs()[1]);
724 assertEquals("3", dbref2.getVersion());
727 * 'real' version replaces "source:0" version
729 dbref3.setVersion("Uniprot:0");
730 DBRefEntry dbref7 = new DBRefEntry(dbref3.getSource(), "3",
731 dbref3.getAccessionId());
733 assertEquals(4, sq.getDBRefs().length);
734 assertSame(dbref3, sq.getDBRefs()[2]);
735 assertEquals("3", dbref2.getVersion());