def annotation_to_html(item: libsbml.SBase) -> str: """Render HTML representation of given annotation. :param item: SBase instance """ lines = [] for kcv in range(item.getNumCVTerms()): cv = item.getCVTerm(kcv) q_type = cv.getQualifierType() if q_type == 0: qualifier = miriam.ModelQualifierType[cv.getModelQualifierType()] elif q_type == 1: qualifier = miriam.BiologicalQualifierType[ cv.getBiologicalQualifierType()] lines.append("".join( ['<span class="collection">', qualifier, "</span>"])) items = [] for k in range(cv.getNumResources()): uri = cv.getResourceURI(k) tokens = uri.split("/") resource_id = tokens[-1] link = "".join( ['<a href="', uri, '" target="_blank">', resource_id, "</a>"]) items.append(link) lines.append("; ".join(items)) res = "<br />".join(lines) return res
def cvterms(cls, sbase: libsbml.SBase) -> Optional[List]: """Parse CVTerms information. :param sbase: SBase instance """ if not sbase.isSetAnnotation(): return None cvterms = [] for kcv in range(sbase.getNumCVTerms()): cv: libsbml.CVTerm = sbase.getCVTerm(kcv) # qualifier q_type = cv.getQualifierType() if q_type == libsbml.MODEL_QUALIFIER: qualifier = ModelQualifierType[cv.getModelQualifierType()] elif q_type == libsbml.BIOLOGICAL_QUALIFIER: qualifier = BiologicalQualifierType[ cv.getBiologicalQualifierType()] else: raise ValueError(f"Unsupported qualifier type: '{q_type}'") resources = [ cv.getResourceURI(k) for k in range(cv.getNumResources()) ] cvterms.append({ "qualifier": qualifier, "resources": resources, }) # add SBO term as CVTerm if sbase.isSetSBOTerm(): sbo = sbase.getSBOTermID() sbo_in_cvs: bool = False for cv in cvterms: for resource in cv["resources"]: if sbo in resource: sbo_in_cvs = True break if not sbo_in_cvs: cvterms = [{ "qualifier": "BQB_IS", "resources": [f"https://identifiers.org/{sbo}"], }] + cvterms return cvterms