JAL-674 hang on to sequences created by secondary parsiing process to manage transfer...
[jalview.git] / src / MCview / PDBChain.java
index 6055a5b..5dd38a4 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;
@@ -493,11 +505,51 @@ public class PDBChain
   public void transferResidueAnnotation(StructureMapping mapping)
   {
     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);
+            mapping.transfer(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)
+          {
+            mapping.transfer(ana);
+          }
+          else
+          {
+            continue;
+          }
+        }
+      }
       }
       float min = -1, max = 0;
       Annotation[] an = new Annotation[sq.getEnd() - sq.getStart() + 1];