iggytop.io.create_knowledge_graph

iggytop.io.create_knowledge_graph#

Functions

build_adapters(cache_dir[, test_mode, ...])

Instantiates each selected adapter exactly once, triggering (lazily, on first access) the expensive per-source table build (read_table/harmonize_sequences, including IEDB lookups).

create_knowledge_graph([cache_dir, ...])

Generates the knowledge graph using specified adapters and saves it in the requested format.

write_knowledge_graph(adapters, cache_dir[, ...])

Drives already-built adapters into a fresh, dbms-appropriate BioCypher instance and writes out the requested output format.

iggytop.io.create_knowledge_graph.build_adapters(cache_dir, test_mode=False, receptors_to_include=None, adapters_to_include=None, bc=None)#

Instantiates each selected adapter exactly once, triggering (lazily, on first access) the expensive per-source table build (read_table/harmonize_sequences, including IEDB lookups).

The returned adapters can be driven into any number of downstream outputs (AnnData, AIRR JSON, knowledge graph via write_knowledge_graph) without repeating that work, since table, airr_cells and _get_ontoweaver_kg are all memoized per adapter instance.

Parameters:
  • cache_dir (str) – Directory to store cache files.

  • test_mode (bool) – Test mode will use only 1% of the data for faster execution. Defaults to False.

  • receptors_to_include (Optional[List[str]]) – List of receptor types to include. Defaults to including both TCR and BCR.

  • adapters_to_include (Optional[List[str]]) – List of adapter names to run. Defaults to providing all available adapters.

  • bc (BioCypher | None) – An existing BioCypher instance to reuse (e.g. built by the caller for a specific dbms). If not given, a default one is created purely for source-download caching purposes.

Returns:

A tuple of (BioCypher instance, list of instantiated adapters).

iggytop.io.create_knowledge_graph.create_knowledge_graph(cache_dir='/home/docs/.cache/iggytop', test_mode=False, receptors_to_include=['TCR', 'BCR'], adapters_to_include=['VDJDB', 'MCPAS', 'TRAIT', 'IEDB', 'TCR3D', 'ITRAP', 'NEOTCR', 'CEDAR', 'BATCAVE'], output_format='neo4j')#

Generates the knowledge graph using specified adapters and saves it in the requested format.

Thin convenience wrapper around build_adapters + write_knowledge_graph for standalone, graph-only runs. Callers that also need the AnnData/AIRR outputs from the same adapter tables (e.g. create_release.py) should call build_adapters once and pass the result to write_knowledge_graph directly, to avoid rebuilding the source tables.

Parameters:
  • cache_dir (str, optional) – Directory to store cache and output files. Includes raw datasets and generated knowledge graphs (see logs for filenames). Defaults to user cache directory.

  • test_mode (bool, optional) – Test mode will use only 1% of the data for faster execution. Defaults to False.

  • receptors_to_include (List[str], optional) – List of receptor types to include in the knowledge graph. Available receptor types: [“TCR”, “BCR”]. Defaults to including both TCR and BCR.

  • adapters_to_include (List[str], optional) – List of adapter names to run. See ADAPTER_CLASSES for the available adapters. Defaults to DEFAULT_ADAPTERS (all of them).

  • output_format (str, optional) – Output format, currently either ‘airr’, ‘neo4j’ or ‘networkx’. Defaults to ‘neo4j’.

iggytop.io.create_knowledge_graph.write_knowledge_graph(adapters, cache_dir, output_format='neo4j', output_directory=None)#

Drives already-built adapters into a fresh, dbms-appropriate BioCypher instance and writes out the requested output format. Since adapters are pre-built, adapter.get_nodes()/get_edges() only replay already-memoized OntoWeaver results; no source table is re-read.

For ‘neo4j’/’networkx’/’airr’, BioCypher’s own CSV+import-call output is written to a predictable <cache_dir>/knowledge_graph directory (unless overridden), so it sits next to the release’s other outputs and can be packaged as a release asset without importing into a running Neo4j instance.

Parameters:
  • adapters – Adapters previously created via build_adapters.

  • cache_dir (str) – Directory to store cache and output files.

  • output_format (str) – Output format, currently either ‘airr’, ‘neo4j’ or ‘networkx’.

  • output_directory (str | None) – Where to write the graph output. Defaults to <cache_dir>/knowledge_graph.

Return type:

None