Skip to content

Commit

Permalink
Fix date parsing from NCBI gene info file
Browse files Browse the repository at this point in the history
Properly parse modification date in NCBI gene info using
SimpleDateFormat.
  • Loading branch information
arteymix committed Jul 3, 2020
1 parent 59e7ad5 commit 3afd5bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 3 additions & 5 deletions src/main/java/ubc/pavlab/rdp/model/Gene.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import lombok.*;

import javax.persistence.*;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.*;

/**
* Created by mjacobson on 17/01/18.
Expand Down Expand Up @@ -37,8 +34,9 @@ public class Gene {
@Column(name = "synonyms", columnDefinition = "TEXT")
private String aliases;

@Temporal(TemporalType.DATE)
@Column(name = "modification_date")
private int modificationDate;
private Date modificationDate;

@Transient
@JsonIgnore
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/ubc/pavlab/rdp/util/GeneInfoParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

import java.io.*;
import java.net.URL;
import java.sql.Date;
import java.text.MessageFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.zip.GZIPInputStream;
Expand Down Expand Up @@ -94,7 +97,12 @@ private static Set<Gene> parse( Taxon taxon, InputStream input ) throws ParseExc
gene.setSymbol( values[2] );
gene.setAliases( values[4] );
gene.setName( values[8] );
gene.setModificationDate( Integer.valueOf( values[14] ) );
SimpleDateFormat ncbiDateFormat = new SimpleDateFormat("YYYYMMDD");
try {
gene.setModificationDate( ncbiDateFormat.parse( values[14] ) );
} catch ( ParseException e ) {
log.warn( MessageFormat.format("Could not parse date {0} for gene {1}.", values[14], values[1]), e);
}
return gene;
} ).collect( Collectors.toSet() );
} catch (IOException e) {
Expand Down

0 comments on commit 3afd5bb

Please sign in to comment.