diff --git a/Cargo.toml b/Cargo.toml index dad80e8..3b2519e 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/my_index.mmi b/my_index.mmi deleted file mode 100644 index 2f2a785..0000000 Binary files a/my_index.mmi and /dev/null differ diff --git a/src/lib.rs b/src/lib.rs index 3527521..9aaa281 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -198,6 +198,7 @@ pub struct Alignment { pub cigar_str: Option, pub md: Option, pub cs: Option, + pub alignment_score: Option, } /// Mapping result @@ -328,14 +329,20 @@ impl Default for Aligner { impl Aligner { /// Create a new aligner with default options pub fn builder() -> Self { - Aligner { + let mut aligner = Aligner { mapopt: MapOpt { - seed: 42, + seed: 11, best_n: 1, ..Default::default() }, ..Default::default() + }; + + unsafe { + minimap2_sys::mm_set_opt(&0, &mut aligner.idxopt, &mut aligner.mapopt); } + + aligner } } @@ -484,7 +491,7 @@ impl Aligner { let mut mapopt = MapOpt::default(); unsafe { - // Set preset + mm_set_opt(&0, &mut idxopt, &mut mapopt); mm_set_opt(preset.into(), &mut idxopt, &mut mapopt) }; @@ -548,6 +555,20 @@ impl Aligner { self } + // Check options + pub fn check_opts(&self) -> Result<(), &'static str> { + let result = unsafe { + mm_check_opt(&self.idxopt, &self.mapopt) + }; + + if result == 0 { + Ok(()) + } else { + Err("Invalid options") + } + } + + /// Set index parameters for minimap2 using builder pattern /// Creates the index as well with the given number of threads (set at struct creation). /// You must set the number of threads before calling this function. @@ -870,6 +891,8 @@ impl Aligner { let is_primary = reg.parent == reg.id; let is_supplementary = reg.sam_pri() == 0; + + // todo holy heck this code is ugly let alignment = if !reg.p.is_null() { let p = &*reg.p; @@ -1063,6 +1086,7 @@ impl Aligner { cigar_str, md: md_str, cs: cs_str, + alignment_score: Some(p.dp_score as u32), }) } else { None @@ -1460,6 +1484,27 @@ mod tests { println!("{:#?}", mappings); } + #[test] + fn test_alignment_score() { + let mut aligner = Aligner::builder() + .preset(Preset::Splice) + .with_index_threads(1); + + aligner.check_opts().expect("Opts are invalid"); + + aligner = aligner + .with_index("test_data/genome.fa", None) + .unwrap(); + + let output = aligner.map( + b"GAAATACGGGTCTCTGGTTTGACATAAAGGTCCAACTGTAATAACTGATTTTATCTGTGGGTGATGCGTTTCTCGGACAACCACGACCGCGCCCAGACTTAAATCGCACATACTGCGTCGTGCAATGCCGGGCGCTAACGGCTCAATATCACGCTGCGTCACTATGGCTACCCCAAAGCGGGGGGGGCATCGACGGGCTGTTTGATTTGAGCTCCATTACCCTACAATTAGAACACTGGCAACATTTGGGCGTTGAGCGGTCTTCCGTGTCGCTCGATCCGCTGGAACTTGGCAACCACACTCTAAACTACATGTGGTATGGCTCATAAGATCATGCGGATCGTGGCACTGCTTTCGGCCACGTTAGAGCCGCTGTGCTCGAAGATTGGGACCTACCAAC", + false, false, None, None).unwrap(); + + println!("{:#?}", aligner.mapopt); + println!("{:#?}", aligner.idxopt); + println!("{:#?}", output); + } + #[test] fn test_aligner_config_and_mapping() { let mut aligner = Aligner::builder() diff --git a/test_data/cDNA.fasta b/test_data/cDNA.fasta new file mode 100644 index 0000000..8f4e502 --- /dev/null +++ b/test_data/cDNA.fasta @@ -0,0 +1,2 @@ +>fwd +GAAATACGGGTCTCTGGTTTGACATAAAGGTCCAACTGTAATAACTGATTTTATCTGTGGGTGATGCGTTTCTCGGACAACCACGACCGCGCCCAGACTTAAATCGCACATACTGCGTCGTGCAATGCCGGGCGCTAACGGCTCAATATCACGCTGCGTCACTATGGCTACCCCAAAGCGGGGGGGGCATCGACGGGCTGTTTGATTTGAGCTCCATTACCCTACAATTAGAACACTGGCAACATTTGGGCGTTGAGCGGTCTTCCGTGTCGCTCGATCCGCTGGAACTTGGCAACCACACTCTAAACTACATGTGGTATGGCTCATAAGATCATGCGGATCGTGGCACTGCTTTCGGCCACGTTAGAGCCGCTGTGCTCGAAGATTGGGACCTACCAAC diff --git a/yeast_ref.mmi b/yeast_ref.mmi deleted file mode 100644 index 22df8b9..0000000 Binary files a/yeast_ref.mmi and /dev/null differ