TCT.translator_query

TCT.translator_query.build_attribute_constraint(attribute_id, operator, value, name=None, is_not=False)[source]

This creates an attribute constraint for a TRAPI query dict.

TCT.translator_query.format_query_json(subject_ids: list[str], object_ids: list[str] | None = None, subject_categories: list[str] | None = None, object_categories: list[str] | None = None, predicates: list[str] | None = None, attribute_constraints: list[dict] | None = None) dict[source]

Formats a query dict, with optional constraints.

Example input: subject_ids = [“NCBIGene:3845”] object_ids = [] subject_categories = [“biolink:Gene”] object_categories = [“biolink:Gene”] predicates = [“biolink:positively_correlated_with”, “biolink:physically_interacts_with”] attribute_constraints = [build_attribute_constraint(‘biolink:has_total’, ‘>’, 2)]

TCT.translator_query.get_translator_API_predicates() tuple[dict, DataFrame, dict][source]

Get the predicates supported by each API.

Returns:
API_namesdict[str, str]

dict of API names to URLs

metaKGpandas.DataFrame

This is a dataframe that represents the meta KG for the KPs in the APInames input - columns include [TODO].

API_predicatesdict[str, list]

A dictionary of API names and a list of their predicates.

Examples

>>> API_names, metaKG, API_predicates = get_translator_API_predicates()
TCT.translator_query.optimize_query_json(query_json, API_name_cur, API_predicates)[source]

Optimize the query JSON by removing predicates that are not supported by the selected APIs.

Parameters:
query_json1str

a query in TRAPI 1.5.0 format

API_name_curstr

the name of the API to query

API_predicatesdict

a dictionary of API names and their predicates

Returns:
A modified query JSON with only the predicates supported by the selected APIs.

Examples

>>> 
TCT.translator_query.parallel_api_query(query_json, select_APIs, APInames, API_predicates, max_workers=1)[source]

Queries multiple APIs in parallel and merges the results into a single knowledge graph.

Parameters:
URLS

list of API URLs to query

query_json

the query JSON to be sent to each API

max_workers

number of parallel workers to use for querying

Returns:
Returns a merged knowledge graph from all successful API responses.

Examples

>>> result = TCT.parallel_api_query(API_URLs,query_json=query_json, max_workers=len(API_URLs1))
TCT.translator_query.query_KP(API_name_cur, query_json, APInames, API_predicates)[source]

Query an individual API with a TRAPI 1.5.0 query JSON, without modifying the original query_json.