parse_curie

parse_curie(curie: str, *, sep: str = ':', use_preferred: bool = False, on_failure_return_type: FailureReturnType = FailureReturnType.pair, strict: Literal[True] = True) ReferenceTuple[source]
parse_curie(curie: str, *, sep: str = ':', use_preferred: bool = False, on_failure_return_type: Literal[FailureReturnType.single], strict: Literal[False] = False) ReferenceTuple | None
parse_curie(curie: str, *, sep: str = ':', use_preferred: bool = False, on_failure_return_type: Literal[FailureReturnType.pair] = FailureReturnType.pair, strict: Literal[False] = False) ReferenceTuple | tuple[None, None]

Parse a CURIE, normalizing the prefix and identifier if necessary.

Parameters:
  • curie – A compact URI (CURIE) in the form of <prefix:identifier>

  • sep – The separator for the CURIE. Defaults to the colon “:” however the slash “/” is sometimes used in Identifiers.org and the underscore “_” is used for OBO PURLs.

  • use_preferred – If set to true, uses the “preferred prefix”, if available, instead of the canonicalized Bioregistry prefix.

  • on_failure_return_type – whether to return a single None or a pair of None’s

Returns:

A tuple of the prefix, identifier, if parsable

Raises:

TypeError – If an invalid on_failure_return_type is given

The algorithm for parsing a CURIE is very simple: it splits the string on the leftmost occurrence of the separator (usually a colon “:” unless specified otherwise). The left part is the prefix, and the right part is the identifier.

>>> parse_curie("pdb:1234")
ReferenceTuple('pdb', '1234')

Address banana problem >>> parse_curie(”go:GO:1234”) ReferenceTuple(‘go’, ‘1234’) >>> parse_curie(”go:go:1234”) ReferenceTuple(‘go’, ‘1234’) >>> parse_curie(”go:1234”) ReferenceTuple(‘go’, ‘1234’)

Address banana problem with OBO banana >>> parse_curie(“fbbt:FBbt:1234”) ReferenceTuple(‘fbbt’, ‘1234’) >>> parse_curie(“fbbt:fbbt:1234”) ReferenceTuple(‘fbbt’, ‘1234’) >>> parse_curie(“fbbt:1234”) ReferenceTuple(‘fbbt’, ‘1234’)

Address banana problem with explit banana >>> parse_curie(“go.ref:GO_REF:1234”) ReferenceTuple(‘go.ref’, ‘1234’) >>> parse_curie(“go.ref:1234”) ReferenceTuple(‘go.ref’, ‘1234’)

Parse OBO PURL curies >>> parse_curie(“GO_1234”, sep=”_”) ReferenceTuple(‘go’, ‘1234’)

Banana with no peel: >>> parse_curie(“omim.ps:PS12345”) ReferenceTuple(‘omim.ps’, ‘12345’)

Use preferred (available) >>> parse_curie(“GO_1234”, sep=”_”, use_preferred=True) ReferenceTuple(‘GO’, ‘1234’)

Use preferred (unavailable) >>> parse_curie(“pdb:1234”, use_preferred=True) ReferenceTuple(‘pdb’, ‘1234’)