Merge branch 'develop' into features/JAL-4134_use_annotation_row_for_colours_and_groups
[jalview.git] / src / jalview / datamodel / Sequence.java
index d62be17..33c8ac5 100755 (executable)
@@ -39,6 +39,7 @@ import jalview.util.Comparison;
 import jalview.util.DBRefUtils;
 import jalview.util.MapList;
 import jalview.util.StringUtils;
+import jalview.ws.datamodel.alphafold.MappableContactMatrix;
 
 /**
  * 
@@ -1625,6 +1626,13 @@ public class Sequence extends ASequence implements SequenceI
           _aa.adjustForAlignment(); // uses annotation's own record of
                                     // sequence-column mapping
           datasetSequence.addAlignmentAnnotation(_aa);
+
+          // transfer contact matrices
+          ContactMatrixI cm = getContactMatrixFor(aa);
+          if (cm != null)
+          {
+            datasetSequence.addContactListFor(_aa, cm);
+          }
         }
       }
     }
@@ -2111,7 +2119,7 @@ public class Sequence extends ASequence implements SequenceI
   ////
   //// Contact Matrix Holder Boilerplate
   ////
-  ContactMapHolder cmholder = new ContactMapHolder();
+  ContactMapHolderI cmholder = new ContactMapHolder();
 
   @Override
   public Collection<ContactMatrixI> getContactMaps()
@@ -2120,6 +2128,12 @@ public class Sequence extends ASequence implements SequenceI
   }
 
   @Override
+  public ContactMatrixI getContactMatrixFor(AlignmentAnnotation ann)
+  {
+    return cmholder.getContactMatrixFor(ann);
+  }
+
+  @Override
   public ContactListI getContactListFor(AlignmentAnnotation _aa, int column)
   {
     return cmholder.getContactListFor(_aa, column);
@@ -2131,14 +2145,27 @@ public class Sequence extends ASequence implements SequenceI
     AlignmentAnnotation aa = cmholder.addContactList(cm);
 
     Annotation _aa[] = new Annotation[getLength()];
-    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))
     {
       ;
     }
     aa.annotations = _aa;
+    aa.setSequenceRef(this);
+    if (cm instanceof MappableContactMatrix
+            && !((MappableContactMatrix) cm).hasReferenceSeq())
+    {
+      ((MappableContactMatrix) cm).setRefSeq(this);
+    }
+    aa.createSequenceMapping(this, getStart(), false);
     addAlignmentAnnotation(aa);
     return aa;
   }
 
+  @Override
+  public void addContactListFor(AlignmentAnnotation annotation,
+          ContactMatrixI cm)
+  {
+    cmholder.addContactListFor(annotation, cm);
+  }
 }