JAL-1479 added transfer of residue annotation for SIFTS mapping, then did some minor...
[jalview.git] / src / jalview / structure / StructureSelectionManager.java
index 3d5a975..1541a6a 100644 (file)
@@ -328,7 +328,7 @@ public class StructureSelectionManager
    * 
    * @param sequenceArray
    *          - one or more sequences to be mapped to pdbFile
-   * @param targetChains
+   * @param targetChainIds
    *          - optional chain specification for mapping each sequence to pdb
    *          (may be nill, individual elements may be nill)
    * @param pdbFile
@@ -338,7 +338,8 @@ public class StructureSelectionManager
    * @return null or the structure data parsed as a pdb file
    */
   synchronized public PDBfile setMapping(boolean forStructureView,
-          SequenceI[] sequenceArray, String[] targetChains, String pdbFile,
+          SequenceI[] sequenceArray, String[] targetChainIds,
+          String pdbFile,
           String protocol)
   {
     /*
@@ -379,54 +380,60 @@ public class StructureSelectionManager
     {
       pdb = new PDBfile(addTempFacAnnot, parseSecStr, secStructServices,
               pdbFile, protocol);
-      if (isMapUsingSIFTs)
-      {
-        siftsClient = new SiftsClient(pdb);
-      }
+
       if (pdb.id != null && pdb.id.trim().length() > 0
               && AppletFormatAdapter.FILE.equals(protocol))
       {
         registerPDBFile(pdb.id.trim(), pdbFile);
       }
-    } catch (SiftsException e)
-    {
-      e.printStackTrace();
     } catch (Exception ex)
     {
       ex.printStackTrace();
       return null;
     }
 
-    String targetChain;
+    try
+    {
+      if (isMapUsingSIFTs)
+      {
+        siftsClient = new SiftsClient(pdb);
+      }
+    } catch (SiftsException e)
+    {
+      isMapUsingSIFTs = false;
+      e.printStackTrace();
+    }
+
+    String targetChainId;
     for (int s = 0; s < sequenceArray.length; s++)
     {
       boolean infChain = true;
       final SequenceI seq = sequenceArray[s];
-      if (targetChains != null && targetChains[s] != null)
+      if (targetChainIds != null && targetChainIds[s] != null)
       {
         infChain = false;
-        targetChain = targetChains[s];
+        targetChainId = targetChainIds[s];
       }
       else if (seq.getName().indexOf("|") > -1)
       {
-        targetChain = seq.getName().substring(
+        targetChainId = seq.getName().substring(
                 seq.getName().lastIndexOf("|") + 1);
-        if (targetChain.length() > 1)
+        if (targetChainId.length() > 1)
         {
-          if (targetChain.trim().length() == 0)
+          if (targetChainId.trim().length() == 0)
           {
-            targetChain = " ";
+            targetChainId = " ";
           }
           else
           {
             // not a valid chain identifier
-            targetChain = "";
+            targetChainId = "";
           }
         }
       }
       else
       {
-        targetChain = "";
+        targetChainId = "";
       }
 
       /*
@@ -440,7 +447,7 @@ public class StructureSelectionManager
       boolean first = true;
       for (PDBChain chain : pdb.chains)
       {
-        if (targetChain.length() > 0 && !targetChain.equals(chain.id)
+        if (targetChainId.length() > 0 && !targetChainId.equals(chain.id)
                 && !infChain)
         {
           continue; // don't try to map chains don't match.
@@ -456,7 +463,7 @@ public class StructureSelectionManager
         // as.traceAlignment();
 
         if (first || as.maxscore > max
-                || (as.maxscore == max && chain.id.equals(targetChain)))
+                || (as.maxscore == max && chain.id.equals(targetChainId)))
         {
           first = false;
           maxChain = chain;
@@ -480,26 +487,35 @@ public class StructureSelectionManager
       {
         try
         {
+          jalview.datamodel.Mapping sqmpping = maxAlignseq
+                  .getMappingFromS1(false);
           seqToStrucMapping = new ArrayList<StructureMapping>();
-          if (targetChain != null && !targetChain.trim().isEmpty())
+          if (targetChainId != null && !targetChainId.trim().isEmpty())
           {
-            maxChainId = targetChain;
             StructureMapping curChainMapping = siftsClient
-                    .getSiftsStructureMapping(seq, pdbFile, targetChain);
+                    .getSiftsStructureMapping(seq, pdbFile, targetChainId);
             seqToStrucMapping.add(curChainMapping);
+            maxChainId = targetChainId;
+            PDBChain chain = pdb.findChain(targetChainId);
+            if (chain != null)
+            {
+              chain.transferResidueAnnotation(curChainMapping, sqmpping);
+            }
           }
           else
           {
             for (PDBChain chain : pdb.chains)
             {
-              maxChainId = chain.id;
               StructureMapping curChainMapping = siftsClient
                       .getSiftsStructureMapping(seq, pdbFile, chain.id);
               seqToStrucMapping.add(curChainMapping);
+              maxChainId = chain.id;
+              chain.transferResidueAnnotation(curChainMapping, sqmpping);
             }
           }
         } catch (SiftsException e)
         {
+          e.printStackTrace();
           System.err
                   .println(">>>>>>> SIFTs mapping could not be obtained... Now mapping with NW alignment");
           seqToStrucMapping = getNWMappings(seq, pdbFile, maxChainId,