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.
21 package jalview.structure;
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertTrue;
26 import jalview.datamodel.AlignedCodonFrame;
27 import jalview.datamodel.Sequence;
28 import jalview.datamodel.SequenceFeature;
29 import jalview.datamodel.SequenceI;
30 import jalview.gui.JvOptionPane;
31 import jalview.io.DataSourceType;
32 import jalview.io.StructureFile;
33 import jalview.util.MapList;
35 import java.util.ArrayList;
36 import java.util.List;
38 import org.testng.annotations.BeforeClass;
39 import org.testng.annotations.BeforeMethod;
40 import org.testng.annotations.Test;
42 public class StructureSelectionManagerTest
45 @BeforeClass(alwaysRun = true)
46 public void setUpJvOptionPane()
48 JvOptionPane.setInteractiveMode(false);
49 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
52 private StructureSelectionManager ssm;
54 @BeforeMethod(alwaysRun = true)
57 StructureImportSettings.setShowSeqFeatures(true);
58 ssm = new StructureSelectionManager();
61 @Test(groups = { "Functional" })
62 public void testRegisterMapping()
64 AlignedCodonFrame acf1 = new AlignedCodonFrame();
65 acf1.addMap(new Sequence("s1", "ttt"), new Sequence("p1", "p"),
66 new MapList(new int[] { 1, 3 }, new int[] { 1, 1 }, 1, 1));
67 AlignedCodonFrame acf2 = new AlignedCodonFrame();
68 acf2.addMap(new Sequence("s2", "ttt"), new Sequence("p2", "p"),
69 new MapList(new int[] { 1, 3 }, new int[] { 1, 1 }, 1, 1));
71 ssm.registerMapping(acf1);
72 assertEquals(1, ssm.getSequenceMappings().size());
73 assertTrue(ssm.getSequenceMappings().contains(acf1));
75 ssm.registerMapping(acf2);
76 assertEquals(2, ssm.getSequenceMappings().size());
77 assertTrue(ssm.getSequenceMappings().contains(acf1));
78 assertTrue(ssm.getSequenceMappings().contains(acf2));
81 * Re-adding the first mapping does nothing
83 ssm.registerMapping(acf1);
84 assertEquals(2, ssm.getSequenceMappings().size());
85 assertTrue(ssm.getSequenceMappings().contains(acf1));
86 assertTrue(ssm.getSequenceMappings().contains(acf2));
89 @Test(groups = { "Functional" })
90 public void testRegisterMappings()
92 AlignedCodonFrame acf1 = new AlignedCodonFrame();
93 acf1.addMap(new Sequence("s1", "ttt"), new Sequence("p1", "p"),
94 new MapList(new int[] { 1, 3 }, new int[] { 1, 1 }, 1, 1));
95 AlignedCodonFrame acf2 = new AlignedCodonFrame();
96 acf2.addMap(new Sequence("s2", "ttt"), new Sequence("p2", "p"),
97 new MapList(new int[] { 1, 3 }, new int[] { 1, 1 }, 1, 1));
98 AlignedCodonFrame acf3 = new AlignedCodonFrame();
99 acf3.addMap(new Sequence("s3", "ttt"), new Sequence("p3", "p"),
100 new MapList(new int[] { 1, 3 }, new int[] { 1, 1 }, 1, 1));
102 List<AlignedCodonFrame> set1 = new ArrayList<AlignedCodonFrame>();
105 List<AlignedCodonFrame> set2 = new ArrayList<AlignedCodonFrame>();
110 * Add both sets twice; each mapping should be added once only
112 ssm.registerMappings(set1);
113 ssm.registerMappings(set1);
114 ssm.registerMappings(set2);
115 ssm.registerMappings(set2);
117 assertEquals(3, ssm.getSequenceMappings().size());
118 assertTrue(ssm.getSequenceMappings().contains(acf1));
119 assertTrue(ssm.getSequenceMappings().contains(acf2));
120 assertTrue(ssm.getSequenceMappings().contains(acf3));
124 * Verify that RESNUM sequence features are present after creating a PDB
127 @Test(groups = { "Functional" })
128 public void testSetMapping_seqFeatures()
130 SequenceI seq = new Sequence(
132 "ATYNVKLITPEGEVELQVPDDVYILDQAEEDGIDLPYSCRAGSCSSCAGKVVSGSVDQSDQSYLDDGQIADGWVLTCHAYPTSDVVIETHKEEELTGA");
133 StructureSelectionManager sm = new StructureSelectionManager();
134 sm.setProcessSecondaryStructure(true);
135 sm.setAddTempFacAnnot(true);
136 StructureFile pmap = sm.setMapping(true, new SequenceI[] { seq },
137 new String[] { null }, "examples/1gaq.txt", DataSourceType.FILE);
138 assertTrue(pmap != null);
140 assertEquals(3, pmap.getSeqs().size());
141 assertEquals("1GAQ|A", pmap.getSeqs().get(0).getName());
142 assertEquals("1GAQ|B", pmap.getSeqs().get(1).getName());
143 assertEquals("1GAQ|C", pmap.getSeqs().get(2).getName());
146 * Verify a RESNUM sequence feature in the PDBfile sequence
148 SequenceFeature sf = pmap.getSeqs().get(0).getSequenceFeatures()[0];
149 assertEquals("RESNUM", sf.getType());
150 assertEquals("1gaq", sf.getFeatureGroup());
151 assertEquals("GLU: 19 1gaqA", sf.getDescription());
154 * Verify a RESNUM sequence feature in the StructureSelectionManager mapped
157 StructureMapping map = sm.getMapping("examples/1gaq.txt")[0];
158 sf = map.sequence.getSequenceFeatures()[0];
159 assertEquals("RESNUM", sf.getType());
160 assertEquals("1gaq", sf.getFeatureGroup());
161 assertEquals("ALA: 1 1gaqB", sf.getDescription());