Skip to content

Commit

Permalink
Remove reverse_complement
Browse files Browse the repository at this point in the history
Now that the extension trait is only implemented on on iterators,
.reverse_complement() doesn't provide any convenience over
.rev().complement() so it's probably better to just rely on the
decoupled version.
  • Loading branch information
swooster committed Dec 1, 2022
1 parent 0460089 commit a0c1c5e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 27 deletions.
6 changes: 4 additions & 2 deletions benches/all_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ impl IterBasedSequenceWindows {
}));
aas.extend(
dna.iter()
.reverse_complement()
.rev()
.complement()
.self_reading_frames()
.into_iter()
.map(|codons| {
Expand All @@ -128,7 +129,8 @@ impl IterBasedSequenceWindows {

let dna_rc = dna
.iter()
.reverse_complement()
.rev()
.complement()
.map(|n| n.to_ascii())
.collect();
let dna_rc = String::from_utf8(dna_rc).unwrap();
Expand Down
27 changes: 2 additions & 25 deletions src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,22 +152,6 @@ pub trait NucleotideIter: Iterator + Sized {
/// ```
fn complement(self) -> Complement<Self>;

/// Returns iterator of reverse complement of contained nucleotides.
///
/// # Examples
///
/// ```
/// use quickdna::{Nucleotide, NucleotideIter};
///
/// use Nucleotide::*;
/// let dna = [C, G, A, T];
///
/// assert!(dna.iter().reverse_complement().eq([A, T, C, G]));
/// ```
fn reverse_complement(self) -> std::iter::Rev<Complement<Self>>
where
Self: DoubleEndedIterator;

/// Returns up to 3 non-empty codon iterators for reading frames.
///
/// The iterators are given in ascending order of offset from the beginning of the
Expand Down Expand Up @@ -230,7 +214,7 @@ where
let mut iter3 = iter2.clone();
iter3.next();

let iter1_rc = iter1.clone().reverse_complement();
let iter1_rc = iter1.clone().rev().complement();
let mut iter2_rc = iter1_rc.clone();
iter2_rc.next();
let mut iter3_rc = iter2_rc.clone();
Expand All @@ -256,13 +240,6 @@ where
Complement(self)
}

fn reverse_complement(self) -> std::iter::Rev<Complement<Self>>
where
Self: DoubleEndedIterator,
{
self.complement().rev()
}

fn self_reading_frames(self) -> SmallVec<[Codons<Self>; 3]>
where
Self: Clone + ExactSizeIterator,
Expand Down Expand Up @@ -388,7 +365,7 @@ where
#[derive(Clone, Debug)]
pub enum ForwardOrRcCodons<I> {
Forward(Codons<I>),
Rc(Codons<std::iter::Rev<Complement<I>>>),
Rc(Codons<Complement<std::iter::Rev<I>>>),
}

impl<N, I> Iterator for ForwardOrRcCodons<I>
Expand Down

0 comments on commit a0c1c5e

Please sign in to comment.