api views

api.views.clear_data(request)[source]

clear your data at /api/clear_data

will return a JSON object with one key ‘status’ and the value ‘success’ if successful

Parameters:request (django:HttpRequest) – the request
Returns:json object with information about the success
Return type:django:JsonResponse
api.views.execute(request)[source]

execute a job at /api/execute

processed the job, that is send as JSON HTTP POST data, such as:

{
  "export": {
      "network_type":"en",
      "network_format":"sbml"
  },
  "filter": {
      "species": ["h2o", "atp"],
      "reactions": [],
      "enzymes": ["gene_abc"],
      "enzyme_complexes": ["a + b + c", "x + Y", "b_098 + r_abc"],
  },
  "file": model
}

returns HTTP 200 and the generated file, or some other HTTP status and an error message

Parameters:request – the request
Returns:HTTP 200 and the file or 404 if no such file
Return type:django:HttpResponse
api.views.export(request)[source]

export the gemtracted file at /api/export

generates the export and returns some JSON data to call /api/serve … (-> serve_file())

expects a job submitted as HTTP POST form data (see gemtract.forms.ExportForm), just like:

network_type: en
network_format: sbml
removing_enzyme_removes_complex: on

returns as JSON object such as:

{
  "status": "success",
  "name": "BIOMD0000000006-gemtracted-EnzymeNetwork.sbml",
  "mime": "application/xml"
}

check for “status” = “success”

if the request was not successful, the ‘status’ key will have a value other than ‘success’ and there will be an ‘error’ key with some information about what went wrong

Parameters:request – the request
Returns:json object with information about the exported file
Return type:django:JsonResponse
api.views.get_bigg_models(request)[source]

get the list of models from BiGG at /api/get_bigg_models

returns the models in a json object just like this

{ 
  "status":"success",
  "results_count":108,
  "results":[ 
    { 
       "reaction_count":95,
       "metabolite_count":72,
       "organism":"Escherichia coli str. K-12 substr. MG1655",
       "bigg_id":"e_coli_core",
       "gene_count":137
    },
    {"...": "..."}
  ]
}

check for “status” = “success”

if the request was not successful, the ‘status’ key will have a value other than ‘success’ and there will be an ‘error’ key with some information about what went wrong

Parameters:request – the request
Returns:json object with information about the models
Return type:django:JsonResponse
api.views.get_biomodels(request)[source]

get the list of models from biomodels at /api/get_biomodels

returns the models in a json object just like this

{ 
  "status":"success",
  "matches":6979,
  "models":[ 
    { 
       "format":"SBML",
       "id":"BIOMD0000000239",
       "lastModified":"2016-04-07T23:00:00Z",
       "name":"Jiang2007 - GSIS system, Pancreatic Beta Cells",
       "submissionDate":"2016-04-07T23:00:00Z",
       "submitter":"Kieran Smallbone",
       "url":"https://www.ebi.ac.uk/biomodels/BIOMD0000000239"
    },
    {"...": "..."}
  ]
}

check for “status” = “success”

if the request was not successful, the ‘status’ key will have a value other than ‘success’ and there will be an ‘error’ key with some information about what went wrong

Parameters:request – the request
Returns:json object with information about the models
Return type:django:JsonResponse
api.views.get_network(request)[source]

get the network at /api/get_network

as encoded in the currently selected model

the returned JSON object will look like this (check for ‘status’ = ‘success’):

{ 
  "status":"success",
  "network":{ 
    "species":[ 
      { 
        "id":"EmptySet",
        "name":"",
        "occ":[ 27, 10 ]
      },
      {"...": "..."}
    ],
    "reactions":[
      { 
        "id":"Reaction1",
        "name":"",
        "rev":false,
        "cons":[ 30, 10 ],
        "prod":[ 17 ],
        "enzs":[ 13 ],
        "enzc":[ 1 ]
      },
      {"...": "..."}
    ],
    "enzs":[
      { 
        "id":"b0351",
        "reactions":[ 22 ],
        "cplx":[ 42 ]
      },
      {"...": "..."}
    ],
    "enzc":[
      { 
        "id":"b0116 + b0738",
        "enzs":[ 12, 28 ],
        "reactions":[ 23 ]
      },
      {"...": "..."}
    ]
  },
  "filter":{ 
    "filter_species":[ "..." ],
    "filter_reactions":[ "..." ],
    "filter_enzymes":[ "..." ],
    "filter_enzyme_complexes":[ "..." ]
  }
}

special notes:

  • network.species[x].occ: in which reactions does the species appear? -> link into the network.reactions array
  • network.reactions[x].cons: which species are consumed? -> link into the network.species array
  • network.reactions[x].prod: which species are produced? -> link into the snetwork.pecies array
  • network.reactions[x].enzs: which enzymes catalyze the reaction? -> link into the network.enzs array
  • network.reactions[x].enzc: which enzyme complexes catalyze the reaction? -> link into the network.enzc array
  • network.enzs[x].reactions: which reactions are catalyzed by the enzyme? -> link into the network.reactions array
  • network.enzs[x].cplx: in which enzyme complexes does the enzyme participate? -> link into the network.enzc array
  • network.enzc[x].enzs: which enzymes participate in this complex? -> link into the network.enzs array
  • network.enzc[x].reactions: which reactions are catalyzed by this complex? -> link into the network.reactions array
  • network.filter.filter_species: list of species identifiers (str)
  • network.filter.filter_reactions: list of reaction identifiers (str)
  • network.filter.filter_enzymes: list of gene identifiers (str)
  • network.filter.filter_enzyme_complexes: list of gene complex identifiers (str)

