Skip to content

Commit

Permalink
fix: put back get_taxon_id for BiGG models
Browse files Browse the repository at this point in the history
  • Loading branch information
breakthewall committed Oct 31, 2023
1 parent 1c2b652 commit 29c4c76
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
53 changes: 52 additions & 1 deletion tools/get_sbml_model/get_infos.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from libsbml import (
readSBMLFromFile
)
from requests import get as r_get

from taxonid import get_taxonid


Expand Down Expand Up @@ -81,6 +83,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 +167,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
2 changes: 1 addition & 1 deletion tools/get_sbml_model/get_sbml_model.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
--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 29c4c76

Please sign in to comment.