JAL-1270 JUnit to TestNG refactoring
[jalview.git] / test / jalview / structures / models / AAStructureBindingModelTest.java
1 package jalview.structures.models;
2
3 import static org.testng.AssertJUnit.assertEquals;
4 import static org.testng.AssertJUnit.assertFalse;
5 import static org.testng.AssertJUnit.assertTrue;
6 import org.testng.annotations.Test;
7 import org.testng.annotations.BeforeMethod;
8 import java.util.Arrays;
9 import java.util.List;
10
11 import jalview.datamodel.Alignment;
12 import jalview.datamodel.AlignmentI;
13 import jalview.datamodel.PDBEntry;
14 import jalview.datamodel.PDBEntry.Type;
15 import jalview.datamodel.Sequence;
16 import jalview.datamodel.SequenceI;
17 import jalview.io.AppletFormatAdapter;
18 import jalview.structure.AtomSpec;
19 import jalview.structure.StructureSelectionManager;
20 import jalview.structures.models.AAStructureBindingModel.SuperposeData;
21
22 /**
23  * Unit tests for non-abstract methods of abstract base class
24  * 
25  * @author gmcarstairs
26  *
27  */
28 public class AAStructureBindingModelTest
29 {
30   private static final String PDB_1 = "HEADER    COMPLEX (ANTI-ONCOGENE/ANKYRIN REPEATS) 30-SEP-96   1YCS              \n"
31           + "ATOM      2  CA  VAL A  97      24.134   4.926  45.821  1.00 47.43           C  \n"
32           + "ATOM      9  CA  PRO A  98      25.135   8.584  46.217  1.00 41.60           C  \n"
33           + "ATOM     16  CA  SER A  99      28.243   9.596  44.271  1.00 39.63           C  \n"
34           + "ATOM     22  CA  GLN A 100      31.488  10.133  46.156  1.00 35.60           C  \n"
35           + "ATOM     31  CA  LYS A 101      33.323  11.587  43.115  1.00 41.69           C  \n";
36
37   private static final String PDB_2 = "HEADER    HYDROLASE                               09-SEP-09   3A6S              \n"
38           + "ATOM      2  CA  MET A   1      15.366 -11.648  24.854  1.00 32.05           C  \n"
39           + "ATOM     10  CA  LYS A   2      16.846  -9.215  22.340  1.00 25.68           C  \n"
40           + "ATOM     19  CA  LYS A   3      15.412  -6.335  20.343  1.00 19.42           C  \n"
41           + "ATOM     28  CA  LEU A   4      15.629  -5.719  16.616  1.00 15.49           C  \n"
42           + "ATOM     36  CA  GLN A   5      14.412  -2.295  15.567  1.00 12.19           C  \n";
43
44   private static final String PDB_3 = "HEADER    STRUCTURAL GENOMICS                     04-MAR-03   1OOT              \n"
45           + "ATOM      2  CA  SER A   1      29.427   3.330  -6.578  1.00 32.50           C  \n"
46           + "ATOM      8  CA  PRO A   2      29.975   3.340  -2.797  1.00 17.62           C  \n"
47           + "ATOM     16  CA ALYS A   3      26.958   3.024  -0.410  0.50  8.78           C  \n"
48           + "ATOM     33  CA  ALA A   4      26.790   4.320   3.172  1.00 11.98           C  \n"
49           + "ATOM     39  CA AVAL A   5      24.424   3.853   6.106  0.50 13.83           C  \n";
50
51   AAStructureBindingModel testee;
52
53   AlignmentI al = null;
54
55   /**
56    * Set up test conditions with three aligned sequences,
57    */
58   @BeforeMethod
59   public void setUp()
60   {
61     SequenceI seq1 = new Sequence("1YCS", "-VPSQK");
62     SequenceI seq2 = new Sequence("3A6S", "MK-KLQ");
63     SequenceI seq3 = new Sequence("1OOT", "SPK-AV");
64     al = new Alignment(new SequenceI[]
65     { seq1, seq2, seq3 });
66     al.setDataset(null);
67
68     PDBEntry[] pdbFiles = new PDBEntry[3];
69     pdbFiles[0] = new PDBEntry("1YCS", "A", Type.PDB, "1YCS.pdb");
70     pdbFiles[1] = new PDBEntry("3A6S", "B", Type.PDB, "3A6S.pdb");
71     pdbFiles[2] = new PDBEntry("1OOT", "A", Type.PDB, "1OOT.pdb");
72     String[][] chains = new String[3][];
73     SequenceI[][] seqs = new SequenceI[3][];
74     seqs[0] = new SequenceI[]
75     { seq1 };
76     seqs[1] = new SequenceI[]
77     { seq2 };
78     seqs[2] = new SequenceI[]
79     { seq3 };
80     StructureSelectionManager ssm = new StructureSelectionManager();
81
82     ssm.setMapping(new SequenceI[]
83     { seq1 }, null, PDB_1, AppletFormatAdapter.PASTE);
84     ssm.setMapping(new SequenceI[]
85     { seq2 }, null, PDB_2, AppletFormatAdapter.PASTE);
86     ssm.setMapping(new SequenceI[]
87     { seq3 }, null, PDB_3, AppletFormatAdapter.PASTE);
88
89     testee = new AAStructureBindingModel(ssm, pdbFiles, seqs, chains, null)
90     {
91       @Override
92       public String[] getPdbFile()
93       {
94         /*
95          * fudge 'filenames' to match those generated when PDBFile parses PASTE
96          * data
97          */
98         return new String[]
99         { "INLINE1YCS", "INLINE3A6S", "INLINE1OOT" };
100       }
101       @Override
102       public void updateColours(Object source)
103       {
104       }
105       @Override
106       public void releaseReferences(Object svl)
107       {
108       }
109       @Override
110       public void highlightAtoms(List<AtomSpec> atoms)
111       {
112       }
113     };
114   }
115
116   /**
117    * Verify that the method determines that columns 2, 5 and 6 of the aligment
118    * are alignable in structure
119    */
120   @Test
121   public void testFindSuperposableResidues()
122   {
123     SuperposeData[] structs = new SuperposeData[al.getHeight()];
124     for (int i = 0; i < structs.length; i++)
125     {
126       structs[i] = testee.new SuperposeData(al.getWidth());
127     }
128     /*
129      * initialise array of 'superposable columns' to true (would be false for
130      * hidden columns)
131      */
132     boolean[] matched = new boolean[al.getWidth()];
133     Arrays.fill(matched, true);
134
135     int refStructure = testee
136             .findSuperposableResidues(al, matched, structs);
137
138     assertEquals(0, refStructure);
139
140     /*
141      * only ungapped, structure-mapped columns are superposable
142      */
143     assertFalse(matched[0]); // gap in first sequence
144     assertTrue(matched[1]);
145     assertFalse(matched[2]); // gap in second sequence
146     assertFalse(matched[3]); // gap in third sequence
147     assertTrue(matched[4]);
148     assertTrue(matched[5]);
149   }
150
151   @Test
152   public void testFindSuperposableResidues_hiddenColumn()
153   {
154     SuperposeData[] structs = new SuperposeData[al.getHeight()];
155     for (int i = 0; i < structs.length; i++)
156     {
157       structs[i] = testee.new SuperposeData(al.getWidth());
158     }
159     /*
160      * initialise array of 'superposable columns' to true (would be false for
161      * hidden columns)
162      */
163     boolean[] matched = new boolean[al.getWidth()];
164     Arrays.fill(matched, true);
165     // treat column 5 of the alignment as hidden
166     matched[4] = false;
167
168     int refStructure = testee
169             .findSuperposableResidues(al, matched, structs);
170
171     assertEquals(0, refStructure);
172
173     // only ungapped, structure-mapped columns are not superposable
174     assertFalse(matched[0]);
175     assertTrue(matched[1]);
176     assertFalse(matched[2]);
177     assertFalse(matched[3]);
178     assertFalse(matched[4]); // superposable, but hidden, column
179     assertTrue(matched[5]);
180   }
181 }