diff --git a/RIAssigner/data/Data.py b/RIAssigner/data/Data.py index da83326..efd9885 100644 --- a/RIAssigner/data/Data.py +++ b/RIAssigner/data/Data.py @@ -146,12 +146,7 @@ def extract_ri_from_comment(self, specific_string): RI values as a list. """ - comments_series = pd.Series(self.comment) - mask = comments_series.str.contains(rf'\b{specific_string}\b', na=False) - extracted_values = comments_series.str.extract(rf'\b{specific_string}=(\d+)\b')[0].astype(float) - - # Fill in NaN values with None or some default value - extracted_values = extracted_values.where(mask, None) - self.retention_indices = extracted_values.tolist() - + mask = pd.Series(self.comment).str.contains(rf'\b{specific_string}\b', na=False) + extracted_values = pd.Series(self.comment).str.extract(rf'\b{specific_string}=(\d+)\b')[0].astype(float) + self.retention_indices = extracted_values.where(mask, None).tolist() diff --git a/RIAssigner/data/MatchMSData.py b/RIAssigner/data/MatchMSData.py index ecce099..47498ef 100644 --- a/RIAssigner/data/MatchMSData.py +++ b/RIAssigner/data/MatchMSData.py @@ -70,10 +70,6 @@ def _read_retention_indices(self): """ Read retention indices from spectrum metadata. """ self.retention_indices = [safe_read_key(spectrum, self._ri_key) for spectrum in self._spectra] - # def _sort_spectra_by_rt(self): - # """ Sort objects (peaks) in spectra list by their retention times. """ - # self._spectra.sort(key=lambda spectrum: safe_read_key(spectrum, self._rt_key)) - # temporary adapted in case _rt_key is None. if safe_read_key return None, it is assigned 0 instead. def _sort_spectra_by_rt(self): """ Sort objects (peaks) in spectra list by their retention times. """ @@ -180,7 +176,8 @@ def safe_read_key(spectrum: Spectrum, key: str) -> Optional[float]: value = None return value - +# fix the error "ValueError: Key 'retentionindex' will be interpreted as 'retention_index'. But this entry already exists. +# Please use 'retention_index' if you want to replace the entry."" def _assign_ri_value(spectrum: Spectrum, key: str, value: Data.RetentionIndexType): """Assign RI value to Spectrum object @@ -190,4 +187,6 @@ def _assign_ri_value(spectrum: Spectrum, key: str, value: Data.RetentionIndexTyp """ if value is not None: retention_index = ('%f' % float(value)).rstrip('0').rstrip('.') + if key == 'retentionindex': + key = 'retention_index' spectrum.set(key=key, value=retention_index)