2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.datamodel;
23 import static org.hamcrest.MatcherAssert.assertThat;
24 import static org.hamcrest.Matchers.contains;
25 import org.hamcrest.Matchers;
26 import static org.testng.Assert.assertEquals;
28 import java.util.Arrays;
29 import java.util.List;
31 import jalview.gui.AlignFrame;
32 import jalview.gui.JvOptionPane;
33 import jalview.io.DataSourceType;
34 import jalview.io.FileLoader;
35 import jalview.viewmodel.AlignmentViewport;
37 import org.testng.annotations.BeforeClass;
38 import org.testng.annotations.Test;
41 public class AlignmentViewTest
44 @BeforeClass(alwaysRun = true)
45 public void setUpJvOptionPane()
47 JvOptionPane.setInteractiveMode(false);
48 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
51 @Test(groups = { "Functional" })
52 public void testGetVisibleAlignmentGapChar()
54 SeqCigar ss = new SeqCigar(new Sequence("One", "A..CDE"));
55 CigarArray ca = new CigarArray(new CigarSimple[] { ss });
56 AlignmentView av = new AlignmentView(ca);
57 String dots = av.getSequenceStrings('.')[0];
58 assertEquals(dots, "A..CDE");
59 String dollars = av.getSequenceStrings('$')[0];
60 assertEquals(dollars, "A$$CDE");
61 assertEquals(av.getVisibleAlignment('$').getSequenceAt(0)
62 .getSequenceAsString(), "A$$CDE");
66 public void testGetVisibleContigMapFor()
68 AlignFrame af = new FileLoader()
69 .LoadFileWaitTillLoaded(">seq\nAAA-AAAA---AA--\n",
70 DataSourceType.PASTE);
71 var av = af.getViewport();
72 var seq = av.getAlignment().getSequenceAt(0);
73 var gapMap = seq.gapMap();
74 assertThat(Arrays.stream(gapMap).boxed().toArray(Integer[]::new),
75 Matchers.arrayContaining(0, 1, 2, 4, 5, 6, 7, 11, 12));
79 AlignmentView view = av.getAlignmentView(true);
80 var delMap = view.getVisibleContigMapFor(gapMap);
81 assertThat(Arrays.stream(delMap).boxed().toArray(Integer[]::new),
82 Matchers.arrayContaining(2, 3, 4, 7, 8));
85 @Test(groups = { "Functional" })
86 public void testGetVisibleContigs()
88 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
89 ">s1\n0123456789\n", DataSourceType.PASTE);
90 AlignmentViewport av = af.getViewport();
91 AlignmentView view = av.getAlignmentView(true);
94 * verify getVisibleContigs returns inclusive [start, end] ranges
98 int[] contigs = view.getVisibleContigs();
99 assertEquals(contigs, new int[] { 0, 9 });
102 * hide 3 internal columns
104 av.hideColumns(5, 7);
105 // the old AlignmentView is now stale!
106 contigs = view.getVisibleContigs();
107 assertEquals(contigs, new int[] { 0, 9 });
108 // get a fresh AlignmentView
109 view = av.getAlignmentView(true);
110 contigs = view.getVisibleContigs();
111 assertEquals(contigs, new int[] { 0, 4, 8, 9 });
113 // hide first 2 columns
114 av.hideColumns(0, 1);
115 view = av.getAlignmentView(true);
116 contigs = view.getVisibleContigs();
117 assertEquals(contigs, new int[] { 2, 4, 8, 9 });
120 av.hideColumns(9, 9);
121 view = av.getAlignmentView(true);
122 contigs = view.getVisibleContigs();
123 assertEquals(contigs, new int[] { 2, 4, 8, 8 });
125 // unhide columns 5-7
127 view = av.getAlignmentView(true);
128 contigs = view.getVisibleContigs();
129 assertEquals(contigs, new int[] { 2, 8 });
132 av.hideColumns(2, 7);
133 view = av.getAlignmentView(true);
134 contigs = view.getVisibleContigs();
135 assertEquals(contigs, new int[] { 8, 8 });
138 av.hideColumns(8, 8);
139 view = av.getAlignmentView(true);
140 contigs = view.getVisibleContigs();
141 assertEquals(contigs, new int[] {});
144 av.showAllHiddenColumns();
145 view = av.getAlignmentView(true);
146 contigs = view.getVisibleContigs();
147 assertEquals(contigs, new int[] { 0, 9 });