Skip to content

Commit 4632f96

Browse files
author
luke czapla
committed
Made test use no println, and class use Logger
1 parent 96deb1c commit 4632f96

2 files changed

Lines changed: 35 additions & 22 deletions

File tree

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
import java.io.IOException;
1212
import java.util.*;
1313

14+
import org.slf4j.Logger;
15+
import org.slf4j.LoggerFactory;
16+
1417
import static java.lang.Math.*;
1518

1619
/**
@@ -22,6 +25,8 @@
2225
*/
2326
public class BasePairParameters {
2427

28+
private static Logger log = LoggerFactory.getLogger(BasePairParameters.class);
29+
2530
private static String[] standardBases = new String[] {
2631
"SEQRES 1 A 1 A\n" +
2732
"ATOM 2 N9 A A 1 -1.291 4.498 0.000\n" +
@@ -119,7 +124,7 @@ public BasePairParameters(String name) {
119124
}
120125
; }
121126
} catch (IOException|StructureException e) {
122-
System.out.println("Error reading file from local drive or internet");
127+
log.info("Error reading file from local drive or internet");
123128
structure = null;
124129
}
125130
}
@@ -166,7 +171,7 @@ public List<Group[]> findPairs(List<Chain> chains) {
166171
for (int j = i+1; j < chains.size(); j++) {
167172
String complement = complement(chains.get(j).getSeqResSequence(), false);
168173
String match = longestCommonSubstring(c.getSeqResSequence(), complement);
169-
//System.out.println(c.getSeqResSequence() + " " + chains.get(j).getSeqResSequence() + " " + match);
174+
//log.info(c.getSeqResSequence() + " " + chains.get(j).getSeqResSequence() + " " + match);
170175
int index1 = c.getSeqResSequence().indexOf(match);
171176
int index2 = complement.length() - complement.indexOf(match) - 1;
172177
for (int k = 0; k < match.length(); k++) {
@@ -182,12 +187,12 @@ public List<Group[]> findPairs(List<Chain> chains) {
182187
Atom a2 = g2.getAtom(ringMap.get(type2).get(0));
183188

184189
if (a1 == null) {
185-
System.out.println("Error processing " + g1.getPDBName() + " in " + pdbId);
190+
log.info("Error processing " + g1.getPDBName() + " in " + pdbId);
186191
if (pairSequence.length() != 0 && pairSequence.charAt(pairSequence.length()-1) != ' ') pairSequence += ' ';
187192
continue;
188193
}
189194
if (a2 == null) {
190-
System.out.println("Error processing " + g2.getPDBName() + " in " + pdbId);
195+
log.info("Error processing " + g2.getPDBName() + " in " + pdbId);
191196
if (pairSequence.length() != 0 && pairSequence.charAt(pairSequence.length()-1) != ' ') pairSequence += ' ';
192197
continue;
193198
}
@@ -196,7 +201,7 @@ public List<Group[]> findPairs(List<Chain> chains) {
196201
double dy = a1.getY()-a2.getY();
197202
double dz = a1.getZ()-a2.getZ();
198203
double distance = Math.sqrt(dx*dx+dy*dy+dz*dz);
199-
//System.out.println("C8-C6 Distance (Å): " + distance);
204+
//log.info("C8-C6 Distance (Å): " + distance);
200205
// could be a base pair
201206
if (Math.abs(distance-10.0) < 2.0) {
202207
boolean valid = true;
@@ -220,9 +225,9 @@ public List<Group[]> findPairs(List<Chain> chains) {
220225
}
221226
if (pairSequence.length() != 0 && pairSequence.charAt(pairSequence.length()-1) != ' ') pairSequence += ' ';
222227
}
223-
//System.out.println();
228+
//log.info();
224229
}
225-
System.out.println("Matched: " + pairSequence);
230+
log.info("Matched: " + pairSequence);
226231
return result;
227232
}
228233

@@ -270,11 +275,11 @@ public Matrix4d basePairReferenceFrame(Group[] pair) {
270275
}
271276
assert count == std2.getAtoms().size();
272277

273-
// System.out.println(ref1);
278+
// log.info(ref1);
274279
Matrix4d temp = (Matrix4d)ref1.clone();
275280
Matrix4d temp2 = (Matrix4d)temp.clone();
276281
Matrix4d ref2 = sp.superposeAndTransform(pointact, pointref);
277-
// System.out.println(ref2);
282+
// log.info(ref2);
278283
double[][] v = new double[3][4];
279284
double[] y3 = new double[4];
280285
double[] z3 = new double[4];

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

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,37 @@
11
import org.biojava.nbio.structure.secstruc.BasePairParameters;
22
import org.junit.Test;
3+
import static org.junit.Assert.*;
34

45
/**
56
* Created by luke on 7/21/17.
67
*/
78
public class TestBasePairParameters {
9+
810
@Test
911
public void testBasePair() {
12+
1013
BasePairParameters bp = new BasePairParameters("1KX5");
1114
double[][] pairs = bp.getPairingParameters();
1215
double[][] steps = bp.getStepParameters();
13-
int pos = 0;
1416
String sequence = bp.getPairSequence();
15-
System.out.println("buckle propeller opening shear stretch stagger tilt roll twist shift slide rise");
16-
for (int i = 0; i < pairs.length; i++) {
17-
while (sequence.charAt(pos) == ' ') pos++;
18-
System.out.print(sequence.charAt(pos) + ": ");
19-
for (int j = 0; j < 6; j++)
20-
System.out.print(pairs[i][j] + " ");
21-
System.out.print(" ");
22-
for (int j = 0; j < 6; j++)
23-
System.out.print(steps[i][j] + " ");
24-
System.out.println();
25-
pos++;
26-
}
17+
18+
assertEquals(sequence.trim().length(), 147);
19+
// below: next 3 in degrees, all this data was from an external program, 3DNA
20+
assertEquals(pairs[0][0], -3.796, 0.1);
21+
assertEquals(pairs[0][1], 4.482, 0.1);
22+
assertEquals(pairs[0][2], -0.730, 0.1);
23+
// in Å
24+
assertEquals(pairs[0][3], -0.324, 0.01);
25+
assertEquals(pairs[0][4], -0.578, 0.01);
26+
assertEquals(pairs[0][5], -0.336, 0.01);
27+
// in degrees
28+
assertEquals(steps[1][0], 2.354, 0.1);
29+
assertEquals(steps[1][1], 0.785, 0.1);
30+
assertEquals(steps[1][2], 32.522, 1.0);
31+
// in Å
32+
assertEquals(steps[1][3], -0.873, 0.01);
33+
assertEquals(steps[1][4], -0.607, 0.01);
34+
assertEquals(steps[1][5], 3.070, 0.01);
2735

2836
}
2937

0 commit comments

Comments
 (0)