Skip to content

Commit 95802b0

Browse files
committed
Some cleanup
1 parent ebaf217 commit 95802b0

9 files changed

Lines changed: 37 additions & 39 deletions

File tree

mzcore/src/chemistry/neutral_loss.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::{
22
borrow::Cow,
33
fmt::Display,
4+
mem::swap,
45
ops::{Add, AddAssign},
56
str::FromStr,
67
};
@@ -163,15 +164,15 @@ impl From<MolecularFormula> for NeutralLoss {
163164
},
164165
);
165166
let number = gcd.try_into().unwrap_or(1);
166-
let num = number as i32;
167+
let num = i32::from(number);
167168
let sign = pos >= neg;
168169
let formula = MolecularFormula {
169170
elements: value
170171
.elements
171172
.into_iter()
172173
.map(|(e, i, a)| (e, i, i32::from(sign) * a / num))
173174
.collect(),
174-
additional_mass: value.additional_mass / num as f64,
175+
additional_mass: value.additional_mass / f64::from(num),
175176
labels: value.labels,
176177
};
177178
if pos >= neg {
@@ -182,15 +183,13 @@ impl From<MolecularFormula> for NeutralLoss {
182183
}
183184
}
184185

185-
fn gcd(mut n: u32, mut m: u32) -> u32 {
186+
const fn gcd(mut n: u32, mut m: u32) -> u32 {
186187
if n == 0 || m == 0 {
187188
return 0;
188189
}
189190
while m != 0 {
190191
if m < n {
191-
let t = m;
192-
m = n;
193-
n = t;
192+
swap(&mut m, &mut n);
194193
}
195194
m = m % n;
196195
}

mzcore/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ pub mod prelude {
2929
Chemical, Element, MassMode, MolecularCharge, MolecularFormula, MultiChemical,
3030
};
3131
pub use crate::isobaric_sets::{
32-
BuildingBlocks, TerminalBuildingBlocks, building_blocks, find_isobaric_sets,
32+
BuildingBlocks, IsobaricSetIterator, TerminalBuildingBlocks, building_blocks,
33+
find_isobaric_sets,
3334
};
3435
pub use crate::molecular_formula;
3536
pub use crate::sequence::{

mzcore/src/sequence/peptidoform/annotated.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ mod tests {
294294
}
295295

296296
#[test]
297+
#[allow(clippy::missing_panics_doc)]
297298
fn annotated_sub_peptidoform() {
298299
let seq = AP {
299300
peptidoform: Peptidoform::pro_forma("PEPTIDE", &STATIC_ONTOLOGIES)

mzcore/src/sequence/peptidoform/compound_peptidoform_ion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl<Complexity> FromIterator<Peptidoform<Complexity>> for CompoundPeptidoformIo
206206
fn from_iter<T: IntoIterator<Item = Peptidoform<Complexity>>>(iter: T) -> Self {
207207
Self {
208208
name: String::new(),
209-
peptidoforms: iter.into_iter().map(|p| p.into()).collect(),
209+
peptidoforms: iter.into_iter().map(Into::into).collect(),
210210
}
211211
}
212212
}

mzcore/src/sequence/peptidoform/parse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ impl CompoundPeptidoformIon {
338338
BoxedError::new(
339339
BasicKind::Warning,
340340
"Improper prefixed mass modification",
341-
"A prefixed mass modification must use a modification that is defined in the referenced ontology",
341+
"A prefixed mass modification must match a modification that is defined in the referenced ontology",
342342
base_context.clone(),
343343
),
344344
);

mzcore/src/sequence/peptidoform/parse_modification.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
use std::{
2-
num::NonZeroU16,
3-
ops::Range,
4-
sync::{Arc, LazyLock},
5-
};
1+
use std::{num::NonZeroU16, ops::Range, sync::Arc};
62

73
use context_error::*;
84
use itertools::Itertools;
@@ -142,22 +138,23 @@ impl SimpleModificationInner {
142138
}
143139
}
144140

141+
type SliceWithRange<'a> = (&'a str, Range<usize>);
142+
145143
fn tokenise_mod(
146144
text: &str,
147145
range: Range<usize>,
148146
) -> (
149-
(&str, Range<usize>),
150-
Option<(&str, Range<usize>)>,
151-
Option<(&str, Range<usize>)>,
152-
Option<(&str, Range<usize>)>,
147+
SliceWithRange<'_>,
148+
Option<SliceWithRange<'_>>,
149+
Option<SliceWithRange<'_>>,
150+
Option<SliceWithRange<'_>>,
153151
) {
154152
// ^(([^:#]*)(?::([^#]+))?)(?:#([0-9A-Za-z]+)(?:\((\d+\.\d+)\))?)?$
155153
// text(:text)?(#label(score)?)?
156154

157155
let (m, label) = text[range.clone()]
158156
.split_once('#')
159-
.map(|(m, l)| (m, Some(l)))
160-
.unwrap_or((&text[range.clone()], None));
157+
.map_or_else(|| (&text[range.clone()], None), |(m, l)| (m, Some(l)));
161158
let (tag, name) =
162159
m.split_once(':')
163160
.map_or(((m, range.start..range.start + m.len()), None), |(t, n)| {
@@ -322,7 +319,7 @@ fn parse_single_modification<'error, const STRICT: bool>(
322319

323320
let mut errors = Vec::new();
324321
let (head, tail, label, score) = tokenise_mod(line, range.clone());
325-
let full = (&line[range.clone()], range.clone());
322+
let full = (&line[range.clone()], range);
326323

327324
let modification = if let Some(tail) = tail {
328325
let basic_error = BoxedError::new(
@@ -580,7 +577,7 @@ fn parse_single_modification<'error, const STRICT: bool>(
580577
BasicKind::Error,
581578
"Invalid branch definition",
582579
"A branch definition has to be identical at both sites, or only defined at one site.",
583-
base_context.clone().add_highlight((0, full.1.clone())),
580+
base_context.clone().add_highlight((0, full.1)),
584581
)]);
585582
}
586583
cross_link_lookup[index].1 = Some(linker);
@@ -611,7 +608,7 @@ fn parse_single_modification<'error, const STRICT: bool>(
611608
BasicKind::Error,
612609
"Invalid cross-link definition",
613610
"A cross-link definition has to be identical at both sites, or only defined at one site.",
614-
base_context.clone().add_highlight((0, full.1.clone())),
611+
base_context.clone().add_highlight((0, full.1)),
615612
)]);
616613
}
617614
cross_link_lookup[index].1 = Some(linker);
@@ -624,7 +621,7 @@ fn parse_single_modification<'error, const STRICT: bool>(
624621
))
625622
} else {
626623
let score = match score.map(|s| {
627-
s.0.parse::<f64>().map_err(|err| {
624+
s.0.parse::<f64>().map_err(|_| {
628625
BoxedError::new(
629626
BasicKind::Error,
630627
"Invalid modification localisation score",
@@ -646,7 +643,7 @@ fn parse_single_modification<'error, const STRICT: bool>(
646643
group,
647644
score,
648645
ambiguous_lookup,
649-
base_context.clone().add_highlight((0, full.1.clone())),
646+
base_context.clone().add_highlight((0, full.1)),
650647
)
651648
.map(|(m, w)| {
652649
combine_errors(&mut errors, w);
@@ -668,7 +665,7 @@ fn parse_single_modification<'error, const STRICT: bool>(
668665
/// If the content of the ambiguous modification was already defined
669666
fn handle_ambiguous_modification<'a>(
670667
modification: Option<SimpleModification>,
671-
group: (&str, Range<usize>),
668+
group: SliceWithRange<'a>,
672669
localisation_score: Option<OrderedFloat<f64>>,
673670
ambiguous_lookup: &mut AmbiguousLookup,
674671
context: Context<'a>,

mzcore/src/sequence/peptidoform/parse_sloppy.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
use std::sync::{Arc, LazyLock};
1+
use std::sync::Arc;
22

33
use context_error::*;
44
use serde::{Deserialize, Serialize};
55

66
use crate::{
77
glycan::MonoSaccharide,
8-
helper_functions::{ResultExtensions, end_of_enclosure},
8+
helper_functions::end_of_enclosure,
99
ontology::{Ontologies, Ontology},
1010
sequence::{
11-
AminoAcid, CheckedAminoAcid, MassTag, Modification, PeptideModificationSearch, Peptidoform,
12-
SemiAmbiguous, SequenceElement, SequencePosition, SimpleModification,
13-
SimpleModificationInner, peptidoform::parse_modification,
11+
AminoAcid, MassTag, Modification, PeptideModificationSearch, Peptidoform, SemiAmbiguous,
12+
SequenceElement, SequencePosition, SimpleModification, SimpleModificationInner,
13+
peptidoform::parse_modification,
1414
},
1515
system::Mass,
1616
};
@@ -326,10 +326,10 @@ impl Modification {
326326
Some(("unimod", tail)) => ontologies.unimod().get_by_index(&tail.parse::<u32>().ok()?),
327327
Some(("m", tail)) =>ontologies.psimod().get_by_name(tail),
328328
Some(("c", tail)) => ontologies.custom().get_by_name(tail),
329-
Some((_, tail)) => Self::find_name(tail, position, ontologies).or_else(||
329+
Some((_, tail)) => Self::find_name(tail, position, ontologies).or_else(||
330330
tail.rsplit_once(' ').and_then(|(n, _)| {
331331
let n = n.trim_end_matches("on").trim_end_matches("from").trim();
332-
Self::find_name(n, position, ontologies).or_else(||
332+
Self::find_name(n, position, ontologies).or_else(||
333333
MonoSaccharide::pro_forma_composition::<false>(n).ok()
334334
.map(|(g, _)| Arc::new(SimpleModificationInner::Glycan(g))))
335335
})

mzcore/src/sequence/peptidoform/validate.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ pub(super) fn cross_links<'a>(
160160
)
161161
{
162162
if let Modification::CrossLink { peptide, .. } = m
163-
&& !found_peptides.contains(&peptide)
164-
&& !stack.contains(&peptide)
163+
&& !found_peptides.contains(peptide)
164+
&& !stack.contains(peptide)
165165
{
166166
stack.push(*peptide);
167167
}
@@ -288,7 +288,7 @@ impl Peptidoform<Linear> {
288288
/// # Panics
289289
/// It panics when information for an ambiguous modification is missing (name/mod).
290290
pub(super) fn apply_ranged_unknown_position_modification(
291-
&mut self,
291+
&self,
292292
ranged_unknown_position_modifications: &[(
293293
usize,
294294
usize,

mzcore/src/sequence/simple_modification.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub enum SimpleModificationInner {
105105
}
106106

107107
/// The length of a linker
108-
#[derive(Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, Default)]
108+
#[derive(Clone, Debug, Default, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
109109
pub enum LinkerLength {
110110
/// The length is unknown
111111
#[default]
@@ -708,8 +708,8 @@ impl ParseJson for SimpleModificationInner {
708708
impl ParseJson for LinkerLength {
709709
fn from_json_value(value: Value) -> Result<Self, BoxedError<'static, BasicKind>> {
710710
match value {
711-
Value::Null => Ok(LinkerLength::Unknown),
712-
Value::Number(ref n) => Ok(LinkerLength::Discreet(vec![
711+
Value::Null => Ok(Self::Unknown),
712+
Value::Number(ref n) => Ok(Self::Discreet(vec![
713713
n.as_f64()
714714
.ok_or_else(|| {
715715
BoxedError::new(

0 commit comments

Comments
 (0)