From: gmungoc Date: Wed, 5 Oct 2016 15:17:59 +0000 (+0100) Subject: Merge branch 'develop' into task/JAL-2196pdbeProperties X-Git-Tag: Release_2_10_0b1~3^2~17 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=e838644df5d5a10a16cf0ad7fb23d24dd7d2729a;hp=5326cbb4462396e84cdbbc178040f42b436c9146;p=jalview.git Merge branch 'develop' into task/JAL-2196pdbeProperties Conflicts: src/jalview/datamodel/PDBEntry.java test/jalview/ws/dbsources/UniprotTest.java --- diff --git a/resources/uniprot_mapping.xml b/resources/uniprot_mapping.xml index a8634af..4a981ad 100755 --- a/resources/uniprot_mapping.xml +++ b/resources/uniprot_mapping.xml @@ -80,7 +80,7 @@ - + diff --git a/src/MCview/PDBViewer.java b/src/MCview/PDBViewer.java index 66ce147..0f6ef27 100755 --- a/src/MCview/PDBViewer.java +++ b/src/MCview/PDBViewer.java @@ -128,18 +128,17 @@ public class PDBViewer extends JInternalFrame implements Runnable worker.start(); } - if (pdbentry.getProperty() != null) + String method = (String) pdbentry.getProperty("method"); + if (method != null) { - if (pdbentry.getProperty().get("method") != null) - { - title.append(" Method: "); - title.append(pdbentry.getProperty().get("method")); - } - if (pdbentry.getProperty().get("chains") != null) - { - title.append(" Chain:"); - title.append(pdbentry.getProperty().get("chains")); - } + title.append(" Method: "); + title.append(method); + } + String ch = (String) pdbentry.getProperty("chains"); + if (ch != null) + { + title.append(" Chain:"); + title.append(ch); } Desktop.addInternalFrame(this, title.toString(), 400, 400); } diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index e36944f..511a264 100644 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -102,7 +102,6 @@ import java.net.URLEncoder; import java.util.Arrays; import java.util.Deque; import java.util.HashMap; -import java.util.Hashtable; import java.util.List; import java.util.Map; import java.util.StringTokenizer; @@ -4025,12 +4024,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, } if (needtoadd) { - // make a note of the access mode and add - if (pdbentry.getProperty() == null) - { - pdbentry.setProperty(new Hashtable()); - } - pdbentry.getProperty().put("protocol", protocol); + pdbentry.setProperty("protocol", protocol); toaddpdb.addPDBId(pdbentry); alignPanel.getStructureSelectionManager() .registerPDBEntry(pdbentry); @@ -4081,7 +4075,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, if (protocol == null || protocol.trim().length() == 0 || protocol.equals("null")) { - protocol = (String) pdb.getProperty().get("protocol"); + protocol = (String) pdb.getProperty("protocol"); if (protocol == null) { System.err.println("Couldn't work out protocol to open structure: " diff --git a/src/jalview/appletgui/AppletJmol.java b/src/jalview/appletgui/AppletJmol.java index 264ac14..c39204f 100644 --- a/src/jalview/appletgui/AppletJmol.java +++ b/src/jalview/appletgui/AppletJmol.java @@ -60,7 +60,6 @@ import java.awt.event.KeyListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.ArrayList; -import java.util.Hashtable; import java.util.List; import java.util.Vector; @@ -293,11 +292,8 @@ public class AppletJmol extends EmbmenuFrame implements closeViewer(); } }); - if (pdbentry.getProperty() == null) - { - pdbentry.setProperty(new Hashtable()); - pdbentry.getProperty().put("protocol", protocol); - } + pdbentry.setProperty("protocol", protocol); + if (pdbentry.getFile() != null) { // import structure data from pdbentry.getFile based on given protocol diff --git a/src/jalview/datamodel/PDBEntry.java b/src/jalview/datamodel/PDBEntry.java index 1403595..6a6ccd0 100755 --- a/src/jalview/datamodel/PDBEntry.java +++ b/src/jalview/datamodel/PDBEntry.java @@ -22,10 +22,20 @@ package jalview.datamodel; import jalview.util.CaseInsensitiveString; +import java.util.Collections; +import java.util.Enumeration; import java.util.Hashtable; public class PDBEntry { + + /** + * constant for storing chain code in properties table + */ + private static final String CHAIN_ID = "chain_code"; + + private Hashtable properties; + private static final int PDB_ID_LENGTH = 4; private String file; @@ -67,12 +77,6 @@ public class PDBEntry } } - /** - * constant for storing chain code in properties table - */ - private static final String CHAIN_ID = "chain_code"; - - Hashtable properties; /** * Answers true if obj is a PDBEntry with the same id and chain code (both @@ -137,13 +141,13 @@ public class PDBEntry /** * @param pdbId * @param chain - * @param type + * @param entryType * @param filePath */ - void init(String pdbId, String chain, PDBEntry.Type type, String filePath) + void init(String pdbId, String chain, PDBEntry.Type entryType, String filePath) { this.id = pdbId; - this.type = type == null ? null : type.toString(); + this.type = entryType == null ? null : entryType.toString(); this.file = filePath; setChainCode(chain); } @@ -160,7 +164,7 @@ public class PDBEntry id = entry.id; if (entry.properties != null) { - properties = (Hashtable) entry.properties.clone(); + properties = (Hashtable) entry.properties.clone(); } } @@ -193,9 +197,9 @@ public class PDBEntry init(pdbId, chainCode, null, null); } - public void setFile(String file) + public void setFile(String f) { - this.file = file; + this.file = f; } public String getFile() @@ -228,14 +232,33 @@ public class PDBEntry return id; } - public void setProperty(Hashtable property) + public void setProperty(String key, Object value) { - this.properties = property; + if (this.properties == null) + { + this.properties = new Hashtable(); + } + properties.put(key, value); } - public Hashtable getProperty() + public Object getProperty(String key) { - return properties; + return properties == null ? null : properties.get(key); + } + + /** + * Returns an enumeration of the keys of this object's properties (or an empty + * enumeration if it has no properties) + * + * @return + */ + public Enumeration getProperties() + { + if (properties == null) + { + return Collections.emptyEnumeration(); + } + return properties.keys(); } /** @@ -248,24 +271,37 @@ public class PDBEntry : properties.get(CHAIN_ID).toString(); } + /** + * Sets a non-case-sensitive property for the given chain code. Two PDBEntry + * objects which differ only in the case of their chain code are considered + * equal. This avoids duplication of objects in lists of PDB ids. + * + * @param chainCode + */ public void setChainCode(String chainCode) { - if (properties == null) + if (chainCode == null) { - if (chainCode == null) - { - // nothing to do. - return; - } - properties = new Hashtable(); + deleteProperty(CHAIN_ID); } - if (chainCode == null) + else + { + setProperty(CHAIN_ID, new CaseInsensitiveString(chainCode)); + } + } + + /** + * Deletes the property with the given key, and returns the deleted value (or + * null) + */ + Object deleteProperty(String key) + { + Object result = null; + if (properties != null) { - properties.remove(CHAIN_ID); - return; + result = properties.remove(key); } - // update property for non-null chainCode - properties.put(CHAIN_ID, new CaseInsensitiveString(chainCode)); + return result; } @Override @@ -275,6 +311,35 @@ public class PDBEntry } /** + * Getter provided for Castor binding only. Application code should call + * getProperty() or getProperties() instead. + * + * @deprecated + * @see #getProperty(String) + * @see #getProperties() + * @see jalview.ws.dbsources.Uniprot#getUniprotEntries + * @return + */ + @Deprecated + public Hashtable getProps() + { + return properties; + } + + /** + * Setter provided for Castor binding only. Application code should call + * setProperty() instead. + * + * @deprecated + * @return + */ + @Deprecated + public void setProps(Hashtable props) + { + properties = props; + } + + /** * Answers true if this object is either equivalent to, or can be 'improved' * by, the given entry. *

@@ -285,7 +350,7 @@ public class PDBEntry * @param newEntry * @return true if modifications were made */ - protected boolean updateFrom(PDBEntry newEntry) + public boolean updateFrom(PDBEntry newEntry) { if (this.equals(newEntry)) { @@ -299,7 +364,7 @@ public class PDBEntry } /* - * id (less any chain code) has to match (ignoring case) + * id has to match (ignoring case) */ if (!getId().equalsIgnoreCase(newId)) { @@ -356,26 +421,20 @@ public class PDBEntry } /* - * copy any new properties; notice this may include chain_code, - * but we excluded differing chain codes earlier + * copy any new or modified properties */ - if (newEntry.getProperty() != null) + Enumeration newProps = newEntry.getProperties(); + while (newProps.hasMoreElements()) { - if (properties == null) + /* + * copy properties unless value matches; this defends against changing + * the case of chain_code which is wrapped in a CaseInsensitiveString + */ + String key = newProps.nextElement(); + Object value = newEntry.getProperty(key); + if (!value.equals(getProperty(key))) { - properties = new Hashtable(); - } - for (Object p : newEntry.getProperty().keySet()) - { - /* - * copy properties unless value matches; this defends against changing - * the case of chain_code which is wrapped in a CaseInsensitiveString - */ - Object value = newEntry.getProperty().get(p); - if (!value.equals(properties.get(p))) - { - properties.put(p, newEntry.getProperty().get(p)); - } + setProperty(key, value); } } return true; diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java index 47a8faf..473d8ab 100644 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -983,17 +983,16 @@ public class Jalview2XML } } - if (entry.getProperty() != null && !entry.getProperty().isEmpty()) + Enumeration props = entry.getProperties(); + if (props.hasMoreElements()) { PdbentryItem item = new PdbentryItem(); - Hashtable properties = entry.getProperty(); - Enumeration en2 = properties.keys(); - while (en2.hasMoreElements()) + while (props.hasMoreElements()) { Property prop = new Property(); - String key = en2.nextElement().toString(); + String key = props.nextElement(); prop.setName(key); - prop.setValue(properties.get(key).toString()); + prop.setValue(entry.getProperty(key).toString()); item.addProperty(prop); } pdb.addPdbentryItem(item); @@ -3020,12 +3019,11 @@ public class Jalview2XML } if (ids[p].getPdbentryItem() != null) { - entry.setProperty(new Hashtable()); for (PdbentryItem item : ids[p].getPdbentryItem()) { for (Property pr : item.getProperty()) { - entry.getProperty().put(pr.getName(), pr.getValue()); + entry.setProperty(pr.getName(), pr.getValue()); } } } diff --git a/src/jalview/io/StructureFile.java b/src/jalview/io/StructureFile.java index 0bc6a73..322c6b8 100644 --- a/src/jalview/io/StructureFile.java +++ b/src/jalview/io/StructureFile.java @@ -15,7 +15,6 @@ import jalview.structure.StructureImportSettings; import java.awt.Color; import java.io.IOException; import java.lang.reflect.Constructor; -import java.util.Hashtable; import java.util.List; import java.util.Vector; @@ -92,7 +91,6 @@ public abstract class StructureFile extends AlignFile { } - @SuppressWarnings("rawtypes") protected SequenceI postProcessChain(PDBChain chain) { SequenceI pdbSequence = chain.sequence; @@ -100,10 +98,9 @@ public abstract class StructureFile extends AlignFile PDBEntry entry = new PDBEntry(); entry.setId(getId()); entry.setType(getStructureFileType()); - entry.setProperty(new Hashtable()); if (chain.id != null) { - entry.setChainCode(String.valueOf(chain.id)); + entry.setChainCode(chain.id); } if (inFile != null) { diff --git a/src/jalview/structures/models/AAStructureBindingModel.java b/src/jalview/structures/models/AAStructureBindingModel.java index dc42315..fc32fa3 100644 --- a/src/jalview/structures/models/AAStructureBindingModel.java +++ b/src/jalview/structures/models/AAStructureBindingModel.java @@ -239,24 +239,21 @@ public abstract class AAStructureBindingModel extends // TODO: give a more informative title when multiple structures are // displayed. StringBuilder title = new StringBuilder(64); - final PDBEntry pdbEntry = getPdbEntry(0); + final PDBEntry pdbe = getPdbEntry(0); title.append(viewerName + " view for " + getSequence()[0][0].getName() - + ":" + pdbEntry.getId()); + + ":" + pdbe.getId()); if (verbose) { - if (pdbEntry.getProperty() != null) + String method = (String) pdbe.getProperty("method"); + if (method != null) { - if (pdbEntry.getProperty().get("method") != null) - { - title.append(" Method: "); - title.append(pdbEntry.getProperty().get("method")); - } - if (pdbEntry.getProperty().get("chains") != null) - { - title.append(" Chain:"); - title.append(pdbEntry.getProperty().get("chains")); - } + title.append(" Method: ").append(method); + } + String chain = (String) pdbe.getProperty("chains"); + if (chain != null) + { + title.append(" Chain:").append(chain); } } return title.toString(); diff --git a/src/jalview/util/DBRefUtils.java b/src/jalview/util/DBRefUtils.java index d43f5bc..e6aa472 100755 --- a/src/jalview/util/DBRefUtils.java +++ b/src/jalview/util/DBRefUtils.java @@ -29,7 +29,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; -import java.util.Hashtable; import java.util.List; import java.util.Map; import java.util.Set; @@ -508,9 +507,7 @@ public class DBRefUtils PDBEntry pdbr = new PDBEntry(); pdbr.setId(pdbid); pdbr.setType(PDBEntry.Type.PDB); - pdbr.setProperty(new Hashtable()); pdbr.setChainCode(chaincode); - // pdbr.getProperty().put("CHAIN", chaincode); seq.addPDBId(pdbr); } else diff --git a/src/jalview/ws/dbsources/Uniprot.java b/src/jalview/ws/dbsources/Uniprot.java index 0c2af3b..caed598 100644 --- a/src/jalview/ws/dbsources/Uniprot.java +++ b/src/jalview/ws/dbsources/Uniprot.java @@ -225,8 +225,7 @@ public class Uniprot extends DbSourceProxyImpl if ("EMBL".equals(pdb.getType())) { // look for a CDS reference and add it, too. - String cdsId = (String) pdb.getProperty() - .get("protein sequence ID"); + String cdsId = (String) pdb.getProperty("protein sequence ID"); if (cdsId != null && cdsId.trim().length() > 0) { // remove version @@ -245,8 +244,7 @@ public class Uniprot extends DbSourceProxyImpl * * */ - String cdsId = (String) pdb.getProperty() - .get("protein sequence ID"); + String cdsId = (String) pdb.getProperty("protein sequence ID"); if (cdsId != null && cdsId.trim().length() > 0) { dbr = new DBRefEntry(DBRefSource.ENSEMBL, DBRefSource.UNIPROT diff --git a/test/jalview/datamodel/PDBEntryTest.java b/test/jalview/datamodel/PDBEntryTest.java index 979fee4..e9d5cb2 100644 --- a/test/jalview/datamodel/PDBEntryTest.java +++ b/test/jalview/datamodel/PDBEntryTest.java @@ -32,8 +32,6 @@ import static org.testng.Assert.fail; import jalview.datamodel.PDBEntry.Type; -import java.util.Hashtable; - //import org.testng.Assert; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; @@ -101,17 +99,17 @@ public class PDBEntryTest assertNotEquals(case9, case10); // add properties - case7.getProperty().put("hello", "world"); + case7.setProperty("hello", "world"); assertNotEquals(case7, case9); - case9.getProperty().put("hello", "world"); + case9.setProperty("hello", "world"); assertEquals(case7, case9); - case9.getProperty().put("hello", "WORLD"); + case9.setProperty("hello", "WORLD"); assertNotEquals(case7, case9); /* * change string wrapper property to string... */ - case1.getProperty().put("chain_code", "a"); + case1.setProperty("chain_code", "a"); assertFalse(pdbEntry.equals(case1)); assertFalse(case1.equals(pdbEntry)); } @@ -245,28 +243,23 @@ public class PDBEntryTest */ pdb1 = new PDBEntry("3A6S", null, null, null); pdb2 = new PDBEntry("3A6S", null, null, null); - // ughh properties not null if chain code has been set... - // JAL-2196 addresses this - pdb1.properties = new Hashtable(); - pdb2.properties = new Hashtable(); - pdb1.properties.put("destination", "mars"); - pdb1.properties.put("hello", "world"); - pdb2.properties.put("hello", "moon"); - pdb2.properties.put("goodbye", "world"); + pdb1.setProperty("destination", "mars"); + pdb1.setProperty("hello", "world"); + pdb2.setProperty("hello", "moon"); + pdb2.setProperty("goodbye", "world"); assertTrue(pdb1.updateFrom(pdb2)); - assertEquals(pdb1.properties.get("destination"), "mars"); - assertEquals(pdb1.properties.get("hello"), "moon"); - assertEquals(pdb1.properties.get("goodbye"), "world"); + assertEquals(pdb1.getProperty("destination"), "mars"); + assertEquals(pdb1.getProperty("hello"), "moon"); + assertEquals(pdb1.getProperty("goodbye"), "world"); /* * add properties only */ pdb1 = new PDBEntry("3A6S", null, null, null); pdb2 = new PDBEntry("3A6S", null, null, null); - pdb2.properties = new Hashtable(); - pdb2.properties.put("hello", "moon"); + pdb2.setProperty("hello", "moon"); assertTrue(pdb1.updateFrom(pdb2)); - assertEquals(pdb1.properties.get("hello"), "moon"); + assertEquals(pdb1.getProperty("hello"), "moon"); } @Test(groups = { "Functional" }) diff --git a/test/jalview/ws/dbsources/UniprotTest.java b/test/jalview/ws/dbsources/UniprotTest.java index 77f8078..4b88b2b 100644 --- a/test/jalview/ws/dbsources/UniprotTest.java +++ b/test/jalview/ws/dbsources/UniprotTest.java @@ -21,6 +21,7 @@ package jalview.ws.dbsources; import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.assertFalse; import static org.testng.AssertJUnit.assertNotNull; import static org.testng.AssertJUnit.assertNull; @@ -117,25 +118,21 @@ public class UniprotTest PDBEntry xref = xrefs.get(0); assertEquals("2FSQ", xref.getId()); assertEquals("PDB", xref.getType()); - assertEquals(2, xref.getProperty().size()); - assertEquals("X-ray", xref.getProperty().get("method")); - assertEquals("1.40", xref.getProperty().get("resolution")); + assertEquals("X-ray", xref.getProperty("method")); + assertEquals("1.40", xref.getProperty("resolution")); xref = xrefs.get(1); assertEquals("2FSR", xref.getId()); assertEquals("PDBsum", xref.getType()); - assertNull(xref.getProperty()); + assertFalse(xref.getProperties().hasMoreElements()); xref = xrefs.get(2); assertEquals("AE007869", xref.getId()); assertEquals("EMBL", xref.getType()); - assertNotNull(xref.getProperty()); assertEquals("AAK85932.1", - (String) xref.getProperty().get("protein sequence ID")); + xref.getProperty("protein sequence ID")); assertEquals("Genomic_DNA", - (String) xref.getProperty().get("molecule type")); - assertEquals(2, xref.getProperty().size()); - + xref.getProperty("molecule type")); } @Test(groups = { "Functional" })