Skip to content

Commit 716780a

Browse files
sroughleysbliven
authored andcommitted
Fixed DBRef#toPDB() method to give 80 characters line
(Cherry-picked from 07de4bb by sbliven to resolve pull biojava#332)
1 parent 08340fb commit 716780a

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
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
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package org.biojava.nbio.structure.io;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import java.io.ByteArrayInputStream;
6+
import java.io.IOException;
7+
import java.io.InputStream;
8+
9+
import org.biojava.nbio.structure.Structure;
10+
import org.biojava.nbio.structure.StructureException;
11+
import org.junit.Test;
12+
13+
public class TestDBRefParsing {
14+
15+
@Test
16+
public void testShortLine() throws IOException, StructureException {
17+
String shortLine = "DBREF 2W6E A -42 510 UNP P19483 ATPA1_BOVIN 1 553";
18+
InputStream is = new ByteArrayInputStream(shortLine.getBytes());
19+
PDBFileParser pdbPars = new PDBFileParser();
20+
Structure s;
21+
try {
22+
s = pdbPars.parsePDBFile(is);
23+
} catch (Exception e) {
24+
is.close();
25+
throw new AssertionError("Unable to process truncated DBRef line");
26+
}
27+
is = new ByteArrayInputStream(String.format("%1$-80s", shortLine)
28+
.getBytes());
29+
Structure ref = pdbPars.parsePDBFile(is);
30+
is.close();
31+
assertEquals(ref.getDBRefs().get(0), s.getDBRefs().get(0));
32+
}
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+
}
51+
}

0 commit comments

Comments
 (0)