File tree Expand file tree Collapse file tree 3 files changed +17
-14
lines changed
Expand file tree Collapse file tree 3 files changed +17
-14
lines changed Original file line number Diff line number Diff line change 11from .chemistry_utils import compute_morgan_fingerprints , inchikey14_from_full
22from .fingerprint_computation import compute_fingerprints_from_smiles
3- from .merging_utils import cluster_block , get_merged_spectra , normalize_spectrum_sum
3+ from .merging_utils import cluster_block , get_merged_spectra
4+ from .spectra_processing import normalize_spectrum_sum
45
56
67__all__ = [
Original file line number Diff line number Diff line change 33from scipy .sparse import csr_matrix
44from scipy .sparse .csgraph import connected_components
55from ms2query .metrics import compute_cosine_greedy
6+ from .spectra_processing import normalize_spectrum_sum
67
78
89METADATA_FIELDS_FROM_FIRST = [
1213
1314
1415# --------------------- Helper functions ---------------------
15- def normalize_spectrum_sum (s ):
16- """Return a spectrum with intensities normalized to sum=1 (if possible)."""
17- mz = np .asarray (s .peaks .mz , dtype = float )
18- intens = np .asarray (s .peaks .intensities , dtype = float )
19- tot = intens .sum ()
20- if tot > 0 :
21- intens = intens / tot
22-
23- # Build a shallow copy with normalized peaks but same metadata
24- md = dict (s .metadata ) if hasattr (s , "metadata" ) else {}
25- return Spectrum (mz = mz , intensities = intens , metadata = md )
26-
27-
2816def _merge_cluster_to_consensus (cluster_spectra , mz_tol = 0.01 , min_frac = 0.25 ):
2917 """
3018 Build a consensus spectrum from a list of matchms Spectra.
Original file line number Diff line number Diff line change 1+ from matchms import Spectrum
2+
3+
4+ def normalize_spectrum_sum (spectrum : Spectrum ) -> Spectrum :
5+ """Return a spectrum with intensities normalized to sum=1 (if possible)."""
6+ mz = spectrum .peaks .mz
7+ intens = spectrum .peaks .intensities
8+ tot = intens .sum ()
9+ if tot > 0 :
10+ intens = intens / tot
11+
12+ # Build a shallow copy with normalized peaks but same metadata
13+ md = dict (spectrum .metadata ) if hasattr (spectrum , "metadata" ) else {}
14+ return Spectrum (mz = mz , intensities = intens , metadata = md )
You can’t perform that action at this time.
0 commit comments