コード例 #1
0
    def section2_3_6_singular_annotations(self):
        """Example of how to create singular annotations"""
        # Create a combine archive called MichaelisMenten1.omex that contains a MichaelisMenten1.sbml file
        combine_archive_filename = create_combine_archive(
            SBML_STRING, name="SingularAnnotations")

        # we extract the sbml from the combine archive
        sbml = extract_sbml_from_combine_archive(combine_archive_filename)

        # sbml is a list of all sbml files in archive. We know there is only 1, so get the string
        if len(sbml) != 1:
            raise ValueError(
                "Something is wrong - you should only have 1 sbml file in the combine archive"
            )

        sbml = sbml[0]

        # create an RDF object. Its empty.
        rdf = RDF()
        rdf.set_model_uri("SingularAnnotations")

        # here we turn off semantic extraction to make output clearer
        editor = rdf.to_editor(sbml,
                               generate_new_metaids=False,
                               sbml_semantic_extraction=False)

        with editor.new_singular_annotation(
        ) as example_using_bqbiol_pred_and_uri_resource:
            example_using_bqbiol_pred_and_uri_resource.about("S") \
                .predicate("bqbiol", "is") \
                .resource_uri("uniprot/Q15796")

        with editor.new_singular_annotation(
        ) as example_using_bqmodel_pred_and_literal_resource:
            example_using_bqmodel_pred_and_literal_resource.about("MichaelisMenten") \
                .predicate("bqmodel", "isDescribedBy") \
                .resource_literal("Anything can go here. It is a string literal.")

        # recreate the combine archive
        fname = create_combine_archive(sbml, "SingularAnnotations", str(rdf))

        return fname
コード例 #2
0
    def section2_3_4_personal_information(self):
        """Example of how to use the PersonalInformation class"""
        # Create a combine archive called MichaelisMenten1.omex that contains a MichaelisMenten1.sbml file
        combine_archive_filename = create_combine_archive(
            SBML_STRING, name="PersonalInformation")

        # we extract the sbml from the combine archive
        sbml = extract_sbml_from_combine_archive(combine_archive_filename)

        # sbml is a list of all sbml files in archive. We know there is only 1, so get the string
        if len(sbml) != 1:
            raise ValueError(
                "Something is wrong - you should only have 1 sbml file in the combine archive"
            )

        sbml = sbml[0]

        # create an RDF object. Its empty.
        rdf = RDF()
        rdf.set_model_uri("PersonalInformation")

        # create an editor. Note these are the default arguments - but shown here for completeness
        editor = rdf.to_editor(sbml,
                               generate_new_metaids=False,
                               sbml_semantic_extraction=True)

        # Here we use a "with" block.
        # internally, the "with" block will always execute a piece of code before
        # exiting the with block. In this case, it calls "Editor.add_personal_information()"
        # so that the user cannot forget to do it.
        # Note that in C or C++, the user must remember to add a newly created annotation to the editor.
        with editor.new_personal_information() as information:
            information.add_creator("orcid:0000-0001-8254-4957") \
                .add_name("Robin hood") \
                .add_mbox("*****@*****.**") \
                .add_account_name("stolen_goods") \
                .add_account_service_homepage("https://get-your-free-stuff-here.com")

        fname = create_combine_archive(sbml, "PersonalInformation", str(rdf))

        return fname
