From 0e90e35fa87e18e80a340f982110b03c5eccc503 Mon Sep 17 00:00:00 2001 From: tcofoegbu Date: Fri, 22 May 2015 17:02:55 +0100 Subject: [PATCH] JAL-1745, JAL-1717 improvement to ensure cached PDB entries are unique within a sequence. Also only truly downloaded files should be shown in the cache view --- src/MCview/PDBfile.java | 1 + src/jalview/datamodel/PDBEntry.java | 6 ++---- src/jalview/ext/jmol/PDBFileWithJmol.java | 2 +- src/jalview/gui/StructureChooser.java | 25 +++++++++++++++++-------- test/jalview/datamodel/PDBEntryTest.java | 4 ++++ 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/MCview/PDBfile.java b/src/MCview/PDBfile.java index 940e27b..6ca8711 100755 --- a/src/MCview/PDBfile.java +++ b/src/MCview/PDBfile.java @@ -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) { diff --git a/src/jalview/datamodel/PDBEntry.java b/src/jalview/datamodel/PDBEntry.java index 36ffdf3..db792e2 100755 --- a/src/jalview/datamodel/PDBEntry.java +++ b/src/jalview/datamodel/PDBEntry.java @@ -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))); + } /** diff --git a/src/jalview/ext/jmol/PDBFileWithJmol.java b/src/jalview/ext/jmol/PDBFileWithJmol.java index bbf90ac..3df8957 100644 --- a/src/jalview/ext/jmol/PDBFileWithJmol.java +++ b/src/jalview/ext/jmol/PDBFileWithJmol.java @@ -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.) diff --git a/src/jalview/gui/StructureChooser.java b/src/jalview/gui/StructureChooser.java index ff7cdcb..2944cd8 100644 --- a/src/jalview/gui/StructureChooser.java +++ b/src/jalview/gui/StructureChooser.java @@ -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 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); } } diff --git a/test/jalview/datamodel/PDBEntryTest.java b/test/jalview/datamodel/PDBEntryTest.java index 49d9c62..01fb4a1 100644 --- a/test/jalview/datamodel/PDBEntryTest.java +++ b/test/jalview/datamodel/PDBEntryTest.java @@ -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(); -- 1.7.10.2