Skip to content

Commit

Permalink
Merge pull request #653 from CAWarmerdam/master
Browse files Browse the repository at this point in the history
Resolved bug in BGEN, BGI writer Genotype-IO, GH
  • Loading branch information
PatrickDeelen authored Feb 6, 2023
2 parents 1bb7989 + 38c5e90 commit 6f76851
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Genotype-Harmonizer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>Genotype-Harmonizer</artifactId>
<version>1.4.26-SNAPSHOT</version>
<version>1.4.27-SNAPSHOT</version>
<name>Genotype Harmonizer</name>
<packaging>jar</packaging>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import java.nio.channels.WritableByteChannel;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
Expand Down Expand Up @@ -304,10 +306,11 @@ private void addMetaData(File bgenFile, BgenixWriter bgenixWriter) throws IOExce

// Add current time in int.
// Create and write new metadata.
BasicFileAttributes basicFileAttributes = Files.readAttributes(bgenFile.toPath(), BasicFileAttributes.class);
BgenixMetadata m = new BgenixMetadata(
bgenFile.getName(),
(int) bgenFile.length(),
(int) (bgenFile.lastModified() / 1000L),
basicFileAttributes.size(),
basicFileAttributes.lastModifiedTime().toMillis() / 1000L,
firstBytes,
(System.currentTimeMillis() / 1000L));
bgenixWriter.writeMetadata(m);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
public class BgenixMetadata {

private final String fileName;
private final int fileSize;
private final long fileSize;
private final long lastWriteTime;
private final byte[] first1000bytes;
private final long indexCreationTime;

public BgenixMetadata(String fileName, int fileSize, long lastWriteTime, byte[] first1000bytes, long indexCreationTime) {
public BgenixMetadata(String fileName, long fileSize, long lastWriteTime, byte[] first1000bytes, long indexCreationTime) {
this.fileName = fileName;
this.fileSize = fileSize;
this.lastWriteTime = lastWriteTime;
Expand All @@ -29,7 +29,7 @@ public String getFileName() {
return fileName;
}

public int getFileSize() {
public long getFileSize() {
return fileSize;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,11 @@ public void writeMetadata(BgenixMetadata metadata) {

PreparedStatement metadataStatement = dbConnection.prepareStatement("INSERT INTO Metadata(filename, file_size, last_write_time, first_1000_bytes, index_creation_time) VALUES(?,?,?,?,?)");

// The sqlite database requires integers for both file size and write time.
// However, in sqlite integers are up to 8 byte integers.
// This is equivalent to a long in java, therefore, we use setLong here.
metadataStatement.setString(1, metadata.getFileName());
metadataStatement.setInt(2, metadata.getFileSize());
metadataStatement.setLong(2, metadata.getFileSize());
metadataStatement.setLong(3, metadata.getLastWriteTime());
metadataStatement.setBytes(4, metadata.getFirst1000bytes());
metadataStatement.setLong(5, metadata.getIndexCreationTime());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@

import java.io.File;
import java.net.URISyntaxException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;

import static org.testng.Assert.*;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
Expand Down

0 comments on commit 6f76851

Please sign in to comment.