Skip to main content

RangeSearch

Struct RangeSearch 

Source
pub struct RangeSearch<'a, Q: ?Sized> { /* private fields */ }
Expand description

A subsequence along with its starting index. This is used for restricting the search range when performing a search. See Restricting the search range for more details.

It is compatible with:

  • Performing string search via the ByteSubstring trait
  • Searching for k-mers using methods similar to those in FindKmers
  • Searching for amino acids in a nucleotides sequence similar to methods in Translate. This requires the original type to implement Translate also

Note

All search methods called on a RangeSearch struct return indices with respect to the original sequence, not the subsequence.

§Parameters

Q tracks the type of the original sequence type. This controls whether find_next_aa and find_next_aa_in_frame are available.

Implementations§

Source§

impl<Q> RangeSearch<'_, Q>
where Q: Translate,

Source

pub fn find_next_aa(self, aa: u8) -> Option<usize>

Slides base by base over the sequence until the next translated aa is found and returns that index (or None otherwise).

Source

pub fn find_next_aa_in_frame(self, aa: u8) -> Option<usize>

Slides codon by codon over the sequence (reading frame starting from 0 in the full sequence) until the next translated aa is found and returns that index (or None otherwise).

This is different than calling Translate::find_next_aa_in_frame on a slice, since it uses the reading frame of the full sequence, irrelevant of the starting position of the search.

Source§

impl<'a, Q: ?Sized> RangeSearch<'a, Q>

Source

pub fn position<P>(&self, predicate: P) -> Option<usize>
where P: FnMut(u8) -> bool,

Takes a closure and returns the index of the first byte found within the sequence that satisfies the closure. Wraps Iterator::position.

Source

pub fn rposition<P>(&self, predicate: P) -> Option<usize>
where P: FnMut(u8) -> bool,

Takes a closure and returns the index of the last byte found within the sequence that satisfies the closure. Wraps Iterator::rposition.

Source

pub fn find_kmers<const MAX_LEN: usize, T>( self, kmers: &T, ) -> Option<Range<usize>>
where T: FindKmersInSeq<MAX_LEN>,

Returns the indices of the leftmost occurrence of any of the k-mers in the passed collection.

If no occurrence is found, then None is returned. To find all matches rather than just the first, use find_all_kmers. A similar unrestricted version of this method exists in FindKmers.

Source

pub fn find_kmers_rev<const MAX_LEN: usize, T>( self, kmers: &T, ) -> Option<Range<usize>>
where T: FindKmersInSeq<MAX_LEN>,

Returns the indices of the rightmost occurrence of any of the k-mers in the passed collection.

If no occurrence is found, then None is returned. To find all matches rather than just the last, use find_all_kmers. A similar unrestricted version of this method exists in FindKmers.

Source

pub fn find_all_kmers<const MAX_LEN: usize, T>( self, kmers: &'a T, ) -> impl Iterator<Item = Range<usize>> + 'a
where Q: 'a, T: FindKmersInSeq<MAX_LEN>,

Returns an iterator over the indices of all matches between the k-mers in the sequence and those in the passed collection.

Consider using find_kmers if only a single match is needed. A similar unrestricted version of this method exists in FindKmers.

Source

pub fn find_all_kmers_rev<const MAX_LEN: usize, T>( self, kmers: &'a T, ) -> impl Iterator<Item = Range<usize>> + 'a
where Q: 'a, T: FindKmersInSeq<MAX_LEN>,

Returns an iterator over the indices of all matches between the k-mers in the sequence and those in the passed collection, in reverse order.

Consider using find_kmers_rev if only a single match is needed. A similar unrestricted version of this method exists in FindKmers.

Trait Implementations§

Source§

impl<Q: ?Sized> ByteSubstring for RangeSearch<'_, Q>

Source§

fn contains_substring(&self, needle: impl AsRef<[u8]>) -> bool

Returns true is the substring is found and false if not. Searches in the forward direction.
Source§

fn find_substring(&self, needle: impl AsRef<[u8]>) -> Option<Range<usize>>

Returns the substring’s index range if found or None if not. Searches in the forward direction.
Source§

fn find_fuzzy_substring<const DIFFERENCES_ALLOWED: usize>( &self, needle: impl AsRef<[u8]>, ) -> Option<Range<usize>>

Finds the needle in the haystack using inexact matching up to the DIFFERENCES_ALLOWED. Read more
Source§

fn find_byte(&self, byte: u8) -> Option<usize>

Finds the first occurrence of the byte in the haystack.
Source§

fn find_repeating_byte(&self, needle: u8, size: usize) -> Option<Range<usize>>

Find contiguous, repeating byte characters in a byte slice. See find_k_repeating for more details.
Source§

fn find_repeating_at_start( &self, needle: u8, min_reps: usize, ) -> Option<Range<usize>>

Checks if the slice begins with some minimal number of consecutive byte repetitions and returns the largest contiguous range if so.
Source§

fn find_repeating_at_end( &self, needle: u8, min_reps: usize, ) -> Option<Range<usize>>

Checks if the slice ends with some minimal number of consecutive byte repetitions and returns the largest contiguous range if so.

Auto Trait Implementations§

§

impl<'a, Q> Freeze for RangeSearch<'a, Q>
where Q: ?Sized,

§

impl<'a, Q> RefUnwindSafe for RangeSearch<'a, Q>
where Q: RefUnwindSafe + ?Sized,

§

impl<'a, Q> Send for RangeSearch<'a, Q>
where Q: Send + ?Sized,

§

impl<'a, Q> Sync for RangeSearch<'a, Q>
where Q: Sync + ?Sized,

§

impl<'a, Q> Unpin for RangeSearch<'a, Q>
where Q: Unpin + ?Sized,

§

impl<'a, Q> UnsafeUnpin for RangeSearch<'a, Q>
where Q: ?Sized,

§

impl<'a, Q> UnwindSafe for RangeSearch<'a, Q>
where Q: UnwindSafe + ?Sized,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.