From 1913e5b5d5635f07019a400e7f8a51760a961eea Mon Sep 17 00:00:00 2001 From: niekdejonge Date: Wed, 7 Aug 2024 11:42:47 +0200 Subject: [PATCH] Handle compound_name is not given in metadata. --- ms2query/results_table.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/ms2query/results_table.py b/ms2query/results_table.py index 88e52d10..e6dfa413 100644 --- a/ms2query/results_table.py +++ b/ms2query/results_table.py @@ -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"]]