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());
83 * in situ change of sequence doesn't change hashcode :-O
84 * (sequence should not expose internal implementation)
86 for (int i = 0; i < sq.getSequence().length; i++)
88 sq.getSequence()[i] = "acgtu".charAt(i % 5);
90 assertTrue(sq.isProtein()); // but it isn't
93 @Test(groups = { "Functional" })
94 public void testGetAnnotation()
96 // initial state returns null not an empty array
97 assertNull(seq.getAnnotation());
98 AlignmentAnnotation ann = addAnnotation("label1", "desc1", "calcId1",
100 AlignmentAnnotation[] anns = seq.getAnnotation();
101 assertEquals(1, anns.length);
102 assertSame(ann, anns[0]);
104 // removing all annotations reverts array to null
105 seq.removeAlignmentAnnotation(ann);
106 assertNull(seq.getAnnotation());
109 @Test(groups = { "Functional" })
110 public void testGetAnnotation_forLabel()
112 AlignmentAnnotation ann1 = addAnnotation("label1", "desc1", "calcId1",
114 AlignmentAnnotation ann2 = addAnnotation("label2", "desc2", "calcId2",
116 AlignmentAnnotation ann3 = addAnnotation("label1", "desc3", "calcId3",
118 AlignmentAnnotation[] anns = seq.getAnnotation("label1");
119 assertEquals(2, anns.length);
120 assertSame(ann1, anns[0]);
121 assertSame(ann3, anns[1]);
124 private AlignmentAnnotation addAnnotation(String label,
125 String description, String calcId, float value)
127 final AlignmentAnnotation annotation = new AlignmentAnnotation(label,
129 annotation.setCalcId(calcId);
130 seq.addAlignmentAnnotation(annotation);
134 @Test(groups = { "Functional" })
135 public void testGetAlignmentAnnotations_forCalcIdAndLabel()
137 AlignmentAnnotation ann1 = addAnnotation("label1", "desc1", "calcId1",
139 AlignmentAnnotation ann2 = addAnnotation("label2", "desc2", "calcId2",
141 AlignmentAnnotation ann3 = addAnnotation("label2", "desc3", "calcId3",
143 AlignmentAnnotation ann4 = addAnnotation("label2", "desc3", "calcId2",
145 AlignmentAnnotation ann5 = addAnnotation("label5", "desc3", null, 1f);
146 AlignmentAnnotation ann6 = addAnnotation(null, "desc3", "calcId3", 1f);
147 List<AlignmentAnnotation> anns = seq.getAlignmentAnnotations("calcId2",
149 assertEquals(2, anns.size());
150 assertSame(ann2, anns.get(0));
151 assertSame(ann4, anns.get(1));
153 assertTrue(seq.getAlignmentAnnotations("calcId2", "label3").isEmpty());
154 assertTrue(seq.getAlignmentAnnotations("calcId3", "label5").isEmpty());
155 assertTrue(seq.getAlignmentAnnotations("calcId2", null).isEmpty());
156 assertTrue(seq.getAlignmentAnnotations(null, "label3").isEmpty());
157 assertTrue(seq.getAlignmentAnnotations(null, null).isEmpty());
161 * Tests for addAlignmentAnnotation. Note this method has the side-effect of
162 * setting the sequenceRef on the annotation. Adding the same annotation twice
165 @Test(groups = { "Functional" })
166 public void testAddAlignmentAnnotation()
168 assertNull(seq.getAnnotation());
169 final AlignmentAnnotation annotation = new AlignmentAnnotation("a",
171 assertNull(annotation.sequenceRef);
172 seq.addAlignmentAnnotation(annotation);
173 assertSame(seq, annotation.sequenceRef);
174 AlignmentAnnotation[] anns = seq.getAnnotation();
175 assertEquals(1, anns.length);
176 assertSame(annotation, anns[0]);
178 // re-adding does nothing
179 seq.addAlignmentAnnotation(annotation);
180 anns = seq.getAnnotation();
181 assertEquals(1, anns.length);
182 assertSame(annotation, anns[0]);
184 // an identical but different annotation can be added
185 final AlignmentAnnotation annotation2 = new AlignmentAnnotation("a",
187 seq.addAlignmentAnnotation(annotation2);
188 anns = seq.getAnnotation();
189 assertEquals(2, anns.length);
190 assertSame(annotation, anns[0]);
191 assertSame(annotation2, anns[1]);
194 @Test(groups = { "Functional" })
195 public void testGetStartGetEnd()
197 SequenceI sq = new Sequence("test", "ABCDEF");
198 assertEquals(1, sq.getStart());
199 assertEquals(6, sq.getEnd());
201 sq = new Sequence("test", "--AB-C-DEF--");
202 assertEquals(1, sq.getStart());
203 assertEquals(6, sq.getEnd());
205 sq = new Sequence("test", "----");
206 assertEquals(1, sq.getStart());
207 assertEquals(0, sq.getEnd()); // ??
211 * Tests for the method that returns an alignment column position (base 1) for
212 * a given sequence position (base 1).
214 @Test(groups = { "Functional" })
215 public void testFindIndex()
217 SequenceI sq = new Sequence("test", "ABCDEF");
218 assertEquals(0, sq.findIndex(0));
219 assertEquals(1, sq.findIndex(1));
220 assertEquals(5, sq.findIndex(5));
221 assertEquals(6, sq.findIndex(6));
222 assertEquals(6, sq.findIndex(9));
224 sq = new Sequence("test", "-A--B-C-D-E-F--");
225 assertEquals(2, sq.findIndex(1));
226 assertEquals(5, sq.findIndex(2));
227 assertEquals(7, sq.findIndex(3));
229 // before start returns 0
230 assertEquals(0, sq.findIndex(0));
231 assertEquals(0, sq.findIndex(-1));
233 // beyond end returns last residue column
234 assertEquals(13, sq.findIndex(99));
239 * Tests for the method that returns a dataset sequence position (base 1) for
240 * an aligned column position (base 0).
242 @Test(groups = { "Functional" })
243 public void testFindPosition()
245 SequenceI sq = new Sequence("test", "ABCDEF");
246 assertEquals(1, sq.findPosition(0));
247 assertEquals(6, sq.findPosition(5));
248 // assertEquals(-1, seq.findPosition(6)); // fails
250 sq = new Sequence("test", "AB-C-D--");
251 assertEquals(1, sq.findPosition(0));
252 assertEquals(2, sq.findPosition(1));
253 // gap position 'finds' residue to the right (not the left as per javadoc)
254 assertEquals(3, sq.findPosition(2));
255 assertEquals(3, sq.findPosition(3));
256 assertEquals(4, sq.findPosition(4));
257 assertEquals(4, sq.findPosition(5));
258 // returns 1 more than sequence length if off the end ?!?
259 assertEquals(5, sq.findPosition(6));
260 assertEquals(5, sq.findPosition(7));
262 sq = new Sequence("test", "--AB-C-DEF--");
263 assertEquals(1, sq.findPosition(0));
264 assertEquals(1, sq.findPosition(1));
265 assertEquals(1, sq.findPosition(2));
266 assertEquals(2, sq.findPosition(3));
267 assertEquals(3, sq.findPosition(4));
268 assertEquals(3, sq.findPosition(5));
269 assertEquals(4, sq.findPosition(6));
270 assertEquals(4, sq.findPosition(7));
271 assertEquals(5, sq.findPosition(8));
272 assertEquals(6, sq.findPosition(9));
273 assertEquals(7, sq.findPosition(10));
274 assertEquals(7, sq.findPosition(11));
277 @Test(groups = { "Functional" })
278 public void testDeleteChars()
280 SequenceI sq = new Sequence("test", "ABCDEF");
281 assertEquals(1, sq.getStart());
282 assertEquals(6, sq.getEnd());
283 sq.deleteChars(2, 3);
284 assertEquals("ABDEF", sq.getSequenceAsString());
285 assertEquals(1, sq.getStart());
286 assertEquals(5, sq.getEnd());
288 sq = new Sequence("test", "ABCDEF");
289 sq.deleteChars(0, 2);
290 assertEquals("CDEF", sq.getSequenceAsString());
291 assertEquals(3, sq.getStart());
292 assertEquals(6, sq.getEnd());
295 @Test(groups = { "Functional" })
296 public void testInsertCharAt()
298 // non-static methods:
299 SequenceI sq = new Sequence("test", "ABCDEF");
300 sq.insertCharAt(0, 'z');
301 assertEquals("zABCDEF", sq.getSequenceAsString());
302 sq.insertCharAt(2, 2, 'x');
303 assertEquals("zAxxBCDEF", sq.getSequenceAsString());
305 // for static method see StringUtilsTest
309 * Test the method that returns an array of aligned sequence positions where
310 * the array index is the data sequence position (both base 0).
312 @Test(groups = { "Functional" })
313 public void testGapMap()
315 SequenceI sq = new Sequence("test", "-A--B-CD-E--F-");
316 sq.createDatasetSequence();
317 assertEquals("[1, 4, 6, 7, 9, 12]", Arrays.toString(sq.gapMap()));
321 * Test the method that gets sequence features, either from the sequence or
324 @Test(groups = { "Functional" })
325 public void testGetSequenceFeatures()
327 SequenceI sq = new Sequence("test", "GATCAT");
328 sq.createDatasetSequence();
330 assertNull(sq.getSequenceFeatures());
333 * SequenceFeature on sequence
335 SequenceFeature sf = new SequenceFeature();
336 sq.addSequenceFeature(sf);
337 SequenceFeature[] sfs = sq.getSequenceFeatures();
338 assertEquals(1, sfs.length);
339 assertSame(sf, sfs[0]);
343 * SequenceFeature on sequence and dataset sequence; returns that on
346 * Note JAL-2046: spurious: we have no use case for this at the moment.
347 * This test also buggy - as sf2.equals(sf), no new feature is added
349 SequenceFeature sf2 = new SequenceFeature();
350 sq.getDatasetSequence().addSequenceFeature(sf2);
351 sfs = sq.getSequenceFeatures();
352 assertEquals(1, sfs.length);
353 assertSame(sf, sfs[0]);
356 * SequenceFeature on dataset sequence only
357 * Note JAL-2046: spurious: we have no use case for setting a non-dataset sequence's feature array to null at the moment.
359 sq.setSequenceFeatures(null);
360 assertNull(sq.getDatasetSequence().getSequenceFeatures());
363 * Corrupt case - no SequenceFeature, dataset's dataset is the original
364 * sequence. Test shows no infinite loop results.
366 sq.getDatasetSequence().setSequenceFeatures(null);
368 * is there a usecase for this ? setDatasetSequence should throw an error if
369 * this actually occurs.
371 sq.getDatasetSequence().setDatasetSequence(sq); // loop!
372 assertNull(sq.getSequenceFeatures());
376 * Test the method that returns an array, indexed by sequence position, whose
377 * entries are the residue positions at the sequence position (or to the right
380 @Test(groups = { "Functional" })
381 public void testFindPositionMap()
384 * Note: Javadoc for findPosition says it returns the residue position to
385 * the left of a gapped position; in fact it returns the position to the
386 * right. Also it returns a non-existent residue position for a gap beyond
389 Sequence sq = new Sequence("TestSeq", "AB.C-D E.");
390 int[] map = sq.findPositionMap();
391 assertEquals(Arrays.toString(new int[] { 1, 2, 3, 3, 4, 4, 5, 5, 6 }),
392 Arrays.toString(map));
396 * Test for getSubsequence
398 @Test(groups = { "Functional" })
399 public void testGetSubsequence()
401 SequenceI sq = new Sequence("TestSeq", "ABCDEFG");
402 sq.createDatasetSequence();
404 // positions are base 0, end position is exclusive
405 SequenceI subseq = sq.getSubSequence(2, 4);
407 assertEquals("CD", subseq.getSequenceAsString());
408 // start/end are base 1 positions
409 assertEquals(3, subseq.getStart());
410 assertEquals(4, subseq.getEnd());
411 // subsequence shares the full dataset sequence
412 assertSame(sq.getDatasetSequence(), subseq.getDatasetSequence());
416 * test createDatasetSequence behaves to doc
418 @Test(groups = { "Functional" })
419 public void testCreateDatasetSequence()
421 SequenceI sq = new Sequence("my","ASDASD");
422 assertNull(sq.getDatasetSequence());
423 SequenceI rds = sq.createDatasetSequence();
425 assertNull(rds.getDatasetSequence());
426 assertEquals(sq.getDatasetSequence(), rds);
430 * Test for deriveSequence applied to a sequence with a dataset
432 @Test(groups = { "Functional" })
433 public void testDeriveSequence_existingDataset()
435 Sequence sq = new Sequence("Seq1", "CD");
436 sq.setDatasetSequence(new Sequence("Seq1", "ABCDEF"));
437 sq.getDatasetSequence().addSequenceFeature(
438 new SequenceFeature("", "", 1, 2, 0f, null));
442 sq.setDescription("Test sequence description..");
443 sq.setVamsasId("TestVamsasId");
444 sq.setSourceDBRef(new DBRefEntry("PDB", "version0", "1TST"));
446 sq.addDBRef(new DBRefEntry("PDB", "version1", "1Tst"));
447 sq.addDBRef(new DBRefEntry("PDB", "version2", "2Tst"));
448 sq.addDBRef(new DBRefEntry("PDB", "version3", "3Tst"));
449 sq.addDBRef(new DBRefEntry("PDB", "version4", "4Tst"));
451 sq.addPDBId(new PDBEntry("1PDB", "A", Type.PDB, "filePath/test1"));
452 sq.addPDBId(new PDBEntry("1PDB", "B", Type.PDB, "filePath/test1"));
453 sq.addPDBId(new PDBEntry("2PDB", "A", Type.MMCIF, "filePath/test2"));
454 sq.addPDBId(new PDBEntry("2PDB", "B", Type.MMCIF, "filePath/test2"));
456 sq.getDatasetSequence().addDBRef(
457 new DBRefEntry("PDB", "version1", "1Tst"));
458 sq.getDatasetSequence().addDBRef(
459 new DBRefEntry("PDB", "version2", "2Tst"));
460 sq.getDatasetSequence().addDBRef(
461 new DBRefEntry("PDB", "version3", "3Tst"));
462 sq.getDatasetSequence().addDBRef(
463 new DBRefEntry("PDB", "version4", "4Tst"));
465 sq.getDatasetSequence().addPDBId(
466 new PDBEntry("1PDB", "A", Type.PDB, "filePath/test1"));
467 sq.getDatasetSequence().addPDBId(
468 new PDBEntry("1PDB", "B", Type.PDB, "filePath/test1"));
469 sq.getDatasetSequence().addPDBId(
470 new PDBEntry("2PDB", "A", Type.MMCIF, "filePath/test2"));
471 sq.getDatasetSequence().addPDBId(
472 new PDBEntry("2PDB", "B", Type.MMCIF, "filePath/test2"));
474 ArrayList<Annotation> annotsList = new ArrayList<Annotation>();
475 System.out.println(">>>>>> " + sq.getSequenceAsString().length());
476 annotsList.add(new Annotation("A", "A", 'X', 0.1f));
477 annotsList.add(new Annotation("A", "A", 'X', 0.1f));
478 Annotation[] annots = annotsList.toArray(new Annotation[0]);
479 sq.addAlignmentAnnotation(new AlignmentAnnotation("Test annot",
480 "Test annot description", annots));
481 sq.getDatasetSequence().addAlignmentAnnotation(
482 new AlignmentAnnotation("Test annot", "Test annot description",
484 Assert.assertEquals(sq.getDescription(), "Test sequence description..");
485 Assert.assertEquals(sq.getDBRefs().length, 4);
486 Assert.assertEquals(sq.getAllPDBEntries().size(), 4);
487 Assert.assertNotNull(sq.getAnnotation());
488 Assert.assertEquals(sq.getAnnotation()[0].annotations.length, 2);
489 Assert.assertEquals(sq.getDatasetSequence().getDBRefs().length, 4);
490 Assert.assertEquals(sq.getDatasetSequence().getAllPDBEntries().size(),
492 Assert.assertNotNull(sq.getDatasetSequence().getAnnotation());
494 Sequence derived = (Sequence) sq.deriveSequence();
496 Assert.assertEquals(derived.getDescription(),
497 "Test sequence description..");
498 Assert.assertEquals(derived.getDBRefs().length, 4);
499 Assert.assertEquals(derived.getAllPDBEntries().size(), 4);
500 Assert.assertNotNull(derived.getAnnotation());
501 Assert.assertEquals(derived.getAnnotation()[0].annotations.length, 2);
502 Assert.assertEquals(derived.getDatasetSequence().getDBRefs().length, 4);
503 Assert.assertEquals(derived.getDatasetSequence().getAllPDBEntries()
505 Assert.assertNotNull(derived.getDatasetSequence().getAnnotation());
507 assertEquals("CD", derived.getSequenceAsString());
508 assertSame(sq.getDatasetSequence(), derived.getDatasetSequence());
510 assertNull(sq.sequenceFeatures);
511 assertNull(derived.sequenceFeatures);
512 // derived sequence should access dataset sequence features
513 assertNotNull(sq.getSequenceFeatures());
514 assertArrayEquals(sq.getSequenceFeatures(),
515 derived.getSequenceFeatures());
519 * Test for deriveSequence applied to an ungapped sequence with no dataset
521 @Test(groups = { "Functional" })
522 public void testDeriveSequence_noDatasetUngapped()
524 SequenceI sq = new Sequence("Seq1", "ABCDEF");
525 assertEquals(1, sq.getStart());
526 assertEquals(6, sq.getEnd());
527 SequenceI derived = sq.deriveSequence();
528 assertEquals("ABCDEF", derived.getSequenceAsString());
529 assertEquals("ABCDEF", derived.getDatasetSequence()
530 .getSequenceAsString());
534 * Test for deriveSequence applied to a gapped sequence with no dataset
536 @Test(groups = { "Functional" })
537 public void testDeriveSequence_noDatasetGapped()
539 SequenceI sq = new Sequence("Seq1", "AB-C.D EF");
540 assertEquals(1, sq.getStart());
541 assertEquals(6, sq.getEnd());
542 assertNull(sq.getDatasetSequence());
543 SequenceI derived = sq.deriveSequence();
544 assertEquals("AB-C.D EF", derived.getSequenceAsString());
545 assertEquals("ABCDEF", derived.getDatasetSequence()
546 .getSequenceAsString());
549 @Test(groups = { "Functional" })
550 public void testCopyConstructor_noDataset()
552 SequenceI seq1 = new Sequence("Seq1", "AB-C.D EF");
553 seq1.setDescription("description");
554 seq1.addAlignmentAnnotation(new AlignmentAnnotation("label", "desc",
556 seq1.addSequenceFeature(new SequenceFeature("type", "desc", 22, 33,
558 seq1.addPDBId(new PDBEntry("1A70", "B", Type.PDB, "File"));
559 seq1.addDBRef(new DBRefEntry("EMBL", "1.2", "AZ12345"));
561 SequenceI copy = new Sequence(seq1);
563 assertNull(copy.getDatasetSequence());
565 verifyCopiedSequence(seq1, copy);
567 // copy has a copy of the DBRefEntry
568 // this is murky - DBrefs are only copied for dataset sequences
569 // where the test for 'dataset sequence' is 'dataset is null'
570 // but that doesn't distinguish it from an aligned sequence
571 // which has not yet generated a dataset sequence
572 // NB getDBRef looks inside dataset sequence if not null
573 DBRefEntry[] dbrefs = copy.getDBRefs();
574 assertEquals(1, dbrefs.length);
575 assertFalse(dbrefs[0] == seq1.getDBRefs()[0]);
576 assertTrue(dbrefs[0].equals(seq1.getDBRefs()[0]));
579 @Test(groups = { "Functional" })
580 public void testCopyConstructor_withDataset()
582 SequenceI seq1 = new Sequence("Seq1", "AB-C.D EF");
583 seq1.createDatasetSequence();
584 seq1.setDescription("description");
585 seq1.addAlignmentAnnotation(new AlignmentAnnotation("label", "desc",
587 // JAL-2046 - what is the contract for using a derived sequence's
588 // addSequenceFeature ?
589 seq1.addSequenceFeature(new SequenceFeature("type", "desc", 22, 33,
591 seq1.addPDBId(new PDBEntry("1A70", "B", Type.PDB, "File"));
592 // here we add DBRef to the dataset sequence:
593 seq1.getDatasetSequence().addDBRef(
594 new DBRefEntry("EMBL", "1.2", "AZ12345"));
596 SequenceI copy = new Sequence(seq1);
598 assertNotNull(copy.getDatasetSequence());
599 assertSame(copy.getDatasetSequence(), seq1.getDatasetSequence());
601 verifyCopiedSequence(seq1, copy);
603 // getDBRef looks inside dataset sequence and this is shared,
604 // so holds the same dbref objects
605 DBRefEntry[] dbrefs = copy.getDBRefs();
606 assertEquals(1, dbrefs.length);
607 assertSame(dbrefs[0], seq1.getDBRefs()[0]);
611 * Helper to make assertions about a copied sequence
616 protected void verifyCopiedSequence(SequenceI seq1, SequenceI copy)
618 // verify basic properties:
619 assertEquals(copy.getName(), seq1.getName());
620 assertEquals(copy.getDescription(), seq1.getDescription());
621 assertEquals(copy.getStart(), seq1.getStart());
622 assertEquals(copy.getEnd(), seq1.getEnd());
623 assertEquals(copy.getSequenceAsString(), seq1.getSequenceAsString());
625 // copy has a copy of the annotation:
626 AlignmentAnnotation[] anns = copy.getAnnotation();
627 assertEquals(1, anns.length);
628 assertFalse(anns[0] == seq1.getAnnotation()[0]);
629 assertEquals(anns[0].label, seq1.getAnnotation()[0].label);
630 assertEquals(anns[0].description, seq1.getAnnotation()[0].description);
631 assertEquals(anns[0].score, seq1.getAnnotation()[0].score);
633 // copy has a copy of the sequence feature:
634 SequenceFeature[] sfs = copy.getSequenceFeatures();
635 assertEquals(1, sfs.length);
636 if (seq1.getDatasetSequence()!=null && copy.getDatasetSequence()==seq1.getDatasetSequence()) {
637 assertTrue(sfs[0] == seq1.getSequenceFeatures()[0]);
639 assertFalse(sfs[0] == seq1.getSequenceFeatures()[0]);
641 assertTrue(sfs[0].equals(seq1.getSequenceFeatures()[0]));
643 // copy has a copy of the PDB entry
644 Vector<PDBEntry> pdbs = copy.getAllPDBEntries();
645 assertEquals(1, pdbs.size());
646 assertFalse(pdbs.get(0) == seq1.getAllPDBEntries().get(0));
647 assertTrue(pdbs.get(0).equals(seq1.getAllPDBEntries().get(0)));
650 @Test(groups = "Functional")
651 public void testGetCharAt()
653 SequenceI sq = new Sequence("", "abcde");
654 assertEquals('a', sq.getCharAt(0));
655 assertEquals('e', sq.getCharAt(4));
656 assertEquals(' ', sq.getCharAt(5));
657 assertEquals(' ', sq.getCharAt(-1));
661 * Tests for adding (or updating) dbrefs
663 * @see DBRefEntry#updateFrom(DBRefEntry)
665 @Test(groups = { "Functional" })
666 public void testAddDBRef()
668 SequenceI sq = new Sequence("", "abcde");
669 assertNull(sq.getDBRefs());
670 DBRefEntry dbref = new DBRefEntry("Uniprot", "1", "P00340");
672 assertEquals(1, sq.getDBRefs().length);
673 assertSame(dbref, sq.getDBRefs()[0]);
676 * change of version - new entry
678 DBRefEntry dbref2 = new DBRefEntry("Uniprot", "2", "P00340");
680 assertEquals(2, sq.getDBRefs().length);
681 assertSame(dbref, sq.getDBRefs()[0]);
682 assertSame(dbref2, sq.getDBRefs()[1]);
685 * matches existing entry - not added
687 sq.addDBRef(new DBRefEntry("UNIPROT", "1", "p00340"));
688 assertEquals(2, sq.getDBRefs().length);
691 * different source = new entry
693 DBRefEntry dbref3 = new DBRefEntry("UniRef", "1", "p00340");
695 assertEquals(3, sq.getDBRefs().length);
696 assertSame(dbref3, sq.getDBRefs()[2]);
699 * different ref = new entry
701 DBRefEntry dbref4 = new DBRefEntry("UniRef", "1", "p00341");
703 assertEquals(4, sq.getDBRefs().length);
704 assertSame(dbref4, sq.getDBRefs()[3]);
707 * matching ref with a mapping - map updated
709 DBRefEntry dbref5 = new DBRefEntry("UniRef", "1", "p00341");
710 Mapping map = new Mapping(new MapList(new int[] { 1, 3 }, new int[] {
714 assertEquals(4, sq.getDBRefs().length);
715 assertSame(dbref4, sq.getDBRefs()[3]);
716 assertSame(map, dbref4.getMap());
719 * 'real' version replaces "0" version
721 dbref2.setVersion("0");
722 DBRefEntry dbref6 = new DBRefEntry(dbref2.getSource(), "3",
723 dbref2.getAccessionId());
725 assertEquals(4, sq.getDBRefs().length);
726 assertSame(dbref2, sq.getDBRefs()[1]);
727 assertEquals("3", dbref2.getVersion());
730 * 'real' version replaces "source:0" version
732 dbref3.setVersion("Uniprot:0");
733 DBRefEntry dbref7 = new DBRefEntry(dbref3.getSource(), "3",
734 dbref3.getAccessionId());
736 assertEquals(4, sq.getDBRefs().length);
737 assertSame(dbref3, sq.getDBRefs()[2]);
738 assertEquals("3", dbref2.getVersion());