Clover icon

Coverage Report

  1. Project Clover database Tue Mar 10 2026 14:58:44 GMT
  2. Package jalview.gui

File AlignViewportTest.java

 

Code metrics

6
246
15
1
587
412
22
0.09
16.4
15
1.47

Classes

Class Line # Actions
AlignViewportTest 63 246 22
0.00%
 

Contributing tests

No tests hitting this source file were found.

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.gui;
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.assertSame;
28    import static org.testng.AssertJUnit.assertTrue;
29   
30    import jalview.api.AlignViewportI;
31    import java.util.ArrayList;
32    import java.util.List;
33   
34    import org.testng.Assert;
35    import org.testng.annotations.BeforeClass;
36    import org.testng.annotations.BeforeMethod;
37    import org.testng.annotations.Test;
38   
39    import jalview.bin.Cache;
40    import jalview.bin.Jalview;
41    import jalview.datamodel.AlignedCodonFrame;
42    import jalview.datamodel.Alignment;
43    import jalview.datamodel.AlignmentAnnotation;
44    import jalview.datamodel.AlignmentI;
45    import jalview.datamodel.Annotation;
46    import jalview.datamodel.ContactMatrixI;
47    import jalview.datamodel.SearchResults;
48    import jalview.datamodel.SearchResultsI;
49    import jalview.datamodel.SeqDistanceContactMatrix;
50    import jalview.datamodel.Sequence;
51    import jalview.datamodel.SequenceGroup;
52    import jalview.datamodel.SequenceI;
53    import jalview.io.DataSourceType;
54    import jalview.io.FileLoader;
55    import jalview.schemes.ClustalxColourScheme;
56    import jalview.schemes.ColourSchemeI;
57    import jalview.schemes.PIDColourScheme;
58    import jalview.structure.StructureSelectionManager;
59    import jalview.util.MapList;
60    import jalview.viewmodel.AlignmentViewport;
61    import jalview.viewmodel.ViewportRanges;
62   
 
63    public class AlignViewportTest
64    {
65   
 
66  0 toggle @BeforeClass(alwaysRun = true)
67    public void setUpJvOptionPane()
68    {
69  0 JvOptionPane.setInteractiveMode(false);
70  0 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
71    }
72   
73    AlignmentI al;
74   
75    AlignmentViewport testee;
76   
 
77  0 toggle @BeforeClass(alwaysRun = true)
78    public static void setUpBeforeClass() throws Exception
79    {
80  0 Jalview.main(
81    new String[]
82    { "--nonews", "--props", "test/jalview/testProps.jvprops" });
83   
84    /*
85    * remove any sequence mappings left lying around by other tests
86    */
87  0 StructureSelectionManager ssm = StructureSelectionManager
88    .getStructureSelectionManager(Desktop.getInstance());
89  0 ssm.resetAll();
90    }
91   
 
92  0 toggle @BeforeMethod(alwaysRun = true)
93    public void setUp()
94    {
95  0 SequenceI seq1 = new Sequence("Seq1", "ABC");
96  0 SequenceI seq2 = new Sequence("Seq2", "ABC");
97  0 SequenceI seq3 = new Sequence("Seq3", "ABC");
98  0 SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3 };
99  0 al = new Alignment(seqs);
100  0 al.setDataset(null);
101  0 testee = new AlignViewport(al);
102    }
103   
104    /**
105    * Test that a mapping is not deregistered when a second view is closed but
106    * the first still holds a reference to the mapping
107    */
 
