Skip to content

Commit

Permalink
Handle compound_name is not given in metadata.
Browse files Browse the repository at this point in the history
  • Loading branch information
niekdejonge committed Aug 7, 2024
1 parent a45afdc commit 1913e5b
Showing 1 changed file with 15 additions and 7 deletions.
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

0 comments on commit 1913e5b

Please sign in to comment.