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.SequenceI;
42 import jalview.io.FileLoader;
43 import jalview.io.FormatAdapter;
44 import jalview.schemes.ColourSchemeI;
45 import jalview.schemes.PIDColourScheme;
46 import jalview.structure.StructureSelectionManager;
47 import jalview.util.MapList;
49 import java.util.ArrayList;
50 import java.util.List;
52 import org.testng.annotations.BeforeClass;
53 import org.testng.annotations.BeforeMethod;
54 import org.testng.annotations.Test;
56 public class AlignViewportTest
63 @BeforeClass(alwaysRun = true)
64 public static void setUpBeforeClass() throws Exception
66 Jalview.main(new String[] { "-props", "test/jalview/testProps.jvprops" });
69 @BeforeMethod(alwaysRun = true)
72 SequenceI seq1 = new Sequence("Seq1", "ABC");
73 SequenceI seq2 = new Sequence("Seq2", "ABC");
74 SequenceI seq3 = new Sequence("Seq3", "ABC");
75 SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3 };
76 al = new Alignment(seqs);
78 testee = new AlignViewport(al);
81 @Test(groups = { "Functional" })
82 public void testCollateForPdb()
84 // JBP: What behaviour is this supposed to test ?
86 * Set up sequence pdb ids
88 PDBEntry pdb1 = new PDBEntry("1ABC", "B", Type.PDB, "1ABC.pdb");
89 PDBEntry pdb2 = new PDBEntry("2ABC", "C", Type.PDB, "2ABC.pdb");
90 PDBEntry pdb3 = new PDBEntry("3ABC", "D", Type.PDB, "3ABC.pdb");
93 * seq1 and seq3 refer to 1abcB, seq2 to 2abcC, none to 3abcD
95 al.getSequenceAt(0).getDatasetSequence()
96 .addPDBId(new PDBEntry("1ABC", "B", Type.PDB, "1ABC.pdb"));
97 al.getSequenceAt(2).getDatasetSequence()
98 .addPDBId(new PDBEntry("1ABC", "B", Type.PDB, "1ABC.pdb"));
99 al.getSequenceAt(1).getDatasetSequence()
100 .addPDBId(new PDBEntry("2ABC", "C", Type.PDB, "2ABC.pdb"));
102 * Add a second chain PDB xref to Seq2 - should not result in a duplicate in
105 al.getSequenceAt(1).getDatasetSequence()
106 .addPDBId(new PDBEntry("2ABC", "D", Type.PDB, "2ABC.pdb"));
108 * Seq3 refers to 3abc - this does not match 3ABC (as the code stands)
110 al.getSequenceAt(2).getDatasetSequence()
111 .addPDBId(new PDBEntry("3abc", "D", Type.PDB, "3ABC.pdb"));
114 * run method under test
116 SequenceI[][] seqs = testee.collateForPDB(new PDBEntry[] { pdb1, pdb2,
119 // seq1 and seq3 refer to PDBEntry[0]
120 assertEquals(2, seqs[0].length);
121 assertSame(al.getSequenceAt(0), seqs[0][0]);
122 assertSame(al.getSequenceAt(2), seqs[0][1]);
124 // seq2 refers to PDBEntry[1]
125 assertEquals(1, seqs[1].length);
126 assertSame(al.getSequenceAt(1), seqs[1][0]);
128 // no sequence refers to PDBEntry[2]
129 assertEquals(0, seqs[2].length);
133 * Test that a mapping is not deregistered when a second view is closed but
134 * the first still holds a reference to the mapping
136 @Test(groups = { "Functional" })
137 public void testDeregisterMapping_onCloseView()
140 * alignment with reference to mappings
142 AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded(
143 ">Seq1\nCAGT\n", FormatAdapter.PASTE);
145 SequenceI s1 = af1.getViewport().getAlignment().getSequenceAt(0);
146 AlignedCodonFrame acf1 = new AlignedCodonFrame();
147 acf1.addMap(s1, s1, new MapList(new int[] { 1, 4 }, new int[] { 1, 4 },
149 AlignedCodonFrame acf2 = new AlignedCodonFrame();
150 acf2.addMap(s1, s1, new MapList(new int[] { 1, 4 }, new int[] { 4, 1 },
153 List<AlignedCodonFrame> mappings = new ArrayList<AlignedCodonFrame>();
156 af1.getViewport().getAlignment().setCodonFrames(mappings);
157 af1.newView_actionPerformed(null);
160 * Verify that creating the alignment for the new View has registered the
163 StructureSelectionManager ssm = StructureSelectionManager
164 .getStructureSelectionManager(Desktop.instance);
165 assertEquals(2, ssm.getSequenceMappings().size());
166 assertTrue(ssm.getSequenceMappings().contains(acf1));
167 assertTrue(ssm.getSequenceMappings().contains(acf2));
170 * Close the second view. Verify that mappings are not removed as the first
171 * view still holds a reference to them.
173 af1.closeMenuItem_actionPerformed(false);
174 assertEquals(2, ssm.getSequenceMappings().size());
175 assertTrue(ssm.getSequenceMappings().contains(acf1));
176 assertTrue(ssm.getSequenceMappings().contains(acf2));
180 * Test that a mapping is deregistered if no alignment holds a reference to it
182 @Test(groups = { "Functional" })
183 public void testDeregisterMapping_withNoReference()
185 Desktop d = Desktop.instance;
187 StructureSelectionManager ssm = StructureSelectionManager
188 .getStructureSelectionManager(Desktop.instance);
191 AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded(
192 ">Seq1\nRSVQ\n", FormatAdapter.PASTE);
193 AlignFrame af2 = new FileLoader().LoadFileWaitTillLoaded(
194 ">Seq2\nDGEL\n", FormatAdapter.PASTE);
195 SequenceI cs1 = new Sequence("cseq1", "CCCGGGTTTAAA");
196 SequenceI cs2 = new Sequence("cseq2", "CTTGAGTCTAGA");
197 SequenceI s1 = af1.getViewport().getAlignment().getSequenceAt(0);
198 SequenceI s2 = af2.getViewport().getAlignment().getSequenceAt(0);
199 // need to be distinct
200 AlignedCodonFrame acf1 = new AlignedCodonFrame();
201 acf1.addMap(cs1, s1, new MapList(new int[] { 1, 4 },
202 new int[] { 1, 12 }, 1, 3));
203 AlignedCodonFrame acf2 = new AlignedCodonFrame();
204 acf2.addMap(cs2, s2, new MapList(new int[] { 1, 4 },
205 new int[] { 1, 12 }, 1, 3));
206 AlignedCodonFrame acf3 = new AlignedCodonFrame();
207 acf3.addMap(cs2, cs2, new MapList(new int[] { 1, 12 }, new int[] { 1,
210 List<AlignedCodonFrame> mappings1 = new ArrayList<AlignedCodonFrame>();
212 af1.getViewport().getAlignment().setCodonFrames(mappings1);
214 List<AlignedCodonFrame> mappings2 = new ArrayList<AlignedCodonFrame>();
217 af2.getViewport().getAlignment().setCodonFrames(mappings2);
220 * AlignFrame1 has mapping acf1, AlignFrame2 has acf2 and acf3
223 List<AlignedCodonFrame> ssmMappings = ssm.getSequenceMappings();
224 assertEquals(0, ssmMappings.size());
225 ssm.registerMapping(acf1);
226 assertEquals(1, ssmMappings.size());
227 ssm.registerMapping(acf2);
228 assertEquals(2, ssmMappings.size());
229 ssm.registerMapping(acf3);
230 assertEquals(3, ssmMappings.size());
233 * Closing AlignFrame2 should remove its mappings from
234 * StructureSelectionManager, since AlignFrame1 has no reference to them
236 af2.closeMenuItem_actionPerformed(true);
237 assertEquals(1, ssmMappings.size());
238 assertTrue(ssmMappings.contains(acf1));
242 * Test that a mapping is not deregistered if another alignment holds a
245 @Test(groups = { "Functional" })
246 public void testDeregisterMapping_withReference()
248 Desktop d = Desktop.instance;
250 StructureSelectionManager ssm = StructureSelectionManager
251 .getStructureSelectionManager(Desktop.instance);
254 AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded(
255 ">Seq1\nRSVQ\n", FormatAdapter.PASTE);
256 AlignFrame af2 = new FileLoader().LoadFileWaitTillLoaded(
257 ">Seq2\nDGEL\n", FormatAdapter.PASTE);
258 SequenceI cs1 = new Sequence("cseq1", "CCCGGGTTTAAA");
259 SequenceI cs2 = new Sequence("cseq2", "CTTGAGTCTAGA");
260 SequenceI s1 = af1.getViewport().getAlignment().getSequenceAt(0);
261 SequenceI s2 = af2.getViewport().getAlignment().getSequenceAt(0);
262 // need to be distinct
263 AlignedCodonFrame acf1 = new AlignedCodonFrame();
264 acf1.addMap(cs1, s1, new MapList(new int[] { 1, 4 },
265 new int[] { 1, 12 }, 1, 3));
266 AlignedCodonFrame acf2 = new AlignedCodonFrame();
267 acf2.addMap(cs2, s2, new MapList(new int[] { 1, 4 },
268 new int[] { 1, 12 }, 1, 3));
269 AlignedCodonFrame acf3 = new AlignedCodonFrame();
270 acf3.addMap(cs2, cs2, new MapList(new int[] { 1, 12 }, new int[] { 1,
273 List<AlignedCodonFrame> mappings1 = new ArrayList<AlignedCodonFrame>();
276 af1.getViewport().getAlignment().setCodonFrames(mappings1);
278 List<AlignedCodonFrame> mappings2 = new ArrayList<AlignedCodonFrame>();
281 af2.getViewport().getAlignment().setCodonFrames(mappings2);
284 * AlignFrame1 has mappings acf1 and acf2, AlignFrame2 has acf2 and acf3
287 List<AlignedCodonFrame> ssmMappings = ssm.getSequenceMappings();
288 assertEquals(0, ssmMappings.size());
289 ssm.registerMapping(acf1);
290 assertEquals(1, ssmMappings.size());
291 ssm.registerMapping(acf2);
292 assertEquals(2, ssmMappings.size());
293 ssm.registerMapping(acf3);
294 assertEquals(3, ssmMappings.size());
297 * Closing AlignFrame2 should remove mapping acf3 from
298 * StructureSelectionManager, but not acf2, since AlignFrame1 still has a
301 af2.closeMenuItem_actionPerformed(true);
302 assertEquals(2, ssmMappings.size());
303 assertTrue(ssmMappings.contains(acf1));
304 assertTrue(ssmMappings.contains(acf2));
305 assertFalse(ssmMappings.contains(acf3));
309 * Test for JAL-1306 - conservation thread should run even when only Quality
310 * (and not Conservation) is enabled in Preferences
312 @Test(groups = { "Functional" })
313 public void testUpdateConservation_qualityOnly()
315 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
316 Boolean.TRUE.toString());
317 Cache.applicationProperties.setProperty("SHOW_QUALITY",
318 Boolean.TRUE.toString());
319 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
320 Boolean.FALSE.toString());
321 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
322 Boolean.FALSE.toString());
323 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
324 "examples/uniref50.fa", FormatAdapter.FILE);
325 AlignmentAnnotation[] anns = af.viewport.getAlignment()
326 .getAlignmentAnnotation();
327 assertNotNull("No annotations found", anns);
328 assertEquals("More than one annotation found", 1, anns.length);
329 assertTrue("Annotation is not Quality",
330 anns[0].description.startsWith("Alignment Quality"));
331 Annotation[] annotations = anns[0].annotations;
332 assertNotNull("Quality annotations are null", annotations);
333 assertNotNull("Quality in column 1 is null", annotations[0]);
334 assertTrue("No quality value in column 1", annotations[0].value > 10f);
337 @Test(groups = { "Functional" })
338 public void testSetGlobalColourScheme()
341 * test for JAL-2283 don't inadvertently turn on colour by conservation
343 Cache.applicationProperties.setProperty("DEFAULT_COLOUR_PROT", "NONE");
344 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
345 Boolean.TRUE.toString());
346 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
347 "examples/uniref50.fa", FormatAdapter.FILE);
348 ColourSchemeI cs = new PIDColourScheme();
349 af.getViewport().setGlobalColourScheme(cs);
350 assertFalse(cs.conservationApplied());
353 @Test(groups = { "Functional" })
354 public void testSetGetHasSearchResults()
356 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
357 "examples/uniref50.fa", FormatAdapter.FILE);
358 SearchResultsI sr = new SearchResults();
359 SequenceI s1 = af.getViewport().getAlignment().getSequenceAt(0);
361 // create arbitrary range on first sequence
362 sr.addResult(s1, s1.getStart() + 10, s1.getStart() + 15);
365 af.getViewport().setSearchResults(sr);
367 assertTrue(af.getViewport().hasSearchResults());
369 assertEquals(sr, af.getViewport().getSearchResults());
371 // set(null) results in has -> false
373 af.getViewport().setSearchResults(null);
374 assertFalse(af.getViewport().hasSearchResults());