licencing and format applied (eclipse)
[jalview.git] / src / MCview / PDBChain.java
index 8dea416..c1c586a 100755 (executable)
@@ -33,19 +33,33 @@ public class PDBChain
    * SequenceFeature group for PDB File features added to sequences
    */
   private static final String PDBFILEFEATURE = "PDBFile";
+
   private static final String IEASTATUS = "IEA:jalview";
+
   public String id;
+
   public Vector bonds = new Vector();
+
   public Vector atoms = new Vector();
+
   public Vector residues = new Vector();
+
   public int offset;
+
   public Sequence sequence;
+
   public boolean isVisible = true;
+
   public int pdbstart = 0;
+
   public int pdbend = 0;
+
   public int seqstart = 0;
+
   public int seqend = 0;
+
   public String pdbid = "";
+
   public PDBChain(String pdbid, String id)
   {
     this.pdbid = pdbid.toLowerCase();
@@ -58,9 +72,9 @@ public class PDBChain
 
     for (int i = 0; i < bonds.size(); i++)
     {
-      tmp = tmp + ( (Bond) bonds.elementAt(i)).at1.resName + " " +
-          ( (Bond) bonds.elementAt(i)).at1.resNumber + " " + offset +
-          "\n";
+      tmp = tmp + ((Bond) bonds.elementAt(i)).at1.resName + " "
+              + ((Bond) bonds.elementAt(i)).at1.resNumber + " " + offset
+              + "\n";
     }
 
     return tmp;
@@ -95,16 +109,21 @@ public class PDBChain
       }
     }
   }
+
   /**
-   * copy over the RESNUM seqfeatures from the internal chain sequence to the mapped sequence
+   * copy over the RESNUM seqfeatures from the internal chain sequence to the
+   * mapped sequence
+   * 
    * @param seq
-   * @param status The Status of the transferred annotation
+   * @param status
+   *                The Status of the transferred annotation
    * @return the features added to sq (or its dataset)
    */
-  public SequenceFeature[] transferRESNUMFeatures(SequenceI seq, String status)
+  public SequenceFeature[] transferRESNUMFeatures(SequenceI seq,
+          String status)
   {
     SequenceI sq = seq;
-    while (sq!=null && sq.getDatasetSequence()!=null)
+    while (sq != null && sq.getDatasetSequence() != null)
     {
       sq = sq.getDatasetSequence();
       if (sq == sequence)
@@ -114,11 +133,10 @@ public class PDBChain
     }
     /**
      * Remove any existing features for this chain if they exist ?
-     * SequenceFeature[] seqsfeatures=seq.getSequenceFeatures();
-        int totfeat=seqsfeatures.length;
-        // Remove any features for this exact chain ?
-        for (int i=0; i<seqsfeatures.length; i++) {
-        } */
+     * SequenceFeature[] seqsfeatures=seq.getSequenceFeatures(); int
+     * totfeat=seqsfeatures.length; // Remove any features for this exact chain ?
+     * for (int i=0; i<seqsfeatures.length; i++) { }
+     */
     if (status == null)
     {
       status = PDBChain.IEASTATUS;
@@ -129,16 +147,15 @@ public class PDBChain
       if (features[i].getFeatureGroup().equals(pdbid))
       {
         SequenceFeature tx = new SequenceFeature(features[i]);
-        tx.setBegin(1 +
-                    ( (Atom) ( (Residue) residues.elementAt(tx.getBegin() - offset)).
-                     atoms.elementAt(0)).alignmentMapping);
-        tx.setEnd(1 +
-                  ( (Atom) ( (Residue) residues.elementAt(tx.getEnd() - offset)).
-                   atoms.elementAt(0)).alignmentMapping);
-        tx.setStatus(status +
-                     ( (tx.getStatus() == null || tx.getStatus().length() == 0) ?
-                      "" : ":" + tx.getStatus()));
-        if (tx.begin!=0 && tx.end!=0)
+        tx.setBegin(1 + ((Atom) ((Residue) residues.elementAt(tx.getBegin()
+                - offset)).atoms.elementAt(0)).alignmentMapping);
+        tx.setEnd(1 + ((Atom) ((Residue) residues.elementAt(tx.getEnd()
+                - offset)).atoms.elementAt(0)).alignmentMapping);
+        tx
+                .setStatus(status
+                        + ((tx.getStatus() == null || tx.getStatus()
+                                .length() == 0) ? "" : ":" + tx.getStatus()));
+        if (tx.begin != 0 && tx.end != 0)
           sq.addSequenceFeature(tx);
       }
     }
@@ -154,7 +171,7 @@ public class PDBChain
       Atom at1 = tmpres.findAtom("CA");
       Atom at2 = tmpres2.findAtom("CA");
 
-      if ( (at1 != null) && (at2 != null))
+      if ((at1 != null) && (at2 != null))
       {
         if (at1.chain.equals(at2.chain))
         {
@@ -204,16 +221,16 @@ public class PDBChain
       }
 
       Vector resAtoms = new Vector();
-      //Add atoms to a vector while the residue number
-      //remains the same as the first atom's resNumber (res)
-      while ( (resNumber == res) && (i < atoms.size()))
+      // Add atoms to a vector while the residue number
+      // remains the same as the first atom's resNumber (res)
+      while ((resNumber == res) && (i < atoms.size()))
       {
-        resAtoms.addElement( (Atom) atoms.elementAt(i));
+        resAtoms.addElement((Atom) atoms.elementAt(i));
         i++;
 
         if (i < atoms.size())
         {
-          resNumber = ( (Atom) atoms.elementAt(i)).resNumber;
+          resNumber = ((Atom) atoms.elementAt(i)).resNumber;
         }
         else
         {
@@ -221,38 +238,34 @@ public class PDBChain
         }
       }
 
-      //We need this to keep in step with the outer for i = loop
+      // We need this to keep in step with the outer for i = loop
       i--;
 
-      //Make a new Residue object with the new atoms vector
+      // Make a new Residue object with the new atoms vector
       residues.addElement(new Residue(resAtoms, resNumber - 1, count));
 
       Residue tmpres = (Residue) residues.lastElement();
       Atom tmpat = (Atom) tmpres.atoms.elementAt(0);
       // Make A new SequenceFeature for the current residue numbering
-      SequenceFeature sf =
-          new SequenceFeature("RESNUM",
-                              tmpat.resName + ":" + tmpat.resNumIns + " " +
-                              pdbid + id,
-                              "", offset + count, offset + count,
-                              pdbid);
-
-      //MCview.PDBChain.PDBFILEFEATURE);
+      SequenceFeature sf = new SequenceFeature("RESNUM", tmpat.resName
+              + ":" + tmpat.resNumIns + " " + pdbid + id, "", offset
+              + count, offset + count, pdbid);
+
+      // MCview.PDBChain.PDBFILEFEATURE);
       resFeatures.addElement(sf);
       resAnnotation.addElement(new Annotation(tmpat.tfactor));
       // Keep totting up the sequence
       if (ResidueProperties.getAA3Hash().get(tmpat.resName) == null)
       {
         seq.append("X");
-        //  System.err.println("PDBReader:Null aa3Hash for " +
-        //     tmpat.resName);
+        // System.err.println("PDBReader:Null aa3Hash for " +
+        // tmpat.resName);
       }
       else
       {
 
-        seq.append(ResidueProperties.aa[ ( (Integer) ResidueProperties.
-                                          getAA3Hash()
-                                          .get(tmpat.resName)).intValue()]);
+        seq.append(ResidueProperties.aa[((Integer) ResidueProperties
+                .getAA3Hash().get(tmpat.resName)).intValue()]);
       }
       count++;
     }
@@ -262,25 +275,31 @@ public class PDBChain
       id = " ";
     }
 
