JAL-2349 JAL-3855 PAE tests covers ContactListI.getMappedPositons
[jalview.git] / test / jalview / datamodel / PAEContactMatrixTest.java
index 7426cba..71e824e 100644 (file)
@@ -6,6 +6,8 @@ import org.testng.Assert;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
+import jalview.analysis.AlignmentUtils;
+import jalview.analysis.SeqsetUtils;
 import jalview.gui.JvOptionPane;
 import jalview.util.MapList;
 import jalview.ws.datamodel.MappableContactMatrixI;
@@ -81,6 +83,22 @@ public class PAEContactMatrixTest
     // last column
     assertNotNull(newseq.getContactListFor(newaa, -1+newseq.findIndex(10)));
 
+    // verify MappedPositions includes discontinuity
+    int[] mappedCl = newseq.getContactListFor(newaa, 5).getMappedPositionsFor(0, 4);
+    assertEquals(4,mappedCl.length,"getMappedPositionsFor doesn't support discontinuous mappings to contactList");
+    
+    // make it harder. 
+    
+    SequenceI alseq = newseq.getSubSequence(6, 10);
+    alseq.insertCharAt(2, 2, '-');
+    AlignmentI alForSeq=new Alignment(new SequenceI[] { alseq });
+    newaa = AlignmentUtils.addReferenceAnnotationTo(alForSeq, alseq, newaa, null);
+    ContactListI alcl = alForSeq.getContactListFor(newaa, 1);
+    assertNotNull(alcl);
+    mappedCl = alcl.getMappedPositionsFor(0, 4);
+    assertNotNull(mappedCl);
+    assertEquals(4,mappedCl.length,"getMappedPositionsFor doesn't support discontinuous mappings to contactList");
+    
     // remap2 - test with original matrix map from 1-5 remapped to 5-9
     
     seq = new Sequence("Seq/1-5","ASDQE");
@@ -114,7 +132,6 @@ public class PAEContactMatrixTest
     
     newaa = newseq.addContactList(remapped);
     verify_mapping(newseq, newaa);
-    
   }
   /**
    * checks that the PAE matrix is located at positions 1-9 in newseq, and columns are not truncated.
@@ -134,16 +151,19 @@ public class PAEContactMatrixTest
     assertNull(newseq.getContactListFor(newaa, -1+newseq.findIndex(10)));
     
     verifyPAEmatrix(newseq, newaa, 4, 4, 8);
-    
-
   }
 
   private void verifyPAEmatrix(SequenceI seq, AlignmentAnnotation aa, int topl, int rowl, int rowr)
   {
+    int[] mappedCl;
     for (int f=rowl;f<=rowr;f++) {
       ContactListI clist = seq.getContactListFor(aa, f);
       assertNotNull(clist,"No ContactListI for position "+(f));
       assertEquals(clist.getContactAt(0), (double) f-topl+1,"for column "+f+" relative to "+topl);
+      mappedCl = clist.getMappedPositionsFor(0, 0);
+      assertNotNull(mappedCl);
+      assertEquals(mappedCl[0],mappedCl[1]);
+      assertEquals(mappedCl[0],seq.findIndex(seq.getStart()+topl));
       assertEquals(clist.getContactAt(f-topl),1d, "for column and row "+f+" relative to "+topl);
     }    
   }