|
| 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