-    sequence = new Sequence(id, seq.toString(), offset, resNumber - 1); // Note: resNumber-offset ~= seq.size()
-    //  System.out.println("PDB Sequence is :\nSequence = " + seq);
-    //   System.out.println("No of residues = " + residues.size());
+    sequence = new Sequence(id, seq.toString(), offset, resNumber - 1); // Note:
+                                                                        // resNumber-offset
+                                                                        // ~=
+                                                                        // seq.size()
+    // System.out.println("PDB Sequence is :\nSequence = " + seq);
+    // System.out.println("No of residues = " + residues.size());
     for (i = 0, iSize = resFeatures.size(); i < iSize; i++)
     {
-      sequence.addSequenceFeature( (SequenceFeature) resFeatures.elementAt(i));
+      sequence.addSequenceFeature((SequenceFeature) resFeatures
+              .elementAt(i));
       resFeatures.setElementAt(null, i);
     }
     Annotation[] annots = new Annotation[resAnnotation.size()];
-    float max=0;
-    for (i=0,iSize=annots.length; i<iSize; i++)
+    float max = 0;
+    for (i = 0, iSize = annots.length; i < iSize; i++)
     {
       annots[i] = (Annotation) resAnnotation.elementAt(i);
-      if (annots[i].value>max)
+      if (annots[i].value > max)
         max = annots[i].value;
       resAnnotation.setElementAt(null, i);
     }
-    AlignmentAnnotation tfactorann = new AlignmentAnnotation("PDB.CATempFactor","CA Temperature Factor for "+sequence.getName(),
-            annots, 0, max, AlignmentAnnotation.LINE_GRAPH);
+    AlignmentAnnotation tfactorann = new AlignmentAnnotation(
+            "PDB.CATempFactor", "CA Temperature Factor for "
+                    + sequence.getName(), annots, 0, max,
+            AlignmentAnnotation.LINE_GRAPH);
     tfactorann.setSequenceRef(sequence);
     sequence.addAlignmentAnnotation(tfactorann);
   }
