X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FPDBEntry.java;h=a966ca1390c8f0d2be2ece6e2a981ae6502c94d4;hb=d043ce47fc710d3eb2629ba926a8a7417bd67d8c;hp=97fb08ddae8428f89008b165fe6909ad99d369c4;hpb=7d67fb613ec026dc9a265e351e7fab542e3f1d61;p=jalview.git diff --git a/src/jalview/datamodel/PDBEntry.java b/src/jalview/datamodel/PDBEntry.java index 97fb08d..a966ca1 100755 --- a/src/jalview/datamodel/PDBEntry.java +++ b/src/jalview/datamodel/PDBEntry.java @@ -20,12 +20,12 @@ */ package jalview.datamodel; -import jalview.util.CaseInsensitiveString; - import java.util.Collections; import java.util.Enumeration; import java.util.Hashtable; +import jalview.util.CaseInsensitiveString; + public class PDBEntry { @@ -38,6 +38,18 @@ 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; private String type; @@ -46,11 +58,22 @@ public class PDBEntry public enum Type { - // TODO is FILE needed; if not is this needed or can we + // TODO is FILE needed; if not is this enum needed, or can we // use FileFormatI for PDB, MMCIF? - PDB("pdb", "xml"), MMCIF("mmcif", "mmcif"), FILE("?", "?"); + PDB("pdb", "pdb"), MMCIF("mmcif", "cif"), BCIF("bcif", "bcif"), + FILE("?", "?"); + + /* + * file extension for cached structure file; must be one that + * is recognised by Chimera 'open' command + * @see https://www.cgl.ucsf.edu/chimera/current/docs/UsersGuide/filetypes.html + */ String ext; + /* + * format specifier used in dbfetch request + * @see http://www.ebi.ac.uk/Tools/dbfetch/dbfetch/dbfetch.databases#pdb + */ String format; private Type(String fmt, String ex) @@ -63,6 +86,7 @@ public class PDBEntry { return format; } + public String getExtension() { return ext; @@ -141,7 +165,32 @@ public class PDBEntry { } - + /** + * Entry point when file is not known and fileType may be string + * @param pdbId + * @param chain may be null + * @param fileType "pdb", "mmcif", or "bcif"; null defaults to mmcif + */ + public PDBEntry(String pdbId, String chain, String fileType) { + this.id = pdbId.toLowerCase(); + setChainCode(chain); // I note that PDB Chains ARE case-sensitive now + if (fileType == null) + fileType = "mmcif"; + switch (fileType.toLowerCase()) { + case "pdb": + this.type = Type.PDB.toString(); + break; + case "mmcif": + this.type = Type.MMCIF.toString(); + break; + default: + case "bcif": + System.out.println("format " + fileType + " has not been implemented; using mmCIF"); + this.type = Type.MMCIF.toString(); + break; + } + } + public PDBEntry(String pdbId, String chain, PDBEntry.Type type, String filePath) { @@ -154,7 +203,8 @@ public class PDBEntry * @param entryType * @param filePath */ - void init(String pdbId, String chain, PDBEntry.Type entryType, String filePath) + void init(String pdbId, String chain, PDBEntry.Type entryType, + String filePath) { this.id = pdbId; this.type = entryType == null ? null : entryType.toString(); @@ -189,8 +239,8 @@ public class PDBEntry { if (!DBRefSource.PDB.equals(dbr.getSource())) { - throw new IllegalArgumentException("Invalid source: " - + dbr.getSource()); + throw new IllegalArgumentException( + "Invalid source: " + dbr.getSource()); } String pdbId = dbr.getAccessionId(); @@ -242,6 +292,12 @@ public class PDBEntry return id; } + /** + * TODO + * + * @param key "protocol" + * @param value + */ public void setProperty(String key, Object value) { if (this.properties == null) @@ -373,21 +429,40 @@ public class PDBEntry return false; // shouldn't happen } - /* - * id has to match (ignoring case) - */ - if (!getId().equalsIgnoreCase(newId)) - { - return false; - } + boolean idMatches = getId().equalsIgnoreCase(newId); /* * Don't update if associated with different structure files */ String newFile = newEntry.getFile(); - if (newFile != null && getFile() != null && !newFile.equals(getFile())) + if (newFile != null && getFile() != null) { - return false; + if (!newFile.equals(getFile())) + { + return false; + } + else + { + // files match. + if (!idMatches) + { + // 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() && !isAuthoritative()) + { + return false; + } // otherwise we can update + } + } + } + else + { + // one has data, one doesn't .. + if (!idMatches) + { + return false; + } // otherwise maybe can update } /* @@ -442,6 +517,11 @@ public class PDBEntry */ String key = newProps.nextElement(); Object value = newEntry.getProperty(key); + if (FAKED_ID.equals(key) || AUTHORITATIVE_ID.equals(key)) + { + // we never update the fake ID property + continue; + } if (!value.equals(getProperty(key))) { setProperty(key, value); @@ -449,4 +529,133 @@ 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 + */ + 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)); + } + + private static final String RETRIEVE_FROM = "RETRIEVE_FROM"; + + private static final String PROVIDER = "PROVIDER"; + + private static final String MODELPAGE = "PROVIDERPAGE"; + + /** + * Permanent URI for retrieving the original structure data + * + * @param urlStr + */ + public void setRetrievalUrl(String urlStr) + { + setProperty(RETRIEVE_FROM, urlStr); + } + + public boolean hasRetrievalUrl() + { + return _hasProperty(RETRIEVE_FROM); + } + + /** + * get the Permanent URI for retrieving the original structure data + */ + public String getRetrievalUrl() + { + return (String) getProperty(RETRIEVE_FROM); + } + + /** + * Data provider name - from 3D Beacons + * + * @param provider + */ + public void setProvider(String provider) + { + setProperty(PROVIDER, provider); + } + + /** + * Get Data provider name - from 3D Beacons + * + */ + public String getProvider() + { + return (String) getProperty(PROVIDER); + } + + /** + * Permanent URI for retrieving the original structure data + * + * @param urlStr + */ + public void setProviderPage(String urlStr) + { + setProperty(MODELPAGE, urlStr); + } + + /** + * get the Permanent URI for retrieving the original structure data + */ + public String getProviderPage() + { + return (String) getProperty(MODELPAGE); + } + + public boolean hasProviderPage() + { + return _hasProperty(MODELPAGE); + } + + public boolean hasProvider() + { + return _hasProperty(PROVIDER); + } }