From 9351b1c50314c9815d67a96ddcb2fe8b4934eb74 Mon Sep 17 00:00:00 2001 From: tfenne Date: Wed, 16 Nov 2022 04:11:10 -0700 Subject: [PATCH] Allow the BAM index to be up to 5 seconds older than the BAM before emitting the "WARNING: BAM index file ... is older than BAM " message. HTSJDK itself when writing a BAM and indexing it will frequently leave an mtime on the index that is slightly older than the BAM itself, and this causes a lot of spurious warnings. This is a simple attempt to fix those. --- src/main/java/htsjdk/samtools/BAMFileReader.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/htsjdk/samtools/BAMFileReader.java b/src/main/java/htsjdk/samtools/BAMFileReader.java index c0012cd97c..3693eeba8c 100644 --- a/src/main/java/htsjdk/samtools/BAMFileReader.java +++ b/src/main/java/htsjdk/samtools/BAMFileReader.java @@ -175,10 +175,12 @@ public class BAMFileReader extends SamReader.ReaderImplementation { throws IOException { this(useAsynchronousIO ? new AsyncBlockCompressedInputStream(file, inflaterFactory) : new BlockCompressedInputStream(file, inflaterFactory), indexFile!=null ? indexFile : SamFiles.findIndex(file), eagerDecode, useAsynchronousIO, file.getAbsolutePath(), validationStringency, samRecordFactory); - if (mIndexFile != null && mIndexFile.lastModified() < file.lastModified()) { + + if (mIndexFile != null && mIndexFile.lastModified() < file.lastModified() - 5000) { System.err.println("WARNING: BAM index file " + mIndexFile.getAbsolutePath() + " is older than BAM " + file.getAbsolutePath()); } + // Provide better error message when there is an error reading. mStream.setInputFileName(file.getAbsolutePath()); }