JAL-1673 new test to verify transferRESNUMFeatures()
[jalview.git] / test / jalview / structure / StructureSelectionManagerTest.java
1 package jalview.structure;
2
3 import static org.testng.AssertJUnit.assertEquals;
4 import static org.testng.AssertJUnit.assertTrue;
5
6 import jalview.datamodel.AlignedCodonFrame;
7 import jalview.datamodel.Sequence;
8 import jalview.datamodel.SequenceFeature;
9 import jalview.datamodel.SequenceI;
10 import jalview.io.FormatAdapter;
11
12 import java.util.HashSet;
13 import java.util.Set;
14
15 import org.testng.annotations.BeforeMethod;
16 import org.testng.annotations.Test;
17
18 import MCview.PDBfile;
19
20 public class StructureSelectionManagerTest
21 {
22   private StructureSelectionManager ssm;
23
24  @BeforeMethod(alwaysRun = true)
25   public void setUp()
26   {
27     ssm = new StructureSelectionManager();
28   }
29
30   @Test(groups ={ "Functional" })
31   public void testRegisterMapping()
32   {
33     AlignedCodonFrame acf1 = new AlignedCodonFrame();
34     AlignedCodonFrame acf2 = new AlignedCodonFrame();
35
36     ssm.registerMapping(acf1);
37     assertEquals(1, ssm.seqmappings.size());
38     assertTrue(ssm.seqmappings.contains(acf1));
39
40     ssm.registerMapping(acf2);
41     assertEquals(2, ssm.seqmappings.size());
42     assertTrue(ssm.seqmappings.contains(acf1));
43     assertTrue(ssm.seqmappings.contains(acf2));
44
45     /*
46      * Re-adding the first mapping does nothing
47      */
48     ssm.registerMapping(acf1);
49     assertEquals(2, ssm.seqmappings.size());
50     assertTrue(ssm.seqmappings.contains(acf1));
51     assertTrue(ssm.seqmappings.contains(acf2));
52   }
53
54   @Test(groups ={ "Functional" })
55   public void testRegisterMappings()
56   {
57     AlignedCodonFrame acf1 = new AlignedCodonFrame();
58     AlignedCodonFrame acf2 = new AlignedCodonFrame();
59     AlignedCodonFrame acf3 = new AlignedCodonFrame();
60
61     Set<AlignedCodonFrame> set1 = new HashSet<AlignedCodonFrame>();
62     set1.add(acf1);
63     set1.add(acf2);
64     Set<AlignedCodonFrame> set2 = new HashSet<AlignedCodonFrame>();
65     set2.add(acf2);
66     set2.add(acf3);
67
68     /*
69      * Add both sets twice; each mapping should be added once only
70      */
71     ssm.registerMappings(set1);
72     ssm.registerMappings(set1);
73     ssm.registerMappings(set2);
74     ssm.registerMappings(set2);
75
76     assertEquals(3, ssm.seqmappings.size());
77     assertTrue(ssm.seqmappings.contains(acf1));
78     assertTrue(ssm.seqmappings.contains(acf2));
79     assertTrue(ssm.seqmappings.contains(acf3));
80   }
81
82   /**
83    * Verify that RESNUM sequence features are present after creating a PDB
84    * mapping
85    */
86   @Test(groups = { "Functional" })
87   public void testSetMapping_seqFeatures()
88   {
89     SequenceI seq = new Sequence(
90             "1GAQ|B",
91             "ATYNVKLITPEGEVELQVPDDVYILDQAEEDGIDLPYSCRAGSCSSCAGKVVSGSVDQSDQSYLDDGQIADGWVLTCHAYPTSDVVIETHKEEELTGA");
92     StructureSelectionManager sm = new StructureSelectionManager();
93     sm.setProcessSecondaryStructure(true);
94     sm.setAddTempFacAnnot(true);
95     PDBfile pmap = sm.setMapping(true, new SequenceI[] { seq },
96             new String[] { null }, "examples/1gaq.txt",
97             FormatAdapter.FILE);
98     assertTrue(pmap != null);
99
100     assertEquals(3, pmap.getSeqs().size());
101     assertEquals("1GAQ|A", pmap.getSeqs().get(0).getName());
102     assertEquals("1GAQ|B", pmap.getSeqs().get(1).getName());
103     assertEquals("1GAQ|C", pmap.getSeqs().get(2).getName());
104
105     /*
106      * Verify a RESNUM sequence feature in the PDBfile sequence
107      */
108     SequenceFeature sf = pmap.getSeqs().get(0).getSequenceFeatures()[0];
109     assertEquals("RESNUM", sf.getType());
110     assertEquals("1gaq", sf.getFeatureGroup());
111     assertEquals("GLU:  19  1gaqA", sf.getDescription());
112
113     /*
114      * Verify a RESNUM sequence feature in the StructureSelectionManager mapped
115      * sequence
116      */
117     StructureMapping map = sm.getMapping("examples/1gaq.txt")[0];
118     sf = map.sequence.getSequenceFeatures()[0];
119     assertEquals("RESNUM", sf.getType());
120     assertEquals("1gaq", sf.getFeatureGroup());
121     assertEquals("ALA:   1  1gaqB", sf.getDescription());
122   }
123 }