Skip to content

Commit 1fe46b4

Browse files
committed
Fix PDBFileParser bug with missing trailing spaces.
This solves the same problem as sroughley's ab9f89f, but with narrower focus. Also refactors TestDBRefParsing a bit for Java 1.7
1 parent 716780a commit 1fe46b4

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

biojava-structure/src/main/java/org/biojava/nbio/structure/io/PDBFileParser.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2188,7 +2188,12 @@ private void pdb_DBREF_Handler(String line){
21882188
String dbseqBegin = line.substring(55,60);
21892189
String idbnsBeg = line.substring(60,61);
21902190
String dbseqEnd = line.substring(62,67);
2191-
String dbinsEnd = line.substring(67,68);
2191+
// Support implicit space character at end
2192+
String dbinsEnd;
2193+
if(line.length() >= 68)
2194+
dbinsEnd = line.substring(67,68);
2195+
else
2196+
dbinsEnd = " ";
21922197

21932198
dbref.setIdCode(idCode);
21942199
dbref.setChainId(chainId);

biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestDBRefParsing.java

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,30 @@ public class TestDBRefParsing {
1414

1515
@Test
1616
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());
17+
Structure s,ref;
1918
PDBFileParser pdbPars = new PDBFileParser();
20-
Structure s;
21-
try {
19+
20+
String shortLine = "DBREF 2W6E A -42 510 UNP P19483 ATPA1_BOVIN 1 553";
21+
// Parse short
22+
try(InputStream is = new ByteArrayInputStream(shortLine.getBytes())) {
2223
s = pdbPars.parsePDBFile(is);
23-
} catch (Exception e) {
24-
is.close();
25-
throw new AssertionError("Unable to process truncated DBRef line");
2624
}
27-
is = new ByteArrayInputStream(String.format("%1$-80s", shortLine)
28-
.getBytes());
29-
Structure ref = pdbPars.parsePDBFile(is);
30-
is.close();
25+
// Parse padded
26+
String longline = String.format("%1$-80s", shortLine);
27+
try(InputStream is = new ByteArrayInputStream(longline.getBytes()) ){
28+
ref = pdbPars.parsePDBFile(is);
29+
}
3130
assertEquals(ref.getDBRefs().get(0), s.getDBRefs().get(0));
3231
}
3332

3433
@Test
3534
public void testToPdbLength() throws IOException {
35+
Structure s;
3636
String shortLine = "DBREF 2W6E A -42 510 UNP P19483 ATPA1_BOVIN 1 553";
37-
InputStream is = new ByteArrayInputStream(shortLine.getBytes());
3837
PDBFileParser pdbPars = new PDBFileParser();
39-
Structure s;
40-
try {
38+
// Parse short
39+
try(InputStream is = new ByteArrayInputStream(shortLine.getBytes()) ) {
4140
s = pdbPars.parsePDBFile(is);
42-
} catch (Exception e) {
43-
is.close();
44-
throw new AssertionError("Unable to process truncated DBRef line");
4541
}
4642
//Make sure that the record is true to the input
4743
assertEquals(shortLine, s.getDBRefs().get(0).toPDB().trim());

0 commit comments

Comments
 (0)