コード例 #1
0
ファイル: sbml.py プロジェクト: willigott/framed
def _save_gpr(model, sbml_model):
    for r_id in model.reactions:
        sbml_reaction = sbml_model.getReaction(r_id)
        #sbml_reaction.appendNotes(GPR_TAG + ' ' + model.rules[r_id])
        note = XMLNode.convertStringToXMLNode('<html><p>' + GPR_TAG + ' ' + model.rules[r_id] + '</p></html>')
        note.getNamespaces().add('http://www.w3.org/1999/xhtml')
        sbml_reaction.setNotes(note)

        
コード例 #2
0
    def __addReactants(self, model, enzmldoc):

        for key, reactant in enzmldoc.getReactantDict().items():

            species = model.createSpecies()
            species.setId(key)
            species.setName(reactant.getName())
            species.setMetaId(reactant.getMetaid())
            species.setSBOTerm(reactant.getSboterm())
            species.setCompartment(reactant.getCompartment())
            species.setBoundaryCondition(reactant.getBoundary())

            if reactant.getInitConc() > 0:
                species.setInitialConcentration(reactant.getInitConc())
            if reactant.getSubstanceunits() != 'NAN':
                species.setSubstanceUnits(reactant.getSubstanceunits())

            species.setConstant(reactant.getConstant())
            species.setHasOnlySubstanceUnits(False)

            # Controls if annotation will be added
            append_bool = False
            reactant_annot = inchi_annot = XMLNode(
                XMLTriple('enzymeml:reactant'), XMLAttributes(),
                XMLNamespaces())
            reactant_annot.addNamespace("http://sbml.org/enzymeml/version1",
                                        "enzymeml")

            try:
                append_bool = True
                inchi_annot = XMLNode(XMLTriple('enzymeml:inchi'),
                                      XMLAttributes(), XMLNamespaces())
                inchi_annot.addAttr('inchi', reactant.getInchi())
                reactant_annot.addChild(inchi_annot)
            except AttributeError:
                pass

            try:
                append_bool = True
                smiles_annot = XMLNode(XMLTriple('enzymeml:smiles'),
                                       XMLAttributes(), XMLNamespaces())
                smiles_annot.addAttr('smiles', reactant.getSmiles())
                reactant_annot.addChild(smiles_annot)
            except AttributeError:
                pass

            if append_bool == True: species.appendAnnotation(reactant_annot)
コード例 #3
0
def _save_metadata(elem, sbml_elem):
    if elem.metadata:
        try:
            notes = ['<p>{}: {}</p>'.format(key, cgi.escape(value))
                     for key, value in elem.metadata.items()]
            note_string = '<html>' + ''.join(notes) + '</html>'
            note_xml = XMLNode.convertStringToXMLNode(note_string)
            note_xml.getNamespaces().add('http://www.w3.org/1999/xhtml')
            sbml_elem.setNotes(note_xml)
        except AttributeError:
            warnings.warn("Unable to save metadata for object {}:".format(sbml_elem.getId()), RuntimeWarning)
コード例 #4
0
def _save_metadata(elem, sbml_elem):
    if elem.metadata:
        try:
            notes = ['<p>{}: {}</p>'.format(key, cgi.escape(value))
                     for key, value in elem.metadata.items()]
            note_string = '<html>' + ''.join(notes) + '</html>'
            note_xml = XMLNode.convertStringToXMLNode(note_string)
            note_xml.getNamespaces().add('http://www.w3.org/1999/xhtml')
            sbml_elem.setNotes(note_xml)
        except AttributeError:
            warnings.warn("Unable to save metadata for object {}:".format(sbml_elem.getId()), RuntimeWarning)
コード例 #5
0
    def backtrace_complexes(species: libsbml.XMLNode):
        species_ident = species.getAttrValue(0)
        species_name_cd = species.getAttrValue(1)

        species_annotation = species.getChild('annotation')
        complex_species = species_annotation.getChild(
            'complexSpecies').getChild(0).getCharacters()
        species_class = species_annotation.getChild(
            'speciesIdentity').getChild('class').getChild(0).getCharacters()
        protein_reference = species_annotation.getChild(
            'speciesIdentity').getChild('proteinReference').getChild(
                0).getCharacters()
        kmer_association = species_annotation.getChild(
            'speciesIdentity').getChild('state').getChild(
                'homodimer').getChild(0).getCharacters()

        try:
            molecules = [mol_id2molecule[species_ident]]
        except:
            molecules = [complex_id2complex[species_ident]]

        return molecules
