Exemplo n.º 1
0
    def annotate_sbase(sbase: libsbml.SBase, annotation: Annotation):
        """ Annotate SBase based on given annotation data

        :param sbase: libsbml.SBase
        :param annotation: Annotation
        :return:
        """
        qualifier, resource = annotation.qualifier.value, annotation.resource
        cv = libsbml.CVTerm()  # type: libsbml.CVTerm

        # set correct type of qualifier
        if qualifier.startswith("BQB"):
            cv.setQualifierType(libsbml.BIOLOGICAL_QUALIFIER)
            sbml_qualifier = ModelAnnotator.get_SBMLQualifier(qualifier)
            cv.setBiologicalQualifierType(sbml_qualifier)
        elif qualifier.startswith('BQM'):
            cv.setQualifierType(libsbml.MODEL_QUALIFIER)
            sbml_qualifier = ModelAnnotator.get_SBMLQualifier(qualifier)
            cv.setModelQualifierType(sbml_qualifier)
        else:
            LOGGER.error('Unsupported qualifier: {}'.format(qualifier))

        cv.addResource(resource)

        # meta id has to be set
        if not sbase.isSetMetaId():
            sbase.setMetaId(utils.create_metaid(sbase))

        success = sbase.addCVTerm(cv)

        if success != 0:
            LOGGER.error("RDF not written: ", success)
            LOGGER.error(libsbml.OperationReturnValue_toString(success))
            LOGGER.error("{}, {}, {}".format(object, qualifier, resource))
Exemplo n.º 2
0
    def annotate_sbase(sbase: libsbml.SBase, annotation: Annotation) -> None:
        """Annotate SBase based on given annotation data.

        :param sbase: libsbml.SBase
        :param annotation: Annotation
        :return:
        """
        qualifier, resource = annotation.qualifier.value, annotation.resource
        cv: libsbml.CVTerm = libsbml.CVTerm()

        # set correct type of qualifier
        if isinstance(qualifier, str):
            if qualifier.startswith("BQB"):
                cv.setQualifierType(libsbml.BIOLOGICAL_QUALIFIER)
                sbml_qualifier = ModelAnnotator.get_SBMLQualifier(qualifier)
                success = check(
                    cv.setBiologicalQualifierType(str(sbml_qualifier)),
                    f"Set biological qualifier: '{sbml_qualifier}'",
                )
                if success != 0:
                    logger.error(
                        f"Could not set biological qualifier: {qualifier}")
            elif qualifier.startswith("BQM"):
                cv.setQualifierType(libsbml.MODEL_QUALIFIER)
                sbml_qualifier = ModelAnnotator.get_SBMLQualifier(qualifier)
                success = check(
                    cv.setModelQualifierType(str(sbml_qualifier)),
                    f"Set model qualifier: '{sbml_qualifier}'",
                )
                if success != 0:
                    logger.error(f"Could not set model qualifier: {qualifier}")
            else:
                logger.error(f"Unsupported qualifier: '{qualifier}'")
        else:
            msg = (f"qualifier is not a string, but: '{qualifier}' of type "
                   f"'{type(qualifier)}'.")
            logger.error(msg)
            raise ValueError(msg)

        success = check(cv.addResource(resource),
                        f"Add resource: '{resource}'")
        if success != 0:
            logger.error(f"Could not add resource: {resource}")

        # meta id has to be set
        if not sbase.isSetMetaId():
            sbase.setMetaId(utils.create_metaid(sbase))

        success = sbase.addCVTerm(cv)

        if success != 0:
            logger.error(
                f"Annotation RDF for CVTerm could not be written: {cv}")
            logger.error(libsbml.OperationReturnValue_toString(success))
            logger.error(f"{sbase}, {qualifier}, {resource}")
Exemplo n.º 3
0
def set_model_history(model: libsbml.Model, creators) -> None:
    """Sets the model history from given creators.

    :param model: SBML model
    :param creators: list of creators
    :return None
    """
    if not model.isSetMetaId():
        model.setMetaId(create_metaid(sbase=model))

    if (creators is None) or (len(creators) == 0):
        # at least on
        return
    else:
        # create and set model history
        h = _create_history(creators)
        check(model.setModelHistory(h), "set model history")
Exemplo n.º 4
0
def set_model_history(model, creators):
    """ Sets the model history from given creators.

    :param model: SBML model
    :type model: libsbml.Model
    :param creators: list of creators
    :type creators:
    """
    if not model.isSetMetaId():
        model.setMetaId(create_metaid(sbase=model))

    if creators is None or len(creators) is 0:
        # at least on
        return
    else:
        # create and set model history
        h = _create_history(creators)
        check(model.setModelHistory(h), 'set model history')