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

alignment score #78

Merged
merged 6 commits into from
Aug 20, 2024
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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Binary file removed my_index.mmi
Binary file not shown.
51 changes: 48 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ pub struct Alignment {
pub cigar_str: Option<String>,
pub md: Option<String>,
pub cs: Option<String>,
pub alignment_score: Option<u32>,
}

/// Mapping result
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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)
};

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -1063,6 +1086,7 @@ impl Aligner {
cigar_str,
md: md_str,
cs: cs_str,
alignment_score: Some(p.dp_score as u32),
})
} else {
None
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions test_data/cDNA.fasta
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
>fwd
GAAATACGGGTCTCTGGTTTGACATAAAGGTCCAACTGTAATAACTGATTTTATCTGTGGGTGATGCGTTTCTCGGACAACCACGACCGCGCCCAGACTTAAATCGCACATACTGCGTCGTGCAATGCCGGGCGCTAACGGCTCAATATCACGCTGCGTCACTATGGCTACCCCAAAGCGGGGGGGGCATCGACGGGCTGTTTGATTTGAGCTCCATTACCCTACAATTAGAACACTGGCAACATTTGGGCGTTGAGCGGTCTTCCGTGTCGCTCGATCCGCTGGAACTTGGCAACCACACTCTAAACTACATGTGGTATGGCTCATAAGATCATGCGGATCGTGGCACTGCTTTCGGCCACGTTAGAGCCGCTGTGCTCGAAGATTGGGACCTACCAAC
Binary file removed yeast_ref.mmi
Binary file not shown.
Loading