[docs]defcreate_minimal_ontology(graph:OntologyGraph[ID],terms:typing.Sequence[MINIMAL_TERM],version:typing.Optional[str]=None)->MinimalOntology[ID,MINIMAL_TERM]:""" Create minimal ontology from the components. :param graph: the ontology graph. :param terms: ALL ontology terms (both obsolete and primary). :param version: ontology version or `None` if unknown. :return: the ontology """current_terms=[termfortermintermsifterm.is_current]term_id_to_term=make_term_id_map(current_terms)returnDefaultMinimalOntology(graph,current_terms,term_id_to_term,version)
[docs]defcreate_ontology(graph:OntologyGraph[ID],terms:typing.Sequence[TERM],version:typing.Optional[str]=None)->Ontology[ID,TERM]:""" Create ontology from the components. :param graph: the ontology graph. :param terms: ALL ontology terms (both obsolete and primary). :param version: ontology version or `None` if unknown. :return: the ontology. """current_terms=[termfortermintermsifterm.is_current]term_id_to_term=make_term_id_map(current_terms)returnDefaultOntology(graph,current_terms,term_id_to_term,version)
defmake_term_id_map(terms:typing.Sequence[MINIMAL_TERM])->typing.Mapping[ID,MINIMAL_TERM]:""" Create a mapping from primary and alternate IDs to `MINIMAL_TERM`. :param terms: current ontology terms :return: mapping from primary and alternate IDs to `MINIMAL_TERM` """data={}forterminterms:data[term.identifier]=termforalt_idinterm.alt_term_ids:data[alt_id]=termreturndatadef_validate_term_id(term_id:CURIE_OR_TERM_ID_OR_IDENTIFIED)->TermId:""" Validate that `term_id` is a `TermId` or a valid CURIE `str`. """ifisinstance(term_id,TermId):returnterm_idelifisinstance(term_id,Identified):returnterm_id.identifierelifisinstance(term_id,str):returnTermId.from_curie(term_id)else:raiseValueError(f'Expected a `str`, a `TermId` or an `Identified` entity but got {type(term_id)}')