JAL-1620 version bump and release notes
[jalview.git] / src / jalview / structure / StructureSelectionManager.java
index 449e133..e9aa575 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2b1)
  * Copyright (C) 2014 The Jalview Authors
  * 
  * This file is part of Jalview.
@@ -28,7 +28,7 @@ import jalview.datamodel.Annotation;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SearchResults;
 import jalview.datamodel.SequenceI;
-import jalview.io.FormatAdapter;
+import jalview.io.AppletFormatAdapter;
 import jalview.util.MessageManager;
 
 import java.io.PrintStream;
@@ -46,6 +46,70 @@ public class StructureSelectionManager
 
   StructureMapping[] mappings;
 
+  private boolean processSecondaryStructure = false,
+          secStructServices = false, addTempFacAnnot = false;
+
+  /**
+   * @return true if will try to use external services for processing secondary
+   *         structure
+   */
+  public boolean isSecStructServices()
+  {
+    return secStructServices;
+  }
+
+  /**
+   * control use of external services for processing secondary structure
+   * 
+   * @param secStructServices
+   */
+  public void setSecStructServices(boolean secStructServices)
+  {
+    this.secStructServices = secStructServices;
+  }
+
+  /**
+   * flag controlling addition of any kind of structural annotation
+   * 
+   * @return true if temperature factor annotation will be added
+   */
+  public boolean isAddTempFacAnnot()
+  {
+    return addTempFacAnnot;
+  }
+
+  /**
+   * set flag controlling addition of structural annotation
+   * 
+   * @param addTempFacAnnot
+   */
+  public void setAddTempFacAnnot(boolean addTempFacAnnot)
+  {
+    this.addTempFacAnnot = addTempFacAnnot;
+  }
+
+  /**
+   * 
+   * @return if true, the structure manager will attempt to add secondary
+   *         structure lines for unannotated sequences
+   */
+
+  public boolean isProcessSecondaryStructure()
+  {
+    return processSecondaryStructure;
+  }
+
+  /**
+   * Control whether structure manager will try to annotate mapped sequences
+   * with secondary structure from PDB data.
+   * 
+   * @param enable
+   */
+  public void setProcessSecondaryStructure(boolean enable)
+  {
+    processSecondaryStructure = enable;
+  }
+
   /**
    * debug function - write all mappings to stdout
    */
@@ -245,26 +309,42 @@ public class StructureSelectionManager
      * the tried and tested MCview pdb mapping
      */
     MCview.PDBfile pdb = null;
-    boolean parseSecStr=true;
-    for (SequenceI sq:sequence)
+    boolean parseSecStr = processSecondaryStructure;
+    if (isPDBFileRegistered(pdbFile))
     {
-      SequenceI ds = sq;while (ds.getDatasetSequence()!=null) { ds = ds.getDatasetSequence();};
-      if (ds.getAnnotation()!=null)
+      for (SequenceI sq : sequence)
       {
-        for (AlignmentAnnotation ala:ds.getAnnotation())
+        SequenceI ds = sq;
+        while (ds.getDatasetSequence() != null)
+        {
+          ds = ds.getDatasetSequence();
+        }
+        ;
+        if (ds.getAnnotation() != null)
         {
-          // false if any annotation present from this structure
-          if (MCview.PDBfile.isCalcIdForFile(ala.getCalcId(), pdbFile))
+          for (AlignmentAnnotation ala : ds.getAnnotation())
           {
-            parseSecStr = false;
+            // false if any annotation present from this structure
+            // JBPNote this fails for jmol/chimera view because the *file* is
+            // passed, not the structure data ID -
+            if (MCview.PDBfile.isCalcIdForFile(ala,
+                    findIdForPDBFile(pdbFile)))
+            {
+              parseSecStr = false;
+            }
           }
         }
       }
     }
     try
     {
-      pdb = new MCview.PDBfile(true, parseSecStr, pdbFile, protocol);
-      
+      pdb = new MCview.PDBfile(addTempFacAnnot, parseSecStr,
+              secStructServices, pdbFile, protocol);
+      if (pdb.id != null && pdb.id.trim().length() > 0
+              && AppletFormatAdapter.FILE.equals(protocol))
+      {
+        registerPDBFile(pdb.id.trim(), pdbFile);
+      }
     } catch (Exception ex)
     {
       ex.printStackTrace();
@@ -345,11 +425,13 @@ public class StructureSelectionManager
               + maxChain.residues.size() + "\n\n");
       PrintStream ps = new PrintStream(System.out)
       {
+        @Override
         public void print(String x)
         {
           mappingDetails.append(x);
         }
 
+        @Override
         public void println()
         {
           mappingDetails.append("\n");
@@ -365,7 +447,10 @@ public class StructureSelectionManager
               + (maxAlignseq.seq1end + sequence[s].getEnd() - 1));
 
       maxChain.makeExactMapping(maxAlignseq, sequence[s]);
-
+      jalview.datamodel.Mapping sqmpping = maxAlignseq
+              .getMappingFromS1(false);
+      jalview.datamodel.Mapping omap = new jalview.datamodel.Mapping(
+              sqmpping.getMap().getInverse());
       maxChain.transferRESNUMFeatures(sequence[s], null);
 
       // allocate enough slots to store the mapping from positions in
@@ -411,7 +496,7 @@ public class StructureSelectionManager
 
         mappings[mappings.length - 1] = newMapping;
       }
-      maxChain.transferResidueAnnotation(newMapping);
+      maxChain.transferResidueAnnotation(newMapping, sqmpping);
     }
     // ///////
 
@@ -437,7 +522,6 @@ public class StructureSelectionManager
     {
       return;
     }
-    boolean removeMapping = true;
     String[] handlepdbs;
     Vector pdbs = new Vector();
     for (int i = 0; i < pdbfiles.length; pdbs.addElement(pdbfiles[i++]))