108  0 toggle @Test(groups = { "Functional" })
109    public void testDeregisterMapping_onCloseView()
110    {
111    /*
112    * alignment with reference to mappings
113    */
114  0 AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded(
115    ">Seq1\nCAGT\n", DataSourceType.PASTE);
116   
117  0 SequenceI s1 = af1.getViewport().getAlignment().getSequenceAt(0);
118  0 AlignedCodonFrame acf1 = new AlignedCodonFrame();
119  0 acf1.addMap(s1, s1, new MapList(new int[] { 1, 4 }, new int[] { 1, 4 },
120    1, 1));
121  0 AlignedCodonFrame acf2 = new AlignedCodonFrame();
122  0 acf2.addMap(s1, s1, new MapList(new int[] { 1, 4 }, new int[] { 4, 1 },
123    1, 1));
124   
125  0 List<AlignedCodonFrame> mappings = new ArrayList<>();
126  0 mappings.add(acf1);
127  0 mappings.add(acf2);
128  0 af1.getViewport().getAlignment().setCodonFrames(mappings);
129  0 af1.newView_actionPerformed(null);
130   
131    /*
132    * Verify that creating the alignment for the new View has registered the
133    * mappings
134    */
135  0 StructureSelectionManager ssm = StructureSelectionManager
136    .getStructureSelectionManager(Desktop.getInstance());
137  0 List<AlignedCodonFrame> sequenceMappings = ssm.getSequenceMappings();
138  0 assertEquals(2, sequenceMappings.size());
139  0 assertTrue(sequenceMappings.contains(acf1));
140  0 assertTrue(sequenceMappings.contains(acf2));
141   
142    /*
143    * Close the second view. Verify that mappings are not removed as the first
144    * view still holds a reference to them.
145    */
146  0 af1.closeMenuItem_actionPerformed(false);
147  0 assertEquals(2, sequenceMappings.size());
148  0 assertTrue(sequenceMappings.contains(acf1));
149  0 assertTrue(sequenceMappings.contains(acf2));
150    }
151   
152    /**
153    * Test that a mapping is deregistered if no alignment holds a reference to it
154    */
 
155  0 toggle @Test(groups = { "Functional" })
156    public void testDeregisterMapping_withNoReference()
157    {
158  0 Desktop d = Desktop.getInstance();
159  0 assertNotNull(d);
160  0 StructureSelectionManager ssm = StructureSelectionManager
161    .getStructureSelectionManager(Desktop.getInstance());
162  0 ssm.resetAll();
163   
164  0 AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded(
165    ">Seq1\nRSVQ\n", DataSourceType.PASTE);
166  0 AlignFrame af2 = new FileLoader().LoadFileWaitTillLoaded(
167    ">Seq2\nDGEL\n", DataSourceType.PASTE);
168  0 SequenceI cs1 = new Sequence("cseq1", "CCCGGGTTTAAA");
169  0 SequenceI cs2 = new Sequence("cseq2", "CTTGAGTCTAGA");
170  0 SequenceI s1 = af1.getViewport().getAlignment().getSequenceAt(0);
171  0 SequenceI s2 = af2.getViewport().getAlignment().getSequenceAt(0);
172    // need to be distinct
173  0 AlignedCodonFrame acf1 = new AlignedCodonFrame();
174  0 acf1.addMap(cs1, s1, new MapList(new int[] { 1, 4 },
175    new int[] { 1, 12 }, 1, 3));
176  0 AlignedCodonFrame acf2 = new AlignedCodonFrame();
177  0 acf2.addMap(cs2, s2, new MapList(new int[] { 1, 4 },
178    new int[] { 1, 12 }, 1, 3));
179  0 AlignedCodonFrame acf3 = new AlignedCodonFrame();
180  0 acf3.addMap(cs2, cs2, new MapList(new int[] { 1, 12 }, new int[] { 1,
181    12 }, 1, 1));
182   
183  0 List<AlignedCodonFrame> mappings1 = new ArrayList<>();
184  0 mappings1.add(acf1);
185  0 af1.getViewport().getAlignment().setCodonFrames(mappings1);
186   
187  0 List<AlignedCodonFrame> mappings2 = new ArrayList<>();
188  0 mappings2.add(acf2);
189  0 mappings2.add(acf3);
190  0 af2.getViewport().getAlignment().setCodonFrames(mappings2);
191   
192    /*
193    * AlignFrame1 has mapping acf1, AlignFrame2 has acf2 and acf3
194    */
195   
196  0 List<AlignedCodonFrame> ssmMappings = ssm.getSequenceMappings();
197  0 assertEquals(0, ssmMappings.size());
198  0 ssm.registerMapping(acf1);
199  0 assertEquals(1, ssmMappings.size());
200  0 ssm.registerMapping(acf2);
201  0 assertEquals(2, ssmMappings.size());
202  0 ssm.registerMapping(acf3);
203  0 assertEquals(3, ssmMappings.size());
204   
205    /*
206    * Closing AlignFrame2 should remove its mappings from
207    * StructureSelectionManager, since AlignFrame1 has no reference to them
208    */
209  0 af2.closeMenuItem_actionPerformed(true);
210  0 assertEquals(1, ssmMappings.size());
211  0 assertTrue(ssmMappings.contains(acf1));
212    }
213   
214    /**
215    * Test that a mapping is not deregistered if another alignment holds a
216    * reference to it
217    */
 
