Skip to content

Commit

Permalink
Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
wverastegui committed Dec 4, 2023
1 parent 0befcaa commit 6ea2b07
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
11 changes: 3 additions & 8 deletions RIAssigner/data/Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

9 changes: 4 additions & 5 deletions RIAssigner/data/MatchMSData.py
Original file line number Diff line number Diff line change
Expand Up @@ -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. """
Expand Down Expand Up @@ -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
Expand All @@ -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)

0 comments on commit 6ea2b07

Please sign in to comment.