Skip to content

Commit 15336ed

Browse files
Merge pull request #7 from ecell/fix
[v1.2.0] Return API list
2 parents 73fb997 + bbf66c7 commit 15336ed

File tree

3 files changed

+146
-4
lines changed

3 files changed

+146
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ Call those commands from the root of this repository
3737
```
3838
wget http://bigg.ucsd.edu/static/namespace/bigg_models_reactions.txt -OutFile ./models/bigg_models_reactions.txt
3939
wget http://bigg.ucsd.edu/static/namespace/bigg_models_metabolites.txt -OutFile ./models/bigg_models_metabolites.txt
40-
wget https://www.metanetx.org/cgi-bin/mnxget/mnxref/reac_prop.tsv -OutFile ./models/reac_prop.txt
41-
wget https://github.com/ecell/id2id/releases/download/test2/id2id.tsv -OutFile ./models/id2id.txt
40+
wget https://www.metanetx.org/cgi-bin/mnxget/mnxref/reac_prop.tsv -OutFile ./models/reac_prop.tsv
41+
wget https://github.com/ecell/id2id/releases/download/test2/id2id.tsv -OutFile ./models/id2id.tsv
4242
```
4343

4444
*Note: Currently, we are indeed downloading the content of the database and store them locally. This is to avoid the hassle of handling the query API of each databases and to focus on handling the requests between other systems and Kosmogora (as it is the case with [ECellDive](https://github.com/ecell/ECell_Dive))*

api_definition.py

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
2+
schema = {
3+
"list_models": {
4+
"httpMethod": "GET",
5+
"request": {
6+
"pathParameters" : [],
7+
"queryParameters": [],
8+
},
9+
"responce" : {
10+
"key": "models", "value_type": "str",
11+
},
12+
},
13+
"list_views" : {
14+
"httpMethod": "GET",
15+
"request": {
16+
"pathParameters" : [],
17+
"queryParameters": [
18+
{"id": "model_name", "type": "str" }
19+
]
20+
},
21+
"responce" : {
22+
"key": "views",
23+
"value_type": "str",
24+
},
25+
},
26+
"list_user_model" : {
27+
"httpMethod": "GET",
28+
"request": {
29+
"pathParameters" : [],
30+
"queryParameters": [
31+
{"id": "base_model_name", "value_type": "str" }
32+
]
33+
},
34+
"response": {
35+
"key": "user_models",
36+
"value_type" : "str"
37+
}
38+
},
39+
"list_reaction_id" : {
40+
"httpMethod": "GET",
41+
"request": {
42+
"pathParameters" : [],
43+
"queryParameters": [
44+
{"id": "model_name", "type": "str" }
45+
]
46+
},
47+
"response": "list[str]",
48+
},
49+
50+
"solve": {
51+
"httpMethod": "GET",
52+
"request" : {
53+
"pathParameters" : [
54+
{"id": "modelName", "type" : "str"}
55+
],
56+
"queryParameters": [
57+
{"id": "command", "type" : "list[str]"},
58+
{"id": "view_name", "type" : "str"},
59+
]
60+
},
61+
"responce": {
62+
"key" : "fluxes",
63+
"value_type": "list[list[str, float]]",
64+
}
65+
},
66+
67+
"save": {
68+
"httpMethod": "GET",
69+
"request" : {
70+
"pathParameters" : [
71+
{"id": "model_name", "type" : "str"},
72+
{"id": "author", "type" : "str"},
73+
{"id": "new_model_name", "type" : "str"},
74+
],
75+
"queryParameters": [
76+
{"id": "command", "type" : "list[str]"},
77+
{"id": "view_name", "type" : "str"},
78+
]
79+
},
80+
"responce": {
81+
"key" : "new_model_name",
82+
"value_type": "str",
83+
}
84+
},
85+
86+
"reaction_information" : {
87+
"httpMethod": "GET",
88+
"request" : {
89+
"pathParameters" : [
90+
{"id" : "model_name", "type" : "str"},
91+
{"id" : "reaction_id", "type" : "str"}
92+
],
93+
"queryParameters" : [
94+
{"id" : "db_src", "type" : "str"},
95+
{"id" : "view_name", "type" : "str"},
96+
]
97+
},
98+
"response": {
99+
"key" : "reaction_information",
100+
"value" : {
101+
"ID" : "reaction_id" ,
102+
"NAME" : "reaction_name" ,
103+
"REACTION" : "reaction_expression" ,
104+
"MODEL_LIST" : "model_list" ,
105+
}
106+
}
107+
}
108+
}
109+

app.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from model_handler import ModelHandler
44
from typing import Tuple, List, Union
55
import os
6+
from fastapi.encoders import jsonable_encoder
7+
from fastapi.responses import JSONResponse
68

79
class XMLResponse(Response):
810
media_type = "application/xml"
@@ -365,6 +367,37 @@ def get_reaction_info(model_name: str, reaction_id: str,
365367
raise HTTPException(status_code=404, detail="Reaction {} not found at {}".format(reaction_id, db_src))
366368

367369

370+
@app.get("/modules")
371+
def get_module_information():
372+
return {"modules": ["FBA"]}
368373

369-
370-
374+
@app.get("/apis/")
375+
def get_api_information(api_id: str = Query(None)):
376+
import api_definition
377+
import json
378+
if api_id == None:
379+
api_list = [
380+
"list_models",
381+
"user_model_tree",
382+
"list_views",
383+
"open_sbml",
384+
"open_sbml",
385+
"get_model_property",
386+
"open_view",
387+
"get_view_property",
388+
"list_user_model",
389+
"open_user_model",
390+
"list_reaction_id",
391+
"solve",
392+
"save",
393+
"metabolite_information",
394+
"reaction_information",
395+
]
396+
s = {"apis" : api_list}
397+
return JSONResponse(content = s)
398+
else:
399+
if api_id in api_definition.schema:
400+
s = json.dumps( api_definition.schema[api_id] )
401+
return JSONResponse(content = s)
402+
else:
403+
return None

0 commit comments

Comments
 (0)