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.
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.assertSame;
27 import static org.testng.AssertJUnit.assertTrue;
29 import jalview.datamodel.AlignedCodonFrame;
30 import jalview.datamodel.Alignment;
31 import jalview.datamodel.AlignmentI;
32 import jalview.datamodel.PDBEntry;
33 import jalview.datamodel.PDBEntry.Type;
34 import jalview.datamodel.Sequence;
35 import jalview.datamodel.SequenceI;
36 import jalview.io.FileLoader;
37 import jalview.io.FormatAdapter;
38 import jalview.structure.StructureSelectionManager;
39 import jalview.util.MapList;
41 import java.util.ArrayList;
42 import java.util.List;
44 import org.testng.annotations.BeforeClass;
45 import org.testng.annotations.BeforeMethod;
46 import org.testng.annotations.Test;
48 public class AlignViewportTest
55 @BeforeClass(alwaysRun = true)
56 public static void setUpBeforeClass() throws Exception
58 jalview.bin.Jalview.main(new String[] { "-props",
59 "test/jalview/testProps.jvprops" });
62 @BeforeMethod(alwaysRun = true)
65 SequenceI seq1 = new Sequence("Seq1", "ABC");
66 SequenceI seq2 = new Sequence("Seq2", "ABC");
67 SequenceI seq3 = new Sequence("Seq3", "ABC");
68 SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3 };
69 al = new Alignment(seqs);
71 testee = new AlignViewport(al);
74 @Test(groups = { "Functional" })
75 public void testCollateForPdb()
78 * Set up sequence pdb ids
80 PDBEntry pdb1 = new PDBEntry("1ABC", "B", Type.PDB, "1ABC.pdb");
81 PDBEntry pdb2 = new PDBEntry("2ABC", "C", Type.PDB, "2ABC.pdb");
82 PDBEntry pdb3 = new PDBEntry("3ABC", "D", Type.PDB, "3ABC.pdb");
85 * seq1 and seq3 refer to 1abcB, seq2 to 2abcC, none to 3abcD
87 al.getSequenceAt(0).getDatasetSequence()
88 .addPDBId(new PDBEntry("1ABC", "B", Type.PDB, "1ABC.pdb"));
89 al.getSequenceAt(2).getDatasetSequence()
90 .addPDBId(new PDBEntry("1ABC", "B", Type.PDB, "1ABC.pdb"));
91 al.getSequenceAt(1).getDatasetSequence()
92 .addPDBId(new PDBEntry("2ABC", "C", Type.PDB, "2ABC.pdb"));
94 * Add a second chain PDB xref to Seq2 - should not result in a duplicate in
97 al.getSequenceAt(1).getDatasetSequence()
98 .addPDBId(new PDBEntry("2ABC", "D", Type.PDB, "2ABC.pdb"));
100 * Seq3 refers to 3abc - this does not match 3ABC (as the code stands)
102 al.getSequenceAt(2).getDatasetSequence()
103 .addPDBId(new PDBEntry("3abc", "D", Type.PDB, "3ABC.pdb"));
106 * run method under test
108 SequenceI[][] seqs = testee.collateForPDB(new PDBEntry[] { pdb1, pdb2,
111 // seq1 and seq3 refer to PDBEntry[0]
112 assertEquals(2, seqs[0].length);
113 assertSame(al.getSequenceAt(0), seqs[0][0]);
114 assertSame(al.getSequenceAt(2), seqs[0][1]);
116 // seq2 refers to PDBEntry[1]
117 assertEquals(1, seqs[1].length);
118 assertSame(al.getSequenceAt(1), seqs[1][0]);
120 // no sequence refers to PDBEntry[2]
121 assertEquals(0, seqs[2].length);
125 * Test that a mapping is not deregistered when a second view is closed but
126 * the first still holds a reference to the mapping
128 @Test(groups = { "Functional" })
129 public void testDeregisterMapping_onCloseView()
132 * alignment with reference to mappings
134 AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded(
135 ">Seq1\nCAGT\n", FormatAdapter.PASTE);
137 SequenceI s1 = af1.getViewport().getAlignment().getSequenceAt(0);
138 AlignedCodonFrame acf1 = new AlignedCodonFrame();
139 acf1.addMap(s1, s1, new MapList(new int[] { 1, 4 }, new int[] { 1, 4 },
141 AlignedCodonFrame acf2 = new AlignedCodonFrame();
142 acf2.addMap(s1, s1, new MapList(new int[] { 1, 4 }, new int[] { 4, 1 },
145 List<AlignedCodonFrame> mappings = new ArrayList<AlignedCodonFrame>();
148 af1.getViewport().getAlignment().setCodonFrames(mappings);
149 af1.newView_actionPerformed(null);
152 * Verify that creating the alignment for the new View has registered the
155 StructureSelectionManager ssm = StructureSelectionManager
156 .getStructureSelectionManager(Desktop.instance);
157 assertEquals(2, ssm.getSequenceMappings().size());
158 assertTrue(ssm.getSequenceMappings().contains(acf1));
159 assertTrue(ssm.getSequenceMappings().contains(acf2));
162 * Close the second view. Verify that mappings are not removed as the first
163 * view still holds a reference to them.
165 af1.closeMenuItem_actionPerformed(false);
166 assertEquals(2, ssm.getSequenceMappings().size());
167 assertTrue(ssm.getSequenceMappings().contains(acf1));
168 assertTrue(ssm.getSequenceMappings().contains(acf2));
172 * Test that a mapping is deregistered if no alignment holds a reference to it
174 @Test(groups = { "Functional" })
175 public void testDeregisterMapping_withNoReference()
177 Desktop d = Desktop.instance;
179 StructureSelectionManager ssm = StructureSelectionManager
180 .getStructureSelectionManager(Desktop.instance);
183 AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded(
184 ">Seq1\nRSVQ\n", FormatAdapter.PASTE);
185 AlignFrame af2 = new FileLoader().LoadFileWaitTillLoaded(
186 ">Seq2\nDGEL\n", FormatAdapter.PASTE);
187 SequenceI cs1 = new Sequence("cseq1", "CCCGGGTTTAAA");
188 SequenceI cs2 = new Sequence("cseq2", "CTTGAGTCTAGA");
189 SequenceI s1 = af1.getViewport().getAlignment().getSequenceAt(0);
190 SequenceI s2 = af2.getViewport().getAlignment().getSequenceAt(0);
191 // need to be distinct
192 AlignedCodonFrame acf1 = new AlignedCodonFrame();
193 acf1.addMap(cs1, s1, new MapList(new int[] { 1, 4 },
194 new int[] { 1, 12 }, 1, 3));
195 AlignedCodonFrame acf2 = new AlignedCodonFrame();
196 acf2.addMap(cs2, s2, new MapList(new int[] { 1, 4 },
197 new int[] { 1, 12 }, 1, 3));
198 AlignedCodonFrame acf3 = new AlignedCodonFrame();
199 acf3.addMap(cs2, cs2, new MapList(new int[] { 1, 12 }, new int[] { 1,
202 List<AlignedCodonFrame> mappings1 = new ArrayList<AlignedCodonFrame>();
204 af1.getViewport().getAlignment().setCodonFrames(mappings1);
206 List<AlignedCodonFrame> mappings2 = new ArrayList<AlignedCodonFrame>();
209 af2.getViewport().getAlignment().setCodonFrames(mappings2);
212 * AlignFrame1 has mapping acf1, AlignFrame2 has acf2 and acf3
215 List<AlignedCodonFrame> ssmMappings = ssm.getSequenceMappings();
216 assertEquals(0, ssmMappings.size());
217 ssm.registerMapping(acf1);
218 assertEquals(1, ssmMappings.size());
219 ssm.registerMapping(acf2);
220 assertEquals(2, ssmMappings.size());
221 ssm.registerMapping(acf3);
222 assertEquals(3, ssmMappings.size());
225 * Closing AlignFrame2 should remove its mappings from
226 * StructureSelectionManager, since AlignFrame1 has no reference to them
228 af2.closeMenuItem_actionPerformed(true);
229 assertEquals(1, ssmMappings.size());
230 assertTrue(ssmMappings.contains(acf1));
234 * Test that a mapping is not deregistered if another alignment holds a
237 @Test(groups = { "Functional" })
238 public void testDeregisterMapping_withReference()
240 Desktop d = Desktop.instance;
242 StructureSelectionManager ssm = StructureSelectionManager
243 .getStructureSelectionManager(Desktop.instance);
246 AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded(
247 ">Seq1\nRSVQ\n", FormatAdapter.PASTE);
248 AlignFrame af2 = new FileLoader().LoadFileWaitTillLoaded(
249 ">Seq2\nDGEL\n", FormatAdapter.PASTE);
250 SequenceI cs1 = new Sequence("cseq1", "CCCGGGTTTAAA");
251 SequenceI cs2 = new Sequence("cseq2", "CTTGAGTCTAGA");
252 SequenceI s1 = af1.getViewport().getAlignment().getSequenceAt(0);
253 SequenceI s2 = af2.getViewport().getAlignment().getSequenceAt(0);
254 // need to be distinct
255 AlignedCodonFrame acf1 = new AlignedCodonFrame();
256 acf1.addMap(cs1, s1, new MapList(new int[] { 1, 4 },
257 new int[] { 1, 12 }, 1, 3));
258 AlignedCodonFrame acf2 = new AlignedCodonFrame();
259 acf2.addMap(cs2, s2, new MapList(new int[] { 1, 4 },
260 new int[] { 1, 12 }, 1, 3));
261 AlignedCodonFrame acf3 = new AlignedCodonFrame();
262 acf3.addMap(cs2, cs2, new MapList(new int[] { 1, 12 }, new int[] { 1,
265 List<AlignedCodonFrame> mappings1 = new ArrayList<AlignedCodonFrame>();
268 af1.getViewport().getAlignment().setCodonFrames(mappings1);
270 List<AlignedCodonFrame> mappings2 = new ArrayList<AlignedCodonFrame>();
273 af2.getViewport().getAlignment().setCodonFrames(mappings2);
276 * AlignFrame1 has mappings acf1 and acf2, AlignFrame2 has acf2 and acf3
279 List<AlignedCodonFrame> ssmMappings = ssm.getSequenceMappings();
280 assertEquals(0, ssmMappings.size());
281 ssm.registerMapping(acf1);
282 assertEquals(1, ssmMappings.size());
283 ssm.registerMapping(acf2);
284 assertEquals(2, ssmMappings.size());
285 ssm.registerMapping(acf3);
286 assertEquals(3, ssmMappings.size());
289 * Closing AlignFrame2 should remove mapping acf3 from
290 * StructureSelectionManager, but not acf2, since AlignFrame1 still has a
293 af2.closeMenuItem_actionPerformed(true);
294 assertEquals(2, ssmMappings.size());
295 assertTrue(ssmMappings.contains(acf1));
296 assertTrue(ssmMappings.contains(acf2));
297 assertFalse(ssmMappings.contains(acf3));