keep_subject_prefixes

keep_subject_prefixes(mappings: Iterable[Mapping], prefixes: str | Iterable[str], *, progress: bool = True) list[Mapping][source]

Filter out mappings whose subjects are not in the given list of prefixes.

Parameters:
  • mappings – A list of mappings

  • prefixes – A set of prefixes to use for filtering the mappings’ subjects

  • progress – Should a progress bar be shown? Defaults to true.

Returns:

A subset of the original mappings whose subjects are in the given prefix list

>>> from semra import DB_XREF, EXACT_MATCH, Reference
>>> curies = "DOID:0050577", "mesh:C562966", "umls:C4551571"
>>> r1, r2, r3 = (Reference.from_curie(c) for c in curies)
>>> m1 = Mapping.from_triple((r1, DB_XREF, r2))
>>> m2 = Mapping.from_triple((r2, DB_XREF, r3))
>>> m3 = Mapping.from_triple((r1, DB_XREF, r3))
>>> assert keep_subject_prefixes([m1, m2, m3], {"DOID"})