3 import static org.testng.AssertJUnit.assertEquals;
4 import static org.testng.AssertJUnit.assertFalse;
5 import static org.testng.AssertJUnit.assertNotNull;
6 import static org.testng.AssertJUnit.assertSame;
7 import static org.testng.AssertJUnit.assertTrue;
9 import jalview.datamodel.AlignedCodonFrame;
10 import jalview.datamodel.Alignment;
11 import jalview.datamodel.AlignmentI;
12 import jalview.datamodel.PDBEntry;
13 import jalview.datamodel.PDBEntry.Type;
14 import jalview.datamodel.Sequence;
15 import jalview.datamodel.SequenceI;
16 import jalview.io.FileLoader;
17 import jalview.io.FormatAdapter;
18 import jalview.structure.StructureSelectionManager;
20 import java.util.LinkedHashSet;
23 import org.testng.annotations.BeforeClass;
24 import org.testng.annotations.BeforeMethod;
25 import org.testng.annotations.Test;
27 public class AlignViewportTest
33 @BeforeClass(alwaysRun = true)
34 public static void setUpBeforeClass() throws Exception
36 jalview.bin.Jalview.main(new String[] { "-props",
37 "test/jalview/testProps.jvprops" });
40 @BeforeMethod(alwaysRun = true)
43 SequenceI seq1 = new Sequence("Seq1", "ABC");
44 SequenceI seq2 = new Sequence("Seq2", "ABC");
45 SequenceI seq3 = new Sequence("Seq3", "ABC");
46 SequenceI[] seqs = new SequenceI[]
48 al = new Alignment(seqs);
50 testee = new AlignViewport(al);
53 @Test(groups ={ "Functional" })
54 public void testCollateForPdb()
57 * Set up sequence pdb ids
59 PDBEntry pdb1 = new PDBEntry("1ABC", "A", Type.PDB, "1ABC.pdb");
60 PDBEntry pdb2 = new PDBEntry("2ABC", "A", Type.PDB, "2ABC.pdb");
61 PDBEntry pdb3 = new PDBEntry("3ABC", "A", Type.PDB, "3ABC.pdb");
64 * seq1 and seq3 refer to 1ABC, seq2 to 2ABC, none to 3ABC
66 al.getSequenceAt(0).getDatasetSequence()
68 new PDBEntry("1ABC", "B", Type.PDB, "1ABC.pdb"));
69 al.getSequenceAt(2).getDatasetSequence()
71 new PDBEntry("1ABC", "B", Type.PDB, "1ABC.pdb"));
72 al.getSequenceAt(1).getDatasetSequence()
74 new PDBEntry("2ABC", "C", Type.PDB, "2ABC.pdb"));
76 * Add a second chain PDB xref to Seq2 - should not result in a duplicate in
79 al.getSequenceAt(1).getDatasetSequence()
80 .addPDBId(new PDBEntry("2ABC", "D", Type.PDB, "2ABC.pdb"));
82 * Seq3 refers to 3abc - this does not match 3ABC (as the code stands)
84 al.getSequenceAt(2).getDatasetSequence()
85 .addPDBId(new PDBEntry("3abc", "D", Type.PDB, "3ABC.pdb"));
88 * run method under test
90 SequenceI[][] seqs = testee.collateForPDB(new PDBEntry[]
91 { pdb1, pdb2, pdb3 });
93 // seq1 and seq3 refer to PDBEntry[0]
94 assertEquals(2, seqs[0].length);
95 assertSame(al.getSequenceAt(0), seqs[0][0]);
96 assertSame(al.getSequenceAt(2), seqs[0][1]);
98 // seq2 refers to PDBEntry[1]
99 assertEquals(1, seqs[1].length);
100 assertSame(al.getSequenceAt(1), seqs[1][0]);
102 // no sequence refers to PDBEntry[2]
103 assertEquals(0, seqs[2].length);
107 * Test that a mapping is not deregistered when a second view is closed but
108 * the first still holds a reference to the mapping
110 @Test(groups ={ "Functional" })
111 public void testDeregisterMapping_onCloseView()
114 * alignment with reference to mappings
116 AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded(
117 ">Seq1\nCAGT\n", FormatAdapter.PASTE);
119 AlignedCodonFrame acf1 = new AlignedCodonFrame();
120 AlignedCodonFrame acf2 = new AlignedCodonFrame();
122 Set<AlignedCodonFrame> mappings = new LinkedHashSet<AlignedCodonFrame>();
125 af1.getViewport().getAlignment().setCodonFrames(mappings);
126 af1.newView_actionPerformed(null);
129 * Verify that creating the alignment for the new View has registered the
132 StructureSelectionManager ssm = StructureSelectionManager
133 .getStructureSelectionManager(Desktop.instance);
134 assertEquals(2, ssm.seqmappings.size());
135 assertTrue(ssm.seqmappings.contains(acf1));
136 assertTrue(ssm.seqmappings.contains(acf2));
139 * Close the second view. Verify that mappings are not removed as the first
140 * view still holds a reference to them.
142 af1.closeMenuItem_actionPerformed(false);
143 assertEquals(2, ssm.seqmappings.size());
144 assertTrue(ssm.seqmappings.contains(acf1));
145 assertTrue(ssm.seqmappings.contains(acf2));
149 * Test that a mapping is deregistered if no alignment holds a reference to it
151 @Test(groups ={ "Functional" })
152 public void testDeregisterMapping_withNoReference()
154 Desktop d = Desktop.instance;
156 StructureSelectionManager ssm = StructureSelectionManager
157 .getStructureSelectionManager(Desktop.instance);
160 AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded(
161 ">Seq1\nRSVQ\n", FormatAdapter.PASTE);
162 AlignFrame af2 = new FileLoader().LoadFileWaitTillLoaded(
163 ">Seq2\nDGEL\n", FormatAdapter.PASTE);
165 AlignedCodonFrame acf1 = new AlignedCodonFrame();
166 AlignedCodonFrame acf2 = new AlignedCodonFrame();
167 AlignedCodonFrame acf3 = new AlignedCodonFrame();
169 Set<AlignedCodonFrame> mappings1 = new LinkedHashSet<AlignedCodonFrame>();
171 af1.getViewport().getAlignment().setCodonFrames(mappings1);
173 Set<AlignedCodonFrame> mappings2 = new LinkedHashSet<AlignedCodonFrame>();
176 af2.getViewport().getAlignment().setCodonFrames(mappings2);
179 * AlignFrame1 has mapping acf1, AlignFrame2 has acf2 and acf3
182 Set<AlignedCodonFrame> ssmMappings = ssm.seqmappings;
183 assertEquals(0, ssmMappings.size());
184 ssm.registerMapping(acf1);
185 assertEquals(1, ssmMappings.size());
186 ssm.registerMapping(acf2);
187 assertEquals(2, ssmMappings.size());
188 ssm.registerMapping(acf3);
189 assertEquals(3, ssmMappings.size());
192 * Closing AlignFrame2 should remove its mappings from
193 * StructureSelectionManager, since AlignFrame1 has no reference to them
195 af2.closeMenuItem_actionPerformed(true);
196 assertEquals(1, ssmMappings.size());
197 assertTrue(ssmMappings.contains(acf1));
201 * Test that a mapping is not deregistered if another alignment holds a
204 @Test(groups ={ "Functional" })
205 public void testDeregisterMapping_withReference()
207 Desktop d = Desktop.instance;
209 StructureSelectionManager ssm = StructureSelectionManager
210 .getStructureSelectionManager(Desktop.instance);
213 AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded(
214 ">Seq1\nRSVQ\n", FormatAdapter.PASTE);
215 AlignFrame af2 = new FileLoader().LoadFileWaitTillLoaded(
216 ">Seq2\nDGEL\n", FormatAdapter.PASTE);
218 AlignedCodonFrame acf1 = new AlignedCodonFrame();
219 AlignedCodonFrame acf2 = new AlignedCodonFrame();
220 AlignedCodonFrame acf3 = new AlignedCodonFrame();
222 Set<AlignedCodonFrame> mappings1 = new LinkedHashSet<AlignedCodonFrame>();
225 af1.getViewport().getAlignment().setCodonFrames(mappings1);
227 Set<AlignedCodonFrame> mappings2 = new LinkedHashSet<AlignedCodonFrame>();
230 af2.getViewport().getAlignment().setCodonFrames(mappings2);
233 * AlignFrame1 has mappings acf1 and acf2, AlignFrame2 has acf2 and acf3
236 Set<AlignedCodonFrame> ssmMappings = ssm.seqmappings;
237 assertEquals(0, ssmMappings.size());
238 ssm.registerMapping(acf1);
239 assertEquals(1, ssmMappings.size());
240 ssm.registerMapping(acf2);
241 assertEquals(2, ssmMappings.size());
242 ssm.registerMapping(acf3);
243 assertEquals(3, ssmMappings.size());
246 * Closing AlignFrame2 should remove mapping acf3 from
247 * StructureSelectionManager, but not acf2, since AlignFrame1 still has a
250 af2.closeMenuItem_actionPerformed(true);
251 assertEquals(2, ssmMappings.size());
252 assertTrue(ssmMappings.contains(acf1));
253 assertTrue(ssmMappings.contains(acf2));
254 assertFalse(ssmMappings.contains(acf3));