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.io.FormatAdapter;
31 import jalview.io.StructureFile;
32 import jalview.util.MapList;
34 import java.util.ArrayList;
35 import java.util.List;
37 import org.testng.annotations.BeforeMethod;
38 import org.testng.annotations.Test;
40 public class StructureSelectionManagerTest
42 private StructureSelectionManager ssm;
44 @BeforeMethod(alwaysRun = true)
47 StructureImportSettings.setShowSeqFeatures(true);
48 ssm = new StructureSelectionManager();
51 @Test(groups = { "Functional" })
52 public void testRegisterMapping()
54 AlignedCodonFrame acf1 = new AlignedCodonFrame();
55 acf1.addMap(new Sequence("s1", "ttt"), new Sequence("p1", "p"),
56 new MapList(new int[] { 1, 3 }, new int[] { 1, 1 }, 1, 1));
57 AlignedCodonFrame acf2 = new AlignedCodonFrame();
58 acf2.addMap(new Sequence("s2", "ttt"), new Sequence("p2", "p"),
59 new MapList(new int[] { 1, 3 }, new int[] { 1, 1 }, 1, 1));
61 ssm.registerMapping(acf1);
62 assertEquals(1, ssm.getSequenceMappings().size());
63 assertTrue(ssm.getSequenceMappings().contains(acf1));
65 ssm.registerMapping(acf2);
66 assertEquals(2, ssm.getSequenceMappings().size());
67 assertTrue(ssm.getSequenceMappings().contains(acf1));
68 assertTrue(ssm.getSequenceMappings().contains(acf2));
71 * Re-adding the first mapping does nothing
73 ssm.registerMapping(acf1);
74 assertEquals(2, ssm.getSequenceMappings().size());
75 assertTrue(ssm.getSequenceMappings().contains(acf1));
76 assertTrue(ssm.getSequenceMappings().contains(acf2));
79 @Test(groups = { "Functional" })
80 public void testRegisterMappings()
82 AlignedCodonFrame acf1 = new AlignedCodonFrame();
83 acf1.addMap(new Sequence("s1", "ttt"), new Sequence("p1", "p"),
84 new MapList(new int[] { 1, 3 }, new int[] { 1, 1 }, 1, 1));
85 AlignedCodonFrame acf2 = new AlignedCodonFrame();
86 acf2.addMap(new Sequence("s2", "ttt"), new Sequence("p2", "p"),
87 new MapList(new int[] { 1, 3 }, new int[] { 1, 1 }, 1, 1));
88 AlignedCodonFrame acf3 = new AlignedCodonFrame();
89 acf3.addMap(new Sequence("s3", "ttt"), new Sequence("p3", "p"),
90 new MapList(new int[] { 1, 3 }, new int[] { 1, 1 }, 1, 1));
92 List<AlignedCodonFrame> set1 = new ArrayList<AlignedCodonFrame>();
95 List<AlignedCodonFrame> set2 = new ArrayList<AlignedCodonFrame>();
100 * Add both sets twice; each mapping should be added once only
102 ssm.registerMappings(set1);
103 ssm.registerMappings(set1);
104 ssm.registerMappings(set2);
105 ssm.registerMappings(set2);
107 assertEquals(3, ssm.getSequenceMappings().size());
108 assertTrue(ssm.getSequenceMappings().contains(acf1));
109 assertTrue(ssm.getSequenceMappings().contains(acf2));
110 assertTrue(ssm.getSequenceMappings().contains(acf3));
114 * Verify that RESNUM sequence features are present after creating a PDB
117 @Test(groups = { "Functional" })
118 public void testSetMapping_seqFeatures()
120 SequenceI seq = new Sequence(
122 "ATYNVKLITPEGEVELQVPDDVYILDQAEEDGIDLPYSCRAGSCSSCAGKVVSGSVDQSDQSYLDDGQIADGWVLTCHAYPTSDVVIETHKEEELTGA");
123 StructureSelectionManager sm = new StructureSelectionManager();
124 sm.setProcessSecondaryStructure(true);
125 sm.setAddTempFacAnnot(true);
126 StructureFile pmap = sm.setMapping(true, new SequenceI[] { seq },
127 new String[] { null }, "examples/1gaq.txt", FormatAdapter.FILE);
128 assertTrue(pmap != null);
130 assertEquals(3, pmap.getSeqs().size());
131 assertEquals("1GAQ|A", pmap.getSeqs().get(0).getName());
132 assertEquals("1GAQ|B", pmap.getSeqs().get(1).getName());
133 assertEquals("1GAQ|C", pmap.getSeqs().get(2).getName());
136 * Verify a RESNUM sequence feature in the PDBfile sequence
138 SequenceFeature sf = pmap.getSeqs().get(0).getSequenceFeatures()[0];
139 assertEquals("RESNUM", sf.getType());
140 assertEquals("1gaq", sf.getFeatureGroup());
141 assertEquals("GLU: 19 1gaqA", sf.getDescription());
144 * Verify a RESNUM sequence feature in the StructureSelectionManager mapped
147 StructureMapping map = sm.getMapping("examples/1gaq.txt")[0];
148 sf = map.sequence.getSequenceFeatures()[0];
149 assertEquals("RESNUM", sf.getType());
150 assertEquals("1gaq", sf.getFeatureGroup());
151 assertEquals("ALA: 1 1gaqB", sf.getDescription());