@@ -171,19 +171,19 @@ def _apply_spectrum_id_pattern(
171171 )
172172
173173 # Validate that the same number of unique IDs were matched
174- elif len (set ( id_mapping . keys ())) != len (set ( precursors . keys ()) ):
175- example_old_id , example_new_id = next (iter (id_mapping .items ()))
174+ elif len (id_mapping ) != len (precursors ):
175+ new_id , old_id = next (iter (id_mapping .items ()))
176176 raise MS2RescoreConfigurationError (
177177 "'spectrum_id_pattern' resulted in a different number of unique PSM IDs. This might "
178178 "indicate issues with the regex pattern. Please check and try again. "
179- f"Example old ID: '{ example_old_id } ' -> new ID: '{ example_new_id } '. "
179+ f"Example old ID: '{ old_id } ' -> new ID: '{ new_id } '. "
180180 "See https://ms2rescore.readthedocs.io/en/stable/userguide/configuration/#mapping-psms-to-spectra "
181181 "for more information."
182182 )
183183
184184 precursors = {new_id : precursors [orig_id ] for new_id , orig_id in id_mapping .items ()}
185185
186- return id_mapping
186+ return precursors
187187
188188
189189def _get_precursor_values (
@@ -201,13 +201,6 @@ def _get_precursor_values(
201201 LOGGER .debug ("Reading spectrum file: '%s'" , spectrum_file )
202202 precursors : dict [str , Precursor ] = get_precursor_info (str (spectrum_file ))
203203
204- # Ensure unique spectrum IDs
205- if len (precursors ) != len (set (precursors .keys ())):
206- raise SpectrumParsingError (
207- f"Spectrum file '{ spectrum_file } ' contains duplicate spectrum IDs. "
208- "Please ensure that all spectrum IDs are unique."
209- )
210-
211204 # Parse spectrum IDs with regex pattern if provided
212205 if spectrum_id_pattern :
213206 precursors = _apply_spectrum_id_pattern (precursors , spectrum_id_pattern )
@@ -216,8 +209,8 @@ def _get_precursor_values(
216209 for psm in psm_list_run :
217210 if psm .spectrum_id not in precursors :
218211 raise MS2RescoreConfigurationError (
219- "Mismatch between PSM and spectrum file IDs. Could find precursor values "
220- f"for PSM with ID { psm .spectrum_id } in run { run_name } .\n "
212+ "Mismatch between PSM and spectrum file IDs. Could not find precursor "
213+ f"values for PSM with ID { psm .spectrum_id } in run { run_name } .\n "
221214 "Please check that the `spectrum_id_pattern` and `psm_id_pattern` options "
222215 "are configured correctly. See "
223216 "https://ms2rescore.readthedocs.io/en/stable/userguide/configuration/#mapping-psms-to-spectra"
0 commit comments