From 0e7e6d35d852edc837e75a0c93efd49bda192826 Mon Sep 17 00:00:00 2001 From: Yossi Farjoun Date: Mon, 29 Apr 2013 12:49:02 -0400 Subject: [PATCH 1/2] GATKBAMIndex calls buffer.length() on every read. This is causing much pain. Optimized by getting the read of the file upon opening the index-file and using that instead. --- .../gatk/datasources/reads/GATKBAMIndex.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/public/java/src/org/broadinstitute/sting/gatk/datasources/reads/GATKBAMIndex.java b/public/java/src/org/broadinstitute/sting/gatk/datasources/reads/GATKBAMIndex.java index 57b409dcd..9a6b9b521 100644 --- a/public/java/src/org/broadinstitute/sting/gatk/datasources/reads/GATKBAMIndex.java +++ b/public/java/src/org/broadinstitute/sting/gatk/datasources/reads/GATKBAMIndex.java @@ -25,16 +25,17 @@ package org.broadinstitute.sting.gatk.datasources.reads; +import net.sf.samtools.Bin; +import net.sf.samtools.GATKBin; +import net.sf.samtools.GATKChunk; +import net.sf.samtools.LinearIndex; import net.sf.samtools.seekablestream.SeekableBufferedStream; import net.sf.samtools.seekablestream.SeekableFileStream; - -import net.sf.samtools.*; - import org.broadinstitute.sting.utils.exceptions.ReviewedStingException; -import org.broadinstitute.sting.utils.exceptions.StingException; import org.broadinstitute.sting.utils.exceptions.UserException; -import java.io.*; +import java.io.File; +import java.io.IOException; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.ArrayList; @@ -86,6 +87,7 @@ public class GATKBAMIndex { private SeekableFileStream fileStream; private SeekableBufferedStream bufferedStream; + private Long fileLength; public GATKBAMIndex(final File file) { mFile = file; @@ -307,6 +309,7 @@ public class GATKBAMIndex { try { fileStream = new SeekableFileStream(mFile); bufferedStream = new SeekableBufferedStream(fileStream,BUFFERED_STREAM_BUFFER_SIZE); + fileLength=bufferedStream.length(); } catch (IOException exc) { throw new ReviewedStingException("Unable to open index file (" + exc.getMessage() +")" + mFile, exc); @@ -317,6 +320,7 @@ public class GATKBAMIndex { try { bufferedStream.close(); fileStream.close(); + fileLength=null; } catch (IOException exc) { throw new ReviewedStingException("Unable to close index file " + mFile, exc); @@ -368,7 +372,7 @@ public class GATKBAMIndex { // We have a rigid expectation here to read in exactly the number of bytes we've limited // our buffer to -- if there isn't enough data in the file, the index // must be truncated or otherwise corrupt: - if(bytesRequested > bufferedStream.length() - bufferedStream.position()){ + if(bytesRequested > fileLength - bufferedStream.position()){ throw new UserException.MalformedFile(mFile, String.format("Premature end-of-file while reading BAM index file %s. " + "It's likely that this file is truncated or corrupt -- " + "Please try re-indexing the corresponding BAM file.", From 73fcacbf1b88978bf542a8b31113a565b89c47c3 Mon Sep 17 00:00:00 2001 From: Mark DePristo Date: Tue, 30 Apr 2013 09:21:10 -0400 Subject: [PATCH 2/2] Change Long to long --- .../sting/gatk/datasources/reads/GATKBAMIndex.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/java/src/org/broadinstitute/sting/gatk/datasources/reads/GATKBAMIndex.java b/public/java/src/org/broadinstitute/sting/gatk/datasources/reads/GATKBAMIndex.java index 9a6b9b521..6c7a6c867 100644 --- a/public/java/src/org/broadinstitute/sting/gatk/datasources/reads/GATKBAMIndex.java +++ b/public/java/src/org/broadinstitute/sting/gatk/datasources/reads/GATKBAMIndex.java @@ -87,7 +87,7 @@ public class GATKBAMIndex { private SeekableFileStream fileStream; private SeekableBufferedStream bufferedStream; - private Long fileLength; + private long fileLength; public GATKBAMIndex(final File file) { mFile = file; @@ -320,7 +320,7 @@ public class GATKBAMIndex { try { bufferedStream.close(); fileStream.close(); - fileLength=null; + fileLength = -1; } catch (IOException exc) { throw new ReviewedStingException("Unable to close index file " + mFile, exc);