diff --git a/TCT/TCT_neighborhood_finder.py b/TCT/TCT_neighborhood_finder.py index bdef854..31c0fc2 100644 --- a/TCT/TCT_neighborhood_finder.py +++ b/TCT/TCT_neighborhood_finder.py @@ -195,41 +195,39 @@ def neighborhood_finder(input_node, node2_categories, APInames, metaKG, API_pred Parameters ---------- - input_node (str) + input_node : str The input node - should be a CURIE id. - node2_categories (list) + node2_categories : list A list of intermediate categories to be used in the neighborhood finding process. - APInames (dict) + APInames : dict A dictionary containing the names of the APIs to be used. - metaKG (DataFrame) + metaKG : DataFrame The metadata knowledge graph containing information about the APIs and their predicates. - API_predicates (dict) + API_predicates : dict A dictionary containing the predicates for each API. - input_node_category (list) + input_node_category : list Optional. A list of categories for the input node. If empty, it will be derived from the input node's types. - attribute_constraints (list) + attribute_constraints : list Optional. List of outputs of translator_query.build_attribute_constraint Returns - -------------- - input_node_id (str) + ------- + input_node_id : str The curie id of the input node. - result (dict) + result : dict The result of the query for the input node. - result_parsed (DataFrame) + result_parsed : DataFrame The parsed results for the input node. - result_ranked_by_primary_infores (DataFrame) + result_ranked_by_primary_infores : DataFrame The ranked results based on primary infores. - -------------- - Example: + Examples + -------- >>> input_node_id, result, result_parsed, result_ranked_by_primary_infores1 = neighborhood_finder('MONDO:0008170', #Ovarian Cancer node2_categories = ['biolink:SmallMolecule', 'biolink:Drug', 'biolink:ChemicalEntity'], APInames = APInames, metaKG = metaKG, API_predicates = API_predicates) - -------------- - """ from . import node_normalizer from . import translator_query @@ -291,23 +289,23 @@ def neighborhood_finder_multiple_inputs(input_nodes:list[str], node2_categories: Parameters ---------- - input_nodes (list[str]) + input_nodes : list[str] The input nodes - should be a list of CURIE ids. - node2_categories (list) + node2_categories : list A list of intermediate categories to be used in the neighborhood finding process. - APInames (dict) + APInames : dict A dictionary containing the names of the APIs to be used. - metaKG (DataFrame) + metaKG : DataFrame The metadata knowledge graph containing information about the APIs and their predicates. - API_predicates (dict) + API_predicates : dict A dictionary containing the predicates for each API. - input_node_category (list) + input_node_category : list Optional. A list of categories for the input node. If empty, it will be derived from the input node's types. - attribute_constraints (list) + attribute_constraints : list Optional. List of outputs of translator_query.build_attribute_constraint Returns - -------------- + ------- input_node_id (str) The curie id of the input node. result (dict) @@ -317,15 +315,14 @@ def neighborhood_finder_multiple_inputs(input_nodes:list[str], node2_categories: result_ranked_by_primary_infores (DataFrame) The ranked results based on primary infores. - -------------- - Example: - >>> input_node_id, result, result_parsed, result_ranked_by_primary_infores1 = neighborhood_finder('MONDO:0008170', #Ovarian Cancer - node2_categories = ['biolink:SmallMolecule', 'biolink:Drug', 'biolink:ChemicalEntity'], - APInames = APInames, - metaKG = metaKG, - API_predicates = API_predicates) - -------------- + Examples + -------- + >>> result, result_parsed = neighborhood_finder_multiple_inputs(['NCBIGene:6774', 'NCBIGene:4170', 'NCBIGene:4792'], + node2_categories = ['biolink:SmallMolecule', 'biolink:Drug', 'biolink:ChemicalEntity'], + APInames = APInames, + metaKG = metaKG, + API_predicates = API_predicates) """ from . import node_normalizer from . import translator_query diff --git a/TCT/TCT_network_annotator.py b/TCT/TCT_network_annotator.py index c0b1d0a..0dff740 100644 --- a/TCT/TCT_network_annotator.py +++ b/TCT/TCT_network_annotator.py @@ -175,36 +175,31 @@ def get_connected_graph(result_parsed, input_identifiers): Parameters ---------- - result_parsed (dict) + result_parsed : dict The parsed results for results from TCT_neighborhood_finder.neighborhood_finder_multiple_inputs(). - input_identifiers (list) + input_identifiers : list A list of input node identifiers, which are also input for TCT_neighborhood_finder.neighborhood_finder_multiple_inputs(). Returns - -------------- - result_parsed (dict) + ------- + result_parsed : dict The connected graph extracted from the parsed results. - -------------- - Example: - >>> - input_identifiers = ['NCBIGene:6774', 'NCBIGene:4170','NCBIGene:4792','NCBIGene:4288','NCBIGene:596','NCBIGene:581','NCBIGene:836','NCBIGene:6777','NCBIGene:4790','NCBIGene:545'] - - result, result_parsed = TCT_neighborhood_finder.neighborhood_finder_multiple_inputs(input_identifiers, + Examples + -------- + >>> input_identifiers = ['NCBIGene:6774', 'NCBIGene:4170','NCBIGene:4792','NCBIGene:4288','NCBIGene:596','NCBIGene:581','NCBIGene:836','NCBIGene:6777','NCBIGene:4790','NCBIGene:545'] + >>> result, result_parsed = TCT_neighborhood_finder.neighborhood_finder_multiple_inputs(input_identifiers, node2_categories = ['biolink:Gene','biolink:Protein'], APInames = APInames, metaKG = metaKG, API_predicates = API_predicates) - - result = TCT_network_annotator.get_connected_graph(result_parsed, input_identifiers) - import datetime - import json - timestamp = datetime.datetime.now().strftime('%Y%m%d_%H%M%S') - with open('./PathFinder_testing_results/'+'TCT_neighborhood_finder_result_'+'_'+timestamp+'.json', 'w') as f: - json.dump(result, f) - # visualize the result using the TCT visualization tool (https://github.com/NCATSTranslator/Translator_component_toolkit/blob/main/notebooks/visulize_path_finder_results.html). - -------------- - + >>> result = TCT_network_annotator.get_connected_graph(result_parsed, input_identifiers) + >>> import datetime + >>> import json + >>> timestamp = datetime.datetime.now().strftime('%Y%m%d_%H%M%S') + >>> with open('./PathFinder_testing_results/'+'TCT_neighborhood_finder_result_'+'_'+timestamp+'.json', 'w') as f: + >>> json.dump(result, f) + >>> # visualize the result using the TCT visualization tool (https://github.com/NCATSTranslator/Translator_component_toolkit/blob/main/notebooks/visulize_path_finder_results.html). """ result_parsed_copy = result_parsed.copy() diff --git a/TCT/TCT_pathfinder.py b/TCT/TCT_pathfinder.py index 2a0dd6f..77cbcad 100644 --- a/TCT/TCT_pathfinder.py +++ b/TCT/TCT_pathfinder.py @@ -31,20 +31,21 @@ def format_query_json_for_pathfinder_with_constraints(subject_ids, a list of predicates for the edge between subject and object nodes constraints : list a list of intermediate categories for the pathfinder pipeline, currently only one intermediate category is allowed in the constraints list. + Returns ------- query_json_temp : dict a query json for pathfinder pipeline - Example - ------- - query_json_temp = format_query_json_for_pathfinder_with_constraints( - subject_ids='NCBIGene:6774', - object_ids='NCBIGene:4170', - subject_categories=['biolink:Gene'], - object_categories=['biolink:Gene'], - predicates=['biolink:related_to'], - constraints=['biolink:Protein'] + Examples + -------- + >>> query_json_temp = format_query_json_for_pathfinder_with_constraints( + subject_ids='NCBIGene:6774', + object_ids='NCBIGene:4170', + subject_categories=['biolink:Gene'], + object_categories=['biolink:Gene'], + predicates=['biolink:related_to'], + constraints=['biolink:Protein']) """ if constraints is None or len(constraints) == 0: constraints_intermediate_category = None