@@ -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 :
0 commit comments