Skip to content

Commit

Permalink
Tool get_sbml_model (#162)
Browse files Browse the repository at this point in the history
* 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 <joan.herisson@univ-evry.fr>
  • Loading branch information
guillaume-gricourt and breakthewall authored Dec 12, 2023
1 parent 9952584 commit a38242d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
51 changes: 50 additions & 1 deletion tools/get_sbml_model/get_infos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions tools/get_sbml_model/get_sbml_model.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit a38242d

Please sign in to comment.