JAL-2089 patch broken merge to master for Release 2.10.0b1
[jalview.git] / test / jalview / structure / StructureSelectionManagerTest.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
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.
11  *  
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.
16  * 
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.
20  */
21 package jalview.structure;
22
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertTrue;
25
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;
33
34 import java.util.ArrayList;
35 import java.util.List;
36
37 import org.testng.annotations.BeforeMethod;
38 import org.testng.annotations.Test;
39
40 public class StructureSelectionManagerTest
41 {
42   private StructureSelectionManager ssm;
43
44   @BeforeMethod(alwaysRun = true)
45   public void setUp()
46   {
47     StructureImportSettings.setShowSeqFeatures(true);
48     ssm = new StructureSelectionManager();
49   }
50
51   @Test(groups = { "Functional" })
52   public void testRegisterMapping()
53   {
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));
60
61     ssm.registerMapping(acf1);
62     assertEquals(1, ssm.getSequenceMappings().size());
63     assertTrue(ssm.getSequenceMappings().contains(acf1));
64
65     ssm.registerMapping(acf2);
66     assertEquals(2, ssm.getSequenceMappings().size());
67     assertTrue(ssm.getSequenceMappings().contains(acf1));
68     assertTrue(ssm.getSequenceMappings().contains(acf2));
69
70     /*
71      * Re-adding the first mapping does nothing
72      */
73     ssm.registerMapping(acf1);
74     assertEquals(2, ssm.getSequenceMappings().size());
75     assertTrue(ssm.getSequenceMappings().contains(acf1));
76     assertTrue(ssm.getSequenceMappings().contains(acf2));
77   }
78
79   @Test(groups = { "Functional" })
80   public void testRegisterMappings()
81   {
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));
91
92     List<AlignedCodonFrame> set1 = new ArrayList<AlignedCodonFrame>();
93     set1.add(acf1);
94     set1.add(acf2);
95     List<AlignedCodonFrame> set2 = new ArrayList<AlignedCodonFrame>();
96     set2.add(acf2);
97     set2.add(acf3);
98
99     /*
100      * Add both sets twice; each mapping should be added once only
101      */
102     ssm.registerMappings(set1);
103     ssm.registerMappings(set1);
104     ssm.registerMappings(set2);
105     ssm.registerMappings(set2);
106
107     assertEquals(3, ssm.getSequenceMappings().size());
108     assertTrue(ssm.getSequenceMappings().contains(acf1));
109     assertTrue(ssm.getSequenceMappings().contains(acf2));
110     assertTrue(ssm.getSequenceMappings().contains(acf3));
111   }
112
113   /**
114    * Verify that RESNUM sequence features are present after creating a PDB
115    * mapping
116    */
117   @Test(groups = { "Functional" })
118   public void testSetMapping_seqFeatures()
119   {
120     SequenceI seq = new Sequence(
121             "1GAQ|B",
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);
129
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());
134
135     /*
136      * Verify a RESNUM sequence feature in the PDBfile sequence
137      */
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());
142
143     /*
144      * Verify a RESNUM sequence feature in the StructureSelectionManager mapped
145      * sequence
146      */
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());
152   }
153 }