Skip to content

Commit

Permalink
add error message for api
Browse files Browse the repository at this point in the history
  • Loading branch information
cwieder committed Jan 15, 2024
1 parent 8f66261 commit d8b2e0f
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/sspa/identifier_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,25 @@ 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",
}

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):
"""
Expand Down

0 comments on commit d8b2e0f

Please sign in to comment.