Merge branch 'releases/Release_2_11_3_Branch'
[jalview.git] / src / jalview / datamodel / Alignment.java
index 7f97f33..73ccdc5 100755 (executable)
@@ -2047,14 +2047,33 @@ 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 && _aa.sequenceRef.getDatasetSequence() != null)
+      {
+        // TODO fix up this logic and unify with getContactListFor
+        cm = _aa.sequenceRef.getDatasetSequence().getContactMatrixFor(_aa);
+      }
+    }
+    return cm;
   }
 
   @Override
   public ContactListI getContactListFor(AlignmentAnnotation _aa, int column)
   {
+    if (_aa.annotations == null || column >= _aa.annotations.length
+            || column < 0)
+    {
+      return null;
+    }
     ContactListI cl = cmholder.getContactListFor(_aa, column);
     if (cl == null && _aa.groupRef != null)
     {
@@ -2062,14 +2081,19 @@ public class Alignment implements AlignmentI, AutoCloseable
     }
     if (cl == null && _aa.sequenceRef != null)
     {
-      int spos = _aa.sequenceRef.findPosition(column);
-      if (spos >= _aa.sequenceRef.getStart()
-              && spos <= 1 + _aa.sequenceRef.getEnd())
+      if (_aa.annotations[column] != null)
       {
-        cl = _aa.sequenceRef.getContactListFor(_aa, spos);
+        // sequence associated
+        cl = _aa.sequenceRef.getContactListFor(_aa, column);
         if (cl == null && _aa.sequenceRef.getDatasetSequence() != null)
         {
-          _aa.sequenceRef.getDatasetSequence().getContactListFor(_aa, spos);
+          int spos = _aa.sequenceRef.findPosition(column);
+          if (spos >= _aa.sequenceRef.getStart()
+                  && spos <= 1 + _aa.sequenceRef.getEnd())
+          {
+            cl = _aa.sequenceRef.getDatasetSequence().getContactListFor(_aa,
+                    spos - _aa.sequenceRef.getStart());
+          }
         }
       }
     }
@@ -2082,8 +2106,7 @@ public class Alignment implements AlignmentI, AutoCloseable
     AlignmentAnnotation aa = cmholder.addContactList(cm);
 
     Annotation _aa[] = new Annotation[getWidth()];
-    Annotation dummy = new Annotation(0.0f);
-    for (int i = 0; i < _aa.length; _aa[i++] = dummy)
+    for (int i = 0; i < _aa.length; _aa[i++] = new Annotation(0.0f))
     {
       ;
     }