From 584ab9644955bec02d96448361b8aac5b9542599 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Mon, 14 Feb 2022 14:03:39 +0000 Subject: [PATCH] JAL-3956 - PDBEntry objects constructed from 3D-Beacons have authoritative IDs overriding any embedded IDs --- src/jalview/datamodel/PDBEntry.java | 30 ++++++++++++++++++-- .../ThreeDBStructureChooserQuerySource.java | 1 + test/jalview/datamodel/PDBEntryTest.java | 17 ++++++++++- 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/jalview/datamodel/PDBEntry.java b/src/jalview/datamodel/PDBEntry.java index adcefb3..741ef07 100755 --- a/src/jalview/datamodel/PDBEntry.java +++ b/src/jalview/datamodel/PDBEntry.java @@ -38,7 +38,14 @@ public class PDBEntry private static final int PDB_ID_LENGTH = 4; + /** + * property set when id is a 'manufactured' identifier from the structure data's filename + */ private static final String FAKED_ID = "faked_pdbid"; + /** + * property set when the id is authoritative, and should be used in preference to any identifiers in the structure data + */ + private static final String AUTHORITATIVE_ID = "authoritative_pdbid"; private String file; @@ -406,7 +413,7 @@ public class PDBEntry // this shouldn't happen, but could do if the id from the // file is not the same as the id from the authority that provided // the file - if (!newEntry.fakedPDBId()) + if (!newEntry.fakedPDBId() && !isAuthoritative()) { return false; } // otherwise we can update @@ -474,7 +481,7 @@ public class PDBEntry */ String key = newProps.nextElement(); Object value = newEntry.getProperty(key); - if (FAKED_ID.equals(key)) + if (FAKED_ID.equals(key) || AUTHORITATIVE_ID.equals(key)) { // we never update the fake ID property continue; @@ -487,6 +494,25 @@ public class PDBEntry return true; } + public void setAuthoritative(boolean isAuthoritative) + { + setProperty(AUTHORITATIVE_ID, Boolean.valueOf(isAuthoritative)); + } + + /** + * + * @return true if the identifier should be preferred over any identifiers + * embedded in the structure data + */ + public boolean isAuthoritative() + { + if (_hasProperty(AUTHORITATIVE_ID)) + { + return ((Boolean)getProperty(AUTHORITATIVE_ID)); + } + return false; + } + /** * set when Jalview has manufactured the ID using a local filename * @return diff --git a/src/jalview/gui/structurechooser/ThreeDBStructureChooserQuerySource.java b/src/jalview/gui/structurechooser/ThreeDBStructureChooserQuerySource.java index 23b96c9..669e58a 100644 --- a/src/jalview/gui/structurechooser/ThreeDBStructureChooserQuerySource.java +++ b/src/jalview/gui/structurechooser/ThreeDBStructureChooserQuerySource.java @@ -415,6 +415,7 @@ public class ThreeDBStructureChooserQuerySource { pdbEntry = new PDBEntry(); pdbEntry.setId(pdbIdStr); + pdbEntry.setAuthoritative(true); try { pdbEntry.setType(PDBEntry.Type.valueOf(strucFormat)); diff --git a/test/jalview/datamodel/PDBEntryTest.java b/test/jalview/datamodel/PDBEntryTest.java index 198cde3..80b7376 100644 --- a/test/jalview/datamodel/PDBEntryTest.java +++ b/test/jalview/datamodel/PDBEntryTest.java @@ -90,7 +90,7 @@ public class PDBEntryTest PDBEntry case9 = new PDBEntry("1xyz", "A", null, "x/y/z/File"); // different file only PDBEntry case10 = new PDBEntry("1xyz", "A", null, "a/b/c/File"); - + /* * assertEquals will invoke PDBEntry.equals() */ @@ -269,6 +269,21 @@ public class PDBEntryTest pdb2.setProperty("hello", "moon"); assertTrue(pdb1.updateFrom(pdb2)); assertEquals(pdb1.getProperty("hello"), "moon"); + + /* + * different id but authoritative + */ + pdb1 = new PDBEntry("af:1xyz", "A", null, "a/b/c/File"); + pdb2 = new PDBEntry("af-1xyz", "A", null, "a/b/c/File"); + pdb1.setAuthoritative(true); + + assertTrue(pdb1.isAuthoritative()); + assertFalse(pdb2.isAuthoritative()); + // can update pdb1 (authoritative) from pdb2 (non-authoritative) + assertTrue(pdb1.updateFrom(pdb2)); + // but the ID must remain the same + assertEquals(pdb1.getId(),"af:1xyz"); + } @Test(groups = { "Functional" }) -- 1.7.10.2