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;
40 import java.util.LinkedHashSet;
43 import org.testng.annotations.BeforeClass;
44 import org.testng.annotations.BeforeMethod;
45 import org.testng.annotations.Test;
47 public class AlignViewportTest
54 @BeforeClass(alwaysRun = true)
55 public static void setUpBeforeClass() throws Exception
57 jalview.bin.Jalview.main(new String[] { "-props",
58 "test/jalview/testProps.jvprops" });
61 @BeforeMethod(alwaysRun = true)
64 SequenceI seq1 = new Sequence("Seq1", "ABC");
65 SequenceI seq2 = new Sequence("Seq2", "ABC");
66 SequenceI seq3 = new Sequence("Seq3", "ABC");
67 SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3 };
68 al = new Alignment(seqs);
70 testee = new AlignViewport(al);
73 @Test(groups = { "Functional" })
74 public void testCollateForPdb()
77 * Set up sequence pdb ids
79 PDBEntry pdb1 = new PDBEntry("1ABC", "A", Type.PDB, "1ABC.pdb");
80 PDBEntry pdb2 = new PDBEntry("2ABC", "A", Type.PDB, "2ABC.pdb");
81 PDBEntry pdb3 = new PDBEntry("3ABC", "A", Type.PDB, "3ABC.pdb");
84 * seq1 and seq3 refer to 1ABC, seq2 to 2ABC, none to 3ABC
86 al.getSequenceAt(0).getDatasetSequence()
87 .addPDBId(new PDBEntry("1ABC", "B", Type.PDB, "1ABC.pdb"));
88 al.getSequenceAt(2).getDatasetSequence()
89 .addPDBId(new PDBEntry("1ABC", "B", Type.PDB, "1ABC.pdb"));
90 al.getSequenceAt(1).getDatasetSequence()
91 .addPDBId(new PDBEntry("2ABC", "C", Type.PDB, "2ABC.pdb"));
93 * Add a second chain PDB xref to Seq2 - should not result in a duplicate in
96 al.getSequenceAt(1).getDatasetSequence()
97 .addPDBId(new PDBEntry("2ABC", "D", Type.PDB, "2ABC.pdb"));
99 * Seq3 refers to 3abc - this does not match 3ABC (as the code stands)
101 al.getSequenceAt(2).getDatasetSequence()
102 .addPDBId(new PDBEntry("3abc", "D", Type.PDB, "3ABC.pdb"));
105 * run method under test
107 SequenceI[][] seqs = testee.collateForPDB(new PDBEntry[] { pdb1, pdb2,
110 // seq1 and seq3 refer to PDBEntry[0]
111 assertEquals(2, seqs[0].length);
112 assertSame(al.getSequenceAt(0), seqs[0][0]);
113 assertSame(al.getSequenceAt(2), seqs[0][1]);
115 // seq2 refers to PDBEntry[1]
116 assertEquals(1, seqs[1].length);
117 assertSame(al.getSequenceAt(1), seqs[1][0]);
119 // no sequence refers to PDBEntry[2]
120 assertEquals(0, seqs[2].length);
124 * Test that a mapping is not deregistered when a second view is closed but
125 * the first still holds a reference to the mapping
127 @Test(groups = { "Functional" })
128 public void testDeregisterMapping_onCloseView()
131 * alignment with reference to mappings
133 AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded(
134 ">Seq1\nCAGT\n", FormatAdapter.PASTE);
136 AlignedCodonFrame acf1 = new AlignedCodonFrame();
137 AlignedCodonFrame acf2 = new AlignedCodonFrame();
139 Set<AlignedCodonFrame> mappings = new LinkedHashSet<AlignedCodonFrame>();
142 af1.getViewport().getAlignment().setCodonFrames(mappings);
143 af1.newView_actionPerformed(null);
146 * Verify that creating the alignment for the new View has registered the
149 StructureSelectionManager ssm = StructureSelectionManager
150 .getStructureSelectionManager(Desktop.instance);
151 assertEquals(2, ssm.seqmappings.size());
152 assertTrue(ssm.seqmappings.contains(acf1));
153 assertTrue(ssm.seqmappings.contains(acf2));
156 * Close the second view. Verify that mappings are not removed as the first
157 * view still holds a reference to them.
159 af1.closeMenuItem_actionPerformed(false);
160 assertEquals(2, ssm.seqmappings.size());
161 assertTrue(ssm.seqmappings.contains(acf1));
162 assertTrue(ssm.seqmappings.contains(acf2));
166 * Test that a mapping is deregistered if no alignment holds a reference to it
168 @Test(groups = { "Functional" })
169 public void testDeregisterMapping_withNoReference()
171 Desktop d = Desktop.instance;
173 StructureSelectionManager ssm = StructureSelectionManager
174 .getStructureSelectionManager(Desktop.instance);
177 AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded(
178 ">Seq1\nRSVQ\n", FormatAdapter.PASTE);
179 AlignFrame af2 = new FileLoader().LoadFileWaitTillLoaded(
180 ">Seq2\nDGEL\n", FormatAdapter.PASTE);
182 AlignedCodonFrame acf1 = new AlignedCodonFrame();
183 AlignedCodonFrame acf2 = new AlignedCodonFrame();
184 AlignedCodonFrame acf3 = new AlignedCodonFrame();
186 Set<AlignedCodonFrame> mappings1 = new LinkedHashSet<AlignedCodonFrame>();
188 af1.getViewport().getAlignment().setCodonFrames(mappings1);
190 Set<AlignedCodonFrame> mappings2 = new LinkedHashSet<AlignedCodonFrame>();
193 af2.getViewport().getAlignment().setCodonFrames(mappings2);
196 * AlignFrame1 has mapping acf1, AlignFrame2 has acf2 and acf3
199 Set<AlignedCodonFrame> ssmMappings = ssm.seqmappings;
200 assertEquals(0, ssmMappings.size());
201 ssm.registerMapping(acf1);
202 assertEquals(1, ssmMappings.size());
203 ssm.registerMapping(acf2);
204 assertEquals(2, ssmMappings.size());
205 ssm.registerMapping(acf3);
206 assertEquals(3, ssmMappings.size());
209 * Closing AlignFrame2 should remove its mappings from
210 * StructureSelectionManager, since AlignFrame1 has no reference to them
212 af2.closeMenuItem_actionPerformed(true);
213 assertEquals(1, ssmMappings.size());
214 assertTrue(ssmMappings.contains(acf1));
218 * Test that a mapping is not deregistered if another alignment holds a
221 @Test(groups = { "Functional" })
222 public void testDeregisterMapping_withReference()
224 Desktop d = Desktop.instance;
226 StructureSelectionManager ssm = StructureSelectionManager
227 .getStructureSelectionManager(Desktop.instance);
230 AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded(
231 ">Seq1\nRSVQ\n", FormatAdapter.PASTE);
232 AlignFrame af2 = new FileLoader().LoadFileWaitTillLoaded(
233 ">Seq2\nDGEL\n", FormatAdapter.PASTE);
235 AlignedCodonFrame acf1 = new AlignedCodonFrame();
236 AlignedCodonFrame acf2 = new AlignedCodonFrame();
237 AlignedCodonFrame acf3 = new AlignedCodonFrame();
239 Set<AlignedCodonFrame> mappings1 = new LinkedHashSet<AlignedCodonFrame>();
242 af1.getViewport().getAlignment().setCodonFrames(mappings1);
244 Set<AlignedCodonFrame> mappings2 = new LinkedHashSet<AlignedCodonFrame>();
247 af2.getViewport().getAlignment().setCodonFrames(mappings2);
250 * AlignFrame1 has mappings acf1 and acf2, AlignFrame2 has acf2 and acf3
253 Set<AlignedCodonFrame> ssmMappings = ssm.seqmappings;
254 assertEquals(0, ssmMappings.size());
255 ssm.registerMapping(acf1);
256 assertEquals(1, ssmMappings.size());
257 ssm.registerMapping(acf2);
258 assertEquals(2, ssmMappings.size());
259 ssm.registerMapping(acf3);
260 assertEquals(3, ssmMappings.size());
263 * Closing AlignFrame2 should remove mapping acf3 from
264 * StructureSelectionManager, but not acf2, since AlignFrame1 still has a
267 af2.closeMenuItem_actionPerformed(true);
268 assertEquals(2, ssmMappings.size());
269 assertTrue(ssmMappings.contains(acf1));
270 assertTrue(ssmMappings.contains(acf2));
271 assertFalse(ssmMappings.contains(acf3));