JAL-2349 fix off by one when resolving columns for sequence associated contact matrix
authorJames Procter <j.procter@dundee.ac.uk>
Mon, 20 Mar 2023 15:23:38 +0000 (15:23 +0000)
committerJames Procter <j.procter@dundee.ac.uk>
Mon, 20 Mar 2023 15:23:38 +0000 (15:23 +0000)
src/jalview/datamodel/Alignment.java
src/jalview/datamodel/ContactMapHolderI.java
test/jalview/analysis/AlignmentUtilsTests.java

index 321eee3..517a6dd 100755 (executable)
@@ -2080,10 +2080,10 @@ public class Alignment implements AlignmentI, AutoCloseable
       if (spos >= _aa.sequenceRef.getStart()
               && spos <= 1 + _aa.sequenceRef.getEnd())
       {
-        cl = _aa.sequenceRef.getContactListFor(_aa, spos);
+        cl = _aa.sequenceRef.getContactListFor(_aa, spos-_aa.sequenceRef.getStart());
         if (cl == null && _aa.sequenceRef.getDatasetSequence() != null)
         {
-          _aa.sequenceRef.getDatasetSequence().getContactListFor(_aa, spos);
+          _aa.sequenceRef.getDatasetSequence().getContactListFor(_aa, spos-_aa.sequenceRef.getStart());
         }
       }
     }
index ba23e67..342abf8 100644 (file)
@@ -6,10 +6,13 @@ public interface ContactMapHolderI
 {
   /**
    * resolve a contact list instance (if any) associated with the annotation row
-   * and column position
+   * and column position Columns of ContactMap are indexed relative to context
+   * object (columns of alignment, positions on sequence relative to
+   * sequence.getStart())
    * 
    * @param _aa
    * @param column
+   *          - base 0 column index
    * @return
    */
   ContactListI getContactListFor(AlignmentAnnotation _aa, int column);
index 1193c39..4baa384 100644 (file)
@@ -2630,6 +2630,11 @@ public class AlignmentUtilsTests
     assertNotNull(
             "No contact matrix recovered after reference annotation transfer",
             cl);
+    // semantics of sequence associated contact list is slightly tricky - column 3 in alignment should have data
+    cl = al.getContactListFor(alan, 3);
+    assertNotNull(
+            "Contact matrix should have data for last position in sequence",
+            cl);
 
     ContactMatrixI cm2 = new SeqDistanceContactMatrix(4);
     dssq.addContactList(cm2);