JAL-674 hang on to sequences created by secondary parsiing process to manage transfer...
authorJim Procter <jprocter@dundee.ac.uk>
Thu, 30 Oct 2014 16:53:20 +0000 (16:53 +0000)
committerJim Procter <jprocter@dundee.ac.uk>
Thu, 30 Oct 2014 16:53:20 +0000 (16:53 +0000)
src/MCview/PDBChain.java
src/MCview/PDBfile.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];
index 7d2ceac..11e7188 100755 (executable)
@@ -339,13 +339,43 @@ public class PDBfile extends jalview.io.AlignFile
             sq.getPDBId().clear();
           }
         }
-        AlignSeq.replaceMatchingSeqsWith(seqs, annotations, prot, al, AlignSeq.PEP, false);
+        replaceAndUpdateChains(prot, al, AlignSeq.PEP, false);
       }
     } catch (ClassNotFoundException q)
     {
     }
   }
 
+  private void replaceAndUpdateChains(ArrayList<SequenceI> prot,
+          AlignmentI al, String pep, boolean b)
+  {
+    List<List<? extends Object>> replaced = AlignSeq
+            .replaceMatchingSeqsWith(seqs,
+            annotations, prot, al, AlignSeq.PEP, false);
+    for (PDBChain ch : chains)
+    {
+      int p = 0;
+      for (SequenceI sq : (List<SequenceI>) replaced.get(0))
+      {
+        p++;
+        if (sq == ch.sequence || sq.getDatasetSequence() == ch.sequence)
+        {
+          p = -p;
+          break;
+        }
+      }
+      if (p < 0)
+      {
+        p = -p - 1;
+        // set shadow entry for chains
+        ch.shadow = (SequenceI) replaced.get(1).get(p);
+        ch.shadowMap = ((AlignSeq) replaced.get(2)
+.get(p))
+                .getMappingFromS1(false);
+      }
+    }
+  }
+
   private void processPdbFileWithAnnotate3d(ArrayList<SequenceI> rna)
           throws Exception
   {
@@ -371,14 +401,20 @@ public class PDBfile extends jalview.io.AlignFile
         {
           if (sq.getDatasetSequence() != null)
           {
-            sq.getDatasetSequence().getPDBId().clear();
+            if (sq.getDatasetSequence().getPDBId() != null)
+            {
+              sq.getDatasetSequence().getPDBId().clear();
+            }
           }
           else
           {
-            sq.getPDBId().clear();
+            if (sq.getPDBId() != null)
+            {
+              sq.getPDBId().clear();
+            }
           }
         }
-        AlignSeq.replaceMatchingSeqsWith(seqs, annotations, rna, al, AlignSeq.DNA, false);
+        replaceAndUpdateChains(rna, al, AlignSeq.DNA, false);
       }
     } catch (ClassNotFoundException x)
     {