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