Skip to content

Commit

Permalink
fix load from file
Browse files Browse the repository at this point in the history
  • Loading branch information
breakthewall committed Sep 1, 2023
1 parent 3412c99 commit 4cffff2
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 35 deletions.
56 changes: 35 additions & 21 deletions tools/get_sbml_model/get_infos.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ def entry_point():
type=str,
help='SBML input file (xml)'
)
# argument to tag file from BiGG
parser.add_argument(
'--bigg',
action='store_true',
help='Tag file from BiGG'
)
parser.add_argument(
'--comp',
type=str,
Expand Down Expand Up @@ -52,33 +58,41 @@ def entry_point():
f.write(f'{rxn.getId()}\n')

if params.taxid:
# Extended Name
server = 'http://bigg.ucsd.edu/api/v2/models/'
ext = params.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 {params.hostid}")
else:
try:
hostname = r.json()["organism"]
except KeyError:
print(f"Warning: unable to retrieve host name for id {params.hostid}")
hostname = ''
if not hostname:
taxid = ''
else:
# TAXON ID
server = 'https://rest.ensembl.org'
ext = f'/taxonomy/id/{hostname}?'
hostname = ''

# Model from BiGG
if params.bigg:
# Extended Name
server = 'http://bigg.ucsd.edu/api/v2/models/'
ext = params.hostid
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}")
print(f"Warning: unable to retrieve host name for id {params.hostid}")
else:
try:
taxid = r.json()["id"]
hostname = r.json()["organism"]
except KeyError:
print(f"Warning: unable to retrieve host name for id {params.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}")
taxid = ''
else:
try:
taxid = r.json()["id"]
except KeyError:
print(f"Warning: unable to retrieve taxonomy ID for host organism {hostname}")
taxid = ''

# Model from user
else:
taxid = params.hostid

with open(params.taxid, 'w') as f:
f.write('#ID\n')
f.write(f'{taxid}\n')
Expand Down
38 changes: 24 additions & 14 deletions tools/get_sbml_model/get_sbml_model.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,28 @@
<requirement type="package" version="1.11">gzip</requirement>
<requirement type="package" version="5.19.2">python-libsbml</requirement>
<requirement type="package" version="2.29">requests</requirement>
<requirement type="package" version="0.1.0">taxonid</requirement>
</requirements>
<command detect_errors="exit_code"><![CDATA[
#if str($cond_src.from_src) == 'from_bigg'
curl -o - 'http://bigg.ucsd.edu/static/models/${cond_src.hostid}.xml.gz' | gunzip > '$model' &&
#else
cp '${cond_src.input_file}' '$model' &&
#end if
python '$__tool_directory__/'get_infos.py
'$model'
--hostid '${cond_src.hostid}'
--comp '$compartments'
--biomass '$biomass'
--taxid '$taxid'
#if str($cond_src.from_src) == 'from_bigg'
'$model'
#else
'${cond_src.input_file}'
#end if
--hostid '${cond_src.hostid}'
--comp '$compartments'
--biomass '$biomass'
#if str($cond_src.from_src) == 'from_bigg'
--taxid '$taxid'
#else
python -m taxonid '${cond_src.hostid}' --output-file tmpfile
echo "#ID" > '$taxid'
cat tmpfile >> '$taxid'
#end if
]]></command>
<inputs>
<conditional name="cond_src">
Expand All @@ -26,8 +35,8 @@
<option value="from_history">Select file from the History</option>
</param>
<when value="from_history">
<param name="hostid" type="text" help="ID of the model">
<validator type="empty_field" message="An ID is required"/>
<param name="hostid" type="text" help="Fullname of the model">
<validator type="empty_field" message="The fullname of the organism is required"/>
</param>
<param name="input_file" type="data" format="sbml,xml" label="SBML model" help="An SBML file is expected"/>
</when>
Expand Down Expand Up @@ -85,7 +94,9 @@
</conditional>
</inputs>
<outputs>
<data name="model" format="sbml" label="${cond_src.hostid}" />
<when value="from_bigg">
<data name="model" format="sbml" label="${cond_src.hostid}" />
</when>
<data name="taxid" format="tsv" label="${cond_src.hostid} (taxon id)" />
<data name="compartments" format="tsv" label="${cond_src.hostid} (compartments)" />
<data name="biomass" format="tsv" label="${cond_src.hostid} (biomass reactions)" />
Expand All @@ -104,13 +115,12 @@
<test>
<conditional name="cond_src">
<param name="from_src" value="from_history" />
<param name="hostid" value="e_coli_core" />
<param name="hostid" value="Escherichia coli str. K-12 substr. MG1655" />
<param name="input_file" value="e_coli_core.xml" />
</conditional>
<output name="model" md5="4574760460afe9e1b3388dc15f354706" />
<output name="taxid" md5="6b35ad8a1c2b640af4ba738c2f5f876e" />
<output name="compartments" md5="71dc18974a12e9bb75bb2c4cffd13edf" />
<output name="biomass" md5="d10baa335181450c7bffa9b4ca01754a" />
<output name="compartments" md5="e93a875a2d8efc10a880ae3ac0018236" />
<output name="biomass" md5="cffb2fbdb07d1301dfdb7bb284fb7e06" />
</test>
</tests>
<help><![CDATA[
Expand Down

0 comments on commit 4cffff2

Please sign in to comment.