Readjustments
[jalview.git] / src / MCview / PDBChain.java
index 208ecd0..5f23a26 100755 (executable)
@@ -25,6 +25,7 @@ import jalview.schemes.ResidueProperties;
 import java.awt.*;\r
 \r
 import java.util.*;\r
+import jalview.analysis.AlignSeq;\r
 \r
 \r
 public class PDBChain {\r
@@ -34,13 +35,12 @@ public class PDBChain {
     public Vector residues = new Vector();\r
     public int offset;\r
     public Sequence sequence;\r
-    public boolean isVisible = false;\r
+    public boolean isVisible = true;\r
     public int pdbstart = 0;\r
     public int pdbend = 0;\r
     public int seqstart = 0;\r
     public int seqend = 0;\r
 \r
-    //public DrawableSequence ds;\r
     public PDBChain(String id) {\r
         this.id = id;\r
     }\r
@@ -57,22 +57,60 @@ public class PDBChain {
         return tmp;\r
     }\r
 \r
-    public void makeCaBondList() {\r
-        for (int i = 0; i < (residues.size() - 1); i++) {\r
+    void makeExactMapping(AlignSeq as, Sequence s1)\r
+    {\r
+        int pdbpos =   as.getSeq2Start()-2;\r
+        int alignpos = s1.getStart() + as.getSeq1Start()-3;\r
+\r
+        for(int i=0; i<as.astr1.length(); i++)\r
+        {\r
+            if (as.astr1.charAt(i) != '-')\r
+            {\r
+              alignpos++;\r
+            }\r
+\r
+            if (as.astr2.charAt(i) != '-')\r
+            {\r
+              pdbpos++;\r
+            }\r
+\r
+            if (as.astr1.charAt(i) == as.astr2.charAt(i))\r
+            {\r
+                Residue res = (Residue) residues.elementAt(pdbpos);\r
+                Enumeration en = res.atoms.elements();\r
+                while (en.hasMoreElements())\r
+                {\r
+                  Atom atom = (Atom) en.nextElement();\r
+                  atom.alignmentMapping = alignpos;\r
+                }\r
+            }\r
+        }\r
+\r
+    }\r
+\r
+\r
+    public void makeCaBondList()\r
+    {\r
+        for (int i = 0; i < (residues.size() - 1); i++)\r
+        {\r
             Residue tmpres = (Residue) residues.elementAt(i);\r
             Residue tmpres2 = (Residue) residues.elementAt(i + 1);\r
-            myAtom at1 = tmpres.findAtom("CA");\r
-            myAtom at2 = tmpres2.findAtom("CA");\r
+            Atom at1 = tmpres.findAtom("CA");\r
+            Atom at2 = tmpres2.findAtom("CA");\r
 \r
-            if ((at1 != null) && (at2 != null)) {\r
-                if (at1.chain.equals(at2.chain)) {\r
+            if ((at1 != null) && (at2 != null))\r
+            {\r
+                if (at1.chain.equals(at2.chain))\r
+                {\r
                     makeBond(at1, at2);\r
                 }\r
             }\r
+            else\r
+              System.out.println("not found "+i);\r
         }\r
     }\r
 \r
-    public void makeBond(myAtom at1, myAtom at2) {\r
+    public void makeBond(Atom at1, Atom at2) {\r
         float[] start = new float[3];\r
         float[] end = new float[3];\r
 \r
@@ -89,11 +127,12 @@ public class PDBChain {
 \r
     public void makeResidueList() {\r
         int count = 0;\r
-        String seq = "";\r
+        StringBuffer seq = new StringBuffer();\r
 \r
-        for (int i = 0; i < atoms.size(); i++) {\r
-            myAtom tmp = (myAtom) atoms.elementAt(i);\r
-            //String resName = tmp.resName;\r
+        int i, iSize = atoms.size()-1;\r
+        for (i = 0; i < iSize; i++)\r
+        {\r
+            Atom tmp = (Atom) atoms.elementAt(i);\r
             int resNumber = tmp.resNumber;\r
             int res = resNumber;\r
 \r
@@ -103,18 +142,18 @@ public class PDBChain {
 \r
             Vector resAtoms = new Vector();\r
 \r
-            resAtoms.addElement((myAtom) atoms.elementAt(i));\r
+            resAtoms.addElement((Atom) atoms.elementAt(i));\r
             i++;\r
-            resNumber = ((myAtom) atoms.elementAt(i)).resNumber;\r
+            resNumber = ((Atom) atoms.elementAt(i)).resNumber;\r
 \r
             //Add atoms to a vector while the residue number\r
             //remains the same\r
             while ((resNumber == res) && (i < atoms.size())) {\r
-                resAtoms.addElement((myAtom) atoms.elementAt(i));\r
+                resAtoms.addElement((Atom) atoms.elementAt(i));\r
                 i++;\r
 \r
                 if (i < atoms.size()) {\r
-                    resNumber = ((myAtom) atoms.elementAt(i)).resNumber;\r
+                    resNumber = ((Atom) atoms.elementAt(i)).resNumber;\r
                 } else {\r
                     resNumber++;\r
                 }\r
@@ -128,22 +167,26 @@ public class PDBChain {
             count++;\r
 \r
             Residue tmpres = (Residue) residues.lastElement();\r
-            myAtom tmpat = (myAtom) tmpres.atoms.elementAt(0);\r
+            Atom tmpat = (Atom) tmpres.atoms.elementAt(0);\r
 \r
             // Keep totting up the sequence\r
-            if (ResidueProperties.getAA3Hash().get(tmpat.resName) == null) {\r
-                System.err.println("PDBReader:Null aa3Hash for " +\r
-                    tmpat.resName);\r
+            if (ResidueProperties.getAA3Hash().get(tmpat.resName) == null)\r
+            {\r
+                seq.append("X") ;\r
+               //  System.err.println("PDBReader:Null aa3Hash for " +\r
+               //     tmpat.resName);\r
             } else {\r
-                String tmpres2 = ResidueProperties.aa[((Integer) ResidueProperties.getAA3Hash()\r
-                                                                                  .get(tmpat.resName)).intValue()];\r
-                seq = seq + tmpres2;\r
-            }\r
 \r
+                seq.append(ResidueProperties.aa[((Integer) ResidueProperties.getAA3Hash()\r
+                                                                                  .get(tmpat.resName)).intValue()]);\r
+            }\r
         }\r
 \r
-        sequence = new Sequence("PDB_seq", seq, 1, seq.length());\r
-     //   System.out.println("PDB Sequence is :\nSequence = " + seq);\r
+        if(id.length()<1 || id.equals(" "))\r
+           id = "_";\r
+\r
+        sequence = new Sequence(id, seq.toString(), 1, seq.length());\r
+      //  System.out.println("PDB Sequence is :\nSequence = " + seq);\r
      //   System.out.println("No of residues = " + residues.size());\r
     }\r
 \r
@@ -231,17 +274,13 @@ public class PDBChain {
 \r
 \r
 \r
-    public void setChainColours() {\r
-        for (int i = 0; i < bonds.size(); i++) {\r
+    public void setChainColours(Color col)\r
+    {\r
+        for (int i = 0; i < bonds.size(); i++)\r
+        {\r
             Bond tmp = (Bond) bonds.elementAt(i);\r
-\r
-            try {\r
-                tmp.startCol = (Color) ResidueProperties.getChainColours().get(id);\r
-                tmp.endCol = (Color) ResidueProperties.getChainColours().get(id);\r
-            } catch (Exception e) {\r
-                tmp.startCol = Color.lightGray;\r
-                tmp.endCol = Color.lightGray;\r
-            }\r
+            tmp.startCol = col;\r
+            tmp.endCol = col;\r
         }\r
     }\r
 }\r