JAL-1805 test envirionment separation
[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
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[]
67     { seq1, seq2, seq3 });
68     al.setDataset(null);
69
70     PDBEntry[] pdbFiles = new PDBEntry[3];
71     pdbFiles[0] = new PDBEntry("1YCS", "A", Type.PDB, "1YCS.pdb");
72     pdbFiles[1] = new PDBEntry("3A6S", "B", Type.PDB, "3A6S.pdb");
73     pdbFiles[2] = new PDBEntry("1OOT", "A", Type.PDB, "1OOT.pdb");
74     String[][] chains = new String[3][];
75     SequenceI[][] seqs = new SequenceI[3][];
76     seqs[0] = new SequenceI[]
77     { seq1 };
78     seqs[1] = new SequenceI[]
79     { seq2 };
80     seqs[2] = new SequenceI[]
81     { seq3 };
82     StructureSelectionManager ssm = new StructureSelectionManager();
83
84     ssm.setMapping(new SequenceI[]
85     { seq1 }, null, PDB_1, AppletFormatAdapter.PASTE);
86     ssm.setMapping(new SequenceI[]
87     { seq2 }, null, PDB_2, AppletFormatAdapter.PASTE);
88     ssm.setMapping(new SequenceI[]
89     { seq3 }, null, PDB_3, AppletFormatAdapter.PASTE);
90
91     testee = new AAStructureBindingModel(ssm, pdbFiles, seqs, chains, null)
92     {
93       @Override
94       public String[] getPdbFile()
95       {
96         /*
97          * fudge 'filenames' to match those generated when PDBFile parses PASTE
98          * data
99          */
100         return new String[]
101         { "INLINE1YCS", "INLINE3A6S", "INLINE1OOT" };
102       }
103       @Override
104       public void updateColours(Object source)
105       {
106       }
107       @Override
108       public void releaseReferences(Object svl)
109       {
110       }
111       @Override
112       public void highlightAtoms(List<AtomSpec> atoms)
113       {
114       }
115     };
116   }
117
118   /**
119    * Verify that the method determines that columns 2, 5 and 6 of the aligment
120    * are alignable in structure
121    */
122   @Test(groups ={ "Functional" })
123   public void testFindSuperposableResidues()
124   {
125     SuperposeData[] structs = new SuperposeData[al.getHeight()];
126     for (int i = 0; i < structs.length; i++)
127     {
128       structs[i] = testee.new SuperposeData(al.getWidth());
129     }
130     /*
131      * initialise array of 'superposable columns' to true (would be false for
132      * hidden columns)
133      */
134     boolean[] matched = new boolean[al.getWidth()];
135     Arrays.fill(matched, true);
136
137     int refStructure = testee
138             .findSuperposableResidues(al, matched, structs);
139
140     assertEquals(0, refStructure);
141
142     /*
143      * only ungapped, structure-mapped columns are superposable
144      */
145     assertFalse(matched[0]); // gap in first sequence
146     assertTrue(matched[1]);
147     assertFalse(matched[2]); // gap in second sequence
148     assertFalse(matched[3]); // gap in third sequence
149     assertTrue(matched[4]);
150     assertTrue(matched[5]);
151   }
152
153   @Test(groups ={ "Functional" })
154   public void testFindSuperposableResidues_hiddenColumn()
155   {
156     SuperposeData[] structs = new SuperposeData[al.getHeight()];
157     for (int i = 0; i < structs.length; i++)
158     {
159       structs[i] = testee.new SuperposeData(al.getWidth());
160     }
161     /*
162      * initialise array of 'superposable columns' to true (would be false for
163      * hidden columns)
164      */
165     boolean[] matched = new boolean[al.getWidth()];
166     Arrays.fill(matched, true);
167     // treat column 5 of the alignment as hidden
168     matched[4] = false;
169
170     int refStructure = testee
171             .findSuperposableResidues(al, matched, structs);
172
173     assertEquals(0, refStructure);
174
175     // only ungapped, structure-mapped columns are not superposable
176     assertFalse(matched[0]);
177     assertTrue(matched[1]);
178     assertFalse(matched[2]);
179     assertFalse(matched[3]);
180     assertFalse(matched[4]); // superposable, but hidden, column
181     assertTrue(matched[5]);
182   }
183 }