Skip to content

Commit

Permalink
#71 move drop to minimap2-sys
Browse files Browse the repository at this point in the history
impl Drop for mm_idx_t {
    fn drop(&mut self) {
        unsafe { mm_idx_destroy(self) };
    }
}
  • Loading branch information
jguhlin committed Nov 25, 2024
1 parent a60a985 commit 36ab013
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ test_data/*.bam
test_data/*.mmi
.ipynb_checkpoints
.vscode/
.quarto
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ rayon = "1.10"

[features]
default = ["map-file"]
sse2only = ["minimap2-sys/sse2only"]
map-file = ["needletail"] #, "simdutf8"]
htslib = ['rust-htslib']
simde = ["minimap2-sys/simde"]
map-file = ["needletail"] #, "simdutf8"]
zlib-ng = ["minimap2-sys/zlib-ng"]
curl = ["rust-htslib/curl"]
static = ["minimap2-sys/static", "rust-htslib/static"]
sse2only = ["minimap2-sys/sse2only"]


[package.metadata.docs.rs]
features = ["map-file", "htslib"]
45 changes: 24 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@ A rust FFI library for [minimap2](https://github.com/lh3/minimap2/). In developm
[![codecov](https://codecov.io/gh/jguhlin/minimap2-rs/branch/main/graph/badge.svg?token=huw27ZC6Qy)](https://codecov.io/gh/jguhlin/minimap2-rs)

# Structure
minimap2-sys is the library of the raw FFI bindings to minimap2. minimap2 is the more rusty version.
minimap2-sys is the raw FFI bindings to minimap2. minimap2 is the more opinionated, rusty version.

# How to use
## Requirements
```toml
minimap2 = "0.1.20+minimap2.2.28"
minimap2 = "0.1.21+minimap2.2.28"
```
Also see [Features](#features)

Tested with rustc 1.64.0 and nightly. So probably a good idea to upgrade before running. But let me know if you run into pain points with older versions and will try to fix!
Tested with rustc 1.82.0 and nightly. So probably a good idea to upgrade before running. But let me know if you run into pain points with older versions and will try to fix.

## Minimap2 Version Table
| minimap2-rs | minimap2 |
|-------------|----------|
| 0.1.21 | 2.28 |
| 0.1.20 | 2.28 |
| 0.1.19 | 2.28 |
| 0.1.18 | 2.28 |
Expand Down Expand Up @@ -117,19 +118,21 @@ let results = sequences.par_iter().map(|seq| {

## Features
The following crate features are available:
* `mm2-fast` - Replace minimap2 with [mm2-fast](https://github.com/bwa-mem2/mm2-fast). This is likely not portable.
* `htslib` - Support output of bam/sam files using htslib.
* `simde` - Compile minimap2 / mm2-fast with [simd-everywhere](https://github.com/simd-everywhere/simde) support.
* `map-file` - *Default* - Convenience function for mapping an entire file. Caution, this is single-threaded.
* `sse2only` - Compiles for SSE2 support only (Default is to try to compile for SSE4.1, SSE2 only is default on aarch64)
* map-file - Enables the ability to map a file directly to a reference. Enabled by deafult
* htslib - Provides an interface to minimap2 that returns rust_htslib::Records
* simde - Enables SIMD Everywhere library in minimap2
* zlib-ng - Enables the use of zlib-ng for faster compression
* curl - Enables curl for htslib
* static - Builds minimap2 as a static library
* sse2only - Builds minimap2 with only SSE2 support

Map-file is a *default* feature and enabled unless otherwise specified.

## Missing Features
* setting mismatch penalty for base transitions [minimap 2.27 release notes](https://github.com/lh3/minimap2/releases/tag/v2.27)
* Generate ds tags to indicate uncertainty in indels

Potentially more, but I'm using this to keep track. I'd expect those would get implemented over time, but if you have urgent need open a pull request or an issue! Thanks
Potentially others. Please create an issue!

## Building for MUSL
Follow these [instructions](https://github.com/rust-cross/rust-musl-cross#prebuilt-images).
Expand All @@ -141,10 +144,9 @@ alias rust-musl-builder='docker run --rm -it -v "$(pwd)":/home/rust/src messense
rust-musl-builder cargo build --release
```

Please note minimap2 is only tested for x86_64. Other platforms may work, please open an issue if minimap2 compiles but minimap2-rs does not.
Minimap2 is tested on x86_64 and aarch64 (arm64). Other platforms may work, please open an issue if minimap2 compiles but minimap2-rs does not.

### Features tested with MUSL
* `mm2-fast` - **Fail**
* `htslib` - **Success**
* `simde` - **Success**

Expand All @@ -153,23 +155,19 @@ Please note minimap2 is only tested for x86_64. Other platforms may work, please
- [mappy-rs](https://github.com/Adoni5/mappy-rs) - Drop-in multi-threaded replacement for python's mappy
- [HiFiHLA](https://github.com/PacificBiosciences/hifihla) - HLA star-calling tool for PacBio HiFi data
- [STRdust](https://github.com/wdecoster/STRdust) - Tandem repeat genotyper for long reads

# Want feedback
* Many fields are i32 / i8 to mimic the C environment, but would it make more sense to convert to u32 / u8 / usize?
* Let me know pain points!
- [oarfish](https://github.com/COMBINE-lab/oarfish) - transcript quantification from long-read RNA-seq data

# Next things todo
* Print other tags so we can have an entire PAF format
* -sys Compile with SSE2 / SSE4.1 (auto-detect, but also make with features)
* Multi-thread guide (tokio async threads or use crossbeam queue and traditional threads?)
* Iterator interface for map_file
* MORE TESTS
* -sys Get SSE working with "sse" feature (compiles and tests work in -sys crate, but not main crate)
* -sys Possible to decouple from pthread?
* -sys Enable Lisa-hash for mm2-fast? But must handle build arguments from the command-line.

# Citation
You should cite the minimap2 papers if you use this in your work.
Please cite the appropriate minimap2 papers if you use this in your work, as well as this library.

## DOI for this library

## Minimap2 Papers

> Li, H. (2018). Minimap2: pairwise alignment for nucleotide sequences.
> *Bioinformatics*, **34**:3094-3100. [doi:10.1093/bioinformatics/bty191][doi]
Expand All @@ -180,6 +178,11 @@ and/or:
> *Bioinformatics*, **37**:4572-4574. [doi:10.1093/bioinformatics/btab705][doi2]
# Changelog
### 0.1.21 minimap2 2.28
#### Breaking Changes
+ Map now returns Arc String's to reduce memory allocation for large and/or repetitive jobs
+ map now takes an additional argument, query_name: Option<impl AsRef<[u8]>>

### 0.1.20 minimap2 2.28
+ Fix htslib errors. No update to -sys crate needed.

Expand Down
34 changes: 31 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! API providing a rusty interface to minimap2 or mm2-fast libraries.
//! API providing a rusty interface to minimap2
//!
//! This library supports statically linking and compiling minimap2 directly, no separate install is required.
//!
Expand All @@ -12,10 +12,26 @@
//! # Crate Features
//! This crate has multiple create features available.
//! * map-file - Enables the ability to map a file directly to a reference. Enabled by deafult
//! * mm2-fast - Uses the mm2-fast library instead of standard minimap2
//! * htslib - Provides an interface to minimap2 that returns rust_htslib::Records
//! * simde - Enables SIMD Everywhere library in minimap2
//! * sse - Enables the use of SSE instructions
//! * zlib-ng - Enables the use of zlib-ng for faster compression
//! * curl - Enables curl for htslib
//! * static - Builds minimap2 as a static library
//! * sse2only - Builds minimap2 with only SSE2 support
//!
//! ## Previously Supported Features
//! * mm2-fast - Uses the mm2-fast library instead of standard minimap2
//!
//! If needed, this can be re-enabled.
//!
//! # Compile-time options
//! I recommend the following:
//! ```toml
//! [profile.release]
//! opt-level = 3
//! lto = "fat"
//! codegen-units = 1
//! ```
//!
//! # Examples
//! ## Mapping a file to a reference
Expand Down Expand Up @@ -2050,7 +2066,19 @@ mod tests {

jh1.join().unwrap();
});
}

// Test aligner cloning for flag permanence
#[test]
fn aligner_cloning_flags() {
let aligner = Aligner::builder().map_ont().with_cigar().with_index("yeast_ref.mmi", None).unwrap();
// Confirm with_cigar is set
// self.mapopt.flag |= MM_F_CIGAR as i64;
assert_eq!(aligner.mapopt.flag & MM_F_CIGAR as i64, MM_F_CIGAR as i64);

// Clone aligner
let aligner_clone = aligner.clone();
assert_eq!(aligner_clone.mapopt.flag & MM_F_CIGAR as i64, MM_F_CIGAR as i64);
}

}

0 comments on commit 36ab013

Please sign in to comment.