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.Sequence;
39 import jalview.datamodel.SequenceI;
40 import jalview.io.FileLoader;
41 import jalview.io.FormatAdapter;
42 import jalview.schemes.ColourSchemeI;
43 import jalview.schemes.PIDColourScheme;
44 import jalview.structure.StructureSelectionManager;
45 import jalview.util.MapList;
47 import java.util.ArrayList;
48 import java.util.List;
50 import org.testng.annotations.BeforeClass;
51 import org.testng.annotations.BeforeMethod;
52 import org.testng.annotations.Test;
54 public class AlignViewportTest
61 @BeforeClass(alwaysRun = true)
62 public static void setUpBeforeClass() throws Exception
64 Jalview.main(new String[] { "-props", "test/jalview/testProps.jvprops" });
67 @BeforeMethod(alwaysRun = true)
70 SequenceI seq1 = new Sequence("Seq1", "ABC");
71 SequenceI seq2 = new Sequence("Seq2", "ABC");
72 SequenceI seq3 = new Sequence("Seq3", "ABC");
73 SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3 };
74 al = new Alignment(seqs);
76 testee = new AlignViewport(al);
79 @Test(groups = { "Functional" })
80 public void testCollateForPdb()
82 // JBP: What behaviour is this supposed to test ?
84 * Set up sequence pdb ids
86 PDBEntry pdb1 = new PDBEntry("1ABC", "B", Type.PDB, "1ABC.pdb");
87 PDBEntry pdb2 = new PDBEntry("2ABC", "C", Type.PDB, "2ABC.pdb");
88 PDBEntry pdb3 = new PDBEntry("3ABC", "D", Type.PDB, "3ABC.pdb");
91 * seq1 and seq3 refer to 1abcB, seq2 to 2abcC, none to 3abcD
93 al.getSequenceAt(0).getDatasetSequence()
94 .addPDBId(new PDBEntry("1ABC", "B", Type.PDB, "1ABC.pdb"));
95 al.getSequenceAt(2).getDatasetSequence()
96 .addPDBId(new PDBEntry("1ABC", "B", Type.PDB, "1ABC.pdb"));
97 al.getSequenceAt(1).getDatasetSequence()
98 .addPDBId(new PDBEntry("2ABC", "C", Type.PDB, "2ABC.pdb"));
100 * Add a second chain PDB xref to Seq2 - should not result in a duplicate in
103 al.getSequenceAt(1).getDatasetSequence()
104 .addPDBId(new PDBEntry("2ABC", "D", Type.PDB, "2ABC.pdb"));
106 * Seq3 refers to 3abc - this does not match 3ABC (as the code stands)
108 al.getSequenceAt(2).getDatasetSequence()
109 .addPDBId(new PDBEntry("3abc", "D", Type.PDB, "3ABC.pdb"));
112 * run method under test
114 SequenceI[][] seqs = testee.collateForPDB(new PDBEntry[] { pdb1, pdb2,
117 // seq1 and seq3 refer to PDBEntry[0]
118 assertEquals(2, seqs[0].length);
119 assertSame(al.getSequenceAt(0), seqs[0][0]);
120 assertSame(al.getSequenceAt(2), seqs[0][1]);
122 // seq2 refers to PDBEntry[1]
123 assertEquals(1, seqs[1].length);
124 assertSame(al.getSequenceAt(1), seqs[1][0]);
126 // no sequence refers to PDBEntry[2]
127 assertEquals(0, seqs[2].length);
131 * Test that a mapping is not deregistered when a second view is closed but
132 * the first still holds a reference to the mapping
134 @Test(groups = { "Functional" })
135 public void testDeregisterMapping_onCloseView()
138 * alignment with reference to mappings
140 AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded(
141 ">Seq1\nCAGT\n", FormatAdapter.PASTE);
143 SequenceI s1 = af1.getViewport().getAlignment().getSequenceAt(0);
144 AlignedCodonFrame acf1 = new AlignedCodonFrame();
145 acf1.addMap(s1, s1, new MapList(new int[] { 1, 4 }, new int[] { 1, 4 },
147 AlignedCodonFrame acf2 = new AlignedCodonFrame();
148 acf2.addMap(s1, s1, new MapList(new int[] { 1, 4 }, new int[] { 4, 1 },
151 List<AlignedCodonFrame> mappings = new ArrayList<AlignedCodonFrame>();
154 af1.getViewport().getAlignment().setCodonFrames(mappings);
155 af1.newView_actionPerformed(null);
158 * Verify that creating the alignment for the new View has registered the
161 StructureSelectionManager ssm = StructureSelectionManager
162 .getStructureSelectionManager(Desktop.instance);
163 assertEquals(2, ssm.getSequenceMappings().size());
164 assertTrue(ssm.getSequenceMappings().contains(acf1));
165 assertTrue(ssm.getSequenceMappings().contains(acf2));
168 * Close the second view. Verify that mappings are not removed as the first
169 * view still holds a reference to them.
171 af1.closeMenuItem_actionPerformed(false);
172 assertEquals(2, ssm.getSequenceMappings().size());
173 assertTrue(ssm.getSequenceMappings().contains(acf1));
174 assertTrue(ssm.getSequenceMappings().contains(acf2));
178 * Test that a mapping is deregistered if no alignment holds a reference to it
180 @Test(groups = { "Functional" })
181 public void testDeregisterMapping_withNoReference()
183 Desktop d = Desktop.instance;
185 StructureSelectionManager ssm = StructureSelectionManager
186 .getStructureSelectionManager(Desktop.instance);
189 AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded(
190 ">Seq1\nRSVQ\n", FormatAdapter.PASTE);
191 AlignFrame af2 = new FileLoader().LoadFileWaitTillLoaded(
192 ">Seq2\nDGEL\n", FormatAdapter.PASTE);
193 SequenceI cs1 = new Sequence("cseq1", "CCCGGGTTTAAA");
194 SequenceI cs2 = new Sequence("cseq2", "CTTGAGTCTAGA");
195 SequenceI s1 = af1.getViewport().getAlignment().getSequenceAt(0);
196 SequenceI s2 = af2.getViewport().getAlignment().getSequenceAt(0);
197 // need to be distinct
198 AlignedCodonFrame acf1 = new AlignedCodonFrame();
199 acf1.addMap(cs1, s1, new MapList(new int[] { 1, 4 },
200 new int[] { 1, 12 }, 1, 3));
201 AlignedCodonFrame acf2 = new AlignedCodonFrame();
202 acf2.addMap(cs2, s2, new MapList(new int[] { 1, 4 },
203 new int[] { 1, 12 }, 1, 3));
204 AlignedCodonFrame acf3 = new AlignedCodonFrame();
205 acf3.addMap(cs2, cs2, new MapList(new int[] { 1, 12 }, new int[] { 1,
208 List<AlignedCodonFrame> mappings1 = new ArrayList<AlignedCodonFrame>();
210 af1.getViewport().getAlignment().setCodonFrames(mappings1);
212 List<AlignedCodonFrame> mappings2 = new ArrayList<AlignedCodonFrame>();
215 af2.getViewport().getAlignment().setCodonFrames(mappings2);
218 * AlignFrame1 has mapping acf1, AlignFrame2 has acf2 and acf3
221 List<AlignedCodonFrame> ssmMappings = ssm.getSequenceMappings();
222 assertEquals(0, ssmMappings.size());
223 ssm.registerMapping(acf1);
224 assertEquals(1, ssmMappings.size());
225 ssm.registerMapping(acf2);
226 assertEquals(2, ssmMappings.size());
227 ssm.registerMapping(acf3);
228 assertEquals(3, ssmMappings.size());
231 * Closing AlignFrame2 should remove its mappings from
232 * StructureSelectionManager, since AlignFrame1 has no reference to them
234 af2.closeMenuItem_actionPerformed(true);
235 assertEquals(1, ssmMappings.size());
236 assertTrue(ssmMappings.contains(acf1));
240 * Test that a mapping is not deregistered if another alignment holds a
243 @Test(groups = { "Functional" })
244 public void testDeregisterMapping_withReference()
246 Desktop d = Desktop.instance;
248 StructureSelectionManager ssm = StructureSelectionManager
249 .getStructureSelectionManager(Desktop.instance);
252 AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded(
253 ">Seq1\nRSVQ\n", FormatAdapter.PASTE);
254 AlignFrame af2 = new FileLoader().LoadFileWaitTillLoaded(
255 ">Seq2\nDGEL\n", FormatAdapter.PASTE);
256 SequenceI cs1 = new Sequence("cseq1", "CCCGGGTTTAAA");
257 SequenceI cs2 = new Sequence("cseq2", "CTTGAGTCTAGA");
258 SequenceI s1 = af1.getViewport().getAlignment().getSequenceAt(0);
259 SequenceI s2 = af2.getViewport().getAlignment().getSequenceAt(0);
260 // need to be distinct
261 AlignedCodonFrame acf1 = new AlignedCodonFrame();
262 acf1.addMap(cs1, s1, new MapList(new int[] { 1, 4 },
263 new int[] { 1, 12 }, 1, 3));
264 AlignedCodonFrame acf2 = new AlignedCodonFrame();
265 acf2.addMap(cs2, s2, new MapList(new int[] { 1, 4 },
266 new int[] { 1, 12 }, 1, 3));
267 AlignedCodonFrame acf3 = new AlignedCodonFrame();
268 acf3.addMap(cs2, cs2, new MapList(new int[] { 1, 12 }, new int[] { 1,
271 List<AlignedCodonFrame> mappings1 = new ArrayList<AlignedCodonFrame>();
274 af1.getViewport().getAlignment().setCodonFrames(mappings1);
276 List<AlignedCodonFrame> mappings2 = new ArrayList<AlignedCodonFrame>();
279 af2.getViewport().getAlignment().setCodonFrames(mappings2);
282 * AlignFrame1 has mappings acf1 and acf2, AlignFrame2 has acf2 and acf3
285 List<AlignedCodonFrame> ssmMappings = ssm.getSequenceMappings();
286 assertEquals(0, ssmMappings.size());
287 ssm.registerMapping(acf1);
288 assertEquals(1, ssmMappings.size());
289 ssm.registerMapping(acf2);
290 assertEquals(2, ssmMappings.size());
291 ssm.registerMapping(acf3);
292 assertEquals(3, ssmMappings.size());
295 * Closing AlignFrame2 should remove mapping acf3 from
296 * StructureSelectionManager, but not acf2, since AlignFrame1 still has a
299 af2.closeMenuItem_actionPerformed(true);
300 assertEquals(2, ssmMappings.size());
301 assertTrue(ssmMappings.contains(acf1));
302 assertTrue(ssmMappings.contains(acf2));
303 assertFalse(ssmMappings.contains(acf3));
307 * Test for JAL-1306 - conservation thread should run even when only Quality
308 * (and not Conservation) is enabled in Preferences
310 @Test(groups = { "Functional" })
311 public void testUpdateConservation_qualityOnly()
313 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
314 Boolean.TRUE.toString());
315 Cache.applicationProperties.setProperty("SHOW_QUALITY",
316 Boolean.TRUE.toString());
317 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
318 Boolean.FALSE.toString());
319 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
320 Boolean.FALSE.toString());
321 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
322 "examples/uniref50.fa", FormatAdapter.FILE);
323 AlignmentAnnotation[] anns = af.viewport.getAlignment()
324 .getAlignmentAnnotation();
325 assertNotNull("No annotations found", anns);
326 assertEquals("More than one annotation found", 1, anns.length);
327 assertTrue("Annotation is not Quality",
328 anns[0].description.startsWith("Alignment Quality"));
329 Annotation[] annotations = anns[0].annotations;
330 assertNotNull("Quality annotations are null", annotations);
331 assertNotNull("Quality in column 1 is null", annotations[0]);
332 assertTrue("No quality value in column 1", annotations[0].value > 10f);
335 @Test(groups = { "Functional" })
336 public void testSetGlobalColourScheme()
339 * test for JAL-2283 don't inadvertently turn on colour by conservation
341 Cache.applicationProperties.setProperty("DEFAULT_COLOUR_PROT", "NONE");
342 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
343 Boolean.TRUE.toString());
344 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
345 "examples/uniref50.fa", FormatAdapter.FILE);
346 ColourSchemeI cs = new PIDColourScheme();
347 af.getViewport().setGlobalColourScheme(cs);
348 assertFalse(cs.conservationApplied());