mearge with develop
[jalview.git] / src / MCview / PDBfile.java
index a99f172..b22eb29 100755 (executable)
@@ -33,11 +33,12 @@ import java.awt.Color;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Hashtable;
+import java.util.List;
 import java.util.Vector;
 
 public class PDBfile extends jalview.io.AlignFile
 {
-  public Vector chains;
+  public Vector<PDBChain> chains;
 
   public String id;
 
@@ -181,15 +182,15 @@ public class PDBfile extends jalview.io.AlignFile
       }
       for (int i = 0; i < chains.size(); i++)
       {
-        SequenceI dataset = ((PDBChain) chains.elementAt(i)).sequence;
+        SequenceI dataset = chains.elementAt(i).sequence;
         dataset.setName(id + "|" + dataset.getName());
         PDBEntry entry = new PDBEntry();
         entry.setId(id);
         entry.setProperty(new Hashtable());
-        if (((PDBChain) chains.elementAt(i)).id != null)
+        if (chains.elementAt(i).id != null)
         {
           entry.getProperty().put("CHAIN",
-                  ((PDBChain) chains.elementAt(i)).id);
+                  chains.elementAt(i).id);
         }
         if (inFile != null)
         {
@@ -272,19 +273,19 @@ public class PDBfile extends jalview.io.AlignFile
     markCalcIds();
   }
 
-  private static String calcIdPrefix = "JalviewPDB:";
+  private static String calcIdPrefix = "JalviewPDB";
 
   public static boolean isCalcIdHandled(String calcId)
   {
     return calcId != null
-            && (calcId.startsWith(calcIdPrefix) && calcId.indexOf(
-                    calcIdPrefix,
-            calcIdPrefix.length() + 1) > -1);
+ && (calcIdPrefix.equals(calcId));
   }
-  public static boolean isCalcIdForFile(String calcId, String pdbFile)
+
+  public static boolean isCalcIdForFile(AlignmentAnnotation alan, String pdbFile)
   {
-    return (calcId != null && calcId.startsWith(calcIdPrefix + pdbFile
-            + ":" + calcIdPrefix));
+    return alan.getCalcId() != null
+            && calcIdPrefix.equals(alan.getCalcId())
+            && pdbFile.equals(alan.getProperty("PDBID"));
   }
 
   public static String relocateCalcId(String calcId,
@@ -307,7 +308,9 @@ public class PDBfile extends jalview.io.AlignFile
         {
           oldId = "";
         }
-        aa.setCalcId("JalviewPDB:" + id + ":JalviewPDB:" + oldId);
+        aa.setCalcId(calcIdPrefix);
+        aa.setProperty("PDBID", id);
+        aa.setProperty("oldCalcId", oldId);
       }
     }
   }
@@ -338,13 +341,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
   {
@@ -370,14 +403,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)
     {
@@ -406,7 +445,7 @@ public class PDBfile extends jalview.io.AlignFile
   {
     for (int i = 0; i < chains.size(); i++)
     {
-      ((PDBChain) chains.elementAt(i)).makeResidueList();
+      chains.elementAt(i).makeResidueList();
     }
   }
 
@@ -414,7 +453,7 @@ public class PDBfile extends jalview.io.AlignFile
   {
     for (int i = 0; i < chains.size(); i++)
     {
-      ((PDBChain) chains.elementAt(i)).makeCaBondList();
+      chains.elementAt(i).makeCaBondList();
     }
   }
 
@@ -422,9 +461,9 @@ public class PDBfile extends jalview.io.AlignFile
   {
     for (int i = 0; i < chains.size(); i++)
     {
-      if (((PDBChain) chains.elementAt(i)).id.equals(id))
+      if (chains.elementAt(i).id.equals(id))
       {
-        return (PDBChain) chains.elementAt(i);
+        return chains.elementAt(i);
       }
     }
 
@@ -435,7 +474,7 @@ public class PDBfile extends jalview.io.AlignFile
   {
     for (int i = 0; i < chains.size(); i++)
     {
-      ((PDBChain) chains.elementAt(i)).setChargeColours();
+      chains.elementAt(i).setChargeColours();
     }
   }
 
@@ -443,7 +482,7 @@ public class PDBfile extends jalview.io.AlignFile
   {
     for (int i = 0; i < chains.size(); i++)
     {
-      ((PDBChain) chains.elementAt(i)).setChainColours(cs);
+      chains.elementAt(i).setChainColours(cs);
     }
   }
 
@@ -451,7 +490,7 @@ public class PDBfile extends jalview.io.AlignFile
   {
     for (int i = 0; i < chains.size(); i++)
     {
-      ((PDBChain) chains.elementAt(i)).setChainColours(Color.getHSBColor(
+      chains.elementAt(i).setChainColours(Color.getHSBColor(
               1.0f / i, .4f, 1.0f));
     }
   }