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