From cf02a7088e2835fa4764d034e662f4319073c8a9 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Tue, 21 Sep 2021 08:30:03 +0100 Subject: [PATCH] JAL-3829 ignore the fake ID generated when a PDB format file without embedded ID is imported for an existing PDBEntry --- src/jalview/datamodel/PDBEntry.java | 38 ++++++++++++++++++++++++++++- src/jalview/io/StructureFile.java | 1 + test/jalview/datamodel/SequenceTest.java | 15 ++++++++++++ test/jalview/ext/jmol/JmolParserTest.java | 4 +++ 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/jalview/datamodel/PDBEntry.java b/src/jalview/datamodel/PDBEntry.java index b3e17bf..fc4ee46 100755 --- a/src/jalview/datamodel/PDBEntry.java +++ b/src/jalview/datamodel/PDBEntry.java @@ -38,6 +38,8 @@ public class PDBEntry private static final int PDB_ID_LENGTH = 4; + private static final String FAKED_ID = "faked_pdbid"; + private String file; private String type; @@ -404,7 +406,10 @@ 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 - return false; + if (!newEntry.fakedPDBId()) + { + return false; + } // otherwise we can update } } } @@ -469,6 +474,11 @@ public class PDBEntry */ String key = newProps.nextElement(); Object value = newEntry.getProperty(key); + if (FAKED_ID.equals(key)) + { + // we never update the fake ID property + continue; + } if (!value.equals(getProperty(key))) { setProperty(key, value); @@ -477,6 +487,32 @@ public class PDBEntry return true; } + /** + * set when Jalview has manufactured the ID using a local filename + * @return + */ + public boolean fakedPDBId() + { + if (_hasProperty(FAKED_ID)) + { + return true; + } + return false; + } + public void setFakedPDBId(boolean faked) + { + if (faked) + { + setProperty(FAKED_ID, Boolean.TRUE); + } + else + { + if (properties!=null) { + properties.remove(FAKED_ID); + } + } + } + private boolean _hasProperty(final String key) { return (properties != null && properties.containsKey(key)); diff --git a/src/jalview/io/StructureFile.java b/src/jalview/io/StructureFile.java index 084f886..94a832b 100644 --- a/src/jalview/io/StructureFile.java +++ b/src/jalview/io/StructureFile.java @@ -119,6 +119,7 @@ public abstract class StructureFile extends AlignFile pdbSequence.setName(getId() + "|" + pdbSequence.getName()); PDBEntry entry = new PDBEntry(); entry.setId(getId()); + entry.setFakedPDBId(!isPPDBIdAvailable()); entry.setType(getStructureFileType()); if (chain.id != null) { diff --git a/test/jalview/datamodel/SequenceTest.java b/test/jalview/datamodel/SequenceTest.java index eb75645..5069759 100644 --- a/test/jalview/datamodel/SequenceTest.java +++ b/test/jalview/datamodel/SequenceTest.java @@ -1460,6 +1460,21 @@ public class SequenceTest seq.addPDBId(pdbe5); assertEquals(4, seq.getAllPDBEntries().size()); assertSame(pdbe5, seq.getAllPDBEntries().get(3)); + + // add with a fake pdbid + // (models don't have an embedded ID) + String realId = "RealIDQ"; + PDBEntry pdbe6 = new PDBEntry(realId,null,Type.PDB,"real/localpath"); + PDBEntry pdbe7 = new PDBEntry("RealID/real/localpath","C",Type.MMCIF,"real/localpath"); + pdbe7.setFakedPDBId(true); + seq.addPDBId(pdbe6); + assertEquals(5,seq.getAllPDBEntries().size()); + seq.addPDBId(pdbe7); + assertEquals(5,seq.getAllPDBEntries().size()); + assertFalse(pdbe6.fakedPDBId()); + assertSame(pdbe6,seq.getAllPDBEntries().get(4)); + assertEquals("C",pdbe6.getChainCode()); + assertEquals(realId, pdbe6.getId()); } @Test( diff --git a/test/jalview/ext/jmol/JmolParserTest.java b/test/jalview/ext/jmol/JmolParserTest.java index 2832135..10882d3 100644 --- a/test/jalview/ext/jmol/JmolParserTest.java +++ b/test/jalview/ext/jmol/JmolParserTest.java @@ -277,6 +277,10 @@ public class JmolParserTest assertEquals(structureData.getId(), "localstruct"); assertNotNull(structureData.getSeqs()); /* + * local structures have a fake ID + */ + assertTrue(structureData.getSeqs().get(0).getAllPDBEntries().get(0).fakedPDBId()); + /* * the ID is also the group for features derived from structure data */ String featureGroup = structureData.getSeqs().get(0) -- 1.7.10.2