Merge branch 'develop' into features/JAL-653_gffalignments
[jalview.git] / test / jalview / structures / models / AAStructureBindingModelTest.java
diff --git a/test/jalview/structures/models/AAStructureBindingModelTest.java b/test/jalview/structures/models/AAStructureBindingModelTest.java
new file mode 100644 (file)
index 0000000..3db7f23
--- /dev/null
@@ -0,0 +1,183 @@
+package jalview.structures.models;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.PDBEntry;
+import jalview.datamodel.PDBEntry.Type;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceI;
+import jalview.io.AppletFormatAdapter;
+import jalview.structure.AtomSpec;
+import jalview.structure.StructureSelectionManager;
+import jalview.structures.models.AAStructureBindingModel.SuperposeData;
+
+/**
+ * Unit tests for non-abstract methods of abstract base class
+ * 
+ * @author gmcarstairs
+ *
+ */
+public class AAStructureBindingModelTest
+{
+  private static final String PDB_1 = "HEADER    COMPLEX (ANTI-ONCOGENE/ANKYRIN REPEATS) 30-SEP-96   1YCS              \n"
+          + "ATOM      2  CA  VAL A  97      24.134   4.926  45.821  1.00 47.43           C  \n"
+          + "ATOM      9  CA  PRO A  98      25.135   8.584  46.217  1.00 41.60           C  \n"
+          + "ATOM     16  CA  SER A  99      28.243   9.596  44.271  1.00 39.63           C  \n"
+          + "ATOM     22  CA  GLN A 100      31.488  10.133  46.156  1.00 35.60           C  \n"
+          + "ATOM     31  CA  LYS A 101      33.323  11.587  43.115  1.00 41.69           C  \n";
+
+  private static final String PDB_2 = "HEADER    HYDROLASE                               09-SEP-09   3A6S              \n"
+          + "ATOM      2  CA  MET A   1      15.366 -11.648  24.854  1.00 32.05           C  \n"
+          + "ATOM     10  CA  LYS A   2      16.846  -9.215  22.340  1.00 25.68           C  \n"
+          + "ATOM     19  CA  LYS A   3      15.412  -6.335  20.343  1.00 19.42           C  \n"
+          + "ATOM     28  CA  LEU A   4      15.629  -5.719  16.616  1.00 15.49           C  \n"
+          + "ATOM     36  CA  GLN A   5      14.412  -2.295  15.567  1.00 12.19           C  \n";
+
+  private static final String PDB_3 = "HEADER    STRUCTURAL GENOMICS                     04-MAR-03   1OOT              \n"
+          + "ATOM      2  CA  SER A   1      29.427   3.330  -6.578  1.00 32.50           C  \n"
+          + "ATOM      8  CA  PRO A   2      29.975   3.340  -2.797  1.00 17.62           C  \n"
+          + "ATOM     16  CA ALYS A   3      26.958   3.024  -0.410  0.50  8.78           C  \n"
+          + "ATOM     33  CA  ALA A   4      26.790   4.320   3.172  1.00 11.98           C  \n"
+          + "ATOM     39  CA AVAL A   5      24.424   3.853   6.106  0.50 13.83           C  \n";
+
+  AAStructureBindingModel testee;
+
+  AlignmentI al = null;
+
+  /**
+   * Set up test conditions with three aligned sequences,
+   */
+  @Before
+  public void setUp()
+  {
+    SequenceI seq1 = new Sequence("1YCS", "-VPSQK");
+    SequenceI seq2 = new Sequence("3A6S", "MK-KLQ");
+    SequenceI seq3 = new Sequence("1OOT", "SPK-AV");
+    al = new Alignment(new SequenceI[]
+    { seq1, seq2, seq3 });
+    al.setDataset(null);
+
+    PDBEntry[] pdbFiles = new PDBEntry[3];
+    pdbFiles[0] = new PDBEntry("1YCS", "A", Type.PDB, "1YCS.pdb");
+    pdbFiles[1] = new PDBEntry("3A6S", "B", Type.PDB, "3A6S.pdb");
+    pdbFiles[2] = new PDBEntry("1OOT", "A", Type.PDB, "1OOT.pdb");
+    String[][] chains = new String[3][];
+    SequenceI[][] seqs = new SequenceI[3][];
+    seqs[0] = new SequenceI[]
+    { seq1 };
+    seqs[1] = new SequenceI[]
+    { seq2 };
+    seqs[2] = new SequenceI[]
+    { seq3 };
+    StructureSelectionManager ssm = new StructureSelectionManager();
+
+    ssm.setMapping(new SequenceI[]
+    { seq1 }, null, PDB_1, AppletFormatAdapter.PASTE);
+    ssm.setMapping(new SequenceI[]
+    { seq2 }, null, PDB_2, AppletFormatAdapter.PASTE);
+    ssm.setMapping(new SequenceI[]
+    { seq3 }, null, PDB_3, AppletFormatAdapter.PASTE);
+
+    testee = new AAStructureBindingModel(ssm, pdbFiles, seqs, chains, null)
+    {
+      @Override
+      public String[] getPdbFile()
+      {
+        /*
+         * fudge 'filenames' to match those generated when PDBFile parses PASTE
+         * data
+         */
+        return new String[]
+        { "INLINE1YCS", "INLINE3A6S", "INLINE1OOT" };
+      }
+      @Override
+      public void updateColours(Object source)
+      {
+      }
+      @Override
+      public void releaseReferences(Object svl)
+      {
+      }
+      @Override
+      public void highlightAtoms(List<AtomSpec> atoms)
+      {
+      }
+    };
+  }
+
+  /**
+   * Verify that the method determines that columns 2, 5 and 6 of the aligment
+   * are alignable in structure
+   */
+  @Test
+  public void testFindSuperposableResidues()
+  {
+    SuperposeData[] structs = new SuperposeData[al.getHeight()];
+    for (int i = 0; i < structs.length; i++)
+    {
+      structs[i] = testee.new SuperposeData(al.getWidth());
+    }
+    /*
+     * initialise array of 'superposable columns' to true (would be false for
+     * hidden columns)
+     */
+    boolean[] matched = new boolean[al.getWidth()];
+    Arrays.fill(matched, true);
+
+    int refStructure = testee
+            .findSuperposableResidues(al, matched, structs);
+
+    assertEquals(0, refStructure);
+
+    /*
+     * only ungapped, structure-mapped columns are superposable
+     */
+    assertFalse(matched[0]); // gap in first sequence
+    assertTrue(matched[1]);
+    assertFalse(matched[2]); // gap in second sequence
+    assertFalse(matched[3]); // gap in third sequence
+    assertTrue(matched[4]);
+    assertTrue(matched[5]);
+  }
+
+  @Test
+  public void testFindSuperposableResidues_hiddenColumn()
+  {
+    SuperposeData[] structs = new SuperposeData[al.getHeight()];
+    for (int i = 0; i < structs.length; i++)
+    {
+      structs[i] = testee.new SuperposeData(al.getWidth());
+    }
+    /*
+     * initialise array of 'superposable columns' to true (would be false for
+     * hidden columns)
+     */
+    boolean[] matched = new boolean[al.getWidth()];
+    Arrays.fill(matched, true);
+    // treat column 5 of the alignment as hidden
+    matched[4] = false;
+
+    int refStructure = testee
+            .findSuperposableResidues(al, matched, structs);
+
+    assertEquals(0, refStructure);
+
+    // only ungapped, structure-mapped columns are not superposable
+    assertFalse(matched[0]);
+    assertTrue(matched[1]);
+    assertFalse(matched[2]);
+    assertFalse(matched[3]);
+    assertFalse(matched[4]); // superposable, but hidden, column
+    assertTrue(matched[5]);
+  }
+}