Skip to content

Commit

Permalink
Fix incomptiable result format
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanzhou committed Nov 27, 2023
1 parent 8ec3fd0 commit 97d2c90
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/schema/schema_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SchemaConstants(object):
INGEST_API_FILE_COMMIT_ENDPOINT = '/file-commit'
INGEST_API_FILE_REMOVE_ENDPOINT = '/file-remove'
ONTOLOGY_API_ASSAY_TYPES_ENDPOINT = '/assaytype?application_context=HuBMAP'
ONTOLOGY_API_ORGAN_TYPES_ENDPOINT = '/organs?application_context=HuBMAP'
ONTOLOGY_API_ORGAN_TYPES_ENDPOINT = '/organs/by-code?application_context=HuBMAP'

DOI_BASE_URL = 'https://doi.org/'

Expand Down
53 changes: 44 additions & 9 deletions src/schema/schema_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1778,12 +1778,22 @@ def delete_memcached_cache(uuids_list):
Returns
-------
dict
The available organ types
The available organ types in the following format:
{
"AO": "Aorta",
"BD": "Blood",
"BL": "Bladder",
"BM": "Bone Marrow",
"BR": "Brain",
"HT": "Heart",
...
}
"""
def get_organ_types():
global _ontology_api_url

target_url = _ontology_api_url + '/organs?application_context=HuBMAP'
target_url = _ontology_api_url + SchemaConstants.ONTOLOGY_API_ORGAN_TYPES_ENDPOINT

# Use Memcached to improve performance
response = make_request_get(target_url, internal_token_used = True)
Expand All @@ -1795,8 +1805,6 @@ def get_organ_types():
ids_dict = response.json()
return ids_dict
else:
# uuid-api will also return 400 if the given id is invalid
# We'll just hanle that and all other cases all together here
msg = f"Unable to make a request to query the id via uuid-api: {id}"
# Log the full stack trace, prepend a line with our message
logger.exception(msg)
Expand All @@ -1817,12 +1825,32 @@ def get_organ_types():
Returns
-------
dict
The available assay types
The available assay types by name in the following format:
{
"10x-multiome": {
"contains_pii": true,
"description": "10x Multiome",
"name": "10x-multiome",
"primary": true,
"vis_only": false,
"vitessce_hints": []
},
"AF": {
"contains_pii": false,
"description": "Autofluorescence Microscopy",
"name": "AF",
"primary": true,
"vis_only": false,
"vitessce_hints": []
},
...
}
"""
def get_assay_types():
global _ontology_api_url

target_url = _ontology_api_url + '/assaytype?application_context=HuBMAP'
target_url = _ontology_api_url + SchemaConstants.ONTOLOGY_API_ASSAY_TYPES_ENDPOINT

# Use Memcached to improve performance
response = make_request_get(target_url, internal_token_used = True)
Expand All @@ -1831,8 +1859,15 @@ def get_assay_types():
response.raise_for_status()

if response.status_code == 200:
ids_dict = response.json()
return ids_dict
assay_types_by_name = {}
result_dict = response.json()

# Due to the json envelop being used int the json result
assay_types_list = result_dict['result']
for assay_type_dict in assay_types_list:
assay_types_dict_by_name[assay_type_dict['name']] = assay_type_dict

return assay_types_by_name
else:
# uuid-api will also return 400 if the given id is invalid
# We'll just hanle that and all other cases all together here
Expand Down Expand Up @@ -1876,4 +1911,4 @@ def _create_request_headers(user_token):
auth_header_name: auth_scheme + ' ' + user_token
}

return headers_dict
return headers_dict
23 changes: 3 additions & 20 deletions src/schema/schema_triggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1024,9 +1024,10 @@ def get_dataset_title(property_key, normalized_type, user_token, existing_data_d
# Parse the organ description
if organ_name is not None:
try:
# The organ_name is the two-letter code only set if specimen_type == 'organ'
# The organ_name is the two-letter code only set for 'organ'
# Convert the two-letter code to a description
organ_desc = _get_organ_description(organ_name)
organ_types_dict = schema_manager.get_organ_types()
organ_desc = organ_types_dict[organ_name].lower()
except (yaml.YAMLError, requests.exceptions.RequestException) as e:
raise Exception(e)

Expand Down Expand Up @@ -2098,21 +2099,3 @@ def _get_combined_assay_type_description(data_types):

return assay_type_desc


"""
Get the organ description based on the given organ code
Parameters
----------
organ_code : str
The two-letter organ code
Returns
-------
str: The organ code description
"""
def _get_organ_description(organ_code):
organ_types_dict = schema_manager.get_organ_types()
return organ_types_dict[organ_code]['description'].lower()


0 comments on commit 97d2c90

Please sign in to comment.