Skip to content
Snippets Groups Projects
Commit 2d131b9c authored by Martin Larralde's avatar Martin Larralde
Browse files

Apply `clippy` suggestions

parent 068523db
No related branches found
No related tags found
No related merge requests found
......@@ -14,10 +14,8 @@ use lightmotif::seq::EncodedSequence;
use lightmotif::utils::StrictlyPositive;
use typenum::consts::U16;
use typenum::consts::U32;
use typenum::marker_traits::NonZero;
use typenum::marker_traits::Unsigned;
const SEQUENCE: &'static str = include_str!("ecoli.txt");
const SEQUENCE: &str = include_str!("ecoli.txt");
fn bench<C: StrictlyPositive, P: Score<Dna, C>>(bencher: &mut test::Bencher, pli: &P) {
let encoded = EncodedSequence::<Dna>::from_str(SEQUENCE).unwrap();
......@@ -34,7 +32,10 @@ fn bench<C: StrictlyPositive, P: Score<Dna, C>>(bencher: &mut test::Bencher, pli
striped.configure(&pssm);
let mut scores = StripedScores::new_for(&striped, &pssm);
bencher.bytes = SEQUENCE.len() as u64;
bencher.iter(|| test::black_box(pli.score_into(&striped, &pssm, &mut scores)));
bencher.iter(|| {
pli.score_into(&striped, &pssm, &mut scores);
test::black_box(())
});
}
#[bench]
......
......@@ -85,7 +85,7 @@ impl Alphabet for Dna {
}
/// A deoxyribonucleotide.
#[derive(Clone, Copy, PartialEq, Debug)]
#[derive(Clone, Copy, Debug, Default, PartialEq)]
#[repr(u8)]
pub enum Nucleotide {
/// Adenine.
......@@ -105,15 +105,10 @@ pub enum Nucleotide {
/// ![guanine.png](https://www.ebi.ac.uk/chebi/displayImage.do?defaultImage=true&imageIndex=0&chebiId=16235)
G = 3,
/// Unknown base.
#[default]
N = 4,
}
impl Default for Nucleotide {
fn default() -> Nucleotide {
Nucleotide::N
}
}
impl From<Nucleotide> for char {
fn from(n: Nucleotide) -> char {
n.as_char()
......@@ -197,7 +192,7 @@ impl Alphabet for Protein {
}
/// A proteinogenic amino acid.
#[derive(Clone, Copy, PartialEq, Debug)]
#[derive(Clone, Copy, Default, Debug, PartialEq)]
#[repr(u8)]
pub enum AminoAcid {
A = 0,
......@@ -220,15 +215,10 @@ pub enum AminoAcid {
V = 17,
W = 18,
Y = 19,
#[default]
X = 20,
}
impl Default for AminoAcid {
fn default() -> Self {
AminoAcid::X
}
}
impl From<AminoAcid> for char {
fn from(aa: AminoAcid) -> char {
aa.as_char()
......@@ -315,7 +305,7 @@ impl<A: Alphabet> Background<A> {
let frequencies = frequencies.into();
let mut sum = 0.0;
for &f in frequencies.iter() {
if f < 0.0 || f > 1.0 {
if !(0.0..=1.0).contains(&f) {
return Err(InvalidData);
}
sum += f;
......@@ -324,7 +314,7 @@ impl<A: Alphabet> Background<A> {
return Err(InvalidData);
}
Ok(Self {
frequencies: frequencies.into(),
frequencies,
alphabet: std::marker::PhantomData,
})
}
......@@ -346,7 +336,6 @@ impl<A: Alphabet> Background<A> {
/// ```
pub fn uniform() -> Self {
let frequencies = (0..A::K::USIZE)
.into_iter()
.map(|i| {
if i != A::default_symbol().as_index() {
1.0 / ((A::K::USIZE - 1) as f32)
......@@ -410,7 +399,7 @@ impl<A: Alphabet> From<GenericArray<f32, A::K>> for Pseudocounts<A> {
fn from(counts: GenericArray<f32, A::K>) -> Self {
Self {
alphabet: std::marker::PhantomData,
counts: counts.into(),
counts,
}
}
}
......@@ -418,7 +407,6 @@ impl<A: Alphabet> From<GenericArray<f32, A::K>> for Pseudocounts<A> {
impl<A: Alphabet> From<f32> for Pseudocounts<A> {
fn from(count: f32) -> Self {
let counts = (0..A::K::USIZE)
.into_iter()
.map(|i| {
if i != A::default_symbol().as_index() {
count
......
......@@ -51,7 +51,7 @@ impl<T: Default + Copy, C: Unsigned> DenseMatrix<T, C> {
}
// record indices to each rows
let indices = (0..rows).into_iter().map(|i| offset + i * c).collect();
let indices = (0..rows).map(|i| offset + i * c).collect();
Self {
data,
......
......@@ -42,10 +42,7 @@ unsafe fn score_sse2<A, C>(
let zero = _mm_setzero_si128();
// process columns of the striped matrix, any multiple of 16 is supported
let data = scores.matrix_mut();
for offset in (0..<C as Div<U16>>::Output::USIZE)
.into_iter()
.map(|i| i * <Sse2 as Backend>::LANES::USIZE)
{
for offset in (0..<C as Div<U16>>::Output::USIZE).map(|i| i * <Sse2 as Backend>::LANES::USIZE) {
// process every position of the sequence data
for i in 0..seq.data.rows() - seq.wrap {
// reset sums for current position
......@@ -81,7 +78,7 @@ unsafe fn score_sse2<A, C>(
}
// record the score for the current position
let row = &mut data[i];
_mm_storeu_ps(row[offset + 0..].as_mut_ptr(), s1);
_mm_storeu_ps(row[offset..].as_mut_ptr(), s1);
_mm_storeu_ps(row[offset + 4..].as_mut_ptr(), s2);
_mm_storeu_ps(row[offset + 8..].as_mut_ptr(), s3);
_mm_storeu_ps(row[offset + 12..].as_mut_ptr(), s4);
......
......@@ -77,7 +77,7 @@ impl<C: Unsigned + NonZero> StripedScores<C> {
/// Iterate over scores of individual sequence positions.
pub fn iter(&self) -> Iter<'_, C> {
Iter::new(&self)
Iter::new(self)
}
/// Convert the striped scores to a vector of scores.
......
......@@ -91,7 +91,7 @@ impl<A: Alphabet> CountMatrix<A> {
let src = &self.data[i];
let dst = &mut probas[i];
for (j, &x) in src.iter().enumerate() {
dst[j] = x as f32 + p.counts()[j] as f32;
dst[j] = x as f32 + p.counts()[j];
}
let s: f32 = dst.iter().sum();
for x in dst.iter_mut() {
......@@ -289,7 +289,7 @@ impl<A: ComplementableAlphabet> WeightMatrix<A> {
impl<A: Alphabet> AsRef<WeightMatrix<A>> for WeightMatrix<A> {
fn as_ref(&self) -> &Self {
&self
self
}
}
......@@ -361,7 +361,7 @@ impl<A: Alphabet> ScoringMatrix<A> {
impl<A: Alphabet> AsRef<ScoringMatrix<A>> for ScoringMatrix<A> {
fn as_ref(&self) -> &Self {
&self
self
}
}
......
......@@ -80,7 +80,7 @@ impl<A: Alphabet> EncodedSequence<A> {
impl<A: Alphabet> AsRef<EncodedSequence<A>> for EncodedSequence<A> {
fn as_ref(&self) -> &Self {
&self
self
}
}
......@@ -148,7 +148,7 @@ impl<A: Alphabet, C: StrictlyPositive> StripedSequence<A, C> {
impl<A: Alphabet, C: StrictlyPositive> AsRef<StripedSequence<A, C>> for StripedSequence<A, C> {
fn as_ref(&self) -> &Self {
&self
self
}
}
......
......@@ -13,8 +13,8 @@ use typenum::consts::U1;
use typenum::consts::U16;
use typenum::consts::U32;
const SEQUENCE: &'static str = "ATGTCCCAACAACGATACCCCGAGCCCATCGCCGTCATCGGCTCGGCATGCAGATTCCCAGGCG";
const PATTERNS: &[&'static str] = &["GTTGACCTTATCAAC", "GTTGATCCAGTCAAC"];
const SEQUENCE: &str = "ATGTCCCAACAACGATACCCCGAGCCCATCGCCGTCATCGGCTCGGCATGCAGATTCCCAGGCG";
const PATTERNS: &[&str] = &["GTTGACCTTATCAAC", "GTTGATCCAGTCAAC"];
// scores computed with Bio.motifs
#[rustfmt::skip]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment