Last active
May 29, 2024 22:27
-
-
Save epshteinmatthew/a9df7d8db75e2222720bdbba595ec678 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.