Skip to content

Commit a145f9c

Browse files
committed
Test parsing dates from PDB format
biojava#677
1 parent 8bb0b4e commit a145f9c

File tree

4 files changed

+49
-19
lines changed

4 files changed

+49
-19
lines changed

biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/PDBFileParserTest.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.io.IOException;
3333
import java.io.InputStream;
3434
import java.io.StringReader;
35+
import java.util.Calendar;
3536

3637
import org.biojava.nbio.structure.Atom;
3738
import org.biojava.nbio.structure.Chain;
@@ -50,6 +51,12 @@
5051
import org.junit.Before;
5152
import org.junit.Test;
5253

54+
/**
55+
* Test the {@link PDBFileParser}.
56+
*
57+
* @author Aleix Lafita
58+
*
59+
*/
5360
public class PDBFileParserTest {
5461

5562
private static PDBFileParser parser;
@@ -555,8 +562,6 @@ public void testCorrectAtomNamePadding() throws IOException {
555562

556563
/**
557564
* Test handling of missing Element column. Issue 537 in github.
558-
* @author Aleix Lafita
559-
* @throws IOException
560565
*/
561566
@Test
562567
public void testMissingElements() throws IOException {
@@ -627,4 +632,28 @@ public void testMissingElements() throws IOException {
627632
assertTrue("the Element column has not been filled correctly", pdb.equals(original));
628633

629634
}
635+
636+
/**
637+
* Test the parsing of release and last modified dates.
638+
*/
639+
@Test
640+
public void testDates() throws IOException {
641+
642+
String revisionDates =
643+
"REVDAT 5 13-JUL-11 1STP 1 VERSN "+newline+
644+
"REVDAT 4 24-FEB-09 1STP 1 VERSN " + newline+
645+
"REVDAT 3 01-APR-03 1STP 1 JRNL " + newline+
646+
"REVDAT 2 15-OCT-94 1STP 1 AUTHOR " + newline+
647+
"REVDAT 1 15-OCT-92 1STP 0 " + newline;
648+
649+
BufferedReader br = new BufferedReader(new StringReader(revisionDates));
650+
Structure s = parser.parsePDBFile(br);
651+
652+
// The latest modified date should be 2011
653+
assertEquals(s.getPDBHeader().getModDate().getYear() + 1900, 2011);
654+
655+
// The release date should be 1992
656+
assertEquals(s.getPDBHeader().getRelDate().getYear() + 1900, 1992);
657+
658+
}
630659
}

biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/StructureIOTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
*/
2121
package org.biojava.nbio.structure.test.io;
2222

23-
2423
import static org.junit.Assert.*;
2524

2625
import java.io.IOException;
@@ -29,15 +28,16 @@
2928
import org.biojava.nbio.structure.StructureIO;
3029
import org.junit.Test;
3130

32-
33-
31+
/**
32+
* Test StructureIO methods.
33+
*
34+
*/
3435
public class StructureIOTest {
3536

3637
@Test
3738
public void testStructureIO() throws IOException, StructureException {
3839

3940
String pdbId = "1gav";
40-
4141
int nrAssembls = StructureIO.getBiologicalAssemblies(pdbId).size();
4242
assertEquals(1,nrAssembls);
4343

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -672,31 +672,32 @@ private void pdb_TURN_Handler( String line){
672672
*/
673673
private void pdb_REVDAT_Handler(String line) {
674674

675-
// keep the first as release date and the last as modification date
676-
Date relDate = pdbHeader.getRelDate();
675+
// keep the first as latest modified date and the last as release date
676+
Date modDate = pdbHeader.getModDate();
677677

678-
if ( relDate == null || relDate.equals(new Date(0)) ) {
678+
if ( modDate == null || modDate.equals(new Date(0)) ) {
679679

680-
// release date is still uninitialized
681-
String releaseDate = line.substring (13, 22).trim() ;
680+
// modified date is still uninitialized
681+
String modificationDate = line.substring (13, 22).trim() ;
682682

683683
try {
684-
Date dep = dateFormat.parse(releaseDate);
684+
Date dep = dateFormat.parse(modificationDate);
685685
pdbHeader.setModDate(dep);
686+
pdbHeader.setRelDate(dep);
686687
} catch (ParseException e){
687-
logger.info("Could not parse modification date string '"+releaseDate+"'. Will continue without modification date");
688+
logger.info("Could not parse revision date string '"+modificationDate+"'. ");
688689
}
689690

690691
} else {
691692

692-
// set as the latest modification date
693-
String modificationDate = line.substring (13, 22).trim() ;
693+
// set as the release date
694+
String releaseDate = line.substring (13, 22).trim() ;
694695

695696
try {
696-
Date dep = dateFormat.parse(modificationDate);
697-
pdbHeader.setModDate(dep);
697+
Date dep = dateFormat.parse(releaseDate);
698+
pdbHeader.setRelDate(dep);
698699
} catch (ParseException e){
699-
logger.info("Could not parse modification date string '"+modificationDate+"'. Will continue without modification date");
700+
logger.info("Could not parse revision date string '"+releaseDate+"'. ");
700701
}
701702
}
702703
}

biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestParseHeader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import org.junit.Test;
1313

1414
/**
15-
* A class to test the parsing of R-work from files
15+
* Test the parsing header informationof R-work from files
1616
* @author Anthony Bradley
1717
*
1818
*/

0 commit comments

Comments
 (0)