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.assertNotSame;
27 import static org.testng.AssertJUnit.assertNull;
28 import static org.testng.AssertJUnit.assertSame;
29 import static org.testng.AssertJUnit.assertTrue;
31 import jalview.datamodel.PDBEntry.Type;
32 import jalview.gui.JvOptionPane;
33 import jalview.util.MapList;
36 import java.util.ArrayList;
37 import java.util.Arrays;
38 import java.util.List;
39 import java.util.Vector;
41 import junit.extensions.PA;
43 import org.testng.Assert;
44 import org.testng.annotations.BeforeClass;
45 import org.testng.annotations.BeforeMethod;
46 import org.testng.annotations.Test;
48 public class SequenceTest
51 @BeforeClass(alwaysRun = true)
52 public void setUpJvOptionPane()
54 JvOptionPane.setInteractiveMode(false);
55 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
60 @BeforeMethod(alwaysRun = true)
63 seq = new Sequence("FER1", "AKPNGVL");
66 @Test(groups = { "Functional" })
67 public void testInsertGapsAndGapmaps()
69 SequenceI aseq = seq.deriveSequence();
70 aseq.insertCharAt(2, 3, '-');
71 aseq.insertCharAt(6, 3, '-');
72 assertEquals("Gap insertions not correct", "AK---P---NGVL",
73 aseq.getSequenceAsString());
74 List<int[]> gapInt = aseq.getInsertions();
75 assertEquals("Gap interval 1 start wrong", 2, gapInt.get(0)[0]);
76 assertEquals("Gap interval 1 end wrong", 4, gapInt.get(0)[1]);
77 assertEquals("Gap interval 2 start wrong", 6, gapInt.get(1)[0]);
78 assertEquals("Gap interval 2 end wrong", 8, gapInt.get(1)[1]);
81 @Test(groups = ("Functional"))
82 public void testIsProtein()
85 assertTrue(new Sequence("prot", "ASDFASDFASDF").isProtein());
87 assertFalse(new Sequence("prot", "ACGTACGTACGT").isProtein());
89 SequenceI sq = new Sequence("prot", "ACGUACGUACGU");
90 assertFalse(sq.isProtein());
91 // change sequence, should trigger an update of cached result
92 sq.setSequence("ASDFASDFADSF");
93 assertTrue(sq.isProtein());
95 * in situ change of sequence doesn't change hashcode :-O
96 * (sequence should not expose internal implementation)
98 for (int i = 0; i < sq.getSequence().length; i++)
100 sq.getSequence()[i] = "acgtu".charAt(i % 5);
102 assertTrue(sq.isProtein()); // but it isn't
105 @Test(groups = { "Functional" })
106 public void testGetAnnotation()
108 // initial state returns null not an empty array
109 assertNull(seq.getAnnotation());
110 AlignmentAnnotation ann = addAnnotation("label1", "desc1", "calcId1",
112 AlignmentAnnotation[] anns = seq.getAnnotation();
113 assertEquals(1, anns.length);
114 assertSame(ann, anns[0]);
116 // removing all annotations reverts array to null
117 seq.removeAlignmentAnnotation(ann);
118 assertNull(seq.getAnnotation());
121 @Test(groups = { "Functional" })
122 public void testGetAnnotation_forLabel()
124 AlignmentAnnotation ann1 = addAnnotation("label1", "desc1", "calcId1",
126 addAnnotation("label2", "desc2", "calcId2", 1f);
127 AlignmentAnnotation ann3 = addAnnotation("label1", "desc3", "calcId3",
129 AlignmentAnnotation[] anns = seq.getAnnotation("label1");
130 assertEquals(2, anns.length);
131 assertSame(ann1, anns[0]);
132 assertSame(ann3, anns[1]);
135 private AlignmentAnnotation addAnnotation(String label,
136 String description, String calcId, float value)
138 final AlignmentAnnotation annotation = new AlignmentAnnotation(label,
140 annotation.setCalcId(calcId);
141 seq.addAlignmentAnnotation(annotation);
145 @Test(groups = { "Functional" })
146 public void testGetAlignmentAnnotations_forCalcIdAndLabel()
148 addAnnotation("label1", "desc1", "calcId1", 1f);
149 AlignmentAnnotation ann2 = addAnnotation("label2", "desc2", "calcId2",
151 addAnnotation("label2", "desc3", "calcId3", 1f);
152 AlignmentAnnotation ann4 = addAnnotation("label2", "desc3", "calcId2",
154 addAnnotation("label5", "desc3", null, 1f);
155 addAnnotation(null, "desc3", "calcId3", 1f);
157 List<AlignmentAnnotation> anns = seq.getAlignmentAnnotations("calcId2",
159 assertEquals(2, anns.size());
160 assertSame(ann2, anns.get(0));
161 assertSame(ann4, anns.get(1));
163 assertTrue(seq.getAlignmentAnnotations("calcId2", "label3").isEmpty());
164 assertTrue(seq.getAlignmentAnnotations("calcId3", "label5").isEmpty());
165 assertTrue(seq.getAlignmentAnnotations("calcId2", null).isEmpty());
166 assertTrue(seq.getAlignmentAnnotations(null, "label3").isEmpty());
167 assertTrue(seq.getAlignmentAnnotations(null, null).isEmpty());
171 * Tests for addAlignmentAnnotation. Note this method has the side-effect of
172 * setting the sequenceRef on the annotation. Adding the same annotation twice
175 @Test(groups = { "Functional" })
176 public void testAddAlignmentAnnotation()
178 assertNull(seq.getAnnotation());
179 final AlignmentAnnotation annotation = new AlignmentAnnotation("a",
181 assertNull(annotation.sequenceRef);
182 seq.addAlignmentAnnotation(annotation);
183 assertSame(seq, annotation.sequenceRef);
184 AlignmentAnnotation[] anns = seq.getAnnotation();
185 assertEquals(1, anns.length);
186 assertSame(annotation, anns[0]);
188 // re-adding does nothing
189 seq.addAlignmentAnnotation(annotation);
190 anns = seq.getAnnotation();
191 assertEquals(1, anns.length);
192 assertSame(annotation, anns[0]);
194 // an identical but different annotation can be added
195 final AlignmentAnnotation annotation2 = new AlignmentAnnotation("a",
197 seq.addAlignmentAnnotation(annotation2);
198 anns = seq.getAnnotation();
199 assertEquals(2, anns.length);
200 assertSame(annotation, anns[0]);
201 assertSame(annotation2, anns[1]);
204 @Test(groups = { "Functional" })
205 public void testGetStartGetEnd()
207 SequenceI sq = new Sequence("test", "ABCDEF");
208 assertEquals(1, sq.getStart());
209 assertEquals(6, sq.getEnd());
211 sq = new Sequence("test", "--AB-C-DEF--");
212 assertEquals(1, sq.getStart());
213 assertEquals(6, sq.getEnd());
215 sq = new Sequence("test", "----");
216 assertEquals(1, sq.getStart());
217 assertEquals(0, sq.getEnd()); // ??
221 * Tests for the method that returns an alignment column position (base 1) for
222 * a given sequence position (base 1).
224 @Test(groups = { "Functional" })
225 public void testFindIndex()
227 SequenceI sq = new Sequence("test", "ABCDEF");
228 assertEquals(0, sq.findIndex(0));
229 PA.setValue(sq, "cursor", null);
230 assertEquals(1, sq.findIndex(1));
231 PA.setValue(sq, "cursor", null);
232 assertEquals(5, sq.findIndex(5));
233 PA.setValue(sq, "cursor", null);
234 assertEquals(6, sq.findIndex(6));
235 PA.setValue(sq, "cursor", null);
236 assertEquals(6, sq.findIndex(9));
238 sq = new Sequence("test/8-13", "-A--B-C-D-E-F--");
239 assertEquals(2, sq.findIndex(8));
240 PA.setValue(sq, "cursor", null);
241 assertEquals(5, sq.findIndex(9));
242 PA.setValue(sq, "cursor", null);
243 assertEquals(7, sq.findIndex(10));
245 // before start returns 0
246 PA.setValue(sq, "cursor", null);
247 assertEquals(0, sq.findIndex(0));
248 PA.setValue(sq, "cursor", null);
249 assertEquals(0, sq.findIndex(-1));
251 // beyond end returns last residue column
252 PA.setValue(sq, "cursor", null);
253 assertEquals(13, sq.findIndex(99));
257 * Tests for the method that returns a dataset sequence position (base 1) for
258 * an aligned column position (base 0).
260 @Test(groups = { "Functional" })
261 public void testFindPosition()
263 SequenceI sq = new Sequence("test", "ABCDEF");
264 assertEquals(1, sq.findPosition(0));
265 assertEquals(6, sq.findPosition(5));
266 // assertEquals(-1, seq.findPosition(6)); // fails
268 sq = new Sequence("test", "AB-C-D--");
269 assertEquals(1, sq.findPosition(0));
270 assertEquals(2, sq.findPosition(1));
271 // gap position 'finds' residue to the right (not the left as per javadoc)
272 assertEquals(3, sq.findPosition(2));
273 assertEquals(3, sq.findPosition(3));
274 assertEquals(4, sq.findPosition(4));
275 assertEquals(4, sq.findPosition(5));
276 // returns 1 more than sequence length if off the end ?!?
277 assertEquals(5, sq.findPosition(6));
278 assertEquals(5, sq.findPosition(7));
280 sq = new Sequence("test", "--AB-C-DEF--");
281 assertEquals(1, sq.findPosition(0));
282 assertEquals(1, sq.findPosition(1));
283 assertEquals(1, sq.findPosition(2));
284 assertEquals(2, sq.findPosition(3));
285 assertEquals(3, sq.findPosition(4));
286 assertEquals(3, sq.findPosition(5));
287 assertEquals(4, sq.findPosition(6));
288 assertEquals(4, sq.findPosition(7));
289 assertEquals(5, sq.findPosition(8));
290 assertEquals(6, sq.findPosition(9));
291 assertEquals(7, sq.findPosition(10));
292 assertEquals(7, sq.findPosition(11));
295 @Test(groups = { "Functional" })
296 public void testDeleteChars()
301 SequenceI sq = new Sequence("test", "ABCDEF");
302 assertNull(PA.getValue(sq, "datasetSequence"));
303 assertEquals(1, sq.getStart());
304 assertEquals(6, sq.getEnd());
305 sq.deleteChars(2, 3);
306 assertEquals("ABDEF", sq.getSequenceAsString());
307 assertEquals(1, sq.getStart());
308 assertEquals(5, sq.getEnd());
309 assertNull(PA.getValue(sq, "datasetSequence"));
314 sq = new Sequence("test", "ABCDEF");
315 sq.deleteChars(0, 2);
316 assertEquals("CDEF", sq.getSequenceAsString());
317 assertEquals(3, sq.getStart());
318 assertEquals(6, sq.getEnd());
319 assertNull(PA.getValue(sq, "datasetSequence"));
324 sq = new Sequence("test", "ABCDEF");
325 sq.deleteChars(4, 6);
326 assertEquals("ABCD", sq.getSequenceAsString());
327 assertEquals(1, sq.getStart());
328 assertEquals(4, sq.getEnd());
329 assertNull(PA.getValue(sq, "datasetSequence"));
332 @Test(groups = { "Functional" })
333 public void testDeleteChars_withDbRefsAndFeatures()
336 * internal delete - new dataset sequence created
337 * gets a copy of any dbrefs
339 SequenceI sq = new Sequence("test", "ABCDEF");
340 sq.createDatasetSequence();
341 DBRefEntry dbr1 = new DBRefEntry("Uniprot", "0", "a123");
343 Object ds = PA.getValue(sq, "datasetSequence");
345 assertEquals(1, sq.getStart());
346 assertEquals(6, sq.getEnd());
347 sq.deleteChars(2, 3);
348 assertEquals("ABDEF", sq.getSequenceAsString());
349 assertEquals(1, sq.getStart());
350 assertEquals(5, sq.getEnd());
351 Object newDs = PA.getValue(sq, "datasetSequence");
352 assertNotNull(newDs);
353 assertNotSame(ds, newDs);
354 assertNotNull(sq.getDBRefs());
355 assertEquals(1, sq.getDBRefs().length);
356 assertNotSame(dbr1, sq.getDBRefs()[0]);
357 assertEquals(dbr1, sq.getDBRefs()[0]);
360 * internal delete with sequence features
361 * (failure case for JAL-2541)
363 sq = new Sequence("test", "ABCDEF");
364 sq.createDatasetSequence();
365 SequenceFeature sf1 = new SequenceFeature("Cath", "desc", 2, 4, 2f,
367 sq.addSequenceFeature(sf1);
368 ds = PA.getValue(sq, "datasetSequence");
370 assertEquals(1, sq.getStart());
371 assertEquals(6, sq.getEnd());
372 sq.deleteChars(2, 4);
373 assertEquals("ABEF", sq.getSequenceAsString());
374 assertEquals(1, sq.getStart());
375 assertEquals(4, sq.getEnd());
376 newDs = PA.getValue(sq, "datasetSequence");
377 assertNotNull(newDs);
378 assertNotSame(ds, newDs);
379 List<SequenceFeature> sfs = sq.getSequenceFeatures();
380 assertEquals(1, sfs.size());
381 assertNotSame(sf1, sfs.get(0));
382 assertEquals(sf1, sfs.get(0));
385 * delete at start - no new dataset sequence created
386 * any sequence features remain as before
388 sq = new Sequence("test", "ABCDEF");
389 sq.createDatasetSequence();
390 ds = PA.getValue(sq, "datasetSequence");
391 sf1 = new SequenceFeature("Cath", "desc", 2, 4, 2f, "CathGroup");
392 sq.addSequenceFeature(sf1);
393 sq.deleteChars(0, 2);
394 assertEquals("CDEF", sq.getSequenceAsString());
395 assertEquals(3, sq.getStart());
396 assertEquals(6, sq.getEnd());
397 assertSame(ds, PA.getValue(sq, "datasetSequence"));
398 sfs = sq.getSequenceFeatures();
400 assertEquals(1, sfs.size());
401 assertSame(sf1, sfs.get(0));
404 * delete at end - no new dataset sequence created
405 * any dbrefs remain as before
407 sq = new Sequence("test", "ABCDEF");
408 sq.createDatasetSequence();
409 ds = PA.getValue(sq, "datasetSequence");
410 dbr1 = new DBRefEntry("Uniprot", "0", "a123");
412 sq.deleteChars(4, 6);
413 assertEquals("ABCD", sq.getSequenceAsString());
414 assertEquals(1, sq.getStart());
415 assertEquals(4, sq.getEnd());
416 assertSame(ds, PA.getValue(sq, "datasetSequence"));
417 assertNotNull(sq.getDBRefs());
418 assertEquals(1, sq.getDBRefs().length);
419 assertSame(dbr1, sq.getDBRefs()[0]);
422 @Test(groups = { "Functional" })
423 public void testInsertCharAt()
425 // non-static methods:
426 SequenceI sq = new Sequence("test", "ABCDEF");
427 sq.insertCharAt(0, 'z');
428 assertEquals("zABCDEF", sq.getSequenceAsString());
429 sq.insertCharAt(2, 2, 'x');
430 assertEquals("zAxxBCDEF", sq.getSequenceAsString());
432 // for static method see StringUtilsTest
436 * Test the method that returns an array of aligned sequence positions where
437 * the array index is the data sequence position (both base 0).
439 @Test(groups = { "Functional" })
440 public void testGapMap()
442 SequenceI sq = new Sequence("test", "-A--B-CD-E--F-");
443 sq.createDatasetSequence();
444 assertEquals("[1, 4, 6, 7, 9, 12]", Arrays.toString(sq.gapMap()));
448 * Test the method that gets sequence features, either from the sequence or
451 @Test(groups = { "Functional" })
452 public void testGetSequenceFeatures()
454 SequenceI sq = new Sequence("test", "GATCAT");
455 sq.createDatasetSequence();
457 assertTrue(sq.getSequenceFeatures().isEmpty());
460 * SequenceFeature on sequence
462 SequenceFeature sf = new SequenceFeature("Cath", "desc", 2, 4, 2f, null);
463 sq.addSequenceFeature(sf);
464 List<SequenceFeature> sfs = sq.getSequenceFeatures();
465 assertEquals(1, sfs.size());
466 assertSame(sf, sfs.get(0));
469 * SequenceFeature on sequence and dataset sequence; returns that on
472 * Note JAL-2046: spurious: we have no use case for this at the moment.
473 * This test also buggy - as sf2.equals(sf), no new feature is added
475 SequenceFeature sf2 = new SequenceFeature("Cath", "desc", 2, 4, 2f,
477 sq.getDatasetSequence().addSequenceFeature(sf2);
478 sfs = sq.getSequenceFeatures();
479 assertEquals(1, sfs.size());
480 assertSame(sf, sfs.get(0));
483 * SequenceFeature on dataset sequence only
484 * Note JAL-2046: spurious: we have no use case for setting a non-dataset sequence's feature array to null at the moment.
486 sq.setSequenceFeatures(null);
487 assertTrue(sq.getDatasetSequence().getSequenceFeatures().isEmpty());
490 * Corrupt case - no SequenceFeature, dataset's dataset is the original
491 * sequence. Test shows no infinite loop results.
493 sq.getDatasetSequence().setSequenceFeatures(null);
495 * is there a usecase for this ? setDatasetSequence should throw an error if
496 * this actually occurs.
500 sq.getDatasetSequence().setDatasetSequence(sq); // loop!
501 Assert.fail("Expected Error to be raised when calling setDatasetSequence with self reference");
502 } catch (IllegalArgumentException e)
504 // TODO Jalview error/exception class for raising implementation errors
505 assertTrue(e.getMessage().toLowerCase()
506 .contains("implementation error"));
508 assertTrue(sq.getSequenceFeatures().isEmpty());
512 * Test the method that returns an array, indexed by sequence position, whose
513 * entries are the residue positions at the sequence position (or to the right
516 @Test(groups = { "Functional" })
517 public void testFindPositionMap()
520 * Note: Javadoc for findPosition says it returns the residue position to
521 * the left of a gapped position; in fact it returns the position to the
522 * right. Also it returns a non-existent residue position for a gap beyond
525 Sequence sq = new Sequence("TestSeq", "AB.C-D E.");
526 int[] map = sq.findPositionMap();
527 assertEquals(Arrays.toString(new int[] { 1, 2, 3, 3, 4, 4, 5, 5, 6 }),
528 Arrays.toString(map));
532 * Test for getSubsequence
534 @Test(groups = { "Functional" })
535 public void testGetSubsequence()
537 SequenceI sq = new Sequence("TestSeq", "ABCDEFG");
538 sq.createDatasetSequence();
540 // positions are base 0, end position is exclusive
541 SequenceI subseq = sq.getSubSequence(2, 4);
543 assertEquals("CD", subseq.getSequenceAsString());
544 // start/end are base 1 positions
545 assertEquals(3, subseq.getStart());
546 assertEquals(4, subseq.getEnd());
547 // subsequence shares the full dataset sequence
548 assertSame(sq.getDatasetSequence(), subseq.getDatasetSequence());
552 * test createDatasetSequence behaves to doc
554 @Test(groups = { "Functional" })
555 public void testCreateDatasetSequence()
557 SequenceI sq = new Sequence("my", "ASDASD");
558 sq.addSequenceFeature(new SequenceFeature("type", "desc", 1, 10, 1f,
560 sq.addDBRef(new DBRefEntry("source", "version", "accession"));
561 assertNull(sq.getDatasetSequence());
562 assertNotNull(PA.getValue(sq, "sequenceFeatureStore"));
563 assertNotNull(PA.getValue(sq, "dbrefs"));
565 SequenceI rds = sq.createDatasetSequence();
567 assertNull(rds.getDatasetSequence());
568 assertSame(sq.getDatasetSequence(), rds);
570 // sequence features and dbrefs transferred to dataset sequence
571 assertNull(PA.getValue(sq, "sequenceFeatureStore"));
572 assertNull(PA.getValue(sq, "dbrefs"));
573 assertNotNull(PA.getValue(rds, "sequenceFeatureStore"));
574 assertNotNull(PA.getValue(rds, "dbrefs"));
578 * Test for deriveSequence applied to a sequence with a dataset
580 @Test(groups = { "Functional" })
581 public void testDeriveSequence_existingDataset()
583 Sequence sq = new Sequence("Seq1", "CD");
584 sq.setDatasetSequence(new Sequence("Seq1", "ABCDEF"));
585 sq.getDatasetSequence().addSequenceFeature(
586 new SequenceFeature("", "", 1, 2, 0f, null));
590 sq.setDescription("Test sequence description..");
591 sq.setVamsasId("TestVamsasId");
592 sq.addDBRef(new DBRefEntry("PDB", "version0", "1TST"));
594 sq.addDBRef(new DBRefEntry("PDB", "version1", "1PDB"));
595 sq.addDBRef(new DBRefEntry("PDB", "version2", "2PDB"));
596 sq.addDBRef(new DBRefEntry("PDB", "version3", "3PDB"));
597 sq.addDBRef(new DBRefEntry("PDB", "version4", "4PDB"));
599 sq.addPDBId(new PDBEntry("1PDB", "A", Type.PDB, "filePath/test1"));
600 sq.addPDBId(new PDBEntry("1PDB", "B", Type.PDB, "filePath/test1"));
601 sq.addPDBId(new PDBEntry("2PDB", "A", Type.MMCIF, "filePath/test2"));
602 sq.addPDBId(new PDBEntry("2PDB", "B", Type.MMCIF, "filePath/test2"));
604 // these are the same as ones already added
605 DBRefEntry pdb1pdb = new DBRefEntry("PDB", "version1", "1PDB");
606 DBRefEntry pdb2pdb = new DBRefEntry("PDB", "version2", "2PDB");
608 List<DBRefEntry> primRefs = Arrays.asList(new DBRefEntry[] { pdb1pdb,
611 sq.getDatasetSequence().addDBRef(pdb1pdb); // should do nothing
612 sq.getDatasetSequence().addDBRef(pdb2pdb); // should do nothing
613 sq.getDatasetSequence().addDBRef(
614 new DBRefEntry("PDB", "version3", "3PDB")); // should do nothing
615 sq.getDatasetSequence().addDBRef(
616 new DBRefEntry("PDB", "version4", "4PDB")); // should do nothing
618 PDBEntry pdbe1a = new PDBEntry("1PDB", "A", Type.PDB, "filePath/test1");
619 PDBEntry pdbe1b = new PDBEntry("1PDB", "B", Type.PDB, "filePath/test1");
620 PDBEntry pdbe2a = new PDBEntry("2PDB", "A", Type.MMCIF,
622 PDBEntry pdbe2b = new PDBEntry("2PDB", "B", Type.MMCIF,
624 sq.getDatasetSequence().addPDBId(pdbe1a);
625 sq.getDatasetSequence().addPDBId(pdbe1b);
626 sq.getDatasetSequence().addPDBId(pdbe2a);
627 sq.getDatasetSequence().addPDBId(pdbe2b);
630 * test we added pdb entries to the dataset sequence
632 Assert.assertEquals(sq.getDatasetSequence().getAllPDBEntries(), Arrays
633 .asList(new PDBEntry[] { pdbe1a, pdbe1b, pdbe2a, pdbe2b }),
634 "PDB Entries were not found on dataset sequence.");
637 * we should recover a pdb entry that is on the dataset sequence via PDBEntry
639 Assert.assertEquals(pdbe1a,
640 sq.getDatasetSequence().getPDBEntry("1PDB"),
641 "PDB Entry '1PDB' not found on dataset sequence via getPDBEntry.");
642 ArrayList<Annotation> annotsList = new ArrayList<Annotation>();
643 System.out.println(">>>>>> " + sq.getSequenceAsString().length());
644 annotsList.add(new Annotation("A", "A", 'X', 0.1f));
645 annotsList.add(new Annotation("A", "A", 'X', 0.1f));
646 Annotation[] annots = annotsList.toArray(new Annotation[0]);
647 sq.addAlignmentAnnotation(new AlignmentAnnotation("Test annot",
648 "Test annot description", annots));
649 sq.getDatasetSequence().addAlignmentAnnotation(
650 new AlignmentAnnotation("Test annot", "Test annot description",
652 Assert.assertEquals(sq.getDescription(), "Test sequence description..");
653 Assert.assertEquals(sq.getDBRefs().length, 5); // DBRefs are on dataset
655 Assert.assertEquals(sq.getAllPDBEntries().size(), 4);
656 Assert.assertNotNull(sq.getAnnotation());
657 Assert.assertEquals(sq.getAnnotation()[0].annotations.length, 2);
658 Assert.assertEquals(sq.getDatasetSequence().getDBRefs().length, 5); // same
661 Assert.assertEquals(sq.getDatasetSequence().getAllPDBEntries().size(),
663 Assert.assertNotNull(sq.getDatasetSequence().getAnnotation());
665 Sequence derived = (Sequence) sq.deriveSequence();
667 Assert.assertEquals(derived.getDescription(),
668 "Test sequence description..");
669 Assert.assertEquals(derived.getDBRefs().length, 5); // come from dataset
670 Assert.assertEquals(derived.getAllPDBEntries().size(), 4);
671 Assert.assertNotNull(derived.getAnnotation());
672 Assert.assertEquals(derived.getAnnotation()[0].annotations.length, 2);
673 Assert.assertEquals(derived.getDatasetSequence().getDBRefs().length, 5);
674 Assert.assertEquals(derived.getDatasetSequence().getAllPDBEntries()
676 Assert.assertNotNull(derived.getDatasetSequence().getAnnotation());
678 assertEquals("CD", derived.getSequenceAsString());
679 assertSame(sq.getDatasetSequence(), derived.getDatasetSequence());
681 // derived sequence should access dataset sequence features
682 assertNotNull(sq.getSequenceFeatures());
683 assertEquals(sq.getSequenceFeatures(), derived.getSequenceFeatures());
686 * verify we have primary db refs *just* for PDB IDs with associated
690 assertEquals(primRefs, sq.getPrimaryDBRefs());
691 assertEquals(primRefs, sq.getDatasetSequence().getPrimaryDBRefs());
693 assertEquals(sq.getPrimaryDBRefs(), derived.getPrimaryDBRefs());
698 * Test for deriveSequence applied to an ungapped sequence with no dataset
700 @Test(groups = { "Functional" })
701 public void testDeriveSequence_noDatasetUngapped()
703 SequenceI sq = new Sequence("Seq1", "ABCDEF");
704 assertEquals(1, sq.getStart());
705 assertEquals(6, sq.getEnd());
706 SequenceI derived = sq.deriveSequence();
707 assertEquals("ABCDEF", derived.getSequenceAsString());
708 assertEquals("ABCDEF", derived.getDatasetSequence()
709 .getSequenceAsString());
713 * Test for deriveSequence applied to a gapped sequence with no dataset
715 @Test(groups = { "Functional" })
716 public void testDeriveSequence_noDatasetGapped()
718 SequenceI sq = new Sequence("Seq1", "AB-C.D EF");
719 assertEquals(1, sq.getStart());
720 assertEquals(6, sq.getEnd());
721 assertNull(sq.getDatasetSequence());
722 SequenceI derived = sq.deriveSequence();
723 assertEquals("AB-C.D EF", derived.getSequenceAsString());
724 assertEquals("ABCDEF", derived.getDatasetSequence()
725 .getSequenceAsString());
728 @Test(groups = { "Functional" })
729 public void testCopyConstructor_noDataset()
731 SequenceI seq1 = new Sequence("Seq1", "AB-C.D EF");
732 seq1.setDescription("description");
733 seq1.addAlignmentAnnotation(new AlignmentAnnotation("label", "desc",
735 seq1.addSequenceFeature(new SequenceFeature("type", "desc", 22, 33,
737 seq1.addPDBId(new PDBEntry("1A70", "B", Type.PDB, "File"));
738 seq1.addDBRef(new DBRefEntry("EMBL", "1.2", "AZ12345"));
740 SequenceI copy = new Sequence(seq1);
742 assertNull(copy.getDatasetSequence());
744 verifyCopiedSequence(seq1, copy);
746 // copy has a copy of the DBRefEntry
747 // this is murky - DBrefs are only copied for dataset sequences
748 // where the test for 'dataset sequence' is 'dataset is null'
749 // but that doesn't distinguish it from an aligned sequence
750 // which has not yet generated a dataset sequence
751 // NB getDBRef looks inside dataset sequence if not null
752 DBRefEntry[] dbrefs = copy.getDBRefs();
753 assertEquals(1, dbrefs.length);
754 assertFalse(dbrefs[0] == seq1.getDBRefs()[0]);
755 assertTrue(dbrefs[0].equals(seq1.getDBRefs()[0]));
758 @Test(groups = { "Functional" })
759 public void testCopyConstructor_withDataset()
761 SequenceI seq1 = new Sequence("Seq1", "AB-C.D EF");
762 seq1.createDatasetSequence();
763 seq1.setDescription("description");
764 seq1.addAlignmentAnnotation(new AlignmentAnnotation("label", "desc",
766 // JAL-2046 - what is the contract for using a derived sequence's
767 // addSequenceFeature ?
768 seq1.addSequenceFeature(new SequenceFeature("type", "desc", 22, 33,
770 seq1.addPDBId(new PDBEntry("1A70", "B", Type.PDB, "File"));
771 // here we add DBRef to the dataset sequence:
772 seq1.getDatasetSequence().addDBRef(
773 new DBRefEntry("EMBL", "1.2", "AZ12345"));
775 SequenceI copy = new Sequence(seq1);
777 assertNotNull(copy.getDatasetSequence());
778 assertSame(copy.getDatasetSequence(), seq1.getDatasetSequence());
780 verifyCopiedSequence(seq1, copy);
782 // getDBRef looks inside dataset sequence and this is shared,
783 // so holds the same dbref objects
784 DBRefEntry[] dbrefs = copy.getDBRefs();
785 assertEquals(1, dbrefs.length);
786 assertSame(dbrefs[0], seq1.getDBRefs()[0]);
790 * Helper to make assertions about a copied sequence
795 protected void verifyCopiedSequence(SequenceI seq1, SequenceI copy)
797 // verify basic properties:
798 assertEquals(copy.getName(), seq1.getName());
799 assertEquals(copy.getDescription(), seq1.getDescription());
800 assertEquals(copy.getStart(), seq1.getStart());
801 assertEquals(copy.getEnd(), seq1.getEnd());
802 assertEquals(copy.getSequenceAsString(), seq1.getSequenceAsString());
804 // copy has a copy of the annotation:
805 AlignmentAnnotation[] anns = copy.getAnnotation();
806 assertEquals(1, anns.length);
807 assertFalse(anns[0] == seq1.getAnnotation()[0]);
808 assertEquals(anns[0].label, seq1.getAnnotation()[0].label);
809 assertEquals(anns[0].description, seq1.getAnnotation()[0].description);
810 assertEquals(anns[0].score, seq1.getAnnotation()[0].score);
812 // copy has a copy of the sequence feature:
813 List<SequenceFeature> sfs = copy.getSequenceFeatures();
814 assertEquals(1, sfs.size());
815 if (seq1.getDatasetSequence() != null
816 && copy.getDatasetSequence() == seq1.getDatasetSequence())
818 assertSame(sfs.get(0), seq1.getSequenceFeatures().get(0));
822 assertNotSame(sfs.get(0), seq1.getSequenceFeatures().get(0));
824 assertEquals(sfs.get(0), seq1.getSequenceFeatures().get(0));
826 // copy has a copy of the PDB entry
827 Vector<PDBEntry> pdbs = copy.getAllPDBEntries();
828 assertEquals(1, pdbs.size());
829 assertFalse(pdbs.get(0) == seq1.getAllPDBEntries().get(0));
830 assertTrue(pdbs.get(0).equals(seq1.getAllPDBEntries().get(0)));
833 @Test(groups = "Functional")
834 public void testGetCharAt()
836 SequenceI sq = new Sequence("", "abcde");
837 assertEquals('a', sq.getCharAt(0));
838 assertEquals('e', sq.getCharAt(4));
839 assertEquals(' ', sq.getCharAt(5));
840 assertEquals(' ', sq.getCharAt(-1));
843 @Test(groups = { "Functional" })
844 public void testAddSequenceFeatures()
846 SequenceI sq = new Sequence("", "abcde");
847 // type may not be null
848 assertFalse(sq.addSequenceFeature(new SequenceFeature(null, "desc", 4,
850 assertTrue(sq.addSequenceFeature(new SequenceFeature("Cath", "desc", 4,
852 // can't add a duplicate feature
853 assertFalse(sq.addSequenceFeature(new SequenceFeature("Cath", "desc",
855 // can add a different feature
856 assertTrue(sq.addSequenceFeature(new SequenceFeature("Scop", "desc", 4,
857 8, 0f, null))); // different type
858 assertTrue(sq.addSequenceFeature(new SequenceFeature("Cath",
859 "description", 4, 8, 0f, null)));// different description
860 assertTrue(sq.addSequenceFeature(new SequenceFeature("Cath", "desc", 3,
861 8, 0f, null))); // different start position
862 assertTrue(sq.addSequenceFeature(new SequenceFeature("Cath", "desc", 4,
863 9, 0f, null))); // different end position
864 assertTrue(sq.addSequenceFeature(new SequenceFeature("Cath", "desc", 4,
865 8, 1f, null))); // different score
866 assertTrue(sq.addSequenceFeature(new SequenceFeature("Cath", "desc", 4,
867 8, Float.NaN, null))); // score NaN
868 assertTrue(sq.addSequenceFeature(new SequenceFeature("Cath", "desc", 4,
869 8, 0f, "Metal"))); // different group
870 assertEquals(8, sq.getFeatures().getAllFeatures().size());
874 * Tests for adding (or updating) dbrefs
876 * @see DBRefEntry#updateFrom(DBRefEntry)
878 @Test(groups = { "Functional" })
879 public void testAddDBRef()
881 SequenceI sq = new Sequence("", "abcde");
882 assertNull(sq.getDBRefs());
883 DBRefEntry dbref = new DBRefEntry("Uniprot", "1", "P00340");
885 assertEquals(1, sq.getDBRefs().length);
886 assertSame(dbref, sq.getDBRefs()[0]);
889 * change of version - new entry
891 DBRefEntry dbref2 = new DBRefEntry("Uniprot", "2", "P00340");
893 assertEquals(2, sq.getDBRefs().length);
894 assertSame(dbref, sq.getDBRefs()[0]);
895 assertSame(dbref2, sq.getDBRefs()[1]);
898 * matches existing entry - not added
900 sq.addDBRef(new DBRefEntry("UNIPROT", "1", "p00340"));
901 assertEquals(2, sq.getDBRefs().length);
904 * different source = new entry
906 DBRefEntry dbref3 = new DBRefEntry("UniRef", "1", "p00340");
908 assertEquals(3, sq.getDBRefs().length);
909 assertSame(dbref3, sq.getDBRefs()[2]);
912 * different ref = new entry
914 DBRefEntry dbref4 = new DBRefEntry("UniRef", "1", "p00341");
916 assertEquals(4, sq.getDBRefs().length);
917 assertSame(dbref4, sq.getDBRefs()[3]);
920 * matching ref with a mapping - map updated
922 DBRefEntry dbref5 = new DBRefEntry("UniRef", "1", "p00341");
923 Mapping map = new Mapping(new MapList(new int[] { 1, 3 }, new int[] {
927 assertEquals(4, sq.getDBRefs().length);
928 assertSame(dbref4, sq.getDBRefs()[3]);
929 assertSame(map, dbref4.getMap());
932 * 'real' version replaces "0" version
934 dbref2.setVersion("0");
935 DBRefEntry dbref6 = new DBRefEntry(dbref2.getSource(), "3",
936 dbref2.getAccessionId());
938 assertEquals(4, sq.getDBRefs().length);
939 assertSame(dbref2, sq.getDBRefs()[1]);
940 assertEquals("3", dbref2.getVersion());
943 * 'real' version replaces "source:0" version
945 dbref3.setVersion("Uniprot:0");
946 DBRefEntry dbref7 = new DBRefEntry(dbref3.getSource(), "3",
947 dbref3.getAccessionId());
949 assertEquals(4, sq.getDBRefs().length);
950 assertSame(dbref3, sq.getDBRefs()[2]);
951 assertEquals("3", dbref2.getVersion());
954 @Test(groups = { "Functional" })
955 public void testGetPrimaryDBRefs_peptide()
957 SequenceI sq = new Sequence("aseq", "ASDFKYLMQPRST", 10, 22);
960 List<DBRefEntry> primaryDBRefs = sq.getPrimaryDBRefs();
961 assertTrue(primaryDBRefs.isEmpty());
964 sq.setDBRefs(new DBRefEntry[] {});
965 primaryDBRefs = sq.getPrimaryDBRefs();
966 assertTrue(primaryDBRefs.isEmpty());
969 DBRefEntry upentry1 = new DBRefEntry("UNIPROT", "0", "Q04760");
970 sq.addDBRef(upentry1);
972 // primary - uniprot with congruent map
973 DBRefEntry upentry2 = new DBRefEntry("UNIPROT", "0", "Q04762");
974 upentry2.setMap(new Mapping(null, new MapList(new int[] { 10, 22 },
975 new int[] { 10, 22 }, 1, 1)));
976 sq.addDBRef(upentry2);
978 // primary - uniprot with map of enclosing sequence
979 DBRefEntry upentry3 = new DBRefEntry("UNIPROT", "0", "Q04763");
980 upentry3.setMap(new Mapping(null, new MapList(new int[] { 8, 24 },
981 new int[] { 8, 24 }, 1, 1)));
982 sq.addDBRef(upentry3);
984 // not primary - uniprot with map of sub-sequence (5')
985 DBRefEntry upentry4 = new DBRefEntry("UNIPROT", "0", "Q04764");
986 upentry4.setMap(new Mapping(null, new MapList(new int[] { 10, 18 },
987 new int[] { 10, 18 }, 1, 1)));
988 sq.addDBRef(upentry4);
990 // not primary - uniprot with map that overlaps 3'
991 DBRefEntry upentry5 = new DBRefEntry("UNIPROT", "0", "Q04765");
992 upentry5.setMap(new Mapping(null, new MapList(new int[] { 12, 22 },
993 new int[] { 12, 22 }, 1, 1)));
994 sq.addDBRef(upentry5);
996 // not primary - uniprot with map to different coordinates frame
997 DBRefEntry upentry6 = new DBRefEntry("UNIPROT", "0", "Q04766");
998 upentry6.setMap(new Mapping(null, new MapList(new int[] { 12, 18 },
999 new int[] { 112, 118 }, 1, 1)));
1000 sq.addDBRef(upentry6);
1002 // not primary - dbref to 'non-core' database
1003 DBRefEntry upentry7 = new DBRefEntry("Pfam", "0", "PF00903");
1004 sq.addDBRef(upentry7);
1006 // primary - type is PDB
1007 DBRefEntry pdbentry = new DBRefEntry("PDB", "0", "1qip");
1008 sq.addDBRef(pdbentry);
1010 // not primary - PDBEntry has no file
1011 sq.addDBRef(new DBRefEntry("PDB", "0", "1AAA"));
1013 // not primary - no PDBEntry
1014 sq.addDBRef(new DBRefEntry("PDB", "0", "1DDD"));
1016 // add corroborating PDB entry for primary DBref -
1017 // needs to have a file as well as matching ID
1018 // note PDB ID is not treated as case sensitive
1019 sq.addPDBId(new PDBEntry("1QIP", null, Type.PDB, new File("/blah")
1022 // not valid DBRef - no file..
1023 sq.addPDBId(new PDBEntry("1AAA", null, null, null));
1025 primaryDBRefs = sq.getPrimaryDBRefs();
1026 assertEquals(4, primaryDBRefs.size());
1027 assertTrue("Couldn't find simple primary reference (UNIPROT)",
1028 primaryDBRefs.contains(upentry1));
1029 assertTrue("Couldn't find mapped primary reference (UNIPROT)",
1030 primaryDBRefs.contains(upentry2));
1031 assertTrue("Couldn't find mapped context reference (UNIPROT)",
1032 primaryDBRefs.contains(upentry3));
1033 assertTrue("Couldn't find expected PDB primary reference",
1034 primaryDBRefs.contains(pdbentry));
1037 @Test(groups = { "Functional" })
1038 public void testGetPrimaryDBRefs_nucleotide()
1040 SequenceI sq = new Sequence("aseq", "TGATCACTCGACTAGCATCAGCATA", 10, 34);
1042 // primary - Ensembl
1043 DBRefEntry dbr1 = new DBRefEntry("ENSEMBL", "0", "ENSG1234");
1046 // not primary - Ensembl 'transcript' mapping of sub-sequence
1047 DBRefEntry dbr2 = new DBRefEntry("ENSEMBL", "0", "ENST1234");
1048 dbr2.setMap(new Mapping(null, new MapList(new int[] { 15, 25 },
1049 new int[] { 1, 11 }, 1, 1)));
1052 // primary - EMBL with congruent map
1053 DBRefEntry dbr3 = new DBRefEntry("EMBL", "0", "J1234");
1054 dbr3.setMap(new Mapping(null, new MapList(new int[] { 10, 34 },
1055 new int[] { 10, 34 }, 1, 1)));
1058 // not primary - to non-core database
1059 DBRefEntry dbr4 = new DBRefEntry("CCDS", "0", "J1234");
1062 // not primary - to protein
1063 DBRefEntry dbr5 = new DBRefEntry("UNIPROT", "0", "Q87654");
1066 List<DBRefEntry> primaryDBRefs = sq.getPrimaryDBRefs();
1067 assertEquals(2, primaryDBRefs.size());
1068 assertTrue(primaryDBRefs.contains(dbr1));
1069 assertTrue(primaryDBRefs.contains(dbr3));
1073 * Test the method that updates the list of PDBEntry from any new DBRefEntry
1076 @Test(groups = { "Functional" })
1077 public void testUpdatePDBIds()
1079 PDBEntry pdbe1 = new PDBEntry("3A6S", null, null, null);
1080 seq.addPDBId(pdbe1);
1081 seq.addDBRef(new DBRefEntry("Ensembl", "8", "ENST1234"));
1082 seq.addDBRef(new DBRefEntry("PDB", "0", "1A70"));
1083 seq.addDBRef(new DBRefEntry("PDB", "0", "4BQGa"));
1084 seq.addDBRef(new DBRefEntry("PDB", "0", "3a6sB"));
1085 // 7 is not a valid chain code:
1086 seq.addDBRef(new DBRefEntry("PDB", "0", "2GIS7"));
1089 List<PDBEntry> pdbIds = seq.getAllPDBEntries();
1090 assertEquals(4, pdbIds.size());
1091 assertSame(pdbe1, pdbIds.get(0));
1092 // chain code got added to 3A6S:
1093 assertEquals("B", pdbe1.getChainCode());
1094 assertEquals("1A70", pdbIds.get(1).getId());
1095 // 4BQGA is parsed into id + chain
1096 assertEquals("4BQG", pdbIds.get(2).getId());
1097 assertEquals("a", pdbIds.get(2).getChainCode());
1098 assertEquals("2GIS7", pdbIds.get(3).getId());
1099 assertNull(pdbIds.get(3).getChainCode());
1103 * Test the method that either adds a pdbid or updates an existing one
1105 @Test(groups = { "Functional" })
1106 public void testAddPDBId()
1108 PDBEntry pdbe = new PDBEntry("3A6S", null, null, null);
1110 assertEquals(1, seq.getAllPDBEntries().size());
1111 assertSame(pdbe, seq.getPDBEntry("3A6S"));
1112 assertSame(pdbe, seq.getPDBEntry("3a6s")); // case-insensitive
1114 // add the same entry
1116 assertEquals(1, seq.getAllPDBEntries().size());
1117 assertSame(pdbe, seq.getPDBEntry("3A6S"));
1119 // add an identical entry
1120 seq.addPDBId(new PDBEntry("3A6S", null, null, null));
1121 assertEquals(1, seq.getAllPDBEntries().size());
1122 assertSame(pdbe, seq.getPDBEntry("3A6S"));
1124 // add a different entry
1125 PDBEntry pdbe2 = new PDBEntry("1A70", null, null, null);
1126 seq.addPDBId(pdbe2);
1127 assertEquals(2, seq.getAllPDBEntries().size());
1128 assertSame(pdbe, seq.getAllPDBEntries().get(0));
1129 assertSame(pdbe2, seq.getAllPDBEntries().get(1));
1131 // update pdbe with chain code, file, type
1132 PDBEntry pdbe3 = new PDBEntry("3a6s", "A", Type.PDB, "filepath");
1133 seq.addPDBId(pdbe3);
1134 assertEquals(2, seq.getAllPDBEntries().size());
1135 assertSame(pdbe, seq.getAllPDBEntries().get(0)); // updated in situ
1136 assertEquals("3A6S", pdbe.getId()); // unchanged
1137 assertEquals("A", pdbe.getChainCode()); // updated
1138 assertEquals(Type.PDB.toString(), pdbe.getType()); // updated
1139 assertEquals("filepath", pdbe.getFile()); // updated
1140 assertSame(pdbe2, seq.getAllPDBEntries().get(1));
1142 // add with a different file path
1143 PDBEntry pdbe4 = new PDBEntry("3a6s", "A", Type.PDB, "filepath2");
1144 seq.addPDBId(pdbe4);
1145 assertEquals(3, seq.getAllPDBEntries().size());
1146 assertSame(pdbe4, seq.getAllPDBEntries().get(2));
1148 // add with a different chain code
1149 PDBEntry pdbe5 = new PDBEntry("3a6s", "B", Type.PDB, "filepath");
1150 seq.addPDBId(pdbe5);
1151 assertEquals(4, seq.getAllPDBEntries().size());
1152 assertSame(pdbe5, seq.getAllPDBEntries().get(3));
1156 groups = { "Functional" },
1157 expectedExceptions = { IllegalArgumentException.class })
1158 public void testSetDatasetSequence_toSelf()
1160 seq.setDatasetSequence(seq);
1164 groups = { "Functional" },
1165 expectedExceptions = { IllegalArgumentException.class })
1166 public void testSetDatasetSequence_cascading()
1168 SequenceI seq2 = new Sequence("Seq2", "xyz");
1169 seq2.createDatasetSequence();
1170 seq.setDatasetSequence(seq2);
1174 public void testFindPositions()
1176 SequenceI sq = new Sequence("Seq", "ABC--DE-F", 8, 13);
1178 Range range = sq.findPositions(1, 4); // BC
1179 assertEquals(new Range(9, 10), range);
1181 range = sq.findPositions(2, 4); // C
1182 assertEquals(new Range(10, 10), range);
1184 assertNull(sq.findPositions(3, 4)); // all gaps
1186 range = sq.findPositions(2, 6); // CDE
1187 assertEquals(new Range(10, 12), range);
1189 range = sq.findPositions(3, 7); // DE
1190 assertEquals(new Range(11, 12), range);
1193 @Test(groups = { "Functional" })
1194 public void testFindIndex_withCursor()
1196 Sequence sq = new Sequence("test/8-13", "-A--BCD-EF--");
1199 assertEquals(10, sq.findIndex(13, new SequenceCursor(sq, 8, 2, 0)));
1202 assertEquals(2, sq.findIndex(8, new SequenceCursor(sq, 13, 10, 0)));
1205 assertEquals(6, sq.findIndex(10, new SequenceCursor(sq, 10, 6, 0)));
1208 @Test(groups = { "Functional" })
1209 public void testFindPosition_withCursor()
1211 Sequence sq = new Sequence("test/8-13", "-A--BCD-EF--");
1213 // find F pos given A
1214 assertEquals(13, sq.findPosition(10, new SequenceCursor(sq, 8, 2, 0)));
1216 // find A pos given F
1217 assertEquals(8, sq.findPosition(2, new SequenceCursor(sq, 13, 10, 0)));
1219 // find C pos given C
1220 assertEquals(10, sq.findPosition(6, new SequenceCursor(sq, 10, 6, 0)));
1222 // now the grey area - what residue position for a gapped column? JAL-2562
1224 // find 'residue' for column 3 given cursor for D (so working left)
1225 assertEquals(9, sq.findPosition(3, new SequenceCursor(sq, 11, 7, 0)));
1227 // find 'residue' for column 8 given cursor for D (so working right)
1228 assertEquals(12, sq.findPosition(8, new SequenceCursor(sq, 11, 7, 0)));
1230 // find 'residue' for column 12 given cursor for B
1231 assertEquals(14, sq.findPosition(12, new SequenceCursor(sq, 9, 5, 0)));
1235 public void testFindPositions_withCursor()
1237 Sequence sq = new Sequence("Seq", "ABC--DE-F", 8, 13);
1239 // find positions for columns 1-4 (BC--) given E cursor
1240 Range range = sq.findPositions(1, 4, new SequenceCursor(sq, 12, 7, 0)); // BC
1241 assertEquals(new Range(9, 10), range);
1243 // repeat using B cursor
1244 range = sq.findPositions(1, 4, new SequenceCursor(sq, 9, 2, 0)); // BC
1245 assertEquals(new Range(9, 10), range);
1247 // find positions for columns 2-4 (C--) given A cursor
1248 range = sq.findPositions(2, 4, new SequenceCursor(sq, 8, 1, 0)); // C
1249 assertEquals(new Range(10, 10), range);
1252 assertNull(sq.findPositions(3, 4, new SequenceCursor(sq, 10, 3, 0)));
1253 assertNull(sq.findPositions(3, 4, new SequenceCursor(sq, 12, 7, 0)));
1255 // find positions for columns 2-6 (C--DE) given B cursor
1256 range = sq.findPositions(2, 6, new SequenceCursor(sq, 9, 2, 0)); // CDE
1257 assertEquals(new Range(10, 12), range);
1259 // repeat using C as cursor
1260 range = sq.findPositions(2, 6, new SequenceCursor(sq, 10, 3, 0));
1261 assertEquals(new Range(10, 12), range);
1263 // repeat using D as cursor
1264 range = sq.findPositions(2, 6, new SequenceCursor(sq, 11, 6, 0));
1265 assertEquals(new Range(10, 12), range);
1267 // repeat using E as cursor
1268 range = sq.findPositions(2, 6, new SequenceCursor(sq, 12, 7, 0));
1269 assertEquals(new Range(10, 12), range);
1271 // repeat using F as cursor
1272 range = sq.findPositions(2, 6, new SequenceCursor(sq, 13, 9, 0));
1273 assertEquals(new Range(10, 12), range);