From a38242d512114614adc4fcbfff9ef3f6d9fe686b Mon Sep 17 00:00:00 2001 From: GuillaumeG Date: Tue, 12 Dec 2023 17:11:03 +0100 Subject: [PATCH] Tool `get_sbml_model` (#162) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(tools): get_sbml_model, load file from history * chore(wrapper): change option + taxonid version * chore(python): use get_taxonid from taxonid pkg * chore(wrapper): rm shell cmd * chore(wrapper): upgrade version * chore: global modifications * fix: put back get_taxon_id for BiGG models --------- Co-authored-by: Joan Hérisson --- tools/get_sbml_model/get_infos.py | 51 ++++++++++++++++++++++++- tools/get_sbml_model/get_sbml_model.xml | 4 +- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/tools/get_sbml_model/get_infos.py b/tools/get_sbml_model/get_infos.py index b764ed04..5ebdf7e4 100644 --- a/tools/get_sbml_model/get_infos.py +++ b/tools/get_sbml_model/get_infos.py @@ -81,6 +81,55 @@ def args(): return params +def get_taxon_id(hostid: str, bigg: bool): + ''' + Returns the taxonomy ID of the host organism + + Parameters + ---------- + hostid: str + Extended name of the host organism or host ID if from BiGG + bigg: bool + True if the model is from BiGG + + Returns + ------- + taxid: str + Taxonomy ID of the host organism + ''' + if not bigg: + return get_taxonid(hostid) + + hostname = '' + # Extended Name + server = 'http://bigg.ucsd.edu/api/v2/models/' + ext = hostid + r = r_get(server+ext, headers={ "Content-Type" : "application/json"}) + if not r.ok: + print(f"Warning: unable to retrieve host name for id {hostid}") + else: + try: + hostname = r.json()["organism"] + except KeyError: + print(f"Warning: unable to retrieve host name for id {hostid}") + if not hostname: + taxid = '' + else: + # TAXON ID + server = 'https://rest.ensembl.org' + ext = f'/taxonomy/id/{hostname}?' + r = r_get(server+ext, headers={ "Content-Type" : "application/json"}) + if not r.ok: + print(f"Warning: unable to retrieve taxonomy ID for host organism {hostname}") + else: + try: + taxid = r.json()["id"] + except KeyError: + print(f"Warning: unable to retrieve taxonomy ID for host organism {hostname}") + taxid = '' + return taxid + + def entry_point(): params = args() @@ -116,7 +165,7 @@ def entry_point(): else: print(f'Biomass reaction ID: {biomass_id}') - taxid = get_taxonid(params.hostname) + taxid = get_taxon_id(params.hostname, params.bigg) if params.taxid: with open(params.taxid, 'w') as f: diff --git a/tools/get_sbml_model/get_sbml_model.xml b/tools/get_sbml_model/get_sbml_model.xml index 808f8934..bbe6e363 100644 --- a/tools/get_sbml_model/get_sbml_model.xml +++ b/tools/get_sbml_model/get_sbml_model.xml @@ -11,16 +11,14 @@ #if str($cond_src.from_src) == 'from_bigg' curl -o - 'http://bigg.ucsd.edu/static/models/${cond_src.hostid}.xml.gz' | gunzip > '$model' && #end if - echo "listdir:"; - ls; python '$__tool_directory__/'get_infos.py #if str($cond_src.from_src) == 'from_bigg' '$model' --bigg #else '${cond_src.input_file}' - --hostname '${cond_src.hostid}' #end if + --hostname '${cond_src.hostid}' --taxid '$taxid' --comp '$compartments' --biomass '$biomass'