diff --git a/Cargo.toml b/Cargo.toml index c7fd851..1533cda 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/search.rs b/src/search.rs index 36e23e5..a7792a2 100644 --- a/src/search.rs +++ b/src/search.rs @@ -4,22 +4,24 @@ 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, @@ -27,26 +29,26 @@ pub struct SearchRange { 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, @@ -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, @@ -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 { + pub fn range_iter(&self) -> core::ops::Range { match self.is_empty() { true => 0..0, false => self.start_ptr..(self.end_ptr + 1),