merge commit
[jalview.git] / src / MCview / PDBChain.java
index 6055a5b..e8f1bc9 100755 (executable)
@@ -23,6 +23,7 @@ package MCview;
 import jalview.analysis.AlignSeq;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.Annotation;
+import jalview.datamodel.Mapping;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
@@ -53,7 +54,16 @@ public class PDBChain
 
   public int offset;
 
-  public Sequence sequence;
+  /**
+   * sequence is the sequence extracted by the chain parsing code
+   */
+  public SequenceI sequence;
+
+  /**
+   * shadow is the sequence created by any other parsing processes (e.g. Jmol,
+   * RNAview)
+   */
+  public SequenceI shadow = null;
 
   public boolean isNa = false;
 
@@ -80,6 +90,8 @@ public class PDBChain
    */
   protected String newline = System.getProperty("line.separator");
 
+  public Mapping shadowMap;
+
   public void setNewlineString(String nl)
   {
     newline = nl;
@@ -255,7 +267,7 @@ public class PDBChain
     bonds.addElement(new Bond(start, end, at1, at2));
   }
 
-  public void makeResidueList()
+  public void makeResidueList(boolean visibleChainAnnotation)
   {
     int count = 0;
     Object symbol;
@@ -365,23 +377,27 @@ public class PDBChain
               .elementAt(i));
       resFeatures.setElementAt(null, i);
     }
-    Annotation[] annots = new Annotation[resAnnotation.size()];
-    float max = 0;
-    for (i = 0, iSize = annots.length; i < iSize; i++)
+    if (visibleChainAnnotation)
     {
-      annots[i] = (Annotation) resAnnotation.elementAt(i);
-      if (annots[i].value > max)
+      Annotation[] annots = new Annotation[resAnnotation.size()];
+      float max = 0;
+      for (i = 0, iSize = annots.length; i < iSize; i++)
       {
-        max = annots[i].value;
+        annots[i] = (Annotation) resAnnotation.elementAt(i);
+        if (annots[i].value > max)
+        {
+          max = annots[i].value;
+        }
+        resAnnotation.setElementAt(null, i);
       }
-      resAnnotation.setElementAt(null, i);
+
+      AlignmentAnnotation tfactorann = new AlignmentAnnotation(
+              "PDB.TempFactor", "Temperature Factor for "
+                      + sequence.getName(), annots, 0, max,
+              AlignmentAnnotation.LINE_GRAPH);
+      tfactorann.setSequenceRef(sequence);
+      sequence.addAlignmentAnnotation(tfactorann);
     }
-    AlignmentAnnotation tfactorann = new AlignmentAnnotation(
-            "PDB.TempFactor", "Temperature Factor for "
-                    + sequence.getName(), annots, 0, max,
-            AlignmentAnnotation.LINE_GRAPH);
-    tfactorann.setSequenceRef(sequence);
-    sequence.addAlignmentAnnotation(tfactorann);
   }
 
   public void setChargeColours()
@@ -475,29 +491,66 @@ public class PDBChain
     }
   }
 
-  public AlignmentAnnotation[] transferResidueAnnotation(SequenceI seq,
-          String status)
-  {
-    AlignmentAnnotation[] transferred = null;
-
-    return transferred;
-
-  }
-
   /**
    * copy any sequence annotation onto the sequence mapped using the provided
    * StructureMapping
    * 
    * @param mapping
+   *          - positional mapping between destination sequence and pdb resnum
+   * @param sqmpping
+   *          - mapping between destination sequence and local chain
    */
-  public void transferResidueAnnotation(StructureMapping mapping)
+  public void transferResidueAnnotation(
+          StructureMapping mapping, jalview.datamodel.Mapping sqmpping)
   {
     SequenceI sq = mapping.getSequence();
+    SequenceI dsq = sq;
     if (sq != null)
     {
-      if (sequence != null && sequence.getAnnotation() != null)
+      while (dsq.getDatasetSequence() != null)
+      {
+        dsq = dsq.getDatasetSequence();
+      }
+      // any annotation will be transferred onto the dataset sequence
+
+      if (shadow != null && shadow.getAnnotation() != null)
       {
 
+        for (AlignmentAnnotation ana : shadow.getAnnotation())
+        {
+          List<AlignmentAnnotation> transfer = sq.getAlignmentAnnotations(
+                  ana.getCalcId(), ana.label);
+          if (transfer == null || transfer.size() == 0)
+          {
+            ana.liftOver(sequence, shadowMap);
+            ana.liftOver(dsq, sqmpping);
+            dsq.addAlignmentAnnotation(ana);
+          }
+          else
+          {
+            continue;
+          }
+        }
+      }
+      else
+      {
+      if (sequence != null && sequence.getAnnotation() != null)
+      {
+        for (AlignmentAnnotation ana : sequence.getAnnotation())
+        {
+          List<AlignmentAnnotation> transfer = sq.getAlignmentAnnotations(
+                  ana.getCalcId(), ana.label);
+          if (transfer == null || transfer.size() == 0)
+          {
+            ana.liftOver(dsq, sqmpping);
+            // mapping.transfer(ana);
+          }
+          else
+          {
+            continue;
+          }
+        }
+      }
       }
       float min = -1, max = 0;
       Annotation[] an = new Annotation[sq.getEnd() - sq.getStart() + 1];