use rust_htslib::bam::pileup::Alignment;
use rust_htslib::bam::record::Record;
pub trait ReadFilter {
fn filter_read(&self, read: &Record, alignment: Option<&Alignment>) -> bool;
}
pub struct DefaultReadFilter {
include_flags: u16,
exclude_flags: u16,
min_mapq: u8,
}
impl DefaultReadFilter {
pub fn new(include_flags: u16, exclude_flags: u16, min_mapq: u8) -> Self {
Self {
include_flags,
exclude_flags,
min_mapq,
}
}
}
impl ReadFilter for DefaultReadFilter {
#[inline(always)]
fn filter_read(&self, read: &Record, _alignment: Option<&Alignment>) -> bool {
let flags = read.flags();
(!flags) & self.include_flags == 0
&& flags & self.exclude_flags == 0
&& read.mapq() >= self.min_mapq
}
}