JAL-1551 format and tidy
[jalview.git] / src / jalview / structure / StructureSelectionManager.java
index c6f8f17..58bba48 100644 (file)
  */
 package jalview.structure;
 
-import java.io.*;
-import java.util.*;
-
-import MCview.*;
-import jalview.analysis.*;
-import jalview.api.AlignmentViewPanel;
+import jalview.analysis.AlignSeq;
 import jalview.api.StructureSelectionManagerProvider;
-import jalview.datamodel.*;
+import jalview.datamodel.AlignedCodonFrame;
+import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.Annotation;
+import jalview.datamodel.SearchResults;
+import jalview.datamodel.SequenceI;
+import jalview.util.MessageManager;
+
+import java.io.PrintStream;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.IdentityHashMap;
+import java.util.Vector;
+
+import MCview.Atom;
+import MCview.PDBChain;
 
 public class StructureSelectionManager
 {
@@ -56,18 +65,20 @@ public class StructureSelectionManager
   }
 
   Hashtable mappingData = new Hashtable();
+
   private static StructureSelectionManager nullProvider = null;
+
   public static StructureSelectionManager getStructureSelectionManager(
           StructureSelectionManagerProvider context)
   {
-    if (context==null) { 
+    if (context == null)
+    {
       if (nullProvider == null)
       {
         if (instances != null)
         {
-          throw new Error(
-                  "Implementation error. Structure selection manager's context is 'null'",
-                  new NullPointerException("SSM context is null"));
+          throw new Error(MessageManager.getString("error.implementation_error_structure_selection_manager_null"),
+                  new NullPointerException(MessageManager.getString("exception.ssm_context_is_null")));
         }
         else
         {
@@ -83,10 +94,12 @@ public class StructureSelectionManager
     StructureSelectionManager instance = instances.get(context);
     if (instance == null)
     {
-      if (nullProvider!=null)
+      if (nullProvider != null)
       {
         instance = nullProvider;
-      } else {
+      }
+      else
+      {
         instance = new StructureSelectionManager();
       }
       instances.put(context, instance);
@@ -176,9 +189,26 @@ public class StructureSelectionManager
      * the tried and tested MCview pdb mapping
      */
     MCview.PDBfile pdb = null;
+    boolean parseSecStr=true;
+    for (SequenceI sq:sequence)
+    {
+      SequenceI ds = sq;while (ds.getDatasetSequence()!=null) { ds = ds.getDatasetSequence();};
+      if (ds.getAnnotation()!=null)
+      {
+        for (AlignmentAnnotation ala:ds.getAnnotation())
+        {
+          // false if any annotation present from this structure
+          if (MCview.PDBfile.isCalcIdForFile(ala.getCalcId(), pdbFile))
+          {
+            parseSecStr = false;
+          }
+        }
+      }
+    }
     try
     {
-      pdb = new MCview.PDBfile(pdbFile, protocol);
+      pdb = new MCview.PDBfile(true, parseSecStr, pdbFile, protocol);
+      
     } catch (Exception ex)
     {
       ex.printStackTrace();
@@ -212,7 +242,9 @@ public class StructureSelectionManager
         }
       }
       else
+      {
         targetChain = "";
+      }
 
       int max = -10;
       AlignSeq maxAlignseq = null;
@@ -221,7 +253,7 @@ public class StructureSelectionManager
       boolean first = true;
       for (int i = 0; i < pdb.chains.size(); i++)
       {
-        PDBChain chain = ((PDBChain) pdb.chains.elementAt(i));
+        PDBChain chain = (pdb.chains.elementAt(i));
         if (targetChain.length() > 0 && !targetChain.equals(chain.id)
                 && !infChain)
         {
@@ -230,8 +262,8 @@ public class StructureSelectionManager
         // TODO: correctly determine sequence type for mixed na/peptide
         // structures
         AlignSeq as = new AlignSeq(sequence[s],
-                ((PDBChain) pdb.chains.elementAt(i)).sequence,
-                ((PDBChain) pdb.chains.elementAt(i)).isNa ? AlignSeq.DNA
+                pdb.chains.elementAt(i).sequence,
+                pdb.chains.elementAt(i).isNa ? AlignSeq.DNA
                         : AlignSeq.PEP);
         as.calcScoreMatrix();
         as.traceAlignment();
@@ -312,7 +344,9 @@ public class StructureSelectionManager
       }
 
       if (protocol.equals(jalview.io.AppletFormatAdapter.PASTE))
+      {
         pdbFile = "INLINE" + pdb.id;
+      }
 
       mappings[mappings.length - 1] = new StructureMapping(sequence[s],
               pdbFile, pdb.id, maxChainId, mapping,
@@ -347,7 +381,9 @@ public class StructureSelectionManager
     String[] handlepdbs;
     Vector pdbs = new Vector();
     for (int i = 0; i < pdbfiles.length; pdbs.addElement(pdbfiles[i++]))
+    {
       ;
+    }
     StructureListener sl;
     for (int i = 0; i < listeners.size(); i++)
     {
@@ -439,7 +475,9 @@ public class StructureSelectionManager
       {
         Object li = listeners.elementAt(i);
         if (li instanceof SequenceListener)
+        {
           ((SequenceListener) li).highlightSequence(results);
+        }
       }
     }
   }
@@ -463,7 +501,9 @@ public class StructureSelectionManager
     boolean hasSequenceListeners = handlingVamsasMo || seqmappings != null;
     SearchResults results = null;
     if (index == -1)
+    {
       index = seq.findPosition(indexpos);
+    }
     StructureListener sl;
     int atomNo = 0;
     for (int i = 0; i < listeners.size(); i++)
@@ -681,9 +721,13 @@ public class StructureSelectionManager
           AlignedCodonFrame[] codonFrames)
   {
     if (!add && (seqmappings == null || seqmappings.size() == 0))
+    {
       return;
+    }
     if (seqmappings == null)
+    {
       seqmappings = new Vector();
+    }
     if (codonFrames != null && codonFrames.length > 0)
     {
       for (int cf = 0; cf < codonFrames.length; cf++)
@@ -721,8 +765,10 @@ public class StructureSelectionManager
             int[] nsr = new int[(seqmappingrefs == null) ? 1
                     : seqmappingrefs.length + 1];
             if (seqmappingrefs != null && seqmappingrefs.length > 0)
+            {
               System.arraycopy(seqmappingrefs, 0, nsr, 0,
                       seqmappingrefs.length);
+            }
             nsr[(seqmappingrefs == null) ? 0 : seqmappingrefs.length] = 1;
             seqmappingrefs = nsr;
           }