Closed markjschreiber closed 8 months ago
Thanks, @markjschreiber!
The architecture is intentional, and there are a few reasons why the caller is required to read the header manually.
Reader::read_lazy_record
is in the hot path and should avoid header checks on each call. (There would also be a concern of what to do after a seek.)There are no plans to automatically discard the header, but you can always create a wrapper yourself, e.g.,
struct LazyBamReader<R>(bam::Reader<R>);
impl<R> LazyBamReader<R>
where
R: Read,
{
fn new(mut inner: bam::Reader<R>) -> io::Result<Self> {
inner.read_header()?;
Ok(Self(inner))
}
fn read_lazy_record(&mut self, record: &mut bam::lazy::Record) -> io::Result<usize> {
self.0.read_lazy_record(record)
}
}
First of all. Very cool to see this library! Great work!
Reading records using
bam_reader.lazy_records()
doesn't require a reference to the header whereas a non lazy read does. Given that it doesn't use the header I thought I could just start reading records. Unfortunately that results in an unexpected EOF error.Having to read the header first isn't a big deal in terms of performance hit but it would be cool if the lazy_records() could automatically skip over the header if it hasn't been read already.