From fed1ff40ada340857d9f8f813e001370f60cffa4 Mon Sep 17 00:00:00 2001 From: Michael Hall Date: Tue, 13 Feb 2024 10:02:46 +1100 Subject: [PATCH] fix: bam header read error [#9] --- src/main.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index d92cd74..40cba47 100644 --- a/src/main.rs +++ b/src/main.rs @@ -102,13 +102,12 @@ fn main() -> Result<()> { println!("Earliest: {}", first_timestamp.format(TIME_FMT)?); println!("Latest : {}", last_timestamp.format(TIME_FMT)?); return Ok(()); - } else { - info!( - "First and last timestamps in the input are {} and {}", - first_timestamp.format(TIME_FMT)?, - last_timestamp.format(TIME_FMT)? - ); } + info!( + "First and last timestamps in the input are {} and {}", + first_timestamp.format(TIME_FMT)?, + last_timestamp.format(TIME_FMT)? + ); let earliest = match args.earliest { None => first_timestamp.to_owned(), @@ -196,6 +195,9 @@ fn main() -> Result<()> { .build_from_path(&args.input)?; let header = bam_reader.read_header()?; writer.write_header(&header)?; + // need to reopen the bam reader as the header has been read and we need to read it again + let mut bam_reader = noodles_util::alignment::io::reader::Builder::default() + .build_from_path(&args.input)?; bam_reader.extract_reads_in_timeframe_into( &reads_to_keep, nb_reads_to_keep,