218  0 toggle @Test(groups = { "Functional" })
219    public void testDeregisterMapping_withReference()
220    {
221  0 Desktop d = Desktop.getInstance();
222  0 assertNotNull(d);
223  0 StructureSelectionManager ssm = StructureSelectionManager
224    .getStructureSelectionManager(Desktop.getInstance());
225  0 ssm.resetAll();
226   
227  0 AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded(
228    ">Seq1\nRSVQ\n", DataSourceType.PASTE);
229  0 AlignFrame af2 = new FileLoader().LoadFileWaitTillLoaded(
230    ">Seq2\nDGEL\n", DataSourceType.PASTE);
231  0 SequenceI cs1 = new Sequence("cseq1", "CCCGGGTTTAAA");
232  0 SequenceI cs2 = new Sequence("cseq2", "CTTGAGTCTAGA");
233  0 SequenceI s1 = af1.getViewport().getAlignment().getSequenceAt(0);
234  0 SequenceI s2 = af2.getViewport().getAlignment().getSequenceAt(0);
235    // need to be distinct
236  0 AlignedCodonFrame acf1 = new AlignedCodonFrame();
237  0 acf1.addMap(cs1, s1, new MapList(new int[] { 1, 4 },
238    new int[] { 1, 12 }, 1, 3));
239  0 AlignedCodonFrame acf2 = new AlignedCodonFrame();
240  0 acf2.addMap(cs2, s2, new MapList(new int[] { 1, 4 },
241    new int[] { 1, 12 }, 1, 3));
242  0 AlignedCodonFrame acf3 = new AlignedCodonFrame();
243  0 acf3.addMap(cs2, cs2, new MapList(new int[] { 1, 12 }, new int[] { 1,
244    12 }, 1, 1));
245   
246  0 List<AlignedCodonFrame> mappings1 = new ArrayList<>();
247  0 mappings1.add(acf1);
248  0 mappings1.add(acf2);
249  0 af1.getViewport().getAlignment().setCodonFrames(mappings1);
250   
251  0 List<AlignedCodonFrame> mappings2 = new ArrayList<>();
252  0 mappings2.add(acf2);
253  0 mappings2.add(acf3);
254  0 af2.getViewport().getAlignment().setCodonFrames(mappings2);
255   
256    /*
257    * AlignFrame1 has mappings acf1 and acf2, AlignFrame2 has acf2 and acf3
258    */
259   
260  0 List<AlignedCodonFrame> ssmMappings = ssm.getSequenceMappings();
261  0 assertEquals(0, ssmMappings.size());
262  0 ssm.registerMapping(acf1);
263  0 assertEquals(1, ssmMappings.size());
264  0 ssm.registerMapping(acf2);
265  0 assertEquals(2, ssmMappings.size());
266  0 ssm.registerMapping(acf3);
267  0 assertEquals(3, ssmMappings.size());
268   
269    /*
270    * Closing AlignFrame2 should remove mapping acf3 from
271    * StructureSelectionManager, but not acf2, since AlignFrame1 still has a
272    * reference to it
273    */
274  0 af2.closeMenuItem_actionPerformed(true);
275  0 assertEquals(2, ssmMappings.size());
276  0 assertTrue(ssmMappings.contains(acf1));
277  0 assertTrue(ssmMappings.contains(acf2));
278  0 assertFalse(ssmMappings.contains(acf3));
279    }
280   
281    /**
282    * Test for JAL-1306 - conservation thread should run even when only Quality
283    * (and not Conservation) is enabled in Preferences
284    */
 
