JAL-1745, JAL-1717 improvement to ensure cached PDB entries are unique within a seque...
authortcofoegbu <tcnofoegbu@dundee.ac.uk>
Fri, 22 May 2015 16:02:55 +0000 (17:02 +0100)
committertcofoegbu <tcnofoegbu@dundee.ac.uk>
Fri, 22 May 2015 16:02:55 +0000 (17:02 +0100)
src/MCview/PDBfile.java
src/jalview/datamodel/PDBEntry.java
src/jalview/ext/jmol/PDBFileWithJmol.java
src/jalview/gui/StructureChooser.java
test/jalview/datamodel/PDBEntryTest.java

index 940e27b..6ca8711 100755 (executable)
@@ -192,6 +192,7 @@ public class PDBfile extends jalview.io.AlignFile
         dataset.setName(id + "|" + dataset.getName());
         PDBEntry entry = new PDBEntry();
         entry.setId(id);
+        entry.setType(PDBEntry.Type.PDB);
         entry.setProperty(new Hashtable());
         if (chains.elementAt(i).id != null)
         {
index 36ffdf3..db792e2 100755 (executable)
@@ -55,10 +55,7 @@ public class PDBEntry
       return true;
     }
     PDBEntry o = (PDBEntry) obj;
-    return /*
-            * (file == o.file || (file != null && o.file != null && o.file
-            * .equals(file))) &&
-            */
+    return
     (type == o.type || (type != null && o.type != null && o.type
                     .equals(type)))
             && (id == o.id || (id != null && o.id != null && o.id
@@ -69,6 +66,7 @@ public class PDBEntry
             && (properties == o.properties || (properties != null
                     && o.properties != null && properties
                       .equals(o.properties)));
+    
   }
 
   /**
index bbf90ac..3df8957 100644 (file)
@@ -177,10 +177,10 @@ public class PDBFileWithJmol extends AlignFile implements
                   PDBEntry pdbe = new PDBEntry();
                   pdbe.setFile(getDataName());
                   pdbe.setId(getDataName());
-                  sq.addPDBId(pdbe);
                   pdbe.setProperty(new Hashtable());
                   // pdbe.getProperty().put("CHAIN", "" + _lastChainId);
                   pdbe.setChainCode(String.valueOf(_lastChainId));
+                  sq.addPDBId(pdbe);
                   // JAL-1533
                   // Need to put the number of models for this polymer somewhere for Chimera/others to grab
                   //                  pdbe.getProperty().put("PDBMODELS", biopoly.)
index ff7cdcb..2944cd8 100644 (file)
@@ -165,7 +165,7 @@ public class StructureChooser extends GStructureChooser
               && !resultList.getSearchSummary().isEmpty())
       {
         discoveredStructuresSet.addAll(resultList.getSearchSummary());
-        updateSequenceDbRef(seq, resultList.getSearchSummary());
+        updateSequencePDBEntries(seq, resultList.getSearchSummary());
       }
     }
 
@@ -216,6 +216,7 @@ public class StructureChooser extends GStructureChooser
       {
         for (PDBEntry pdbEntry : seq.getDatasetSequence().getPDBId())
         {
+
           String chain = pdbEntry.getChainCode() == null ? "_" : pdbEntry
                   .getChainCode();
           String[] pdbEntryRowData = new String[]
@@ -223,7 +224,10 @@ public class StructureChooser extends GStructureChooser
  chain,
               pdbEntry.getType(),
               pdbEntry.getFile() };
-          tableModel.addRow(pdbEntryRowData);
+          if (pdbEntry.getFile() != null)
+          {
+            tableModel.addRow(pdbEntryRowData);
+          }
           cachedEntryMap.put(pdbEntry.getId().toLowerCase(),
                   pdbEntry);
         }
@@ -233,7 +237,7 @@ public class StructureChooser extends GStructureChooser
   }
 
   /**
-   * Update the DBRef entry for a given sequence with values retrieved from
+   * Update the PDBEntry for a given sequence with values retrieved from
    * PDBResponseSummary
    * 
    * @param seq
@@ -241,15 +245,20 @@ public class StructureChooser extends GStructureChooser
    * @param responseSummaries
    *          a collection of PDBResponseSummary
    */
-  public void updateSequenceDbRef(SequenceI seq,
+  public void updateSequencePDBEntries(SequenceI seq,
           Collection<PDBResponseSummary> responseSummaries)
   {
     for (PDBResponseSummary response : responseSummaries)
     {
-      PDBEntry newEntry = new PDBEntry();
-      newEntry.setId(response.getPdbId());
-      newEntry.setType(PDBEntry.Type.PDB);
-      seq.getDatasetSequence().addPDBId(newEntry);
+      String pdbIdStr = response.getPdbId();
+      PDBEntry pdbEntry = cachedEntryMap.get(pdbIdStr.toLowerCase());
+      if (pdbEntry == null)
+      {
+        pdbEntry = new PDBEntry();
+        pdbEntry.setId(pdbIdStr);
+        pdbEntry.setType(PDBEntry.Type.PDB);
+      }
+      seq.getDatasetSequence().addPDBId(pdbEntry);
     }
   }
 
index 49d9c62..01fb4a1 100644 (file)
@@ -41,7 +41,9 @@ public class PDBEntryTest
             "x/y/z/File");
     PDBEntry case7 = new PDBEntry("1xyz", "A", null, "x/y/z/File");
     PDBEntry case8 = new PDBEntry("1xyz", "A", PDBEntry.Type.PDB, null);
+      PDBEntry case9 = new PDBEntry("1xyz", "A", null, "x/y/z/File");
 
+    
       // System.out.println(">>>> Testing case 1");
     assertTrue(pdbEntry.equals(case1));
       // System.out.println(">>>> Testing case 2");
@@ -58,6 +60,8 @@ public class PDBEntryTest
     assertTrue(!pdbEntry.equals(case7));
       // System.out.println(">>>> Testing case 8");
       assertTrue(pdbEntry.equals(case8));
+      assertTrue(pdbEntry.equals(case8));
+      assertTrue(case7.equals(case9));
     } catch (Exception e)
     {
       e.printStackTrace();