metakb.services.search#
Provide search services.
- exception metakb.services.search.EmptySearchError[source]#
Raise for invalid search parameters (e.g. no parameters given)
- exception metakb.services.search.PaginationParamError[source]#
Raise for invalid pagination parameters.
- async metakb.services.search.batch_search_statements(repository, normalizer, variations=None, start=0, limit=None)[source]#
Fetch all statements associated with any of the provided variation description strings.
Because this method could be expanded to include other kinds of search terms,
variationsis optionally nullable.>>> from metakb.repository.neo4j_repository import get_driver, Neo4jRepository >>> from metakb.normalizers import ViccNormalizers >>> from metakb.services.search import batch_search_statements >>> repo, normalizer = Neo4jRepository(get_driver()), ViccNormalizers() >>> response = await batch_search_statements(repo, normalizer, ["EGFR L858R"])
All terms are normalized, so redundant terms don’t alter search results.
>>> redundant_response = await batch_search_statements( ... repo, normalizer, ["EGFR L858R", "NP_005219.2:p.Leu858Arg"] ... ) >>> len(response.statement_ids) == len(redundant_response.statement_ids) True
- Parameters:
repository (
AbstractRepository) –normalizer (
ViccNormalizers) –variations (
Optional[list[str]]) – a list of variation description strings, e.g.["BRAF V600E"]start (
int) – Index of first result to fetch. Must be nonnegative.limit (
Optional[int]) – Max number of results to fetch. Must be nonnegative. Revert to default defined at class initialization if not given.
- Return type:
- Returns:
response object including all matching statements
- Raises:
ValueError – if
startorlimitare nonnegativeEmptySearchError – if no search params given
PaginationParamError – if either pagination param given is negative
- async metakb.services.search.search_statements(repository, normalizer, variation=None, disease=None, therapy=None, gene=None, statement_id=None, start=0, limit=None)[source]#
Get nested statements from queried concepts that match all conditions provided. For example, if
variationandtherapyare provided, will return all statements that have both the providedvariationandtherapy.>>> from metakb.repository.neo4j_repository import get_driver, Neo4jRepository >>> from metakb.normalizers import ViccNormalizers >>> from metakb.services.search import search_statements >>> repo, normalizer = Neo4jRepository(get_driver()), ViccNormalizers() >>> result = search_statements(repo, normalizer, variation="BRAF V600E") >>> result.statements[0].reportedIn[0].urls[0] 'https://www.accessdata.fda.gov/drugsatfda_docs/label/2020/202429s019lbl.pdf'
Variation, disease, therapy, and gene terms are resolved via their respective concept normalization services.
- Parameters:
repository (
AbstractRepository) – data repository instancenormalizer (
ViccNormalizers) – normalizers container instancevariation (
Optional[str]) – Variation query. Free text variation description, e.g."BRAF V600E", or GA4GH variation ID, e.g."ga4gh:VA.4XBXAxSAk-WyAu5H0S1-plrk_SCTW1PO". Case-insensitive.disease (
Optional[str]) – Disease query. Full disease name, e.g."glioblastoma", common shorthand name, e.g."GBM", concept URI, e.g."ncit:C3058". Case-insensitive.therapy (
Optional[str]) – Therapy query. Full name, e.g."imatinib", trade name, e.g."GLEEVEC", or concept URI, e.g."chembl:CHEMBL941". Case-insensitive.gene (
Optional[str]) – Gene query. Common shorthand name, e.g."NTRK1", or compact URI, e.g."ensembl:ENSG00000198400".statement_id (
Optional[str]) – Statement ID query provided by source, e.g."civic.eid:3017".start (
int) – Index of first result to fetch. Must be nonnegative.limit (
Optional[int]) – Max number of results to fetch. Must be nonnegative. Revert to default defined at class initialization if not given.
- Return type:
- Returns:
Results including terms with normalization, and all statements
- Raises:
EmptySearchError – if no search params given
PaginationParamError – if either pagination param given is negative