285  0 toggle @Test(groups = { "Functional" }, timeOut=2000)
286    public void testUpdateConservation_qualityOnly()
287    {
288  0 Cache.setPropertyNoSave("SHOW_ANNOTATIONS",
289    Boolean.TRUE.toString());
290  0 Cache.setPropertyNoSave("SHOW_QUALITY",
291    Boolean.TRUE.toString());
292  0 Cache.setPropertyNoSave("SHOW_CONSERVATION",
293    Boolean.FALSE.toString());
294  0 Cache.setPropertyNoSave("SHOW_OCCUPANCY",
295    Boolean.FALSE.toString());
296  0 Cache.setPropertyNoSave("SHOW_IDENTITY",
297    Boolean.FALSE.toString());
298  0 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
299    "examples/uniref50.fa", DataSourceType.FILE);
300   
301    /*
302    * wait for Conservation thread to complete
303    */
304  0 AlignViewport viewport = af.getViewport();
305  0 waitForCalculations(viewport);
306  0 AlignmentAnnotation[] anns = viewport.getAlignment()
307    .getAlignmentAnnotation();
308  0 assertNotNull("No annotations found", anns);
309  0 assertEquals("More than one annotation found", 1, anns.length);
310  0 assertTrue("Annotation is not Quality",
311    anns[0].description.startsWith("Alignment Quality"));
312  0 Annotation[] annotations = anns[0].annotations;
313  0 assertNotNull("Quality annotations are null", annotations);
314  0 assertNotNull("Quality in column 1 is null", annotations[0]);
315  0 assertTrue("No quality value in column 1", annotations[0].value > 10f);
316    }
317   
318    /**
319    * Wait for consensus etc calculation threads to complete
320    *
321    * @param viewport
322    */
 
323  0 toggle protected void waitForCalculations(AlignViewport viewport)
324    {
325  0 synchronized (this)
326    {
327  0 System.out.print("waiting...");
328  0 int n = 3;
329  0 while (--n >= 0 || viewport.getCalcManager().isWorking())
330    {
331  0 try
332    {
333  0 wait(50);
334    } catch (InterruptedException e)
335    {
336    }
337    }
338  0 System.out.println("...done");
339    }
340    }
341   
 
342  0 toggle @Test(groups = { "Functional" })
343    public void testSetGlobalColourScheme()
344    {
345    /*
346    * test for JAL-2283: don't inadvertently turn on colour by conservation
347    */
348  0 Cache.setPropertyNoSave("DEFAULT_COLOUR_PROT", "None");
349  0 Cache.setPropertyNoSave("SHOW_CONSERVATION",
350    Boolean.TRUE.toString());
351  0 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
352    "examples/uniref50.fa", DataSourceType.FILE);
353  0 ColourSchemeI cs = new PIDColourScheme();
354  0 AlignViewport viewport = af.getViewport();
355  0 viewport.setGlobalColourScheme(cs);
356  0 assertFalse(viewport.getResidueShading()
357    .conservationApplied());
358   
359    /*
360    * JAL-3201 groups have their own ColourSchemeI instances
361    */
362  0 AlignmentI aln = viewport.getAlignment();
363  0 SequenceGroup sg1 = new SequenceGroup();
364  0 sg1.addSequence(aln.getSequenceAt(0), false);
365  0 sg1.addSequence(aln.getSequenceAt(2), false);
366  0 SequenceGroup sg2 = new SequenceGroup();
367  0 sg2.addSequence(aln.getSequenceAt(1), false);
368  0 sg2.addSequence(aln.getSequenceAt(3), false);
369  0 aln.addGroup(sg1);
370  0 aln.addGroup(sg2);
371  0 viewport.setColourAppliesToAllGroups(true);
372  0 viewport.setGlobalColourScheme(new ClustalxColourScheme());
373  0 ColourSchemeI cs0 = viewport.getGlobalColourScheme();
374  0 ColourSchemeI cs1 = sg1.getColourScheme();
375  0 ColourSchemeI cs2 = sg2.getColourScheme();
376  0 assertTrue(cs0 instanceof ClustalxColourScheme);
377  0 assertTrue(cs1 instanceof ClustalxColourScheme);
378  0 assertTrue(cs2 instanceof ClustalxColourScheme);
379  0 assertNotSame(cs0, cs1);
380  0 assertNotSame(cs0, cs2);
381  0 assertNotSame(cs1, cs2);
382    }
383   
 