コード例 #3
0
    def section2_3_7_3_energy_diff(self):
        """Example of how to create EnergyDiff type composite annotations"""

        # Create a combine archive called MichaelisMenten1.omex that contains a MichaelisMenten1.sbml file
        combine_archive_filename = create_combine_archive(SBML_STRING,
                                                          name="EnergyDiff")

        # we extract the sbml from the combine archive
        sbml = extract_sbml_from_combine_archive(combine_archive_filename)

        # sbml is a list of all sbml files in archive. We know there is only 1, so get the string
        if len(sbml) != 1:
            raise ValueError(
                "Something is wrong - you should only have 1 sbml file in the combine archive"
            )

        sbml = sbml[0]

        # create an RDF object. Its empty.
        rdf = RDF()
        rdf.set_model_uri("EnergyDiff")

        # sbml semantic extraction will automatically create these physical entities for us.
        # here, we turn it off so we can create them manually
        editor = rdf.to_editor(sbml,
                               generate_new_metaids=False,
                               sbml_semantic_extraction=False)

        # OPB:OPB_00378 = chemical potential
        with editor.new_energy_diff() as physcial_force:
            physcial_force.about("S") \
                .has_property("OPB:OPB_00378") \
                .add_source(1.0, "EntityProperty0002") \
                .add_sink(1.0, "EntityProperty0001")

        fname = create_combine_archive(sbml, "EnergyDiff", str(rdf))

        return fname
コード例 #4
0
    def section2_3_4_model_level_annotations(self):
        """Example of how to create model level annotations"""
        # Create a combine archive called MichaelisMenten1.omex that contains a MichaelisMenten1.sbml file
        combine_archive_filename = create_combine_archive(
            SBML_STRING, name="ModelLevelAnnotations")

        # we extract the sbml from the combine archive
        sbml = extract_sbml_from_combine_archive(combine_archive_filename)

        # sbml is a list of all sbml files in archive. We know there is only 1, so get the string
        if len(sbml) != 1:
            raise ValueError(
                "Something is wrong - you should only have 1 sbml file in the combine archive"
            )

        sbml = sbml[0]

        # create an RDF object. Its empty.
        rdf = RDF()
        rdf.set_model_uri("ModelLevelAnnotations")

        # create an editor. Note these are the default arguments - but shown here for completeness
        editor = rdf.to_editor(sbml,
                               generate_new_metaids=False,
                               sbml_semantic_extraction=True)

        editor.add_creator("orcid:0000-0001-8254-4957")\
            .add_curator("orcid:0000-0001-8254-4958")\
            .add_taxon("taxon/9895")\
            .add_pubmed("pubmed/12334")\
            .add_description("My supercool model")\
            .add_date_created("18-09-2020")\
            .add_parent_model("pubmed/123456")

        fname = create_combine_archive(sbml, "ModelLevelAnnotations", str(rdf))

        return fname
コード例 #5
0
@prefix OMEXlib: <http://omex-library.org/> .
@prefix myOMEX: <http://omex-library.org/NewOmex.omex/> .
@prefix local: <http://omex-library.org/NewOmex.omex/NewModel.rdf#> .

local:OmexMetaId0001
    bqbiol:isPropertyOf local:EntityProperty0000 ;
    bqbiol:isVersionOf <https://identifiers.org/OPB/OPB_00340> .

local:EntityProperty0000
    bqbiol:is <https://identifiers.org/uniprot/P84022> ;
    bqbiol:isPartOf <https://identifiers.org/fma/FMA:24178>, <https://identifiers.org/fma/FMA:63877>, <https://identifiers.org/fma/FMA:70737>, <https://identifiers.org/fma/FMA:7163> .

