iggytop.adapters.base_adapter.BaseAdapter#

class iggytop.adapters.base_adapter.BaseAdapter(bc, cache_dir=None, receptors_to_include=('TCR', 'BCR'), test=False)#

Base class for all adapters.

This class is responsible for the basic structure and function for Iggytop adapters. It initializes any adapter by calling the corresponding function for downloading and reading the data from the source. It also provides methods for generating BioCypher nodes and edges from the data.

Variables:
  • table (pd.DataFrame) – The data table read from the source.

  • DB_NAME (str) – Name of the database. Must be defined in subclasses.

  • available_receptors (list[str]) – List of receptor types available in the database. Must be defined in subclasses.

Parameters:
  • bc (BioCypher) – An instance of the BioCypher class.

  • cache_dir (str | None) – Directory to cache data. Defaults to None.

  • receptors_to_include (Optional[Sequence[Literal['TCR', 'BCR']]]) – Receptors to include. Defaults to (“TCR”, “BCR”).

  • test (bool) – Whether to run in test mode. Defaults to False.

__init__(bc, cache_dir=None, receptors_to_include=('TCR', 'BCR'), test=False)#

Initializes the BaseAdapter instance.

Parameters:
  • bc (BioCypher) – An instance of the BioCypher class.

  • cache_dir (str | None) – Directory to cache data. Defaults to None.

  • receptors_to_include (Optional[Sequence[Literal['TCR', 'BCR']]]) – Receptors to include. Defaults to (“TCR”, “BCR”).

  • test (bool) – Whether to run in test mode. Defaults to False.

Methods

__init__(bc[, cache_dir, ...])

Initializes the BaseAdapter instance.

create_anndata()

Creates an Anndata object from the AIRR cell data and saves it to a file in the cache directory.

get_edges()

Abstract method to generate BioCypher edges from the data.

get_latest_release(bc)

Abstract method to get the latest release of the data.

get_nodes()

Abstract method to generate BioCypher nodes from the data.

read_table(bc, table_path, receptors[, test])

Abstract method to read and harmonize the data table from the source.

set_metadata([version, source_url, ...])

Sets the metadata for the adapter.

Attributes

airr_cells

Property to get the list of AIRR cells.

cache_dir

Property to get the cache directory.

db_name

Property to get the database name.

metadata

Property to get the adapter metadata.

receptors

Property to get the available receptor types.

table

Property to get the data table.

DB_NAME

available_receptors

_get_ontoweaver_kg()#

Generates BioCypher nodes and edges from the harmonized table via OntoWeaver.

Runs the shared per-hub mappings in _ONTOWEAVER_MAPPINGS (driven purely by REGISTRY_KEYS column names, so they apply unmodified to any adapter’s table) against a copy of the table augmented with a few precomputed columns (the complete flags, which need boolean combinations no single-column mapping can express, and the source database’s identity, which lives in self.metadata rather than as a table column). The passes are reconciled together afterwards, so nodes/edges produced by more than one pass (e.g. a chain_2 node, created as a target by the receptor_complex mapping and as the subject of the chain_2 mapping) are merged into one.

Return type:

tuple[list[tuple], list[tuple]]

Returns:

A tuple of (nodes, edges), each a list of BioCypher tuples.

create_anndata()#

Creates an Anndata object from the AIRR cell data and saves it to a file in the cache directory.

Return type:

None

abstractmethod get_edges()#

Abstract method to generate BioCypher edges from the data.

Adapters are expected to implement this via _get_ontoweaver_kg.

Yields:

tuple – A BioCypher edge (id, source, target, type, properties).

abstractmethod get_latest_release(bc)#

Abstract method to get the latest release of the data.

Parameters:

bc (BioCypher) – An instance of the BioCypher class.

Return type:

str | tuple[str, ...]

Returns:

Path to the latest release file(s).

abstractmethod get_nodes()#

Abstract method to generate BioCypher nodes from the data.

Adapters are expected to implement this via _get_ontoweaver_kg.

Yields:

tuple – A BioCypher node (id, type, properties).

abstractmethod read_table(bc, table_path, receptors, test=False)#

Abstract method to read and harmonize the data table from the source.

Parameters:
  • bc (BioCypher) – An instance of the BioCypher class.

  • table_path (str | tuple[str, ...]) – Path to the data table file(s).

  • receptors (list[str]) – List of receptor types to include in the table.

  • test (bool) – Whether to run in test mode. Defaults to False.

Return type:

DataFrame

Returns:

The data table.

set_metadata(version=None, source_url=None, previous_version=None, previous_checksum=None)#

Sets the metadata for the adapter.

Parameters:
  • version (str) – The version of the database. Defaults to None.

  • source_url (str) – The URL of the source. Defaults to None.

  • previous_version (str) – The version of the database in the previous release. Defaults to None.

  • previous_checksum (str | list | None) – The checksum(s) of the source file(s) in the previous release. Defaults to None.

DB_NAME: str#
_abc_impl = <_abc._abc_data object>#
property airr_cells: list[AirrCell] | None#

Property to get the list of AIRR cells.

Returns:

The list of AIRR cells.

available_receptors: list[str]#
property cache_dir: str#

Property to get the cache directory.

Returns:

The cache directory.

property db_name: str#

Property to get the database name.

Returns:

The database name.

property metadata: dict[str, Any]#

Property to get the adapter metadata.

Returns:

The metadata dictionary.

property receptors: list[str]#

Property to get the available receptor types.

Returns:

List of receptor types.

property table: DataFrame#

Property to get the data table. Reads the table if not already read.

Returns:

The data table.