JAL-3895 alphafold colours via pluggable annotation row builder. Also ensures min...
[jalview.git] / src / mc_view / PDBChain.java
index 72d276e..d9e7ec9 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;
@@ -27,17 +32,13 @@ import jalview.datamodel.Mapping;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
+import jalview.datamodel.annotations.AnnotationRowBuilder.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;
-
 public class PDBChain
 {
   public static final String RESNUM_FEATURE = "RESNUM";
@@ -79,17 +80,16 @@ public class PDBChain
 
   public String pdbid = "";
 
-  String tfacName = "Temperature Factor";
+  AnnotationRowBuilder tfacTemplate = new AnnotationRowBuilder(
+          "TemperatureFactor");
 
   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 +102,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 +518,23 @@ 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.setCalcId(getClass().getName());
 
       tfactorann.setSequenceRef(sequence);
@@ -694,8 +705,8 @@ public class PDBChain
         // Useful for debugging mappings - adds annotation for mapped position
         float min = -1, max = 0;
         Annotation[] an = new Annotation[sq.getEnd() - sq.getStart() + 1];
-        for (int i = sq.getStart(), j = sq
-                .getEnd(), k = 0; i <= j; i++, k++)
+        for (int i = sq.getStart(), j = sq.getEnd(),
+                k = 0; i <= j; i++, k++)
         {
           int prn = mapping.getPDBResNum(k + 1);