Merge branch 'develop' into features/JAL-2094_colourInterface
[jalview.git] / src / MCview / PDBChain.java
index 108ccf1..67ff286 100755 (executable)
 package MCview;
 
 import jalview.analysis.AlignSeq;
+import jalview.api.ColorI;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.Annotation;
 import jalview.datamodel.Mapping;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
+import jalview.schemes.Colour;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.ResidueProperties;
+import jalview.structure.StructureImportSettings;
 import jalview.structure.StructureMapping;
-import jalview.structure.StructureViewSettings;
 
 import java.awt.Color;
 import java.util.List;
@@ -82,7 +84,7 @@ public class PDBChain
 
   public PDBChain(String pdbid, String id)
   {
-    this.pdbid = pdbid.toLowerCase();
+    this.pdbid = pdbid == null ? pdbid : pdbid.toLowerCase();
     this.id = id;
   }
 
@@ -357,18 +359,6 @@ public class PDBChain
       else
       {
 
-        // boolean baseDetected = false;
-        // for (Atom resAtom : resAtoms)
-        // {
-        // if (resAtom.insCode == ' ')
-        // {
-        // baseDetected = true;
-        // }
-        // }
-        // if (!baseDetected)
-        // {
-        // continue;
-        // }
       // Make a new Residue object with the new atoms vector
       residues.addElement(new Residue(resAtoms, resNumber - 1, count));
 
@@ -378,7 +368,6 @@ public class PDBChain
         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
@@ -394,9 +383,12 @@ public class PDBChain
                 || ResidueProperties.nucleotideIndex[nucname
                         .charAt((deoxyn ? 1 : 0))] == -1)
         {
-          seq.append("X");
-          // System.err.println("PDBReader:Null aa3Hash for " +
-          // tmpat.resName);
+            char r = ResidueProperties
+                    .getSingleCharacterCode(ResidueProperties
+                            .getCanonicalAminoAcid(tmpat.resName));
+            seq.append(r == '0' ? 'X' : r);
+            // System.err.println("PDBReader:Null aa3Hash for " +
+            // tmpat.resName);
         }
         else
         {
@@ -433,7 +425,7 @@ public class PDBChain
     // System.out.println("PDB Sequence is :\nSequence = " + seq);
     // System.out.println("No of residues = " + residues.size());
 
-    if (StructureViewSettings.isShowSeqFeatures())
+    if (StructureImportSettings.isShowSeqFeatures())
     {
     for (i = 0, iSize = resFeatures.size(); i < iSize; i++)
     {
@@ -483,26 +475,26 @@ public class PDBChain
       }
       else
       {
-        b.startCol = Color.gray;
-        b.endCol = Color.gray;
+        b.startCol = Colour.gray;
+        b.endCol = Colour.gray;
       }
     }
   }
 
-  public static Color getChargeColour(String resName)
+  public static ColorI getChargeColour(String resName)
   {
-    Color result = Color.lightGray;
+    ColorI result = Colour.lightGray;
     if ("ASP".equals(resName) || "GLU".equals(resName))
     {
-      result = Color.red;
+      result = Colour.red;
     }
     else if ("LYS".equals(resName) || "ARG".equals(resName))
     {
-      result = Color.blue;
+      result = Colour.blue;
     }
     else if ("CYS".equals(resName))
     {
-      result = Color.yellow;
+      result = Colour.yellow;
     }
     return result;
   }
@@ -522,15 +514,17 @@ public class PDBChain
       try
       {
         index = ResidueProperties.aa3Hash.get(b.at1.resName).intValue();
-        b.startCol = cs.findColour(ResidueProperties.aa[index].charAt(0));
+        b.startCol = new Colour(cs.findColour(ResidueProperties.aa[index]
+                .charAt(0)));
 
         index = ResidueProperties.aa3Hash.get(b.at2.resName).intValue();
-        b.endCol = cs.findColour(ResidueProperties.aa[index].charAt(0));
+        b.endCol = new Colour(cs.findColour(ResidueProperties.aa[index]
+                .charAt(0)));
 
       } catch (Exception e)
       {
-        b.startCol = Color.gray;
-        b.endCol = Color.gray;
+        b.startCol = Colour.gray;
+        b.endCol = Colour.gray;
       }
     }
   }
@@ -539,8 +533,8 @@ public class PDBChain
   {
     for (Bond b : bonds)
     {
-      b.startCol = col;
-      b.endCol = col;
+      b.startCol = new Colour(col);
+      b.endCol = new Colour(col);
     }
   }
 
@@ -592,12 +586,13 @@ public class PDBChain
         {
           for (AlignmentAnnotation ana : sequence.getAnnotation())
           {
-            List<AlignmentAnnotation> transfer = sq
+            List<AlignmentAnnotation> transfer = dsq
                     .getAlignmentAnnotations(ana.getCalcId(), ana.label);
             if (transfer == null || transfer.size() == 0)
             {
               ana = new AlignmentAnnotation(ana);
               ana.liftOver(dsq, sqmpping);
+              dsq.addAlignmentAnnotation(ana);
               // mapping.transfer(ana);
             }
             else