Merge branch 'releases/Release_2_11_3_Branch'
[jalview.git] / src / mc_view / PDBChain.java
index 72d276e..2970ccf 100755 (executable)
  */
 package mc_view;
 
+import java.awt.Color;
+import java.util.List;
+import java.util.Locale;
+import java.util.Vector;
+
 import jalview.analysis.AlignSeq;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.Annotation;
+import jalview.datamodel.ContactMatrixI;
 import jalview.datamodel.Mapping;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
+import jalview.datamodel.annotations.AnnotationRowBuilder;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.ResidueProperties;
 import jalview.structure.StructureImportSettings;
 import jalview.structure.StructureMapping;
 import jalview.util.Comparison;
-
-import java.awt.Color;
-import java.util.List;
-import java.util.Locale;
-import java.util.Vector;
+import jalview.ws.datamodel.MappableContactMatrixI;
 
 public class PDBChain
 {
@@ -79,17 +82,16 @@ public class PDBChain
 
   public String pdbid = "";
 
-  String tfacName = "Temperature Factor";
+  AnnotationRowBuilder tfacTemplate = new AnnotationRowBuilder(
+          "Temperature Factor");
 
   public PDBChain(String thePdbid, String theId,
-          String tempFactorColumnName)
+          AnnotationRowBuilder template)
   {
-    this.pdbid = thePdbid == null ? thePdbid
-            : thePdbid.toLowerCase(Locale.ROOT);
-    this.id = theId;
-    if (tempFactorColumnName != null && tempFactorColumnName.length() > 0)
+    this(thePdbid, theId);
+    if (template != null)
     {
-      tfacName = tempFactorColumnName;
+      tfacTemplate = template;
     }
   }
 
@@ -102,7 +104,9 @@ public class PDBChain
    */
   public PDBChain(String thePdbid, String theId)
   {
-    this(thePdbid, theId, null);
+    this.pdbid = thePdbid == null ? thePdbid
+            : thePdbid.toLowerCase(Locale.ROOT);
+    this.id = theId;
   }
 
   /**
@@ -516,14 +520,24 @@ public class PDBChain
       for (int i = 0; i < iSize; i++)
       {
         annots[i] = resAnnotation.elementAt(i);
+        tfacTemplate.processAnnotation(annots[i]);
         max = Math.max(max, annots[i].value);
         min = Math.min(min, annots[i].value);
         resAnnotation.setElementAt(null, i);
       }
-      AlignmentAnnotation tfactorann = new AlignmentAnnotation(tfacName,
-              tfacName + " for " + pdbid + id, annots, min, max,
-              AlignmentAnnotation.LINE_GRAPH);
+      if (tfacTemplate.isHasMinMax())
+      {
+        max = tfacTemplate.getMax();
+        min = tfacTemplate.getMin();
+      }
 
+      AlignmentAnnotation tfactorann = new AlignmentAnnotation(
+              tfacTemplate.getName(),
+              (tfacTemplate.isHasDescription()
+                      ? tfacTemplate.getDescription()
+                      : tfacTemplate.getName()) + " for " + pdbid + id,
+              annots, min, max, AlignmentAnnotation.LINE_GRAPH);
+      tfactorann.setTFType(tfacTemplate.getTFType());
       tfactorann.setCalcId(getClass().getName());
 
       tfactorann.setSequenceRef(sequence);
@@ -653,10 +667,16 @@ public class PDBChain
                   ana.getCalcId(), ana.label, ana.description);
           if (transfer == null || transfer.size() == 0)
           {
+            ContactMatrixI cm = shadow.getContactMatrixFor(ana);
             ana = new AlignmentAnnotation(ana);
+            // TODO map contact matrix under mapping
             ana.liftOver(sequence, shadowMap);
             ana.liftOver(dsq, sqmpping);
             dsq.addAlignmentAnnotation(ana);
+            if (cm != null)
+            {
+              dsq.addContactListFor(ana, cm);
+            }
           }
           else
           {
@@ -677,10 +697,15 @@ public class PDBChain
                             ana.description);
             if (transfer == null || transfer.size() == 0)
             {
+              ContactMatrixI cm = sequence.getContactMatrixFor(ana);
               ana = new AlignmentAnnotation(ana);
               ana.liftOver(dsq, sqmpping);
               dsq.addAlignmentAnnotation(ana);
-              // mapping.transfer(ana);
+              if (cm != null && cm instanceof MappableContactMatrixI)
+              {
+                dsq.addContactListFor(ana, ((MappableContactMatrixI) cm)
+                        .liftOver(dsq, sqmpping));
+              }
             }
             else
             {