JAL-1645 source formatting and organise imports
[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
7 import jalview.datamodel.Alignment;
8 import jalview.datamodel.AlignmentI;
9 import jalview.datamodel.PDBEntry;
10 import jalview.datamodel.PDBEntry.Type;
11 import jalview.datamodel.Sequence;
12 import jalview.datamodel.SequenceI;
13 import jalview.io.AppletFormatAdapter;
14 import jalview.structure.AtomSpec;
15 import jalview.structure.StructureSelectionManager;
16 import jalview.structures.models.AAStructureBindingModel.SuperposeData;
17
18 import java.util.Arrays;
19 import java.util.List;
20
21 import org.testng.annotations.BeforeMethod;
22 import org.testng.annotations.Test;
23
24 /**
25  * Unit tests for non-abstract methods of abstract base class
26  * 
27  * @author gmcarstairs
28  *
29  */
30 public class AAStructureBindingModelTest
31 {
32   private static final String PDB_1 = "HEADER    COMPLEX (ANTI-ONCOGENE/ANKYRIN REPEATS) 30-SEP-96   1YCS              \n"
33           + "ATOM      2  CA  VAL A  97      24.134   4.926  45.821  1.00 47.43           C  \n"
34           + "ATOM      9  CA  PRO A  98      25.135   8.584  46.217  1.00 41.60           C  \n"
35           + "ATOM     16  CA  SER A  99      28.243   9.596  44.271  1.00 39.63           C  \n"
36           + "ATOM     22  CA  GLN A 100      31.488  10.133  46.156  1.00 35.60           C  \n"
37           + "ATOM     31  CA  LYS A 101      33.323  11.587  43.115  1.00 41.69           C  \n";
38
39   private static final String PDB_2 = "HEADER    HYDROLASE                               09-SEP-09   3A6S              \n"
40           + "ATOM      2  CA  MET A   1      15.366 -11.648  24.854  1.00 32.05           C  \n"
41           + "ATOM     10  CA  LYS A   2      16.846  -9.215  22.340  1.00 25.68           C  \n"
42           + "ATOM     19  CA  LYS A   3      15.412  -6.335  20.343  1.00 19.42           C  \n"
43           + "ATOM     28  CA  LEU A   4      15.629  -5.719  16.616  1.00 15.49           C  \n"
44           + "ATOM     36  CA  GLN A   5      14.412  -2.295  15.567  1.00 12.19           C  \n";
45
46   private static final String PDB_3 = "HEADER    STRUCTURAL GENOMICS                     04-MAR-03   1OOT              \n"
47           + "ATOM      2  CA  SER A   1      29.427   3.330  -6.578  1.00 32.50           C  \n"
48           + "ATOM      8  CA  PRO A   2      29.975   3.340  -2.797  1.00 17.62           C  \n"
49           + "ATOM     16  CA ALYS A   3      26.958   3.024  -0.410  0.50  8.78           C  \n"
50           + "ATOM     33  CA  ALA A   4      26.790   4.320   3.172  1.00 11.98           C  \n"
51           + "ATOM     39  CA AVAL A   5      24.424   3.853   6.106  0.50 13.83           C  \n";
52
53   AAStructureBindingModel testee;
54
55   AlignmentI al = null;
56
57   /**
58    * Set up test conditions with three aligned sequences,
59    */
60   @BeforeMethod(alwaysRun = true)
61   public void setUp()
62   {
63     SequenceI seq1 = new Sequence("1YCS", "-VPSQK");
64     SequenceI seq2 = new Sequence("3A6S", "MK-KLQ");
65     SequenceI seq3 = new Sequence("1OOT", "SPK-AV");
66     al = new Alignment(new SequenceI[] { seq1, seq2, seq3 });
67     al.setDataset(null);
68
69     PDBEntry[] pdbFiles = new PDBEntry[3];
70     pdbFiles[0] = new PDBEntry("1YCS", "A", Type.PDB, "1YCS.pdb");
71     pdbFiles[1] = new PDBEntry("3A6S", "B", Type.PDB, "3A6S.pdb");
72     pdbFiles[2] = new PDBEntry("1OOT", "A", Type.PDB, "1OOT.pdb");
73     String[][] chains = new String[3][];
74     SequenceI[][] seqs = new SequenceI[3][];
75     seqs[0] = new SequenceI[] { seq1 };
76     seqs[1] = new SequenceI[] { seq2 };
77     seqs[2] = new SequenceI[] { seq3 };
78     StructureSelectionManager ssm = new StructureSelectionManager();
79
80     ssm.setMapping(new SequenceI[] { seq1 }, null, PDB_1,
81             AppletFormatAdapter.PASTE);
82     ssm.setMapping(new SequenceI[] { seq2 }, null, PDB_2,
83             AppletFormatAdapter.PASTE);
84     ssm.setMapping(new SequenceI[] { seq3 }, null, PDB_3,
85             AppletFormatAdapter.PASTE);
86
87     testee = new AAStructureBindingModel(ssm, pdbFiles, seqs, chains, null)
88     {
89       @Override
90       public String[] getPdbFile()
91       {
92         /*
93          * fudge 'filenames' to match those generated when PDBFile parses PASTE
94          * data
95          */
96         return new String[] { "INLINE1YCS", "INLINE3A6S", "INLINE1OOT" };
97       }
98
99       @Override
100       public void updateColours(Object source)
101       {
102       }
103
104       @Override
105       public void releaseReferences(Object svl)
106       {
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 alignment
118    * are alignable in structure
119    */
120   @Test(groups = { "Functional" })
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(groups = { "Functional" })
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 }