diff --git a/src/pyobo/api/alts.py b/src/pyobo/api/alts.py index 6dd192af..c975f6dd 100644 --- a/src/pyobo/api/alts.py +++ b/src/pyobo/api/alts.py @@ -63,7 +63,7 @@ def get_primary_curie( **kwargs: Unpack[GetOntologyKwargs], ) -> str | None: """Get the primary curie for an entity.""" - reference = Reference.from_curie(curie, strict=kwargs.get("strict", True)) + reference = Reference.from_curie_or_uri(curie, strict=kwargs.get("strict", True)) if reference is None: return None primary_identifier = get_primary_identifier(reference, **kwargs) diff --git a/src/pyobo/cli/lookup.py b/src/pyobo/cli/lookup.py index 121f06c9..8dfb8c40 100644 --- a/src/pyobo/cli/lookup.py +++ b/src/pyobo/cli/lookup.py @@ -213,7 +213,7 @@ def relations( else: echo_df(relations_df) else: - relation_reference = Reference.from_curie(relation, strict=False) + relation_reference = Reference.from_curie_or_uri(relation, strict=False) if relation_reference is None: click.secho(f"not a valid curie: {relation}", fg="red") raise sys.exit(1) diff --git a/src/pyobo/reader.py b/src/pyobo/reader.py index c15dfb44..ddfe10f3 100644 --- a/src/pyobo/reader.py +++ b/src/pyobo/reader.py @@ -113,20 +113,6 @@ def from_obonet(graph: nx.MultiDiGraph, *, strict: bool = True) -> Obo: f"[{ontology_prefix}] will not accept slash in data version: {data_version}" ) - #: Parsed CURIEs to references (even external ones) - reference_it = ( - Reference( - prefix=prefix, - identifier=bioregistry.standardize_identifier(prefix, identifier), - # if name isn't available, it means its external to this ontology - name=data.get("name"), - ) - for prefix, identifier, data in _iter_obo_graph(graph=graph, strict=strict) - ) - references: Mapping[ReferenceTuple, Reference] = { - reference.pair: reference for reference in reference_it - } - #: CURIEs to typedefs typedefs: Mapping[ReferenceTuple, TypeDef] = { typedef.pair: typedef @@ -143,14 +129,22 @@ def from_obonet(graph: nx.MultiDiGraph, *, strict: bool = True) -> Obo: missing_typedefs: set[ReferenceTuple] = set() terms = [] n_alt_ids, n_parents, n_synonyms, n_relations, n_properties, n_xrefs = 0, 0, 0, 0, 0, 0 - for prefix, identifier, data in _iter_obo_graph(graph=graph, strict=strict): - if prefix != ontology_prefix or not data: + n_references = 0 + for reference, data in _iter_obo_graph( + graph=graph, strict=strict, ontology_prefix=ontology_prefix + ): + if reference.prefix != ontology_prefix or not data: continue + n_references += 1 - identifier = bioregistry.standardize_identifier(prefix, identifier) - reference = references[ReferenceTuple(ontology_prefix, identifier)] - - node_xrefs = list(iterate_node_xrefs(prefix=prefix, data=data, strict=strict)) + node_xrefs = list( + iterate_node_xrefs( + data=data, + strict=strict, + ontology_prefix=ontology_prefix, + node=reference, + ) + ) xrefs, provenance = [], [] for node_xref in node_xrefs: if node_xref.prefix in PROVENANCE_PREFIXES: @@ -159,10 +153,16 @@ def from_obonet(graph: nx.MultiDiGraph, *, strict: bool = True) -> Obo: xrefs.append(node_xref) n_xrefs += len(xrefs) - definition, definition_references = get_definition(data, node=reference) + definition, definition_references = get_definition( + data, node=reference, strict=strict, ontology_prefix=ontology_prefix + ) provenance.extend(definition_references) - alt_ids = list(iterate_node_alt_ids(data, strict=strict)) + alt_ids = list( + iterate_node_alt_ids( + data, node=reference, strict=strict, ontology_prefix=ontology_prefix + ) + ) n_alt_ids += len(alt_ids) parents = list( @@ -173,7 +173,13 @@ def from_obonet(graph: nx.MultiDiGraph, *, strict: bool = True) -> Obo: n_parents += len(parents) synonyms = list( - iterate_node_synonyms(data, synonym_typedefs, node=reference, strict=strict) + iterate_node_synonyms( + data, + synonym_typedefs, + node=reference, + strict=strict, + ontology_prefix=ontology_prefix, + ) ) n_synonyms += len(synonyms) @@ -221,7 +227,7 @@ def from_obonet(graph: nx.MultiDiGraph, *, strict: bool = True) -> Obo: terms.append(term) logger.info( - f"[{ontology_prefix}] got {len(references):,} references, {len(typedefs):,} typedefs, {len(terms):,} terms," + f"[{ontology_prefix}] got {n_references:,} references, {len(typedefs):,} typedefs, {len(terms):,} terms," f" {n_alt_ids:,} alt ids, {n_parents:,} parents, {n_synonyms:,} synonyms, {n_xrefs:,} xrefs," f" {n_relations:,} relations, and {n_properties:,} properties", ) @@ -257,13 +263,15 @@ def _iter_obo_graph( graph: nx.MultiDiGraph, *, strict: bool = True, -) -> Iterable[tuple[str, str, Mapping[str, Any]]]: + ontology_prefix: str | None = None, +) -> Iterable[tuple[Reference, Mapping[str, Any]]]: """Iterate over the nodes in the graph with the prefix stripped (if it's there).""" for node, data in graph.nodes(data=True): - prefix, identifier = normalize_curie(node, strict=strict) - if prefix is None or identifier is None: - continue - yield prefix, identifier, data + node = Reference.from_curie_or_uri( + node, strict=strict, ontology_prefix=ontology_prefix, name=data.get("name") + ) + if node: + yield node, data def _get_date(graph, ontology_prefix: str) -> datetime | None: @@ -301,7 +309,7 @@ def iterate_graph_synonym_typedefs( # assume it's a default reference yield SynonymTypeDef(reference=default_reference(ontology_prefix, sid, name=name)) else: - reference = Reference.from_curie( + reference = Reference.from_curie_or_uri( sid, name=name, strict=strict, ontology_prefix=ontology_prefix ) if reference is not None: @@ -329,7 +337,9 @@ def iterate_graph_typedefs( logger.debug("[%s] typedef %s is missing a name", graph.graph["ontology"], curie) if ":" in curie: - reference = Reference.from_curie(curie, name=name, strict=strict) + reference = Reference.from_curie_or_uri( + curie, name=name, strict=strict, ontology_prefix=ontology_prefix + ) else: reference = default_reference(ontology_prefix, curie, name=name) if reference is None: @@ -338,18 +348,24 @@ def iterate_graph_typedefs( xrefs = [] for curie in typedef.get("xref", []): - _xref = Reference.from_curie(curie, strict=strict) + _xref = Reference.from_curie_or_uri( + curie, strict=strict, ontology_prefix=ontology_prefix + ) if _xref: xrefs.append(_xref) yield TypeDef(reference=reference, xrefs=xrefs) -def get_definition(data, *, node: Reference) -> tuple[None | str, list[Reference]]: +def get_definition( + data, *, node: Reference, ontology_prefix: str | None, strict: bool = True +) -> tuple[None | str, list[Reference]]: """Extract the definition from the data.""" definition = data.get("def") # it's allowed not to have a definition if not definition: return None, [] - return _extract_definition(definition, node=node) + return _extract_definition( + definition, node=node, strict=strict, ontology_prefix=ontology_prefix + ) def _extract_definition( @@ -357,6 +373,7 @@ def _extract_definition( *, node: Reference, strict: bool = False, + ontology_prefix: str | None, ) -> tuple[None | str, list[Reference]]: """Extract the definitions.""" if not s.startswith('"'): @@ -375,7 +392,9 @@ def _extract_definition( ) provenance = [] else: - provenance = _parse_trailing_ref_list(rest, strict=strict, node=node) + provenance = _parse_trailing_ref_list( + rest, strict=strict, node=node, ontology_prefix=ontology_prefix + ) return definition or None, provenance @@ -414,6 +433,7 @@ def _extract_synonym( *, node: Reference, strict: bool = True, + ontology_prefix: str | None, ) -> Synonym | None: # TODO check if the synonym is written like a CURIE... it shouldn't but I've seen it happen try: @@ -451,7 +471,9 @@ def _extract_synonym( if not rest.startswith("[") or not rest.endswith("]"): provenance = [] else: - provenance = _parse_trailing_ref_list(rest, strict=strict, node=node) + provenance = _parse_trailing_ref_list( + rest, strict=strict, node=node, ontology_prefix=ontology_prefix + ) return Synonym( name=name, specificity=specificity or "EXACT", @@ -460,10 +482,14 @@ def _extract_synonym( ) -def _parse_trailing_ref_list(rest, *, strict: bool = True, node: Reference): +def _parse_trailing_ref_list( + rest, *, strict: bool = True, node: Reference, ontology_prefix: str | None +): rest = rest.lstrip("[").rstrip("]") return [ - Reference.from_curie(curie.strip(), strict=strict, node=node) + Reference.from_curie_or_uri( + curie.strip(), strict=strict, node=node, ontology_prefix=ontology_prefix + ) for curie in rest.split(",") if curie.strip() ] @@ -475,6 +501,7 @@ def iterate_node_synonyms( *, node: Reference, strict: bool = False, + ontology_prefix: str | None, ) -> Iterable[Synonym]: """Extract synonyms from a :mod:`obonet` node's data. @@ -485,7 +512,9 @@ def iterate_node_synonyms( - "LTEC I" [] """ for s in data.get("synonym", []): - s = _extract_synonym(s, synonym_typedefs, node=node, strict=strict) + s = _extract_synonym( + s, synonym_typedefs, node=node, strict=strict, ontology_prefix=ontology_prefix + ) if s is not None: yield s @@ -524,7 +553,7 @@ def _handle_prop( # if the value doesn't start with a quote, we're going to # assume that it's a reference if not value_type.startswith('"'): - obj_reference = Reference.from_curie( + obj_reference = Reference.from_curie_or_uri( value_type, strict=strict, ontology_prefix=ontology_prefix, node=node ) if obj_reference is None: @@ -549,7 +578,7 @@ def _handle_prop( if not datatype: return LiteralProperty(prop_reference, value, Reference(prefix="xsd", identifier="string")) - datatype_reference = Reference.from_curie( + datatype_reference = Reference.from_curie_or_uri( datatype, strict=strict, ontology_prefix=ontology_prefix, node=node ) if datatype_reference is None: @@ -577,7 +606,9 @@ def _get_prop( elif ":" not in prop: return default_reference(ontology_prefix, prop) else: - return Reference.from_curie(prop, strict=strict, node=node, ontology_prefix=ontology_prefix) + return Reference.from_curie_or_uri( + prop, strict=strict, node=node, ontology_prefix=ontology_prefix + ) def iterate_node_parents( @@ -589,7 +620,7 @@ def iterate_node_parents( ) -> Iterable[Reference]: """Extract parents from a :mod:`obonet` node's data.""" for parent_curie in data.get("is_a", []): - reference = Reference.from_curie( + reference = Reference.from_curie_or_uri( parent_curie, strict=strict, ontology_prefix=ontology_prefix, node=node ) if reference is None: @@ -598,10 +629,14 @@ def iterate_node_parents( yield reference -def iterate_node_alt_ids(data: Mapping[str, Any], *, strict: bool = True) -> Iterable[Reference]: +def iterate_node_alt_ids( + data: Mapping[str, Any], *, node: Reference, strict: bool = True, ontology_prefix: str | None +) -> Iterable[Reference]: """Extract alternate identifiers from a :mod:`obonet` node's data.""" for curie in data.get("alt_id", []): - reference = Reference.from_curie(curie, strict=strict) + reference = Reference.from_curie_or_uri( + curie, strict=strict, node=node, ontology_prefix=ontology_prefix + ) if reference is not None: yield reference @@ -634,7 +669,7 @@ def iterate_node_relationships( relation.curie, ) - target = Reference.from_curie( + target = Reference.from_curie_or_uri( target_curie, strict=strict, ontology_prefix=ontology_prefix, node=node ) if target is None: @@ -645,7 +680,11 @@ def iterate_node_relationships( def iterate_node_xrefs( - *, prefix: str, data: Mapping[str, Any], strict: bool = True + *, + data: Mapping[str, Any], + strict: bool = True, + ontology_prefix: str | None, + node: Reference, ) -> Iterable[Reference]: """Extract xrefs from a :mod:`obonet` node's data.""" for xref in data.get("xref", []): @@ -654,16 +693,18 @@ def iterate_node_xrefs( if curie_has_blacklisted_prefix(xref) or curie_is_blacklisted(xref) or ":" not in xref: continue # sometimes xref to self... weird - xref = remap_prefix(xref) + xref = remap_prefix(xref, ontology_prefix=ontology_prefix) split_space = " " in xref if split_space: _xref_split = xref.split(" ", 1) if _xref_split[1][0] not in {'"', "("}: - logger.debug("[%s] Problem with space in xref %s", prefix, xref) + logger.debug("[%s] Problem with space in xref %s", node.curie, xref) continue xref = _xref_split[0] - yv = Reference.from_curie(xref, strict=strict) + yv = Reference.from_curie_or_uri( + xref, strict=strict, ontology_prefix=ontology_prefix, node=node + ) if yv is not None: yield yv diff --git a/src/pyobo/sources/complexportal.py b/src/pyobo/sources/complexportal.py index ea74215c..4da56a09 100644 --- a/src/pyobo/sources/complexportal.py +++ b/src/pyobo/sources/complexportal.py @@ -125,7 +125,7 @@ def _parse_xrefs(s) -> list[tuple[Reference, str]]: xref_curie = _clean_intenz(xref_curie) try: - reference = Reference.from_curie(xref_curie) + reference = Reference.from_curie_or_uri(xref_curie) except ValueError: logger.warning("can not parse CURIE: %s", xref_curie) continue diff --git a/src/pyobo/sources/conso.py b/src/pyobo/sources/conso.py index be4e40f6..6ef8d0b2 100644 --- a/src/pyobo/sources/conso.py +++ b/src/pyobo/sources/conso.py @@ -42,7 +42,7 @@ def iter_terms() -> Iterable[Term]: synonyms_df = ensure_df(PREFIX, url=SYNONYMS_URL) synonyms_df["reference"] = synonyms_df["reference"].map( - lambda s: [Reference.from_curie(s)] if pd.notna(s) and s != "?" else [], + lambda s: [Reference.from_curie_or_uri(s)] if pd.notna(s) and s != "?" else [], ) synonyms_df["specificity"] = synonyms_df["specificity"].map( lambda s: "EXACT" if pd.isna(s) or s == "?" else s @@ -71,7 +71,7 @@ def iter_terms() -> Iterable[Term]: curie = curie.strip() if not curie: continue - reference = Reference.from_curie(curie) + reference = Reference.from_curie_or_uri(curie) if reference is not None: provenance.append(reference) identifier = row["Identifier"] diff --git a/src/pyobo/sources/famplex.py b/src/pyobo/sources/famplex.py index 47f542a5..083f38e0 100644 --- a/src/pyobo/sources/famplex.py +++ b/src/pyobo/sources/famplex.py @@ -107,7 +107,7 @@ def get_terms(version: str, force: bool = False) -> Iterable[Term]: reference = Reference(prefix=PREFIX, identifier=entity, name=entity) definition, provenance = id_to_definition.get(entity, (None, None)) provenance_reference = ( - Reference.from_curie(provenance) if isinstance(provenance, str) else None + Reference.from_curie_or_uri(provenance) if isinstance(provenance, str) else None ) term = Term( reference=reference, diff --git a/src/pyobo/sources/flybase.py b/src/pyobo/sources/flybase.py index ab766925..dd3b0c7a 100644 --- a/src/pyobo/sources/flybase.py +++ b/src/pyobo/sources/flybase.py @@ -154,7 +154,7 @@ def get_terms(version: str, force: bool = False) -> Iterable[Term]: for hgnc_curie in human_orthologs.get(identifier, []): if not hgnc_curie or pd.isna(hgnc_curie): continue - hgnc_ortholog = Reference.from_curie(hgnc_curie) + hgnc_ortholog = Reference.from_curie_or_uri(hgnc_curie) if hgnc_ortholog is None: tqdm.write(f"[{PREFIX}] {identifier} had invalid ortholog: {hgnc_curie}") else: diff --git a/src/pyobo/sources/uniprot/uniprot.py b/src/pyobo/sources/uniprot/uniprot.py index 8a870eb6..b2d710c9 100644 --- a/src/pyobo/sources/uniprot/uniprot.py +++ b/src/pyobo/sources/uniprot/uniprot.py @@ -126,7 +126,7 @@ def iter_terms(version: str | None = None) -> Iterable[Term]: # FIXME this needs a different relation than enables # see https://github.com/biopragmatics/pyobo/pull/168#issuecomment-1918680152 enables, - cast(Reference, Reference.from_curie(rhea_curie, strict=True)), + cast(Reference, Reference.from_curie_or_uri(rhea_curie, strict=True)), ) if bindings: @@ -136,7 +136,7 @@ def iter_terms(version: str | None = None) -> Iterable[Term]: if part.startswith("/ligand_id"): curie = part.removeprefix('/ligand_id="').rstrip('"') binding_references.add( - cast(Reference, Reference.from_curie(curie, strict=True)) + cast(Reference, Reference.from_curie_or_uri(curie, strict=True)) ) for binding_reference in sorted(binding_references): term.annotate_object(molecularly_interacts_with, binding_reference) diff --git a/src/pyobo/sources/uniprot/uniprot_ptm.py b/src/pyobo/sources/uniprot/uniprot_ptm.py index 1a71a895..28f8be35 100644 --- a/src/pyobo/sources/uniprot/uniprot_ptm.py +++ b/src/pyobo/sources/uniprot/uniprot_ptm.py @@ -96,7 +96,7 @@ def _parse(i, lines: Iterable[tuple[str, str]]) -> Term | None: if line.startswith(y): line = x + line[len(y) :] - ref = Reference.from_curie(line.replace("; ", ":")) + ref = Reference.from_curie_or_uri(line.replace("; ", ":")) if ref: term.append_xref(ref) else: diff --git a/src/pyobo/sources/zfin.py b/src/pyobo/sources/zfin.py index 17d4ed68..1e23d731 100644 --- a/src/pyobo/sources/zfin.py +++ b/src/pyobo/sources/zfin.py @@ -150,7 +150,7 @@ def get_terms(force: bool = False, version: str | None = None) -> Iterable[Term] for hgnc_id in human_orthologs.get(identifier, []): term.append_relationship(orthologous, Reference(prefix="hgnc", identifier=hgnc_id)) for mgi_curie in mouse_orthologs.get(identifier, []): - mouse_ortholog = Reference.from_curie(mgi_curie) + mouse_ortholog = Reference.from_curie_or_uri(mgi_curie) if mouse_ortholog: term.append_relationship(orthologous, mouse_ortholog) for flybase_id in fly_orthologs.get(identifier, []): diff --git a/src/pyobo/struct/reference.py b/src/pyobo/struct/reference.py index a9956f08..75bf9a96 100644 --- a/src/pyobo/struct/reference.py +++ b/src/pyobo/struct/reference.py @@ -73,7 +73,7 @@ def bioregistry_link(self) -> str: return f"https://bioregistry.io/{self.curie}" @classmethod - def from_curie( # type:ignore[override] + def from_curie_or_uri( cls, curie: str, name: str | None = None, @@ -95,6 +95,9 @@ def from_curie( # type:ignore[override] ) if prefix is None or identifier is None: return None + + identifier = bioregistry.standardize_identifier(prefix, identifier) + if name is None and auto: from ..api import get_name diff --git a/src/pyobo/struct/struct.py b/src/pyobo/struct/struct.py index fd22e59c..760c9529 100644 --- a/src/pyobo/struct/struct.py +++ b/src/pyobo/struct/struct.py @@ -190,7 +190,7 @@ def _ensure_ref( if not ontology_prefix: raise ValueError(f"can't parse reference: {reference}") return default_reference(ontology_prefix, reference) - _rv = Reference.from_curie(reference, strict=True, ontology_prefix=ontology_prefix) + _rv = Reference.from_curie_or_uri(reference, strict=True, ontology_prefix=ontology_prefix) if _rv is None: raise ValueError(f"[{ontology_prefix}] unable to parse {reference}") return _rv @@ -295,14 +295,6 @@ def auto( definition=get_definition(prefix, identifier), ) - @classmethod - def from_curie(cls, curie: str, name: str | None = None) -> Term: - """Create a term directly from a CURIE and optional name.""" - reference = Reference.from_curie(curie, name=name, strict=True) - if reference is None: - raise RuntimeError - return cls(reference=reference) - def append_provenance(self, reference: ReferenceHint) -> None: """Add a provenance reference.""" self.provenance.append(_ensure_ref(reference)) diff --git a/src/pyobo/struct/typedef.py b/src/pyobo/struct/typedef.py index d556fa8c..f301d918 100644 --- a/src/pyobo/struct/typedef.py +++ b/src/pyobo/struct/typedef.py @@ -136,18 +136,6 @@ def from_triple(cls, prefix: str, identifier: str, name: str | None = None) -> T """Create a typedef from a reference.""" return cls(reference=Reference(prefix=prefix, identifier=identifier, name=name)) - @classmethod - def from_curie( - cls, curie: str, *, name: str | None = None, ontology_prefix: str | None = None - ) -> TypeDef: - """Create a TypeDef directly from a CURIE and optional name.""" - reference = Reference.from_curie( - curie, name=name, strict=True, ontology_prefix=ontology_prefix - ) - if reference is None: - raise RuntimeError - return cls(reference=reference) - @classmethod def default(cls, prefix: str, identifier: str, *, name: str | None = None) -> Self: """Construct a default type definition from within the OBO namespace.""" @@ -329,7 +317,9 @@ def default(cls, prefix: str, identifier: str, *, name: str | None = None) -> Se definition_source = TypeDef.from_triple( prefix=IAO_PREFIX, identifier="0000119", name="definition source" ) -has_dbxref = TypeDef.from_curie("oboInOwl:hasDbXref", name="has database cross-reference") +has_dbxref = TypeDef.from_triple( + prefix="oboInOwl", identifier="hasDbXref", name="has database cross-reference" +) editor_note = TypeDef.from_triple(prefix=IAO_PREFIX, identifier="0000116", name="editor note") diff --git a/tests/test_get.py b/tests/test_get.py index 2bcb615a..2a49eeee 100644 --- a/tests/test_get.py +++ b/tests/test_get.py @@ -85,7 +85,7 @@ def test_extract_definition(self): ]: with self.subTest(s=s): actual_text, actual_references = _extract_definition( - s, node=Reference(prefix="chebi", identifier="XXX") + s, node=Reference(prefix="chebi", identifier="XXX"), ontology_prefix="chebi" ) self.assertEqual(expected_text, actual_text) self.assertEqual(expected_references, actual_references) @@ -95,7 +95,10 @@ def test_extract_definition_with_escapes(self): expected_text = """The canonical 3' splice site has the sequence "AG".""" s = """"The canonical 3' splice site has the sequence \\"AG\\"." [PMID:1234]""" actual_text, actual_references = _extract_definition( - s, strict=True, node=Reference(prefix="chebi", identifier="XXX") + s, + strict=True, + node=Reference(prefix="chebi", identifier="XXX"), + ontology_prefix="chebi", ) self.assertEqual(expected_text, actual_text) self.assertEqual([Reference(prefix="pubmed", identifier="1234")], actual_references) @@ -159,7 +162,10 @@ def test_extract_synonym(self): ]: with self.subTest(s=text): actual_synonym = _extract_synonym( - text, synoynym_typedefs, node=Reference(prefix="chebi", identifier="XXX") + text, + synoynym_typedefs, + node=Reference(prefix="chebi", identifier="XXX"), + ontology_prefix="chebi", ) self.assertIsInstance(actual_synonym, Synonym) self.assertEqual(expected_synonym, actual_synonym) @@ -175,7 +181,10 @@ def test_get_node_synonyms(self): data = self.graph.nodes["CHEBI:51990"] synonyms = list( iterate_node_synonyms( - data, synoynym_typedefs, node=Reference(prefix="chebi", identifier="XXX") + data, + synoynym_typedefs, + node=Reference(prefix="chebi", identifier="XXX"), + ontology_prefix="chebi", ) ) self.assertEqual(1, len(synonyms)) @@ -215,7 +224,13 @@ def test_get_node_parents(self): def test_get_node_xrefs(self): """Test getting parents from a node in a :mod:`obonet` graph.""" data = self.graph.nodes["CHEBI:51990"] - xrefs = list(iterate_node_xrefs(prefix="chebi", data=data)) + xrefs = list( + iterate_node_xrefs( + data=data, + ontology_prefix="chebi", + node=Reference(prefix="chebi", identifier="51990"), + ) + ) self.assertEqual(7, len(xrefs)) # NOTE the prefixes are remapped by Bioregistry self.assertEqual({"pubmed", "cas", "reaxys"}, {xref.prefix for xref in xrefs}) @@ -290,12 +305,14 @@ def test_typedefs(self): def test_iter_filtered_relations(self): """Test getting filtered relations w/ upgrade.""" - curie = "obo:chebi#is_conjugate_base_of" + term_reference = Reference(prefix="chebi", identifier="17051") + reference = default_reference("chebi", "is_conjugate_base_of") + object_reference = Reference(prefix="chebi", identifier="29228") for inp in [ - curie, - ReferenceTuple.from_curie(curie), - Reference.from_curie(curie), - TypeDef.from_curie(curie), + reference.curie, + reference, + reference.pair, + TypeDef(reference=reference), ]: with self.subTest(inp=inp): rr = multidict( @@ -303,6 +320,5 @@ def test_iter_filtered_relations(self): for term, target in self.ontology.iterate_filtered_relations(inp) ) self.assertNotEqual(0, len(rr)) - term = Reference.from_curie("chebi:17051") - self.assertIn(term, rr) - self.assertIn(Reference.from_curie("chebi:29228"), rr[term]) + self.assertIn(term_reference, rr) + self.assertIn(object_reference, rr[term_reference]) diff --git a/tests/test_reader.py b/tests/test_reader.py index 8a19ab9e..7d3cc341 100644 --- a/tests/test_reader.py +++ b/tests/test_reader.py @@ -390,7 +390,7 @@ def test_property_literal_url(self) -> None: id: CHEBI:1234 property_value: https://w3id.org/biolink/vocab/something CHEBI:5678 """) - td = TypeDef.from_curie("biolink:something") + td = TypeDef.from_triple(prefix="biolink", identifier="something") term = self.get_only_term(ontology) self.assertEqual(0, len(list(term.annotations_literal))) self.assertEqual(1, len(list(term.annotations_object))) diff --git a/tests/test_struct.py b/tests/test_struct.py index 233dd10e..78161115 100644 --- a/tests/test_struct.py +++ b/tests/test_struct.py @@ -12,7 +12,7 @@ LYSINE_DEHYDROGENASE_ACT = Reference( prefix="GO", identifier="0050069", name="lysine dehydrogenase activity" ) -RO_DUMMY = TypeDef(reference=Reference.from_curie("RO:1234567")) +RO_DUMMY = TypeDef(reference=Reference(prefix="RO", identifier="1234567")) CHARLIE = Reference(prefix="orcid", identifier="0000-0003-4423-4370")