JAL-4356 release notes for JAL-3978 patch
[jalview.git] / src / mc_view / PDBChain.java
index 60c289e..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.Vector;
+import jalview.ws.datamodel.MappableContactMatrixI;
 
 public class PDBChain
 {
@@ -78,11 +82,31 @@ public class PDBChain
 
   public String pdbid = "";
 
-  public PDBChain(String thePdbid, String theId, boolean isAlphaFoldModel)
+  AnnotationRowBuilder tfacTemplate = new AnnotationRowBuilder(
+          "Temperature Factor");
+
+  public PDBChain(String thePdbid, String theId,
+          AnnotationRowBuilder template)
   {
-    this.pdbid = thePdbid == null ? thePdbid : thePdbid.toLowerCase();
+    this(thePdbid, theId);
+    if (template != null)
+    {
+      tfacTemplate = template;
+    }
+  }
+
+  /**
+   * import chain data assuming Temperature Factor is in the Temperature Factor
+   * column
+   * 
+   * @param thePdbid
+   * @param theId
+   */
+  public PDBChain(String thePdbid, String theId)
+  {
+    this.pdbid = thePdbid == null ? thePdbid
+            : thePdbid.toLowerCase(Locale.ROOT);
     this.id = theId;
-    this.alphaFoldModel = isAlphaFoldModel;
   }
 
   /**
@@ -92,8 +116,6 @@ public class PDBChain
 
   public Mapping shadowMap;
 
-  private boolean alphaFoldModel;
-
   public void setNewlineString(String nl)
   {
     newline = nl;
@@ -196,8 +218,8 @@ public class PDBChain
       }
       char seqchar = ds.getCharAt(seqpos - ds.getStart());
 
-      boolean sameResidue = Comparison.isSameResidue(
-              seqchar, strchar, false);
+      boolean sameResidue = Comparison.isSameResidue(seqchar, strchar,
+              false);
       if (sameResidue)
       {
         for (Atom atom : res.atoms)
@@ -215,10 +237,18 @@ public class PDBChain
    * @param seq
    * @param status
    *          The Status of the transferred annotation
+   * 
+   * @param altPDBID
+   *          the group id for the features on the destination sequence (e.g.
+   *          the official accession ID)
    */
-  public void transferRESNUMFeatures(SequenceI seq,
-          String status)
+  public void transferRESNUMFeatures(SequenceI seq, String status,
+          String altPDBID)
   {
+    if (altPDBID == null)
+    {
+      altPDBID = pdbid;
+    }
     SequenceI sq = seq;
     while (sq != null && sq.getDatasetSequence() != null)
     {
@@ -246,12 +276,13 @@ public class PDBChain
       if (feature.getFeatureGroup() != null
               && feature.getFeatureGroup().equals(pdbid))
       {
-        int newBegin = 1 + residues.elementAt(feature.getBegin() - offset).atoms
-                .elementAt(0).alignmentMapping;
+        int newBegin = 1
+                + residues.elementAt(feature.getBegin() - offset).atoms
+                        .elementAt(0).alignmentMapping;
         int newEnd = 1 + residues.elementAt(feature.getEnd() - offset).atoms
                 .elementAt(0).alignmentMapping;
         SequenceFeature tx = new SequenceFeature(feature, newBegin, newEnd,
-                feature.getFeatureGroup(), feature.getScore());
+                altPDBID, feature.getScore());
         tx.setStatus(status
                 + ((tx.getStatus() == null || tx.getStatus().length() == 0)
                         ? ""
@@ -396,8 +427,8 @@ public class PDBChain
       {
         String desc = currAtom.resName + ":" + currAtom.resNumIns + " "
                 + pdbid + id;
-        SequenceFeature sf = new SequenceFeature("INSERTION", desc, offset
-                + count - 1, offset + count - 1, "PDB_INS");
+        SequenceFeature sf = new SequenceFeature("INSERTION", desc,
+                offset + count - 1, offset + count - 1, "PDB_INS");
         resFeatures.addElement(sf);
         residues.lastElement().atoms.addAll(resAtoms);
       }
@@ -409,8 +440,8 @@ public class PDBChain
         Residue tmpres = residues.lastElement();
         Atom tmpat = tmpres.atoms.get(0);
         // Make A new SequenceFeature for the current residue numbering
-        String desc = tmpat.resName
-                + ":" + tmpat.resNumIns + " " + pdbid + id;
+        String desc = tmpat.resName + ":" + tmpat.resNumIns + " " + pdbid
+                + id;
         SequenceFeature sf = new SequenceFeature(RESNUM_FEATURE, desc,
                 offset + count, offset + count, pdbid);
         resFeatures.addElement(sf);
@@ -489,28 +520,31 @@ 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);
       }
-      String tfacName = "Temperature Factor";
-      if (isAlphaFoldModel())
+      if (tfacTemplate.isHasMinMax())
       {
-        tfacName = "Alphafold Reliability";
+        max = tfacTemplate.getMax();
+        min = tfacTemplate.getMin();
       }
+
       AlignmentAnnotation tfactorann = new AlignmentAnnotation(
-              tfacName, tfacName + " for " + pdbid + id,
+              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);
       sequence.addAlignmentAnnotation(tfactorann);
     }
   }
 
-  private boolean isAlphaFoldModel()
-  {
-    return alphaFoldModel;
-  }
-
   /**
    * Colour start/end of bonds by charge
    * <ul>
@@ -627,14 +661,22 @@ public class PDBChain
 
         for (AlignmentAnnotation ana : shadow.getAnnotation())
         {
-          List<AlignmentAnnotation> transfer = sq
-                  .getAlignmentAnnotations(ana.getCalcId(), ana.label);
+          // match on calcId, label and description so annotations from
+          // different structures are preserved
+          List<AlignmentAnnotation> transfer = sq.getAlignmentAnnotations(
+                  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
           {
@@ -648,14 +690,22 @@ public class PDBChain
         {
           for (AlignmentAnnotation ana : sequence.getAnnotation())
           {
+            // match on calcId, label and description so annotations from
+            // different structures are preserved
             List<AlignmentAnnotation> transfer = dsq
-                    .getAlignmentAnnotations(ana.getCalcId(), ana.label);
+                    .getAlignmentAnnotations(ana.getCalcId(), ana.label,
+                            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
             {