X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FPDBEntry.java;h=fc4ee46b5439fe587c5135d464c02f03185e27eb;hb=cf02a7088e2835fa4764d034e662f4319073c8a9;hp=3cba683f2342a16272322b8fbe3a53922a20824f;hpb=3ab582bfeeab1563bedf60e97994e63e672d2e31;p=jalview.git diff --git a/src/jalview/datamodel/PDBEntry.java b/src/jalview/datamodel/PDBEntry.java index 3cba683..fc4ee46 100755 --- a/src/jalview/datamodel/PDBEntry.java +++ b/src/jalview/datamodel/PDBEntry.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9.0b2) - * Copyright (C) 2015 The Jalview Authors + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * @@ -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; @@ -46,7 +48,39 @@ public class PDBEntry public enum Type { - PDB, MMCIF, FILE; + // TODO is FILE needed; if not is this enum needed, or can we + // use FileFormatI for PDB, MMCIF? + PDB("pdb", "pdb"), MMCIF("mmcif", "cif"), 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) + { + format = fmt; + ext = ex; + } + + public String getFormat() + { + return format; + } + + public String getExtension() + { + return ext; + } + /** * case insensitive matching for Type enum * @@ -77,7 +111,6 @@ public class PDBEntry } } - /** * Answers true if obj is a PDBEntry with the same id and chain code (both * ignoring case), file, type and properties @@ -121,17 +154,6 @@ public class PDBEntry { } - /** - * Constructor given file path and PDB id. - * - * @param filePath - */ - // public PDBEntry(String filePath, String pdbId) - // { - // this.file = filePath; - // this.id = pdbId; - // } - public PDBEntry(String pdbId, String chain, PDBEntry.Type type, String filePath) { @@ -144,7 +166,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(); @@ -179,8 +202,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(); @@ -363,21 +386,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()) + { + return false; + } // otherwise we can update + } + } + } + else + { + // one has data, one doesn't .. + if (!idMatches) + { + return false; + } // otherwise maybe can update } /* @@ -432,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); @@ -439,4 +486,111 @@ 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)); + } + + 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); + } }