384  0 toggle @Test(groups = { "Functional" })
385    public void testSetGetHasSearchResults()
386    {
387  0 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
388    "examples/uniref50.fa", DataSourceType.FILE);
389  0 SearchResultsI sr = new SearchResults();
390  0 SequenceI s1 = af.getViewport().getAlignment().getSequenceAt(0);
391   
392    // create arbitrary range on first sequence
393  0 sr.addResult(s1, s1.getStart() + 10, s1.getStart() + 15);
394   
395    // test set
396  0 af.getViewport().setSearchResults(sr);
397    // has -> true
398  0 assertTrue(af.getViewport().hasSearchResults());
399    // get == original
400  0 assertEquals(sr, af.getViewport().getSearchResults());
401   
402    // set(null) results in has -> false
403   
404  0 af.getViewport().setSearchResults(null);
405  0 assertFalse(af.getViewport().hasSearchResults());
406    }
407   
408    /**
409    * Verify that setting the selection group has the side-effect of setting the
410    * context on the group, unless it already has one, but does not change
411    * whether the group is defined or not.
412    */
 
413  0 toggle @Test(groups = { "Functional" })
414    public void testSetSelectionGroup()
415    {
416  0 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
417    "examples/uniref50.fa", DataSourceType.FILE);
418  0 AlignViewportI av = af.getViewport();
419  0 SequenceGroup sg1 = new SequenceGroup();
420  0 SequenceGroup sg2 = new SequenceGroup();
421  0 SequenceGroup sg3 = new SequenceGroup();
422   
423  0 av.setSelectionGroup(sg1);
424  0 assertSame(sg1.getContext(), av.getAlignment()); // context set
425  0 assertFalse(sg1.isDefined()); // group not defined
426   
427  0 sg2.setContext(sg1, false);
428  0 av.setSelectionGroup(sg2);
429  0 assertFalse(sg2.isDefined()); // unchanged
430  0 assertSame(sg2.getContext(), sg1); // unchanged
431   
432    // create a defined group
433  0 sg3.setContext(av.getAlignment(), true);
434  0 av.setSelectionGroup(sg3);
435  0 assertTrue(sg3.isDefined()); // unchanged
436    }
437    /**
438    * Verify that setting/clearing SHOW_OCCUPANCY preference adds or omits occupancy row from viewport
439    */
 
440  0 toggle @Test(groups = { "Functional" })
441    public void testShowOrDontShowOccupancy()
442    {
443    // disable occupancy
444  0 jalview.bin.Cache.setProperty("SHOW_OCCUPANCY", Boolean.FALSE.toString());
445  0 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
446    "examples/uniref50.fa", DataSourceType.FILE);
447  0 AlignViewportI av = af.getViewport();
448  0 while (av.getCalcManager().isWorking())
449    {
450  0 try {
451  0 Thread.sleep(5);
452    } catch (InterruptedException x) {}
453    }
454  0 Assert.assertNull(av.getAlignmentGapAnnotation(),
455    "Preference did not disable occupancy row.");
456  0 int c = 0;
457  0 for (AlignmentAnnotation aa : av.getAlignment().findAnnotations(null,
458    null, "Occupancy"))
459    {
460  0 c++;
461    }
462  0 Assert.assertEquals(c, 0, "Expected zero occupancy rows.");
463   
464    // enable occupancy
465  0 jalview.bin.Cache.setProperty("SHOW_OCCUPANCY", Boolean.TRUE.toString());
466  0 af = new FileLoader().LoadFileWaitTillLoaded(
467    "examples/uniref50.fa", DataSourceType.FILE);
468   
469  0 av = af.getViewport();
470   
471  0 while (av.getCalcManager().isWorking())
472    {
473  0 try {
474  0 Thread.sleep(5);
475    } catch (InterruptedException x) {}
476    }
477  0 Assert.assertNotNull(av.getAlignmentGapAnnotation(),
478    "Preference did not enable occupancy row.");
479  0 c = 0;
480  0 for (AlignmentAnnotation aa : av.getAlignment().findAnnotations(null,
481    null, av.getAlignmentGapAnnotation().label))
482    {
483  0 c++;
484  0 Assert.assertNotNull(aa.annotations);
485    // check that an arbitrary column has an occupancy of greater than zero
486  0 Assert.assertNotNull(aa.annotations[5],
487    "Expected occupancy to be non-null in column 5");
488  0 Assert.assertNotEquals(aa.annotations[5].value, 0f,
489    "Expected occupancy to not be zero in column 5");
490   
491    }
492  0 ;
493  0 Assert.assertEquals(c, 1, "Expected to find one occupancy row.");
494    }
495   
 