"""

# remember that the default parser is "guess".
# the parser will try to figure out which syntax is being used.
# but if it doesn't guess well, you can use the format argument for `from_string`
rdf = RDF.from_string(turtle_string)

formats = [
    "ntriples", "turtle", "rdfxml-abbrev", "rdfxml", "dot", "json-triples",
    "json", "nquads", "html"
]

for syntax in formats:
    print("Serializing to {}".format(syntax))
    print(rdf.to_string(syntax))
    print("\n\n")

# Note: printing the rdf object is the same as rdf.to_string("turtle")
コード例 #6
0
import os
from pyomexmeta import RDF, eUriType

# get the link to teusink2000
teusink_biomod_link = r"https://www.ebi.ac.uk/biomodels/model/download/BIOMD0000000064.2?filename=BIOMD0000000064_url.xml"

# download model xml, scan for rdf, create rdf graph and store in sqlite database
rdf = RDF.from_uri(teusink_biomod_link, format="rdfxml",
                   storage_type="sqlite", storage_name="TeusinkAnnotations2000",
                   storage_options="new='yes'")

# do a search for all annotations with glucode as resource: CHEBI:17234
query_string = """
SELECT ?x ?y
WHERE {
    ?x ?y <http://identifiers.org/obo.chebi/CHEBI:17234>
}
"""

results_formats = [
    "xml",
    "json",
    "table",
    "csv",
    "mkr",
    "tsv",
    "html",
    "turtle",
    "rdfxml",
]
コード例 #7
0
import os
from pyomexmeta import RDF, eUriType

rdf_str = """@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix bqbiol: <http://biomodels.net/biology-qualifiers/> .
@prefix OMEXlib: <http://omex-library.org/> .
@prefix myOMEX: <http://omex-library.org/NewOmex.omex/> .
@prefix local: <http://omex-library.org/NewOmex.omex/NewModel.rdf#> .

<http://omex-library.org/NewOmex.omex/NewModel.xml#OmexMetaId0000>
  bqbiol:is <https://identifiers.org/uniprot/PD12345> ."""

# download model xml, scan for rdf, create rdf graph and store in sqlite database
rdf = RDF.from_string(rdf_str, syntax="turtle")

# pick a filename (this can be anywhere on your system)
docs_dir = os.path.join(os.path.dirname(__file__), "source")
diagrams_dir = os.path.join(docs_dir, "diagrams")
fname = os.path.join(diagrams_dir, "Diagram")
# draw a diagram
rdf.draw(fname)
print(f"file saved to {fname}.pdf")
コード例 #8
0
        <kineticLaw>
          <math xmlns="http://www.w3.org/1998/Math/MathML">
            <apply>
              <times/>
              <ci> k4 </ci>
              <ci> D </ci>
            </apply>
          </math>
        </kineticLaw>
      </reaction>
    </listOfReactions>
  </model>
</sbml>
"""
# create an empty RDF object
rdf = RDF()

editor = rdf.to_editor(sbml,
                       generate_new_metaids=True,
                       sbml_semantic_extraction=False)

# Property: Osmotic Pressure
with editor.new_energy_diff() as energy_diff:
    energy_diff \
        .about("R1", eUriType.MODEL_URI) \
        .add_source(physical_entity_reference="SpeciesA", uri_type=eUriType.MODEL_URI) \
        .add_sink(physical_entity_reference="SpeciesB", uri_type=eUriType.MODEL_URI) \
        .has_property( property_about="k1", about_uri_type=eUriType.LOCAL_URI, is_version_of="opb:OPB_01058")

print(rdf)
コード例 #9
0
from pyomexmeta import RDF, eUriType
import os

rdf_str = """@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix bqbiol: <http://biomodels.net/biology-qualifiers/> .
@prefix OMEXlib: <http://omex-library.org/> .
@prefix myOMEX: <http://omex-library.org/NewOmex.omex/> .
@prefix local: <http://omex-library.org/NewOmex.omex/NewModel.rdf#> .

<http://omex-library.org/NewOmex.omex/NewModel.xml#OmexMetaId0000>
  bqbiol:is <https://identifiers.org/uniprot/PD12345> ."""

# create an empty RDF graph
rdf = RDF()

# we write the annotations to file, so we can read it in from file
#   filename is in same directory as your python script
fname = os.path.join(os.path.dirname(__file__), "annotations.rdf")

#   write turtle syntax to file
with open(fname, "w") as f:
    f.write(rdf_str)

#   Add to our RDF graph by reading the second string
rdf.add_from_file(fname, "turtle")

# print out annotations in turtle syntax
rdfxml_abbrev_string = rdf.to_string("rdfxml-abbrev")
print(rdfxml_abbrev_string)

