Skip to content

Commit edb9e73

Browse files
committed
Crate Test for consistency in getting representative Atoms
1 parent b1bd534 commit edb9e73

File tree

1 file changed

+69
-52
lines changed

1 file changed

+69
-52
lines changed

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

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

2525
import junit.framework.TestCase;
26+
2627
import org.biojava.nbio.structure.*;
2728
import org.biojava.nbio.structure.align.util.AtomCache;
2829
import org.biojava.nbio.structure.io.FileParsingParameters;
@@ -35,7 +36,7 @@
3536

3637
public class StructureToolsTest extends TestCase {
3738

38-
Structure structure, structure2, structure3;
39+
Structure structure, structure2, structure3, structure4;
3940

4041
@Override
4142
protected void setUp() throws IOException
@@ -59,7 +60,7 @@ protected void setUp() throws IOException
5960

6061
Chain chain = structure.getChain(0);
6162
assertEquals("Wrong number of residues.",123,chain.getAtomLength());
62-
63+
6364
inStream.close();
6465

6566
// Load structure2
@@ -93,11 +94,27 @@ public void testGetCAAtoms(){
9394
assertEquals("did not find the expected number of Atoms (58), but got " + cas.length,58,cas.length);
9495
}
9596

97+
public void testGetAtomsConsistency() throws IOException, StructureException{
98+
AtomCache cache = new AtomCache();
99+
Structure hivA = cache.getStructure("1hiv.A");
100+
Atom[] caSa = StructureTools.getRepresentativeAtomArray(hivA);
101+
Atom[] caCa = StructureTools.getRepresentativeAtomArray(hivA.getChain(0));
102+
assertEquals("did not find the same number of Atoms from structure and from chain..",
103+
caSa.length,caCa.length);
104+
Structure hivB = cache.getStructure("1hiv.B");
105+
Atom[] caSb = StructureTools.getRepresentativeAtomArray(hivB);
106+
Atom[] caCb = StructureTools.getRepresentativeAtomArray(hivB.getChain(0));
107+
assertEquals("did not find the same number of Atoms from structure and from chain..",
108+
caSb.length,caCb.length);
109+
//Both chains have to be the same size (A and B)
110+
assertEquals(caSa.length,99);
111+
assertEquals("did not find the same number of Atoms in both chains...",
112+
caSa.length,caCb.length);
113+
}
114+
96115
public void testGetNrAtoms(){
97116
int length = StructureTools.getNrAtoms(structure);
98117
assertEquals("did not find the expected number of Atoms (1087), but got " + length,1087,length);
99-
100-
101118
}
102119

103120
public void testGetSubRanges() throws StructureException {
@@ -188,18 +205,18 @@ public void testGetSubRanges() throws StructureException {
188205
range = "_:";
189206
substr = StructureTools.getSubRanges(structure2, range);
190207
assertEquals("Wrong number of chains in "+range, 1, substr.size());
191-
208+
192209
chain = substr.getChain(0);
193210
assertEquals("Chain _ not converted to chain A.","A",chain.getChainID());
194211
assertEquals("Did not find the expected number of residues in first chain of "+range, 411, chain.getAtomLength() );
195-
212+
196213
try {
197214
// Illegal chain name
198215
range = "X:";
199216
substr = StructureTools.getSubRanges(structure2, range);
200217
fail("Illegal chain name in '"+range+"'. Should throw StructureException");
201218
} catch(StructureException ex) {} //expected
202-
219+
203220
// some negative tests
204221
try {
205222
range = "7-10";
@@ -217,7 +234,7 @@ public void testRevisedConvention() throws IOException, StructureException{
217234

218235
AtomCache cache = new AtomCache();
219236

220-
237+
221238
String name11 = "4hhb.A";
222239
Structure s = cache.getStructure(name11);
223240
assertTrue(s.getChains().size() == 1);
@@ -230,7 +247,7 @@ public void testRevisedConvention() throws IOException, StructureException{
230247
String name13 = "4hhb.A_";
231248
s = cache.getStructure(name13);
232249
assertTrue(s.getChains().size() == 1);
233-
250+
234251
String name9 = "4hhb.C_1-83";
235252
String chainId = "C";
236253
s = cache.getStructure(name9);
@@ -247,47 +264,47 @@ public void testRevisedConvention() throws IOException, StructureException{
247264
ca = StructureTools.getRepresentativeAtomArray(s);
248265
assertEquals(93, ca.length);
249266

250-
267+
251268
}
252269

253270

254-
// this will get replaced by #81
255-
// public void testStructureToolsRegexp(){
256-
//
257-
//
258-
// Pattern p = ResidueRange.RANGE_REGEX;
259-
//
260-
// String t2 = "A_10-20";
261-
// Matcher m2 = p.matcher(t2);
262-
// assertNotNull(m2);
263-
// assertTrue(m2.find());
264-
// assertTrue(m2.matches());
265-
//
266-
// // for (int i=0;i< m2.groupCount();i++){
267-
// // String s = m2.group(i);
268-
// // System.out.println(s);
269-
// // }
270-
// assertEquals(3,m2.groupCount());
271-
//
272-
//
273-
// String t1 = "A:10-20";
274-
// Matcher m1 = p.matcher(t1);
275-
// assertNotNull(m1);
276-
// assertTrue(m1.find());
277-
// assertTrue(m1.matches());
278-
// assertEquals(3,m1.groupCount());
279-
//
280-
//
281-
// String t3 = "A";
282-
// Matcher m3 = p.matcher(t3);
283-
//
284-
// assertNotNull(m3);
285-
// assertTrue(m3.find());
286-
// assertTrue(m3.matches());
287-
// assertEquals(3,m3.groupCount());
288-
//
289-
//
290-
// }
271+
// this will get replaced by #81
272+
// public void testStructureToolsRegexp(){
273+
//
274+
//
275+
// Pattern p = ResidueRange.RANGE_REGEX;
276+
//
277+
// String t2 = "A_10-20";
278+
// Matcher m2 = p.matcher(t2);
279+
// assertNotNull(m2);
280+
// assertTrue(m2.find());
281+
// assertTrue(m2.matches());
282+
//
283+
// // for (int i=0;i< m2.groupCount();i++){
284+
// // String s = m2.group(i);
285+
// // System.out.println(s);
286+
// // }
287+
// assertEquals(3,m2.groupCount());
288+
//
289+
//
290+
// String t1 = "A:10-20";
291+
// Matcher m1 = p.matcher(t1);
292+
// assertNotNull(m1);
293+
// assertTrue(m1.find());
294+
// assertTrue(m1.matches());
295+
// assertEquals(3,m1.groupCount());
296+
//
297+
//
298+
// String t3 = "A";
299+
// Matcher m3 = p.matcher(t3);
300+
//
301+
// assertNotNull(m3);
302+
// assertTrue(m3.find());
303+
// assertTrue(m3.matches());
304+
// assertEquals(3,m3.groupCount());
305+
//
306+
//
307+
// }
291308

292309
/**
293310
* Test some subranges that we used to have problems with
@@ -408,27 +425,27 @@ public void testGetSubRangesInsertionCodes() throws StructureException {
408425
public void testGroupsWithinShell() {
409426
//TODO
410427
}
411-
428+
412429
public void testCAmmCIF() throws StructureException {
413430
//mmCIF files left justify their atom names (eg "CA "), so can have different behavior
414431
AtomCache pdbCache = new AtomCache();
415432
pdbCache.setUseMmCif(false);
416433
AtomCache mmcifCache = new AtomCache();
417434
mmcifCache.setUseMmCif(true);
418-
435+
419436
Structure pdb=null, mmcif=null;
420-
437+
421438
String name = "3PIU";
422439
try {
423440
pdb = pdbCache.getStructure(name);
424441
mmcif = mmcifCache.getStructure(name);
425442
} catch (IOException e) {
426443
assumeNoException(e);
427444
}
428-
445+
429446
Atom[] pdbCA = StructureTools.getRepresentativeAtomArray(pdb);
430447
Atom[] mmcifCA = StructureTools.getRepresentativeAtomArray(mmcif);
431-
448+
432449
assertEquals("PDB has wrong length",409,pdbCA.length);
433450
assertEquals("PDB has wrong length",409,mmcifCA.length);
434451
}

0 commit comments

Comments
 (0)