TCT utility functions¶
- class TCT.TCT.FinderResult(query: dict[str, Any], knowledge_graph: dict[str, Any], results: list[dict[str, Any]], auxiliary_graphs: dict[str, Any], resolved_nodes: dict[str, ResolvedNode], raw: dict[str, Any])[source]¶
Convenience wrapper around a parsed TRAPI-style finder response.
Methods
to_dict()Return the raw parsed TRAPI-style output dictionary.
- TCT.TCT.ID_convert_to_preferred_name_nodeNormalizer(id_list)[source]¶
Convert a list of CURIEs to their preferred names using NodeNorm. Arg:
id_list: list of CURIEs to be converted
- Returns:
dic_id_map: dictionary mapping CURIEs to their preferred names
- Example:
dic_id_map = ID_convert_to_preferred_name_nodeNormalizer([“NCBIGene:1234”, “NCBIGene:5678”])
- class TCT.TCT.ResolvedNode(input_value: str, curie: str, label: str | None, categories: list[str])[source]¶
Resolved node metadata used by the finder APIs.
- class TCT.TCT.TranslatorResources(api_names: dict[str, str], meta_kg: DataFrame, api_predicates: dict[str, list[str]])[source]¶
Translator API metadata required by the finder query functions.
- TCT.TCT.clear_translator_resource_cache() None[source]¶
Clear the in-memory Translator resource singleton.
Examples
>>> clear_translator_resource_cache() >>> resources = get_translator_resources() # refetches
- TCT.TCT.format_query_json(subject_ids, object_ids, subject_categories, object_categories, predicates)[source]¶
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”]
- TCT.TCT.get_SmartAPI_Translator_KP_info()[source]¶
Get the SmartAPI Translator KP info from the smart-api.info API. Returns a DataFrame with the SmartAPI Translator KP info.
Examples
>>> Translator_KP_info,APInames = get_SmartAPI_Translator_KP_info('AML')
- TCT.TCT.get_Translator_APIs()[source]¶
Get a list of Translator APIs from the smart-api.info and return the detailed information for each API in a data frame and the list of API names.
Examples
>>> Translator_KP_info,APInames= TCT.get_SmartAPI_Translator_KP_info()
- TCT.TCT.get_translator_resources(*, refresh: bool = False) TranslatorResources[source]¶
Return cached Translator API metadata, loading it on first use.
- Parameters:
- refreshbool
If true, refetch SmartAPI/MetaKG data even when the singleton is already populated.
- Returns:
- TranslatorResources
API names, MetaKG dataframe, and API predicate mapping used by the finder functions.
Examples
>>> resources = get_translator_resources() >>> paths = query_TCT_pathfinder("asthma", "albuterol", ["Gene"], resources=resources)
- TCT.TCT.neighborhood_finder(node: str | list[str], neighbor_categories: list[str], *, node_categories: list[str] | None = None, api_names: dict[str, str] | None = None, meta_kg: DataFrame | None = None, api_predicates: dict[str, list[str]] | None = None, resources: TranslatorResources | None = None, predicates_subset: list[str] | None = None, attribute_constraints: list[dict[str, Any]] | None = None, name_resolver_kwargs: dict[str, Any] | None = None, node_normalizer_kwargs: dict[str, Any] | None = None) FinderResult[source]¶
Find one-hop neighbors for one or more biomedical concepts.
- Parameters:
- nodestr or list[str]
Source node or nodes. Each value may be a CURIE or human-readable string. Human-readable strings are resolved with Name Resolver and then normalized with Node Normalizer.
- neighbor_categorieslist[str]
Desired neighbor categories. Values may be short names like
"Drug"or full Biolink names like"biolink:Drug".- node_categorieslist[str], optional
Category override for source nodes. If omitted, categories are inferred from the first normalized source node.
- resourcesTranslatorResources, optional
Preloaded Translator resources. If omitted, the module-level singleton is loaded on first use and reused.
- api_names, meta_kg, api_predicatesoptional
Advanced partial overrides for the Translator resources used by the neighborhood implementation.
- predicates_subsetlist[str], optional
Optional predicate filter applied after MetaKG predicate selection.
- attribute_constraintslist[dict], optional
TRAPI attribute constraints passed through to query construction.
- name_resolver_kwargsdict, optional
Extra keyword arguments for
name_resolver.lookup.- node_normalizer_kwargsdict, optional
Extra keyword arguments for
node_normalizer.get_normalized_nodes.
- Returns:
- FinderResult
Convenience wrapper containing resolved input nodes, parsed neighborhood knowledge graph, results, auxiliary graphs, and raw TRAPI-style output.
Examples
>>> from TCT import neighborhood_finder >>> result = neighborhood_finder("asthma", ["SmallMolecule", "Drug"]) >>> result.knowledge_graph["nodes"] {...}
- TCT.TCT.parse_KG(result)[source]¶
subject_object subject object predicate primary_knowledge_sources aggregator_knowledge_sources subject_predicate_object_primary_knowledge_sources_aggregator_knowledge_sources
- TCT.TCT.query_TCT_pathfinder(start: str, end: str, intermediate_categories: list[str], *, start_categories: list[str] | None = None, end_categories: list[str] | None = None, api_names: dict[str, str] | None = None, meta_kg: DataFrame | None = None, api_predicates: dict[str, list[str]] | None = None, resources: TranslatorResources | None = None, scoring_method: str = 'infores', name_resolver_kwargs: dict[str, Any] | None = None, node_normalizer_kwargs: dict[str, Any] | None = None) FinderResult[source]¶
Find paths between two biomedical concepts using Translator KPs.
- Parameters:
- startstr
Start node as either a CURIE (for example,
"MONDO:0004979") or a human-readable string (for example,"asthma").- endstr
End node as either a CURIE or human-readable string.
- intermediate_categorieslist[str]
Allowed categories for intermediate path nodes. Values may be short names like
"Gene"or full Biolink names like"biolink:Gene".- start_categorieslist[str], optional
Category override for the start node. If omitted, categories are inferred from Node Normalizer.
- end_categorieslist[str], optional
Category override for the end node. If omitted, categories are inferred from Node Normalizer.
- resourcesTranslatorResources, optional
Preloaded Translator resources. If omitted, the module-level singleton is loaded on first use and reused.
- api_names, meta_kg, api_predicatesoptional
Advanced partial overrides for the Translator resources used by the pathfinder implementation.
- scoring_methodstr
Scoring method passed to the legacy parser. Current values are
"infores"and"edges".- name_resolver_kwargsdict, optional
Extra keyword arguments for
name_resolver.lookup.- node_normalizer_kwargsdict, optional
Extra keyword arguments for
node_normalizer.get_normalized_nodes.
- Returns:
- FinderResult
Convenience wrapper containing resolved input nodes, the parsed knowledge graph, results, auxiliary graphs, and the raw TRAPI-style output dictionary.
Examples
>>> from TCT import query_TCT_pathfinder >>> result = query_TCT_pathfinder("asthma", "albuterol", ["Gene"]) >>> result.resolved_nodes["start"].curie 'MONDO:0004979'
- TCT.TCT.rank_by_primary_infores_input_as_list(result_parsed, input_nodes)[source]¶
Editd Dec 5, 2023
- TCT.TCT.sele_predicates_API(input_node1_category, input_node2_category, metaKG, APInames)[source]¶
Selects predicates, APIs, and API URLs for the given input node categories.
- TCT.TCT.select_API(sub_list, obj_list, metaKG)[source]¶
selects the APIs that can connect the given subject and object categories in the meta knowledge graph.
sub_list = [“biolink:Gene”, “biolink:Protein”] obj_list = [“biolink:Gene”, “biolink:Disease”]
>>> obj_list = ["biolink:Gene", "biolink:Disease"] >>> >>> Translator_KP_info,APInames= translator_kpinfo.get_translator_kp_info() >>> print(len(Translator_KP_info)) >>> metaKG = translator_metakg.get_KP_metadata(APInames) >>> print(metaKG.shape) >>> APInames,metaKG = translator_metakg.add_plover_API(APInames, metaKG) >>> selected_apis = select_API(sub_list, obj_list, metaKG) >>> print(selected_apis)