Skip to main content

DnaIterExt

Trait DnaIterExt 

Source
pub trait DnaIterExt: Iterator {
    // Provided methods
    fn reverse_complemented<N>(self) -> Complemented<N, Rev<Self>> 
       where Self: Sized + DoubleEndedIterator<Item: AsRef<N>>,
             N: Nucleotide { ... }
    fn complemented<N>(self) -> Complemented<N, Self> 
       where Self: Sized + Iterator<Item: AsRef<N>>,
             N: Nucleotide { ... }
    fn reverse_complement<N>(self)
       where Self: Sized + DoubleEndedIterator<Item: AsMut<N>>,
             N: Nucleotide { ... }
    fn complement<'a, N>(self)
       where Self: Sized + Iterator<Item = &'a mut N>,
             N: Nucleotide { ... }
    fn codons<N>(self) -> Codons<N, Self> 
       where Self: Sized + Iterator<Item: AsRef<N>>,
             N: Nucleotide { ... }
    fn trimmed_to_codon<N>(self) -> Self
       where Self: Sized + DoubleEndedIterator<Item: AsRef<N>> + ExactSizeIterator,
             N: Nucleotide { ... }
    fn translated_by<N, G>(
        self,
        genetic_code: G,
    ) -> Translated<G, Codons<N, Self>> 
       where Self: Sized + Iterator<Item: AsRef<N>>,
             N: Nucleotide,
             G: GeneticCode { ... }
    fn display<N>(&self) -> Display<Self>
       where Self: Clone + Iterator<Item: AsRef<N>>,
             N: Nucleotide { ... }
}
Expand description

Helpers for working with iterators of Nucleotides.

Provided Methods§

Source

fn reverse_complemented<N>(self) -> Complemented<N, Rev<Self>>
where Self: Sized + DoubleEndedIterator<Item: AsRef<N>>, N: Nucleotide,

Return iterator over reverse-complemented nucleotides.

§Examples
use nucs::{DnaIterExt, Nuc};

let complement = Nuc::arr(b"GATTACA").into_iter().reverse_complemented();
assert!(complement.eq(Nuc::arr(b"TGTAATC")));
Source

fn complemented<N>(self) -> Complemented<N, Self>
where Self: Sized + Iterator<Item: AsRef<N>>, N: Nucleotide,

Return iterator over complemented nucleotides.

This is like mapping the iterator through Nucleotide::complement.

§Examples
use nucs::{DnaIterExt, Nuc};

let complement = Nuc::arr(b"GATTACA").into_iter().complemented();
assert!(complement.eq(Nuc::arr(b"CTAATGT")));
Source

fn reverse_complement<N>(self)
where Self: Sized + DoubleEndedIterator<Item: AsMut<N>>, N: Nucleotide,

Perform in-place reverse-complement, consuming the iterator.

This swaps the front and back of the iterator and sets them to their Nucleotide::complement.

§Examples
use nucs::{DnaIterExt, Nuc};

let mut dna = Nuc::arr(b"GATTACA");
dna.iter_mut().reverse_complement();
assert_eq!(dna, Nuc::arr(b"TGTAATC"));
Source

fn complement<'a, N>(self)
where Self: Sized + Iterator<Item = &'a mut N>, N: Nucleotide,

Perform in-place complement, consuming the iterator.

This is sets each element to its Nucleotide::complement.

§Examples
use nucs::{DnaIterExt, Nuc};

let mut dna = Nuc::arr(b"GATTACA");
dna.iter_mut().complement();
assert_eq!(dna, Nuc::arr(b"CTAATGT"));
Source

fn codons<N>(self) -> Codons<N, Self>
where Self: Sized + Iterator<Item: AsRef<N>>, N: Nucleotide,

Return iterator over codons of first reading frame.

This discards any leftover trailing nucleotides.

§Examples
use nucs::{DnaIterExt, Nuc};
use Nuc::{A, C, G, T};

let codons = Nuc::arr(b"GATTACA").into_iter().codons();
assert!(codons.eq([
    [G, A, T],
    [T, A, C],
]));
Source

fn trimmed_to_codon<N>(self) -> Self

Discard trailing nucleotides that aren’t part of the first reading frame.

§Examples
use nucs::{DnaIterExt, Nuc};
use Nuc::{A, C, G, T};

let codons = Nuc::arr(b"GATTACA").into_iter().trimmed_to_codon();
assert!(codons.eq([
    G, A, T,
    T, A, C,
]));
Source

fn translated_by<N, G>(self, genetic_code: G) -> Translated<G, Codons<N, Self>>
where Self: Sized + Iterator<Item: AsRef<N>>, N: Nucleotide, G: GeneticCode,

Return iterator translating codons into amino acids.

The given GeneticCode is applied to the first reading frame’s codons (discarding leftover trailing nucleotides).

§Examples
use nucs::{DnaIterExt, NCBI1, Nuc, Seq};

let peptide: Seq<Vec<_>> = Nuc::arr(b"TATGCGAGAAAC")
    .into_iter()
    .translated_by(NCBI1)
    .collect();
assert_eq!(peptide, "YARN");
Source

fn display<N>(&self) -> Display<Self>
where Self: Clone + Iterator<Item: AsRef<N>>, N: Nucleotide,

Return object that implements Display for printing the iterated sequence compactly.

§Examples
use nucs::{DnaIterExt, Nuc};

let dna = Nuc::arr(b"GATTACA").into_iter().display();
assert_eq!(format!("{dna:#4}"), "GATT\nACA");

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§