Repository 'get_sbml_model'
hg clone https://toolshed.g2.bx.psu.edu/repos/tduigou/get_sbml_model

Changeset 8:768ed7cc0978 (2023-09-29)
Previous changeset 7:8dc4d3964ab5 (2023-09-04) Next changeset 9:6a2871e89352 (2024-02-14)
Commit message:
planemo upload for repository https://github.com/brsynth/synbiocad-galaxy-wrappers commit aa5a9ac47997d9c1718b9c7eaff1b83c63ac1d58
modified:
get_infos.py
get_sbml_model.xml
added:
model.sbml
b
diff -r 8dc4d3964ab5 -r 768ed7cc0978 get_infos.py
--- a/get_infos.py Mon Sep 04 14:19:43 2023 +0000
+++ b/get_infos.py Fri Sep 29 09:03:09 2023 +0000
[
@@ -5,7 +5,86 @@
 from requests import get as r_get
 
 
-def entry_point():
+def get_biomass_rxn(sbml_doc):
+    '''
+    Returns the biomass reaction of the model
+    
+    Parameters
+    ----------
+    sbml_doc: libsbml.SBMLDocument
+        SBML model
+        
+    Returns
+    -------
+    biomass_rxn: libsbml.Reaction
+        Biomass reaction
+    '''
+    reactions = sbml_doc.getModel().getListOfReactions()
+    # Search for 'biomass' keyword in reaction name
+    for rxn in reactions:
+        if 'biomass' in rxn.getName().lower():
+            return rxn
+    # Search for 'biomass' keyword in products
+    # AND not in reactants
+    for rxn in reactions:
+        in_reactants = False
+        for reac in rxn.getListOfReactants():
+            if 'biomass' in reac.getSpecies().lower():
+                in_reactants = True
+                break
+        if not in_reactants:
+            for prod in rxn.getListOfProducts():
+                if 'biomass' in prod.getSpecies().lower():
+                    return rxn
+    return None
+
+
+def get_taxon_id(hostid):
+    '''
+    Returns the taxonomy ID of the host organism
+    
+    Parameters
+    ----------
+    hostid: str
+        Extended name of the host organism
+        
+    Returns
+    -------
+    taxid: str
+        Taxonomy ID of the host organism
+    '''
+    taxid = get_taxon_id(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 args():
     parser = ArgumentParser('Returns cell informations')
     parser.add_argument(
         'infile',
@@ -29,6 +108,11 @@
         help='Path to store biomass reaction ID'
     )
     parser.add_argument(
+        '--biomass-id',
+        type=str,
+        help='ID of biomass reaction'
+    )
+    parser.add_argument(
         '--hostid',
         type=str,
         help='Extended name of the host organism'
@@ -39,63 +123,57 @@
         help='Path to store host taxonomy ID'
     )
     params = parser.parse_args()
+    return params
+
+
+def entry_point():
+
+    params = args()
 
     sbml_doc = readSBMLFromFile(params.infile)
 
+    compartments = sbml_doc.getModel().getListOfCompartments()
+    comp_str = ''
+    for comp in compartments:
+        comp_str += f'{comp.getId()}\t{comp.getName()}\n'
     if params.comp:
-        compartments = sbml_doc.getModel().getListOfCompartments()
         with open(params.comp, 'w') as f:
             f.write('#ID\tNAME\n')
-            for comp in compartments:
-                f.write(f'{comp.getId()}\t{comp.getName()}\n')
+            f.write(comp_str)
+    else:
+        print('Compartments:')
+        for comp in compartments:
+            print(f'{comp.getId()}\t{comp.getName()}'.replace('\n', ' | '))
 
+    if params.biomass_id:
+        biomass_rxn = sbml_doc.getModel().getReaction(params.biomass_id)
+    else:
+        biomass_rxn = get_biomass_rxn(sbml_doc)
+    if not biomass_rxn:
+        print('Warning: unable to retrieve biomass reaction')
+        biomass_id = ''
+    else:
+        biomass_id = biomass_rxn.getId()
     if params.biomass:
-        reactions = sbml_doc.getModel().getListOfReactions()
         with open(params.biomass, 'w') as f:
             f.write('#ID\n')
-            for rxn in reactions:
-                if 'biomass' in rxn.getId().lower():
-                    f.write(f'{rxn.getId()}\n')
+            f.write(f'{biomass_id}\n')
+    else:
+        print(f'Biomass reaction ID: {biomass_id}')
+
+    # Model from BiGG
+    if params.bigg:
+        taxid = get_taxon_id(params.hostid)
+    # Model from user
+    else:
+        taxid = params.hostid
 
     if params.taxid:
-        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 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}")
-            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 = ''
-
-        # Model from user
-        else:
-            taxid = params.hostid
-
         with open(params.taxid, 'w') as f:
             f.write('#ID\n')
             f.write(f'{taxid}\n')
+    else:
+        print(f'Taxonomy ID: {taxid}')
 
 
 if __name__ == "__main__":
b
diff -r 8dc4d3964ab5 -r 768ed7cc0978 get_sbml_model.xml
--- a/get_sbml_model.xml Mon Sep 04 14:19:43 2023 +0000
+++ b/get_sbml_model.xml Fri Sep 29 09:03:09 2023 +0000
b
@@ -20,6 +20,7 @@
         python '$__tool_directory__/'get_infos.py
             #if str($cond_src.from_src) == 'from_bigg'
                 '$model'
+                --bigg
                 --taxid '$taxid'
             #else
                 '${cond_src.input_file}'
b
diff -r 8dc4d3964ab5 -r 768ed7cc0978 model.sbml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/model.sbml Fri Sep 29 09:03:09 2023 +0000
b
b'@@ -0,0 +1,169810 @@\n+<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n+<sbml xmlns:fbc="http://www.sbml.org/sbml/level3/version1/fbc/version2" xmlns="http://www.sbml.org/sbml/level3/version1/core" level="3" version="1" sboTerm="SBO:0000624" fbc:required="false">\n+  <model fbc:strict="true" id="iML1515">\n+    <listOfUnitDefinitions>\n+      <unitDefinition id="mmol_per_gDW_per_hr">\n+        <listOfUnits>\n+          <unit kind="mole" scale="-3" multiplier="1" exponent="1"/>\n+          <unit kind="gram" scale="0" multiplier="1" exponent="-1"/>\n+          <unit kind="second" scale="0" multiplier="3600" exponent="-1"/>\n+        </listOfUnits>\n+      </unitDefinition>\n+    </listOfUnitDefinitions>\n+    <fbc:listOfObjectives fbc:activeObjective="obj">\n+      <fbc:objective fbc:id="obj" fbc:type="maximize">\n+        <fbc:listOfFluxObjectives>\n+          <fbc:fluxObjective fbc:reaction="R_BIOMASS_Ec_iML1515_core_75p37M" fbc:coefficient="1"/>\n+        </fbc:listOfFluxObjectives>\n+      </fbc:objective>\n+    </fbc:listOfObjectives>\n+    <listOfParameters>\n+      <parameter value="-1000" id="cobra_default_lb" sboTerm="SBO:0000626" constant="true" units="mmol_per_gDW_per_hr"/>\n+      <parameter value="1000" id="cobra_default_ub" sboTerm="SBO:0000626" constant="true" units="mmol_per_gDW_per_hr"/>\n+      <parameter value="0" id="cobra_0_bound" sboTerm="SBO:0000626" constant="true" units="mmol_per_gDW_per_hr"/>\n+      <parameter id="R_EX_glc__D_e_lower_bound" value="-10" sboTerm="SBO:0000625" constant="true" units="mmol_per_gDW_per_hr"/>\n+      <parameter id="R_ATPM_lower_bound" value="6.86" sboTerm="SBO:0000625" constant="true" units="mmol_per_gDW_per_hr"/>\n+    </listOfParameters>\n+    <listOfCompartments>\n+      <compartment id="c" name="cytosol" constant="true"/>\n+      <compartment id="e" name="extracellular space" constant="true"/>\n+      <compartment id="p" name="periplasm" constant="true"/>\n+    </listOfCompartments>\n+    <listOfSpecies>\n+      <species id="M_octapb_c" constant="false" boundaryCondition="false" hasOnlySubstanceUnits="false" name="Octanoate (protein bound)" metaid="M_octapb_c" sboTerm="SBO:0000247" compartment="c" fbc:charge="1" fbc:chemicalFormula="C8H15O">\n+        <sbml:annotation xmlns:sbml="http://www.sbml.org/sbml/level3/version1/core">\n+          <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">\n+            <rdf:Description rdf:about="#M_octapb_c">\n+              <bqbiol:is xmlns:bqbiol="http://biomodels.net/biology-qualifiers/">\n+                <rdf:Bag>\n+                  <rdf:li rdf:resource="http://identifiers.org/bigg.metabolite/octapb"/>\n+                  <rdf:li rdf:resource="http://identifiers.org/metanetx.chemical/MNXM147531"/>\n+                </rdf:Bag>\n+              </bqbiol:is>\n+            </rdf:Description>\n+          </rdf:RDF>\n+        </sbml:annotation>\n+      </species>\n+      <species id="M_cysi__L_e" constant="false" boundaryCondition="false" hasOnlySubstanceUnits="false" name="L Cystine C6H12N2O4S2" metaid="M_cysi__L_e" sboTerm="SBO:0000247" compartment="e" fbc:charge="0" fbc:chemicalFormula="C6H12N2O4S2">\n+        <sbml:annotation xmlns:sbml="http://www.sbml.org/sbml/level3/version1/core">\n+          <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">\n+            <rdf:Description rdf:about="#M_cysi__L_e">\n+              <bqbiol:is xmlns:bqbiol="http://biomodels.net/biology-qualifiers/">\n+                <rdf:Bag>\n+                  <rdf:li rdf:resource="http://identifiers.org/bigg.metabolite/cysi__L"/>\n+                  <rdf:li rdf:resource="http://identifiers.org/biocyc/META:CYSTINE"/>\n+                  <rdf:li rdf:resource="http://identifiers.org/chebi/CHEBI:6209"/>\n+                  <rdf:li rdf:resource="http://identifiers.org/chebi/CHEBI:35491"/>\n+                  <rdf:li rdf:resource="http://identifiers.org/chebi/CHEBI:63163"/>\n+                  <rdf:li rdf:resource="http://identifiers.org/chebi/CHEBI:13097"/>\n+                  <rdf:li rdf:resource="htt'..b'istOfProducts>\n+          <speciesReference species="M_bmocogdp_c" stoichiometry="1" constant="true"/>\n+          <speciesReference species="M_ppi_c" stoichiometry="1" constant="true"/>\n+        </listOfProducts>\n+        <fbc:geneProductAssociation>\n+          <fbc:or>\n+            <fbc:and>\n+              <fbc:geneProductRef fbc:geneProduct="G_b3857"/>\n+              <fbc:geneProductRef fbc:geneProduct="G_b3856"/>\n+            </fbc:and>\n+            <fbc:geneProductRef fbc:geneProduct="G_b3857"/>\n+          </fbc:or>\n+        </fbc:geneProductAssociation>\n+      </reaction>\n+      <reaction id="R_FESD2s" fast="false" reversible="false" name="Iron-sulfur cluster damage (nitrous oxide, spontaneous)" metaid="R_FESD2s" sboTerm="SBO:0000176" fbc:upperFluxBound="cobra_default_ub" fbc:lowerFluxBound="cobra_0_bound">\n+        <sbml:annotation xmlns:sbml="http://www.sbml.org/sbml/level3/version1/core">\n+          <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">\n+            <rdf:Description rdf:about="#R_FESD2s">\n+              <bqbiol:is xmlns:bqbiol="http://biomodels.net/biology-qualifiers/">\n+                <rdf:Bag>\n+                  <rdf:li rdf:resource="http://identifiers.org/bigg.reaction/FESD2s"/>\n+                  <rdf:li rdf:resource="http://identifiers.org/metanetx.reaction/MNXR99586"/>\n+                </rdf:Bag>\n+              </bqbiol:is>\n+            </rdf:Description>\n+          </rdf:RDF>\n+        </sbml:annotation>\n+        <listOfReactants>\n+          <speciesReference species="M_4fe4s_c" stoichiometry="2" constant="true"/>\n+          <speciesReference species="M_h_c" stoichiometry="2" constant="true"/>\n+          <speciesReference species="M_no_c" stoichiometry="2" constant="true"/>\n+        </listOfReactants>\n+        <listOfProducts>\n+          <speciesReference species="M_3fe4s_c" stoichiometry="2" constant="true"/>\n+          <speciesReference species="M_fe3_c" stoichiometry="2" constant="true"/>\n+          <speciesReference species="M_h2o_c" stoichiometry="1" constant="true"/>\n+          <speciesReference species="M_n2o_c" stoichiometry="1" constant="true"/>\n+        </listOfProducts>\n+        <fbc:geneProductAssociation>\n+          <fbc:geneProductRef fbc:geneProduct="G_s0001"/>\n+        </fbc:geneProductAssociation>\n+      </reaction>\n+      <reaction id="R_OCTNLL" fast="false" reversible="false" name="Octanoate non-lipoylated apo domain ligase" metaid="R_OCTNLL" sboTerm="SBO:0000176" fbc:upperFluxBound="cobra_default_ub" fbc:lowerFluxBound="cobra_0_bound">\n+        <sbml:annotation xmlns:sbml="http://www.sbml.org/sbml/level3/version1/core">\n+          <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">\n+            <rdf:Description rdf:about="#R_OCTNLL">\n+              <bqbiol:is xmlns:bqbiol="http://biomodels.net/biology-qualifiers/">\n+                <rdf:Bag>\n+                  <rdf:li rdf:resource="http://identifiers.org/bigg.reaction/OCTNLL"/>\n+                  <rdf:li rdf:resource="http://identifiers.org/metanetx.reaction/MNXR102155"/>\n+                </rdf:Bag>\n+              </bqbiol:is>\n+            </rdf:Description>\n+          </rdf:RDF>\n+        </sbml:annotation>\n+        <listOfReactants>\n+          <speciesReference species="M_atp_c" stoichiometry="1" constant="true"/>\n+          <speciesReference species="M_h_c" stoichiometry="1" constant="true"/>\n+          <speciesReference species="M_octa_c" stoichiometry="1" constant="true"/>\n+        </listOfReactants>\n+        <listOfProducts>\n+          <speciesReference species="M_amp_c" stoichiometry="1" constant="true"/>\n+          <speciesReference species="M_octapb_c" stoichiometry="1" constant="true"/>\n+          <speciesReference species="M_ppi_c" stoichiometry="1" constant="true"/>\n+        </listOfProducts>\n+        <fbc:geneProductAssociation>\n+          <fbc:geneProductRef fbc:geneProduct="G_b4386"/>\n+        </fbc:geneProductAssociation>\n+      </reaction>\n+    </listOfReactions>\n+  </model>\n+</sbml>\n'