コード例 #6
0
from sbmlutils.modelcreator.processes import ReactionTemplate

PORT_SUFFIX = "_port"

########################################################################################################################
# RBC Metabolism
########################################################################################################################
mid = 'glucose_rbc'
version = 4
########################################################################################################################

notes = XMLNode.convertStringToXMLNode("""
    <body xmlns='http://www.w3.org/1999/xhtml'>
    <h1>Erythrocyte glucose model</h1>
    <h2>Description</h2>
    <p>
        Erythrocyte metabolism of glucose encoded in <a href="http://sbml.org">SBML</a> format.<br /> 
    </p>
    """ + templates.terms_of_use + """
    </body>
    """)

creators = templates.creators
main_units = {
    'time': 'h',
    'extent': 'mmole',
    'substance': 'mmole',
    'length': 'm',
    'area': 'm2',
    'volume': UNIT_KIND_LITRE,
}
ports = []
コード例 #7
0
    def __addReactions(self, model, enzmldoc, csv=True):

        # initialize format annotation
        data_root = XMLNode(XMLTriple('enzymeml:data'), XMLAttributes(),
                            XMLNamespaces())
        data_root.addNamespace("http://sbml.org/enzymeml/version1", "enzymeml")

        list_formats = XMLNode(XMLTriple('enzymeml:listOfFormats'),
                               XMLAttributes(), XMLNamespaces())
        format_ = XMLNode(XMLTriple('enzymeml:format'), XMLAttributes(),
                          XMLNamespaces())
        format_.addAttr('id', 'format0')

        # initialize csv data collection
        data = []

        # initialize time
        index = 0

        if len(list(enzmldoc.getReactionDict().items())) == 0:
            raise ValueError("Please define a reaction before writing")

        for key, reac in enzmldoc.getReactionDict().items():

            reaction = model.createReaction()
            reaction.setName(reac.getName())
            reaction.setId(key)
            reaction.setMetaId(reac.getMetaid())
            reaction.setReversible(reac.getReversible())

            # initialize conditions annotations
            annot_root = XMLNode(XMLTriple('enzymeml:reaction'),
                                 XMLAttributes(), XMLNamespaces())
            annot_root.addNamespace("http://sbml.org/enzymeml/version1",
                                    "enzymeml")

            conditions_root = XMLNode(XMLTriple('enzymeml:conditions'),
                                      XMLAttributes(), XMLNamespaces())

            temp_node = XMLNode(XMLTriple('enzymeml:temperature'),
                                XMLAttributes(), XMLNamespaces())
            temp_node.addAttr('value', str(reac.getTemperature()))
            temp_node.addAttr('unit', reac.getTempunit())

            ph_node = XMLNode(XMLTriple('enzymeml:ph'), XMLAttributes(),
                              XMLNamespaces())
            ph_node.addAttr('value', str(reac.getPh()))

            conditions_root.addChild(temp_node)
            conditions_root.addChild(ph_node)

            annot_root.addChild(conditions_root)

            all_elems = reac.getEducts() + reac.getProducts()
            all_repls = [repl for tup in all_elems for repl in tup[3]]

            if len(all_repls) > 0:

                # initialize replica/format annotations
                replica_root = XMLNode(XMLTriple('enzymeml:replicas'),
                                       XMLAttributes(), XMLNamespaces())

                replicate = all_repls[0]

                time = replicate.getData().index.tolist()
                time_unit = replicate.getTimeUnit()

                time_node = XMLNode(XMLTriple('enzymeml:column'),
                                    XMLAttributes(), XMLNamespaces())
                time_node.addAttr('type', 'time')
                time_node.addAttr('unit', time_unit)
                time_node.addAttr('index', str(index))

                format_.addChild(time_node)
                data.append(time)
                index += 1

            # iterate over lists
            # educts
            for educt in reac.getEducts():

                species = educt[0]
                stoich = educt[1]
                const = educt[2]
                init_concs = educt[-1]

                specref = reaction.createReactant()
                specref.setSpecies(species)
                specref.setStoichiometry(stoich)
                specref.setConstant(const)

                # if there are different initial concentrations create an annotation
                try:
                    # DIRTY WAY ATM TO MAINTAIN FUNCTIONALITY
                    init_concs.remove([])
                except ValueError:
                    pass

                if len(init_concs) > 0:

                    conc_annot = XMLNode(XMLTriple('enzymeml:initConcs'),
                                         XMLAttributes(), XMLNamespaces())
                    conc_annot.addNamespace(
                        "http://sbml.org/enzymeml/version1", "enzymeml")

                    for conc in init_concs:

                        try:
                            conc_node = XMLNode(XMLTriple('enzymeml:initConc'),
                                                XMLAttributes(),
                                                XMLNamespaces())
                            conc_node.addAttr("id", str(conc))
                            conc_node.addAttr(
                                "value", str(enzmldoc.getConcDict()[conc][0]))
                            conc_node.addAttr(
                                "unit",
                                enzmldoc.getReactant(
                                    species).getSubstanceunits())
                            conc_annot.addChild(conc_node)

                        except KeyError:

                            inv_initconc = {
                                item: key
                                for key, item in
                                enzmldoc.getConcDict().items()
                            }
                            init_entry = enzmldoc.getConcDict()[inv_initconc[(
                                conc, enzmldoc.getReactant(
                                    species).getSubstanceunits())]]

                            conc_node = XMLNode(XMLTriple('enzymeml:initConc'),
                                                XMLAttributes(),
                                                XMLNamespaces())
                            conc_node.addAttr(
                                "id",
                                inv_initconc[(conc,
                                              enzmldoc.getReactant(species).
                                              getSubstanceunits())])
                            conc_node.addAttr("value", str(init_entry[0]))
                            conc_node.addAttr("unit", str(init_entry[1]))
                            conc_annot.addChild(conc_node)

                    specref.appendAnnotation(conc_annot)

                for repl in educt[3]:

                    repl_node = XMLNode(XMLTriple('enzymeml:replica'),
                                        XMLAttributes(), XMLNamespaces())
                    repl_node.addAttr('measurement', 'M0')
                    repl_node.addAttr('replica', repl.getReplica())

                    form_node = XMLNode(XMLTriple('enzymeml:column'),
                                        XMLAttributes(), XMLNamespaces())
                    form_node.addAttr('replica', repl.getReplica())
                    form_node.addAttr('species', repl.getReactant())
                    form_node.addAttr('type', repl.getType())
                    form_node.addAttr('unit', repl.getDataUnit())
                    form_node.addAttr('index', str(index))
                    form_node.addAttr('initConcID', str(repl.getInitConc()))

                    replica_root.addChild(repl_node)
                    format_.addChild(form_node)

                    data.append(repl.getData().values.tolist())

                    index += 1

            # products
            for product in reac.getProducts():

                species = product[0]
                stoich = product[1]
                const = product[2]

                specref = reaction.createProduct()
                specref.setSpecies(species)
                specref.setStoichiometry(stoich)
                specref.setConstant(const)

                for repl in product[3]:

                    repl_node = XMLNode(XMLTriple('enzymeml:replica'),
                                        XMLAttributes(), XMLNamespaces())
                    repl_node.addAttr('measurement', 'M0')
                    repl_node.addAttr('replica', repl.getReplica())

                    form_node = XMLNode(XMLTriple('enzymeml:column'),
                                        XMLAttributes(), XMLNamespaces())
                    form_node.addAttr('replica', repl.getReplica())
                    form_node.addAttr('species', repl.getReactant())
                    form_node.addAttr('type', repl.getType())
                    form_node.addAttr('unit', repl.getDataUnit())
                    form_node.addAttr('index', str(index))
                    form_node.addAttr('initConcID', str(repl.getInitConc()))

                    replica_root.addChild(repl_node)
                    format_.addChild(form_node)

                    data.append(repl.getData().values.tolist())

                    index += 1

            # modifiers
            for modifier in reac.getModifiers():

                species = modifier[0]

                specref = reaction.createModifier()
                specref.setSpecies(species)

                for repl in modifier[-1]:

                    repl_node = XMLNode(XMLTriple('enzymeml:replica'),
                                        XMLAttributes(), XMLNamespaces())
                    repl_node.addAttr('measurement', 'M0')
                    repl_node.addAttr('replica', repl.getReplica())

                    form_node = XMLNode(XMLTriple('enzymeml:column'),
                                        XMLAttributes(), XMLNamespaces())
                    form_node.addAttr('replica', repl.getReplica())
                    form_node.addAttr('species', repl.getReactant())
                    form_node.addAttr('initConcID', str(repl.getInitConc()))

                    replica_root.addChild(repl_node)
                    format_.addChild(form_node)

                    data.append(repl.getData().values.tolist())

                    index += 1

                try:
                    # add kinetic law if existent
                    reac.getModel().addToReaction(reaction)
                except AttributeError:
                    pass

            if len(all_repls) > 0:
                annot_root.addChild(replica_root)

            reaction.appendAnnotation(annot_root)

        # finalize all reactions
        list_formats.addChild(format_)

        list_measurements = XMLNode(XMLTriple('enzymeml:listOfMeasurements'),
                                    XMLAttributes(), XMLNamespaces())

        meas = XMLNode(XMLTriple('enzymeml:measurement'), XMLAttributes(),
                       XMLNamespaces())
        meas.addAttr('file', 'file0')
        meas.addAttr('id', 'M0')
        meas.addAttr('name', 'AnyName')

        list_measurements.addChild(meas)

        if len(all_repls) > 0:
            list_files = XMLNode(XMLTriple('enzymeml:listOfFiles'),
                                 XMLAttributes(), XMLNamespaces())

            file = XMLNode(XMLTriple('enzymeml:file'), XMLAttributes(),
                           XMLNamespaces())
            file.addAttr('file', './data/data.csv')
            file.addAttr('format', 'format0')
            file.addAttr('id', 'file0')

            list_files.addChild(file)

        if csv:
            # write file to csv
            df = pd.DataFrame(np.array(data).T)
            df.to_csv(self.path + '/data/data.csv', index=False, header=False)

        if len(all_repls) > 0:
            data_root.addChild(list_formats)
            data_root.addChild(list_files)

        data_root.addChild(list_measurements)

        model.getListOfReactions().appendAnnotation(data_root)
