Skip to content

Instantly share code, notes, and snippets.

@epshteinmatthew
Last active May 29, 2024 22:27
Show Gist options
  • Select an option

  • Save epshteinmatthew/a9df7d8db75e2222720bdbba595ec678 to your computer and use it in GitHub Desktop.

Select an option

Save epshteinmatthew/a9df7d8db75e2222720bdbba595ec678 to your computer and use it in GitHub Desktop.
import requests
URL = "https://raw.githubusercontent.com/sys-bio/cesium/main/model_db/cesiumDB.json"
def filter(data, criteria):
return [item for item in data if all(item.get(k) == v for k, v in criteria.items())]
def filter_antimony_string(data, criteria):
return [item["antString"] for item in data if all(item.get(k) == v for k, v in criteria.items())]
def get_models_by_criteria(criteria):
r = requests.get(url = URL)
results = filter(r.json(), criteria)
return {"models" : results, "count" : len(results)}
def get_antimony_strings_by_criteria(criteria):
r = requests.get(url = URL)
results = filter_antimony_string(r.json(), criteria)
return {"models" : results, "count" : len(results)}
#example: get the amount of models with 12 reactions
print(get_models_by_criteria({"numReactions":12})["count"])
@bartjuw

bartjuw commented May 29, 2024

Copy link
Copy Markdown

Besides the 'get_models_by_criteria()' we will probably want specific method names for each search making it easier for the user to grab the models. For the 'get_models_by_criteria()' the user will have to know what the valid criteria are (maybe have a help method that lists valid criteria).
So methods like getModelsWithNumberOfReactions(number, modelType) and getModelsWithNumberOfSpecies(number, modelType) .
We will need to discuss this with the goal of making it easy for the user to get the results they want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment