Clover icon

Coverage Report

  1. Project Clover database Thu Aug 13 2020 12:04:21 BST
  2. Package jalview.datamodel

File SequenceTest.java

 

Code metrics

2
1,106
49
1
2,178
1,459
52
0.05
22.57
49
1.06

Classes

Class Line # Actions
SequenceTest 54 1,106 52
0.9680207496.8%
 

Contributing tests

This file is covered by 43 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.datamodel;
22   
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;
30   
31    import jalview.analysis.AlignmentGenerator;
32    import jalview.commands.EditCommand;
33    import jalview.commands.EditCommand.Action;
34    import jalview.datamodel.PDBEntry.Type;
35    import jalview.gui.JvOptionPane;
36    import jalview.util.MapList;
37    import jalview.ws.params.InvalidArgumentException;
38   
39    import java.io.File;
40    import java.util.ArrayList;
41    import java.util.Arrays;
42    import java.util.BitSet;
43    import java.util.Iterator;
44    import java.util.List;
45    import java.util.Vector;
46   
47    import org.testng.Assert;
48    import org.testng.annotations.BeforeClass;
49    import org.testng.annotations.BeforeMethod;
50    import org.testng.annotations.Test;
51   
52    import junit.extensions.PA;
53   
 
54    public class SequenceTest
55    {
 
56  1 toggle @BeforeClass(alwaysRun = true)
57    public void setUpJvOptionPane()
58    {
59  1 JvOptionPane.setInteractiveMode(false);
60  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
61    }
62   
63    Sequence seq;
64   
 
65  43 toggle @BeforeMethod(alwaysRun = true)
66    public void setUp()
67    {
68  43 seq = new Sequence("FER1", "AKPNGVL");
69    }
70   
 
71  1 toggle @Test(groups = { "Functional" })
72    public void testInsertGapsAndGapmaps()
73    {
74  1 SequenceI aseq = seq.deriveSequence();
75  1 aseq.insertCharAt(2, 3, '-');
76  1 aseq.insertCharAt(6, 3, '-');
77  1 assertEquals("Gap insertions not correct", "AK---P---NGVL",
78    aseq.getSequenceAsString());
79  1 List<int[]> gapInt = aseq.getInsertions();
80  1 assertEquals("Gap interval 1 start wrong", 2, gapInt.get(0)[0]);
81  1 assertEquals("Gap interval 1 end wrong", 4, gapInt.get(0)[1]);
82  1 assertEquals("Gap interval 2 start wrong", 6, gapInt.get(1)[0]);
83  1 assertEquals("Gap interval 2 end wrong", 8, gapInt.get(1)[1]);
84   
85  1 BitSet gapfield = aseq.getInsertionsAsBits();
86  1 BitSet expectedgaps = new BitSet();
87  1 expectedgaps.set(2, 5);
88  1 expectedgaps.set(6, 9);
89   
90  1 assertEquals(6, expectedgaps.cardinality());
91   
92  1 assertEquals("getInsertionsAsBits didn't mark expected number of gaps",
93    6, gapfield.cardinality());
94   
95  1 assertEquals("getInsertionsAsBits not correct.", expectedgaps, gapfield);
96    }
97   
 
98  1 toggle @Test(groups = ("Functional"))
99    public void testIsProtein()
100    {
101    // test Protein
102  1 assertTrue(new Sequence("prot", "ASDFASDFASDF").isProtein());
103    // test DNA
104  1 assertFalse(new Sequence("prot", "ACGTACGTACGT").isProtein());
105    // test RNA
106  1 SequenceI sq = new Sequence("prot", "ACGUACGUACGU");
107  1 assertFalse(sq.isProtein());
108    // change sequence, should trigger an update of cached result
109  1 sq.setSequence("ASDFASDFADSF");
110  1 assertTrue(sq.isProtein());
111    }
112   
 
113  1 toggle @Test(groups = { "Functional" })
114    public void testGetAnnotation()
115    {
116    // initial state returns null not an empty array
117  1 assertNull(seq.getAnnotation());
118  1 AlignmentAnnotation ann = addAnnotation("label1", "desc1", "calcId1",
119    1f);
120  1 AlignmentAnnotation[] anns = seq.getAnnotation();
121  1 assertEquals(1, anns.length);
122  1 assertSame(ann, anns[0]);
123   
124    // removing all annotations reverts array to null
125  1 seq.removeAlignmentAnnotation(ann);
126  1 assertNull(seq.getAnnotation());
127    }
128   
 
129  1 toggle @Test(groups = { "Functional" })
130    public void testGetAnnotation_forLabel()
131    {
132  1 AlignmentAnnotation ann1 = addAnnotation("label1", "desc1", "calcId1",
133    1f);
134  1 addAnnotation("label2", "desc2", "calcId2", 1f);
135  1 AlignmentAnnotation ann3 = addAnnotation("label1", "desc3", "calcId3",
136    1f);
137  1 AlignmentAnnotation[] anns = seq.getAnnotation("label1");
138  1 assertEquals(2, anns.length);
139  1 assertSame(ann1, anns[0]);
140  1 assertSame(ann3, anns[1]);
141    }
142   
 
143  10 toggle private AlignmentAnnotation addAnnotation(String label,
144    String description, String calcId, float value)
145    {
146  10 final AlignmentAnnotation annotation = new AlignmentAnnotation(label,
147    description, value);
148  10 annotation.setCalcId(calcId);
149  10 seq.addAlignmentAnnotation(annotation);
150  10 return annotation;
151    }
152   
 
153  1 toggle @Test(groups = { "Functional" })
154    public void testGetAlignmentAnnotations_forCalcIdAndLabel()
155    {
156  1 addAnnotation("label1", "desc1", "calcId1", 1f);
157  1 AlignmentAnnotation ann2 = addAnnotation("label2", "desc2", "calcId2",
158    1f);
159  1 addAnnotation("label2", "desc3", "calcId3", 1f);
160  1 AlignmentAnnotation ann4 = addAnnotation("label2", "desc3", "calcId2",
161    1f);
162  1 addAnnotation("label5", "desc3", null, 1f);
163  1 addAnnotation(null, "desc3", "calcId3", 1f);
164   
165  1 List<AlignmentAnnotation> anns = seq.getAlignmentAnnotations("calcId2",
166    "label2");
167  1 assertEquals(2, anns.size());
168  1 assertSame(ann2, anns.get(0));
169  1 assertSame(ann4, anns.get(1));
170   
171  1 assertTrue(seq.getAlignmentAnnotations("calcId2", "label3").isEmpty());
172  1 assertTrue(seq.getAlignmentAnnotations("calcId3", "label5").isEmpty());
173  1 assertTrue(seq.getAlignmentAnnotations("calcId2", null).isEmpty());
174  1 assertTrue(seq.getAlignmentAnnotations(null, "label3").isEmpty());
175  1 assertTrue(seq.getAlignmentAnnotations(null, null).isEmpty());
176    }
177   
178    /**
179    * Tests for addAlignmentAnnotation. Note this method has the side-effect of
180    * setting the sequenceRef on the annotation. Adding the same annotation twice
181    * should be ignored.
182    */
 
183  1 toggle @Test(groups = { "Functional" })
184    public void testAddAlignmentAnnotation()
185    {
186  1 assertNull(seq.getAnnotation());
187  1 final AlignmentAnnotation annotation = new AlignmentAnnotation("a",
188    "b", 2d);
189  1 assertNull(annotation.sequenceRef);
190  1 seq.addAlignmentAnnotation(annotation);
191  1 assertSame(seq, annotation.sequenceRef);
192  1 AlignmentAnnotation[] anns = seq.getAnnotation();
193  1 assertEquals(1, anns.length);
194  1 assertSame(annotation, anns[0]);
195   
196    // re-adding does nothing
197  1 seq.addAlignmentAnnotation(annotation);
198  1 anns = seq.getAnnotation();
199  1 assertEquals(1, anns.length);
200  1 assertSame(annotation, anns[0]);
201   
202    // an identical but different annotation can be added
203  1 final AlignmentAnnotation annotation2 = new AlignmentAnnotation("a",
204    "b", 2d);
205  1 seq.addAlignmentAnnotation(annotation2);
206  1 anns = seq.getAnnotation();
207  1 assertEquals(2, anns.length);
208  1 assertSame(annotation, anns[0]);
209  1 assertSame(annotation2, anns[1]);
210    }
211   
 
212  1 toggle @Test(groups = { "Functional" })
213    public void testGetStartGetEnd()
214    {
215  1 SequenceI sq = new Sequence("test", "ABCDEF");
216  1 assertEquals(1, sq.getStart());
217  1 assertEquals(6, sq.getEnd());
218   
219  1 sq = new Sequence("test", "--AB-C-DEF--");
220  1 assertEquals(1, sq.getStart());
221  1 assertEquals(6, sq.getEnd());
222   
223  1 sq = new Sequence("test", "----");
224  1 assertEquals(1, sq.getStart());
225  1 assertEquals(0, sq.getEnd()); // ??
226    }
227   
228    /**
229    * Tests for the method that returns an alignment column position (base 1) for
230    * a given sequence position (base 1).
231    */
 
232  1 toggle @Test(groups = { "Functional" })
233    public void testFindIndex()
234    {
235    /*
236    * call sequenceChanged() after each test to invalidate any cursor,
237    * forcing the 1-arg findIndex to be executed
238    */
239  1 SequenceI sq = new Sequence("test", "ABCDEF");
240  1 assertEquals(0, sq.findIndex(0));
241  1 sq.sequenceChanged();
242  1 assertEquals(1, sq.findIndex(1));
243  1 sq.sequenceChanged();
244  1 assertEquals(5, sq.findIndex(5));
245  1 sq.sequenceChanged();
246  1 assertEquals(6, sq.findIndex(6));
247  1 sq.sequenceChanged();
248  1 assertEquals(6, sq.findIndex(9));
249   
250  1 final String aligned = "-A--B-C-D-E-F--";
251  1 assertEquals(15, aligned.length());
252  1 sq = new Sequence("test/8-13", aligned);
253  1 assertEquals(2, sq.findIndex(8));
254  1 sq.sequenceChanged();
255  1 assertEquals(5, sq.findIndex(9));
256  1 sq.sequenceChanged();
257  1 assertEquals(7, sq.findIndex(10));
258   
259    // before start returns 0
260  1 sq.sequenceChanged();
261  1 assertEquals(0, sq.findIndex(0));
262  1 sq.sequenceChanged();
263  1 assertEquals(0, sq.findIndex(-1));
264   
265    // beyond end returns last residue column
266  1 sq.sequenceChanged();
267  1 assertEquals(13, sq.findIndex(99));
268   
269    /*
270    * residue before sequence 'end' but beyond end of sequence returns
271    * length of sequence (last column) (rightly or wrongly!)
272    */
273  1 sq = new Sequence("test/8-15", "A-B-C-"); // trailing gap case
274  1 assertEquals(6, sq.getLength());
275  1 sq.sequenceChanged();
276  1 assertEquals(sq.getLength(), sq.findIndex(14));
277  1 sq = new Sequence("test/8-99", "-A--B-C-D"); // trailing residue case
278  1 sq.sequenceChanged();
279  1 assertEquals(sq.getLength(), sq.findIndex(65));
280   
281    /*
282    * residue after sequence 'start' but before first residue returns
283    * zero (before first column) (rightly or wrongly!)
284    */
285  1 sq = new Sequence("test/8-15", "-A-B-C-"); // leading gap case
286  1 sq.sequenceChanged();
287  1 assertEquals(0, sq.findIndex(3));
288  1 sq = new Sequence("test/8-15", "A-B-C-"); // leading residue case
289  1 sq.sequenceChanged();
290  1 assertEquals(0, sq.findIndex(2));
291    }
292   
 
293  1 toggle @Test(groups = { "Functional" })
294    public void testFindPositions()
295    {
296  1 SequenceI sq = new Sequence("test/8-13", "-ABC---DE-F--");
297   
298    /*
299    * invalid inputs
300    */
301  1 assertNull(sq.findPositions(6, 5));
302  1 assertNull(sq.findPositions(0, 5));
303  1 assertNull(sq.findPositions(-1, 5));
304   
305    /*
306    * all gapped ranges
307    */
308  1 assertNull(sq.findPositions(1, 1)); // 1-based columns
309  1 assertNull(sq.findPositions(5, 5));
310  1 assertNull(sq.findPositions(5, 6));
311  1 assertNull(sq.findPositions(5, 7));
312   
313    /*
314    * all ungapped ranges
315    */
316  1 assertEquals(new Range(8, 8), sq.findPositions(2, 2)); // A
317  1 assertEquals(new Range(8, 9), sq.findPositions(2, 3)); // AB
318  1 assertEquals(new Range(8, 10), sq.findPositions(2, 4)); // ABC
319  1 assertEquals(new Range(9, 10), sq.findPositions(3, 4)); // BC
320   
321    /*
322    * gap to ungapped range
323    */
324  1 assertEquals(new Range(8, 10), sq.findPositions(1, 4)); // ABC
325  1 assertEquals(new Range(11, 12), sq.findPositions(6, 9)); // DE
326   
327    /*
328    * ungapped to gapped range
329    */
330  1 assertEquals(new Range(10, 10), sq.findPositions(4, 5)); // C
331  1 assertEquals(new Range(9, 13), sq.findPositions(3, 11)); // BCDEF
332   
333    /*
334    * ungapped to ungapped enclosing gaps
335    */
336  1 assertEquals(new Range(10, 11), sq.findPositions(4, 8)); // CD
337  1 assertEquals(new Range(8, 13), sq.findPositions(2, 11)); // ABCDEF
338   
339    /*
340    * gapped to gapped enclosing ungapped
341    */
342  1 assertEquals(new Range(8, 10), sq.findPositions(1, 5)); // ABC
343  1 assertEquals(new Range(11, 12), sq.findPositions(5, 10)); // DE
344  1 assertEquals(new Range(8, 13), sq.findPositions(1, 13)); // the lot
345  1 assertEquals(new Range(8, 13), sq.findPositions(1, 99));
346    }
347   
348    /**
349    * Tests for the method that returns a dataset sequence position (start..) for
350    * an aligned column position (base 0).
351    */
 
352  1 toggle @Test(groups = { "Functional" })
353    public void testFindPosition()
354    {
355    /*
356    * call sequenceChanged() after each test to invalidate any cursor,
357    * forcing the 1-arg findPosition to be executed
358    */
359  1 SequenceI sq = new Sequence("test/8-13", "ABCDEF");
360  1 assertEquals(8, sq.findPosition(0));
361    // Sequence should now hold a cursor at [8, 0]
362  1 assertEquals("test:Pos8:Col1:startCol1:endCol0:tok1",
363    PA.getValue(sq, "cursor").toString());
364  1 SequenceCursor cursor = (SequenceCursor) PA.getValue(sq, "cursor");
365  1 int token = (int) PA.getValue(sq, "changeCount");
366  1 assertEquals(new SequenceCursor(sq, 8, 1, token), cursor);
367   
368  1 sq.sequenceChanged();
369   
370    /*
371    * find F13 at column offset 5, cursor should update to [13, 6]
372    * endColumn is found and saved in cursor
373    */
374  1 assertEquals(13, sq.findPosition(5));
375  1 cursor = (SequenceCursor) PA.getValue(sq, "cursor");
376  1 assertEquals(++token, (int) PA.getValue(sq, "changeCount"));
377  1 assertEquals(new SequenceCursor(sq, 13, 6, token), cursor);
378  1 assertEquals("test:Pos13:Col6:startCol1:endCol6:tok2",
379    PA.getValue(sq, "cursor").toString());
380   
381    // assertEquals(-1, seq.findPosition(6)); // fails
382   
383  1 sq = new Sequence("test/8-11", "AB-C-D--");
384  1 token = (int) PA.getValue(sq, "changeCount"); // 1 for setStart
385  1 assertEquals(8, sq.findPosition(0));
386  1 cursor = (SequenceCursor) PA.getValue(sq, "cursor");
387  1 assertEquals(new SequenceCursor(sq, 8, 1, token), cursor);
388  1 assertEquals("test:Pos8:Col1:startCol1:endCol0:tok1",
389    PA.getValue(sq, "cursor").toString());
390   
391  1 sq.sequenceChanged();
392  1 assertEquals(9, sq.findPosition(1));
393  1 cursor = (SequenceCursor) PA.getValue(sq, "cursor");
394  1 assertEquals(new SequenceCursor(sq, 9, 2, ++token), cursor);
395  1 assertEquals("test:Pos9:Col2:startCol1:endCol0:tok2",
396    PA.getValue(sq, "cursor").toString());
397   
398  1 sq.sequenceChanged();
399    // gap position 'finds' residue to the right (not the left as per javadoc)
400    // cursor is set to the last residue position found [B 2]
401  1 assertEquals(10, sq.findPosition(2));
402  1 cursor = (SequenceCursor) PA.getValue(sq, "cursor");
403  1 assertEquals(new SequenceCursor(sq, 9, 2, ++token), cursor);
404  1 assertEquals("test:Pos9:Col2:startCol1:endCol0:tok3",
405    PA.getValue(sq, "cursor").toString());
406   
407  1 sq.sequenceChanged();
408  1 assertEquals(10, sq.findPosition(3));
409  1 cursor = (SequenceCursor) PA.getValue(sq, "cursor");
410  1 assertEquals(new SequenceCursor(sq, 10, 4, ++token), cursor);
411  1 assertEquals("test:Pos10:Col4:startCol1:endCol0:tok4",
412    PA.getValue(sq, "cursor").toString());
413   
414  1 sq.sequenceChanged();
415    // column[4] is the gap after C - returns D11
416    // cursor is set to [C 4]
417  1 assertEquals(11, sq.findPosition(4));
418  1 cursor = (SequenceCursor) PA.getValue(sq, "cursor");
419  1 assertEquals(new SequenceCursor(sq, 10, 4, ++token), cursor);
420  1 assertEquals("test:Pos10:Col4:startCol1:endCol0:tok5",
421    PA.getValue(sq, "cursor").toString());
422   
423  1 sq.sequenceChanged();
424  1 assertEquals(11, sq.findPosition(5)); // D
425  1 cursor = (SequenceCursor) PA.getValue(sq, "cursor");
426  1 assertEquals(new SequenceCursor(sq, 11, 6, ++token), cursor);
427    // lastCol has been found and saved in the cursor
428  1 assertEquals("test:Pos11:Col6:startCol1:endCol6:tok6",
429    PA.getValue(sq, "cursor").toString());
430   
431  1 sq.sequenceChanged();
432    // returns 1 more than sequence length if off the end ?!?
433  1 assertEquals(12, sq.findPosition(6));
434   
435  1 sq.sequenceChanged();
436  1 assertEquals(12, sq.findPosition(7));
437   
438    /*
439    * first findPosition should also set firstResCol in cursor
440    */
441  1 sq = new Sequence("test/8-13", "--AB-C-DEF--");
442  1 assertEquals(8, sq.findPosition(0));
443  1 assertNull(PA.getValue(sq, "cursor"));
444  1 assertEquals(1, PA.getValue(sq, "changeCount"));
445   
446  1 sq.sequenceChanged();
447  1 assertEquals(8, sq.findPosition(1));
448  1 assertNull(PA.getValue(sq, "cursor"));
449   
450  1 sq.sequenceChanged();
451  1 assertEquals(8, sq.findPosition(2));
452  1 assertEquals("test:Pos8:Col3:startCol3:endCol0:tok3",
453    PA.getValue(sq, "cursor").toString());
454   
455  1 sq.sequenceChanged();
456  1 assertEquals(9, sq.findPosition(3));
457  1 assertEquals("test:Pos9:Col4:startCol3:endCol0:tok4",
458    PA.getValue(sq, "cursor").toString());
459   
460  1 sq.sequenceChanged();
461    // column[4] is a gap, returns next residue pos (C10)
462    // cursor is set to last residue found [B]
463  1 assertEquals(10, sq.findPosition(4));
464  1 assertEquals("test:Pos9:Col4:startCol3:endCol0:tok5",
465    PA.getValue(sq, "cursor").toString());
466   
467  1 sq.sequenceChanged();
468  1 assertEquals(10, sq.findPosition(5));
469  1 assertEquals("test:Pos10:Col6:startCol3:endCol0:tok6",
470    PA.getValue(sq, "cursor").toString());
471   
472  1 sq.sequenceChanged();
473    // column[6] is a gap, returns next residue pos (D11)
474    // cursor is set to last residue found [C]
475  1 assertEquals(11, sq.findPosition(6));
476  1 assertEquals("test:Pos10:Col6:startCol3:endCol0:tok7",
477    PA.getValue(sq, "cursor").toString());
478   
479  1 sq.sequenceChanged();
480  1 assertEquals(11, sq.findPosition(7));
481  1 assertEquals("test:Pos11:Col8:startCol3:endCol0:tok8",
482    PA.getValue(sq, "cursor").toString());
483   
484  1 sq.sequenceChanged();
485  1 assertEquals(12, sq.findPosition(8));
486  1 assertEquals("test:Pos12:Col9:startCol3:endCol0:tok9",
487    PA.getValue(sq, "cursor").toString());
488   
489    /*
490    * when the last residue column is found, it is set in the cursor
491    */
492  1 sq.sequenceChanged();
493  1 assertEquals(13, sq.findPosition(9));
494  1 assertEquals("test:Pos13:Col10:startCol3:endCol10:tok10",
495    PA.getValue(sq, "cursor").toString());
496   
497  1 sq.sequenceChanged();
498  1 assertEquals(14, sq.findPosition(10));
499  1 assertEquals("test:Pos13:Col10:startCol3:endCol10:tok11",
500    PA.getValue(sq, "cursor").toString());
501   
502    /*
503    * findPosition for column beyond sequence length
504    * returns 1 more than last residue position
505    */
506  1 sq.sequenceChanged();
507  1 assertEquals(14, sq.findPosition(11));
508  1 assertEquals("test:Pos13:Col10:startCol3:endCol10:tok12",
509    PA.getValue(sq, "cursor").toString());
510   
511  1 sq.sequenceChanged();
512  1 assertEquals(14, sq.findPosition(99));
513  1 assertEquals("test:Pos13:Col10:startCol3:endCol10:tok13",
514    PA.getValue(sq, "cursor").toString());
515   
516    /*
517    * gapped sequence ending in non-gap
518    */
519  1 sq = new Sequence("test/8-13", "--AB-C-DEF");
520  1 assertEquals(13, sq.findPosition(9));
521  1 assertEquals("test:Pos13:Col10:startCol3:endCol10:tok1",
522    PA.getValue(sq, "cursor").toString());
523  1 sq.sequenceChanged();
524  1 assertEquals(12, sq.findPosition(8)); // E12
525    // sequenceChanged() invalidates cursor.lastResidueColumn
526  1 cursor = (SequenceCursor) PA.getValue(sq, "cursor");
527  1 assertEquals("test:Pos12:Col9:startCol3:endCol0:tok2",
528    cursor.toString());
529    // findPosition with cursor accepts base 1 column values
530  1 assertEquals(13, ((Sequence) sq).findPosition(10, cursor));
531  1 assertEquals(13, sq.findPosition(9)); // F13
532    // lastResidueColumn has now been found and saved in cursor
533  1 assertEquals("test:Pos13:Col10:startCol3:endCol10:tok2",
534    PA.getValue(sq, "cursor").toString());
535    }
536   
 
537  1 toggle @Test(groups = { "Functional" })
538    public void testDeleteChars()
539    {
540    /*
541    * internal delete
542    */
543  1 SequenceI sq = new Sequence("test", "ABCDEF");
544  1 assertNull(PA.getValue(sq, "datasetSequence"));
545  1 assertEquals(1, sq.getStart());
546  1 assertEquals(6, sq.getEnd());
547  1 sq.deleteChars(2, 3);
548  1 assertEquals("ABDEF", sq.getSequenceAsString());
549  1 assertEquals(1, sq.getStart());
550  1 assertEquals(5, sq.getEnd());
551  1 assertNull(PA.getValue(sq, "datasetSequence"));
552   
553    /*
554    * delete at start
555    */
556  1 sq = new Sequence("test", "ABCDEF");
557  1 sq.deleteChars(0, 2);
558  1 assertEquals("CDEF", sq.getSequenceAsString());
559  1 assertEquals(3, sq.getStart());
560  1 assertEquals(6, sq.getEnd());
561  1 assertNull(PA.getValue(sq, "datasetSequence"));
562   
563  1 sq = new Sequence("test", "ABCDE");
564  1 sq.deleteChars(0, 3);
565  1 assertEquals("DE", sq.getSequenceAsString());
566  1 assertEquals(4, sq.getStart());
567  1 assertEquals(5, sq.getEnd());
568  1 assertNull(PA.getValue(sq, "datasetSequence"));
569   
570    /*
571    * delete at end
572    */
573  1 sq = new Sequence("test", "ABCDEF");
574  1 sq.deleteChars(4, 6);
575  1 assertEquals("ABCD", sq.getSequenceAsString());
576  1 assertEquals(1, sq.getStart());
577  1 assertEquals(4, sq.getEnd());
578  1 assertNull(PA.getValue(sq, "datasetSequence"));
579   
580    /*
581    * delete more positions than there are
582    */
583  1 sq = new Sequence("test/8-11", "ABCD");
584  1 sq.deleteChars(0, 99);
585  1 assertEquals("", sq.getSequenceAsString());
586  1 assertEquals(12, sq.getStart()); // = findPosition(99) ?!?
587  1 assertEquals(11, sq.getEnd());
588   
589  1 sq = new Sequence("test/8-11", "----");
590  1 sq.deleteChars(0, 99); // ArrayIndexOutOfBoundsException <= 2.10.2
591  1 assertEquals("", sq.getSequenceAsString());
592  1 assertEquals(8, sq.getStart());
593  1 assertEquals(11, sq.getEnd());
594    }
595   
 
596  1 toggle @Test(groups = { "Functional" })
597    public void testDeleteChars_withDbRefsAndFeatures()
598    {
599    /*
600    * internal delete - new dataset sequence created
601    * gets a copy of any dbrefs
602    */
603  1 SequenceI sq = new Sequence("test", "ABCDEF");
604  1 sq.createDatasetSequence();
605  1 DBRefEntry dbr1 = new DBRefEntry("Uniprot", "0", "a123");
606  1 sq.addDBRef(dbr1);
607  1 Object ds = PA.getValue(sq, "datasetSequence");
608  1 assertNotNull(ds);
609  1 assertEquals(1, sq.getStart());
610  1 assertEquals(6, sq.getEnd());
611  1 sq.deleteChars(2, 3);
612  1 assertEquals("ABDEF", sq.getSequenceAsString());
613  1 assertEquals(1, sq.getStart());
614  1 assertEquals(5, sq.getEnd());
615  1 Object newDs = PA.getValue(sq, "datasetSequence");
616  1 assertNotNull(newDs);
617  1 assertNotSame(ds, newDs);
618  1 assertNotNull(sq.getDBRefs());
619  1 assertEquals(1, sq.getDBRefs().size());
620  1 assertNotSame(dbr1, sq.getDBRefs().get(0));
621  1 assertEquals(dbr1, sq.getDBRefs().get(0));
622   
623    /*
624    * internal delete with sequence features
625    * (failure case for JAL-2541)
626    */
627  1 sq = new Sequence("test", "ABCDEF");
628  1 sq.createDatasetSequence();
629  1 SequenceFeature sf1 = new SequenceFeature("Cath", "desc", 2, 4, 2f,
630    "CathGroup");
631  1 sq.addSequenceFeature(sf1);
632  1 ds = PA.getValue(sq, "datasetSequence");
633  1 assertNotNull(ds);
634  1 assertEquals(1, sq.getStart());
635  1 assertEquals(6, sq.getEnd());
636  1 sq.deleteChars(2, 4);
637  1 assertEquals("ABEF", sq.getSequenceAsString());
638  1 assertEquals(1, sq.getStart());
639  1 assertEquals(4, sq.getEnd());
640  1 newDs = PA.getValue(sq, "datasetSequence");
641  1 assertNotNull(newDs);
642  1 assertNotSame(ds, newDs);
643  1 List<SequenceFeature> sfs = sq.getSequenceFeatures();
644  1 assertEquals(1, sfs.size());
645  1 assertNotSame(sf1, sfs.get(0));
646  1 assertEquals(sf1, sfs.get(0));
647   
648    /*
649    * delete at start - no new dataset sequence created
650    * any sequence features remain as before
651    */
652  1 sq = new Sequence("test", "ABCDEF");
653  1 sq.createDatasetSequence();
654  1 ds = PA.getValue(sq, "datasetSequence");
655  1 sf1 = new SequenceFeature("Cath", "desc", 2, 4, 2f, "CathGroup");
656  1 sq.addSequenceFeature(sf1);
657  1 sq.deleteChars(0, 2);
658  1 assertEquals("CDEF", sq.getSequenceAsString());
659  1 assertEquals(3, sq.getStart());
660  1 assertEquals(6, sq.getEnd());
661  1 assertSame(ds, PA.getValue(sq, "datasetSequence"));
662  1 sfs = sq.getSequenceFeatures();
663  1 assertNotNull(sfs);
664  1 assertEquals(1, sfs.size());
665  1 assertSame(sf1, sfs.get(0));
666   
667    /*
668    * delete at end - no new dataset sequence created
669    * any dbrefs remain as before
670    */
671  1 sq = new Sequence("test", "ABCDEF");
672  1 sq.createDatasetSequence();
673  1 ds = PA.getValue(sq, "datasetSequence");
674  1 dbr1 = new DBRefEntry("Uniprot", "0", "a123");
675  1 sq.addDBRef(dbr1);
676  1 sq.deleteChars(4, 6);
677  1 assertEquals("ABCD", sq.getSequenceAsString());
678  1 assertEquals(1, sq.getStart());
679  1 assertEquals(4, sq.getEnd());
680  1 assertSame(ds, PA.getValue(sq, "datasetSequence"));
681  1 assertNotNull(sq.getDBRefs());
682  1 assertEquals(1, sq.getDBRefs().size());
683  1 assertSame(dbr1, sq.getDBRefs().get(0));
684    }
685   
 
686  1 toggle @Test(groups = { "Functional" })
687    public void testInsertCharAt()
688    {
689    // non-static methods:
690  1 SequenceI sq = new Sequence("test", "ABCDEF");
691  1 sq.insertCharAt(0, 'z');
692  1 assertEquals("zABCDEF", sq.getSequenceAsString());
693  1 sq.insertCharAt(2, 2, 'x');
694  1 assertEquals("zAxxBCDEF", sq.getSequenceAsString());
695   
696    // for static method see StringUtilsTest
697    }
698   
699    /**
700    * Test the method that returns an array of aligned sequence positions where
701    * the array index is the data sequence position (both base 0).
702    */
 
703  1 toggle @Test(groups = { "Functional" })
704    public void testGapMap()
705    {
706  1 SequenceI sq = new Sequence("test", "-A--B-CD-E--F-");
707  1 sq.createDatasetSequence();
708  1 assertEquals("[1, 4, 6, 7, 9, 12]", Arrays.toString(sq.gapMap()));
709    }
710   
711    /**
712    * Test the method that gets sequence features, either from the sequence or
713    * its dataset.
714    */
 
715  1 toggle @Test(groups = { "Functional" })
716    public void testGetSequenceFeatures()
717    {
718  1 SequenceI sq = new Sequence("test", "GATCAT");
719  1 sq.createDatasetSequence();
720   
721  1 assertTrue(sq.getSequenceFeatures().isEmpty());
722   
723    /*
724    * SequenceFeature on sequence
725    */
726  1 SequenceFeature sf = new SequenceFeature("Cath", "desc", 2, 4, 2f, null);
727  1 sq.addSequenceFeature(sf);
728  1 List<SequenceFeature> sfs = sq.getSequenceFeatures();
729  1 assertEquals(1, sfs.size());
730  1 assertSame(sf, sfs.get(0));
731   
732    /*
733    * SequenceFeature on sequence and dataset sequence; returns that on
734    * sequence
735    *
736    * Note JAL-2046: spurious: we have no use case for this at the moment.
737    * This test also buggy - as sf2.equals(sf), no new feature is added
738    */
739  1 SequenceFeature sf2 = new SequenceFeature("Cath", "desc", 2, 4, 2f,
740    null);
741  1 sq.getDatasetSequence().addSequenceFeature(sf2);
742  1 sfs = sq.getSequenceFeatures();
743  1 assertEquals(1, sfs.size());
744  1 assertSame(sf, sfs.get(0));
745   
746    /*
747    * SequenceFeature on dataset sequence only
748    * Note JAL-2046: spurious: we have no use case for setting a non-dataset sequence's feature array to null at the moment.
749    */
750  1 sq.setSequenceFeatures(null);
751  1 assertTrue(sq.getDatasetSequence().getSequenceFeatures().isEmpty());
752   
753    /*
754    * Corrupt case - no SequenceFeature, dataset's dataset is the original
755    * sequence. Test shows no infinite loop results.
756    */
757  1 sq.getDatasetSequence().setSequenceFeatures(null);
758    /**
759    * is there a usecase for this ? setDatasetSequence should throw an error if
760    * this actually occurs.
761    */
762  1 try
763    {
764  1 sq.getDatasetSequence().setDatasetSequence(sq); // loop!
765  0 Assert.fail("Expected Error to be raised when calling setDatasetSequence with self reference");
766    } catch (IllegalArgumentException e)
767    {
768    // TODO Jalview error/exception class for raising implementation errors
769  1 assertTrue(e.getMessage().toLowerCase()
770    .contains("implementation error"));
771    }
772  1 assertTrue(sq.getSequenceFeatures().isEmpty());
773    }
774   
775    /**
776    * Test the method that returns an array, indexed by sequence position, whose
777    * entries are the residue positions at the sequence position (or to the right
778    * if a gap)
779    */
 
780  1 toggle @Test(groups = { "Functional" })
781    public void testFindPositionMap()
782    {
783    /*
784    * Note: Javadoc for findPosition says it returns the residue position to
785    * the left of a gapped position; in fact it returns the position to the
786    * right. Also it returns a non-existent residue position for a gap beyond
787    * the sequence.
788    */
789  1 Sequence sq = new Sequence("TestSeq", "AB.C-D E.");
790  1 int[] map = sq.findPositionMap();
791  1 assertEquals(Arrays.toString(new int[] { 1, 2, 3, 3, 4, 4, 5, 5, 6 }),
792    Arrays.toString(map));
793    }
794   
795    /**
796    * Test for getSubsequence
797    */
 
798  1 toggle @Test(groups = { "Functional" })
799    public void testGetSubsequence()
800    {
801  1 SequenceI sq = new Sequence("TestSeq", "ABCDEFG");
802  1 sq.createDatasetSequence();
803   
804    // positions are base 0, end position is exclusive
805  1 SequenceI subseq = sq.getSubSequence(2, 4);
806   
807  1 assertEquals("CD", subseq.getSequenceAsString());
808    // start/end are base 1 positions
809  1 assertEquals(3, subseq.getStart());
810  1 assertEquals(4, subseq.getEnd());
811    // subsequence shares the full dataset sequence
812  1 assertSame(sq.getDatasetSequence(), subseq.getDatasetSequence());
813    }
814   
815    /**
816    * test createDatasetSequence behaves to doc
817    */
 
818  1 toggle @Test(groups = { "Functional" })
819    public void testCreateDatasetSequence()
820    {
821  1 SequenceI sq = new Sequence("my", "ASDASD");
822  1 sq.addSequenceFeature(new SequenceFeature("type", "desc", 1, 10, 1f,
823    "group"));
824  1 sq.addDBRef(new DBRefEntry("source", "version", "accession"));
825  1 assertNull(sq.getDatasetSequence());
826  1 assertNotNull(PA.getValue(sq, "sequenceFeatureStore"));
827  1 assertNotNull(PA.getValue(sq, "dbrefs"));
828   
829  1 SequenceI rds = sq.createDatasetSequence();
830  1 assertNotNull(rds);
831  1 assertNull(rds.getDatasetSequence());
832  1 assertSame(sq.getDatasetSequence(), rds);
833   
834    // sequence features and dbrefs transferred to dataset sequence
835  1 assertNull(PA.getValue(sq, "sequenceFeatureStore"));
836  1 assertNull(PA.getValue(sq, "dbrefs"));
837  1 assertNotNull(PA.getValue(rds, "sequenceFeatureStore"));
838  1 assertNotNull(PA.getValue(rds, "dbrefs"));
839    }
840   
841    /**
842    * Test for deriveSequence applied to a sequence with a dataset
843    */
 
844  1 toggle @Test(groups = { "Functional" })
845    public void testDeriveSequence_existingDataset()
846    {
847  1 Sequence sq = new Sequence("Seq1", "CD");
848  1 sq.setDatasetSequence(new Sequence("Seq1", "ABCDEF"));
849  1 sq.getDatasetSequence().addSequenceFeature(
850    new SequenceFeature("", "", 1, 2, 0f, null));
851  1 sq.setStart(3);
852  1 sq.setEnd(4);
853   
854  1 sq.setDescription("Test sequence description..");
855  1 sq.setVamsasId("TestVamsasId");
856  1 sq.addDBRef(new DBRefEntry("PDB", "version0", "1TST"));
857   
858  1 sq.addDBRef(new DBRefEntry("PDB", "version1", "1PDB"));
859  1 sq.addDBRef(new DBRefEntry("PDB", "version2", "2PDB"));
860  1 sq.addDBRef(new DBRefEntry("PDB", "version3", "3PDB"));
861  1 sq.addDBRef(new DBRefEntry("PDB", "version4", "4PDB"));
862   
863  1 sq.addPDBId(new PDBEntry("1PDB", "A", Type.PDB, "filePath/test1"));
864  1 sq.addPDBId(new PDBEntry("1PDB", "B", Type.PDB, "filePath/test1"));
865  1 sq.addPDBId(new PDBEntry("2PDB", "A", Type.MMCIF, "filePath/test2"));
866  1 sq.addPDBId(new PDBEntry("2PDB", "B", Type.MMCIF, "filePath/test2"));
867   
868    // these are the same as ones already added
869  1 DBRefEntry pdb1pdb = new DBRefEntry("PDB", "version1", "1PDB");
870  1 DBRefEntry pdb2pdb = new DBRefEntry("PDB", "version2", "2PDB");
871   
872  1 List<DBRefEntry> primRefs = Arrays.asList(new DBRefEntry[] { pdb1pdb,
873    pdb2pdb });
874   
875  1 sq.getDatasetSequence().addDBRef(pdb1pdb); // should do nothing
876  1 sq.getDatasetSequence().addDBRef(pdb2pdb); // should do nothing
877  1 sq.getDatasetSequence().addDBRef(
878    new DBRefEntry("PDB", "version3", "3PDB")); // should do nothing
879  1 sq.getDatasetSequence().addDBRef(
880    new DBRefEntry("PDB", "version4", "4PDB")); // should do nothing
881   
882  1 PDBEntry pdbe1a = new PDBEntry("1PDB", "A", Type.PDB, "filePath/test1");
883  1 PDBEntry pdbe1b = new PDBEntry("1PDB", "B", Type.PDB, "filePath/test1");
884  1 PDBEntry pdbe2a = new PDBEntry("2PDB", "A", Type.MMCIF,
885    "filePath/test2");
886  1 PDBEntry pdbe2b = new PDBEntry("2PDB", "B", Type.MMCIF,
887    "filePath/test2");
888  1 sq.getDatasetSequence().addPDBId(pdbe1a);
889  1 sq.getDatasetSequence().addPDBId(pdbe1b);
890  1 sq.getDatasetSequence().addPDBId(pdbe2a);
891  1 sq.getDatasetSequence().addPDBId(pdbe2b);
892   
893    /*
894    * test we added pdb entries to the dataset sequence
895    */
896  1 Assert.assertEquals(sq.getDatasetSequence().getAllPDBEntries(), Arrays
897    .asList(new PDBEntry[] { pdbe1a, pdbe1b, pdbe2a, pdbe2b }),
898    "PDB Entries were not found on dataset sequence.");
899   
900    /*
901    * we should recover a pdb entry that is on the dataset sequence via PDBEntry
902    */
903  1 Assert.assertEquals(pdbe1a,
904    sq.getDatasetSequence().getPDBEntry("1PDB"),
905    "PDB Entry '1PDB' not found on dataset sequence via getPDBEntry.");
906  1 ArrayList<Annotation> annotsList = new ArrayList<>();
907  1 System.out.println(">>>>>> " + sq.getSequenceAsString().length());
908  1 annotsList.add(new Annotation("A", "A", 'X', 0.1f));
909  1 annotsList.add(new Annotation("A", "A", 'X', 0.1f));
910  1 Annotation[] annots = annotsList.toArray(new Annotation[0]);
911  1 sq.addAlignmentAnnotation(new AlignmentAnnotation("Test annot",
912    "Test annot description", annots));
913  1 sq.getDatasetSequence().addAlignmentAnnotation(
914    new AlignmentAnnotation("Test annot", "Test annot description",
915    annots));
916  1 Assert.assertEquals(sq.getDescription(), "Test sequence description..");
917  1 Assert.assertEquals(sq.getDBRefs().size(), 5); // DBRefs are on dataset
918    // sequence
919  1 Assert.assertEquals(sq.getAllPDBEntries().size(), 4);
920  1 Assert.assertNotNull(sq.getAnnotation());
921  1 Assert.assertEquals(sq.getAnnotation()[0].annotations.length, 2);
922  1 Assert.assertEquals(sq.getDatasetSequence().getDBRefs().size(), 5); // same
923    // as
924    // sq.getDBRefs()
925  1 Assert.assertEquals(sq.getDatasetSequence().getAllPDBEntries().size(),
926    4);
927  1 Assert.assertNotNull(sq.getDatasetSequence().getAnnotation());
928   
929  1 Sequence derived = (Sequence) sq.deriveSequence();
930   
931  1 Assert.assertEquals(derived.getDescription(),
932    "Test sequence description..");
933  1 Assert.assertEquals(derived.getDBRefs().size(), 5); // come from dataset
934  1 Assert.assertEquals(derived.getAllPDBEntries().size(), 4);
935  1 Assert.assertNotNull(derived.getAnnotation());
936  1 Assert.assertEquals(derived.getAnnotation()[0].annotations.length, 2);
937  1 Assert.assertEquals(derived.getDatasetSequence().getDBRefs().size(), 5);
938  1 Assert.assertEquals(derived.getDatasetSequence().getAllPDBEntries()
939    .size(), 4);
940  1 Assert.assertNotNull(derived.getDatasetSequence().getAnnotation());
941   
942  1 assertEquals("CD", derived.getSequenceAsString());
943  1 assertSame(sq.getDatasetSequence(), derived.getDatasetSequence());
944   
945    // derived sequence should access dataset sequence features
946  1 assertNotNull(sq.getSequenceFeatures());
947  1 assertEquals(sq.getSequenceFeatures(), derived.getSequenceFeatures());
948   
949    /*
950    * verify we have primary db refs *just* for PDB IDs with associated
951    * PDBEntry objects
952    */
953   
954  1 assertEquals(primRefs, sq.getPrimaryDBRefs());
955  1 assertEquals(primRefs, sq.getDatasetSequence().getPrimaryDBRefs());
956   
957  1 assertEquals(sq.getPrimaryDBRefs(), derived.getPrimaryDBRefs());
958   
959    }
960   
961    /**
962    * Test for deriveSequence applied to an ungapped sequence with no dataset
963    */
 
964  1 toggle @Test(groups = { "Functional" })
965    public void testDeriveSequence_noDatasetUngapped()
966    {
967  1 SequenceI sq = new Sequence("Seq1", "ABCDEF");
968  1 assertEquals(1, sq.getStart());
969  1 assertEquals(6, sq.getEnd());
970  1 SequenceI derived = sq.deriveSequence();
971  1 assertEquals("ABCDEF", derived.getSequenceAsString());
972  1 assertEquals("ABCDEF", derived.getDatasetSequence()
973    .getSequenceAsString());
974    }
975   
976    /**
977    * Test for deriveSequence applied to a gapped sequence with no dataset
978    */
 
979  1 toggle @Test(groups = { "Functional" })
980    public void testDeriveSequence_noDatasetGapped()
981    {
982  1 SequenceI sq = new Sequence("Seq1", "AB-C.D EF");
983  1 assertEquals(1, sq.getStart());
984  1 assertEquals(6, sq.getEnd());
985  1 assertNull(sq.getDatasetSequence());
986  1 SequenceI derived = sq.deriveSequence();
987  1 assertEquals("AB-C.D EF", derived.getSequenceAsString());
988  1 assertEquals("ABCDEF", derived.getDatasetSequence()
989    .getSequenceAsString());
990    }
991   
 
992  1 toggle @Test(groups = { "Functional" })
993    public void testCopyConstructor_noDataset()
994    {
995  1 SequenceI seq1 = new Sequence("Seq1", "AB-C.D EF");
996  1 seq1.setDescription("description");
997  1 seq1.addAlignmentAnnotation(new AlignmentAnnotation("label", "desc",
998    1.3d));
999  1 seq1.addSequenceFeature(new SequenceFeature("type", "desc", 22, 33,
1000    12.4f, "group"));
1001  1 seq1.addPDBId(new PDBEntry("1A70", "B", Type.PDB, "File"));
1002  1 seq1.addDBRef(new DBRefEntry("EMBL", "1.2", "AZ12345"));
1003   
1004  1 SequenceI copy = new Sequence(seq1);
1005   
1006  1 assertNull(copy.getDatasetSequence());
1007   
1008  1 verifyCopiedSequence(seq1, copy);
1009   
1010    // copy has a copy of the DBRefEntry
1011    // this is murky - DBrefs are only copied for dataset sequences
1012    // where the test for 'dataset sequence' is 'dataset is null'
1013    // but that doesn't distinguish it from an aligned sequence
1014    // which has not yet generated a dataset sequence
1015    // NB getDBRef looks inside dataset sequence if not null
1016  1 List<DBRefEntry> dbrefs = copy.getDBRefs();
1017  1 assertEquals(1, dbrefs.size());
1018  1 assertFalse(dbrefs.get(0) == seq1.getDBRefs().get(0));
1019  1 assertTrue(dbrefs.get(0).equals(seq1.getDBRefs().get(0)));
1020    }
1021   
 
1022  1 toggle @Test(groups = { "Functional" })
1023    public void testCopyConstructor_withDataset()
1024    {
1025  1 SequenceI seq1 = new Sequence("Seq1", "AB-C.D EF");
1026  1 seq1.createDatasetSequence();
1027  1 seq1.setDescription("description");
1028  1 seq1.addAlignmentAnnotation(new AlignmentAnnotation("label", "desc",
1029    1.3d));
1030    // JAL-2046 - what is the contract for using a derived sequence's
1031    // addSequenceFeature ?
1032  1 seq1.addSequenceFeature(new SequenceFeature("type", "desc", 22, 33,
1033    12.4f, "group"));
1034  1 seq1.addPDBId(new PDBEntry("1A70", "B", Type.PDB, "File"));
1035    // here we add DBRef to the dataset sequence:
1036  1 seq1.getDatasetSequence().addDBRef(
1037    new DBRefEntry("EMBL", "1.2", "AZ12345"));
1038   
1039  1 SequenceI copy = new Sequence(seq1);
1040   
1041  1 assertNotNull(copy.getDatasetSequence());
1042  1 assertSame(copy.getDatasetSequence(), seq1.getDatasetSequence());
1043   
1044  1 verifyCopiedSequence(seq1, copy);
1045   
1046    // getDBRef looks inside dataset sequence and this is shared,
1047    // so holds the same dbref objects
1048  1 List<DBRefEntry> dbrefs = copy.getDBRefs();
1049  1 assertEquals(1, dbrefs.size());
1050  1 assertSame(dbrefs.get(0), seq1.getDBRefs().get(0));
1051    }
1052   
1053    /**
1054    * Helper to make assertions about a copied sequence
1055    *
1056    * @param seq1
1057    * @param copy
1058    */
 
1059  2 toggle protected void verifyCopiedSequence(SequenceI seq1, SequenceI copy)
1060    {
1061    // verify basic properties:
1062  2 assertEquals(copy.getName(), seq1.getName());
1063  2 assertEquals(copy.getDescription(), seq1.getDescription());
1064  2 assertEquals(copy.getStart(), seq1.getStart());
1065  2 assertEquals(copy.getEnd(), seq1.getEnd());
1066  2 assertEquals(copy.getSequenceAsString(), seq1.getSequenceAsString());
1067   
1068    // copy has a copy of the annotation:
1069  2 AlignmentAnnotation[] anns = copy.getAnnotation();
1070  2 assertEquals(1, anns.length);
1071  2 assertFalse(anns[0] == seq1.getAnnotation()[0]);
1072  2 assertEquals(anns[0].label, seq1.getAnnotation()[0].label);
1073  2 assertEquals(anns[0].description, seq1.getAnnotation()[0].description);
1074  2 assertEquals(anns[0].score, seq1.getAnnotation()[0].score);
1075   
1076    // copy has a copy of the sequence feature:
1077  2 List<SequenceFeature> sfs = copy.getSequenceFeatures();
1078  2 assertEquals(1, sfs.size());
1079  2 if (seq1.getDatasetSequence() != null
1080    && copy.getDatasetSequence() == seq1.getDatasetSequence())
1081    {
1082  1 assertSame(sfs.get(0), seq1.getSequenceFeatures().get(0));
1083    }
1084    else
1085    {
1086  1 assertNotSame(sfs.get(0), seq1.getSequenceFeatures().get(0));
1087    }
1088  2 assertEquals(sfs.get(0), seq1.getSequenceFeatures().get(0));
1089   
1090    // copy has a copy of the PDB entry
1091  2 Vector<PDBEntry> pdbs = copy.getAllPDBEntries();
1092  2 assertEquals(1, pdbs.size());
1093  2 assertFalse(pdbs.get(0) == seq1.getAllPDBEntries().get(0));
1094  2 assertTrue(pdbs.get(0).equals(seq1.getAllPDBEntries().get(0)));
1095    }
1096   
 
1097  1 toggle @Test(groups = "Functional")
1098    public void testGetCharAt()
1099    {
1100  1 SequenceI sq = new Sequence("", "abcde");
1101  1 assertEquals('a', sq.getCharAt(0));
1102  1 assertEquals('e', sq.getCharAt(4));
1103  1 assertEquals(' ', sq.getCharAt(5));
1104  1 assertEquals(' ', sq.getCharAt(-1));
1105    }
1106   
 
1107  1 toggle @Test(groups = { "Functional" })
1108    public void testAddSequenceFeatures()
1109    {
1110  1 SequenceI sq = new Sequence("", "abcde");
1111    // type may not be null
1112  1 assertFalse(sq.addSequenceFeature(new SequenceFeature(null, "desc", 4,
1113    8, 0f, null)));
1114  1 assertTrue(sq.addSequenceFeature(new SequenceFeature("Cath", "desc", 4,
1115    8, 0f, null)));
1116    // can't add a duplicate feature
1117  1 assertFalse(sq.addSequenceFeature(new SequenceFeature("Cath", "desc",
1118    4, 8, 0f, null)));
1119    // can add a different feature
1120  1 assertTrue(sq.addSequenceFeature(new SequenceFeature("Scop", "desc", 4,
1121    8, 0f, null))); // different type
1122  1 assertTrue(sq.addSequenceFeature(new SequenceFeature("Cath",
1123    "description", 4, 8, 0f, null)));// different description
1124  1 assertTrue(sq.addSequenceFeature(new SequenceFeature("Cath", "desc", 3,
1125    8, 0f, null))); // different start position
1126  1 assertTrue(sq.addSequenceFeature(new SequenceFeature("Cath", "desc", 4,
1127    9, 0f, null))); // different end position
1128  1 assertTrue(sq.addSequenceFeature(new SequenceFeature("Cath", "desc", 4,
1129    8, 1f, null))); // different score
1130  1 assertTrue(sq.addSequenceFeature(new SequenceFeature("Cath", "desc", 4,
1131    8, Float.NaN, null))); // score NaN
1132  1 assertTrue(sq.addSequenceFeature(new SequenceFeature("Cath", "desc", 4,
1133    8, 0f, "Metal"))); // different group
1134  1 assertEquals(8, sq.getFeatures().getAllFeatures().size());
1135    }
1136   
1137    /**
1138    * Tests for adding (or updating) dbrefs
1139    *
1140    * @see DBRefEntry#updateFrom(DBRefEntry)
1141    */
 
1142  1 toggle @Test(groups = { "Functional" })
1143    public void testAddDBRef()
1144    {
1145  1 SequenceI sq = new Sequence("", "abcde");
1146  1 assertNull(sq.getDBRefs());
1147  1 DBRefEntry dbref = new DBRefEntry("Uniprot", "1", "P00340");
1148  1 sq.addDBRef(dbref);
1149  1 assertEquals(1, sq.getDBRefs().size());
1150  1 assertSame(dbref, sq.getDBRefs().get(0));
1151   
1152    /*
1153    * change of version - new entry
1154    */
1155  1 DBRefEntry dbref2 = new DBRefEntry("Uniprot", "2", "P00340");
1156  1 sq.addDBRef(dbref2);
1157  1 assertEquals(2, sq.getDBRefs().size());
1158  1 assertSame(dbref, sq.getDBRefs().get(0));
1159  1 assertSame(dbref2, sq.getDBRefs().get(1));
1160   
1161    /*
1162    * matches existing entry - not added
1163    */
1164  1 sq.addDBRef(new DBRefEntry("UNIPROT", "1", "p00340"));
1165  1 assertEquals(2, sq.getDBRefs().size());
1166   
1167    /*
1168    * different source = new entry
1169    */
1170  1 DBRefEntry dbref3 = new DBRefEntry("UniRef", "1", "p00340");
1171  1 sq.addDBRef(dbref3);
1172  1 assertEquals(3, sq.getDBRefs().size());
1173  1 assertSame(dbref3, sq.getDBRefs().get(2));
1174   
1175    /*
1176    * different ref = new entry
1177    */
1178  1 DBRefEntry dbref4 = new DBRefEntry("UniRef", "1", "p00341");
1179  1 sq.addDBRef(dbref4);
1180  1 assertEquals(4, sq.getDBRefs().size());
1181  1 assertSame(dbref4, sq.getDBRefs().get(3));
1182   
1183    /*
1184    * matching ref with a mapping - map updated
1185    */
1186  1 DBRefEntry dbref5 = new DBRefEntry("UniRef", "1", "p00341");
1187  1 Mapping map = new Mapping(new MapList(new int[] { 1, 3 }, new int[] {
1188    1, 1 }, 3, 1));
1189  1 dbref5.setMap(map);
1190  1 sq.addDBRef(dbref5);
1191  1 assertEquals(4, sq.getDBRefs().size());
1192  1 assertSame(dbref4, sq.getDBRefs().get(3));
1193  1 assertSame(map, dbref4.getMap());
1194   
1195    /*
1196    * 'real' version replaces "0" version
1197    */
1198  1 dbref2.setVersion("0");
1199  1 DBRefEntry dbref6 = new DBRefEntry(dbref2.getSource(), "3",
1200    dbref2.getAccessionId());
1201  1 sq.addDBRef(dbref6);
1202  1 assertEquals(4, sq.getDBRefs().size());
1203  1 assertSame(dbref2, sq.getDBRefs().get(1));
1204  1 assertEquals("3", dbref2.getVersion());
1205   
1206    /*
1207    * 'real' version replaces "source:0" version
1208    */
1209  1 dbref3.setVersion("Uniprot:0");
1210  1 DBRefEntry dbref7 = new DBRefEntry(dbref3.getSource(), "3",
1211    dbref3.getAccessionId());
1212  1 sq.addDBRef(dbref7);
1213  1 assertEquals(4, sq.getDBRefs().size());
1214  1 assertSame(dbref3, sq.getDBRefs().get(2));
1215  1 assertEquals("3", dbref2.getVersion());
1216    }
1217   
 
1218  1 toggle @Test(groups = { "Functional" })
1219    public void testGetPrimaryDBRefs_peptide()
1220    {
1221  1 SequenceI sq = new Sequence("aseq", "ASDFKYLMQPRST", 10, 22);
1222   
1223    // no dbrefs
1224  1 List<DBRefEntry> primaryDBRefs = sq.getPrimaryDBRefs();
1225  1 assertTrue(primaryDBRefs.isEmpty());
1226   
1227    // empty dbrefs
1228  1 sq.setDBRefs(null);
1229  1 primaryDBRefs = sq.getPrimaryDBRefs();
1230  1 assertTrue(primaryDBRefs.isEmpty());
1231   
1232    // primary - uniprot
1233  1 DBRefEntry upentry1 = new DBRefEntry("UNIPROT", "0", "Q04760");
1234  1 sq.addDBRef(upentry1);
1235   
1236    // primary - uniprot with congruent map
1237  1 DBRefEntry upentry2 = new DBRefEntry("UNIPROT", "0", "Q04762");
1238  1 upentry2.setMap(new Mapping(null, new MapList(new int[] { 10, 22 },
1239    new int[] { 10, 22 }, 1, 1)));
1240  1 sq.addDBRef(upentry2);
1241   
1242    // primary - uniprot with map of enclosing sequence
1243  1 DBRefEntry upentry3 = new DBRefEntry("UNIPROT", "0", "Q04763");
1244  1 upentry3.setMap(new Mapping(null, new MapList(new int[] { 8, 24 },
1245    new int[] { 8, 24 }, 1, 1)));
1246  1 sq.addDBRef(upentry3);
1247   
1248    // not primary - uniprot with map of sub-sequence (5')
1249  1 DBRefEntry upentry4 = new DBRefEntry("UNIPROT", "0", "Q04764");
1250  1 upentry4.setMap(new Mapping(null, new MapList(new int[] { 10, 18 },
1251    new int[] { 10, 18 }, 1, 1)));
1252  1 sq.addDBRef(upentry4);
1253   
1254    // not primary - uniprot with map that overlaps 3'
1255  1 DBRefEntry upentry5 = new DBRefEntry("UNIPROT", "0", "Q04765");
1256  1 upentry5.setMap(new Mapping(null, new MapList(new int[] { 12, 22 },
1257    new int[] { 12, 22 }, 1, 1)));
1258  1 sq.addDBRef(upentry5);
1259   
1260    // not primary - uniprot with map to different coordinates frame
1261  1 DBRefEntry upentry6 = new DBRefEntry("UNIPROT", "0", "Q04766");
1262  1 upentry6.setMap(new Mapping(null, new MapList(new int[] { 12, 18 },
1263    new int[] { 112, 118 }, 1, 1)));
1264  1 sq.addDBRef(upentry6);
1265   
1266    // not primary - dbref to 'non-core' database
1267  1 DBRefEntry upentry7 = new DBRefEntry("Pfam", "0", "PF00903");
1268  1 sq.addDBRef(upentry7);
1269   
1270    // primary - type is PDB
1271  1 DBRefEntry pdbentry = new DBRefEntry("PDB", "0", "1qip");
1272  1 sq.addDBRef(pdbentry);
1273   
1274    // not primary - PDBEntry has no file
1275  1 sq.addDBRef(new DBRefEntry("PDB", "0", "1AAA"));
1276   
1277    // not primary - no PDBEntry
1278  1 sq.addDBRef(new DBRefEntry("PDB", "0", "1DDD"));
1279   
1280    // add corroborating PDB entry for primary DBref -
1281    // needs to have a file as well as matching ID
1282    // note PDB ID is not treated as case sensitive
1283  1 sq.addPDBId(new PDBEntry("1QIP", null, Type.PDB, new File("/blah")
1284    .toString()));
1285   
1286    // not valid DBRef - no file..
1287  1 sq.addPDBId(new PDBEntry("1AAA", null, null, null));
1288   
1289  1 primaryDBRefs = sq.getPrimaryDBRefs();
1290  1 assertEquals(4, primaryDBRefs.size());
1291  1 assertTrue("Couldn't find simple primary reference (UNIPROT)",
1292    primaryDBRefs.contains(upentry1));
1293  1 assertTrue("Couldn't find mapped primary reference (UNIPROT)",
1294    primaryDBRefs.contains(upentry2));
1295  1 assertTrue("Couldn't find mapped context reference (UNIPROT)",
1296    primaryDBRefs.contains(upentry3));
1297  1 assertTrue("Couldn't find expected PDB primary reference",
1298    primaryDBRefs.contains(pdbentry));
1299    }
1300   
 
1301  1 toggle @Test(groups = { "Functional" })
1302    public void testGetPrimaryDBRefs_nucleotide()
1303    {
1304  1 SequenceI sq = new Sequence("aseq", "TGATCACTCGACTAGCATCAGCATA", 10, 34);
1305   
1306    // primary - Ensembl
1307  1 DBRefEntry dbr1 = new DBRefEntry("ENSEMBL", "0", "ENSG1234");
1308  1 sq.addDBRef(dbr1);
1309   
1310    // not primary - Ensembl 'transcript' mapping of sub-sequence
1311  1 DBRefEntry dbr2 = new DBRefEntry("ENSEMBL", "0", "ENST1234");
1312  1 dbr2.setMap(new Mapping(null, new MapList(new int[] { 15, 25 },
1313    new int[] { 1, 11 }, 1, 1)));
1314  1 sq.addDBRef(dbr2);
1315   
1316    // primary - EMBL with congruent map
1317  1 DBRefEntry dbr3 = new DBRefEntry("EMBL", "0", "J1234");
1318  1 dbr3.setMap(new Mapping(null, new MapList(new int[] { 10, 34 },
1319    new int[] { 10, 34 }, 1, 1)));
1320  1 sq.addDBRef(dbr3);
1321   
1322    // not primary - to non-core database
1323  1 DBRefEntry dbr4 = new DBRefEntry("CCDS", "0", "J1234");
1324  1 sq.addDBRef(dbr4);
1325   
1326    // not primary - to protein
1327  1 DBRefEntry dbr5 = new DBRefEntry("UNIPROT", "0", "Q87654");
1328  1 sq.addDBRef(dbr5);
1329   
1330  1 List<DBRefEntry> primaryDBRefs = sq.getPrimaryDBRefs();
1331  1 assertEquals(2, primaryDBRefs.size());
1332  1 assertTrue(primaryDBRefs.contains(dbr1));
1333  1 assertTrue(primaryDBRefs.contains(dbr3));
1334    }
1335   
1336    /**
1337    * Test the method that updates the list of PDBEntry from any new DBRefEntry
1338    * for PDB
1339    */
 
1340  1 toggle @Test(groups = { "Functional" })
1341    public void testUpdatePDBIds()
1342    {
1343  1 PDBEntry pdbe1 = new PDBEntry("3A6S", null, null, null);
1344  1 seq.addPDBId(pdbe1);
1345  1 seq.addDBRef(new DBRefEntry("Ensembl", "8", "ENST1234"));
1346  1 seq.addDBRef(new DBRefEntry("PDB", "0", "1A70"));
1347  1 seq.addDBRef(new DBRefEntry("PDB", "0", "4BQGa"));
1348  1 seq.addDBRef(new DBRefEntry("PDB", "0", "3a6sB"));
1349    // 7 is not a valid chain code:
1350  1 seq.addDBRef(new DBRefEntry("PDB", "0", "2GIS7"));
1351   
1352  1 seq.updatePDBIds();
1353  1 List<PDBEntry> pdbIds = seq.getAllPDBEntries();
1354  1 assertEquals(4, pdbIds.size());
1355  1 assertSame(pdbe1, pdbIds.get(0));
1356    // chain code got added to 3A6S:
1357  1 assertEquals("B", pdbe1.getChainCode());
1358  1 assertEquals("1A70", pdbIds.get(1).getId());
1359    // 4BQGA is parsed into id + chain
1360  1 assertEquals("4BQG", pdbIds.get(2).getId());
1361  1 assertEquals("a", pdbIds.get(2).getChainCode());
1362  1 assertEquals("2GIS7", pdbIds.get(3).getId());
1363  1 assertNull(pdbIds.get(3).getChainCode());
1364    }
1365   
1366    /**
1367    * Test the method that either adds a pdbid or updates an existing one
1368    */
 
1369  1 toggle @Test(groups = { "Functional" })
1370    public void testAddPDBId()
1371    {
1372  1 PDBEntry pdbe = new PDBEntry("3A6S", null, null, null);
1373  1 seq.addPDBId(pdbe);
1374  1 assertEquals(1, seq.getAllPDBEntries().size());
1375  1 assertSame(pdbe, seq.getPDBEntry("3A6S"));
1376  1 assertSame(pdbe, seq.getPDBEntry("3a6s")); // case-insensitive
1377   
1378    // add the same entry
1379  1 seq.addPDBId(pdbe);
1380  1 assertEquals(1, seq.getAllPDBEntries().size());
1381  1 assertSame(pdbe, seq.getPDBEntry("3A6S"));
1382   
1383    // add an identical entry
1384  1 seq.addPDBId(new PDBEntry("3A6S", null, null, null));
1385  1 assertEquals(1, seq.getAllPDBEntries().size());
1386  1 assertSame(pdbe, seq.getPDBEntry("3A6S"));
1387   
1388    // add a different entry
1389  1 PDBEntry pdbe2 = new PDBEntry("1A70", null, null, null);
1390  1 seq.addPDBId(pdbe2);
1391  1 assertEquals(2, seq.getAllPDBEntries().size());
1392  1 assertSame(pdbe, seq.getAllPDBEntries().get(0));
1393  1 assertSame(pdbe2, seq.getAllPDBEntries().get(1));
1394   
1395    // update pdbe with chain code, file, type
1396  1 PDBEntry pdbe3 = new PDBEntry("3a6s", "A", Type.PDB, "filepath");
1397  1 seq.addPDBId(pdbe3);
1398  1 assertEquals(2, seq.getAllPDBEntries().size());
1399  1 assertSame(pdbe, seq.getAllPDBEntries().get(0)); // updated in situ
1400  1 assertEquals("3A6S", pdbe.getId()); // unchanged
1401  1 assertEquals("A", pdbe.getChainCode()); // updated
1402  1 assertEquals(Type.PDB.toString(), pdbe.getType()); // updated
1403  1 assertEquals("filepath", pdbe.getFile()); // updated
1404  1 assertSame(pdbe2, seq.getAllPDBEntries().get(1));
1405   
1406    // add with a different file path
1407  1 PDBEntry pdbe4 = new PDBEntry("3a6s", "A", Type.PDB, "filepath2");
1408  1 seq.addPDBId(pdbe4);
1409  1 assertEquals(3, seq.getAllPDBEntries().size());
1410  1 assertSame(pdbe4, seq.getAllPDBEntries().get(2));
1411   
1412    // add with a different chain code
1413  1 PDBEntry pdbe5 = new PDBEntry("3a6s", "B", Type.PDB, "filepath");
1414  1 seq.addPDBId(pdbe5);
1415  1 assertEquals(4, seq.getAllPDBEntries().size());
1416  1 assertSame(pdbe5, seq.getAllPDBEntries().get(3));
1417    }
1418   
 
1419  1 toggle @Test(
1420    groups = { "Functional" },
1421    expectedExceptions = { IllegalArgumentException.class })
1422    public void testSetDatasetSequence_toSelf()
1423    {
1424  1 seq.setDatasetSequence(seq);
1425    }
1426   
 
1427  1 toggle @Test(
1428    groups = { "Functional" },
1429    expectedExceptions = { IllegalArgumentException.class })
1430    public void testSetDatasetSequence_cascading()
1431    {
1432  1 SequenceI seq2 = new Sequence("Seq2", "xyz");
1433  1 seq2.createDatasetSequence();
1434  1 seq.setDatasetSequence(seq2);
1435    }
1436   
 
1437  1 toggle @Test(groups = { "Functional" })
1438    public void testFindFeatures()
1439    {
1440  1 SequenceI sq = new Sequence("test/8-16", "-ABC--DEF--GHI--");
1441  1 sq.createDatasetSequence();
1442   
1443  1 assertTrue(sq.findFeatures(1, 99).isEmpty());
1444   
1445    // add non-positional feature
1446  1 SequenceFeature sf0 = new SequenceFeature("Cath", "desc", 0, 0, 2f,
1447    null);
1448  1 sq.addSequenceFeature(sf0);
1449    // add feature on BCD
1450  1 SequenceFeature sfBCD = new SequenceFeature("Cath", "desc", 9, 11, 2f,
1451    null);
1452  1 sq.addSequenceFeature(sfBCD);
1453    // add feature on DE
1454  1 SequenceFeature sfDE = new SequenceFeature("Cath", "desc", 11, 12, 2f,
1455    null);
1456  1 sq.addSequenceFeature(sfDE);
1457    // add contact feature at [B, H]
1458  1 SequenceFeature sfContactBH = new SequenceFeature("Disulphide bond",
1459    "desc", 9, 15, 2f, null);
1460  1 sq.addSequenceFeature(sfContactBH);
1461    // add contact feature at [F, G]
1462  1 SequenceFeature sfContactFG = new SequenceFeature("Disulfide Bond",
1463    "desc", 13, 14, 2f, null);
1464  1 sq.addSequenceFeature(sfContactFG);
1465    // add single position feature at [I]
1466  1 SequenceFeature sfI = new SequenceFeature("Disulfide Bond",
1467    "desc", 16, 16, null);
1468  1 sq.addSequenceFeature(sfI);
1469   
1470    // no features in columns 1-2 (-A)
1471  1 List<SequenceFeature> found = sq.findFeatures(1, 2);
1472  1 assertTrue(found.isEmpty());
1473   
1474    // columns 1-6 (-ABC--) includes BCD and B/H feature but not DE
1475  1 found = sq.findFeatures(1, 6);
1476  1 assertEquals(2, found.size());
1477  1 assertTrue(found.contains(sfBCD));
1478  1 assertTrue(found.contains(sfContactBH));
1479   
1480    // columns 5-6 (--) includes (enclosing) BCD but not (contact) B/H feature
1481  1 found = sq.findFeatures(5, 6);
1482  1 assertEquals(1, found.size());
1483  1 assertTrue(found.contains(sfBCD));
1484   
1485    // columns 7-10 (DEF-) includes BCD, DE, F/G but not B/H feature
1486  1 found = sq.findFeatures(7, 10);
1487  1 assertEquals(3, found.size());
1488  1 assertTrue(found.contains(sfBCD));
1489  1 assertTrue(found.contains(sfDE));
1490  1 assertTrue(found.contains(sfContactFG));
1491   
1492    // columns 10-11 (--) should find nothing
1493  1 found = sq.findFeatures(10, 11);
1494  1 assertEquals(0, found.size());
1495   
1496    // columns 14-14 (I) should find variant feature
1497  1 found = sq.findFeatures(14, 14);
1498  1 assertEquals(1, found.size());
1499  1 assertTrue(found.contains(sfI));
1500    }
1501   
 
1502  1 toggle @Test(groups = { "Functional" })
1503    public void testFindIndex_withCursor()
1504    {
1505  1 Sequence sq = new Sequence("test/8-13", "-A--BCD-EF--");
1506  1 final int tok = (int) PA.getValue(sq, "changeCount");
1507  1 assertEquals(1, tok);
1508   
1509    // find F given A, check cursor is now at the found position
1510  1 assertEquals(10, sq.findIndex(13, new SequenceCursor(sq, 8, 2, tok)));
1511  1 SequenceCursor cursor = (SequenceCursor) PA.getValue(sq, "cursor");
1512  1 assertEquals(13, cursor.residuePosition);
1513  1 assertEquals(10, cursor.columnPosition);
1514   
1515    // find A given F
1516  1 assertEquals(2, sq.findIndex(8, new SequenceCursor(sq, 13, 10, tok)));
1517  1 cursor = (SequenceCursor) PA.getValue(sq, "cursor");
1518  1 assertEquals(8, cursor.residuePosition);
1519  1 assertEquals(2, cursor.columnPosition);
1520   
1521    // find C given C (no cursor update is done for this case)
1522  1 assertEquals(6, sq.findIndex(10, new SequenceCursor(sq, 10, 6, tok)));
1523  1 SequenceCursor cursor2 = (SequenceCursor) PA.getValue(sq, "cursor");
1524  1 assertSame(cursor2, cursor);
1525   
1526    /*
1527    * sequence 'end' beyond end of sequence returns length of sequence
1528    * (for compatibility with pre-cursor code)
1529    * - also verify the cursor is left in a valid state
1530    */
1531  1 sq = new Sequence("test/8-99", "-A--B-C-D-E-F--"); // trailing gap case
1532  1 assertEquals(7, sq.findIndex(10)); // establishes a cursor
1533  1 cursor = (SequenceCursor) PA.getValue(sq, "cursor");
1534  1 assertEquals(10, cursor.residuePosition);
1535  1 assertEquals(7, cursor.columnPosition);
1536  1 assertEquals(sq.getLength(), sq.findIndex(65));
1537  1 cursor2 = (SequenceCursor) PA.getValue(sq, "cursor");
1538  1 assertSame(cursor, cursor2); // not updated for this case!
1539   
1540  1 sq = new Sequence("test/8-99", "-A--B-C-D-E-F"); // trailing residue case
1541  1 sq.findIndex(10); // establishes a cursor
1542  1 cursor = (SequenceCursor) PA.getValue(sq, "cursor");
1543  1 assertEquals(sq.getLength(), sq.findIndex(65));
1544  1 cursor2 = (SequenceCursor) PA.getValue(sq, "cursor");
1545  1 assertSame(cursor, cursor2); // not updated for this case!
1546   
1547    /*
1548    * residue after sequence 'start' but before first residue should return
1549    * zero (for compatibility with pre-cursor code)
1550    */
1551  1 sq = new Sequence("test/8-15", "-A-B-C-"); // leading gap case
1552  1 sq.findIndex(10); // establishes a cursor
1553  1 cursor = (SequenceCursor) PA.getValue(sq, "cursor");
1554  1 assertEquals(0, sq.findIndex(3));
1555  1 cursor2 = (SequenceCursor) PA.getValue(sq, "cursor");
1556  1 assertSame(cursor, cursor2); // not updated for this case!
1557   
1558  1 sq = new Sequence("test/8-15", "A-B-C-"); // leading residue case
1559  1 sq.findIndex(10); // establishes a cursor
1560  1 cursor = (SequenceCursor) PA.getValue(sq, "cursor");
1561  1 assertEquals(0, sq.findIndex(2));
1562  1 cursor2 = (SequenceCursor) PA.getValue(sq, "cursor");
1563  1 assertSame(cursor, cursor2); // not updated for this case!
1564    }
1565   
 
1566  1 toggle @Test(groups = { "Functional" })
1567    public void testFindPosition_withCursor()
1568    {
1569  1 Sequence sq = new Sequence("test/8-13", "-A--BCD-EF--");
1570  1 final int tok = (int) PA.getValue(sq, "changeCount");
1571  1 assertEquals(1, tok);
1572   
1573    // find F pos given A - lastCol gets set in cursor
1574  1 assertEquals(13,
1575    sq.findPosition(10, new SequenceCursor(sq, 8, 2, tok)));
1576  1 assertEquals("test:Pos13:Col10:startCol0:endCol10:tok1",
1577    PA.getValue(sq, "cursor").toString());
1578   
1579    // find A pos given F - first residue column is saved in cursor
1580  1 assertEquals(8,
1581    sq.findPosition(2, new SequenceCursor(sq, 13, 10, tok)));
1582  1 assertEquals("test:Pos8:Col2:startCol2:endCol10:tok1",
1583    PA.getValue(sq, "cursor").toString());
1584   
1585    // find C pos given C (neither startCol nor endCol is set)
1586  1 assertEquals(10,
1587    sq.findPosition(6, new SequenceCursor(sq, 10, 6, tok)));
1588  1 assertEquals("test:Pos10:Col6:startCol0:endCol0:tok1",
1589    PA.getValue(sq, "cursor").toString());
1590   
1591    // now the grey area - what residue position for a gapped column? JAL-2562
1592   
1593    // find 'residue' for column 3 given cursor for D (so working left)
1594    // returns B9; cursor is updated to [B 5]
1595  1 assertEquals(9, sq.findPosition(3, new SequenceCursor(sq, 11, 7, tok)));
1596  1 assertEquals("test:Pos9:Col5:startCol0:endCol0:tok1",
1597    PA.getValue(sq, "cursor").toString());
1598   
1599    // find 'residue' for column 8 given cursor for D (so working right)
1600    // returns E12; cursor is updated to [D 7]
1601  1 assertEquals(12,
1602    sq.findPosition(8, new SequenceCursor(sq, 11, 7, tok)));
1603  1 assertEquals("test:Pos11:Col7:startCol0:endCol0:tok1",
1604    PA.getValue(sq, "cursor").toString());
1605   
1606    // find 'residue' for column 12 given cursor for B
1607    // returns 1 more than last residue position; cursor is updated to [F 10]
1608    // lastCol position is saved in cursor
1609  1 assertEquals(14,
1610    sq.findPosition(12, new SequenceCursor(sq, 9, 5, tok)));
1611  1 assertEquals("test:Pos13:Col10:startCol0:endCol10:tok1",
1612    PA.getValue(sq, "cursor").toString());
1613   
1614    /*
1615    * findPosition for column beyond length of sequence
1616    * returns 1 more than the last residue position
1617    * cursor is set to last real residue position [F 10]
1618    */
1619  1 assertEquals(14,
1620    sq.findPosition(99, new SequenceCursor(sq, 8, 2, tok)));
1621  1 assertEquals("test:Pos13:Col10:startCol0:endCol10:tok1",
1622    PA.getValue(sq, "cursor").toString());
1623   
1624    /*
1625    * and the case without a trailing gap
1626    */
1627  1 sq = new Sequence("test/8-13", "-A--BCD-EF");
1628    // first find C from A
1629  1 assertEquals(10, sq.findPosition(6, new SequenceCursor(sq, 8, 2, tok)));
1630  1 SequenceCursor cursor = (SequenceCursor) PA.getValue(sq, "cursor");
1631  1 assertEquals("test:Pos10:Col6:startCol0:endCol0:tok1",
1632    cursor.toString());
1633    // now 'find' 99 from C
1634    // cursor is set to [F 10] and saved lastCol
1635  1 assertEquals(14, sq.findPosition(99, cursor));
1636  1 assertEquals("test:Pos13:Col10:startCol0:endCol10:tok1",
1637    PA.getValue(sq, "cursor").toString());
1638    }
1639   
 
1640  0 toggle @Test
1641    public void testIsValidCursor()
1642    {
1643  0 Sequence sq = new Sequence("Seq", "ABC--DE-F", 8, 13);
1644  0 assertFalse(sq.isValidCursor(null));
1645   
1646    /*
1647    * cursor is valid if it has valid sequence ref and changeCount token
1648    * and positions within the range of the sequence
1649    */
1650  0 int changeCount = (int) PA.getValue(sq, "changeCount");
1651  0 SequenceCursor cursor = new SequenceCursor(sq, 13, 1, changeCount);
1652  0 assertTrue(sq.isValidCursor(cursor));
1653   
1654    /*
1655    * column position outside [0 - length] is rejected
1656    */
1657  0 cursor = new SequenceCursor(sq, 13, -1, changeCount);
1658  0 assertFalse(sq.isValidCursor(cursor));
1659  0 cursor = new SequenceCursor(sq, 13, 10, changeCount);
1660  0 assertFalse(sq.isValidCursor(cursor));
1661  0 cursor = new SequenceCursor(sq, 7, 8, changeCount);
1662  0 assertFalse(sq.isValidCursor(cursor));
1663  0 cursor = new SequenceCursor(sq, 14, 2, changeCount);
1664  0 assertFalse(sq.isValidCursor(cursor));
1665   
1666    /*
1667    * wrong sequence is rejected
1668    */
1669  0 cursor = new SequenceCursor(null, 13, 1, changeCount);
1670  0 assertFalse(sq.isValidCursor(cursor));
1671  0 cursor = new SequenceCursor(new Sequence("Seq", "abc"), 13, 1,
1672    changeCount);
1673  0 assertFalse(sq.isValidCursor(cursor));
1674   
1675    /*
1676    * wrong token value is rejected
1677    */
1678  0 cursor = new SequenceCursor(sq, 13, 1, changeCount + 1);
1679  0 assertFalse(sq.isValidCursor(cursor));
1680  0 cursor = new SequenceCursor(sq, 13, 1, changeCount - 1);
1681  0 assertFalse(sq.isValidCursor(cursor));
1682    }
1683   
 
1684  1 toggle @Test(groups = { "Functional" })
1685    public void testFindPosition_withCursorAndEdits()
1686    {
1687  1 Sequence sq = new Sequence("test/8-13", "-A--BCD-EF--");
1688   
1689    // find F pos given A
1690  1 assertEquals(13, sq.findPosition(10, new SequenceCursor(sq, 8, 2, 0)));
1691  1 int token = (int) PA.getValue(sq, "changeCount"); // 0
1692  1 SequenceCursor cursor = (SequenceCursor) PA.getValue(sq, "cursor");
1693  1 assertEquals(new SequenceCursor(sq, 13, 10, token), cursor);
1694   
1695    /*
1696    * setSequence should invalidate the cursor cached by the sequence
1697    */
1698  1 sq.setSequence("-A-BCD-EF---"); // one gap removed
1699  1 assertEquals(8, sq.getStart()); // sanity check
1700  1 assertEquals(11, sq.findPosition(5)); // D11
1701    // cursor should now be at [D 6]
1702  1 cursor = (SequenceCursor) PA.getValue(sq, "cursor");
1703  1 assertEquals(new SequenceCursor(sq, 11, 6, ++token), cursor);
1704  1 assertEquals(0, cursor.lastColumnPosition); // not yet found
1705  1 assertEquals(13, sq.findPosition(8)); // E13
1706  1 cursor = (SequenceCursor) PA.getValue(sq, "cursor");
1707  1 assertEquals(9, cursor.lastColumnPosition); // found
1708   
1709    /*
1710    * deleteChars should invalidate the cached cursor
1711    */
1712  1 sq.deleteChars(2, 5); // delete -BC
1713  1 assertEquals("-AD-EF---", sq.getSequenceAsString());
1714  1 assertEquals(8, sq.getStart()); // sanity check
1715  1 assertEquals(10, sq.findPosition(4)); // E10
1716    // cursor should now be at [E 5]
1717  1 cursor = (SequenceCursor) PA.getValue(sq, "cursor");
1718  1 assertEquals(new SequenceCursor(sq, 10, 5, ++token), cursor);
1719   
1720    /*
1721    * Edit to insert gaps should invalidate the cached cursor
1722    * insert 2 gaps at column[3] to make -AD---EF---
1723    */
1724  1 SequenceI[] seqs = new SequenceI[] { sq };
1725  1 AlignmentI al = new Alignment(seqs);
1726  1 new EditCommand().appendEdit(Action.INSERT_GAP, seqs, 3, 2, al, true);
1727  1 assertEquals("-AD---EF---", sq.getSequenceAsString());
1728  1 assertEquals(10, sq.findPosition(4)); // E10
1729    // cursor should now be at [D 3]
1730  1 cursor = (SequenceCursor) PA.getValue(sq, "cursor");
1731  1 assertEquals(new SequenceCursor(sq, 9, 3, ++token), cursor);
1732   
1733    /*
1734    * insertCharAt should invalidate the cached cursor
1735    * insert CC at column[4] to make -AD-CC--EF---
1736    */
1737  1 sq.insertCharAt(4, 2, 'C');
1738  1 assertEquals("-AD-CC--EF---", sq.getSequenceAsString());
1739  1 assertEquals(13, sq.findPosition(9)); // F13
1740    // cursor should now be at [F 10]
1741  1 cursor = (SequenceCursor) PA.getValue(sq, "cursor");
1742  1 assertEquals(new SequenceCursor(sq, 13, 10, ++token), cursor);
1743   
1744    /*
1745    * changing sequence start should invalidate cursor
1746    */
1747  1 sq = new Sequence("test/8-13", "-A--BCD-EF--");
1748  1 assertEquals(8, sq.getStart());
1749  1 assertEquals(9, sq.findPosition(4)); // B(9)
1750  1 sq.setStart(7);
1751  1 assertEquals(8, sq.findPosition(4)); // is now B(8)
1752  1 sq.setStart(10);
1753  1 assertEquals(11, sq.findPosition(4)); // is now B(11)
1754    }
1755   
 
1756  1 toggle @Test(groups = { "Functional" })
1757    public void testGetSequence()
1758    {
1759  1 String seqstring = "-A--BCD-EF--";
1760  1 Sequence sq = new Sequence("test/8-13", seqstring);
1761  1 sq.createDatasetSequence();
1762  1 assertTrue(Arrays.equals(sq.getSequence(), seqstring.toCharArray()));
1763  1 assertTrue(Arrays.equals(sq.getDatasetSequence().getSequence(),
1764    "ABCDEF".toCharArray()));
1765   
1766    // verify a copy of the sequence array is returned
1767  1 char[] theSeq = (char[]) PA.getValue(sq, "sequence");
1768  1 assertNotSame(theSeq, sq.getSequence());
1769  1 theSeq = (char[]) PA.getValue(sq.getDatasetSequence(), "sequence");
1770  1 assertNotSame(theSeq, sq.getDatasetSequence().getSequence());
1771    }
1772   
 
1773  1 toggle @Test(groups = { "Functional" })
1774    public void testReplace()
1775    {
1776  1 String seqstring = "-A--BCD-EF--";
1777  1 SequenceI sq = new Sequence("test/8-13", seqstring);
1778    // changeCount is incremented for setStart
1779  1 assertEquals(1, PA.getValue(sq, "changeCount"));
1780   
1781  1 assertEquals(0, sq.replace('A', 'A')); // same char
1782  1 assertEquals(seqstring, sq.getSequenceAsString());
1783  1 assertEquals(1, PA.getValue(sq, "changeCount"));
1784   
1785  1 assertEquals(0, sq.replace('X', 'Y')); // not there
1786  1 assertEquals(seqstring, sq.getSequenceAsString());
1787  1 assertEquals(1, PA.getValue(sq, "changeCount"));
1788   
1789  1 assertEquals(1, sq.replace('A', 'K'));
1790  1 assertEquals("-K--BCD-EF--", sq.getSequenceAsString());
1791  1 assertEquals(2, PA.getValue(sq, "changeCount"));
1792   
1793  1 assertEquals(6, sq.replace('-', '.'));
1794  1 assertEquals(".K..BCD.EF..", sq.getSequenceAsString());
1795  1 assertEquals(3, PA.getValue(sq, "changeCount"));
1796    }
1797   
 
1798  1 toggle @Test(groups = { "Functional" })
1799    public void testGapBitset()
1800    {
1801  1 SequenceI sq = new Sequence("test/8-13", "-ABC---DE-F--");
1802  1 BitSet bs = sq.gapBitset();
1803  1 BitSet expected = new BitSet();
1804  1 expected.set(0);
1805  1 expected.set(4, 7);
1806  1 expected.set(9);
1807  1 expected.set(11, 13);
1808   
1809  1 assertTrue(bs.equals(expected));
1810   
1811    }
1812   
 
1813  0 toggle public void testFindFeatures_largeEndPos()
1814    {
1815    /*
1816    * imitate a PDB sequence where end is larger than end position
1817    */
1818  0 SequenceI sq = new Sequence("test", "-ABC--DEF--", 1, 20);
1819  0 sq.createDatasetSequence();
1820   
1821  0 assertTrue(sq.findFeatures(1, 9).isEmpty());
1822    // should be no array bounds exception - JAL-2772
1823  0 assertTrue(sq.findFeatures(1, 15).isEmpty());
1824   
1825    // add feature on BCD
1826  0 SequenceFeature sfBCD = new SequenceFeature("Cath", "desc", 2, 4, 2f,
1827    null);
1828  0 sq.addSequenceFeature(sfBCD);
1829   
1830    // no features in columns 1-2 (-A)
1831  0 List<SequenceFeature> found = sq.findFeatures(1, 2);
1832  0 assertTrue(found.isEmpty());
1833   
1834    // columns 1-6 (-ABC--) includes BCD
1835  0 found = sq.findFeatures(1, 6);
1836  0 assertEquals(1, found.size());
1837  0 assertTrue(found.contains(sfBCD));
1838   
1839    // columns 10-11 (--) should find nothing
1840  0 found = sq.findFeatures(10, 11);
1841  0 assertEquals(0, found.size());
1842    }
1843   
 
1844  1 toggle @Test(groups = { "Functional" })
1845    public void testSetName()
1846    {
1847  1 SequenceI sq = new Sequence("test", "-ABC---DE-F--");
1848  1 assertEquals("test", sq.getName());
1849  1 assertEquals(1, sq.getStart());
1850  1 assertEquals(6, sq.getEnd());
1851   
1852  1 sq.setName("testing");
1853  1 assertEquals("testing", sq.getName());
1854   
1855  1 sq.setName("test/8-10");
1856  1 assertEquals("test", sq.getName());
1857  1 assertEquals(8, sq.getStart());
1858  1 assertEquals(13, sq.getEnd()); // note end is recomputed
1859   
1860  1 sq.setName("testing/7-99");
1861  1 assertEquals("testing", sq.getName());
1862  1 assertEquals(7, sq.getStart());
1863  1 assertEquals(99, sq.getEnd()); // end may be beyond physical end
1864   
1865  1 sq.setName("/2-3");
1866  1 assertEquals("", sq.getName());
1867  1 assertEquals(2, sq.getStart());
1868  1 assertEquals(7, sq.getEnd());
1869   
1870  1 sq.setName("test/"); // invalid
1871  1 assertEquals("test/", sq.getName());
1872  1 assertEquals(2, sq.getStart());
1873  1 assertEquals(7, sq.getEnd());
1874   
1875  1 sq.setName("test/6-13/7-99");
1876  1 assertEquals("test/6-13", sq.getName());
1877  1 assertEquals(7, sq.getStart());
1878  1 assertEquals(99, sq.getEnd());
1879   
1880  1 sq.setName("test/0-5"); // 0 is invalid - ignored
1881  1 assertEquals("test/0-5", sq.getName());
1882  1 assertEquals(7, sq.getStart());
1883  1 assertEquals(99, sq.getEnd());
1884   
1885  1 sq.setName("test/a-5"); // a is invalid - ignored
1886  1 assertEquals("test/a-5", sq.getName());
1887  1 assertEquals(7, sq.getStart());
1888  1 assertEquals(99, sq.getEnd());
1889   
1890  1 sq.setName("test/6-5"); // start > end is invalid - ignored
1891  1 assertEquals("test/6-5", sq.getName());
1892  1 assertEquals(7, sq.getStart());
1893  1 assertEquals(99, sq.getEnd());
1894   
1895  1 sq.setName("test/5"); // invalid - ignored
1896  1 assertEquals("test/5", sq.getName());
1897  1 assertEquals(7, sq.getStart());
1898  1 assertEquals(99, sq.getEnd());
1899   
1900  1 sq.setName("test/-5"); // invalid - ignored
1901  1 assertEquals("test/-5", sq.getName());
1902  1 assertEquals(7, sq.getStart());
1903  1 assertEquals(99, sq.getEnd());
1904   
1905  1 sq.setName("test/5-"); // invalid - ignored
1906  1 assertEquals("test/5-", sq.getName());
1907  1 assertEquals(7, sq.getStart());
1908  1 assertEquals(99, sq.getEnd());
1909   
1910  1 sq.setName("test/5-6-7"); // invalid - ignored
1911  1 assertEquals("test/5-6-7", sq.getName());
1912  1 assertEquals(7, sq.getStart());
1913  1 assertEquals(99, sq.getEnd());
1914   
1915  1 sq.setName(null); // invalid, gets converted to space
1916  1 assertEquals("", sq.getName());
1917  1 assertEquals(7, sq.getStart());
1918  1 assertEquals(99, sq.getEnd());
1919    }
1920   
 
1921  1 toggle @Test(groups = { "Functional" })
1922    public void testCheckValidRange()
1923    {
1924  1 Sequence sq = new Sequence("test/7-12", "-ABC---DE-F--");
1925  1 assertEquals(7, sq.getStart());
1926  1 assertEquals(12, sq.getEnd());
1927   
1928    /*
1929    * checkValidRange ensures end is at least the last residue position
1930    */
1931  1 PA.setValue(sq, "end", 2);
1932  1 sq.checkValidRange();
1933  1 assertEquals(12, sq.getEnd());
1934   
1935    /*
1936    * end may be beyond the last residue position
1937    */
1938  1 PA.setValue(sq, "end", 22);
1939  1 sq.checkValidRange();
1940  1 assertEquals(22, sq.getEnd());
1941    }
1942   
 
1943  1 toggle @Test(groups = { "Functional" })
1944    public void testDeleteChars_withGaps()
1945    {
1946    /*
1947    * delete gaps only
1948    */
1949  1 SequenceI sq = new Sequence("test/8-10", "A-B-C");
1950  1 sq.createDatasetSequence();
1951  1 assertEquals("ABC", sq.getDatasetSequence().getSequenceAsString());
1952  1 sq.deleteChars(1, 2); // delete first gap
1953  1 assertEquals("AB-C", sq.getSequenceAsString());
1954  1 assertEquals(8, sq.getStart());
1955  1 assertEquals(10, sq.getEnd());
1956  1 assertEquals("ABC", sq.getDatasetSequence().getSequenceAsString());
1957   
1958    /*
1959    * delete gaps and residues at start (no new dataset sequence)
1960    */
1961  1 sq = new Sequence("test/8-10", "A-B-C");
1962  1 sq.createDatasetSequence();
1963  1 sq.deleteChars(0, 3); // delete A-B
1964  1 assertEquals("-C", sq.getSequenceAsString());
1965  1 assertEquals(10, sq.getStart());
1966  1 assertEquals(10, sq.getEnd());
1967  1 assertEquals("ABC", sq.getDatasetSequence().getSequenceAsString());
1968   
1969    /*
1970    * delete gaps and residues at end (no new dataset sequence)
1971    */
1972  1 sq = new Sequence("test/8-10", "A-B-C");
1973  1 sq.createDatasetSequence();
1974  1 sq.deleteChars(2, 5); // delete B-C
1975  1 assertEquals("A-", sq.getSequenceAsString());
1976  1 assertEquals(8, sq.getStart());
1977  1 assertEquals(8, sq.getEnd());
1978  1 assertEquals("ABC", sq.getDatasetSequence().getSequenceAsString());
1979   
1980    /*
1981    * delete gaps and residues internally (new dataset sequence)
1982    * first delete from gap to residue
1983    */
1984  1 sq = new Sequence("test/8-10", "A-B-C");
1985  1 sq.createDatasetSequence();
1986  1 sq.deleteChars(1, 3); // delete -B
1987  1 assertEquals("A-C", sq.getSequenceAsString());
1988  1 assertEquals(8, sq.getStart());
1989  1 assertEquals(9, sq.getEnd());
1990  1 assertEquals("AC", sq.getDatasetSequence().getSequenceAsString());
1991  1 assertEquals(8, sq.getDatasetSequence().getStart());
1992  1 assertEquals(9, sq.getDatasetSequence().getEnd());
1993   
1994    /*
1995    * internal delete from gap to gap
1996    */
1997  1 sq = new Sequence("test/8-10", "A-B-C");
1998  1 sq.createDatasetSequence();
1999  1 sq.deleteChars(1, 4); // delete -B-
2000  1 assertEquals("AC", sq.getSequenceAsString());
2001  1 assertEquals(8, sq.getStart());
2002  1 assertEquals(9, sq.getEnd());
2003  1 assertEquals("AC", sq.getDatasetSequence().getSequenceAsString());
2004  1 assertEquals(8, sq.getDatasetSequence().getStart());
2005  1 assertEquals(9, sq.getDatasetSequence().getEnd());
2006   
2007    /*
2008    * internal delete from residue to residue
2009    */
2010  1 sq = new Sequence("test/8-10", "A-B-C");
2011  1 sq.createDatasetSequence();
2012  1 sq.deleteChars(2, 3); // delete B
2013  1 assertEquals("A--C", sq.getSequenceAsString());
2014  1 assertEquals(8, sq.getStart());
2015  1 assertEquals(9, sq.getEnd());
2016  1 assertEquals("AC", sq.getDatasetSequence().getSequenceAsString());
2017  1 assertEquals(8, sq.getDatasetSequence().getStart());
2018  1 assertEquals(9, sq.getDatasetSequence().getEnd());
2019    }
2020   
2021    /**
2022    * Test the code used to locate the reference sequence ruler origin
2023    */
 
2024  1 toggle @Test(groups = { "Functional" })
2025    public void testLocateVisibleStartofSequence()
2026    {
2027    // create random alignment
2028  1 AlignmentGenerator gen = new AlignmentGenerator(false);
2029  1 AlignmentI al = gen.generate(50, 20, 123, 5, 5);
2030   
2031  1 HiddenColumns cs = al.getHiddenColumns();
2032  1 ColumnSelection colsel = new ColumnSelection();
2033   
2034  1 SequenceI seq = new Sequence("RefSeq", "-A-SD-ASD--E---");
2035  1 assertEquals(2, seq.findIndex(seq.getStart()));
2036   
2037    // no hidden columns
2038  1 assertEquals(seq.findIndex(seq.getStart()) - 1,
2039    seq.firstResidueOutsideIterator(cs.iterator()));
2040   
2041    // hidden column on gap after end of sequence - should not affect bounds
2042  1 colsel.hideSelectedColumns(13, al.getHiddenColumns());
2043  1 assertEquals(seq.findIndex(seq.getStart()) - 1,
2044    seq.firstResidueOutsideIterator(cs.iterator()));
2045   
2046  1 cs.revealAllHiddenColumns(colsel);
2047    // hidden column on gap before beginning of sequence - should vis bounds by
2048    // one
2049  1 colsel.hideSelectedColumns(0, al.getHiddenColumns());
2050  1 assertEquals(seq.findIndex(seq.getStart()) - 2,
2051    cs.absoluteToVisibleColumn(
2052    seq.firstResidueOutsideIterator(cs.iterator())));
2053   
2054  1 cs.revealAllHiddenColumns(colsel);
2055    // hide columns around most of sequence - leave one residue remaining
2056  1 cs.hideColumns(1, 3);
2057  1 cs.hideColumns(6, 11);
2058   
2059  1 Iterator<int[]> it = cs.getVisContigsIterator(0, 6, false);
2060   
2061  1 assertEquals("-D", seq.getSequenceStringFromIterator(it));
2062    // cs.getVisibleSequenceStrings(0, 5, new SequenceI[]
2063    // { seq })[0]);
2064   
2065  1 assertEquals(4, seq.firstResidueOutsideIterator(cs.iterator()));
2066  1 cs.revealAllHiddenColumns(colsel);
2067   
2068    // hide whole sequence - should just get location of hidden region
2069    // containing sequence
2070  1 cs.hideColumns(1, 11);
2071  1 assertEquals(0, seq.firstResidueOutsideIterator(cs.iterator()));
2072   
2073  1 cs.revealAllHiddenColumns(colsel);
2074  1 cs.hideColumns(0, 15);
2075  1 assertEquals(0, seq.firstResidueOutsideIterator(cs.iterator()));
2076   
2077  1 SequenceI seq2 = new Sequence("RefSeq2", "-------A-SD-ASD--E---");
2078   
2079  1 cs.revealAllHiddenColumns(colsel);
2080  1 cs.hideColumns(7, 17);
2081  1 assertEquals(0, seq2.firstResidueOutsideIterator(cs.iterator()));
2082   
2083  1 cs.revealAllHiddenColumns(colsel);
2084  1 cs.hideColumns(3, 17);
2085  1 assertEquals(0, seq2.firstResidueOutsideIterator(cs.iterator()));
2086   
2087  1 cs.revealAllHiddenColumns(colsel);
2088  1 cs.hideColumns(3, 19);
2089  1 assertEquals(0, seq2.firstResidueOutsideIterator(cs.iterator()));
2090   
2091  1 cs.revealAllHiddenColumns(colsel);
2092  1 cs.hideColumns(0, 0);
2093  1 assertEquals(1, seq.firstResidueOutsideIterator(cs.iterator()));
2094   
2095  1 cs.revealAllHiddenColumns(colsel);
2096  1 cs.hideColumns(0, 1);
2097  1 assertEquals(3, seq.firstResidueOutsideIterator(cs.iterator()));
2098   
2099  1 cs.revealAllHiddenColumns(colsel);
2100  1 cs.hideColumns(0, 2);
2101  1 assertEquals(3, seq.firstResidueOutsideIterator(cs.iterator()));
2102   
2103  1 cs.revealAllHiddenColumns(colsel);
2104  1 cs.hideColumns(1, 1);
2105  1 assertEquals(3, seq.firstResidueOutsideIterator(cs.iterator()));
2106   
2107  1 cs.revealAllHiddenColumns(colsel);
2108  1 cs.hideColumns(1, 2);
2109  1 assertEquals(3, seq.firstResidueOutsideIterator(cs.iterator()));
2110   
2111  1 cs.revealAllHiddenColumns(colsel);
2112  1 cs.hideColumns(1, 3);
2113  1 assertEquals(4, seq.firstResidueOutsideIterator(cs.iterator()));
2114   
2115  1 cs.revealAllHiddenColumns(colsel);
2116  1 cs.hideColumns(0, 2);
2117  1 cs.hideColumns(5, 6);
2118  1 assertEquals(3, seq.firstResidueOutsideIterator(cs.iterator()));
2119   
2120  1 cs.revealAllHiddenColumns(colsel);
2121  1 cs.hideColumns(0, 2);
2122  1 cs.hideColumns(5, 6);
2123  1 cs.hideColumns(9, 10);
2124  1 assertEquals(3, seq.firstResidueOutsideIterator(cs.iterator()));
2125   
2126  1 cs.revealAllHiddenColumns(colsel);
2127  1 cs.hideColumns(0, 2);
2128  1 cs.hideColumns(7, 11);
2129  1 assertEquals(3, seq.firstResidueOutsideIterator(cs.iterator()));
2130   
2131  1 cs.revealAllHiddenColumns(colsel);
2132  1 cs.hideColumns(2, 4);
2133  1 cs.hideColumns(7, 11);
2134  1 assertEquals(1, seq.firstResidueOutsideIterator(cs.iterator()));
2135   
2136  1 cs.revealAllHiddenColumns(colsel);
2137  1 cs.hideColumns(2, 4);
2138  1 cs.hideColumns(7, 12);
2139  1 assertEquals(1, seq.firstResidueOutsideIterator(cs.iterator()));
2140   
2141  1 cs.revealAllHiddenColumns(colsel);
2142  1 cs.hideColumns(1, 11);
2143  1 assertEquals(0, seq.firstResidueOutsideIterator(cs.iterator()));
2144   
2145  1 cs.revealAllHiddenColumns(colsel);
2146  1 cs.hideColumns(0, 12);
2147  1 assertEquals(0, seq.firstResidueOutsideIterator(cs.iterator()));
2148   
2149  1 cs.revealAllHiddenColumns(colsel);
2150  1 cs.hideColumns(0, 4);
2151  1 cs.hideColumns(6, 12);
2152  1 assertEquals(0, seq.firstResidueOutsideIterator(cs.iterator()));
2153   
2154  1 cs.revealAllHiddenColumns(colsel);
2155  1 cs.hideColumns(0, 1);
2156  1 cs.hideColumns(3, 12);
2157  1 assertEquals(0, seq.firstResidueOutsideIterator(cs.iterator()));
2158   
2159  1 cs.revealAllHiddenColumns(colsel);
2160  1 cs.hideColumns(3, 14);
2161  1 cs.hideColumns(17, 19);
2162  1 assertEquals(0, seq2.firstResidueOutsideIterator(cs.iterator()));
2163   
2164  1 cs.revealAllHiddenColumns(colsel);
2165  1 cs.hideColumns(3, 7);
2166  1 cs.hideColumns(9, 14);
2167  1 cs.hideColumns(17, 19);
2168  1 assertEquals(0, seq2.firstResidueOutsideIterator(cs.iterator()));
2169   
2170  1 cs.revealAllHiddenColumns(colsel);
2171  1 cs.hideColumns(0, 1);
2172  1 cs.hideColumns(3, 4);
2173  1 cs.hideColumns(6, 8);
2174  1 cs.hideColumns(10, 12);
2175  1 assertEquals(0, seq.firstResidueOutsideIterator(cs.iterator()));
2176   
2177    }
2178    }