コード例 #8
0
    def __addProteins(self, model, enzmldoc):

        for key, protein in enzmldoc.getProteinDict().items():

            species = model.createSpecies()
            species.setId(key)
            species.setName(protein.getName())
            species.setMetaId(protein.getMetaid())
            species.setSBOTerm(protein.getSboterm())
            species.setCompartment(protein.getCompartment())
            species.setBoundaryCondition(protein.getBoundary())
            species.setInitialConcentration(protein.getInitConc())
            species.setSubstanceUnits(protein.getSubstanceUnits())
            species.setConstant(protein.getConstant())
            species.setHasOnlySubstanceUnits(False)

            # add annotation
            annot_root = XMLNode(XMLTriple('enzymeml:protein'),
                                 XMLAttributes(), XMLNamespaces())
            annot_root.addNamespace("http://sbml.org/enzymeml/version1",
                                    "enzymeml")

            annot_sequence = XMLNode(XMLTriple('enzymeml:sequence'),
                                     XMLAttributes(), XMLNamespaces())
            sequence = XMLNode(protein.getSequence())

            annot_sequence.addChild(sequence)
            annot_root.addChild(annot_sequence)

            try:
                annot_ec = XMLNode(XMLTriple('enzymeml:ECnumber'),
                                   XMLAttributes(), XMLNamespaces())
                ecnumber = XMLNode(protein.getEcnumber())
                annot_ec.addChild(ecnumber)
                annot_root.addChild(annot_ec)
            except AttributeError:
                pass

            try:
                annot_uniprot = XMLNode(XMLTriple('enzymeml:uniprotID'),
                                        XMLAttributes(), XMLNamespaces())
                uniprotid = XMLNode(protein.getUniprotID())
                annot_uniprot.addChild(uniprotid)
                annot_root.addChild(annot_uniprot)
            except AttributeError:
                pass

            try:
                annot_org = XMLNode(XMLTriple('enzymeml:organism'),
                                    XMLAttributes(), XMLNamespaces())
                organism = XMLNode(protein.getOrganism())
                annot_org.addChild(organism)
                annot_root.addChild(annot_org)
            except AttributeError:
                pass

            species.appendAnnotation(annot_root)
