JAL-2349 fix off by one when resolving columns for sequence associated contact matrix
[jalview.git] / src / jalview / datamodel / Alignment.java
index 7f97f33..517a6dd 100755 (executable)
@@ -2047,9 +2047,23 @@ public class Alignment implements AlignmentI, AutoCloseable
   }
 
   @Override
-  public ContactMatrixI getContactMatrixFor(AlignmentAnnotation ann)
+  public ContactMatrixI getContactMatrixFor(AlignmentAnnotation _aa)
   {
-    return cmholder.getContactMatrixFor(ann);
+    ContactMatrixI cm = cmholder.getContactMatrixFor(_aa);
+    if (cm==null && _aa.groupRef!=null)
+    {
+      cm = _aa.groupRef.getContactMatrixFor(_aa);
+    }
+    if (cm==null && _aa.sequenceRef!=null)
+    {
+      cm = _aa.sequenceRef.getContactMatrixFor(_aa);
+      if (cm==null)
+      {
+        // TODO fix up this logic and unify with getContactListFor
+        cm = _aa.sequenceRef.getDatasetSequence().getContactMatrixFor(_aa);
+      }
+    }
+    return cm;
   }
 
   @Override
@@ -2066,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());
         }
       }
     }