Skip to content

Commit

Permalink
Some ergonomic functions for getting n_seqs and get_seq
Browse files Browse the repository at this point in the history
  • Loading branch information
jguhlin committed Nov 25, 2024
1 parent 84bd02f commit 4d3be0b
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,31 @@ impl Aligner {

aligner
}

/// Get the number of sequences in the index
pub fn n_seq(&self) -> u32 {
unsafe {
let idx = Arc::as_ptr(self.idx.as_ref().unwrap());
let idx: *const mm_idx_t = *idx;
(*idx).n_seq as u32
}
}

/// Get sequences direct from the index
pub fn get_seq<'aln>(&'aln self, i: usize) -> Option<&'aln mm_idx_seq_t> {
unsafe {
let idx = Arc::as_ptr(self.idx.as_ref().unwrap());
let idx: *const mm_idx_t = *idx;
// todo, should this be > or >=
if i > self.n_seq() as usize {
return None;
}
let seq = (*idx).seq;
let seq = seq.offset(i as isize);
let seq = &*seq;
Some(seq)
}
}
}

impl Aligner {
Expand Down

0 comments on commit 4d3be0b

Please sign in to comment.