# remove the file we wrote
コード例 #10
0
from pyomexmeta import RDF

# collect the link from "https://www.ebi.ac.uk/biomodels/BIOMD0000000308#Files"
tyson2003 = "https://www.ebi.ac.uk/biomodels/model/download/BIOMD0000000308.2?filename=BIOMD0000000308_url.xml"

# download the model, scan document for annotations and docs-build a graph
rdf = RDF.from_uri(tyson2003, format="rdfxml")

print(f"Number of annotations in graph: {len(rdf)}")
コード例 #11
0
from pyomexmeta import RDF, eUriType
import os

rdf_str = """@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix bqbiol: <http://biomodels.net/biology-qualifiers/> .
@prefix OMEXlib: <http://omex-library.org/> .
@prefix myOMEX: <http://omex-library.org/NewOmex.omex/> .
@prefix local: <http://omex-library.org/NewOmex.omex/NewModel.rdf#> .

<http://omex-library.org/NewOmex.omex/NewModel.xml#OmexMetaId0000>
  bqbiol:is <https://identifiers.org/uniprot/PD12345> ."""

# we write the annotations to file, so we can read it in from file
#   filename is in same directory as your python script
fname = os.path.join(os.path.dirname(__file__), "annotations.rdf")
#   write turtle syntax to file
with open(fname, "w") as f:
    f.write(rdf_str)

# Add to our RDF graph by reading the second string
rdf = RDF.from_file(fname, "turtle")

print(f"{len(rdf)} triples read from file")

# remove the file we wrote
if os.path.isfile(fname):
    os.remove(fname)
コード例 #12
0
            </reaction>
            <reaction id="r2" metaid="react2" reversible="false" fast="false">
                <listOfReactants>
                    <speciesReference species="Ca" stoichiometry="1" constant="true"/>
                    <speciesReference species="A" stoichiometry="1" constant="true"/>
                </listOfReactants>
                <listOfProducts>
                    <speciesReference species="PlasmaCa" stoichiometry="1" constant="true"/>
                </listOfProducts>
                <listOfModifiers>
                    <modifierSpeciesReference species="Enzyme"/>
                </listOfModifiers>
                <kineticLaw>
                    <math xmlns="http://www.w3.org/1998/Math/MathML">
                        <apply>
                            <times/>
                            <ci>k2</ci>
                            <ci>Ca</ci>
                        </apply>
                    </math>
                </kineticLaw>
            </reaction>
        </listOfReactions>
    </model>
