SeqSlice

Struct SeqSlice 

Source
pub struct SeqSlice<A: Codec> { /* private fields */ }
Expand description

An unsized, read-only window into part of a sequence

Implementations§

Source§

impl SeqSlice<Iupac>

Source

pub fn contains(&self, rhs: &SeqSlice<Iupac>) -> bool

Source§

impl<'a, A: Codec> SeqSlice<A>

Source

pub fn chain( self: &'a SeqSlice<A>, second: &'a SeqSlice<A>, ) -> Chain<SeqIter<'a, A>, SeqIter<'a, A>>

Source

pub fn iter(&'a self) -> SeqIter<'a, A>

Source

pub fn kmers<const K: usize>(&self) -> KmerIter<'_, A, K>

Iterate over sliding windows of length K

Source

pub fn rev_iter(&self) -> RevIter<'_, A>

Iterate over the sequence in reverse order

Source

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"]);
Source

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")]);
Source§

impl<A: Codec> SeqSlice<A>

Source

pub fn nth(&self, i: usize) -> A

unsafely index into the ith position of a sequence

Source

pub fn len(&self) -> usize

Source

pub fn get(&self, i: usize) -> Option<A>

Get the ith element of a Seq. Returns None if index out of range.

Source

pub fn is_empty(&self) -> bool

Trait Implementations§

Source§

impl<A: Codec, const K: usize> AsRef<SeqSlice<A>> for Kmer<A, K, usize>

Source§

fn as_ref(&self) -> &SeqSlice<A>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

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§

fn as_ref(&self) -> &SeqSlice<A>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<A: Codec, const N: usize, const W: usize> AsRef<SeqSlice<A>> for SeqArray<A, N, W>

Source§

fn as_ref(&self) -> &SeqSlice<A>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<A: Codec> AsRef<SeqSlice<A>> for SeqSlice<A>

Source§

fn as_ref(&self) -> &SeqSlice<A>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<A: Codec> BitAnd for &SeqSlice<A>

Source§

type Output = Seq<A>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Self) -> Self::Output

Performs the & operation. Read more
Source§

impl<A: Codec> BitOr for &SeqSlice<A>

Source§

type Output = Seq<A>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Self) -> Self::Output

Performs the | operation. Read more
Source§

impl<A: Codec> Borrow<SeqSlice<A>> for &Seq<A>

Source§

fn borrow(&self) -> &SeqSlice<A>

Immutably borrows from an owned value. Read more
Source§

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§

fn borrow(&self) -> &SeqSlice<A>

Immutably borrows from an owned value. Read more
Source§

impl<A: Codec + ComplementMut> Complement for SeqSlice<A>

Source§

fn to_comp(&self) -> <Self as ToOwned>::Owned

Source§

impl<A: Codec + ComplementMut> ComplementMut for SeqSlice<A>

Source§

fn comp(&mut self)

Source§

impl<A: Debug + Codec> Debug for SeqSlice<A>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<A: Codec> Display for SeqSlice<A>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<A, B: Codec> From<&SeqSlice<A>> for Seq<B>
where A: Into<B> + Codec,

Source§

fn from(slice: &SeqSlice<A>) -> Self

Converts to this type from the input type.
Source§

impl<A: Codec> From<&SeqSlice<A>> for String

Source§

fn from(seq: &SeqSlice<A>) -> Self

Converts to this type from the input type.
Source§

impl<A: Codec> From<&SeqSlice<A>> for u8

Source§

fn from(slice: &SeqSlice<A>) -> u8

Converts to this type from the input type.
Source§

impl<'a, A: Codec> FromIterator<&'a SeqSlice<A>> for Vec<Seq<A>>

Source§

fn from_iter<T: IntoIterator<Item = &'a SeqSlice<A>>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl<A: Codec> Hash for SeqSlice<A>

Warning! hashes are not currently stable between platforms/version

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
Source§

impl<A: Codec> Index<Range<usize>> for SeqSlice<A>

Source§

type Output = SeqSlice<A>

The returned type after indexing.
Source§

