Skip to content

Commit 469c553

Browse files
committed
bug fix
1 parent 147b672 commit 469c553

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

modifinder/classes/Compound.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ def __init__(self, incoming_data=None, **kwargs):
116116
# attempt to initialize the class with the provided data
117117
if incoming_data is not None:
118118
convert.to_compound(incoming_data, use_object = self, **kwargs)
119+
else:
120+
self.update(**kwargs)
119121

120122
# TODO: write setters for spectrum, structure to warn the user to update the dependent attributes
121123

modifinder/classes/Spectrum.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@ def __init__(self, incoming_data=None, normalize_peaks = True, **kwargs):
7070
return
7171

7272
if incoming_data is not None:
73-
convert.to_spectrum(incoming_data, self)
74-
75-
self.update(normalize_peaks = normalize_peaks, **kwargs)
73+
kwargs['normalize_peaks'] = normalize_peaks
74+
convert.to_spectrum(incoming_data, self, **kwargs)
75+
else:
76+
self.update(**kwargs)
7677

7778
@property
7879
def adduct(self):
@@ -82,7 +83,13 @@ def adduct(self):
8283
def adduct(self, value):
8384
self._adduct = adduct_mapping.get(value, value)
8485
if self._adduct is not None:
85-
self._adduct_mass = general_utils.get_adduct_mass(self._adduct)
86+
try:
87+
self._adduct_mass = general_utils.get_adduct_mass(self._adduct)
88+
except Exception as e:
89+
if not self.ignore_adduct_format:
90+
raise e
91+
else:
92+
self._adduct_mass = None
8693
else:
8794
self._adduct_mass = 0
8895

@@ -93,7 +100,7 @@ def adduct_mass(self):
93100
def update(self, peaks = None, peaks_json = None, mz=None, intensity=None, precursor_mz=None, precursor_charge=None,
94101
_adduct = None, adduct=None, ms_level=None, instrument=None, ms_mass_analyzer=None,
95102
ms_dissociation_method=None, spectrum_id=None, normalize_peaks = False, ratio_to_base_peak = None,
96-
remove_large_peaks = False, keep_top_k=None, peak_fragments_map: dict = None, **kwargs):
103+
remove_large_peaks = False, keep_top_k=None, peak_fragments_map: dict = None, ignore_adduct_format = False, **kwargs):
97104
"""Update the Spectrum object with the given values.
98105
99106
Args:
@@ -115,7 +122,10 @@ def update(self, peaks = None, peaks_json = None, mz=None, intensity=None, precu
115122
remove_large_peaks (bool): If True, remove all the peaks that are larger than the precursor m/z value.
116123
keep_top_k (int): If not None, only keep the top k peaks.
117124
peak_fragments_map (dict): A dictionary mapping peaks to fragments
125+
ignore_adduct_format (bool): If True, if the adduct format is not recognized, it will not throw an error.
126+
**kwargs: Additional keyword arguments.
118127
"""
128+
self.ignore_adduct_format = ignore_adduct_format
119129
if peaks_json is not None:
120130
peaks = json.loads(peaks_json)
121131
if peaks is not None:

modifinder/utilities/visualizer.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -597,13 +597,12 @@ def draw_alignment(spectrums, matches = None, output_type='png', normalize_peaks
597597
matches.append(match)
598598

599599

600+
# if matches is one dimentional, convert it to two dimentional
601+
if len(matches) > 0 and isinstance(matches[0], int):
602+
matches = [matches]
603+
600604
if len(matches) > 0 and len(matches) != len(spectrums) - 1:
601605
raise ValueError("Number of matches should be equal to the number of spectrums - 1")
602-
603-
# in case there is only one match, accept it as both a list of tuples or a list of lists
604-
if len(matches) == 1:
605-
if type(matches[0][0]) == int:
606-
matches = [matches]
607606

608607
flipped = False
609608
if "flipped" in kwargs:

0 commit comments

Comments
 (0)