diff --git a/Cargo.toml b/Cargo.toml index 3b2519e..dad80e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,8 +36,8 @@ simdutf8 = {version = "0.1", optional = true} needletail = { version = "0.5", optional = true, default-features = false} # Dep for development -# minimap2-sys = { path = "./minimap2-sys" } -minimap2-sys = "0.1.19" +minimap2-sys = { path = "./minimap2-sys" } +# minimap2-sys = "0.1.19" rust-htslib = { version = "0.47", default-features = false, optional = true } [dev-dependencies] diff --git a/minimap2-sys/Cargo.lock b/minimap2-sys/Cargo.lock index 98cfb8e..2c26ee5 100644 --- a/minimap2-sys/Cargo.lock +++ b/minimap2-sys/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "aho-corasick" -version = "1.0.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43f6cb1bf222025340178f382c426f13757b2960e89779dfcb319c32542a5a41" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ "memchr", ] @@ -34,15 +34,15 @@ dependencies = [ [[package]] name = "bitflags" -version = "2.3.3" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "cc" -version = "1.0.90" +version = "1.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5" +checksum = "26a5c3fd7bfa1ce3897a3a3501d362b2d87b7f2583ebcb4a949ec25911025cbc" [[package]] name = "cexpr" @@ -61,9 +61,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clang-sys" -version = "1.6.1" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c688fc74432808e3eb684cae8830a86be1d66a2bd58e1f248ed0960a590baf6f" +checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" dependencies = [ "glob", "libc", @@ -81,9 +81,19 @@ dependencies = [ [[package]] name = "either" -version = "1.8.1" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys", +] [[package]] name = "glob" @@ -91,6 +101,15 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys", +] + [[package]] name = "itertools" version = "0.12.1" @@ -102,9 +121,9 @@ dependencies = [ [[package]] name = "lazy_static" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "lazycell" @@ -114,25 +133,25 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.147" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "libloading" -version = "0.7.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" +checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" dependencies = [ "cfg-if", - "winapi", + "windows-targets", ] [[package]] name = "libz-sys" -version = "1.1.15" +version = "1.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "037731f5d3aaa87a5675e895b63ddff1a87624bc29f77004ea829809654e48f6" +checksum = "c15da26e5af7e25c90b37a2d75cdbf940cf4a55316de9d84c679c9b8bfabf82e" dependencies = [ "cc", "cmake", @@ -141,11 +160,17 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + [[package]] name = "memchr" -version = "2.5.0" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "minimal-lexical" @@ -175,9 +200,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.18.0" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "pkg-config" @@ -187,27 +212,27 @@ checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" [[package]] name = "proc-macro2" -version = "1.0.63" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b368fba921b0dce7e60f5e04ec15e565b3303972b42bcfde1d0713b881959eb" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.29" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "573015e8ab27661678357f27dc26460738fd2b6c86e46f386fde94cb5d913105" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] [[package]] name = "regex" -version = "1.9.1" +version = "1.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2eae68fc220f7cf2532e4494aded17545fce192d59cd996e0fe7887f4ceb575" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" dependencies = [ "aho-corasick", "memchr", @@ -217,9 +242,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.3.1" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9aaecc05d5c4b5f7da074b9a0d1a0867e71fd36e7fc0482d8bcfe8e8fc56290" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" dependencies = [ "aho-corasick", "memchr", @@ -228,9 +253,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.7.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ab07dc67230e4a4718e70fd5c20055a4334b121f1f9db8fe63ef39ce9b8c846" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" [[package]] name = "rustc-hash" @@ -238,17 +263,30 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + [[package]] name = "shlex" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "syn" -version = "2.0.27" +version = "2.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b60f673f44a8255b9c8c657daf66a596d435f2da81a555b06dc644d080ba45e0" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" dependencies = [ "proc-macro2", "quote", @@ -257,9 +295,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.10" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22049a19f4a68748a168c0fc439f9516686aa045927ff767eca0a85101fb6e73" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "vcpkg" @@ -269,33 +307,85 @@ checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" [[package]] name = "which" -version = "4.4.0" +version = "4.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" dependencies = [ "either", - "libc", + "home", "once_cell", + "rustix", ] [[package]] -name = "winapi" -version = "0.3.9" +name = "windows-sys" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", + "windows-targets", ] [[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" +name = "windows_x86_64_msvc" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git a/minimap2-sys/Cargo.toml b/minimap2-sys/Cargo.toml index ab2f8aa..1d93468 100644 --- a/minimap2-sys/Cargo.toml +++ b/minimap2-sys/Cargo.toml @@ -33,7 +33,7 @@ exclude = [ crate-type = ["cdylib", "rlib"] [dependencies] -libz-sys = { version = "1.1.15", default-features = false } +libz-sys = { version = "1.1.17", default-features = false, features = ["libc"] } [build-dependencies] pkg-config = "0.3.30" @@ -45,10 +45,10 @@ default-features = false features = ["which-rustfmt", "runtime"] [build-dependencies.cc] -version = "1.0.90" +version = "1.1" [features] -default = ["libz-sys/libc"] +default = [] # "libz-sys/libc" vendored = ["bindgen"] sse2only = [] simde = [] diff --git a/minimap2-sys/build.rs b/minimap2-sys/build.rs index 4fe4c2a..28c274f 100644 --- a/minimap2-sys/build.rs +++ b/minimap2-sys/build.rs @@ -4,7 +4,7 @@ use std::path::PathBuf; // Configure for minimap2 fn configure(mut cc: &mut cc::Build) { println!("cargo:rerun-if-changed=minimap2/*.c"); - + cc.include("minimap2"); cc.opt_level(2); @@ -14,9 +14,7 @@ fn configure(mut cc: &mut cc::Build) { #[cfg(feature = "simde")] simde(&mut cc); - // Include ksw2.h kalloc.h cc.include("minimap2/"); - // cc.include("minimap2/"); let files: Vec<_> = std::fs::read_dir("minimap2") .unwrap() @@ -30,19 +28,20 @@ fn configure(mut cc: &mut cc::Build) { if file.file_name().unwrap() == "main.c" || file.file_name().unwrap() == "example.c" { continue; } - + // Ignore all "neon" if file.file_name().unwrap().to_str().unwrap().contains("neon") { continue; } - + // Ignore all "ksw" if file.file_name().unwrap().to_str().unwrap().contains("ksw") { continue; } - + if let Some(x) = file.extension() { if x == "c" { + println!("Compiling: {:?}", file); cc.file(file); } } @@ -55,7 +54,9 @@ fn configure(mut cc: &mut cc::Build) { } fn target_specific(cc: &mut cc::Build) { - let target = env::var("TARGET").unwrap_or_default(); + + // let host = env::var("HOST").unwrap(); + let target = env::var("TARGET").unwrap(); if target.contains("aarch64") | target.contains("arm") { cc.include("minimap2/sse2neon/"); @@ -80,6 +81,19 @@ fn target_specific(cc: &mut cc::Build) { ))] cc.flag("-msse4.1"); + if target.contains("aarch64") { + cc.include("minimap2/sse2neon/"); + // Include appropriate NEON files + cc.file("minimap2/ksw2_extz2_neon.c"); + cc.file("minimap2/ksw2_extd2_neon.c"); + cc.file("minimap2/ksw2_exts2_neon.c"); + + cc.flag("-D_FILE_OFFSET_BITS=64"); + cc.flag("-fsigned-char"); + cc.flag("-Isse2neon"); + cc.flag("-D__SSE2__"); + } + #[cfg(all(not(target_feature = "sse4.1"), target_feature = "sse2",))] { cc.flag("-msse2"); @@ -111,6 +125,9 @@ fn simde(cc: &mut cc::Build) { } fn compile() { + + let mut cc = cc::Build::new(); + let out_path = PathBuf::from(env::var_os("OUT_DIR").unwrap()); let _host = env::var("HOST").unwrap(); @@ -121,8 +138,18 @@ fn compile() { println!("cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR"); println!("cargo:rustc-link-lib=m"); + println!("cargo:rustc-link-lib=z"); - println!("cargo:rustc-link-lib=pthread"); + if !env::var("TARGET").unwrap().contains("android") { + println!("cargo:rustc-link-lib=pthread"); + } + + if !env::var("TARGET").unwrap().contains("android") { + cc.flag("-lpthread"); + } + + cc.flag("-lm"); + cc.flag("-lz"); let mut cc = cc::Build::new(); @@ -133,13 +160,11 @@ fn compile() { configure(&mut cc); cc.flag("-DHAVE_KALLOC"); - cc.flag("-lm"); - cc.flag("-lz"); - cc.flag("-lpthread"); - #[cfg(feature = "static")] cc.static_flag(true); + println!("cargo:rustc-cfg=link_libz"); + if let Some(include) = std::env::var_os("DEP_Z_INCLUDE") { println!("-------------FOUND ZLIB INCLUDE: {:?}", include); cc.include(include); @@ -207,7 +232,7 @@ fn gen_bindings() { #[cfg(not(feature = "bindgen"))] fn gen_bindings() {} -fn main() { +fn main() { compile(); gen_bindings(); } diff --git a/src/htslib.rs b/src/htslib.rs index 9536a11..94c940a 100644 --- a/src/htslib.rs +++ b/src/htslib.rs @@ -221,7 +221,6 @@ impl Aligner { } } - pub fn mapping_to_record( mapping: Option<&Mapping>, seq: &[u8], diff --git a/src/lib.rs b/src/lib.rs index 9aaa281..f400c20 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -228,6 +228,7 @@ thread_local! { } /// ThreadLocalBuffer for minimap2 memory management +#[derive(Debug)] struct ThreadLocalBuffer { buf: *mut mm_tbuf_t, max_uses: usize, @@ -753,38 +754,15 @@ impl Aligner { .collect(); let idx = MaybeUninit::new(unsafe { - // conditionally compile using the correct pointer type (u8 or i8) for the platform - #[cfg(any( - all(target_arch = "aarch64", target_os = "linux"), - all(target_arch = "arm", target_os = "linux") - ))] - { - mm_idx_str( - self.idxopt.w as i32, - self.idxopt.k as i32, - (self.idxopt.flag & 1) as i32, - self.idxopt.bucket_bits as i32, - seqs.len() as i32, - seqs.as_ptr() as *mut *const u8, - ids.as_ptr() as *mut *const u8, - ) - } - #[cfg(any( - all(target_arch = "aarch64", target_os = "macos"), - all(target_arch = "x86_64", target_os = "linux"), - all(target_arch = "x86_64", target_os = "macos") - ))] - { - mm_idx_str( - self.idxopt.w as i32, - self.idxopt.k as i32, - (self.idxopt.flag & 1) as i32, - self.idxopt.bucket_bits as i32, - seqs.len() as i32, - seqs.as_ptr() as *mut *const i8, - ids.as_ptr() as *mut *const i8, - ) - } + mm_idx_str( + self.idxopt.w as i32, + self.idxopt.k as i32, + (self.idxopt.flag & 1) as i32, + self.idxopt.bucket_bits as i32, + seqs.len() as i32, + seqs.as_ptr() as *mut *const libc::c_char, + ids.as_ptr() as *mut *const libc::c_char, + ) }); self.idx = Some(unsafe { idx.assume_init() }); @@ -804,7 +782,6 @@ impl Aligner { /// MD: Whether to output MD tag /// max_frag_len: Maximum fragment length /// extra_flags: Extra flags to pass to minimap2 as `Vec` - /// pub fn map( &self, seq: &[u8], @@ -845,38 +822,15 @@ impl Aligner { let km = unsafe { mm_tbuf_get_km(buf.borrow_mut().get_buf()) }; mm_reg = MaybeUninit::new(unsafe { - // conditionally compile using the correct pointer type (u8 or i8) for the platform - #[cfg(any( - all(target_arch = "aarch64", target_os = "linux"), - all(target_arch = "arm", target_os = "linux") - ))] - { - mm_map( - self.idx.as_ref().unwrap() as *const mm_idx_t, - seq.len() as i32, - seq.as_ptr() as *const u8, - &mut n_regs, - buf.borrow_mut().get_buf(), - &map_opt, - std::ptr::null(), - ) - } - #[cfg(any( - all(target_arch = "aarch64", target_os = "macos"), - all(target_arch = "x86_64", target_os = "linux"), - all(target_arch = "x86_64", target_os = "macos") - ))] - { - mm_map( - self.idx.unwrap() as *const mm_idx_t, - seq.len() as i32, - seq.as_ptr() as *const i8, - &mut n_regs, - buf.borrow_mut().get_buf(), - &map_opt, - std::ptr::null(), - ) - } + mm_map( + self.idx.unwrap() as *const mm_idx_t, + seq.len() as i32, + seq.as_ptr() as *const ::std::os::raw::c_char, + &mut n_regs, + buf.borrow_mut().get_buf(), + &map_opt, + std::ptr::null(), + ) }); let mut mappings = Vec::with_capacity(n_regs as usize); @@ -984,93 +938,38 @@ impl Aligner { let mut m_cs_string: libc::c_int = 0i32; let cs_str = if cs { - // conditionally compile using the correct pointer type (u8 or i8) for the platform - #[cfg(any( - all(target_arch = "aarch64", target_os = "linux"), - all(target_arch = "arm", target_os = "linux") - ))] - { - let _cs_len = mm_gen_cs( - km, - &mut cs_string, - &mut m_cs_string, - &self.idx.unwrap() as *const mm_idx_t, - const_ptr, - seq.as_ptr() as *const u8, - true.into(), - ); - let _cs_string = std::ffi::CStr::from_ptr(cs_string) - .to_str() - .unwrap() - .to_string(); - Some(_cs_string) - } - #[cfg(any( - all(target_arch = "aarch64", target_os = "macos"), - all(target_arch = "x86_64", target_os = "linux"), - all(target_arch = "x86_64", target_os = "macos") - ))] - { - let _cs_len = mm_gen_cs( - km, - &mut cs_string, - &mut m_cs_string, - self.idx.unwrap() as *const mm_idx_t, - const_ptr, - seq.as_ptr() as *const i8, - true.into(), - ); - let _cs_string = std::ffi::CStr::from_ptr(cs_string) - .to_str() - .unwrap() - .to_string(); - Some(_cs_string) - } + let _cs_len = mm_gen_cs( + km, + &mut cs_string, + &mut m_cs_string, + self.idx.unwrap() as *const mm_idx_t, + const_ptr, + seq.as_ptr() as *const libc::c_char, + true.into(), + ); + let _cs_string = std::ffi::CStr::from_ptr(cs_string) + .to_str() + .unwrap() + .to_string(); + Some(_cs_string) } else { None }; let md_str = if md { - // conditionally compile using the correct pointer type (u8 or i8) for the platform - #[cfg(any( - all(target_arch = "aarch64", target_os = "linux"), - all(target_arch = "arm", target_os = "linux") - ))] - { - let _md_len = mm_gen_MD( - km, - &mut cs_string, - &mut m_cs_string, - &self.idx.unwrap() as *const mm_idx_t, - const_ptr, - seq.as_ptr() as *const u8, - ); - let _md_string = std::ffi::CStr::from_ptr(cs_string) - .to_str() - .unwrap() - .to_string(); - Some(_md_string) - } - #[cfg(any( - all(target_arch = "aarch64", target_os = "macos"), - all(target_arch = "x86_64", target_os = "linux"), - all(target_arch = "x86_64", target_os = "macos") - ))] - { - let _md_len = mm_gen_MD( - km, - &mut cs_string, - &mut m_cs_string, - self.idx.unwrap() as *const mm_idx_t, - const_ptr, - seq.as_ptr() as *const i8, - ); - let _md_string = std::ffi::CStr::from_ptr(cs_string) - .to_str() - .unwrap() - .to_string(); - Some(_md_string) - } + let _md_len = mm_gen_MD( + km, + &mut cs_string, + &mut m_cs_string, + self.idx.unwrap() as *const mm_idx_t, + const_ptr, + seq.as_ptr() as *const libc::c_char, + ); + let _md_string = std::ffi::CStr::from_ptr(cs_string) + .to_str() + .unwrap() + .to_string(); + Some(_md_string) } else { None }; @@ -1482,6 +1381,7 @@ mod tests { let mappings = aligner.map("atCCTACACTGCATAAACTATTTTGcaccataaaaaaaagttatgtgtgGGTCTAAAATAATTTGCTGAGCAATTAATGATTTCTAAATGATGCTAAAGTGAACCATTGTAatgttatatgaaaaataaatacacaattaagATCAACACAGTGAAATAACATTGATTGGGTGATTTCAAATGGGGTCTATctgaataatgttttatttaacagtaatttttatttctatcaatttttagtaatatctacaaatattttgttttaggcTGCCAGAAGATCGGCGGTGCAAGGTCAGAGGTGAGATGTTAGGTGGTTCCACCAACTGCACGGAAGAGCTGCCCTCTGTCATTCAAAATTTGACAGGTACAAACAGactatattaaataagaaaaacaaactttttaaaggCTTGACCATTAGTGAATAGGTTATATGCTTATTATTTCCATTTAGCTTTTTGAGACTAGTATGATTAGACAAATCTGCTTAGttcattttcatataatattgaGGAACAAAATTTGTGAGATTTTGCTAAAATAACTTGCTTTGCTTGTTTATAGAGGCacagtaaatcttttttattattattataattttagattttttaatttttaaat".as_bytes(), true, false, None, None).unwrap(); println!("{:#?}", mappings); + panic!(); } #[test] @@ -1692,9 +1592,11 @@ mod tests { let query = "GGTCGTCGTCTCGATACTGCCACTATGCCTTTATATTATTGTCTTCAGGTGATGCTGCAGATCGTGCAGACGGGTGGCTTTAGTGTTGTGGGATGCATAGCTATTGACGGATCTTTGTCAATTGACAGAAATACGGGTCTCTGGTTTGACATGAAGGTCCAACTGTAATAACTGATTTTATCTGTGGGTGATGCGTTTCTCGGACAACCACGACCGCGACCAGACTTAAGTCTGGGCGCGGTCGTGGTT"; let aligner = Aligner::builder().short(); let aligner = aligner.with_seq(seq.as_bytes()).unwrap(); + let alignments = aligner .map(query.as_bytes(), false, false, None, None) .unwrap(); + assert_eq!(alignments.len(), 2); println!("----- Trying with_seqs 1"); @@ -1733,6 +1635,8 @@ mod tests { .unwrap(); assert_eq!(alignments.len(), 2); + println!("----- Trying with_seq and id"); + let seq = "CGGCACCAGGTTAAAATCTGAGTGCTGCAATAGGCGATTACAGTACAGCACCCAGCCTCCGAAATTCTTTAACGGTCGTCGTCTCGATACTGCCACTATGCCTTTATATTATTGTCTTCAGGTGATGCTGCAGATCGTGCAGACGGGTGGCTTTAGTGTTGTGGGATGCATAGCTATTGACGGATCTTTGTCAATTGACAGAAATACGGGTCTCTGGTTTGACATGAAGGTCCAACTGTAATAACTGATTTTATCTGTGGGTGATGCGTTTCTCGGACAACCACGACCGCGACCAGACTTAAGTCTGGGCGCGGTCGTGGTTGTCCGAGAAACGCATCACCCACAGATAAAATCAGTTATTACAGTTGGACCTTTATGTCAAACCAGAGACCCGTATTTC"; let query = "CAGGTGATGCTGCAGATCGTGCAGACGGGTGGCTTTAGTGTTGTGGGATGCATAGCTATTGACGGATCTTTGTCAATTGACAGAAATACGGGTCTCTGGTTTGACATGAAGGTCCAACTGTAATAACTGATTTTATCTGTGGGTGATGCGTTTCTCGGACAACCACGACCGCGACCAGACTTAAGTCTGGGCGCGGTCGTGGTTGTCCGAGAAACGCATCACCCACAGATAAAATCAGTTATTACAGTTGGACCTTTATGTCAAACCAGAGACCCGTATTTC"; @@ -1744,9 +1648,11 @@ mod tests { let aligner = aligner .with_seq_and_id(seq.as_bytes(), &id.as_bytes().to_vec()) .unwrap(); + println!("mapping..."); let alignments = aligner .map(query.as_bytes(), true, true, None, None) .unwrap(); + println!("Mapped"); assert_eq!(alignments.len(), 1); println!( "{:#?}", @@ -1801,35 +1707,38 @@ mod tests { let _aligner = Aligner::builder().splice(); let _aligner = Aligner::builder().cdna(); - let aligner = Aligner::builder(); - assert_eq!( - aligner.map_file("test_data/MT-human.fa", false, false), - Err("No index") - ); - let aligner = aligner.with_index("test_data/MT-human.fa", None).unwrap(); - assert_eq!( - aligner.map_file("test_data/file-does-not-exist", false, false), - Err("File does not exist") - ); + #[cfg(feature = "map-file")] + { + let aligner = Aligner::builder(); + assert_eq!( + aligner.map_file("test_data/MT-human.fa", false, false), + Err("No index") + ); + let aligner = aligner.with_index("test_data/MT-human.fa", None).unwrap(); + assert_eq!( + aligner.map_file("test_data/file-does-not-exist", false, false), + Err("File does not exist") + ); - if let Err("File is empty") = Aligner::builder().with_index("test_data/empty.fa", None) { - println!("File is empty - Success"); - } else { - panic!("File is empty error not thrown"); - } + if let Err("File is empty") = Aligner::builder().with_index("test_data/empty.fa", None) { + println!("File is empty - Success"); + } else { + panic!("File is empty error not thrown"); + } - if let Err("Invalid Path") = Aligner::builder().with_index("\0invalid_\0path\0", None) { - println!("Invalid Path - Success"); - } else { - panic!("Invalid Path error not thrown"); - } + if let Err("Invalid Path") = Aligner::builder().with_index("\0invalid_\0path\0", None) { + println!("Invalid Path - Success"); + } else { + panic!("Invalid Path error not thrown"); + } - if let Err("Invalid Output") = - Aligner::builder().with_index("test_data/MT-human.fa", Some("test\0test")) - { - println!("Invalid output - Success"); - } else { - panic!("Invalid output error not thrown"); + if let Err("Invalid Output") = + Aligner::builder().with_index("test_data/MT-human.fa", Some("test\0test")) + { + println!("Invalid output - Success"); + } else { + panic!("Invalid output error not thrown"); + } } }