fn index(&self, range: Range<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<A: Codec> Index<RangeFrom<usize>> for SeqSlice<A>

Source§

type Output = SeqSlice<A>

The returned type after indexing.
Source§

fn index(&self, range: RangeFrom<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<A: Codec> Index<RangeFull> for SeqSlice<A>

Source§

type Output = SeqSlice<A>

The returned type after indexing.
Source§

fn index(&self, _range: RangeFull) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<A: Codec> Index<RangeInclusive<usize>> for SeqSlice<A>

Source§

type Output = SeqSlice<A>

The returned type after indexing.
Source§

fn index(&self, range: RangeInclusive<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<A: Codec> Index<RangeTo<usize>> for SeqSlice<A>

Source§

type Output = SeqSlice<A>

The returned type after indexing.
Source§

fn index(&self, range: RangeTo<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<A: Codec> Index<RangeToInclusive<usize>> for SeqSlice<A>

Source§

type Output = SeqSlice<A>

The returned type after indexing.
Source§

fn index(&self, range: RangeToInclusive<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<A: Codec> Index<usize> for SeqSlice<A>

Source§

type Output = SeqSlice<A>

The returned type after indexing.
Source§

fn index(&self, i: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a, A: Codec> IntoIterator for &'a SeqSlice<A>

Source§

type Item = A

The type of the elements being iterated over.
Source§

type IntoIter = SeqIter<'a, A>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<A: Codec, const K: usize, S: KmerStorage> PartialEq<&SeqSlice<A>> for Kmer<A, K, S>

Source§

fn eq(&self, seq: &&SeqSlice<A>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<A: Codec> PartialEq<&SeqSlice<A>> for Seq<A>

Source§

fn eq(&self, other: &&SeqSlice<A>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<A: Codec> PartialEq<&str> for SeqSlice<A>

Source§

fn eq(&self, other: &&str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<A: Codec> PartialEq<Seq<A>> for &SeqSlice<A>

Source§

fn eq(&self, other: &Seq<A>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<A: Codec> PartialEq<Seq<A>> for SeqSlice<A>

Source§

fn eq(&self, other: &Seq<A>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<A: Codec> PartialEq<SeqSlice<A>> for &SeqSlice<A>

Source§

fn eq(&self, other: &SeqSlice<A>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<A: Codec, const K: usize, S: KmerStorage> PartialEq<SeqSlice<A>> for Kmer<A, K, S>

Source§

fn eq(&self, seq: &SeqSlice<A>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<A: Codec> PartialEq<SeqSlice<A>> for Seq<A>

Source§

fn eq(&self, other: &SeqSlice<A>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<A: Codec> PartialEq for SeqSlice<A>

Source§

fn eq(&self, other: &SeqSlice<A>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<A: Codec> Reverse for SeqSlice<A>

Source§

fn to_rev(&self) -> <Self as ToOwned>::Owned

Source§

impl<A: Codec + ComplementMut> ReverseComplement for SeqSlice<A>

Source§

fn to_revcomp(&self) -> <Self as ToOwned>::Owned

Source§

impl<A: Codec + ComplementMut> ReverseComplementMut for SeqSlice<A>

Source§

fn revcomp(&mut self)

Reverse complement a sequence in place
Source§

impl<A: Codec> ReverseMut for SeqSlice<A>

Source§

fn rev(&mut self)

Reverse sequence in place
Source§

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]);
Source§

type Owned = Seq<A>

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> Self::Owned

Creates owned data from borrowed data, usually by cloning. Read more
1.63.0 · Source§

fn clone_into(&self, target: &mut Self::Owned)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<A: Codec, const K: usize, S: KmerStorage> TryFrom<&SeqSlice<A>> for Kmer<A, K, S>

Source§

type Error = ParseBioError

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

fn try_from(seq: &SeqSlice<A>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<A: Codec> TryFrom<&SeqSlice<A>> for usize

Source§

type Error = ParseBioError

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

fn try_from(slice: &SeqSlice<A>) -> Result<usize, Self::Error>

Performs the conversion.
Source§

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> 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> Pipe for T
where T: ?Sized,

Source§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where 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) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
Source§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Source§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

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
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

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
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
Source§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more