Merge branch 'develop' into feature/JAL-1713_overviewInProject
[jalview.git] / src / jalview / datamodel / Sequence.java
index f8e70b1..5ae7195 100755 (executable)
  */
 package jalview.datamodel;
 
-import jalview.analysis.AlignSeq;
-import jalview.datamodel.features.SequenceFeatures;
-import jalview.datamodel.features.SequenceFeaturesI;
-import jalview.util.Comparison;
-import jalview.util.DBRefUtils;
-import jalview.util.MapList;
-import jalview.util.StringUtils;
-
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.BitSet;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Enumeration;
 import java.util.Iterator;
@@ -39,6 +32,13 @@ import java.util.ListIterator;
 import java.util.Vector;
 
 import fr.orsay.lri.varna.models.rna.RNA;
+import jalview.analysis.AlignSeq;
+import jalview.datamodel.features.SequenceFeatures;
+import jalview.datamodel.features.SequenceFeaturesI;
+import jalview.util.Comparison;
+import jalview.util.DBRefUtils;
+import jalview.util.MapList;
+import jalview.util.StringUtils;
 
 /**
  * 
@@ -1625,6 +1625,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);
+          }
         }
       }
     }
@@ -2107,4 +2114,52 @@ public class Sequence extends ASequence implements SequenceI
     // otherwise, sequence was completely hidden
     return 0;
   }
+
+  ////
+  //// Contact Matrix Holder Boilerplate
+  ////
+  ContactMapHolderI cmholder = new ContactMapHolder();
+
+  @Override
+  public Collection<ContactMatrixI> getContactMaps()
+  {
+    return cmholder.getContactMaps();
+  }
+
+  @Override
+  public ContactMatrixI getContactMatrixFor(AlignmentAnnotation ann)
+  {
+    return cmholder.getContactMatrixFor(ann);
+  }
+
+  @Override
+  public ContactListI getContactListFor(AlignmentAnnotation _aa, int column)
+  {
+    return cmholder.getContactListFor(_aa, column);
+  }
+
+  @Override
+  public AlignmentAnnotation addContactList(ContactMatrixI cm)
+  {
+    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)
+    {
+      ;
+    }
+    aa.annotations = _aa;
+    aa.setSequenceRef(this);
+    aa.createSequenceMapping(this, getStart(), false);
+    addAlignmentAnnotation(aa);
+    return aa;
+  }
+
+  @Override
+  public void addContactListFor(AlignmentAnnotation annotation,
+          ContactMatrixI cm)
+  {
+    cmholder.addContactListFor(annotation, cm);
+  }
 }