コード例 #9
0
    def __addRefs(self, model, enzmldoc):

        annot_bool = False
        ref_annot = XMLNode(XMLTriple("enzymeml:references"), XMLAttributes(),
                            XMLNamespaces())
        ref_annot.addNamespace("http://sbml.org/enzymeml/version1", "enzymeml")

        try:
            doi = XMLNode(enzmldoc.getDoi())
            doi_node = XMLNode(XMLTriple("enzymeml:doi"), XMLAttributes(),
                               XMLNamespaces())
            doi_node.addChild(doi)
            ref_annot.addChild(doi_node)
            annot_bool = True
        except AttributeError:
            pass

        try:
            pubmedid = XMLNode(enzmldoc.getPubmedID())
            pubmed_node = XMLNode(XMLTriple("enzymeml:pubmedID"),
                                  XMLAttributes(), XMLNamespaces())
            pubmed_node.addChild(pubmedid)
            ref_annot.addChild(pubmed_node)
            annot_bool = True
        except AttributeError:
            pass

        try:
            url = XMLNode(enzmldoc.getUrl())
            url_node = XMLNode(XMLTriple("enzymeml:url"), XMLAttributes(),
                               XMLNamespaces())
            url_node.addChild(url)
            ref_annot.addChild(url_node)
            annot_bool = True
        except AttributeError:
            pass

        if annot_bool:
            model.appendAnnotation(ref_annot)
