Skip to main content

DnaString

Struct DnaString 

Source
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

Source

pub fn new() -> DnaString

Create an empty DNA string

Source

pub fn len(&self) -> usize

Length of the sequence

Source

pub fn with_capacity(n: usize) -> Self

Create a new instance with a given capacity.

Source

pub fn blank(n: usize) -> Self

Create a DnaString of length n initialized to all A’s

Source

pub fn from_dna_string(dna: &str) -> DnaString

Create a DnaString corresponding to an ACGT-encoded str.

Source

pub fn from_dna_only_string(dna: &str) -> Vec<DnaString>

Create a DnaString corresponding to an ACGT-encoded str.

Source

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’

Source

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

Source

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.

Source

pub fn from_bytes(bytes: &[u8]) -> DnaString

Create a DnaString from a 0-4 encoded byte slice

Source

pub fn to_bytes(&self) -> Vec<u8> ⓘ

Convert sequence to a Vector of 0-4 encoded bytes

Source

pub fn to_ascii_vec(&self) -> Vec<u8> ⓘ

Convert sequence to a Vector of ascii-encoded bytes

Source

pub fn push(&mut self, value: u8)

Append a 0-4 encoded base.

Source

pub fn extend(&mut self, bytes: impl Iterator<Item = u8>)

Source

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.

Source

pub fn iter(&self) -> DnaStringIter<'_> ⓘ

Iterate over stored values (values will be unpacked into bytes).

Source

pub fn clear(&mut self)

Clear the sequence.

Source

pub fn is_empty(&self) -> bool

Source

pub fn prefix(&self, k: usize) -> DnaStringSlice<'_>

Get the length k prefix of the DnaString

Source

pub fn suffix(&self, k: usize) -> DnaStringSlice<'_>

Get the length k suffix of the DnaString

Source

pub fn slice(&self, start: usize, end: usize) -> DnaStringSlice<'_>

Get slice containing the interval [start, end) of self

Source

pub fn reverse(&self) -> DnaString

Create a fresh DnaString containing the reverse of self

Source

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.

Source

pub fn shrink_to_fit(&mut self)

shrink the storage of the DnaString to fit its contents

Trait Implementations§

Source§

impl Clone for DnaString

Source§

fn clone(&self) -> DnaString

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DnaString

Source§

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

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

impl Default for DnaString

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for DnaString

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for DnaString

Source§

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

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

impl Eq for DnaString

Source§

impl Hash for DnaString

Source§

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

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

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a> IntoIterator for &'a DnaString

Source§

type Item = u8

The type of the elements being iterated over.
Source§

type IntoIter = DnaStringIter<'a>

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

fn into_iter(self) -> DnaStringIter<'a> ⓘ

Creates an iterator from a value. Read more
Source§

impl Mer for DnaString

Source§

fn get(&self, i: usize) -> u8

Get the value at position i.

Source§

fn set_mut(&mut self, i: usize, value: u8)

Set the value as position i.

Source§

fn len(&self) -> usize

Length of DNA sequence
Source§

fn is_empty(&self) -> bool

True if the sequence is empty.
Source§

fn set_slice_mut(&mut self, _: usize, _: usize, _: u64)

Set nbases positions in the sequence, starting at pos. Values must be packed into the upper-most bits of value.
Source§

fn rc(&self) -> DnaString

Return a new object containing the reverse complement of the sequence
Source§

fn iter(&self) -> MerIter<'_, Self> ⓘ

Iterate over the bases in the sequence
Source§

fn at_count(&self) -> u32

Count the number of A/T bases in the kmer
Source§

fn gc_count(&self) -> u32

Count the number of G/C bases in the kmer
Source§

impl Ord for DnaString

Source§

fn cmp(&self, other: &DnaString) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for DnaString

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialOrd for DnaString

Source§

fn partial_cmp(&self, other: &DnaString) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for DnaString

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for DnaString

Source§

impl Vmer for DnaString

Source§

fn get_kmer<K: Kmer>(&self, pos: usize) -> K

Get the kmer starting at position pos

Source§

fn new(len: usize) -> Self

Create a new sequence with length len, initialized to all A’s
Source§

fn max_len() -> usize

Maximum sequence length that can be stored in this type
Source§

fn from_slice(seq: &[u8]) -> Self

Create a Vmer from a sequence of bytes
Source§

fn first_kmer<K: Kmer>(&self) -> K

Get the first Kmer from the sequence
Source§

fn last_kmer<K: Kmer>(&self) -> K

Get the last kmer in the sequence
Source§

fn both_term_kmer<K: Kmer>(&self) -> (K, K)

Get the terminal kmer of the sequence, on the both side of the sequence
Source§

fn term_kmer<K: Kmer>(&self, dir: Dir) -> K

Get the terminal kmer of the sequence, on the side of the sequence given by dir
Source§

fn iter_kmers<K: Kmer>(&self) -> KmerIter<'_, K, Self> ⓘ

Iterate over the kmers in the sequence
Source§

fn iter_kmer_exts<K: Kmer>(&self, seq_exts: Exts) -> KmerExtsIter<'_, K, Self> ⓘ

Iterate over the kmers and their extensions, given the extensions of the whole sequence

Auto Trait Implementations§

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
§

impl<T> ConstructibleKey for T
where T: Hash + Debug + PartialEq + Send + Sync,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> MerImmut for T
where T: Mer + Clone,

Source§

fn set(&self, pos: usize, val: u8) -> Self

Source§

fn set_slice(&self, pos: usize, nbases: usize, bits: u64) -> Self

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V