</sbml>"""

rdf = RDF()
editor = rdf.to_editor(sbml, False)
print(editor.strip_annotations())

コード例 #13
0
    def section2_3_7_2_physical_process(self):
        """Example of how to create PhysicalProcess type composite annotations"""

        # Create a combine archive called MichaelisMenten1.omex that contains a MichaelisMenten1.sbml file
        combine_archive_filename = create_combine_archive(
            SBML_STRING, name="PhysicalProcess")

        # we extract the sbml from the combine archive
        sbml = extract_sbml_from_combine_archive(combine_archive_filename)

        # sbml is a list of all sbml files in archive. We know there is only 1, so get the string
        if len(sbml) != 1:
            raise ValueError(
                "Something is wrong - you should only have 1 sbml file in the combine archive"
            )

        sbml = sbml[0]

        # create an RDF object. Its empty.
        rdf = RDF()
        rdf.set_model_uri("PhysicalProcess")

        # sbml semantic extraction will automatically create these physical entities for us.
        # here, we turn it off so we can create them manually
        editor = rdf.to_editor(sbml,
                               generate_new_metaids=False,
                               sbml_semantic_extraction=False)

        # physical process composite annotations use references to physical entities.
        # therefore we build on the content from OmexMetaSpec1_1.section2_3_7_1_physical_entity()

        with editor.new_physical_entity() as substrate_entity:
            substrate_entity.about("S") \
                .has_property("OPB:OPB_00340") \
                .identity("uniprot/Q15796") \
                .is_part_of("FMA:66836") \
                .is_part_of("FMA:63877")

        with editor.new_physical_entity() as product_entity:
            product_entity.about("P") \
                .has_property("OPB:OPB_00340") \
                .identity("uniprot/smad2-p") \
                .is_part_of("FMA:66836") \
                .is_part_of("FMA:63877")

        with editor.new_physical_entity() as enzyme_entity:
            enzyme_entity.about("E") \
                .has_property("OPB:OPB_00340") \
                .identity("uniprot/P37173") \
                .is_part_of("FMA:66836") \
                .is_part_of("FMA:63877")

        with editor.new_physical_entity() as complex_entity:
            complex_entity.about("ES") \
                .has_property("OPB:OPB_00340") \
                .identity("uniprot/SmadReceptorComplex") \
                .is_part_of("FMA:66836") \
                .is_part_of("FMA:63877")

        ## optionally print out xml to look at the metaids
        # print(editor.get_xml())
        # print(editor.get_metaids())

        # We now create annotations for three reactions (physical processes)
        #  that are simulated in the sbml model
        with editor.new_physical_process() as substrate_bind_enzyme:
            substrate_bind_enzyme.about("R1") \
                .has_property("OPB:OPB_00593") \
                .add_source(1.0, "EntityProperty0000") \
                .add_source(1.0, "EntityProperty0003") \
                .add_sink(1.0, "EntityProperty0000") \
                .is_version_of()

        with editor.new_physical_process() as substrate_unbind_enzyme:
            substrate_unbind_enzyme.about("R2") \
                .has_property("OPB:OPB_00593") \
                .add_sink(1.0, "EntityProperty0000") \
                .add_sink(1.0, "EntityProperty0003") \
                .add_source(1.0, "EntityProperty0000")

        with editor.new_physical_process() as product_formation:
            product_formation.about("R3") \
                .has_property("OPB:OPB_00593") \
                .add_sink(1.0, "EntityProperty0002") \
                .add_sink(1.0, "EntityProperty0001") \
                .add_source(1.0, "EntityProperty0003")

        fname = create_combine_archive(sbml, "PhysicalProcess", str(rdf))

        return fname
コード例 #14
0
    def section2_3_7_1_physical_entity(self):
        """Example of how to create physical entity type composite annotations"""
        # Create a combine archive called MichaelisMenten1.omex that contains a MichaelisMenten1.sbml file
        combine_archive_filename = create_combine_archive(
            SBML_STRING, name="PhysicalEntity")

        # we extract the sbml from the combine archive
        sbml = extract_sbml_from_combine_archive(combine_archive_filename)

        # sbml is a list of all sbml files in archive. We know there is only 1, so get the string
        if len(sbml) != 1:
            raise ValueError(
                "Something is wrong - you should only have 1 sbml file in the combine archive"
            )

        sbml = sbml[0]

        # create an RDF object. Its empty.
        rdf = RDF()
        rdf.set_model_uri("PhysicalEntity")

        # sbml semantic extraction will automatically create these physical entities for us.
        # here, we turn it off so we can create them manually
        editor = rdf.to_editor(sbml,
                               generate_new_metaids=False,
                               sbml_semantic_extraction=False)

        # note: the syntax "fma:fma_12345" == "fma/fma_12345"
        # OPB:OPB_00340 = concentration of chemical
        # FMA:66836 = part of cytosol
        # FMA:63877 = fibroblast
        with editor.new_physical_entity() as substrate_entity:
            substrate_entity.about("S") \
                .has_property("OPB:OPB_00340") \
                .identity("uniprot/Q15796") \
                .is_part_of("FMA:66836") \
                .is_part_of("FMA:63877")

        with editor.new_physical_entity() as product_entity:
            product_entity.about("P") \
                .has_property("OPB:OPB_00340") \
                .identity("uniprot/smad2-p") \
                .is_part_of("FMA:66836") \
                .is_part_of("FMA:63877")

        with editor.new_physical_entity() as enzyme_entity:
            enzyme_entity.about("E") \
                .has_property("OPB:OPB_00340") \
                .identity("uniprot/P37173") \
                .is_part_of("FMA:66836") \
                .is_part_of("FMA:63877")

        with editor.new_physical_entity() as complex_entity:
            complex_entity.about("ES") \
                .has_property("OPB:OPB_00340") \
                .identity("uniprot/P37173") \
                .is_part_of("FMA:66836") \
                .is_part_of("FMA:63877")

        fname = create_combine_archive(sbml, "PhysicalEntity", str(rdf))

        return fname
コード例 #15
0
        <kineticLaw>
          <math xmlns="http://www.w3.org/1998/Math/MathML">
            <apply>
              <times/>
              <ci> k2 </ci>
              <ci> B </ci>
            </apply>
          </math>
        </kineticLaw>
      </reaction>
    </listOfReactions>
  </model>
</sbml>"""

