Skip to content

Commit 12d348d

Browse files
authored
Support extended pdbid (#950)
* Support for extended PDBID PDB_nnnnNXXX Created a new class PDBId, and removed old deprecated methods. Most of the changes are in Structure, StructureImpl, and PDBFileParser classes. * Some deprecated functions removal * Fix typo * Targeted most of Spencer's comments * Fixed a bug in PDBId.equals() method * Changing PDBID in SCOP record to lower case to match the expected String * public static PDBId field XXXX * Behavior is now an enum * Expose Pattern objects instead of Strings * ID stored internally in a reduced format (without initial "PDB_" prefix) Only the ID proper is stored (in upper case). e.g. for 1abc we store 00001ABC. This format is the trade off between storing short/extended format and all extended format. storing the ID proper allows direct comparison and fast ordering of PDBId objects with uniform names in the format \d{4}[1-9][0-9A-Z]{3}. * Enhancements and bug fix * Added BDBId Unit test * Added @deprecated codeTag * Adding more TODOs * more replacement of deprecated methods * Removed PDBIdException I replaced the PDBException with IllegalArgumentException or StructureException: - Constant literal extraction - Inlined short private methods - Renamed isShortPDBId() and isExtendedPDBID() to isValidShortPDBID() and isValidExtendedPDBID() Additional modifications: - Organized imports * review and untouch regular expressions * Un-deprecate, copy javadoc, and remove @author on methods * Remove NullPointerException I will write the full class javadoc later * Bug fix * clean commented out code * Update CHANGELOG Mentioned that getReducedStructure() is removed from StructureTools * Fix unit test I accident.y found that the test case is not written as it should be. * PdbPair does not accept null It also considers an object and its reverse equal * Addressing reviewer's comments * Change capitalization state - Class name: changed into PdbId - methods name: changed into getPdbId(), setPdbId(PdbId) - field name: pdbId * Fix probable NPE + keep consistent PdbId method naming convention * Addressed some of the reviewer's comments. * Use JUnit 5 * PdbId class Documentation * JavaDoc style update * Minor updates * Reverting a wrong optimization It introduced a new bug. Reverting it. * Adding BioJava development code * Javadoc * XXXX PdbId objects are not equal unless they are the same object * No more XXXX. ANY malformed PdbId gracefully set to null * Addressing Reviewer's comments * Removing TODOs
1 parent d205caa commit 12d348d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1206
-412
lines changed

CHANGELOG.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ BioJava 6.0.0 (future release)
2020
* Removed `org.biojava.nbio.structure.io.mmtf.MmtfUtils.setUpBioJava()`
2121
* Removed from `org.biojava.nbio.structure.Chain` interface: `getParent()`, `setParent()`, `getAtomLigands()`, `getSwissprotId()`, `setSwissprotId()`, `getInternalChainID()`, `setInternalChainID()`, `getChainID()`, `setChainID()`
2222
* Removed from `org.biojava.nbio.structure.Structure` interface: `findChain()`, `getId()`, `setId()`, `getChainByPDB()`, `getCompoundById()`, `getResidueRanges()`, `getRanges()`
23-
* Removed from `org.biojava.nbio.structure.StructureTools` : `isNucleicAcid()`, `isProtein()`, `getPredominantGroupType()`, `isChainWaterOnly()`, `isChainPureNonPolymer()`
23+
* Removed from `org.biojava.nbio.structure.StructureTools` : `isNucleicAcid()`, `isProtein()`, `getPredominantGroupType()`, `isChainWaterOnly()`, `isChainPureNonPolymer()`, `getReducedStructure()`
2424
* Removed `org.biojava.nbio.structure.io.SandboxStyleStructureProvider`
2525
* In `org.biojava.nbio.structure.align.xml.MultipleAlignmentXMLParser` made all methods private except `parseXMLfile`
2626

@@ -32,14 +32,15 @@ BioJava 6.0.0 (future release)
3232
* Moved all chem-comp model classes from `org.biojava.nbio.structure.io.mmcif.chem` to `org.biojava.nbio.structure.chem`
3333
* Moved all chem-comp parsing classes from `org.biojava.nbio.structure.io.mmcif.chem` to `org.biojava.nbio.structure.io.cif`
3434
* Moved classes in `org.biojava.nbio.structure.io.mmcif` to `org.biojava.nbio.structure.chem`
35-
* Fixed `CRC64Checksum#public void update(byte[] b, int offset, int length)` to use
36-
the `length` argument correctly as specified in `java.util.zip.Checksum` interface.
37-
* Removed `DownloadChemCompProvider.useDefaultUrlLayout` with a more flexible system to provide templated URLs `DownloadChemCompProvider.setChemCompPathUrlTemplate()`
38-
and `DownloadChemCompProvider.setServerBaseUrl()`
35+
* Fixed `CRC64Checksum#public void update(byte[] b, int offset, int length)` to use the `length` argument correctly as specified in `java.util.zip.Checksum` interface.
36+
* In `SubstructureIdentifier`, `StructureName`, `EcodDomain`, `ScopDomain` : `getPdbId()` returns `PdbId` object instead of `String`.
37+
* Removed `DownloadChemCompProvider.useDefaultUrlLayout` with a more flexible system to provide templated URLs `DownloadChemCompProvider.setChemCompPathUrlTemplate()` and `DownloadChemCompProvider.setServerBaseUrl()`
38+
* In `Structure` (and `StructureImple`), the accessor methods `String getPdbId()` and `setPdbId(String)` were previously depricated. They were revived in BioJava 6.0.0 but as `PdbId getPdbId()` and `setPdbId(PdbId)` instead.n
3939

4040
### Added
41-
* New keywords fields in `PDBHeader` class, populated by PDB and mmCIF parsers #946
41+
* New `keywords` field in `PDBHeader` class, populated by PDB and mmCIF parsers #946
4242
* OBO parsing now supports multiple altids, #960
43+
* New class `PdbId` that wrapps a PDB Identifier and handles conversion between current short PDBID format and upcoming extended PDBID format #930
4344

4445
### Fixed
4546
* Correct chain assignment to entities when parsing PDB/mmCIF without entity information (in cases with more than 3 chains per entity) #931

biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/Test1a4w.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ public void setUp() throws Exception {
6767

6868

6969
@Test
70-
public void test1a4wPDBFile() throws IOException
71-
{
70+
public void test1a4wPDBFile() throws IOException {
7271

7372
// structure = null;
7473

biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/cath/CathDomainTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*/
2121
package org.biojava.nbio.structure.test.cath;
2222

23+
import org.biojava.nbio.structure.StructureException;
2324
import org.biojava.nbio.structure.cath.CathDomain;
2425
import org.biojava.nbio.structure.cath.CathFactory;
2526
import org.junit.Test;
@@ -33,9 +34,9 @@
3334
*/
3435
public class CathDomainTest {
3536
@Test
36-
public void test() {
37+
public void test() throws StructureException {
3738
String id = "1qvrC03";
3839
CathDomain domain = CathFactory.getCathDatabase().getDomainByCathId(id);
39-
assertEquals("1qvr.C_332-400,C_514-540", domain.toCanonical().getIdentifier());
40+
assertEquals("1QVR.C_332-400,C_514-540", domain.toCanonical().getIdentifier());
4041
}
4142
}

biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/ecod/EcodParseTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private static int testVersion(String ecodVersion) throws IOException {
8383
Atom[] ca1;
8484
Structure struct;
8585
try {
86-
struct = cache.getStructure(d.getPdbId());
86+
struct = cache.getStructure(d.getPdbId().getId());
8787
ca1 = StructureTools.getRepresentativeAtomArray(struct);
8888
} catch (IOException e) {
8989
logger.error("Error getting structure for "+d.getDomainId(),e);

biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/gui/SelectPDBPanel.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@
2323
import java.awt.BorderLayout;
2424
import java.awt.Dimension;
2525
import java.io.IOException;
26+
import java.util.ArrayList;
2627

2728
import javax.swing.Box;
2829
import javax.swing.JLabel;
2930
import javax.swing.JPanel;
3031
import javax.swing.JTabbedPane;
3132
import javax.swing.JTextField;
3233

34+
import org.biojava.nbio.structure.PdbId;
3335
import org.biojava.nbio.structure.ResidueRange;
3436
import org.biojava.nbio.structure.Structure;
3537
import org.biojava.nbio.structure.StructureException;
@@ -106,30 +108,32 @@ public SelectPDBPanel(boolean show2PDBs) {
106108
}
107109

108110
public StructureIdentifier getName1() {
109-
String pdbId = f1.getText().trim();
111+
String id = f1.getText().trim();
110112
String chainId = c1.getText().trim();
111113
String range = r1.getText().trim();
112-
114+
115+
PdbId pdbId = new PdbId(id);
113116
// Prefer range over chain
114117
if( ! range.isEmpty() ) {
115118
return new SubstructureIdentifier(pdbId, ResidueRange.parseMultiple(range));
116119
} else if ( ! chainId.isEmpty() ){
117120
return new SubstructureIdentifier(pdbId, ResidueRange.parseMultiple(chainId));
118121
}
119-
return new SubstructureIdentifier(pdbId);
122+
return new SubstructureIdentifier(pdbId, new ArrayList<ResidueRange>());
120123
}
121124
public StructureIdentifier getName2() {
122-
String pdbId = f2.getText().trim();
125+
String id = f2.getText().trim();
123126
String chainId = c2.getText().trim();
124127
String range = r2.getText().trim();
125-
128+
129+
PdbId pdbId = new PdbId(id);
126130
// Prefer range over chain
127131
if( ! range.isEmpty() ) {
128132
return new SubstructureIdentifier(pdbId, ResidueRange.parseMultiple(range));
129133
} else if ( ! chainId.isEmpty() ){
130134
return new SubstructureIdentifier(pdbId, ResidueRange.parseMultiple(chainId));
131135
}
132-
return new SubstructureIdentifier(pdbId);
136+
return new SubstructureIdentifier(pdbId, new ArrayList<ResidueRange>());
133137
}
134138
@Override
135139
public Structure getStructure1() throws StructureException, IOException{

biojava-structure-gui/src/main/java/org/biojava/nbio/structure/gui/util/PDBDirPanel.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package org.biojava.nbio.structure.gui.util;
2424

2525
import org.biojava.nbio.structure.Chain;
26+
import org.biojava.nbio.structure.PdbId;
2627
import org.biojava.nbio.structure.Structure;
2728
import org.biojava.nbio.structure.StructureException;
2829
import org.biojava.nbio.structure.StructureImpl;
@@ -97,17 +98,17 @@ public PDBDirPanel() {
9798

9899

99100
private Structure fromPDB(JTextField f, JTextField c) throws StructureException{
100-
String pdb = f.getText();
101+
String pdbIdString = f.getText();
101102

102103

103-
if ( pdb.length() < 4) {
104+
if ( pdbIdString.length() < 4) {
104105
f.setText("!!!");
105106
return null;
106107
}
107108

108109
String chain = c.getText();
109110
if ( debug )
110-
System.out.println("file :" + pdb + " " + chain);
111+
System.out.println("file :" + pdbIdString + " " + chain);
111112
/// prepare structures
112113

113114
// load them from the file system
@@ -123,19 +124,18 @@ private Structure fromPDB(JTextField f, JTextField c) throws StructureException{
123124
Structure tmp1 = new StructureImpl();
124125

125126
try {
126-
Structure structure1 = reader.getStructureById(pdb);
127+
Structure structure1 = reader.getStructureById(new PdbId(pdbIdString));
127128

128129
// no chain has been specified
129130
// return whole structure
130131
if (( chain == null) || (chain.length()==0)){
131132
return structure1;
132133
}
133134
if ( debug)
134-
System.out.println("using chain " + chain + " for structure " + structure1.getPDBCode());
135+
System.out.println("using chain " + chain + " for structure " + structure1.getPdbId().getId());
135136
Chain c1 = structure1.getPolyChainByPDB(chain);
136-
tmp1.setPDBCode(structure1.getPDBCode());
137137
tmp1.setPDBHeader(structure1.getPDBHeader());
138-
tmp1.setPDBCode(structure1.getPDBCode());
138+
tmp1.setPdbId(structure1.getPdbId());
139139
tmp1.addChain(c1);
140140
System.out.println("ok");
141141

biojava-structure-gui/src/main/java/org/biojava/nbio/structure/gui/util/PDBServerPanel.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
package org.biojava.nbio.structure.gui.util;
2525

2626
import org.biojava.nbio.structure.Chain;
27+
import org.biojava.nbio.structure.PdbId;
2728
import org.biojava.nbio.structure.Structure;
2829
import org.biojava.nbio.structure.StructureException;
2930
import org.biojava.nbio.structure.StructureImpl;
@@ -86,17 +87,17 @@ public PDBServerPanel() {
8687

8788

8889
private Structure fromPDB(JTextField f, JTextField c) throws StructureException{
89-
String pdb = f.getText();
90+
String pdbIdString = f.getText();
9091

9192

92-
if ( pdb.length() < 4) {
93+
if ( pdbIdString.length() < 4) {
9394
f.setText("!!!");
9495
return null;
9596
}
9697

9798
String chain = c.getText();
9899
if ( debug )
99-
System.out.println("file :" + pdb + " " + chain);
100+
System.out.println("file :" + pdbIdString + " " + chain);
100101
/// prepare structures
101102

102103
// load them from the file system
@@ -108,19 +109,18 @@ private Structure fromPDB(JTextField f, JTextField c) throws StructureException{
108109
Structure tmp1 = new StructureImpl();
109110

110111
try {
111-
Structure structure1 = reader.getStructureById(pdb);
112+
Structure structure1 = reader.getStructureById(new PdbId(pdbIdString));
112113

113114
// no chain has been specified
114115
// return whole structure
115116
if (( chain == null) || (chain.length()==0)){
116117
return structure1;
117118
}
118119
if ( debug)
119-
System.out.println("using chain " + chain + " for structure " + structure1.getPDBCode());
120+
System.out.println("using chain " + chain + " for structure " + structure1.getPdbId().getId());
120121
Chain c1 = structure1.getPolyChainByPDB(chain);
121-
tmp1.setPDBCode(structure1.getPDBCode());
122122
tmp1.setPDBHeader(structure1.getPDBHeader());
123-
tmp1.setPDBCode(structure1.getPDBCode());
123+
tmp1.setPdbId(structure1.getPdbId());
124124
tmp1.addChain(c1);
125125
System.out.println("ok");
126126

biojava-structure-gui/src/main/java/org/biojava/nbio/structure/gui/util/PDBUploadPanel.java

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,34 @@
2222
package org.biojava.nbio.structure.gui.util;
2323

2424

25+
import java.awt.Dimension;
26+
import java.awt.event.ActionEvent;
27+
import java.io.File;
28+
import java.io.IOException;
29+
import java.net.URL;
30+
import java.util.Arrays;
31+
32+
import javax.swing.AbstractAction;
33+
import javax.swing.Action;
34+
import javax.swing.Box;
35+
import javax.swing.JButton;
36+
import javax.swing.JComboBox;
37+
import javax.swing.JFileChooser;
38+
import javax.swing.JLabel;
39+
import javax.swing.JPanel;
40+
import javax.swing.JTextField;
41+
42+
import org.biojava.nbio.structure.ResidueRange;
2543
import org.biojava.nbio.structure.Structure;
2644
import org.biojava.nbio.structure.StructureException;
27-
import org.biojava.nbio.structure.StructureTools;
45+
import org.biojava.nbio.structure.SubstructureIdentifier;
2846
import org.biojava.nbio.structure.align.util.UserConfiguration;
2947
import org.biojava.nbio.structure.io.CifFileReader;
3048
import org.biojava.nbio.structure.io.PDBFileReader;
3149
import org.biojava.nbio.structure.io.StructureIOFile;
3250
import org.slf4j.Logger;
3351
import org.slf4j.LoggerFactory;
3452

35-
import javax.swing.*;
36-
import java.awt.*;
37-
import java.awt.event.ActionEvent;
38-
import java.io.File;
39-
import java.io.IOException;
40-
import java.net.URL;
41-
4253
/** A JPanel to upload 2 custom PDB files.
4354
*
4455
* @author Andreas Prlic
@@ -59,16 +70,16 @@ public class PDBUploadPanel
5970

6071

6172

62-
private JComboBox fileType ;
73+
private JComboBox<String> fileType ;
6374

6475
JTextField filePath1;
6576
JTextField filePath2;
6677
JTextField chain1;
6778
JTextField chain2;
6879

69-
public static JComboBox getFileFormatSelect(){
70-
JComboBox fileType = new JComboBox();
71-
fileType = new JComboBox(new String[] {UserConfiguration.PDB_FORMAT,UserConfiguration.MMCIF_FORMAT});
80+
public static JComboBox<String> getFileFormatSelect(){
81+
JComboBox<String> fileType = new JComboBox<>();
82+
fileType = new JComboBox<String>(new String[] {UserConfiguration.PDB_FORMAT,UserConfiguration.MMCIF_FORMAT});
7283
fileType.setSelectedIndex(0);
7384
fileType.setMaximumSize(new Dimension(10,50));
7485

@@ -150,7 +161,10 @@ private Structure getStructure(JTextField filePath,JTextField chainId) throws St
150161
throw new StructureException(e);
151162
}
152163

153-
Structure reduced = StructureTools.getReducedStructure(s, chainId.getText());
164+
// Structure reduced = StructureTools.getReducedStructure(s, chainId.getText());
165+
// Structure reduced = new SubstructureIdentifier(s.getPdbId().getId()+"."+ chainId.getText()).reduce(s); //TODO double check this
166+
Structure reduced = new SubstructureIdentifier(s.getPdbId(),
167+
Arrays.asList(new ResidueRange(chainId.getText(), (String) null, null))).reduce(s);
154168

155169
String fileURL = "";
156170
try {
@@ -169,7 +183,7 @@ private Structure getStructure(JTextField filePath,JTextField chainId) throws St
169183
e.printStackTrace();
170184
}
171185

172-
reduced.setPDBCode(fileURL);
186+
reduced.setPDBCode(fileURL); //TODO FIXME This usage seems wrong and should be changed.
173187
reduced.setName(fileURL);
174188
return reduced;
175189

biojava-structure/pom.xml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@
105105
<artifactId>log4j-core</artifactId>
106106
</dependency>
107107
<!-- Testing related dependencies -->
108-
109108
<dependency>
110109
<groupId>junit</groupId>
111110
<artifactId>junit</artifactId>
@@ -117,6 +116,19 @@
117116
<version>1.6</version>
118117
<scope>test</scope>
119118
</dependency>
119+
<!-- Junit5 dependencies, defined in parent pom. -->
120+
<dependency>
121+
<groupId>org.junit.jupiter</groupId>
122+
<artifactId>junit-jupiter-engine</artifactId>
123+
</dependency>
124+
<dependency>
125+
<groupId>org.junit.jupiter</groupId>
126+
<artifactId>junit-jupiter-params</artifactId>
127+
</dependency>
128+
<dependency>
129+
<groupId>org.junit.vintage</groupId>
130+
<artifactId>junit-vintage-engine</artifactId>
131+
</dependency>
120132

121133
</dependencies>
122134

0 commit comments

Comments
 (0)