コード例 #10
0
notes = XMLNode.convertStringToXMLNode("""
    <body xmlns='http://www.w3.org/1999/xhtml'>
    <h1>Koenig Human Glucose Metabolism</h1>
    <h2>Description</h2>
    <p>
        This is a metabolism model of Human glucose metabolism in <a href="http://sbml.org">SBML</a> format.
    </p>
    <p>This model is based on the article:</p>
    <div class="bibo:title">
        <a href="http://identifiers.org/pubmed/22761565" title="Access to this publication">Quantifying the
        contribution of the liver to glucose homeostasis: a detailed kinetic model of human hepatic glucose metabolism.
        </a>
    </div>
    <div class="bibo:authorList">König M., Bulik S., Holzhütter HG.</div>
    <div class="bibo:Journal">PLoS Comput Biol. 2012;8(6)</div>
    <p>Abstract:</p>
    <div class="bibo:abstract">
    <p>Despite the crucial role of the liver in glucose homeostasis, a detailed mathematical model of human
         hepatic glucose metabolism is lacking so far. Here we present a detailed kinetic model of glycolysis,
         gluconeogenesis and glycogen metabolism in human hepatocytes integrated with the hormonal control of
         these pathways by insulin, glucagon and epinephrine. Model simulations are in good agreement with experimental
         data on (i) the quantitative contributions of glycolysis, gluconeogenesis, and glycogen metabolism to hepatic
         glucose production and hepatic glucose utilization under varying physiological states. (ii) the time courses
         of postprandial glycogen storage as well as glycogen depletion in overnight fasting and short term fasting
         (iii) the switch from net hepatic glucose production under hypoglycemia to net hepatic glucose utilization
         under hyperglycemia essential for glucose homeostasis (iv) hormone perturbations of hepatic glucose
         metabolism. Response analysis reveals an extra high capacity of the liver to counteract changes of
         plasma glucose level below 5 mM (hypoglycemia) and above 7.5 mM (hyperglycemia). Our model may serve as
         an important module of a whole-body model of human glucose metabolism and as a valuable tool for
         understanding the role of the liver in glucose homeostasis under normal conditions and in diseases
         like diabetes or glycogen storage diseases.</p>
    </div>
    """ + templates.terms_of_use + """
    </body>
    """)
