Merge branch 'bug/JAL-2691_nomultimermapping' into documentation/JAL-2675_release2102b1
authorJim Procter <jprocter@issues.jalview.org>
Sun, 3 Sep 2017 17:06:24 +0000 (18:06 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Sun, 3 Sep 2017 17:06:24 +0000 (18:06 +0100)
src/jalview/jbgui/GStructureChooser.java
src/jalview/structure/StructureSelectionManager.java
src/jalview/structures/models/AAStructureBindingModel.java
test/jalview/structures/models/AAStructureBindingModelTest.java

index 3e6cd2a..7c4672a 100644 (file)
@@ -165,6 +165,9 @@ public abstract class GStructureChooser extends JPanel
 
   protected static final String VIEWS_ENTER_ID = "VIEWS_ENTER_ID";
 
+  /**
+   * 'cached' structure view
+   */
   protected static final String VIEWS_LOCAL_PDB = "VIEWS_LOCAL_PDB";
 
   protected JTable tbl_local_pdb = new JTable();
index fbfa486..b973f45 100644 (file)
@@ -340,7 +340,9 @@ public class StructureSelectionManager
    *          - one or more sequences to be mapped to pdbFile
    * @param targetChainIds
    *          - optional chain specification for mapping each sequence to pdb
-   *          (may be nill, individual elements may be nill)
+   *          (may be nill, individual elements may be nill) - JBPNote: JAL-2693
+   *          - this should be List<List<String>>, empty lists indicate no
+   *          predefined mappings
    * @param pdbFile
    *          - structure data resource
    * @param sourceType
index 9f4cea0..2528286 100644 (file)
@@ -142,7 +142,6 @@ public abstract class AAStructureBindingModel
    * @param ssm
    * @param pdbentry
    * @param sequenceIs
-   * @param chains
    * @param protocol
    */
   public AAStructureBindingModel(StructureSelectionManager ssm,
@@ -154,8 +153,60 @@ public abstract class AAStructureBindingModel
     this.nucleotide = Comparison.isNucleotide(sequenceIs);
     this.pdbEntry = pdbentry;
     this.protocol = protocol;
+    resolveChains();
   }
 
+  private boolean resolveChains()
+  {
+    /**
+     * final count of chain mappings discovered
+     */
+    int chainmaps = 0;
+    // JBPNote: JAL-2693 - this should be a list of chain mappings per
+    // [pdbentry][sequence]
+    String[][] newchains = new String[pdbEntry.length][];
+    int pe = 0;
+    for (PDBEntry pdb : pdbEntry)
+    {
+      SequenceI[] seqsForPdb = sequence[pe];
+      if (seqsForPdb != null)
+      {
+        newchains[pe] = new String[seqsForPdb.length];
+        int se = 0;
+        for (SequenceI asq : seqsForPdb)
+        {
+          String chain = (chains != null && chains[pe] != null)
+                  ? chains[pe][se]
+                  : null;
+          SequenceI sq = (asq.getDatasetSequence() == null) ? asq
+                  : asq.getDatasetSequence();
+          if (sq.getAllPDBEntries() != null)
+          {
+            for (PDBEntry pdbentry : sq.getAllPDBEntries())
+            {
+              if (pdb.getFile() != null && pdbentry.getFile() != null
+                      && pdb.getFile().equals(pdbentry.getFile()))
+              {
+                String chaincode = pdbentry.getChainCode();
+                if (chaincode != null && chaincode.length() > 0)
+                {
+                  chain = chaincode;
+                  chainmaps++;
+                  break;
+                }
+              }
+            }
+          }
+          newchains[pe][se] = chain;
+          se++;
+        }
+        pe++;
+      }
+    }
+
+    chains = newchains;
+    return chainmaps > 0;
+  }
   public StructureSelectionManager getSsm()
   {
     return ssm;
index c125ef6..aea3687 100644 (file)
@@ -20,8 +20,8 @@
  */
 package jalview.structures.models;
 
+import static org.testng.Assert.assertFalse;
 import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
 import static org.testng.AssertJUnit.assertTrue;
 
 import jalview.api.AlignmentViewPanel;
@@ -36,6 +36,7 @@ import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceI;
 import jalview.gui.JvOptionPane;
 import jalview.io.DataSourceType;
+import jalview.io.FileFormats;
 import jalview.schemes.ColourSchemeI;
 import jalview.structure.AtomSpec;
 import jalview.structure.StructureMappingcommandSet;
@@ -43,6 +44,7 @@ import jalview.structure.StructureSelectionManager;
 import jalview.structures.models.AAStructureBindingModel.SuperposeData;
 
 import java.awt.Color;
+import java.io.IOException;
 import java.util.Arrays;
 import java.util.BitSet;
 import java.util.List;
@@ -98,6 +100,150 @@ public class AAStructureBindingModelTest
           + "ATOM     33  CA  ALA A  10      26.790   4.320   3.172  1.00 11.98           C  \n"
           + "ATOM     39  CA AVAL A  12      24.424   3.853   6.106  0.50 13.83           C  \n";
 
+  /**
+   * Multichain PDB with identical sequences imported - Binding should correctly
+   * recover chain mappings for each derived sequence
+   */
+  private static final String PDB_4_MC = "HEADER    HYDROLASE                               09-SEP-09   3A6S              \n"
+          + "ATOM      2  CA  MET A   1      15.366 -11.648  24.854  1.00 32.05           C  \n"
+          + "ATOM     10  CA  LYS A   2      16.846  -9.215  22.340  1.00 25.68           C  \n"
+          + "ATOM     19  CA  LYS A   3      15.412  -6.335  20.343  1.00 19.42           C  \n"
+          + "ATOM     28  CA  LEU A   4      15.629  -5.719  16.616  1.00 15.49           C  \n"
+          + "ATOM     36  CA  GLN A   5      14.412  -2.295  15.567  1.00 12.19           C  \n"
+          + "ATOM   1030  CA  MET B   1      18.869  -7.572   3.432  1.00 31.52           C  \n"
+          + "ATOM   1038  CA  LYS B   2      19.182 -10.025   6.313  1.00 26.41           C  \n"
+          + "ATOM   1047  CA  LYS B   3      17.107 -12.963   7.534  1.00 19.71           C  \n"
+          + "ATOM   1056  CA  LEU B   4      16.142 -13.579  11.164  1.00 14.81           C  \n"
+          + "ATOM   1064  CA  GLN B   5      14.648 -17.005  11.785  1.00 13.38           C  \n";
+
+  // TODO: JAL-2227 - import mmCIF PISA assembly & identify master/copy chains
+
+  @Test(groups= {"Functional"})
+  public void testImportPDBPreservesChainMappings() throws IOException
+  {
+    AlignmentI importedAl = new jalview.io.FormatAdapter().readFile(
+            PDB_4_MC, DataSourceType.PASTE, FileFormats.getInstance()
+                    .forName(jalview.io.FileFormat.PDB.toString()));
+    // ideally, we would match on the actual data for the 'File' handle for
+    // pasted files,
+    // see JAL-623 - pasting is still not correctly handled...
+    PDBEntry importedPDB = new PDBEntry("3A6S", "", Type.PDB,
+            "Paste");
+    AAStructureBindingModel binder = new AAStructureBindingModel(
+            new StructureSelectionManager(), new PDBEntry[]
+            { importedPDB },
+            new SequenceI[][]
+            { importedAl.getSequencesArray() }, null)
+    {
+      
+      @Override
+      public void updateColours(Object source)
+      {
+        // TODO Auto-generated method stub
+        
+      }
+      
+      @Override
+      public void releaseReferences(Object svl)
+      {
+        // TODO Auto-generated method stub
+        
+      }
+      
+      @Override
+      public String[] getStructureFiles()
+      {
+        // TODO Auto-generated method stub
+        return null;
+      }
+      
+      @Override
+      public String superposeStructures(AlignmentI[] alignments,
+              int[] structureIndices, HiddenColumns[] hiddenCols)
+      {
+        // TODO Auto-generated method stub
+        return null;
+      }
+      
+      @Override
+      public void setJalviewColourScheme(ColourSchemeI cs)
+      {
+        // TODO Auto-generated method stub
+        
+      }
+      
+      @Override
+      public void setBackgroundColour(Color col)
+      {
+        // TODO Auto-generated method stub
+        
+      }
+      
+      @Override
+      public void highlightAtoms(List<AtomSpec> atoms)
+      {
+        // TODO Auto-generated method stub
+        
+      }
+      
+      @Override
+      public SequenceRenderer getSequenceRenderer(AlignmentViewPanel alignment)
+      {
+        // TODO Auto-generated method stub
+        return null;
+      }
+      
+      @Override
+      public FeatureRenderer getFeatureRenderer(AlignmentViewPanel alignment)
+      {
+        // TODO Auto-generated method stub
+        return null;
+      }
+      
+      @Override
+      protected StructureMappingcommandSet[] getColourBySequenceCommands(
+              String[] files, SequenceRenderer sr, AlignmentViewPanel avp)
+      {
+        // TODO Auto-generated method stub
+        return null;
+      }
+      
+      @Override
+      public List<String> getChainNames()
+      {
+        // TODO Auto-generated method stub
+        return null;
+      }
+      
+      @Override
+      protected void colourBySequence(
+              StructureMappingcommandSet[] colourBySequenceCommands)
+      {
+        // TODO Auto-generated method stub
+        
+      }
+      
+      @Override
+      public void colourByCharge()
+      {
+        // TODO Auto-generated method stub
+        
+      }
+      
+      @Override
+      public void colourByChain()
+      {
+        // TODO Auto-generated method stub
+        
+      }
+    };
+    String[][] chains = binder.getChains();
+    assertFalse(chains == null || chains[0] == null,
+            "No chains discovered by binding");
+    assertEquals(2, chains[0].length);
+    assertEquals("A", chains[0][0]);
+    assertEquals("B", chains[0][1]);
+  }
   AAStructureBindingModel testee;
 
   AlignmentI al = null;