Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle compound_name is not given in metadata. #251

Merged
merged 7 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 1.5.2
### Fixed
- Handle missing compound names. Previously MS2Query would break, when no compound name was available for an analog.

## 1.5.1
### Fixed
- Set max matchms version, since breaking change was introduced (missing add_losses)
Expand Down
22 changes: 15 additions & 7 deletions ms2query/results_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,26 @@ def export_to_dataframe(
selected_analogs = selected_analogs[
(selected_analogs["ms2query_model_prediction"] > minimal_ms2query_score)]
nr_of_analogs = len(selected_analogs)
# Return None if know analogs are selected.
# Return None if no analogs are selected.
if selected_analogs.empty:
return None

# For each analog the compound name is selected from sqlite
metadata_dict = self.sqlite_library.get_metadata_from_sqlite(list(selected_analogs["spectrum_ids"]))
compound_name_list = [metadata_dict[analog_spectrum_id]["compound_name"]
for analog_spectrum_id
in list(selected_analogs["spectrum_ids"])]
smiles_list = [metadata_dict[analog_spectrum_id]["smiles"]
for analog_spectrum_id
in list(selected_analogs["spectrum_ids"])]

compound_name_list = []
for metadata in metadata_dict.values():
if "compound_name" in metadata.keys():
compound_name_list.append(metadata["compound_name"])
else:
compound_name_list.append(None)

smiles_list = []
for metadata in metadata_dict.values():
if "smiles" in metadata.keys():
smiles_list.append(metadata["smiles"])
else:
smiles_list.append(None)

# Add inchikey and ms2query model prediction to results df
# results_df = selected_analogs.loc[:, ["spectrum_ids", "ms2query_model_prediction", "inchikey"]]
Expand Down
Loading