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))
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}")