Merge branch 'patch/JAL-4311_import_pLDDT_scores_from_nonAlphaFold_sources' into...
[jalview.git] / src / jalview / datamodel / ContactMapHolder.java
index f6ccc6a..3a64917 100644 (file)
@@ -3,8 +3,11 @@ package jalview.datamodel;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
 
+import jalview.ws.datamodel.MappableContactMatrixI;
+
 public class ContactMapHolder implements ContactMapHolderI
 {
 
@@ -15,7 +18,8 @@ public class ContactMapHolder implements ContactMapHolderI
   {
     if (contactmaps != null && contactmaps.size() > 0)
     {
-      return contactmaps.values();
+      // defensive copy, and return non redundant set of ContactMatrixI instances
+      return new HashSet<ContactMatrixI>(contactmaps.values());
     }
     return Collections.EMPTY_LIST;
   }
@@ -28,6 +32,14 @@ public class ContactMapHolder implements ContactMapHolderI
     {
       return null;
     }
+    if (cm instanceof MappableContactMatrixI)
+    {
+      if (_aa.sequenceRef != null)
+      {
+        return ((MappableContactMatrixI) cm)
+                .getMappableContactList(_aa.sequenceRef, column);
+      }
+    }
     // TODO: could resolve sequence position to column position here
     // TODO: what about for complexes - where contactMatrix may involve two or
     // more sequences
@@ -44,14 +56,14 @@ public class ContactMapHolder implements ContactMapHolderI
     aa.graphMin = cm.getMin();
     aa.graphMax = cm.getMax();
     aa.editable = false;
-    aa.calcId=cm.getType();
+    aa.calcId = cm.getType();
 
     contactmaps.put(aa.annotationId, cm);
     // TODO: contact matrices could be intra or inter - more than one refseq
     // possible!
-    if (cm.hasReferenceSeq())
+    if (cm instanceof MappableContactMatrixI)
     {
-      aa.setSequenceRef(cm.getReferenceSeq());
+      aa.setSequenceRef(((MappableContactMatrixI) cm).getReferenceSeq());
     }
     return aa;
   }
@@ -66,6 +78,21 @@ public class ContactMapHolder implements ContactMapHolderI
   public void addContactListFor(AlignmentAnnotation annotation,
           ContactMatrixI cm)
   {
+    // update annotation with data from contact map
+    annotation.graphMin = cm.getMin();
+    annotation.graphMax = cm.getMax();
+    annotation.editable = false;
+    annotation.graph = AlignmentAnnotation.CONTACT_MAP;
+    annotation.calcId = cm.getType();
+    if (annotation.label == null || "".equals(annotation.label))
+    {
+      annotation.label = cm.getAnnotLabel();
+
+    }
+    if (annotation.description == null || "".equals(annotation.description))
+    {
+      annotation.description = cm.getAnnotDescr();
+    }
     contactmaps.put(annotation.annotationId, cm);
   }
 }