Clover icon

Coverage Report

  1. Project Clover database Thu Dec 4 2025 14:43:25 GMT
  2. Package jalview.datamodel

File AlignmentAnnotationTests.java

 

Code metrics

28
320
32
1
740
601
47
0.15
10
32
1.47

Classes

Class Line # Actions
AlignmentAnnotationTests 42 320 47
0.9578947495.8%
 

Contributing tests

This file is covered by 31 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.Assert.assertFalse;
24    import static org.testng.Assert.assertNull;
25    import static org.testng.Assert.assertTrue;
26    import static org.testng.AssertJUnit.assertEquals;
27   
28    import jalview.analysis.AlignSeq;
29    import jalview.gui.JvOptionPane;
30    import jalview.io.AppletFormatAdapter;
31    import jalview.io.FileFormat;
32    import org.testng.Assert;
33    import org.testng.annotations.BeforeClass;
34    import org.testng.annotations.DataProvider;
35    import org.testng.annotations.Test;
36   
37    import static jalview.datamodel.Annotation.EMPTY_ANNOTATION;
38    import static jalview.testutils.Matchers.matchesAnnotations;
39    import static org.hamcrest.MatcherAssert.assertThat;
40    import static org.hamcrest.Matchers.*;
41   
 
42    public class AlignmentAnnotationTests
43    {
44   
 
45  1 toggle @BeforeClass(alwaysRun = true)
46    public void setUpJvOptionPane()
47    {
48  1 JvOptionPane.setInteractiveMode(false);
49  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
50    }
51   
 
52  1 toggle @Test(groups = { "Functional" })
53    public void testCopyConstructor()
54    {
55  1 SequenceI sq = new Sequence("Foo", "ARAARARARAWEAWEAWRAWEAWE");
56  1 createAnnotation(sq);
57  1 AlignmentAnnotation alc, alo = sq.getAnnotation()[0];
58  1 alc = new AlignmentAnnotation(alo);
59   
60    // TODO: this only tests string equals (which is unreliable), should use
61    // refactored tests from StockholmFileTest
62  1 Assert.assertEquals(alc.toString(), alo.toString());
63   
64  1 for (String key : alo.getProperties())
65    {
66  1 assertEquals("Property mismatch", alo.getProperty(key),
67    alc.getProperty(key));
68    }
69    }
70   
71    /**
72    * create some dummy annotation derived from the sequence
73    *
74    * @param sq
75    */
 
76  3 toggle public static void createAnnotation(SequenceI sq)
77    {
78  3 Annotation[] al = new Annotation[sq.getLength()];
79  41 for (int i = 0; i < al.length; i++)
80    {
81  38 al[i] = new Annotation(new Annotation("" + sq.getCharAt(i), "", (char) 0,
82    sq.findPosition(i)));
83    }
84  3 AlignmentAnnotation alan = new AlignmentAnnotation("For " + sq.getName(),
85    "Fake alignment annot", al);
86    // create a sequence mapping for the annotation vector in its current state
87  3 alan.createSequenceMapping(sq, sq.getStart(), false);
88  3 alan.setProperty("CreatedBy", "createAnnotation");
89  3 sq.addAlignmentAnnotation(alan);
90    }
91   
92    /**
93    * use this to test annotation derived from method above as it is transferred
94    * across different sequences derived from same dataset coordinate frame
95    *
96    * @param ala
97    */
 
98  0 toggle public static void testAnnotTransfer(AlignmentAnnotation ala)
99    {
100  0 assertEquals("Failed - need annotation created by createAnnotation method",
101    ala.description, "Fake alignment annot");
102  0 ala.adjustForAlignment();
103  0 for (int p = 0; p < ala.annotations.length; p++)
104    {
105  0 if (ala.annotations[p] != null)
106    {
107  0 assertEquals(
108    "Mismatch at position " + p
109    + " between annotation position value and sequence"
110    + ala.annotations[p],
111    (int) ala.annotations[p].value, ala.sequenceRef.findPosition(p));
112    }
113    }
114    }
115   
116    /**
117    * Tests the liftOver method and also exercises the functions for remapping
118    * annotation across different reference sequences. Here, the test is between
119    * different dataset frames (annotation transferred by mapping between
120    * sequences)
121    */
 
122  1 toggle @Test(groups = { "Functional" })
123    public void testLiftOver()
124    {
125  1 SequenceI sqFrom = new Sequence("fromLong", "QQQCDEWGH");
126  1 sqFrom.setStart(10);
127  1 sqFrom.setEnd(sqFrom.findPosition(sqFrom.getLength() - 1));
128  1 SequenceI sqTo = new Sequence("toShort", "RCDEW");
129  1 sqTo.setStart(20);
130  1 sqTo.setEnd(sqTo.findPosition(sqTo.getLength() - 1));
131  1 createAnnotation(sqTo);
132  1 AlignmentAnnotation origTo = sqTo.getAnnotation()[0];
133  1 createAnnotation(sqFrom);
134  1 AlignmentAnnotation origFrom = sqFrom.getAnnotation()[0];
135  1 AlignSeq align = AlignSeq.doGlobalNWAlignment(sqFrom, sqTo, AlignSeq.PEP);
136  1 SequenceI alSeq1 = new Sequence(sqFrom.getName(), align.getAStr1());
137  1 alSeq1.setStart(sqFrom.getStart() + align.getSeq1Start() - 1);
138  1 alSeq1.setEnd(sqFrom.getStart() + align.getSeq1End() - 1);
139  1 alSeq1.setDatasetSequence(sqFrom);
140  1 SequenceI alSeq2 = new Sequence(sqTo.getName(), align.getAStr2());
141  1 alSeq2.setStart(sqTo.getStart() + align.getSeq2Start() - 1);
142  1 alSeq2.setEnd(sqTo.getStart() + align.getSeq2End() - 1);
143  1 alSeq2.setDatasetSequence(sqTo);
144  1 System.out
145    .println(new AppletFormatAdapter()
146    .formatSequences(FileFormat.Stockholm,
147    new Alignment(new SequenceI[] { sqFrom, alSeq1, sqTo, alSeq2 }),
148    true));
149   
150  1 Mapping mp = align.getMappingFromS1(false);
151   
152  1 AlignmentAnnotation almap1 = new AlignmentAnnotation(
153    sqTo.getAnnotation()[0]);
154  1 almap1.liftOver(sqFrom, mp);
155  1 assertEquals(almap1.sequenceRef, sqFrom);
156  1 alSeq1.addAlignmentAnnotation(almap1);
157  1 almap1.setSequenceRef(alSeq1);
158  1 almap1.adjustForAlignment();
159  1 AlignmentAnnotation almap2 = new AlignmentAnnotation(
160    sqFrom.getAnnotation()[0]);
161  1 almap2.liftOver(sqTo, mp);
162  1 assertEquals(almap2.sequenceRef, sqTo);
163   
164  1 alSeq2.addAlignmentAnnotation(almap2);
165  1 almap2.setSequenceRef(alSeq2);
166  1 almap2.adjustForAlignment();
167   
168  1 AlignmentI all = new Alignment(new SequenceI[] { alSeq1, alSeq2 });
169  1 all.addAnnotation(almap1);
170  1 all.addAnnotation(almap2);
171  1 System.out
172    .println(new AppletFormatAdapter()
173    .formatSequences(FileFormat.Stockholm, all, true));
174   
175  6 for (int p = 0; p < alSeq1.getLength(); p++)
176    {
177  5 Annotation orig1, trans1, orig2, trans2;
178  5 trans2 = almap2.annotations[p];
179  5 orig2 = origFrom.annotations[alSeq1.findPosition(p) - sqFrom.getStart()];
180  5 orig1 = origTo.annotations[alSeq2.findPosition(p) - sqTo.getStart()];
181  5 trans1 = almap1.annotations[p];
182  5 if (trans1 == trans2)
183    {
184  1 System.out.println("Pos " + p + " mismatch");
185  1 continue;
186    }
187  4 assertEquals("Mismatch on Original From and transferred annotation on 2",
188  4 (orig2 != null) ? orig2.toString() : null,
189  4 (trans2 != null) ? trans2.toString() : null);
190  4 assertEquals("Mismatch on Original To and transferred annotation on 1",
191  4 (orig1 != null) ? orig1.toString() : null,
192  4 (trans1 != null) ? trans1.toString() : null);
193  4 String alm1 = "" + (almap1.annotations.length > p
194    ? almap1.annotations[p].displayCharacter
195    : "Out of range");
196  4 String alm2 = "" + (almap2.annotations.length > p
197    ? almap2.annotations[p].displayCharacter
198    : "Out of range");
199  4 assertEquals("Position " + p + " " + alm1 + " " + alm2, alm1, alm2);
200    }
201    }
202   
 
203  1 toggle @Test(groups = { "Functional" })
204    public void testAdjustForAlignment()
205    {
206  1 SequenceI seq = new Sequence("TestSeq", "ABCDEFG");
207  1 seq.createDatasetSequence();
208   
209    /*
210    * Annotate positions 3/4/5 (CDE) with values 1/2/3
211    */
212  1 Annotation[] anns = new Annotation[] {
213    null, null, new Annotation(1), new Annotation(2), new Annotation(3) };
214  1 AlignmentAnnotation ann = new AlignmentAnnotation("SS",
215    "secondary structure", anns);
216  1 seq.addAlignmentAnnotation(ann);
217   
218    /*
219    * Check annotation map before modifying aligned sequence
220    */
221  1 assertNull(ann.getAnnotationForPosition(1));
222  1 assertNull(ann.getAnnotationForPosition(2));
223  1 assertNull(ann.getAnnotationForPosition(6));
224  1 assertNull(ann.getAnnotationForPosition(7));
225  1 assertEquals(1, ann.getAnnotationForPosition(3).value, 0.001d);
226  1 assertEquals(2, ann.getAnnotationForPosition(4).value, 0.001d);
227  1 assertEquals(3, ann.getAnnotationForPosition(5).value, 0.001d);
228   
229    /*
230    * Trim the displayed sequence to BCD and adjust annotations
231    */
232  1 seq.setSequence("BCD");
233  1 seq.setStart(2);
234  1 seq.setEnd(4);
235  1 ann.adjustForAlignment();
236   
237    /*
238    * Should now have annotations for aligned positions 2, 3Q (CD) only
239    */
240  1 assertEquals(3, ann.annotations.length);
241  1 assertNull(ann.annotations[0]);
242  1 assertEquals(1, ann.annotations[1].value, 0.001);
243  1 assertEquals(2, ann.annotations[2].value, 0.001);
244    }
245   
246    /**
247    * Test the method that defaults rna symbol to the one matching the preceding
248    * unmatched opening bracket (if any)
249    */
 
250  1 toggle @Test(groups = { "Functional" })
251    public void testGetDefaultRnaHelixSymbol()
252    {
253  1 AlignmentAnnotation ann = new AlignmentAnnotation("SS",
254    "secondary structure", null);
255  1 assertEquals("(", ann.getDefaultRnaHelixSymbol(4));
256   
257  1 Annotation[] anns = new Annotation[20];
258  1 ann.annotations = anns;
259  1 assertEquals("(", ann.getDefaultRnaHelixSymbol(4));
260   
261  1 anns[1] = new Annotation("(", "S", '(', 0f);
262  1 assertEquals("(", ann.getDefaultRnaHelixSymbol(0));
263  1 assertEquals("(", ann.getDefaultRnaHelixSymbol(1));
264  1 assertEquals(")", ann.getDefaultRnaHelixSymbol(2));
265  1 assertEquals(")", ann.getDefaultRnaHelixSymbol(3));
266   
267    /*
268    * .(.[.{.<.}.>.).].
269    */
270  1 anns[1] = new Annotation("(", "S", '(', 0f);
271  1 anns[3] = new Annotation("[", "S", '[', 0f);
272  1 anns[5] = new Annotation("{", "S", '{', 0f);
273  1 anns[7] = new Annotation("<", "S", '<', 0f);
274  1 anns[9] = new Annotation("}", "S", '}', 0f);
275  1 anns[11] = new Annotation(">", "S", '>', 0f);
276  1 anns[13] = new Annotation(")", "S", ')', 0f);
277  1 anns[15] = new Annotation("]", "S", ']', 0f);
278   
279  1 String expected = "(())]]}}>>>>]]]](";
280  18 for (int i = 0; i < expected.length(); i++)
281    {
282  17 assertEquals("column " + i, String.valueOf(expected.charAt(i)),
283    ann.getDefaultRnaHelixSymbol(i));
284    }
285   
286    /*
287    * .(.[.(.).{.}.<.].D.
288    */
289  1 anns[1] = new Annotation("(", "S", '(', 0f);
290  1 anns[3] = new Annotation("[", "S", '[', 0f);
291  1 anns[5] = new Annotation("(", "S", '(', 0f);
292  1 anns[7] = new Annotation(")", "S", ')', 0f);
293  1 anns[9] = new Annotation("{", "S", '{', 0f);
294  1 anns[11] = new Annotation("}", "S", '}', 0f);
295  1 anns[13] = new Annotation("<", "S", '>', 0f);
296  1 anns[15] = new Annotation("]", "S", ']', 0f);
297  1 anns[17] = new Annotation("D", "S", 'D', 0f);
298   
299  1 expected = "(())]]))]]}}]]>>>>dd";
300  21 for (int i = 0; i < expected.length(); i++)
301    {
302  20 assertEquals("column " + i, String.valueOf(expected.charAt(i)),
303    ann.getDefaultRnaHelixSymbol(i));
304    }
305    }
306   
 
307  15 toggle public static Annotation newAnnotation(String ann)
308    {
309  15 float val = 0f;
310  15 try
311    {
312  15 val = Float.parseFloat(ann);
313    } catch (NumberFormatException q)
314    {
315    }
316  15 ;
317  15 return new Annotation(ann, ann, '\0', val);
318    }
319   
 
320  1 toggle @Test(groups = { "Functional" })
321    public void testIsQuantitative()
322    {
323  1 AlignmentAnnotation ann = null;
324   
325  1 ann = new AlignmentAnnotation("an", "some an", null);
326  1 Assert
327    .assertFalse(ann.isQuantitative(),
328    "Empty annotation set should not be quantitative.");
329   
330  1 ann = new AlignmentAnnotation("an", "some an",
331    new Annotation[] {
332    newAnnotation("4"), newAnnotation("1"), newAnnotation("1"),
333    newAnnotation("0.1"), newAnnotation("0.3") });
334  1 Assert
335    .assertTrue(ann.isQuantitative(),
336    "All numbers annotation set should be quantitative.");
337   
338  1 ann = new AlignmentAnnotation("an", "some an",
339    new Annotation[] {
340    newAnnotation("E"), newAnnotation("E"), newAnnotation("E"),
341    newAnnotation("E"), newAnnotation("E") });
342  1 Assert
343    .assertFalse(ann.isQuantitative(),
344    "All 'E' annotation set should not be quantitative.");
345   
346  1 ann = new AlignmentAnnotation("an", "some an",
347    new Annotation[] {
348    newAnnotation("E"), newAnnotation("1"), newAnnotation("2"),
349    newAnnotation("3"), newAnnotation("E") });
350  1 Assert
351    .assertTrue(ann.isQuantitative(),
352    "Mixed 'E' annotation set should be quantitative.");
353    }
354   
 
355  1 toggle @Test(groups = "Functional")
356    public void testMakeVisibleAnnotation()
357    {
358  1 HiddenColumns h = new HiddenColumns();
359  1 Annotation[] anns = new Annotation[] {
360    null, null, new Annotation(1), new Annotation(2), new Annotation(3),
361    null, null, new Annotation(4), new Annotation(5), new Annotation(6),
362    new Annotation(7), new Annotation(8) };
363  1 AlignmentAnnotation ann = new AlignmentAnnotation("an", "some an", anns);
364   
365    // null annotations
366  1 AlignmentAnnotation emptyann = new AlignmentAnnotation("an", "some ann",
367    null);
368  1 emptyann.makeVisibleAnnotation(h);
369  1 assertNull(emptyann.annotations);
370   
371  1 emptyann.makeVisibleAnnotation(3, 4, h);
372  1 assertNull(emptyann.annotations);
373   
374    // without bounds, does everything
375  1 ann.makeVisibleAnnotation(h);
376  1 assertEquals(12, ann.annotations.length);
377  1 assertNull(ann.annotations[0]);
378  1 assertNull(ann.annotations[1]);
379  1 assertEquals(1.0f, ann.annotations[2].value);
380  1 assertEquals(2.0f, ann.annotations[3].value);
381  1 assertEquals(3.0f, ann.annotations[4].value);
382  1 assertNull(ann.annotations[5]);
383  1 assertNull(ann.annotations[6]);
384  1 assertEquals(4.0f, ann.annotations[7].value);
385  1 assertEquals(5.0f, ann.annotations[8].value);
386  1 assertEquals(6.0f, ann.annotations[9].value);
387  1 assertEquals(7.0f, ann.annotations[10].value);
388  1 assertEquals(8.0f, ann.annotations[11].value);
389   
390    // without hidden cols, just truncates
391  1 ann.makeVisibleAnnotation(3, 5, h);
392  1 assertEquals(3, ann.annotations.length);
393  1 assertEquals(2.0f, ann.annotations[0].value);
394  1 assertEquals(3.0f, ann.annotations[1].value);
395  1 assertNull(ann.annotations[2]);
396   
397  1 anns = new Annotation[] {
398    null, null, new Annotation(1), new Annotation(2), new Annotation(3),
399    null, null, new Annotation(4), new Annotation(5), new Annotation(6),
400    new Annotation(7), new Annotation(8) };
401  1 ann = new AlignmentAnnotation("an", "some an", anns);
402  1 h.hideColumns(4, 7);
403  1 ann.makeVisibleAnnotation(1, 9, h);
404  1 assertEquals(5, ann.annotations.length);
405  1 assertNull(ann.annotations[0]);
406  1 assertEquals(1.0f, ann.annotations[1].value);
407  1 assertEquals(2.0f, ann.annotations[2].value);
408  1 assertEquals(5.0f, ann.annotations[3].value);
409  1 assertEquals(6.0f, ann.annotations[4].value);
410   
411  1 anns = new Annotation[] {
412    null, null, new Annotation(1), new Annotation(2), new Annotation(3),
413    null, null, new Annotation(4), new Annotation(5), new Annotation(6),
414    new Annotation(7), new Annotation(8) };
415  1 ann = new AlignmentAnnotation("an", "some an", anns);
416  1 h.hideColumns(1, 2);
417  1 ann.makeVisibleAnnotation(1, 9, h);
418  1 assertEquals(3, ann.annotations.length);
419  1 assertEquals(2.0f, ann.annotations[0].value);
420  1 assertEquals(5.0f, ann.annotations[1].value);
421  1 assertEquals(6.0f, ann.annotations[2].value);
422   
423  1 anns = new Annotation[] {
424    null, null, new Annotation(1), new Annotation(2), new Annotation(3),
425    null, null, new Annotation(4), new Annotation(5), new Annotation(6),
426    new Annotation(7), new Annotation(8), new Annotation(9),
427    new Annotation(10), new Annotation(11), new Annotation(12),
428    new Annotation(13), new Annotation(14), new Annotation(15) };
429  1 ann = new AlignmentAnnotation("an", "some an", anns);
430  1 h = new HiddenColumns();
431  1 h.hideColumns(6, 18);
432  1 h.hideColumns(20, 21);
433  1 ann.makeVisibleAnnotation(1, 21, h);
434  1 assertEquals(5, ann.annotations.length);
435  1 assertNull(ann.annotations[0]);
436  1 assertEquals(1.0f, ann.annotations[1].value);
437  1 assertEquals(2.0f, ann.annotations[2].value);
438  1 assertEquals(3.0f, ann.annotations[3].value);
439  1 assertNull(ann.annotations[4]);
440    }
441   
442    /**
443    * test the contact matrix nogroups property methods
444    */
 
445  1 toggle @Test(groups = { "Functional" })
446    public void test_contactMatrixGroups()
447    {
448  1 AlignmentAnnotation aa = new AlignmentAnnotation("foo", "foo desc",
449    null);
450  1 assertTrue(aa.isShowGroupsForContactMatrix());
451  1 aa.setShowGroupsForContactMatrix(false);
452  1 assertFalse(aa.isShowGroupsForContactMatrix());
453  1 AlignmentAnnotation copy = new AlignmentAnnotation(aa);
454  1 assertFalse(copy.isShowGroupsForContactMatrix());
455  1 aa.setShowGroupsForContactMatrix(true);
456  1 assertTrue(aa.isShowGroupsForContactMatrix());
457    // copy should not be updated
458  1 assertFalse(copy.isShowGroupsForContactMatrix());
459   
460    }
461   
 
462  1 toggle @DataProvider(name = "data_labelAndCalcIdMatches")
463    public Object[][] testData()
464    {
465  1 String label = "label";
466  1 String wrongLabel = "wrongLabel";
467  1 String calcId = "123";
468  1 String wrongCalcId = "abc";
469  1 AlignmentAnnotation aaWithCalcId = new AlignmentAnnotation(label, "foo desc",
470    null);
471  1 aaWithCalcId.setCalcId(calcId);
472   
473  1 AlignmentAnnotation aaWithoutCalcId = new AlignmentAnnotation(label, "foo desc",
474    null);
475  1 return new Object[][] { { aaWithCalcId, label, calcId, true },
476    { aaWithCalcId, wrongLabel, calcId, false },
477    { aaWithCalcId, label, wrongCalcId, false },
478    { aaWithCalcId, wrongLabel, wrongCalcId, false },
479    { aaWithCalcId, label, null, false },
480    { aaWithoutCalcId, label, "", true },
481    { aaWithoutCalcId, label, calcId, false },
482    { aaWithoutCalcId, wrongLabel, null, false },
483    { aaWithoutCalcId, wrongLabel, wrongCalcId, false },
484    };
485    }
486   
487    /**
488    * test the labelAndCalcIdMatches method
489    */
 
490  9 toggle @Test(groups = { "Functional" }, dataProvider = "data_labelAndCalcIdMatches")
491    public void test_labelAndCalcIdMatches(AlignmentAnnotation aa, String label, String calcId, boolean expected)
492    {
493  9 boolean result = aa.labelAndCalcIdMatches(label, calcId);
494  9 assertEquals(expected, result);
495    }
496   
497   
 
498  1 toggle @Test(groups = "Functional")
499    public void testMakeVisibleAnnotation_NullAnnotationsAndNoColsHidden()
500    {
501  1 AlignmentAnnotation ann = new AlignmentAnnotation("label", "desc", null);
502  1 HiddenColumns hc = new HiddenColumns();
503  1 ann.makeVisibleAnnotation(hc);
504  1 assertThat(ann.annotations, is(nullValue()));
505    }
506   
 
507  1 toggle @Test(groups = "Functional")
508    public void testMakeVisibleAnnotation_NullAnnotationsAndTrim()
509    {
510  1 AlignmentAnnotation ann = new AlignmentAnnotation("label", "desc", null);
511  1 HiddenColumns hc = new HiddenColumns();
512  1 ann.makeVisibleAnnotation(3, 5, hc);
513  1 assertThat(ann.annotations, is(nullValue()));
514    }
515   
 
516  1 toggle @Test(groups = "Functional")
517    public void testMakeVisibleAnnotation_NoColsHidden()
518    {
519  1 Annotation[] annots = new Annotation[] {
520    EMPTY_ANNOTATION, EMPTY_ANNOTATION, new Annotation(1),
521    new Annotation(2), new Annotation(3), EMPTY_ANNOTATION,
522    EMPTY_ANNOTATION, new Annotation(4), new Annotation(5),
523    EMPTY_ANNOTATION, new Annotation(6), new Annotation(7),
524    new Annotation(8) };
525  1 AlignmentAnnotation ann = new AlignmentAnnotation("label", "desc", annots);
526  1 HiddenColumns hc = new HiddenColumns();
527  1 ann.makeVisibleAnnotation(hc);
528  1 assertThat(ann.annotations, matchesAnnotations(annots));
529    }
530   
 
531  1 toggle @Test(groups = "Functional")
532    public void testMakeVisibleAnnotation_HideCols()
533    {
534  1 Annotation[] annots = new Annotation[] {
535    new Annotation(0), new Annotation(1), new Annotation(2),
536    new Annotation(3), new Annotation(4), new Annotation(5),
537    new Annotation(6), new Annotation(7), new Annotation(8) };
538  1 AlignmentAnnotation ann = new AlignmentAnnotation("label", "desc", annots);
539  1 HiddenColumns hc = new HiddenColumns();
540  1 hc.hideColumns(2, 6);
541  1 ann.makeVisibleAnnotation(hc);
542  1 var expected = new Annotation[] {
543    new Annotation(0), new Annotation(1), new Annotation(7),
544    new Annotation(8) };
545  1 assertThat(ann.annotations, matchesAnnotations(expected));
546    }
547   
 
548  1 toggle @Test(groups = "Functional")
549    public void testMakeVisibleAnnotation_ExplicitFullWidthAndHideCols()
550    {
551  1 Annotation[] annots = new Annotation[] {
552    new Annotation(0), new Annotation(1), new Annotation(2),
553    new Annotation(3), new Annotation(4), new Annotation(5),
554    new Annotation(6), new Annotation(7), new Annotation(8),
555    new Annotation(9), new Annotation(10), new Annotation(11) };
556  1 AlignmentAnnotation ann = new AlignmentAnnotation("label", "desc", annots);
557  1 HiddenColumns hc = new HiddenColumns();
558  1 hc.hideColumns(4, 7);
559  1 ann.makeVisibleAnnotation(0, 11, hc);
560  1 assertThat(ann.annotations,
561    matchesAnnotations(new Annotation(0), new Annotation(1),
562    new Annotation(2), new Annotation(3), new Annotation(8),
563    new Annotation(9), new Annotation(10), new Annotation(11)));
564    }
565   
 
566  1 toggle @Test(groups = "Functional")
567    public void testMakeVisibleAnnotation_ExplicitFullWidthAndHideCols2()
568    {
569  1 Annotation[] annots = new Annotation[] {
570    new Annotation(0), new Annotation(1), new Annotation(2),
571    new Annotation(3), new Annotation(4), new Annotation(5),
572    new Annotation(6), new Annotation(7), new Annotation(8), };
573  1 AlignmentAnnotation ann = new AlignmentAnnotation("label", "desc", annots);
574  1 HiddenColumns hc = new HiddenColumns();
575  1 hc.hideColumns(4, 7);
576  1 ann.makeVisibleAnnotation(0, 8, hc);
577  1 assertThat(ann.annotations,
578    matchesAnnotations(new Annotation(0), new Annotation(1),
579    new Annotation(2), new Annotation(3), new Annotation(8)));
580    }
581   
 
582  1 toggle @Test(groups = "Functional")
583    public void testMakeVisibleAnnotation_HideColsWithEmptyAnnots()
584    {
585  1 Annotation[] annots = new Annotation[] {
586    EMPTY_ANNOTATION, EMPTY_ANNOTATION, new Annotation(1),
587    new Annotation(2), new Annotation(3), EMPTY_ANNOTATION,
588    EMPTY_ANNOTATION, new Annotation(4), new Annotation(5),
589    EMPTY_ANNOTATION, new Annotation(6), new Annotation(7),
590    new Annotation(8) };
591  1 AlignmentAnnotation ann = new AlignmentAnnotation("label", "desc", annots);
592  1 HiddenColumns hc = new HiddenColumns();
593  1 hc.hideColumns(1, 3);
594  1 hc.hideColumns(8, 9);
595  1 ann.makeVisibleAnnotation(hc);
596  1 var expected = new Annotation[] {
597    EMPTY_ANNOTATION, new Annotation(3), EMPTY_ANNOTATION, EMPTY_ANNOTATION,
598    new Annotation(4), new Annotation(6), new Annotation(7),
599    new Annotation(8) };
600  1 assertThat(ann.annotations, matchesAnnotations(expected));
601    }
602   
 
603  1 toggle @Test(groups = "Functional")
604    public void testMakeVisibleAnnotation_HideColsWithNullAnnots()
605    {
606  1 Annotation[] annots = new Annotation[] {
607    null, null, new Annotation(2), null, new Annotation(4),
608    new Annotation(5), null, null };
609  1 AlignmentAnnotation ann = new AlignmentAnnotation("label", "desc", annots);
610  1 HiddenColumns hc = new HiddenColumns();
611  1 hc.hideColumns(2, 4);
612  1 ann.makeVisibleAnnotation(hc);
613  1 var expected = new Annotation[] {
614    null, null, new Annotation(5), null, null };
615  1 assertThat(ann.annotations, matchesAnnotations(expected));
616    }
617   
 
618  1 toggle @Test(groups = "Functional")
619    public void testMakeVisibleAnnotation_Truncate()
620    {
621  1 Annotation[] annots = new Annotation[] {
622    new Annotation(0), new Annotation(1), new Annotation(2),
623    new Annotation(3), new Annotation(4), new Annotation(5),
624    new Annotation(6), new Annotation(7) };
625  1 AlignmentAnnotation ann = new AlignmentAnnotation("label", "desc", annots);
626  1 ann.makeVisibleAnnotation(3, 6, new HiddenColumns());
627  1 assertThat(ann.annotations, matchesAnnotations(new Annotation(3),
628    new Annotation(4), new Annotation(5), new Annotation(6)));
629    }
630   
 
631  1 toggle @Test(groups = "Functional")
632    public void testMakeVisibleAnnotation_TruncateAndHideColumns()
633    {
634  1 Annotation[] annots = new Annotation[] {
635    new Annotation(0), new Annotation(1), new Annotation(2),
636    new Annotation(3), new Annotation(4), new Annotation(5),
637    new Annotation(6), new Annotation(7), new Annotation(8),
638    new Annotation(9), new Annotation(10), new Annotation(11) };
639  1 AlignmentAnnotation ann = new AlignmentAnnotation("label", "desc", annots);
640  1 HiddenColumns hc = new HiddenColumns();
641  1 hc.hideColumns(4, 7);
642  1 ann.makeVisibleAnnotation(1, 9, hc);
643  1 assertThat(ann.annotations,
644    matchesAnnotations(new Annotation(1), new Annotation(2),
645    new Annotation(3), new Annotation(8), new Annotation(9)));
646    }
647   
 
648  1 toggle @Test(groups = "Functional")
649    public void testMakeVisibleAnnotation_TruncateNegativeStart()
650    {
651  1 Annotation[] annots = annotsRange(8);
652  1 AlignmentAnnotation ann = new AlignmentAnnotation("label", "desc", annots);
653  1 HiddenColumns hc = new HiddenColumns();
654  1 ann.makeVisibleAnnotation(-5, 1, hc);
655  1 assertThat(ann.annotations,
656    matchesAnnotations(new Annotation(0), new Annotation(1)));
657    }
658   
 
659  1 toggle @Test(groups = "Functional")
660    public void testMakeVisibleAnnotation_TruncateNegativeStartAndEnd()
661    {
662  1 Annotation[] annots = annotsRange(8);
663  1 AlignmentAnnotation ann = new AlignmentAnnotation("label", "desc", annots);
664  1 HiddenColumns hc = new HiddenColumns();
665  1 ann.makeVisibleAnnotation(-5, -2, hc);
666  1 assertThat(ann.annotations, is(emptyArray()));
667    }
668   
 
669  1 toggle @Test(groups = "Functional")
670    public void testMakeVisibleAnnotation_TruncateEndBeyondSize()
671    {
672  1 Annotation[] annots = annotsRange(8);
673  1 AlignmentAnnotation ann = new AlignmentAnnotation("label", "desc", annots);
674  1 HiddenColumns hc = new HiddenColumns();
675  1 ann.makeVisibleAnnotation(6, 10, hc);
676  1 assertThat(ann.annotations, matchesAnnotations(new Annotation(6), new Annotation(7)));
677    }
678   
 
679  1 toggle @Test(groups = "Functional")
680    public void testMakeVisibleAnnotation_TruncateStartAndEndBeyondSize()
681    {
682  1 Annotation[] annots = annotsRange(4);
683  1 AlignmentAnnotation ann = new AlignmentAnnotation("label", "desc", annots);
684  1 HiddenColumns hc = new HiddenColumns();
685  1 ann.makeVisibleAnnotation(6, 10, hc);
686  1 assertThat(ann.annotations, is(emptyArray()));
687    }
688   
 
689  1 toggle @Test(groups = "Functional")
690    public void testMakeVisibleAnnotation_HiddenRegionBeyondSize()
691    {
692  1 Annotation[] annots = annotsRange(4);
693  1 AlignmentAnnotation ann = new AlignmentAnnotation("label", "desc", annots);
694  1 HiddenColumns hc = new HiddenColumns();
695  1 hc.hideColumns(6, 7);
696  1 ann.makeVisibleAnnotation(hc);
697  1 assertThat(ann.annotations, matchesAnnotations(annots));
698    }
699   
 
700  1 toggle @Test(groups = "Functional")
701    public void testMakeVisibleAnnotation_HiddenRegionAndTrimEndBeyondSize()
702    {
703  1 Annotation[] annots = annotsRange(4);
704  1 AlignmentAnnotation ann = new AlignmentAnnotation("label", "desc", annots);
705  1 HiddenColumns hc = new HiddenColumns();
706  1 hc.hideColumns(6, 7);
707  1 ann.makeVisibleAnnotation(0, 10, hc);
708  1 assertThat(ann.annotations, matchesAnnotations(annots));
709    }
710   
 
711  1 toggle @Test(groups = "Functional")
712    public void testMakeVisibleAnnotation_HiddenRegionBeforeStart()
713    {
714  1 Annotation[] annots = annotsRange(4);
715  1 AlignmentAnnotation ann = new AlignmentAnnotation("label", "desc", annots);
716  1 HiddenColumns hc = new HiddenColumns();
717  1 hc.hideColumns(-3, -2);
718  1 ann.makeVisibleAnnotation(hc);
719  1 assertThat(ann.annotations, matchesAnnotations(annots));
720    }
721   
 
722  1 toggle @Test(groups = "Functional")
723    public void testMakeVisibleAnnotation_HiddenRegionAndTrimStartBeforeStart()
724    {
725  1 Annotation[] annots = annotsRange(4);
726  1 AlignmentAnnotation ann = new AlignmentAnnotation("label", "desc", annots);
727  1 HiddenColumns hc = new HiddenColumns();
728  1 hc.hideColumns(-3, -2);
729  1 ann.makeVisibleAnnotation(-5, annots.length - 1, hc);
730  1 assertThat(ann.annotations, matchesAnnotations(annots));
731    }
732   
 
733  8 toggle static Annotation[] annotsRange(int stop)
734    {
735  8 Annotation[] annotations = new Annotation[stop];
736  52 for (int i = 0; i < stop; i++)
737  44 annotations[i] = new Annotation(i);
738  8 return annotations;
739    }
740    }