Repository navigation
Expand file tree
/
Copy pathTestStructureCrossReferences.java
More file actions
287 lines (207 loc) · 8.85 KB
/
Copy pathTestStructureCrossReferences.java
File metadata and controls
287 lines (207 loc) · 8.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/*
* BioJava development code
*
* This code may be freely distributed and modified under the
* terms of the GNU Lesser General Public Licence. This should
* be distributed with the code. If you do not have a copy,
* see:
*
* http://www.gnu.org/copyleft/lesser.html
*
* Copyright for this code is held jointly by the individual
* authors. These should be listed in @author doc comments.
*
* For more information on the BioJava project and its aims,
* or to join the biojava-l mailing list, visit the home page
* at:
*
* http://www.biojava.org/
*
*/
package org.biojava.nbio.structure;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.List;
import org.biojava.nbio.structure.align.util.AtomCache;
import org.biojava.nbio.structure.contact.StructureInterface;
import org.biojava.nbio.structure.contact.StructureInterfaceList;
import org.biojava.nbio.structure.io.FileParsingParameters;
import org.biojava.nbio.structure.xtal.CrystalBuilder;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestStructureCrossReferences {
private static final Logger logger = LoggerFactory.getLogger(TestStructureCrossReferences.class);
private static final String PDBCODE1 = "1smt";
private static final String PDBCODE2 = "2mre";
@Test
public void testCrossReferencesMmCif() throws IOException, StructureException {
boolean emptySeqRes = true;
AtomCache cache = new AtomCache();
cache.setUseMmCif(true);
FileParsingParameters params = new FileParsingParameters();
params.setAlignSeqRes(false); // Store empty seqres groups.
cache.setFileParsingParams(params);
StructureIO.setAtomCache(cache);
Structure structure = StructureIO.getStructure(PDBCODE1);
//System.out.println("Testing references in mmCIF loading with NO alignSeqRes");
doFullTest(structure, emptySeqRes);
structure = StructureIO.getStructure(PDBCODE2); // an NMR entry with 2 chains
doFullTest(structure, emptySeqRes);
}
@Test
public void testCrossReferencesMmCifAlignSeqRes() throws IOException, StructureException {
boolean emptySeqRes = false;
AtomCache cache = new AtomCache();
cache.setUseMmCif(true);
FileParsingParameters params = new FileParsingParameters();
params.setAlignSeqRes(true);
cache.setFileParsingParams(params);
StructureIO.setAtomCache(cache);
Structure structure = StructureIO.getStructure(PDBCODE1);
//System.out.println("Testing references in mmCIF loading with alignSeqRes");
doFullTest(structure, emptySeqRes);
structure = StructureIO.getStructure(PDBCODE2); // an NMR entry with 2 chains
doFullTest(structure, emptySeqRes);
}
@Test
public void testCrossReferencesPdb() throws IOException, StructureException {
boolean emptySeqRes = true;
AtomCache cache = new AtomCache();
cache.setUseMmCif(false);
FileParsingParameters params = new FileParsingParameters();
params.setAlignSeqRes(false); // Store empty seqres groups
cache.setFileParsingParams(params);
StructureIO.setAtomCache(cache);
Structure structure = StructureIO.getStructure(PDBCODE1);
doFullTest(structure, emptySeqRes);
structure = StructureIO.getStructure(PDBCODE2); // an NMR entry with 2 chains
doFullTest(structure, emptySeqRes);
}
@Test
public void testCrossReferencesPdbAlignSeqRes() throws IOException, StructureException {
boolean emptySeqRes = false;
AtomCache cache = new AtomCache();
cache.setUseMmCif(false);
FileParsingParameters params = new FileParsingParameters();
params.setAlignSeqRes(true);
cache.setFileParsingParams(params);
StructureIO.setAtomCache(cache);
//System.out.println("Testing references in PDB loading with alignSeqRes");
Structure structure = StructureIO.getStructure(PDBCODE1);
doFullTest(structure, emptySeqRes);
structure = StructureIO.getStructure(PDBCODE2); // an NMR entry with 2 chains
doFullTest(structure, emptySeqRes);
}
//@Test
public void testCrossReferencesRawFile() throws IOException, StructureException {
// TODO implement
}
private void doFullTest(Structure structure, boolean emptySeqRes) throws StructureException {
//System.out.println("Testing references in original structure");
testStructureRefs(structure, emptySeqRes);
logger.debug("Original structure mem hashCode: {}",System.identityHashCode(structure));
Structure structureCopy = structure.clone();
logger.debug("Clone structure mem hashCode: {}",System.identityHashCode(structureCopy));
assertNotSame(structure, structureCopy);
//System.out.println("Testing references in cloned structure");
testStructureRefs(structureCopy, emptySeqRes);
logger.debug("Original structure mem hashCode after cloning: {}",System.identityHashCode(structure));
//System.out.println("Testing references in original structure after having cloned it");
// we test again the original after cloning it, perhaps some references were mixed while cloning
// there is a bug in ChainImpl.clone() that mixes them up!
testStructureRefs(structure, emptySeqRes);
//System.out.println("Testing references of chain clones");
for (Chain c:structure.getChains()) {
Chain clonedChain = (Chain) c.clone();
testChainRefs(clonedChain, emptySeqRes);
}
//System.out.println("Testing references in atom arrays");
for (Chain c:structure.getChains()) {
Atom[] atomArray = StructureTools.getAllAtomArray(c);
testAtomArrayRefs(atomArray, c);
}
CrystalBuilder cb = new CrystalBuilder(structure);
StructureInterfaceList interfaces = cb.getUniqueInterfaces();
for (StructureInterface interf:interfaces) {
testInterfaceRefs(structure, interf);
}
//System.out.println("Testing references in original structure after getUniqueInterfaces");
testStructureRefs(structure, emptySeqRes);
}
private void testStructureRefs(Structure s, boolean emptySeqRes) throws StructureException {
// structure, chain, group, atom linking
for (Chain c:s.getChains()) {
logger.debug("Expected parent structure mem hashCode: {}",System.identityHashCode(s));
logger.debug("Actual parent structure mem hashCode: {}",System.identityHashCode(c.getStructure()));
assertSame(s, c.getStructure());
testChainRefs(c, emptySeqRes);
}
// compounds linking
for (EntityInfo compound:s.getEntityInfos()) {
for (Chain c:compound.getChains()) {
assertSame(compound, c.getEntityInfo());
int count = 0;
for (int modelNr=0;modelNr<s.nrModels();modelNr++) {
// the chain must be matched by 1 and only 1 chain from all models
Chain cFromStruc = s.getChain(c.getId(), modelNr);
if (cFromStruc==c) count++;
}
assertEquals("Only 1 chain must match the compound chain for all models",1,count);
}
}
}
private void testChainRefs(Chain c, boolean emptySeqRes) {
assertNotNull(c.getEntityInfo());
for (Group g:c.getAtomGroups()) {
assertSame("Failed parent chain for group "+g.toString(), c, g.getChain());
for (Atom a:g.getAtoms()) {
assertSame(g, a.getGroup());
assertSame(c, a.getGroup().getChain());
}
// the SEQRES groups should contain a reference to each and every ATOM group
// (of course they will also contain some extra groups: those that are only in SEQRES)
if (c.getSeqResGroups().size()>0) {
// we don't want to test hetatoms that are most likely outside of the seqres defined chains
if (g.getType() == GroupType.HETATM) continue;
// Only test for expected Atom(s) if we parsed Atoms into Structure.
if (!emptySeqRes)
assertTrue("SeqResGroups should contain ATOM group "+g.toString(),
containsReference(g, c.getSeqResGroups()) );
}
}
for (Group g:c.getSeqResGroups()) {
// When not aligned, this can be different.
if (!emptySeqRes)
assertSame("Failed parent chain for group "+g.toString(), c, g.getChain());
for (Atom a:g.getAtoms()) {
assertSame(g, a.getGroup());
assertSame(c, a.getGroup().getChain());
}
}
}
private void testAtomArrayRefs(Atom[] atoms, Chain c) {
for (Atom a:atoms) {
//"Not same: "+c.getChainID()+" ("+c.getAtomLength()+" atomLength, "+c.getSeqResLength()+" seqresLength)"+" | "+a.getGroup().getChain().getChainID()+" ("+a.getGroup().getChain().getAtomLength()+" atomLength, "+a.getGroup().getChain().getSeqResLength()+" seqresLength)"
assertSame(c, a.getGroup().getChain());
}
}
private void testInterfaceRefs(Structure s, StructureInterface i) throws StructureException {
for (Atom a:i.getMolecules().getFirst()) {
assertNotNull(a.getGroup().getChain().getEntityInfo());
}
for (Atom a:i.getMolecules().getSecond()) {
assertNotNull(a.getGroup().getChain().getEntityInfo());
}
}
private static boolean containsReference(Group g, List<Group> list) {
for (Group group:list) {
if (group==g) return true;
}
return false;
}
}