Rest API Utilities (indra_network_search.rest_util)

Utility functions for the Network Search API and Rest API

indra_network_search.rest_util.check_existence_and_date_s3(query_hash)[source]

Check if a query hash has corresponding result and query json on S3

Parameters:

query_hash (Union[int, str]) – The query hash to check

Return type:

Dict[str, str]

Returns:

Dict with S3 key for query and corresponding result, if they exist

indra_network_search.rest_util.dump_query_json_to_s3(query_hash, json_obj, get_url=False)[source]

Dump a query json to S3

Parameters:
  • query_hash (Union[str, int]) – The query hash associated with the query

  • json_obj (Dict) – The json object to upload

  • get_url (bool) – If True return the S3 url of the object. Default: False.

Return type:

Optional[str]

Returns:

Optionally return the S3 url of the json file

indra_network_search.rest_util.dump_query_result_to_s3(filename, json_obj, get_url=False)[source]

Dump a result or query json from the network search to S3

Parameters:
  • filename (str) – The filename to use

  • json_obj (Dict) – The json object to upload

  • get_url (bool) – If True return the S3 url of the object. Default: False.

Return type:

Optional[str]

Returns:

Optionally return the S3 url of the json file

indra_network_search.rest_util.dump_result_json_to_s3(query_hash, json_obj, get_url=False)[source]

Dump a result json to S3

Parameters:
  • query_hash (Union[str, int]) – The query hash associated with the result

  • json_obj (Dict) – The json object to upload

  • get_url (bool) – If True return the S3 url of the object. Default: False.

Return type:

Optional[str]

Returns:

Optionally return the S3 url of the json file

indra_network_search.rest_util.get_default_args(func)[source]

Returns the default args of a function as a dictionary

Returns a dictionary of {arg: default} of the arguments that have default values. Arguments without default values and **kwargs type arguments are excluded.

Code copied from: https://stackoverflow.com/a/12627202/10478812

Parameters:

func (Callable) – Function to find default arguments for

Return type:

Dict[str, Any]

Returns:

A dictionary with the default values keyed by argument name

indra_network_search.rest_util.get_mandatory_args(func)[source]

Returns the mandatory args for a function as a set

Returns the set of arguments names of a functions that are mandatory, i.e. does not have a default value. **kwargs type arguments are ignored.

Parameters:

func (Callable) – Function to find mandatory arguments for

Return type:

Set[str]

Returns:

The of mandatory arguments

indra_network_search.rest_util.get_query_hash(query_json, ignore_keys=None)[source]

Create an FNV-1a 32-bit hash from the query json

Parameters:
  • query_json (Dict) – A json compatible query dict

  • ignore_keys (Union[Set, List, None]) – A list or set of keys to ignore in the query_json. By default, no keys are ignored. Default: None.

Return type:

int

Returns:

An FNV-1a 32-bit hash of the query json ignoring the keys in ignore_keys

indra_network_search.rest_util.is_context_weighted(mesh_id_list, strict_filtering)[source]

Return True if context weighted

Parameters:
  • mesh_id_list (List[str]) – A list of mesh ids

  • strict_filtering (bool) – whether to run strict context filtering or not

Return type:

bool

Returns:

True for the combination of mesh ids being present and unstrict filtering, otherwise False

indra_network_search.rest_util.is_weighted(weighted, mesh_ids, strict_mesh_filtering)[source]

Return True if the combination is either weighted or context weighted

Parameters:
  • weighted (bool) – If a query is weighted or not

  • mesh_ids (List[str]) – A list of mesh ids

  • strict_mesh_filtering (bool) – whether to run strict context filtering or not

Return type:

bool

Returns:

True if the combination is either weighted or context weighted

indra_network_search.rest_util.load_indra_graph(unsigned_graph=True, unsigned_multi_graph=False, sign_edge_graph=False, sign_node_graph=True, use_cache=False)[source]

Return a tuple of graphs to be used in the network search API

Parameters:
  • unsigned_graph (bool) – Load the latest unsigned graph. Default: True.

  • unsigned_multi_graph (bool) – Load the latest unsigned multi graph. Default: False.

  • sign_node_graph (bool) – Load the latest signed node graph. Default: True.

  • sign_edge_graph (bool) – Load the latest signed edge graph. Default: False.

  • use_cache (bool) – If True, try to load files from the designated local cache

Returns:

Returns, as a tuple:
  • unsigned graph

  • unsigned multi graph

  • signed edge graph

  • signed node graph

If a graph was not chosen to be loaded or wasn’t found, None will be returned in its place in the tuple.

Return type:

Tuple[nx.DiGraph, nx.MultiDiGraph, nx.MultiDiGraph, nx.DiGraph]