Skip to content

Commit 07de4bb

Browse files
committed
Fixed DBRef#toPDB() method to give 80 characters line
1 parent ab9f89f commit 07de4bb

File tree

2 files changed

+27
-26
lines changed

2 files changed

+27
-26
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,13 @@ public void toPDB(StringBuffer buf){
131131
// DBREF 3EH2 A 2 767 UNP P53992 SC24C_HUMAN 329 1094
132132
// DBREF 3EH2 A 2 767 UNP P53992 SC24C_HUMAN 329 1094
133133
// DBREF 3ETA A 990 1295 UNP P06213 INSR_HUMAN 1017 1322
134-
formatter.format("DBREF %4s %1s %4d%1s %4d%1s %-6s %-8s %-12s%6d%1c%6d%1c",
134+
formatter.format("DBREF %4s %1s %4d%1s %4d%1s %-6s %-8s %-12s%6d%1c%6d%1c ",
135135
idCode, chainId,seqbegin,insertBegin,seqEnd,insertEnd,
136136
database,dbAccession,dbIdCode,
137137
dbSeqBegin,idbnsBegin,dbSeqEnd,idbnsEnd
138138
);
139139

140-
buf.append(formatter.toString().trim());
140+
buf.append(formatter.toString());
141141
formatter.close();
142142

143143
}
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,51 @@
11
package org.biojava.nbio.structure.io;
22

3-
import static org.junit.Assert.*;
3+
import static org.junit.Assert.assertEquals;
44

55
import java.io.ByteArrayInputStream;
66
import java.io.IOException;
77
import java.io.InputStream;
88

99
import org.biojava.nbio.structure.Structure;
1010
import org.biojava.nbio.structure.StructureException;
11-
import org.biojava.nbio.structure.StructureIO;
12-
import org.biojava.nbio.structure.align.util.AtomCache;
1311
import org.junit.Test;
1412

1513
public class TestDBRefParsing {
16-
@Test
17-
public void test2W6E() throws IOException, StructureException {
18-
19-
// an entry with a title in multiple lines in PDB file
20-
21-
AtomCache cache = new AtomCache();
22-
23-
StructureIO.setAtomCache(cache);
24-
25-
cache.setUseMmCif(false);
26-
Structure sPdb = StructureIO.getStructure("2W6E");
27-
// System.out.println(sPdb.getName());
28-
System.out.println(sPdb.getDBRefs().get(0).toPDB());
29-
}
3014

3115
@Test
32-
public void testShortLine() throws IOException,StructureException{
16+
public void testShortLine() throws IOException, StructureException {
3317
String shortLine = "DBREF 2W6E A -42 510 UNP P19483 ATPA1_BOVIN 1 553";
3418
InputStream is = new ByteArrayInputStream(shortLine.getBytes());
3519
PDBFileParser pdbPars = new PDBFileParser();
3620
Structure s;
37-
try{
38-
s=pdbPars.parsePDBFile(is);
39-
}catch (Exception e){
21+
try {
22+
s = pdbPars.parsePDBFile(is);
23+
} catch (Exception e) {
4024
is.close();
4125
throw new AssertionError("Unable to process truncated DBRef line");
4226
}
43-
44-
45-
is = new ByteArrayInputStream(String.format("%1$-80s", shortLine).getBytes());
27+
is = new ByteArrayInputStream(String.format("%1$-80s", shortLine)
28+
.getBytes());
4629
Structure ref = pdbPars.parsePDBFile(is);
4730
is.close();
4831
assertEquals(ref.getDBRefs().get(0), s.getDBRefs().get(0));
4932
}
33+
34+
@Test
35+
public void testToPdbLength() throws IOException {
36+
String shortLine = "DBREF 2W6E A -42 510 UNP P19483 ATPA1_BOVIN 1 553";
37+
InputStream is = new ByteArrayInputStream(shortLine.getBytes());
38+
PDBFileParser pdbPars = new PDBFileParser();
39+
Structure s;
40+
try {
41+
s = pdbPars.parsePDBFile(is);
42+
} catch (Exception e) {
43+
is.close();
44+
throw new AssertionError("Unable to process truncated DBRef line");
45+
}
46+
//Make sure that the record is true to the input
47+
assertEquals(shortLine, s.getDBRefs().get(0).toPDB().trim());
48+
//And is padded to the correct lenght
49+
assertEquals(80, s.getDBRefs().get(0).toPDB().length());
50+
}
5051
}

0 commit comments

Comments
 (0)