From d8b2e0f19b18cc948004363390fc8a9566ab1375 Mon Sep 17 00:00:00 2001 From: cwieder Date: Mon, 15 Jan 2024 18:48:26 +0000 Subject: [PATCH] add error message for api --- src/sspa/identifier_conversion.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/sspa/identifier_conversion.py b/src/sspa/identifier_conversion.py index 7fa323a..8f7ee17 100644 --- a/src/sspa/identifier_conversion.py +++ b/src/sspa/identifier_conversion.py @@ -11,12 +11,15 @@ def identifier_conversion(input_type, compound_list): Returns: (pd.DataFrame) Dataframe containing identifier matches """ - print('Commencing ID conversion using Metaboanalyst API...') - url = "https://www.xialab.ca/api/mapcompounds" + print('Commencing ID conversion using Metaboanalyst API...') + + if input_type != 'name': + raise NotImplementedError('Currently the API only converts from compound names to other identifiers.') compound_list_string = ";".join(compound_list) - payload = f"{{\n\t\"queryList\": \"{compound_list_string};\",\n\t\"{input_type}\": \"name\"\n}}" + payload = f"{{\n\t\"queryList\": \"{compound_list_string};\",\n\t\"inputType\": \"{input_type}\"\n}}" + headers = { 'Content-Type': "application/json", 'cache-control': "no-cache", @@ -24,8 +27,9 @@ def identifier_conversion(input_type, compound_list): response = requests.request("POST", url, data=payload, headers=headers) resp_dict = response.json() - df_res = pd.DataFrame(resp_dict) - return df_res + resp_df = pd.DataFrame(resp_dict) + return resp_df + def map_identifiers(query_df, output_id_type, matrix): """