perbase_lib/
read_filter.rs1use rust_htslib::bam::pileup::Alignment;
3use rust_htslib::bam::record::Record;
4
5pub trait ReadFilter {
7 fn filter_read(&self, read: &Record, alignment: Option<&Alignment>) -> bool;
9}
10
11pub struct DefaultReadFilter {
13 include_flags: u16,
14 exclude_flags: u16,
15 min_mapq: u8,
16}
17
18impl DefaultReadFilter {
19 pub fn new(include_flags: u16, exclude_flags: u16, min_mapq: u8) -> Self {
21 Self {
22 include_flags,
23 exclude_flags,
24 min_mapq,
25 }
26 }
27}
28
29impl ReadFilter for DefaultReadFilter {
30 #[inline(always)]
32 fn filter_read(&self, read: &Record, _alignment: Option<&Alignment>) -> bool {
33 let flags = read.flags();
34 (!flags) & self.include_flags == 0
35 && flags & self.exclude_flags == 0
36 && read.mapq() >= self.min_mapq
37 }
38}