Exemplo n.º 1
0
def set_model_info(model, notes=None, creators=None, units=None, main_units=None):
    """ Adds the shared information to the models.

    :param model: SBMLModel instance
    :return:
    """
    if creators:
        history.set_model_history(model, creators=creators)
    if units:
        set_units(model, units=units)
    if main_units:
        set_main_units(model, main_units=main_units)
    if notes:
        set_notes(model, notes=notes)
Exemplo n.º 2
0
def test_set_model_history():
    creators = [factory.Creator(familyName='Koenig', givenName="Matthias",
                                email="*****@*****.**", organization="Test organisation")]
    sbmlns = libsbml.SBMLNamespaces(3, 1)
    doc = libsbml.SBMLDocument(sbmlns)
    model = doc.createModel()
    history.set_model_history(model, creators)

    # check if history was written correctly
    h = model.getModelHistory()
    assert h is not None
    assert h.getNumCreators() == 1
    c = h.getCreator(0)
    assert 'Koenig' == c.getFamilyName()
    assert 'Matthias' == c.getGivenName()
    assert '*****@*****.**' == c.getEmail()
    assert 'Test organisation' == c.getOrganization()
Exemplo n.º 3
0
def set_model_info(model,
                   notes=None,
                   creators=None,
                   units=None,
                   main_units=None):
    """ Adds the shared information to the models.

    :param model: SBMLModel instance
    :return:
    """
    if creators:
        history.set_model_history(model, creators=creators)
    if units:
        set_units(model, units=units)
    if main_units:
        set_main_units(model, main_units=main_units)
    if notes:
        set_notes(model, notes=notes)
Exemplo n.º 4
0
def test_set_model_history():
    creators = [
        factory.Creator(familyName='Koenig',
                        givenName="Matthias",
                        email="*****@*****.**",
                        organization="Test organisation")
    ]
    sbmlns = libsbml.SBMLNamespaces(3, 1)
    doc = libsbml.SBMLDocument(sbmlns)
    model = doc.createModel()
    history.set_model_history(model, creators)

    # check if history was written correctly
    h = model.getModelHistory()
    assert h is not None
    assert h.getNumCreators() == 1
    c = h.getCreator(0)
    assert 'Koenig' == c.getFamilyName()
    assert 'Matthias' == c.getGivenName()
    assert '*****@*****.**' == c.getEmail()
    assert 'Test organisation' == c.getOrganization()
Exemplo n.º 5
0
    def create_sbml(self, sbml_level=SBML_LEVEL, sbml_version=SBML_VERSION):
        """ Create the SBML model

        :return:
        :rtype:
        """
        from sbmlutils.validation import check

        logging.info('*'*40)
        logging.info(self.model_id)
        logging.info('*' * 40)

        # create core model
        sbmlns = libsbml.SBMLNamespaces(sbml_level, sbml_version)

        # add all the packages
        # FIXME: only add packages which are required for the model

        sbmlns.addPackageNamespace("fbc", 2)
        sbmlns.addPackageNamespace("comp", 1)
        # sbmlns.addPackageNamespace("distrib", 1)

        self.doc = libsbml.SBMLDocument(sbmlns)
        self.doc.setPackageRequired("comp", True)
        self.doc.setPackageRequired("fbc", False)
        # self.doc.setPackageRequired("distrib", True)

        self.model = self.doc.createModel()
        fbc_plugin = self.model.getPlugin("fbc")
        fbc_plugin.setStrict(False)

        # name & id
        check(self.model.setId(self.model_id), 'set id')
        check(self.model.setName(self.model_id), 'set name')
        # notes
        if hasattr(self, 'notes') and self.notes is not None:
            factory.set_notes(self.model, self.notes)
        # history
        if hasattr(self, 'creators'):
            history.set_model_history(self.model, self.creators)

        # model units
        if hasattr(self, 'model_units'):
            factory.set_model_units(self.model, self.model_units)

        # lists ofs
        for attr in [
            'externalModelDefinitions',
            'submodels',
            'units',
            'functions',
            'parameters',
            'compartments',
            'species',
            'assignments',
            'rules',
            'rate_rules',
            'reactions',
            'events',
            'constraints',
            'ports',
            'replacedElements',
            'deletions',
            'objectives',
            'layouts'
        ]:
            # create the respective objects
            if hasattr(self, attr):
                objects = getattr(self, attr)
                if objects:
                    factory.create_objects(self.model, obj_iter=objects, key=attr)
                else:
                    logging.warning("Not defined: <{}> ".format(attr))