コード例 #11
0
    fcl_px_caf : hepatic clearance paraxanthine (relative to caffeine)
"""
from libsbml import UNIT_KIND_METRE, UNIT_KIND_SECOND, UNIT_KIND_LITRE, UNIT_KIND_GRAM
from libsbml import XMLNode
from sbmlutils.modelcreator import templates
import sbmlutils.factory as mc

##############################################################
mid = 'caffeine_pkpd'
version = 8
notes = XMLNode.convertStringToXMLNode("""
    <body xmlns='http://www.w3.org/1999/xhtml'>
    <h1>PKPD model for clearance of caffeine</h1>
    <h2>Description</h2>
    <p>
        This model is a physiologically based pharmacokinetic model (PKPD) encoded in <a href="http://sbml.org">SBML</a> format
        for the clearance of caffeine by the human body.
    </p>
    """ + templates.terms_of_use + """
    </body>
    """)

creators = templates.creators
main_units = {
    'time': 'h',
    'extent': 'mg',
    'substance': 'mg',
    'length': 'm',
    'area': 'm2',
    'volume': UNIT_KIND_LITRE,
}
コード例 #12
0
notes = XMLNode.convertStringToXMLNode("""
    <body xmlns='http://www.w3.org/1999/xhtml'>
    <h1>DallaMan2006 - Glucose Insulin System</h1>
    <h2>Description</h2>
    <p>
        This is a A simulation model of the glucose-insulin system in the postprandial state in <a href="http://sbml.org">SBML</a> format.
    </p>
    <p>This model is described in the article:</p>
    <div class="bibo:title">
        <a href="http://identifiers.org/pubmed/17926672" title="Access to this publication">Meal simulation model of the glucose-insulin system.</a>
    </div>
    <div class="bibo:authorList">Dalla Man C, Rizza RA, Cobelli C.</div>
    <div class="bibo:Journal">IEEE Trans Biomed Eng. 2007 Oct;54(10):1740-9.</div>
    <p>Abstract:</p>
    <div class="bibo:abstract">
    <p>Asimulation model of the glucose-insulin system in the
postprandial state can be useful in several circumstances, including
testing of glucose sensors, insulin infusion algorithms and decision
support systems for diabetes. Here, we present a new simulation
model in normal humans that describes the physiological events
that occur after a meal, by employing the quantitative knowledge
that has become available in recent years. Model parameters were
set to fit the mean data of a large normal subject database that underwent
a triple tracer meal protocol which provided quasi-modelindependent
estimates of major glucose and insulin fluxes, e.g., meal
rate of appearance, endogenous glucose production, utilization of
glucose, insulin secretion.</p>
    </div>
    """ + templates.terms_of_use + """
    </body>
    """)
コード例 #13
0
from sbmlutils.modelcreator import templates
import sbmlutils.factory as mc
from sbmlutils.modelcreator.processes import ReactionTemplate

########################################################################################################################

mid = 'galactose'
version = "v32"
notes = XMLNode.convertStringToXMLNode("""
    <body xmlns='http://www.w3.org/1999/xhtml'>
    <h1>PBPK model for galactose based dynamical liver function tests (GEC).</h1>
    <h2>Description</h2>
    <p>
        This model is a physiological-base pharmacokinetic model (PBPK) for the
        absorption, distribution, metabolism and elimination of galactose 
        encoded in <a href="http://sbml.org">SBML</a> format.<br /> 
        The model is applied to the analysis of galactose based liver function tests.
    </p>
    """ + templates.terms_of_use + """
    </body>
    """)
creators = templates.creators

########################################################################################################################

COMPARTMENTS = {
    "ve": "venous blood",
    "gu": "gut",
    "ki": "kidney",
    "li": "liver",