if the request was not successful, the ‘status’ key will have a value other than ‘success’ and there will be an ‘error’ key with some information about what went wrong

Parameters:request – the request
Returns:json object with information about the network
Return type:django:JsonResponse
api.views.get_session_data(request)[source]

get your session data at /api/get_session_data

the returned JSON object will have the following keys:

  • status: ‘success’ if it was successful
  • data: dict of the data: - session: dict on session keys and values - files: array of string about uploaded files

example:

{
  "status": "success",
  "data": {
    "session": {
      "has_session": "yes",
      "model_id": "e_coli_core",
      "model_name": "e_coli_core",
      "model_type": "bigg",
      "filter_species": [],
      "filter_reactions": [],
      "filter_enzymes": [],
      "filter_enzyme_complexes": []
    },
    "files": []
  }
}
Parameters:request – the request
Returns:json object with information about the user’s session
Return type:django:JsonResponse
api.views.parse_json_body(request, expected_keys=[])[source]

parse some json payload

loads the json payload from the request and checks if all keys in expected_keys are present

Parameters:
  • request – the request
  • expected_keys (array of str) – array of keys to expect
Returns:

[true, parsed data] if all expected keys were found, otherwise [false, error message]

Return type:

[bool, dict] or [bool, message]

api.views.prepare_filter(request)[source]

prepare the session filter setup

produced empty arrays for

  • request.session[Constants.SESSION_FILTER_SPECIES]
  • request.session[Constants.SESSION_FILTER_REACTION]
  • request.session[Constants.SESSION_FILTER_ENZYMES]
  • request.session[Constants.SESSION_FILTER_ENZYME_COMPLEXES]
Parameters:request – the request
api.views.select_bigg_model(request)[source]

select a certain model from BiGG at /api/select_bigg_model

expects JSON with the key “bigg_id” posted to this endpoint, just like:

{
  "bigg_id":"e_coli_core"
}

returns JSON {“status”: “success”} if successful

if the request was not successful, the ‘status’ key will have a value other than ‘success’ and there will be an ‘error’ key with some information about what went wrong

Parameters:request – the request
Returns:json object with information about the success
Return type:django:JsonResponse
api.views.select_biomodel(request)[source]

select a certain model from biomodels at /api/select_biomodel

expects JSON with the key “biomodels_id” posted to this endpoint, just like:

{
  "biomodels_id":"BIOMD0000000496"
}

returns JSON {“status”: “success”} if successful

if the request was not successful, the ‘status’ key will have a value other than ‘success’ and there will be an ‘error’ key with some information about what went wrong

Parameters:request – the request
Returns:json object with information about the success
Return type:django:JsonResponse
api.views.serve_file(request, file_name, file_type)[source]

server a file at /api/serve/file_name/file_type

serves the file user-generated file

Parameters:
  • request – the request
  • file_name (str) – the name of the file, will be used in HTTP’s Content-Disposition
  • file_type (str) – the mime type of the file, will be used to indicate the mime-type in the HTTP response
Returns:

HTTP 200 and the file or 404 if no such file

Return type:

django:HttpResponse

api.views.sort_gene_complexes(complexes)[source]

sorts the genes in the gene complex identifiers

splits every identifier it at ” + “, sorts the parts, and joins them with ” + “

Example:
  • input: [“z + k + y”, “a + b”]
  • output: [“k + y + z”, “a + b”]
Parameters:complexes (list of str) – the complex identifiers
Returns:the sorted identifiers
Return type:list of str
api.views.status(request)[source]

get the status of this instance

this will clean obsolete files

send the health-secret as JSON POST to get health information about this instance:

{"secret": "XXXX"}

this will then return a json object listing how many files and data we store, such as:

{
  "status": "success",
  "cache": {
    "biomodels": {
      "nfiles": 8,
      "size": 212254013
    },
    "bigg": {
      "nfiles": 5,
      "size": 59429817
    }
  },
  "user": {
    "uploaded": {
      "nfiles": 0,
      "size": 0
    },
    "generated": {
      "nfiles": 0,
      "size": 0
    }
  }
}
Parameters:request – the request
Returns:json object with information about the exported file
Return type:django:JsonResponse
api.views.store_filter(request)[source]

store the user’s filters in the session at /api/store_filter

returns the stored filters in a json object just like this

{ 
  "status":"success",
  "filter":{ 
    "filter_species":[ 
       "M_13dpg_c",
       "M_2pg_c"
    ],
    "filter_reactions":[ 
       "reaction1"
    ],
    "filter_enzymes":[ 

    ],
    "filter_enzyme_complexes":[ 

    ]
  }
}

check for “status” = “success”

if the request was not successful, the ‘status’ key will have a value other than ‘success’ and there will be an ‘error’ key with some information about what went wrong

Parameters:request – the request
Returns:json object with information about the filters
Return type:django:JsonResponse