pub struct DnaString { /* private fields */ }Expand description
A container for sequence of DNA bases.
use debruijn::dna_string::DnaString;
use debruijn::kmer::Kmer8;
use debruijn::{Mer, Vmer};
let dna_string = DnaString::from_dna_string("ATCGTACGTACGTAGTC");
// Iterate over 8-mers
for k in dna_string.iter_kmers::<Kmer8>() {
println!("{:?}", k);
}
// Get a base, encoded as a byte in 0-3 range
assert_eq!(dna_string.get(0), 0);
assert_eq!(dna_string.get(1), 3);
// Make a read-only 'slice' of a DnaString
let slc = dna_string.slice(1, 10);
assert_eq!(slc.iter_kmers::<Kmer8>().next(), dna_string.iter_kmers::<Kmer8>().skip(1).next());Implementations§
Source§impl DnaString
impl DnaString
Sourcepub fn with_capacity(n: usize) -> Self
pub fn with_capacity(n: usize) -> Self
Create a new instance with a given capacity.
Sourcepub fn from_dna_string(dna: &str) -> DnaString
pub fn from_dna_string(dna: &str) -> DnaString
Create a DnaString corresponding to an ACGT-encoded str.
Sourcepub fn from_dna_only_string(dna: &str) -> Vec<DnaString>
pub fn from_dna_only_string(dna: &str) -> Vec<DnaString>
Create a DnaString corresponding to an ACGT-encoded str.
Sourcepub fn from_acgt_bytes(bytes: &[u8]) -> DnaString
pub fn from_acgt_bytes(bytes: &[u8]) -> DnaString
Create a DnaString from an ASCII ACGT-encoded byte slice. Non ACGT positions will be converted to ‘A’
Sourcepub fn from_acgt_bytes_checked(
bytes: &[u8],
) -> Result<DnaString, AmbiguousBasesError>
pub fn from_acgt_bytes_checked( bytes: &[u8], ) -> Result<DnaString, AmbiguousBasesError>
Create a DnaString from an ASCII ACGT-encoded byte slice.
Will return None if there are ambiguous bases in the DnaString
Sourcepub fn from_acgt_bytes_hashn(bytes: &[u8], read_name: &[u8]) -> DnaString
pub fn from_acgt_bytes_hashn(bytes: &[u8], read_name: &[u8]) -> DnaString
Create a DnaString from an ACGT-encoded byte slice, Non ACGT positions will be converted to repeatable random base determined by a hash of the read name and the position within the string.
Sourcepub fn from_bytes(bytes: &[u8]) -> DnaString
pub fn from_bytes(bytes: &[u8]) -> DnaString
Create a DnaString from a 0-4 encoded byte slice
Sourcepub fn to_ascii_vec(&self) -> Vec<u8> ⓘ
pub fn to_ascii_vec(&self) -> Vec<u8> ⓘ
Convert sequence to a Vector of ascii-encoded bytes
pub fn extend(&mut self, bytes: impl Iterator<Item = u8>)
Sourcepub fn push_bytes(&mut self, bytes: &[u8], seq_length: usize)
pub fn push_bytes(&mut self, bytes: &[u8], seq_length: usize)
Push 0-4 encoded bases from a byte array.
§Arguments
bytes: byte array to read values from
seq_length: how many values to read from the byte array. Note that this
is number of values not number of elements of the byte array.
Sourcepub fn iter(&self) -> DnaStringIter<'_> ⓘ
pub fn iter(&self) -> DnaStringIter<'_> ⓘ
Iterate over stored values (values will be unpacked into bytes).
pub fn is_empty(&self) -> bool
Sourcepub fn prefix(&self, k: usize) -> DnaStringSlice<'_>
pub fn prefix(&self, k: usize) -> DnaStringSlice<'_>
Get the length k prefix of the DnaString
Sourcepub fn suffix(&self, k: usize) -> DnaStringSlice<'_>
pub fn suffix(&self, k: usize) -> DnaStringSlice<'_>
Get the length k suffix of the DnaString
Sourcepub fn slice(&self, start: usize, end: usize) -> DnaStringSlice<'_>
pub fn slice(&self, start: usize, end: usize) -> DnaStringSlice<'_>
Get slice containing the interval [start, end) of self
Sourcepub fn hamming_distance(&self, other: &DnaString) -> usize
pub fn hamming_distance(&self, other: &DnaString) -> usize
Compute Hamming distance between this DnaString and another DnaString. The two strings must have the same length.
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
shrink the storage of the DnaString to fit its contents
Trait Implementations§
Source§impl<'de> Deserialize<'de> for DnaString
impl<'de> Deserialize<'de> for DnaString
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<'a> IntoIterator for &'a DnaString
impl<'a> IntoIterator for &'a DnaString
Source§impl Mer for DnaString
impl Mer for DnaString
Source§impl Ord for DnaString
impl Ord for DnaString
Source§impl PartialOrd for DnaString
impl PartialOrd for DnaString
Source§impl Vmer for DnaString
impl Vmer for DnaString
Source§fn from_slice(seq: &[u8]) -> Self
fn from_slice(seq: &[u8]) -> Self
Source§fn first_kmer<K: Kmer>(&self) -> K
fn first_kmer<K: Kmer>(&self) -> K
Source§fn both_term_kmer<K: Kmer>(&self) -> (K, K)
fn both_term_kmer<K: Kmer>(&self) -> (K, K)
Source§fn term_kmer<K: Kmer>(&self, dir: Dir) -> K
fn term_kmer<K: Kmer>(&self, dir: Dir) -> K
Source§fn iter_kmers<K: Kmer>(&self) -> KmerIter<'_, K, Self> ⓘ
fn iter_kmers<K: Kmer>(&self) -> KmerIter<'_, K, Self> ⓘ
Source§fn iter_kmer_exts<K: Kmer>(&self, seq_exts: Exts) -> KmerExtsIter<'_, K, Self> ⓘ
fn iter_kmer_exts<K: Kmer>(&self, seq_exts: Exts) -> KmerExtsIter<'_, K, Self> ⓘ
impl Eq for DnaString
impl StructuralPartialEq for DnaString
Auto Trait Implementations§
impl Freeze for DnaString
impl RefUnwindSafe for DnaString
impl Send for DnaString
impl Sync for DnaString
impl Unpin for DnaString
impl UnsafeUnpin for DnaString
impl UnwindSafe for DnaString
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.