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.bin.Cache;
30 import jalview.bin.Jalview;
31 import jalview.datamodel.AlignedCodonFrame;
32 import jalview.datamodel.Alignment;
33 import jalview.datamodel.AlignmentAnnotation;
34 import jalview.datamodel.AlignmentI;
35 import jalview.datamodel.Annotation;
36 import jalview.datamodel.PDBEntry;
37 import jalview.datamodel.PDBEntry.Type;
38 import jalview.datamodel.SearchResults;
39 import jalview.datamodel.SearchResultsI;
40 import jalview.datamodel.Sequence;
41 import jalview.datamodel.SequenceGroup;
42 import jalview.datamodel.SequenceI;
43 import jalview.io.DataSourceType;
44 import jalview.io.FileLoader;
45 import jalview.schemes.ColourSchemeI;
46 import jalview.schemes.PIDColourScheme;
47 import jalview.structure.StructureSelectionManager;
48 import jalview.util.MapList;
50 import java.util.ArrayList;
51 import java.util.List;
53 import org.testng.annotations.BeforeClass;
54 import org.testng.annotations.BeforeMethod;
55 import org.testng.annotations.Test;
57 public class AlignViewportTest
60 @BeforeClass(alwaysRun = true)
61 public void setUpJvOptionPane()
63 JvOptionPane.setInteractiveMode(false);
64 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
71 @BeforeClass(alwaysRun = true)
72 public static void setUpBeforeClass() throws Exception
74 Jalview.main(new String[] { "-nonews", "-props",
75 "test/jalview/testProps.jvprops" });
78 @BeforeMethod(alwaysRun = true)
81 SequenceI seq1 = new Sequence("Seq1", "ABC");
82 SequenceI seq2 = new Sequence("Seq2", "ABC");
83 SequenceI seq3 = new Sequence("Seq3", "ABC");
84 SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3 };
85 al = new Alignment(seqs);
87 testee = new AlignViewport(al);
90 @Test(groups = { "Functional" })
91 public void testCollateForPdb()
93 // JBP: What behaviour is this supposed to test ?
95 * Set up sequence pdb ids
97 PDBEntry pdb1 = new PDBEntry("1ABC", "B", Type.PDB, "1ABC.pdb");
98 PDBEntry pdb2 = new PDBEntry("2ABC", "C", Type.PDB, "2ABC.pdb");
99 PDBEntry pdb3 = new PDBEntry("3ABC", "D", Type.PDB, "3ABC.pdb");
102 * seq1 and seq3 refer to 1abcB, seq2 to 2abcC, none to 3abcD
104 al.getSequenceAt(0).getDatasetSequence()
105 .addPDBId(new PDBEntry("1ABC", "B", Type.PDB, "1ABC.pdb"));
106 al.getSequenceAt(2).getDatasetSequence()
107 .addPDBId(new PDBEntry("1ABC", "B", Type.PDB, "1ABC.pdb"));
108 al.getSequenceAt(1).getDatasetSequence()
109 .addPDBId(new PDBEntry("2ABC", "C", Type.PDB, "2ABC.pdb"));
111 * Add a second chain PDB xref to Seq2 - should not result in a duplicate in
114 al.getSequenceAt(1).getDatasetSequence()
115 .addPDBId(new PDBEntry("2ABC", "D", Type.PDB, "2ABC.pdb"));
117 * Seq3 refers to 3abc - this does not match 3ABC (as the code stands)
119 al.getSequenceAt(2).getDatasetSequence()
120 .addPDBId(new PDBEntry("3abc", "D", Type.PDB, "3ABC.pdb"));
123 * run method under test
125 SequenceI[][] seqs = testee.collateForPDB(new PDBEntry[] { pdb1, pdb2,
128 // seq1 and seq3 refer to PDBEntry[0]
129 assertEquals(2, seqs[0].length);
130 assertSame(al.getSequenceAt(0), seqs[0][0]);
131 assertSame(al.getSequenceAt(2), seqs[0][1]);
133 // seq2 refers to PDBEntry[1]
134 assertEquals(1, seqs[1].length);
135 assertSame(al.getSequenceAt(1), seqs[1][0]);
137 // no sequence refers to PDBEntry[2]
138 assertEquals(0, seqs[2].length);
142 * Test that a mapping is not deregistered when a second view is closed but
143 * the first still holds a reference to the mapping
145 @Test(groups = { "Functional" })
146 public void testDeregisterMapping_onCloseView()
149 * alignment with reference to mappings
151 AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded(
152 ">Seq1\nCAGT\n", DataSourceType.PASTE);
154 SequenceI s1 = af1.getViewport().getAlignment().getSequenceAt(0);
155 AlignedCodonFrame acf1 = new AlignedCodonFrame();
156 acf1.addMap(s1, s1, new MapList(new int[] { 1, 4 }, new int[] { 1, 4 },
158 AlignedCodonFrame acf2 = new AlignedCodonFrame();
159 acf2.addMap(s1, s1, new MapList(new int[] { 1, 4 }, new int[] { 4, 1 },
162 List<AlignedCodonFrame> mappings = new ArrayList<AlignedCodonFrame>();
165 af1.getViewport().getAlignment().setCodonFrames(mappings);
166 af1.newView_actionPerformed(null);
169 * Verify that creating the alignment for the new View has registered the
172 StructureSelectionManager ssm = StructureSelectionManager
173 .getStructureSelectionManager(Desktop.instance);
174 assertEquals(2, ssm.getSequenceMappings().size());
175 assertTrue(ssm.getSequenceMappings().contains(acf1));
176 assertTrue(ssm.getSequenceMappings().contains(acf2));
179 * Close the second view. Verify that mappings are not removed as the first
180 * view still holds a reference to them.
182 af1.closeMenuItem_actionPerformed(false);
183 assertEquals(2, ssm.getSequenceMappings().size());
184 assertTrue(ssm.getSequenceMappings().contains(acf1));
185 assertTrue(ssm.getSequenceMappings().contains(acf2));
189 * Test that a mapping is deregistered if no alignment holds a reference to it
191 @Test(groups = { "Functional" })
192 public void testDeregisterMapping_withNoReference()
194 Desktop d = Desktop.instance;
196 StructureSelectionManager ssm = StructureSelectionManager
197 .getStructureSelectionManager(Desktop.instance);
200 AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded(
201 ">Seq1\nRSVQ\n", DataSourceType.PASTE);
202 AlignFrame af2 = new FileLoader().LoadFileWaitTillLoaded(
203 ">Seq2\nDGEL\n", DataSourceType.PASTE);
204 SequenceI cs1 = new Sequence("cseq1", "CCCGGGTTTAAA");
205 SequenceI cs2 = new Sequence("cseq2", "CTTGAGTCTAGA");
206 SequenceI s1 = af1.getViewport().getAlignment().getSequenceAt(0);
207 SequenceI s2 = af2.getViewport().getAlignment().getSequenceAt(0);
208 // need to be distinct
209 AlignedCodonFrame acf1 = new AlignedCodonFrame();
210 acf1.addMap(cs1, s1, new MapList(new int[] { 1, 4 },
211 new int[] { 1, 12 }, 1, 3));
212 AlignedCodonFrame acf2 = new AlignedCodonFrame();
213 acf2.addMap(cs2, s2, new MapList(new int[] { 1, 4 },
214 new int[] { 1, 12 }, 1, 3));
215 AlignedCodonFrame acf3 = new AlignedCodonFrame();
216 acf3.addMap(cs2, cs2, new MapList(new int[] { 1, 12 }, new int[] { 1,
219 List<AlignedCodonFrame> mappings1 = new ArrayList<AlignedCodonFrame>();
221 af1.getViewport().getAlignment().setCodonFrames(mappings1);
223 List<AlignedCodonFrame> mappings2 = new ArrayList<AlignedCodonFrame>();
226 af2.getViewport().getAlignment().setCodonFrames(mappings2);
229 * AlignFrame1 has mapping acf1, AlignFrame2 has acf2 and acf3
232 List<AlignedCodonFrame> ssmMappings = ssm.getSequenceMappings();
233 assertEquals(0, ssmMappings.size());
234 ssm.registerMapping(acf1);
235 assertEquals(1, ssmMappings.size());
236 ssm.registerMapping(acf2);
237 assertEquals(2, ssmMappings.size());
238 ssm.registerMapping(acf3);
239 assertEquals(3, ssmMappings.size());
242 * Closing AlignFrame2 should remove its mappings from
243 * StructureSelectionManager, since AlignFrame1 has no reference to them
245 af2.closeMenuItem_actionPerformed(true);
246 assertEquals(1, ssmMappings.size());
247 assertTrue(ssmMappings.contains(acf1));
251 * Test that a mapping is not deregistered if another alignment holds a
254 @Test(groups = { "Functional" })
255 public void testDeregisterMapping_withReference()
257 Desktop d = Desktop.instance;
259 StructureSelectionManager ssm = StructureSelectionManager
260 .getStructureSelectionManager(Desktop.instance);
263 AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded(
264 ">Seq1\nRSVQ\n", DataSourceType.PASTE);
265 AlignFrame af2 = new FileLoader().LoadFileWaitTillLoaded(
266 ">Seq2\nDGEL\n", DataSourceType.PASTE);
267 SequenceI cs1 = new Sequence("cseq1", "CCCGGGTTTAAA");
268 SequenceI cs2 = new Sequence("cseq2", "CTTGAGTCTAGA");
269 SequenceI s1 = af1.getViewport().getAlignment().getSequenceAt(0);
270 SequenceI s2 = af2.getViewport().getAlignment().getSequenceAt(0);
271 // need to be distinct
272 AlignedCodonFrame acf1 = new AlignedCodonFrame();
273 acf1.addMap(cs1, s1, new MapList(new int[] { 1, 4 },
274 new int[] { 1, 12 }, 1, 3));
275 AlignedCodonFrame acf2 = new AlignedCodonFrame();
276 acf2.addMap(cs2, s2, new MapList(new int[] { 1, 4 },
277 new int[] { 1, 12 }, 1, 3));
278 AlignedCodonFrame acf3 = new AlignedCodonFrame();
279 acf3.addMap(cs2, cs2, new MapList(new int[] { 1, 12 }, new int[] { 1,
282 List<AlignedCodonFrame> mappings1 = new ArrayList<AlignedCodonFrame>();
285 af1.getViewport().getAlignment().setCodonFrames(mappings1);
287 List<AlignedCodonFrame> mappings2 = new ArrayList<AlignedCodonFrame>();
290 af2.getViewport().getAlignment().setCodonFrames(mappings2);
293 * AlignFrame1 has mappings acf1 and acf2, AlignFrame2 has acf2 and acf3
296 List<AlignedCodonFrame> ssmMappings = ssm.getSequenceMappings();
297 assertEquals(0, ssmMappings.size());
298 ssm.registerMapping(acf1);
299 assertEquals(1, ssmMappings.size());
300 ssm.registerMapping(acf2);
301 assertEquals(2, ssmMappings.size());
302 ssm.registerMapping(acf3);
303 assertEquals(3, ssmMappings.size());
306 * Closing AlignFrame2 should remove mapping acf3 from
307 * StructureSelectionManager, but not acf2, since AlignFrame1 still has a
310 af2.closeMenuItem_actionPerformed(true);
311 assertEquals(2, ssmMappings.size());
312 assertTrue(ssmMappings.contains(acf1));
313 assertTrue(ssmMappings.contains(acf2));
314 assertFalse(ssmMappings.contains(acf3));
318 * Test for JAL-1306 - conservation thread should run even when only Quality
319 * (and not Conservation) is enabled in Preferences
321 @Test(groups = { "Functional" })
322 public void testUpdateConservation_qualityOnly()
324 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
325 Boolean.TRUE.toString());
326 Cache.applicationProperties.setProperty("SHOW_QUALITY",
327 Boolean.TRUE.toString());
328 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
329 Boolean.FALSE.toString());
330 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
331 Boolean.FALSE.toString());
332 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
333 "examples/uniref50.fa", DataSourceType.FILE);
334 AlignmentAnnotation[] anns = af.viewport.getAlignment()
335 .getAlignmentAnnotation();
336 assertNotNull("No annotations found", anns);
337 assertEquals("More than one annotation found", 1, anns.length);
338 assertTrue("Annotation is not Quality",
339 anns[0].description.startsWith("Alignment Quality"));
340 Annotation[] annotations = anns[0].annotations;
341 assertNotNull("Quality annotations are null", annotations);
342 assertNotNull("Quality in column 1 is null", annotations[0]);
343 assertTrue("No quality value in column 1", annotations[0].value > 10f);
346 @Test(groups = { "Functional" })
347 public void testSetGlobalColourScheme()
350 * test for JAL-2283: don't inadvertently turn on colour by conservation
352 Cache.applicationProperties.setProperty("DEFAULT_COLOUR_PROT", "None");
353 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
354 Boolean.TRUE.toString());
355 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
356 "examples/uniref50.fa", DataSourceType.FILE);
357 ColourSchemeI cs = new PIDColourScheme();
358 af.getViewport().setGlobalColourScheme(cs);
359 assertFalse(af.getViewport().getResidueShading()
360 .conservationApplied());
363 @Test(groups = { "Functional" })
364 public void testSetGetHasSearchResults()
366 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
367 "examples/uniref50.fa", DataSourceType.FILE);
368 SearchResultsI sr = new SearchResults();
369 SequenceI s1 = af.getViewport().getAlignment().getSequenceAt(0);
371 // create arbitrary range on first sequence
372 sr.addResult(s1, s1.getStart() + 10, s1.getStart() + 15);
375 af.getViewport().setSearchResults(sr);
377 assertTrue(af.getViewport().hasSearchResults());
379 assertEquals(sr, af.getViewport().getSearchResults());
381 // set(null) results in has -> false
383 af.getViewport().setSearchResults(null);
384 assertFalse(af.getViewport().hasSearchResults());
388 * Verify that setting the selection group has the side-effect of setting the
389 * context on the group, unless it already has one
391 @Test(groups = { "Functional" })
392 public void testSetSelectionGroup()
394 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
395 "examples/uniref50.fa", DataSourceType.FILE);
396 AlignViewport av = af.getViewport();
397 SequenceGroup sg1 = new SequenceGroup();
398 SequenceGroup sg2 = new SequenceGroup();
400 av.setSelectionGroup(sg1);
401 assertSame(sg1.getContext(), av.getAlignment()); // context set
404 av.setSelectionGroup(sg2);
405 assertSame(sg2.getContext(), sg1); // unchanged