@@ -293,13 +312,13 @@ public class PDBChain
       {
         Bond b = (Bond) bonds.elementAt(i);
 
-        if (b.at1.resName.equalsIgnoreCase("ASP") ||
-            b.at1.resName.equalsIgnoreCase("GLU"))
+        if (b.at1.resName.equalsIgnoreCase("ASP")
+                || b.at1.resName.equalsIgnoreCase("GLU"))
         {
           b.startCol = Color.red;
         }
-        else if (b.at1.resName.equalsIgnoreCase("LYS") ||
-                 b.at1.resName.equalsIgnoreCase("ARG"))
+        else if (b.at1.resName.equalsIgnoreCase("LYS")
+                || b.at1.resName.equalsIgnoreCase("ARG"))
         {
           b.startCol = Color.blue;
         }
@@ -312,13 +331,13 @@ public class PDBChain
           b.startCol = Color.lightGray;
         }
 
-        if (b.at2.resName.equalsIgnoreCase("ASP") ||
-            b.at2.resName.equalsIgnoreCase("GLU"))
+        if (b.at2.resName.equalsIgnoreCase("ASP")
+                || b.at2.resName.equalsIgnoreCase("GLU"))
         {
           b.endCol = Color.red;
         }
-        else if (b.at2.resName.equalsIgnoreCase("LYS") ||
-                 b.at2.resName.equalsIgnoreCase("ARG"))
+        else if (b.at2.resName.equalsIgnoreCase("LYS")
+                || b.at2.resName.equalsIgnoreCase("ARG"))
         {
           b.endCol = Color.blue;
         }
@@ -330,8 +349,7 @@ public class PDBChain
         {
           b.endCol = Color.lightGray;
         }
-      }
-      catch (Exception e)
+      } catch (Exception e)
       {
         Bond b = (Bond) bonds.elementAt(i);
         b.startCol = Color.gray;
@@ -350,16 +368,15 @@ public class PDBChain
       {
         b = (Bond) bonds.elementAt(i);
 
-        index = ( (Integer) ResidueProperties.aa3Hash.get(b.at1.
-            resName)).intValue();
+        index = ((Integer) ResidueProperties.aa3Hash.get(b.at1.resName))
+                .intValue();
         b.startCol = cs.findColour(ResidueProperties.aa[index].charAt(0));
 
-        index = ( (Integer) ResidueProperties.aa3Hash.get(b.at2.resName)).
-            intValue();
+        index = ((Integer) ResidueProperties.aa3Hash.get(b.at2.resName))
+                .intValue();
         b.endCol = cs.findColour(ResidueProperties.aa[index].charAt(0));
 
-      }
-      catch (Exception e)
+      } catch (Exception e)
       {
         b = (Bond) bonds.elementAt(i);
         b.startCol = Color.gray;
@@ -378,7 +395,8 @@ public class PDBChain
     }
   }
 
-  public AlignmentAnnotation[] transferResidueAnnotation(SequenceI seq, String status)
+  public AlignmentAnnotation[] transferResidueAnnotation(SequenceI seq,
+          String status)
   {
     AlignmentAnnotation[] transferred = null;
 
@@ -387,41 +405,49 @@ public class PDBChain
   }
 
   /**
-   * copy any sequence annotation onto the sequence mapped using the provided StructureMapping
+   * copy any sequence annotation onto the sequence mapped using the provided
+   * StructureMapping
+   * 
    * @param mapping
    */
   public void transferResidueAnnotation(StructureMapping mapping)
   {
     SequenceI sq = mapping.getSequence();
-    if (sq!=null)
+    if (sq != null)
     {
-      if (sequence!=null && sequence.getAnnotation()!=null)
+      if (sequence != null && sequence.getAnnotation() != null)
       {
 
       }
-      float min=-1,max=0;
-      Annotation[] an=new Annotation[sq.getEnd()-sq.getStart()+1];
-      for (int i=sq.getStart(),j=sq.getEnd(),k=0; i<=j; i++,k++)
+      float min = -1, max = 0;
+      Annotation[] an = new Annotation[sq.getEnd() - sq.getStart() + 1];
+      for (int i = sq.getStart(), j = sq.getEnd(), k = 0; i <= j; i++, k++)
       {
-        int prn = mapping.getPDBResNum(k+1);
+        int prn = mapping.getPDBResNum(k + 1);
 
-        an[k] = new Annotation((float)prn);
-        if (min==-1)
+        an[k] = new Annotation((float) prn);
+        if (min == -1)
         {
-          min=k;
-          max=k;
-        } else {
-          if (min>k)
+          min = k;
+          max = k;
+        }
+        else
+        {
+          if (min > k)
+          {
+            min = k;
+          }
+          else if (max < k)
           {
-            min=k;
-          } else
-            if (max<k)
-            {
-              max=k;
-            }
+            max = k;
+          }
         }
       }
-      sq.addAlignmentAnnotation(new AlignmentAnnotation("PDB.RESNUM", "PDB Residue Numbering for "+this.pdbid+":"+this.id, an, (float)min,(float)max, AlignmentAnnotation.LINE_GRAPH));
+      sq
+              .addAlignmentAnnotation(new AlignmentAnnotation("PDB.RESNUM",
+                      "PDB Residue Numbering for " + this.pdbid + ":"
+                              + this.id, an, (float) min, (float) max,
+                      AlignmentAnnotation.LINE_GRAPH));
     }
   }
 }