Exemplo n.º 6
0
    def create_sbml(self,
                    sbml_level: int = SBML_LEVEL,
                    sbml_version: int = SBML_VERSION) -> libsbml.SBMLDocument:
        """Create the SBML model.

        :return:
        :rtype:
        """

        logger.info(f"create_sbml: '{self.model_id}'")

        # create core model
        sbmlns = libsbml.SBMLNamespaces(sbml_level, sbml_version)

        # add all the packages
        # FIXME: only add packages which are required for the model
        supported_packages = {"fbc", "comp", "distrib"}
        sbmlns.addPackageNamespace("comp", 1)
        for package in self.packages:
            if package not in supported_packages:
                raise ValueError(
                    f"Supported packages are: '{supported_packages}', "
                    f"but package '{package}' found.")
            if package == "fbc":
                sbmlns.addPackageNamespace("fbc", 2)
            if package == "distrib":
                sbmlns.addPackageNamespace("distrib", 1)

        self.doc = libsbml.SBMLDocument(sbmlns)
        self.model = self.doc.createModel()
        self.doc.setPackageRequired("comp", True)
        if "fbc" in self.packages:
            self.doc.setPackageRequired("fbc", False)
            fbc_plugin = self.model.getPlugin("fbc")
            fbc_plugin.setStrict(False)
        if "distrib" in self.packages:
            self.doc.setPackageRequired("distrib", True)

        # name & id
        if self.model_id:
            check(self.model.setId(self.model_id), "set id")
            check(self.model.setName(self.model_id), "set name")
        else:
            logger.warning("Model id 'mid' should be set on model")
        # notes
        if hasattr(self, "notes") and self.notes is not None:
            factory.set_notes(self.model, self.notes)
        # history
        if hasattr(self, "creators"):
            history.set_model_history(self.model, self.creators)

        # model units
        if hasattr(self, "model_units"):
            factory.ModelUnits.set_model_units(
                self.model, self.model_units)  # type: ignore

        # lists ofs
        for attr in [
                "externalModelDefinitions",
                "submodels",
                "units",
                "functions",
                "parameters",
                "compartments",
                "species",
                "assignments",
                "rules",
                "rate_rules",
                "reactions",
                "events",
                "constraints",
                "ports",
                "replacedElements",
                "deletions",
                "objectives",
                "layouts",
        ]:
            # create the respective objects
            if hasattr(self, attr):
                objects = getattr(self, attr)
                if objects:
                    factory.create_objects(self.model,
                                           obj_iter=objects,
                                           key=attr)
                else:
                    logger.debug(f"Not defined: <{attr}>")

        return self.doc
Exemplo n.º 7
0
    def create_sbml(self, sbml_level=SBML_LEVEL, sbml_version=SBML_VERSION):
        """ Create the SBML model

        :return:
        :rtype:
        """
        from sbmlutils.validation import check

        logging.info('*' * 40)
        logging.info(self.model_id)
        logging.info('*' * 40)

        # create core model
        sbmlns = libsbml.SBMLNamespaces(sbml_level, sbml_version)

        # add all the packages
        # FIXME: only add packages which are required for the model

        sbmlns.addPackageNamespace("fbc", 2)
        sbmlns.addPackageNamespace("comp", 1)
        # sbmlns.addPackageNamespace("distrib", 1)

        self.doc = libsbml.SBMLDocument(sbmlns)
        self.doc.setPackageRequired("comp", True)
        self.doc.setPackageRequired("fbc", False)
        # self.doc.setPackageRequired("distrib", True)

        self.model = self.doc.createModel()
        fbc_plugin = self.model.getPlugin("fbc")
        fbc_plugin.setStrict(False)

        # name & id
        check(self.model.setId(self.model_id), 'set id')
        check(self.model.setName(self.model_id), 'set name')
        # notes
        if hasattr(self, 'notes') and self.notes is not None:
            factory.set_notes(self.model, self.notes)
        # history
        if hasattr(self, 'creators'):
            history.set_model_history(self.model, self.creators)

        # model units
        if hasattr(self, 'model_units'):
            factory.set_model_units(self.model, self.model_units)

        # lists ofs
        for attr in [
                'externalModelDefinitions', 'submodels', 'units', 'functions',
                'parameters', 'compartments', 'species', 'assignments',
                'rules', 'rate_rules', 'reactions', 'events', 'constraints',
                'ports', 'replacedElements', 'deletions', 'objectives',
                'layouts'
        ]:
            # create the respective objects
            if hasattr(self, attr):
                objects = getattr(self, attr)
                if objects:
                    factory.create_objects(self.model,
                                           obj_iter=objects,
                                           key=attr)
                else:
                    logging.info("Not defined: <{}> ".format(attr))