# create an empty RDF object
rdf = RDF()

editor = rdf.to_editor(sbml, generate_new_metaids=True)

with editor.new_singular_annotation() as singular_annotation:
    singular_annotation \
        .about('species0001') \
        .predicate("bqbiol", "is") \
        .resource_uri("uniprot/P01137")

    # In python, the singular annotation gets committed to the model
    # automatically after the current context manager looses scope (i.e.
    # at the end of the current with block). But serializing (printing)
    # here does so without adding to the current RDF graph.
    # This features makes more sense in C/C++
    print(singular_annotation)
コード例 #16
0
from pyomexmeta import RDF, eUriType

# collect the link from "https://www.ebi.ac.uk/biomodels/BIOMD0000000308#Files"
tyson2003 = "https://www.ebi.ac.uk/biomodels/model/download/BIOMD0000000308.2?filename=BIOMD0000000308_url.xml"

# download the model, scan document for annotations and docs-build a graph
rdf = RDF.from_uri(tyson2003, syntax="rdfxml")

print(f"Number of annotations in graph: {len(rdf)}")
コード例 #17
0
from pyomexmeta import RDF

rdf_str = """@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
             @prefix OMEXlib: <http://omex-library.org/> .
             @prefix myOMEX: <http://omex-library.org/NewOmex.omex/> .
             @prefix local: <http://omex-library.org/NewOmex.omex/NewModel.rdf#> .

             <http://omex-library.org/NewOmex.omex/NewModel.xml#>
                 <http://purl.org/dc/terms/creator> <https://orchid.org/1234-1234-1234-1234> ."""

# read the annotations into RDF graph
rdf = RDF.from_string(rdf_str, format="turtle")

# serialize the string to rdfxml-abbrev
xml_string = rdf.to_string("rdfxml-abbrev")
print(f"RDF graph serialized to rdfxml abbreviated is:\n\n{xml_string}")
コード例 #18
0
        </listOfReactants>
        <listOfProducts>
          <speciesReference species="A" stoichiometry="1" constant="true"/>
        </listOfProducts>
        <kineticLaw>
          <math xmlns="http://www.w3.org/1998/Math/MathML">
            <apply>
              <times/>
              <ci> k2 </ci>
              <ci> B </ci>
            </apply>
          </math>
        </kineticLaw>
      </reaction>
    </listOfReactions>
  </model>
</sbml>"""

# create an empty RDF object
rdf = RDF()

editor = rdf.to_editor(sbml, "sbml")

print(editor.get_metaids())  # prints out model metaids

with editor.new_singular_annotation() as singular_annotation:
    singular_annotation \
        .about('ToyModel') \
        .predicate("dc", "description") \
        .resource_literal("This is a toy model for demonstration purposes")
print(rdf)