Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add flag set/unset method #108

Merged
merged 4 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions minimap2-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ crate-type = ["staticlib", "cdylib", "rlib"]

[dependencies]
libz-sys = { version = "1.1", default-features = false, features = ["libc"] }
paste = "1.0.15"

[build-dependencies]
pkg-config = "0.3"
Expand Down
96 changes: 96 additions & 0 deletions minimap2-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ unsafe impl Send for mm_idx_t {}
unsafe impl Send for mm_idx_reader_t {}
unsafe impl Send for mm_mapopt_t {}

use paste::paste;

impl Drop for mm_idx_t {
fn drop(&mut self) {
unsafe { mm_idx_destroy(self) };
Expand Down Expand Up @@ -60,6 +62,80 @@ impl Default for mm_mapopt_t {
}
}


macro_rules! add_flag_methods {
($ty:ty, $struct_name:ident, $(($set_name:ident, $unset_name:ident, $flag:expr)),+) => {
impl $struct_name {
$(
paste! {
#[inline(always)]
#[doc = "Set the " $flag " flag"]
pub fn $set_name(&mut self) {
self.flag |= $flag as $ty;
}

#[inline(always)]
#[doc = "Unset the " $flag " flag"]
pub fn $unset_name(&mut self) {
self.flag &= !$flag as $ty;
}
}
)*
}
};
}

add_flag_methods!(
i64,
mm_mapopt_t,
(set_no_dual, unset_no_dual, MM_F_NO_DUAL),
(set_no_diag, unset_no_diag, MM_F_NO_DIAG),
(set_cigar, unset_cigar, MM_F_CIGAR),
(set_out_sam, unset_out_sam, MM_F_OUT_SAM),
(set_no_qual, unset_no_qual, MM_F_NO_QUAL),
(set_out_cg, unset_out_cg, MM_F_OUT_CG),
(set_out_cs, unset_out_cs, MM_F_OUT_CS),
(set_splice, unset_splice, MM_F_SPLICE),
(set_splice_for, unset_splice_for, MM_F_SPLICE_FOR),
(set_splice_rev, unset_splice_rev, MM_F_SPLICE_REV),
(set_no_ljoin, unset_no_ljoin, MM_F_NO_LJOIN),
(set_out_cs_long, unset_out_cs_long, MM_F_OUT_CS_LONG),
(set_sr, unset_sr, MM_F_SR),
(set_frag_mode, unset_frag_mode, MM_F_FRAG_MODE),
(set_no_print_2nd, unset_no_print_2nd, MM_F_NO_PRINT_2ND),
(set_two_io_threads, unset_two_io_threads, MM_F_2_IO_THREADS),
(set_long_cigar, unset_long_cigar, MM_F_LONG_CIGAR),
(set_indep_seg, unset_indep_seg, MM_F_INDEPEND_SEG),
(set_splice_flank, unset_splice_flank, MM_F_SPLICE_FLANK),
(set_softclip, unset_softclip, MM_F_SOFTCLIP),
(set_for_only, unset_for_only, MM_F_FOR_ONLY),
(set_rev_only, unset_rev_only, MM_F_REV_ONLY),
(set_heap_sort, unset_heap_sort, MM_F_HEAP_SORT),
(set_all_chains, unset_all_chains, MM_F_ALL_CHAINS),
(set_out_md, unset_out_md, MM_F_OUT_MD),
(set_copy_comment, unset_copy_comment, MM_F_COPY_COMMENT),
(set_eqx, unset_eqx, MM_F_EQX),
(set_paf_no_hit, unset_paf_no_hit, MM_F_PAF_NO_HIT),
(set_no_end_flt, unset_no_end_flt, MM_F_NO_END_FLT),
(set_hard_mlevel, unset_hard_mlevel, MM_F_HARD_MLEVEL),
(set_sam_hit_only, unset_sam_hit_only, MM_F_SAM_HIT_ONLY),
(set_rmq, unset_rmq, MM_F_RMQ),
(set_qstrand, unset_qstrand, MM_F_QSTRAND),
(set_no_inv, unset_no_inv, MM_F_NO_INV),
(set_no_hash_name, unset_no_hash_name, MM_F_NO_HASH_NAME),
(set_splice_old, unset_splice_old, MM_F_SPLICE_OLD),
(set_secondary_seq, unset_secondary_seq, MM_F_SECONDARY_SEQ),
(set_out_ds, unset_out_ds, MM_F_OUT_DS)
);

add_flag_methods!(
std::os::raw::c_short,
mm_idxopt_t,
(set_hpc, unset_hpc, MM_I_HPC),
(set_no_seq, unset_no_seq, MM_I_NO_SEQ),
(set_no_name, unset_no_name, MM_I_NO_NAME)
);

impl Default for mm_idxopt_t {
fn default() -> Self {
unsafe {
Expand Down Expand Up @@ -101,4 +177,24 @@ mod tests {
fn idxopt() {
let x: mm_idxopt_t = Default::default();
}

#[test]
fn test_mapopt_flags() {
let mut opt = mm_mapopt_t::default();
opt.set_no_qual();
assert_eq!(opt.flag & MM_F_NO_QUAL as i64, MM_F_NO_QUAL as i64);

opt.unset_no_qual();
assert_eq!(opt.flag & MM_F_NO_QUAL as i64, 0_i64);
}

#[test]
fn test_idxopt_flags() {
let mut opt = mm_idxopt_t::default();
opt.set_hpc();
assert_eq!(opt.flag & MM_I_HPC as i16, MM_I_HPC as i16);

opt.unset_hpc();
assert_eq!(opt.flag & MM_I_HPC as i16, 0_i16);
}
}
21 changes: 21 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1498,6 +1498,27 @@ mod tests {
};
}

#[test]
fn test_mapopt_flags_in_aligner() {
let mut aligner = Aligner::builder();
aligner.mapopt.set_no_qual();
assert_eq!(
aligner.mapopt.flag & MM_F_NO_QUAL as i64,
MM_F_NO_QUAL as i64
);
aligner.mapopt.unset_no_qual();
assert_eq!(aligner.mapopt.flag & MM_F_NO_QUAL as i64, 0_i64);
}

#[test]
fn test_idxopt_flags_in_aligner() {
let mut aligner = Aligner::builder();
aligner.idxopt.set_hpc();
assert_eq!(aligner.idxopt.flag & MM_I_HPC as i16, MM_I_HPC as i16);
aligner.idxopt.unset_hpc();
assert_eq!(aligner.idxopt.flag & MM_I_HPC as i16, 0_i16);
}

#[test]
fn aligner_builder() {
let _result = Aligner::builder();
Expand Down
Loading