Skip to content
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "awry"
version = "0.3.0"
version = "0.3.1"
description = "Library for creating FM-indexes from FASTA/FASTQ files. AWRY is able to search at lightning speed by leveraging SIMD vectorization and multithreading over collections of queries."
license = "BSD-3-Clause"
homepage = "https://github.com/UM-Applied-Algorithms-Lab/AWRY_Index"
Expand Down
28 changes: 15 additions & 13 deletions src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,51 @@ use serde::{Deserialize, Serialize};
use crate::{alphabet::Symbol, fm_index::FmIndex};

/// Type representing a position in the BWT
pub (crate) type SearchPtr = u64;
pub(crate) type SearchPtr = u64;

/// Represents the range in the BWT that corresponds to a query. A range is valid (corresponds to at
/// Represents the range in the BWT that corresponds to a query. A range is valid (corresponds to at
/// least one position) as long as start_ptr <= end_ptr
///
///
/// # Example
/// ```no_run
/// use awry::search::SearchRange;
/// use awry::alphabet::{SymbolAlphabet, Symbol};
/// use awry::fm_index::FmIndex;;
/// use std::path::Path;
///
///
/// let fm_index = FmIndex::load(&Path::new("test.awry")).expect("unable to load fm index from file");
/// let search_range = SearchRange::new(&fm_index, Symbol::new_ascii(SymbolAlphabet::Nucleotide, 'A'));
/// ```
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, PartialOrd, Eq, Ord, Hash, Default, MemSize)]
#[derive(
Clone, Serialize, Deserialize, Debug, PartialEq, PartialOrd, Eq, Ord, Hash, Default, MemSize,
)]
pub struct SearchRange {
pub start_ptr: SearchPtr,
pub end_ptr: SearchPtr,
}

impl SearchRange {
/// Creates a new SearchRange, representing all positions in the BWT
///
///
/// # Example
/// ```no_run
/// use awry::fm_index::{FmIndex, FmBuildArgs};
/// use awry::alphabet::{SymbolAlphabet, Symbol};
/// use awry::search::SearchRange;
/// use std::path::Path;
///
///
/// let fm_index = FmIndex::load(&Path::new("test.awry")).expect("unable to load fm index from file");
/// let search_range = SearchRange::new(&fm_index, Symbol::new_ascii(SymbolAlphabet::Nucleotide, 'A'));
/// ```
pub fn new(fm_index: &FmIndex, symbol:Symbol) -> Self {
pub fn new(fm_index: &FmIndex, symbol: Symbol) -> Self {
SearchRange {
start_ptr: fm_index.prefix_sums()[symbol.index() as usize] as SearchPtr,
end_ptr: fm_index.prefix_sums()[(symbol.index()+1) as usize] - 1 as SearchPtr,
end_ptr: fm_index.prefix_sums()[(symbol.index() + 1) as usize] - 1 as SearchPtr,
}
}

/// Creates a new SearchRange, representing an invalid range (i.e., no elements)
pub (crate) fn zero() -> Self {
pub fn zero() -> Self {
SearchRange {
start_ptr: 1,
end_ptr: 0,
Expand All @@ -55,13 +57,13 @@ impl SearchRange {

///returns true if the search range doesn't represent any elements.
#[inline]
pub (crate) fn is_empty(&self) -> bool {
pub fn is_empty(&self) -> bool {
return self.start_ptr > self.end_ptr;
}

///gets the number of elements represented by the search range
#[inline]
pub (crate) fn len(&self) -> SearchPtr {
pub fn len(&self) -> SearchPtr {
match self.is_empty() {
true => 0,
false => self.end_ptr - self.start_ptr + 1,
Expand All @@ -70,7 +72,7 @@ impl SearchRange {

/// Returns an interator over the BWT positions corresponding to this search range
#[inline]
pub (crate) fn range_iter(&self) -> core::ops::Range<SearchPtr> {
pub fn range_iter(&self) -> core::ops::Range<SearchPtr> {
match self.is_empty() {
true => 0..0,
false => self.start_ptr..(self.end_ptr + 1),
Expand Down
Loading