Skip to content

Commit 9765e76

Browse files
author
luke czapla
committed
Added new getters and refined tests
1 parent 46435ec commit 9765e76

File tree

2 files changed

+185
-40
lines changed

2 files changed

+185
-40
lines changed

biojava-structure/src/main/java/org/biojava/nbio/structure/basepairs/BasePairParameters.java

Lines changed: 123 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,127 @@ public List<Matrix4d> getReferenceFrames() {
234234
return referenceFrames;
235235
}
236236

237+
/**
238+
* Return the buckle in degrees for the given base pair
239+
* @param bp the number of the base pair (starting with 0)
240+
* @return the value as a double (in degrees)
241+
*/
242+
public Double getBuckle(int bp) {
243+
if (bp < 0 || bp >= getPairingParameters().length) return null;
244+
return pairingParameters[bp][0];
245+
}
246+
247+
/**
248+
* Return the propeller ("propeller-twist") in degrees for the given base pair
249+
* @param bp the number of the base pair (starting with 0)
250+
* @return the value as a double (in degrees)
251+
*/
252+
public Double getPropeller(int bp) {
253+
if (bp < 0 || bp >= getPairingParameters().length) return null;
254+
return pairingParameters[bp][1];
255+
}
256+
257+
/**
258+
* Return the opening in degrees for the given base pair
259+
* @param bp the number of the base pair (starting with 0)
260+
* @return the value as a double (in degrees)
261+
*/
262+
public Double getOpening(int bp) {
263+
if (bp < 0 || bp >= getPairingParameters().length) return null;
264+
return pairingParameters[bp][2];
265+
}
266+
267+
/**
268+
* Return the shear in Å for the given base pair
269+
* @param bp the number of the base pair (starting with 0)
270+
* @return the value as a double (in Å)
271+
*/
272+
public Double getShear(int bp) {
273+
if (bp < 0 || bp >= getPairingParameters().length) return null;
274+
return pairingParameters[bp][3];
275+
}
276+
277+
/**
278+
* Return the stretch in Å for the given base pair
279+
* @param bp the number of the base pair (starting with 0)
280+
* @return the value as a double (in Å)
281+
*/
282+
public Double getStretch(int bp) {
283+
if (bp < 0 || bp >= getPairingParameters().length) return null;
284+
return pairingParameters[bp][4];
285+
}
286+
287+
/**
288+
* Return the stagger in Å for the given base pair
289+
* @param bp the number of the base pair (starting with 0)
290+
* @return the value as a double (in Å)
291+
*/
292+
public Double getStagger(int bp) {
293+
if (bp < 0 || bp >= getPairingParameters().length) return null;
294+
return pairingParameters[bp][5];
295+
}
296+
297+
/**
298+
* Return the tilt for the given base pair, relative to the one before it.
299+
* @param bp the number of the base pair (starting with 0)
300+
* @return the value as a double (in degrees)
301+
*/
302+
public Double getTilt(int bp) {
303+
if (bp < 0 || bp >= getStepParameters().length) return null;
304+
return stepParameters[bp][0];
305+
}
306+
307+
/**
308+
* Return the roll for the given base pair, relative to the one before it.
309+
* @param bp the number of the base pair (starting with 0)
310+
* @return the value as a double (in degrees)
311+
*/
312+
public Double getRoll(int bp) {
313+
if (bp < 0 || bp >= getStepParameters().length) return null;
314+
return stepParameters[bp][1];
315+
}
316+
317+
/**
318+
* Return the twist for the given base pair, relative to the one before it.
319+
* @param bp the number of the base pair (starting with 0)
320+
* @return the value as a double (in degrees)
321+
*/
322+
public Double getTwist(int bp) {
323+
if (bp < 0 || bp >= getStepParameters().length) return null;
324+
return stepParameters[bp][2];
325+
}
326+
327+
/**
328+
* Return the shift for the given base pair, relative to the one before it.
329+
* @param bp the number of the base pair (starting with 0)
330+
* @return the value as a double (in Å)
331+
*/
332+
public Double getShift(int bp) {
333+
if (bp < 0 || bp >= getStepParameters().length) return null;
334+
return stepParameters[bp][3];
335+
}
336+
337+
/**
338+
* Return the slide for the given base pair, relative to the one before it.
339+
* @param bp the number of the base pair (starting with 0)
340+
* @return the value as a double (in Å)
341+
*/
342+
public Double getSlide(int bp) {
343+
if (bp < 0 || bp >= getStepParameters().length) return null;
344+
return stepParameters[bp][4];
345+
}
346+
347+
/**
348+
* Return the rise for the given base pair, relative to the one before it.
349+
* @param bp the number of the base pair (starting with 0)
350+
* @return the value as a double (in Å)
351+
*/
352+
public Double getRise(int bp) {
353+
if (bp < 0 || bp >= getStepParameters().length) return null;
354+
return stepParameters[bp][5];
355+
}
356+
357+
237358
/**
238359
* This reports all the nucleic acid chains and has an option to remove duplicates if you
239360
* are considering an analysis of only unique DNA or RNA helices in the Structure.
@@ -262,7 +383,8 @@ public List<Chain> getNucleicChains(boolean removeDups) {
262383

263384
/**
264385
* This performs a search for base pairs in the structure. The criteria is alignment of
265-
* sequences and the canonical base pairs of DNA and RNA.
386+
* sequences and the canonical base pairs of DNA or RNA. Use MismatchedBasePairParameters
387+
* or TertiaryBasePairParameters for finding higher-order associations.
266388
* @param chains The list of chains already found to be nucleic acids
267389
* @return The list of corresponding Watson-Crick groups as pairs, element 0 is on the
268390
* forward strand and element 1 is on the reverse strand.

biojava-structure/src/test/java/org/biojava/nbio/structure/basepairs/TestBasePairParameters.java

Lines changed: 62 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,67 +11,90 @@
1111
import static org.junit.Assert.*;
1212

1313
/**
14+
* Contributed to BioJava under it's LGPL
1415
* Created by luke czapla on 7/21/17.
1516
*/
1617
public class TestBasePairParameters {
1718

1819
@Test
19-
public void testBasePair() {
20-
21-
Structure structure;
22-
try {
23-
structure = StructureIO.getStructure("1KX5");
24-
} catch (IOException|StructureException e) {
25-
e.printStackTrace();
26-
structure = null;
27-
assertEquals(1, 2);
28-
}
20+
public void testBasePair() throws IOException, StructureException {
21+
22+
Structure structure = StructureIO.getStructure("1KX5");
23+
2924
BasePairParameters bp = new BasePairParameters(structure);
3025
bp.analyze();
31-
double[][] pairs = bp.getPairingParameters();
32-
double[][] steps = bp.getStepParameters();
3326
String sequence = bp.getPairSequence();
3427

3528
assertEquals(bp.getPairingParameters().length, 147);
3629
// below all this set of comparator data was from an external program, 3DNA.
3730
// next three in degrees: buckle, propeller, opening
38-
assertEquals(pairs[0][0], -3.796, 0.1);
39-
assertEquals(pairs[0][1], 4.482, 0.1);
40-
assertEquals(pairs[0][2], -0.730, 0.1);
31+
assertEquals(bp.getBuckle(0), -3.796, 0.1);
32+
assertEquals(bp.getPropeller(0), 4.482, 0.1);
33+
assertEquals(bp.getOpening(0), -0.730, 0.1);
4134
// next three in Å: shear, stretch, stagger
42-
assertEquals(pairs[0][3], -0.324, 0.01);
43-
assertEquals(pairs[0][4], -0.578, 0.01);
44-
assertEquals(pairs[0][5], -0.336, 0.01);
35+
assertEquals(bp.getShear(0), -0.324, 0.02);
36+
assertEquals(bp.getStretch(0), -0.578, 0.02);
37+
assertEquals(bp.getStagger(0), -0.336, 0.02);
4538
// next three in degrees: tilt, roll, twist
46-
assertEquals(steps[1][0], 2.354, 0.1);
47-
assertEquals(steps[1][1], 0.785, 0.1);
48-
assertEquals(steps[1][2], 32.522, 0.5);
39+
assertEquals(bp.getTilt(0), 2.354, 0.1);
40+
assertEquals(bp.getRoll(0), 0.785, 0.1);
41+
assertEquals(bp.getTwist(0), 32.522, 0.5);
4942
// next three in Å, shift, slide, rise
50-
assertEquals(steps[1][3], -0.873, 0.01);
51-
assertEquals(steps[1][4], -0.607, 0.01);
52-
assertEquals(steps[1][5], 3.070, 0.01);
53-
54-
try {
55-
structure = StructureIO.getStructure("3PHP");
56-
} catch (IOException|StructureException e) {
57-
e.printStackTrace();
58-
structure = null;
59-
assertEquals(1, 2);
60-
}
43+
assertEquals(bp.getShift(0), -0.873, 0.02);
44+
assertEquals(bp.getSlide(0), -0.607, 0.02);
45+
assertEquals(bp.getRise(0), 3.070, 0.02);
46+
47+
48+
structure = StructureIO.getStructure("3PHP");
6149
bp = new TertiaryBasePairParameters(structure, true, false).analyze();
6250
assertEquals(9, bp.getPairingParameters().length);
6351

64-
try {
65-
structure = StructureIO.getStructure("1P71");
66-
} catch (IOException|StructureException e) {
67-
e.printStackTrace();
68-
structure = null;
69-
assertEquals(1, 2);
70-
}
52+
double[][] pairs = bp.getPairingParameters();
53+
double[][] steps = bp.getStepParameters();
54+
55+
// test against values given by 3DNA, just using the raw arrays
56+
assertEquals(pairs[4][0], 0.060, 0.1);
57+
assertEquals(pairs[4][1], -9.323, 0.1);
58+
assertEquals(pairs[4][2], -5.109, 0.1);
59+
// next three in Å: shear, stretch, stagger
60+
assertEquals(pairs[4][3], 0.126, 0.02);
61+
assertEquals(pairs[4][4], -0.177, 0.02);
62+
assertEquals(pairs[4][5], 0.273, 0.02);
63+
// next three in degrees: tilt, roll, twist
64+
assertEquals(steps[4][0], -1.456, 0.1);
65+
assertEquals(steps[4][1], 6.583, 0.1);
66+
assertEquals(steps[4][2], 33.234, 0.5);
67+
// next three in Å, shift, slide, rise
68+
assertEquals(steps[4][3], -0.735, 0.02);
69+
assertEquals(steps[4][4], -0.978, 0.02);
70+
assertEquals(steps[4][5], 3.491, 0.02);
71+
72+
73+
74+
structure = StructureIO.getStructure("1P71");
7175

7276
bp = new MismatchedBasePairParameters(structure, false, false, false).analyze();
7377
assertEquals(17, bp.getPairingParameters().length);
7478

79+
pairs = bp.getPairingParameters();
80+
steps = bp.getStepParameters();
81+
82+
// this was tested against 3DNA as well.
83+
assertEquals(pairs[16][0], -11.822, 0.1);
84+
assertEquals(pairs[16][1], -11.405, 0.1);
85+
assertEquals(pairs[16][2], -9.669, 0.1);
86+
// next three in Å: shear, stretch, stagger
87+
assertEquals(pairs[16][3], 0.855, 0.02);
88+
assertEquals(pairs[16][4], -0.276, 0.02);
89+
assertEquals(pairs[16][5], -0.604, 0.02);
90+
// next three in degrees: tilt, roll, twist
91+
assertEquals(steps[16][0], 1.516, 0.1);
92+
assertEquals(steps[16][1], 9.291, 0.1);
93+
assertEquals(steps[16][2], 42.052, 1.0);
94+
// next three in Å, shift, slide, rise
95+
assertEquals(steps[16][3], -0.627, 0.02);
96+
assertEquals(steps[16][4], -0.858, 0.02);
97+
assertEquals(steps[16][5], 4.697, 0.02);
7598

7699
}
77100

0 commit comments

Comments
 (0)