JAL-1645 Version-Rel Version 2.9 Year-Rel 2015 Licensing glob
[jalview.git] / test / jalview / structure / StructureSelectionManagerTest.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9)
3  * Copyright (C) 2015 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
32 import java.util.HashSet;
33 import java.util.Set;
34
35 import org.testng.annotations.BeforeMethod;
36 import org.testng.annotations.Test;
37
38 import MCview.PDBfile;
39
40 public class StructureSelectionManagerTest
41 {
42   private StructureSelectionManager ssm;
43
44   @BeforeMethod(alwaysRun = true)
45   public void setUp()
46   {
47     ssm = new StructureSelectionManager();
48   }
49
50   @Test(groups = { "Functional" })
51   public void testRegisterMapping()
52   {
53     AlignedCodonFrame acf1 = new AlignedCodonFrame();
54     AlignedCodonFrame acf2 = new AlignedCodonFrame();
55
56     ssm.registerMapping(acf1);
57     assertEquals(1, ssm.seqmappings.size());
58     assertTrue(ssm.seqmappings.contains(acf1));
59
60     ssm.registerMapping(acf2);
61     assertEquals(2, ssm.seqmappings.size());
62     assertTrue(ssm.seqmappings.contains(acf1));
63     assertTrue(ssm.seqmappings.contains(acf2));
64
65     /*
66      * Re-adding the first mapping does nothing
67      */
68     ssm.registerMapping(acf1);
69     assertEquals(2, ssm.seqmappings.size());
70     assertTrue(ssm.seqmappings.contains(acf1));
71     assertTrue(ssm.seqmappings.contains(acf2));
72   }
73
74   @Test(groups = { "Functional" })
75   public void testRegisterMappings()
76   {
77     AlignedCodonFrame acf1 = new AlignedCodonFrame();
78     AlignedCodonFrame acf2 = new AlignedCodonFrame();
79     AlignedCodonFrame acf3 = new AlignedCodonFrame();
80
81     Set<AlignedCodonFrame> set1 = new HashSet<AlignedCodonFrame>();
82     set1.add(acf1);
83     set1.add(acf2);
84     Set<AlignedCodonFrame> set2 = new HashSet<AlignedCodonFrame>();
85     set2.add(acf2);
86     set2.add(acf3);
87
88     /*
89      * Add both sets twice; each mapping should be added once only
90      */
91     ssm.registerMappings(set1);
92     ssm.registerMappings(set1);
93     ssm.registerMappings(set2);
94     ssm.registerMappings(set2);
95
96     assertEquals(3, ssm.seqmappings.size());
97     assertTrue(ssm.seqmappings.contains(acf1));
98     assertTrue(ssm.seqmappings.contains(acf2));
99     assertTrue(ssm.seqmappings.contains(acf3));
100   }
101
102   /**
103    * Verify that RESNUM sequence features are present after creating a PDB
104    * mapping
105    */
106   @Test(groups = { "Functional" })
107   public void testSetMapping_seqFeatures()
108   {
109     SequenceI seq = new Sequence(
110             "1GAQ|B",
111             "ATYNVKLITPEGEVELQVPDDVYILDQAEEDGIDLPYSCRAGSCSSCAGKVVSGSVDQSDQSYLDDGQIADGWVLTCHAYPTSDVVIETHKEEELTGA");
112     StructureSelectionManager sm = new StructureSelectionManager();
113     sm.setProcessSecondaryStructure(true);
114     sm.setAddTempFacAnnot(true);
115     PDBfile pmap = sm.setMapping(true, new SequenceI[] { seq },
116             new String[] { null }, "examples/1gaq.txt", FormatAdapter.FILE);
117     assertTrue(pmap != null);
118
119     assertEquals(3, pmap.getSeqs().size());
120     assertEquals("1GAQ|A", pmap.getSeqs().get(0).getName());
121     assertEquals("1GAQ|B", pmap.getSeqs().get(1).getName());
122     assertEquals("1GAQ|C", pmap.getSeqs().get(2).getName());
123
124     /*
125      * Verify a RESNUM sequence feature in the PDBfile sequence
126      */
127     SequenceFeature sf = pmap.getSeqs().get(0).getSequenceFeatures()[0];
128     assertEquals("RESNUM", sf.getType());
129     assertEquals("1gaq", sf.getFeatureGroup());
130     assertEquals("GLU:  19  1gaqA", sf.getDescription());
131
132     /*
133      * Verify a RESNUM sequence feature in the StructureSelectionManager mapped
134      * sequence
135      */
136     StructureMapping map = sm.getMapping("examples/1gaq.txt")[0];
137     sf = map.sequence.getSequenceFeatures()[0];
138     assertEquals("RESNUM", sf.getType());
139     assertEquals("1gaq", sf.getFeatureGroup());
140     assertEquals("ALA:   1  1gaqB", sf.getDescription());
141   }
142 }