Merge branch 'feature/JAL-674_dssp' into features/JAL-1264_showHideAnnotations
[jalview.git] / src / MCview / PDBfile.java
index 7f5c427..086c4d9 100755 (executable)
@@ -22,7 +22,7 @@ package MCview;
 
 import java.io.*;
 import java.util.*;
-
+import java.util.List;
 import java.awt.*;
 
 import jalview.analysis.AlignSeq;
@@ -41,14 +41,33 @@ public class PDBfile extends jalview.io.AlignFile
    */
   boolean VisibleChainAnnotation = false;
 
-  public PDBfile(String inFile, String inType) throws IOException
+  boolean processSecondaryStructure=true;
+  
+
+  public PDBfile(boolean visibleChainAnnotation,
+          boolean processSecondaryStructure)
+  {
+    super();
+    VisibleChainAnnotation = visibleChainAnnotation;
+    this.processSecondaryStructure = processSecondaryStructure;
+  }
+
+  public PDBfile(boolean visibleChainAnnotation,
+          boolean processSecondaryStructure, String file, String protocol) throws IOException
   {
-    super(inFile, inType);
+    super(false, file, protocol);
+    VisibleChainAnnotation = visibleChainAnnotation;
+    this.processSecondaryStructure = processSecondaryStructure;
+    doParse();
   }
 
-  public PDBfile(FileParse source) throws IOException
+  public PDBfile(boolean visibleChainAnnotation,
+          boolean processSecondaryStructure, FileParse source) throws IOException
   {
-    super(source);
+    super(false, source);
+    VisibleChainAnnotation = visibleChainAnnotation;
+    this.processSecondaryStructure = processSecondaryStructure;
+    doParse();
   }
 
   public String print()
@@ -202,6 +221,8 @@ public class PDBfile extends jalview.io.AlignFile
           }
         }
       }
+      if (processSecondaryStructure)
+      {
       if (rna.size() > 0)
         try
         {
@@ -221,23 +242,11 @@ public class PDBfile extends jalview.io.AlignFile
         } catch (Exception x)
         {
           System.err
-                  .println("Exceptions when dealing with RNA in pdb file");
-          x.printStackTrace();
-
-        }
-      ;
-      if (prot.size() > 0)
-        try
-        {
-          processPdbFileWithJmol(prot);
-        } catch (Exception x)
-        {
-          System.err
-                  .println("Exceptions when dealing with RNA in pdb file");
+                  .println("Exceptions from Jmol when processing data in pdb file");
           x.printStackTrace();
 
         }
-      ;
+      }
     } catch (OutOfMemoryError er)
     {
       System.out.println("OUT OF MEMORY LOADING PDB FILE");
@@ -270,7 +279,7 @@ public class PDBfile extends jalview.io.AlignFile
                 {}).invoke(jmf));
         cl.getMethod("addAnnotations", new Class[]
         { Alignment.class }).invoke(jmf, al);
-        replaceMatchingSeqsWith(prot, al, AlignSeq.PEP);
+        replaceMatchingSeqsWith(seqs, annotations, prot, al, AlignSeq.PEP, false);
       }
     } catch (ClassNotFoundException q)
     {
@@ -298,7 +307,7 @@ public class PDBfile extends jalview.io.AlignFile
                 new Class[]
                 { FileParse.class }).invoke(annotate3d, new Object[]
         { new FileParse(getDataName(), type) }));
-        replaceMatchingSeqsWith(rna, al, AlignSeq.DNA);
+        replaceMatchingSeqsWith(seqs, annotations, rna, al, AlignSeq.DNA, false);
       }
     } catch (ClassNotFoundException x)
     {
@@ -314,9 +323,10 @@ public class PDBfile extends jalview.io.AlignFile
    * @param ochains
    * @param al
    * @param dnaOrProtein
+   * @param removeOldAnnots when true, old annotation is cleared before new annotation transferred
    */
-  private void replaceMatchingSeqsWith(ArrayList<SequenceI> ochains,
-          AlignmentI al, String dnaOrProtein)
+  public static void replaceMatchingSeqsWith(List<SequenceI> seqs, List<AlignmentAnnotation> annotations, List<SequenceI> ochains,
+          AlignmentI al, String dnaOrProtein, boolean removeOldAnnots)
   {
     if (al != null && al.getHeight() > 0)
     {
@@ -354,17 +364,24 @@ public class PDBfile extends jalview.io.AlignFile
           seqs.set(p, sq = matches.get(q));
           sq.setName(sp.getName());
           sq.setDescription(sp.getDescription());
-          sq.transferAnnotation(sp, aligns.get(q).getMappingFromS1(false));
+          Mapping sp2sq;
+          sq.transferAnnotation(sp, sp2sq = aligns.get(q).getMappingFromS1(false));
           int inspos = -1;
           for (int ap = 0; ap < annotations.size();)
           {
-            if (((AlignmentAnnotation) annotations.get(ap)).sequenceRef == sp)
+            if (annotations.get(ap).sequenceRef == sp)
             {
               if (inspos == -1)
               {
                 inspos = ap;
               }
-              annotations.remove(ap);
+              if (removeOldAnnots) {
+                annotations.remove(ap);
+              } else {
+                AlignmentAnnotation alan = annotations.get(ap);
+                alan.liftOver(sq, sp2sq);
+                alan.setSequenceRef(sq);
+              }
             }
             else
             {