Skip to content

Commit 9e8874d

Browse files
committed
Merge branch 'master' into cesymm
2 parents d66cc12 + 43c8013 commit 9e8874d

15 files changed

Lines changed: 1055 additions & 238 deletions

File tree

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import java.util.List;
3131
import java.util.Set;
3232

33-
import org.junit.Before;
33+
import org.junit.BeforeClass;
3434
import org.junit.Test;
3535

3636
import static org.junit.Assert.*;
@@ -44,10 +44,10 @@
4444

4545
public class StructureTest {
4646

47-
private Structure structure;
47+
private static Structure structure;
4848

49-
@Before
50-
public void setUp() throws IOException {
49+
@BeforeClass
50+
public static void setUp() throws IOException {
5151
InputStream inStream = StructureTest.class.getResourceAsStream("/5pti_old.pdb");
5252
assertNotNull(inStream);
5353

@@ -113,7 +113,10 @@ public void testReadPDBFile() throws Exception {
113113
assertTrue(c2.getAtomGroups(GroupType.NUCLEOTIDE).size() == 0 );
114114

115115
List<Compound> compounds= structure.getCompounds();
116-
assertTrue(compounds.size() == 1);
116+
117+
// from Biojava 4.2 on we are creating compounds whenever an entity is found to be without an assigned compound in the file
118+
// see issues https://github.com/biojava/biojava/issues/305 and https://github.com/biojava/biojava/pull/394
119+
assertEquals(2, compounds.size());
117120
Compound mol = compounds.get(0);
118121
assertTrue(mol.getMolName().startsWith("TRYPSIN INHIBITOR"));
119122
}
@@ -183,7 +186,10 @@ public void testPDBHeader(){
183186

184187

185188
List <Compound> compounds = structure.getCompounds();
186-
assertEquals("did not find the right number of compounds! ", 1, compounds.size());
189+
190+
// from Biojava 4.2 on we are creating compounds whenever an entity is found to be without an assigned compound in the file
191+
// see issues https://github.com/biojava/biojava/issues/305 and https://github.com/biojava/biojava/pull/394
192+
assertEquals("did not find the right number of compounds! ", 2, compounds.size());
187193

188194
Compound comp = compounds.get(0);
189195
assertEquals("did not get the right compounds info",true,comp.getMolName().startsWith("TRYPSIN INHIBITOR"));

biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestLongPdbVsMmCifParsing.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public void testVeryLongPdbVsMmCif() throws IOException, StructureException {
124124

125125
@Test
126126
public void testSingle() throws IOException, StructureException {
127-
testAll(Arrays.asList("4a10"));
127+
testAll(Arrays.asList("2h5d"));
128128
}
129129

130130
@After
@@ -221,6 +221,12 @@ private void testStructureMethods(Structure sPdb, Structure sCif) {
221221
assertEquals("failed number of Compounds pdb vs cif", sPdb.getCompounds().size(), sCif.getCompounds().size());
222222

223223

224+
// ss bonds
225+
// 4ab9 contains an error in ssbond in pdb file (misses 1 ssbond)
226+
// 2bdi contains also errors, the counts in both differ a lot 80 vs 92
227+
if (!sPdb.getPDBCode().equals("4AB9") && !sPdb.getPDBCode().equals("2BDI"))
228+
assertEquals("number of ss bonds should coincide pdb vs cif", sPdb.getSSBonds().size(), sCif.getSSBonds().size());
229+
224230
}
225231

226232
private void testHeader(Structure sPdb, Structure sCif) {

biojava-structure/src/main/java/org/biojava/nbio/structure/SSBond.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424

2525
import java.io.Serializable;
2626

27-
/** A simple bean to store disulfide bridge information, the SSBOND records in the PDB files.
27+
/**
28+
* A simple bean to store disulfide bridge information, the SSBOND records in the PDB files.
2829
*
2930
* The two residues specified here are CYS residues that form a Disulfide bridge.
3031
*
@@ -38,7 +39,7 @@ public interface SSBond extends PDBRecord, Serializable, Cloneable {
3839
public String toPDB();
3940

4041
/**
41-
* append the PDB representation of this SSBOND to the provided StringBUffer
42+
* Append the PDB representation of this SSBOND to the provided StringBUffer
4243
*
4344
* @param buf a StringBuffer to print the PDB representation to
4445
*/
@@ -54,14 +55,14 @@ public interface SSBond extends PDBRecord, Serializable, Cloneable {
5455
public void setInsCode2(String insCode2);
5556

5657
/**
57-
* set serial number of this SSBOND in PDB file
58+
* Set serial number of this SSBOND in PDB file
5859
*
5960
* @return the serial number
6061
*/
6162
public int getSerNum();
6263

6364
/**
64-
* get serial number of this SSBOND in PDB file
65+
* Get serial number of this SSBOND in PDB file
6566
*
6667
* @param serNum
6768
*/
@@ -76,7 +77,7 @@ public interface SSBond extends PDBRecord, Serializable, Cloneable {
7677
public void setChainID2(String chainID2);
7778

7879
/**
79-
* get residue number for first CYS. number and insertion code are joint
80+
* Get residue number for first CYS. number and insertion code are joined
8081
* together.
8182
*
8283
* @return the residue number of the first CYS.
@@ -87,7 +88,7 @@ public interface SSBond extends PDBRecord, Serializable, Cloneable {
8788
public void setResnum1(String resnum1);
8889

8990
/**
90-
* get residue number for second CYS. number and insertion code are joint
91+
* Get residue number for second CYS. number and insertion code are joined
9192
* together.
9293
*
9394
* @return the residue number of the second CYS.

biojava-structure/src/main/java/org/biojava/nbio/structure/SSBondImpl.java

Lines changed: 76 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525

2626
import java.io.Serializable;
2727

28-
/** A simple bean to store disulfide bridge information, the SSBOND records in the PDB files.
28+
/**
29+
* A simple bean to store disulfide bridge information, the SSBOND records in the PDB files.
2930
*
3031
* The two residues specified here are CYS residues that form a Disulfide bridge.
3132
*
@@ -38,13 +39,14 @@ public class SSBondImpl implements PDBRecord, Serializable, Cloneable, SSBond {
3839

3940
private static final long serialVersionUID = -8663681100691188647L;
4041

41-
int serNum;
42-
String chainID1;
43-
String chainID2;
44-
String resnum1;
45-
String resnum2;
46-
String insCode1;
47-
String insCode2;
42+
private int serNum;
43+
44+
private String chainID1;
45+
private String chainID2;
46+
private String resnum1;
47+
private String resnum2;
48+
private String insCode1;
49+
private String insCode2;
4850

4951
public SSBondImpl(){
5052
serNum = 0;
@@ -59,7 +61,8 @@ public String toPDB(){
5961
return buf.toString();
6062
}
6163

62-
/** append the PDB representation of this SSBOND to the provided StringBUffer
64+
/**
65+
* Append the PDB representation of this SSBOND to the provided StringBuffer
6366
*
6467
* @param buf a StringBuffer to print the PDB representation to
6568
*/
@@ -110,10 +113,7 @@ public void setInsCode2(String insCode2) {
110113
this.insCode2 = insCode2;
111114
}
112115

113-
/** set serial number of this SSBOND in PDB file
114-
*
115-
* @return the serial number
116-
*/
116+
117117
@Override
118118
public int getSerNum() {
119119
return serNum;
@@ -155,12 +155,7 @@ public void setChainID2(String chainID2) {
155155
this.chainID2 = chainID2;
156156
}
157157

158-
/** get residue number for first CYS.
159-
* number and insertion code are joint together.
160-
*
161-
* @return the residue number of the first CYS.
162-
*
163-
*/
158+
164159
@Override
165160
public String getResnum1() {
166161
return resnum1;
@@ -170,12 +165,7 @@ public void setResnum1(String resnum1) {
170165
this.resnum1 = resnum1;
171166
}
172167

173-
/** get residue number for second CYS.
174-
* number and insertion code are joint together.
175-
*
176-
* @return the residue number of the second CYS.
177-
*
178-
*/
168+
179169
@Override
180170
public String getResnum2() {
181171
return resnum2;
@@ -203,4 +193,65 @@ public String toString() {
203193

204194
return s;
205195
}
196+
197+
/* (non-Javadoc)
198+
* @see java.lang.Object#hashCode()
199+
*/
200+
@Override
201+
public int hashCode() {
202+
final int prime = 31;
203+
int result = 1;
204+
result = prime * result + ((chainID1 == null) ? 0 : chainID1.hashCode());
205+
result = prime * result + ((chainID2 == null) ? 0 : chainID2.hashCode());
206+
result = prime * result + ((insCode1 == null) ? 0 : insCode1.hashCode());
207+
result = prime * result + ((insCode2 == null) ? 0 : insCode2.hashCode());
208+
result = prime * result + ((resnum1 == null) ? 0 : resnum1.hashCode());
209+
result = prime * result + ((resnum2 == null) ? 0 : resnum2.hashCode());
210+
return result;
211+
}
212+
213+
/* (non-Javadoc)
214+
* @see java.lang.Object#equals(java.lang.Object)
215+
*/
216+
@Override
217+
public boolean equals(Object obj) {
218+
if (this == obj)
219+
return true;
220+
if (obj == null)
221+
return false;
222+
if (getClass() != obj.getClass())
223+
return false;
224+
SSBondImpl other = (SSBondImpl) obj;
225+
if (chainID1 == null) {
226+
if (other.chainID1 != null)
227+
return false;
228+
} else if (!chainID1.equals(other.chainID1))
229+
return false;
230+
if (chainID2 == null) {
231+
if (other.chainID2 != null)
232+
return false;
233+
} else if (!chainID2.equals(other.chainID2))
234+
return false;
235+
if (insCode1 == null) {
236+
if (other.insCode1 != null)
237+
return false;
238+
} else if (!insCode1.equals(other.insCode1))
239+
return false;
240+
if (insCode2 == null) {
241+
if (other.insCode2 != null)
242+
return false;
243+
} else if (!insCode2.equals(other.insCode2))
244+
return false;
245+
if (resnum1 == null) {
246+
if (other.resnum1 != null)
247+
return false;
248+
} else if (!resnum1.equals(other.resnum1))
249+
return false;
250+
if (resnum2 == null) {
251+
if (other.resnum2 != null)
252+
return false;
253+
} else if (!resnum2.equals(other.resnum2))
254+
return false;
255+
return true;
256+
}
206257
}

biojava-structure/src/main/java/org/biojava/nbio/structure/io/CompoundFinder.java

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
import org.slf4j.LoggerFactory;
4040

4141
import java.util.ArrayList;
42+
import java.util.Collections;
43+
import java.util.Comparator;
4244
import java.util.HashMap;
4345
import java.util.List;
4446
import java.util.Map;
@@ -93,7 +95,11 @@ public List<Compound> findCompounds() {
9395

9496
TreeMap<String,Compound> chainIds2entities = findCompoundsFromAlignment();
9597

96-
return findUniqueCompounds(chainIds2entities);
98+
List<Compound> compounds = findUniqueCompounds(chainIds2entities);
99+
100+
createPurelyNonPolyCompounds(compounds);
101+
102+
return compounds;
97103
}
98104

99105
/**
@@ -117,6 +123,42 @@ private static List<Compound> findUniqueCompounds(TreeMap<String,Compound> chain
117123
return list;
118124
}
119125

126+
private void createPurelyNonPolyCompounds(List<Compound> compounds) {
127+
128+
List<Chain> pureNonPolymerChains = new ArrayList<Chain>();
129+
for (int i=0;i<s.getChains().size();i++) {
130+
if (StructureTools.isChainPureNonPolymer(s.getChain(i))) {
131+
pureNonPolymerChains.add(s.getChain(i));
132+
}
133+
}
134+
135+
if (!pureNonPolymerChains.isEmpty()) {
136+
137+
int maxMolId = 0; // if we have no compounds at all we just use 0, so that first assignment is 1
138+
if (!compounds.isEmpty()) {
139+
Collections.max(compounds, new Comparator<Compound>() {
140+
@Override
141+
public int compare(Compound o1, Compound o2) {
142+
return new Integer(o1.getMolId()).compareTo(o2.getMolId());
143+
}
144+
}).getMolId();
145+
}
146+
147+
int molId = maxMolId + 1;
148+
// for the purely non-polymeric chains we assign additional compounds
149+
for (Chain c: pureNonPolymerChains) {
150+
Compound comp = new Compound();
151+
comp.addChain(c);
152+
comp.setMolId(molId);
153+
logger.warn("Chain {} is purely non-polymeric, will assign a new Compound (entity) to it (entity id {})", c.getChainID(), molId);
154+
molId++;
155+
156+
compounds.add(comp);
157+
}
158+
159+
}
160+
}
161+
120162

121163
private static boolean areResNumbersAligned(Chain c1, Chain c2) {
122164

@@ -167,13 +209,13 @@ private TreeMap<String,Compound> findCompoundsFromAlignment() {
167209
// first we determine which chains to consider: anything not looking
168210
// polymeric (protein or nucleotide chain) should be discarded
169211
Set<Integer> polyChainIndices = new TreeSet<Integer>();
212+
List<Chain> pureNonPolymerChains = new ArrayList<Chain>();
170213
for (int i=0;i<s.getChains().size();i++) {
171214
if (StructureTools.isChainPureNonPolymer(s.getChain(i))) {
172-
logger.warn("Chain {} is purely non-polymeric, will not assign a Compound (entity) to it", s.getChain(i).getChainID());
173-
continue;
215+
pureNonPolymerChains.add(s.getChain(i));
216+
} else {
217+
polyChainIndices.add(i);
174218
}
175-
176-
polyChainIndices.add(i);
177219
}
178220

179221

0 commit comments

Comments
 (0)