Skip to content

Commit

Permalink
Fix biosample API check
Browse files Browse the repository at this point in the history
  • Loading branch information
kheal committed Dec 19, 2024
1 parent 7dfa300 commit ca45251
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ share/python-wheels/
*.egg

# Raw thermo data
*.raw
*.raw

# Metabref token
*.token
28 changes: 15 additions & 13 deletions metaMS/nmdc_lipidomics_metadata_generation/api_info_retriever.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,20 @@ def check_if_ids_exist(self, ids: list) -> bool:
If there's an error in making the API request.
"""
ids_test = list(set(ids))
ids_test = [id.replace('"', "'") for id in ids_test]
ids_test_str = ", ".join(f'"{id}"' for id in ids_test)
filter_param = f'{{"id": {{"$in": [{ids_test_str}]}}}}'
og_url = f"{self.base_url}/nmdcschema/{self.collection_name}?&filter={filter_param}&projection=id"

try:
resp = requests.get(og_url)
resp.raise_for_status() # Raises an HTTPError for bad responses
data = resp.json()
if len(data["resources"]) != len(ids_test):
return False
except requests.RequestException as e:
raise requests.RequestException(f"Error making API request: {e}")
for id in ids_test:
filter_param = f'{{"id": "{id}"}}'
field = "id"

og_url = f"{self.base_url}/nmdcschema/{self.collection_name}?&filter={filter_param}&projection={field}"

try:
resp = requests.get(og_url)
resp.raise_for_status() # Raises an HTTPError for bad responses
data = resp.json()
if len(data["resources"]) == 0:
print(f"ID {id} not found")
return False
except requests.RequestException as e:
raise requests.RequestException(f"Error making API request: {e}")

return True

0 comments on commit ca45251

Please sign in to comment.