496  0 toggle @Test(groups = { "Functional" })
497    public void testGetConsensusSeq()
498    {
499    /*
500    * A-C
501    * A-C
502    * A-D
503    * --D
504    * consensus expected to be A-C
505    */
506  0 String fasta = ">s1\nA-C\n>s2\nA-C\n>s3\nA-D\n>s4\n--D\n";
507  0 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(fasta,
508    DataSourceType.PASTE);
509  0 AlignViewport testme = af.getViewport();
510  0 waitForCalculations(testme);
511  0 SequenceI cons = testme.getConsensusSeq();
512  0 assertEquals("A-C", cons.getSequenceAsString());
513    }
514   
 
515  0 toggle @Test(groups = { "Functional" })
516    public void testHideRevealSequences()
517    {
518  0 ViewportRanges ranges = testee.getRanges();
519  0 assertEquals(3, al.getHeight());
520  0 assertEquals(0, ranges.getStartSeq());
521  0 assertEquals(2, ranges.getEndSeq());
522   
523    /*
524    * hide first sequence
525    */
526  0 testee.hideSequence(new SequenceI[] { al.getSequenceAt(0) });
527  0 assertEquals(2, al.getHeight());
528  0 assertEquals(0, ranges.getStartSeq());
529  0 assertEquals(1, ranges.getEndSeq());
530   
531    /*
532    * reveal hidden sequences above the first
533    */
534  0 testee.showSequence(0);
535  0 assertEquals(3, al.getHeight());
536  0 assertEquals(0, ranges.getStartSeq());
537  0 assertEquals(2, ranges.getEndSeq());
538   
539    /*
540    * hide first and third sequences
541    */
542  0 testee.hideSequence(
543    new SequenceI[]
544    { al.getSequenceAt(0), al.getSequenceAt(2) });
545  0 assertEquals(1, al.getHeight());
546  0 assertEquals(0, ranges.getStartSeq());
547  0 assertEquals(0, ranges.getEndSeq());
548   
549    /*
550    * reveal all hidden sequences
551    */
552  0 testee.showAllHiddenSeqs();
553  0 assertEquals(3, al.getHeight());
554  0 assertEquals(0, ranges.getStartSeq());
555  0 assertEquals(2, ranges.getEndSeq());
556    }
557   
 
558  0 toggle @Test(groups = { "Functional" })
559    public void testGetSelectionAsNewSequences_withContactMatrices()
560    {
561  0 SequenceI seq = new Sequence("seq", "ACADA");
562  0 ContactMatrixI cmat = new SeqDistanceContactMatrix(5);
563  0 seq.addContactList(cmat);
564  0 Alignment al = new Alignment(new SequenceI[] { seq.deriveSequence() });
565  0 al.addAnnotation(al.getSequenceAt(0).getAnnotation()[0]);
566  0 AlignFrame af = new AlignFrame(al, 500, 500);
567   
568  0 SequenceI selseqs[] = af.getViewport().getSelectionAsNewSequence();
569  0 assertNotNull(selseqs[0].getAnnotation());
570  0 assertNotNull(selseqs[0].getAnnotation()[0]);
571  0 assertEquals(cmat,
572    selseqs[0].getContactMatrixFor(selseqs[0].getAnnotation()[0]));
573   
574  0 assertNotNull(
575    selseqs[0].getContactListFor(selseqs[0].getAnnotation()[0], 2));
576   
577    // now select everything and test again
578  0 af.selectAllSequenceMenuItem_actionPerformed(null);
579  0 selseqs = af.getViewport().getSelectionAsNewSequence();
580  0 assertNotNull(selseqs[0].getAnnotation());
581  0 assertNotNull(selseqs[0].getAnnotation()[0]);
582  0 assertEquals(cmat,
583    selseqs[0].getContactMatrixFor(selseqs[0].getAnnotation()[0]));
584  0 assertNotNull(
585    selseqs[0].getContactListFor(selseqs[0].getAnnotation()[0], 2));
586    }
587    }