JAL-4027 getter for contact matrices on the Alignment.
[jalview.git] / src / jalview / datamodel / Alignment.java
index 7f73110..0aa8424 100755 (executable)
  */
 package jalview.datamodel;
 
-import jalview.analysis.AlignmentUtils;
-import jalview.datamodel.AlignedCodonFrame.SequenceToSequenceMapping;
-import jalview.io.FastaFile;
-import jalview.util.Comparison;
-import jalview.util.LinkedIdentityHashSet;
-import jalview.util.MessageManager;
-
 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.HashMap;
@@ -41,6 +35,13 @@ import java.util.Map;
 import java.util.Set;
 import java.util.Vector;
 
+import jalview.analysis.AlignmentUtils;
+import jalview.datamodel.AlignedCodonFrame.SequenceToSequenceMapping;
+import jalview.io.FastaFile;
+import jalview.util.Comparison;
+import jalview.util.LinkedIdentityHashSet;
+import jalview.util.MessageManager;
+
 /**
  * Data structure to hold and manipulate a multiple sequence alignment
  */
@@ -196,7 +197,7 @@ public class Alignment implements AlignmentI, AutoCloseable
   {
     synchronized (sequences)
     {
-    
+
       if (i > -1 && i < sequences.size())
       {
         return sequences.get(i);
@@ -717,7 +718,7 @@ public class Alignment implements AlignmentI, AutoCloseable
   public int getWidth()
   {
     int maxLength = -1;
-  
+
     for (int i = 0; i < sequences.size(); i++)
     {
       maxLength = Math.max(maxLength, getSequenceAt(i).getLength());
@@ -1915,11 +1916,12 @@ public class Alignment implements AlignmentI, AutoCloseable
   @Override
   public boolean setHiddenColumns(HiddenColumns cols)
   {
-  boolean changed = cols == null ? hiddenCols != null
-          : !cols.equals(hiddenCols);
-  hiddenCols = cols;
-  return changed;
+    boolean changed = cols == null ? hiddenCols != null
+            : !cols.equals(hiddenCols);
+    hiddenCols = cols;
+    return changed;
   }
+
   @Override
   public void setupJPredAlignment()
   {
@@ -2033,9 +2035,19 @@ public class Alignment implements AlignmentI, AutoCloseable
   }
 
   Map<Object, ContactMatrixI> contactmaps = new HashMap<>();
+
   @Override
-  public
-  ContactListI getContactListFor(AlignmentAnnotation _aa, int column)
+  public Collection<ContactMatrixI> getContactMaps()
+  {
+    if (contactmaps != null && contactmaps.size() > 0)
+    {
+      return contactmaps.values();
+    }
+    return Collections.EMPTY_LIST;
+  }
+
+  @Override
+  public ContactListI getContactListFor(AlignmentAnnotation _aa, int column)
   {
     ContactMatrixI cm = contactmaps.get(_aa.annotationId);
     if (cm == null)
@@ -2062,6 +2074,12 @@ public class Alignment implements AlignmentI, AutoCloseable
     aa.editable = false;
     // aa.autoCalculated = true;
     contactmaps.put(aa.annotationId, cm);
+    // TODO: contact matrices could be intra or inter - more than one refseq
+    // possible!
+    if (cm.hasReferenceSeq())
+    {
+      aa.setSequenceRef(cm.getReferenceSeq());
+    }
     addAnnotation(aa);
     return aa;
   }