pub struct SeqSlice<A: Codec> { /* private fields */ }Expand description
An unsized, read-only window into part of a sequence
Implementations§
Source§impl<'a, A: Codec> SeqSlice<A>
impl<'a, A: Codec> SeqSlice<A>
pub fn chain( self: &'a SeqSlice<A>, second: &'a SeqSlice<A>, ) -> Chain<SeqIter<'a, A>, SeqIter<'a, A>>
pub fn iter(&'a self) -> SeqIter<'a, A> ⓘ
Sourcepub fn kmers<const K: usize>(&self) -> KmerIter<'_, A, K> ⓘ
pub fn kmers<const K: usize>(&self) -> KmerIter<'_, A, K> ⓘ
Iterate over sliding windows of length K
Sourcepub fn windows(&self, width: usize) -> SeqChunks<'_, A> ⓘ
pub fn windows(&self, width: usize) -> SeqChunks<'_, A> ⓘ
Iterate over the sequence in overlapping windows of a specified width
use bio_seq::prelude::*;
let seq: Seq<Dna> = "ACTGATCG".try_into().unwrap();
let windows: Vec<String> = seq.windows(3).map(String::from).collect();
assert_eq!(windows, vec!["ACT", "CTG", "TGA", "GAT", "ATC", "TCG"]);Sourcepub fn chunks(&self, width: usize) -> SeqChunks<'_, A> ⓘ
pub fn chunks(&self, width: usize) -> SeqChunks<'_, A> ⓘ
Iterate over the sequence in non-overlapping chunks of a specified width
The last incomplete chunk will be excluded if the sequence length is not divisible by the specified width.
use bio_seq::prelude::*;
let seq: Seq<Dna> = "ACTGATCG".try_into().unwrap();
let chunks: Vec<Seq<Dna>> = seq.chunks(3).collect();
assert_eq!(chunks, vec![dna!("ACT"), dna!("GAT")]);Trait Implementations§
Source§impl<A: Codec> AsRef<SeqSlice<A>> for Seq<A>
A Seq can be borrowed as a SeqSlice through generic constraints.
impl<A: Codec> AsRef<SeqSlice<A>> for Seq<A>
A Seq can be borrowed as a SeqSlice through generic constraints.
fn count_bases<S: AsRef<SeqSlice<Dna>>>(s: S) -> usize {
s.as_ref().len()
}
let seq: Seq<Dna> = dna!("CATCGATCGATC").into();
let count = count_bases(seq); // the AsRef implementation allows us to directly pass a Seq
assert_eq!(count, 12);Source§impl<A: Codec> Borrow<SeqSlice<A>> for Seq<A>
Borrow a Seq<A> as a SeqSlice<A>.
impl<A: Codec> Borrow<SeqSlice<A>> for Seq<A>
Borrow a Seq<A> as a SeqSlice<A>.
The Borrow trait to is used to obtain a reference to a SeqSlice from a Seq, allowing it to be used wherever a SeqSlice is expected.
use std::collections::HashMap;
use bio_seq::prelude::*;
let reference = dna!("ACGTTCGCATGCTACGACGATC");
let mut table: HashMap<Seq<Dna>, usize> = HashMap::new();
// Associate some kind of count with sequences as keys:
table.insert(dna!("ACGTT").into(), 1);
table.insert(dna!("ACACCCCC").into(), 0);
// The query is a short window in the reference `Seq`
let query: &SeqSlice<Dna> = &reference[..5];
if let Some(value) = table.get(query) {
// `SeqSlice` implements `Display`
println!("{query}: {value}");
}Source§impl<A: Codec + ComplementMut> Complement for SeqSlice<A>
impl<A: Codec + ComplementMut> Complement for SeqSlice<A>
Source§impl<A: Codec + ComplementMut> ComplementMut for SeqSlice<A>
impl<A: Codec + ComplementMut> ComplementMut for SeqSlice<A>
Source§impl<A: Codec> Hash for SeqSlice<A>
Warning! hashes are not currently stable between platforms/version
impl<A: Codec> Hash for SeqSlice<A>
Warning! hashes are not currently stable between platforms/version
Source§impl<'a, A: Codec> IntoIterator for &'a SeqSlice<A>
impl<'a, A: Codec> IntoIterator for &'a SeqSlice<A>
Source§impl<A: Codec + ComplementMut> ReverseComplement for SeqSlice<A>
impl<A: Codec + ComplementMut> ReverseComplement for SeqSlice<A>
fn to_revcomp(&self) -> <Self as ToOwned>::Owned
Source§impl<A: Codec + ComplementMut> ReverseComplementMut for SeqSlice<A>
impl<A: Codec + ComplementMut> ReverseComplementMut for SeqSlice<A>
Source§impl<A: Codec> ToOwned for SeqSlice<A>
Clone a borrowed slice of a sequence into an owned version.
impl<A: Codec> ToOwned for SeqSlice<A>
Clone a borrowed slice of a sequence into an owned version.
use bio_seq::prelude::*;
let seq = dna!("CATCGATCGATCG");
let slice = &seq[2..7]; // TCGAT
let owned = slice.to_owned();
assert_eq!(&owned, &seq[2..7]);impl<A: Eq + Codec> Eq for SeqSlice<A>
Auto Trait Implementations§
impl<A> Freeze for SeqSlice<A>
impl<A> RefUnwindSafe for SeqSlice<A>where
A: RefUnwindSafe,
impl<A> Send for SeqSlice<A>where
A: Send,
impl<A> !Sized for SeqSlice<A>
impl<A> Sync for SeqSlice<A>where
A: Sync,
impl<A> Unpin for SeqSlice<A>where
A: Unpin,
impl<A> UnwindSafe for SeqSlice<A>where
A: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Pipes by value. This is generally the method you want to use. Read more
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
Borrows
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
Mutably borrows
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
Borrows
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
Mutably borrows
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
Borrows
self, then passes self.deref() into the pipe function.