Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions modifinder/classes/ModiFinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,20 @@ def __init__(
--------

"""

self.network = None
self.unknowns = None
self.ppm_tolerance = ppm_tolerance

# Add ppm_tolerance to kwargs
kwargs["ppm_tolerance"] = ppm_tolerance

if alignmentEngine is None:
self.alignmentEngine = CosineAlignmentEngine(ppm_tolerance = self.ppm_tolerance, **kwargs)
self.alignmentEngine = CosineAlignmentEngine(**kwargs)
else:
self.alignmentEngine = alignmentEngine

if annotationEngine is None:
self.annotationEngine = MAGMaAnnotationEngine(ppm_tolerance = self.ppm_tolerance, **kwargs)
self.annotationEngine = MAGMaAnnotationEngine(**kwargs)
else:
self.annotationEngine = annotationEngine

Expand Down Expand Up @@ -230,7 +232,11 @@ def add_adjusted_edge(self, u, v, edgeDetail: EdgeDetail = None, **kwargs):
smaller = u if self.network.nodes[u]["compound"].spectrum.precursor_mz <= self.network.nodes[v]["compound"].spectrum.precursor_mz else v
larger = u if self.network.nodes[u]["compound"].spectrum.precursor_mz > self.network.nodes[v]["compound"].spectrum.precursor_mz else v
if edgeDetail is None:
edgeDetail = self.alignmentEngine.align_single(self.network.nodes[smaller]["compound"].spectrum, self.network.nodes[larger]["compound"].spectrum, **kwargs)

edgeDetail = self.alignmentEngine.align_single(
self.network.nodes[smaller]["compound"].spectrum,
self.network.nodes[larger]["compound"].spectrum,
**kwargs)

self.update_edge(smaller, larger, edgeDetail, **kwargs)

Expand Down
8 changes: 5 additions & 3 deletions modifinder/engines/alignment/CosineAlignmentEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@ def _cosine_fast(
spec_other (Spectrum): Second spectrum
mz_tolerance (float): Tolerance in Da for fragment m/z values, if None, it is not used.
ppm_tolerance (float): Tolerance in ppm for fragment m/z values, if None, it is not used.
allow_shift (bool): _description_
allow_shift (bool): Shift for m/z values. If not 0, hybrid search is performed. shift = prec_mz(qry) - prec_mz(ref)

Returns:
Tuple[float, List[Tuple[int, int]]]: _description_
"""

if mz_tolerance is None and ppm_tolerance is None:
raise ModiFinderError("At least one of mz_tolerance or ppm_tolerance must be provided.")

precursor_charge = spec.precursor_charge if spec.precursor_charge is not None else 1
if precursor_charge == 0:
precursor_charge = 1
precursor_mass_diff = (
spec.precursor_mz - spec_other.precursor_mz
) * precursor_charge
Expand Down Expand Up @@ -169,6 +170,7 @@ def align_single(
Returns:
EdgeDetail: the edge detail object
"""

cosine, matched_peaks = _cosine_fast(
SpectrumTuple1,
SpectrumTuple2,
Expand Down
Loading