kg_microbe.transform_utils.metatraits package

Submodules

kg_microbe.transform_utils.metatraits.io module

File I/O primitives for the MetaTraits transform.

class kg_microbe.transform_utils.metatraits.io.StreamingRowWriter(output_file, header)

Bases: object

Write TSV rows incrementally without accumulating a graph in memory.

write_row(row)

Write one ordered TSV row.

Return type:

None

kg_microbe.transform_utils.metatraits.io.open_jsonl(path)

Open JSONL input through the tolerant gzip reader.

Return type:

IO[str]

kg_microbe.transform_utils.metatraits.io.open_maybe_gzipped(path)

Open gzip input while tolerating a misnamed plain-text Google Drive file.

Return type:

IO[str]

kg_microbe.transform_utils.metatraits.metatraits module

Metatraits transform class.

Reads metatraits summary JSONL files from data/raw, resolves taxon names to NCBITaxon IDs, maps trait names to METPO/ontology terms, and outputs KGX nodes.tsv and edges.tsv.

class kg_microbe.transform_utils.metatraits.metatraits.MetaTraitsTransform(input_dir=None, output_dir=None, use_multiprocessing=True, num_workers=None)

Bases: Transform

Transform metatraits summary JSONL files into KGX nodes and edges.

DATA_INPUTS: tuple = ('mappings/kgmicrobe_unified_entity_mappings.sssom.tsv.gz',)

Repo-relative curation files this transform reads, beyond its own data/raw/ download.

Declared so freshness tooling can tell that an output is stale against its data rather than only its code. Without it a mapping correction lands, every consumer keeps reporting FRESH, and a re-merge silently ships the old groundings: #778 corrected 16 isolation-source ids and #786 rewrote the unified chemical SSSOM, and the merged KG built afterwards still asserted 75 organisms isolated from a “Cell Line”, because nothing re-ran the transforms that read those files (#812).

Paths are relative to the repo root. Keep them tracked in git — the freshness check uses commit time, not mtime, because git checkout rewrites mtimes without changing content (#797).

List every curation file read, not a representative one. A partial declaration fails silently and looks identical to a complete one: ontologies_stubs declared 1 of the 11 files it read and was reported fresh after changes to the other ten (#839). Where the set comes from a constant, derive this from it rather than restating it.

MEASUREMENT_TRAITS = {'cell length maximum', 'cell length minimum', 'cell width maximum', 'cell width minimum', 'coding density', 'estimated gene count', 'estimated genome size', 'gene count', 'genome size', 'ph growth', 'ph maximum', 'ph minimum', 'salinity growth', 'salinity maximum', 'salinity minimum', 'temperature growth', 'temperature maximum', 'temperature minimum'}
TRANSFORM_INPUTS: tuple = ('ontologies',)

Reads ontologies/ncbitaxon_nodes.tsv via NCBITAXON_NODES_FILE in _load_ncbitaxon_labels. metatraits_gtdb inherits this. Undeclared until #1035, because the path lives in constants.py rather than here.

run(data_file=None, show_status=True)

Run MetaTraitsTransform with optional multiprocessing.

Parameters:
  • data_file (Union[Path, None, str]) – Ignored; uses configured input file list.

  • show_status (bool) – Whether to show progress bar.

Return type:

None

Module contents

Metatraits transform package.

class kg_microbe.transform_utils.metatraits.MetaTraitsTransform(input_dir=None, output_dir=None, use_multiprocessing=True, num_workers=None)

Bases: Transform

Transform metatraits summary JSONL files into KGX nodes and edges.

DATA_INPUTS: tuple = ('mappings/kgmicrobe_unified_entity_mappings.sssom.tsv.gz',)

Repo-relative curation files this transform reads, beyond its own data/raw/ download.

Declared so freshness tooling can tell that an output is stale against its data rather than only its code. Without it a mapping correction lands, every consumer keeps reporting FRESH, and a re-merge silently ships the old groundings: #778 corrected 16 isolation-source ids and #786 rewrote the unified chemical SSSOM, and the merged KG built afterwards still asserted 75 organisms isolated from a “Cell Line”, because nothing re-ran the transforms that read those files (#812).

Paths are relative to the repo root. Keep them tracked in git — the freshness check uses commit time, not mtime, because git checkout rewrites mtimes without changing content (#797).

List every curation file read, not a representative one. A partial declaration fails silently and looks identical to a complete one: ontologies_stubs declared 1 of the 11 files it read and was reported fresh after changes to the other ten (#839). Where the set comes from a constant, derive this from it rather than restating it.

MEASUREMENT_TRAITS = {'cell length maximum', 'cell length minimum', 'cell width maximum', 'cell width minimum', 'coding density', 'estimated gene count', 'estimated genome size', 'gene count', 'genome size', 'ph growth', 'ph maximum', 'ph minimum', 'salinity growth', 'salinity maximum', 'salinity minimum', 'temperature growth', 'temperature maximum', 'temperature minimum'}
TRANSFORM_INPUTS: tuple = ('ontologies',)

Reads ontologies/ncbitaxon_nodes.tsv via NCBITAXON_NODES_FILE in _load_ncbitaxon_labels. metatraits_gtdb inherits this. Undeclared until #1035, because the path lives in constants.py rather than here.

ncbitaxon_name_to_id: Dict[str, str]
run(data_file=None, show_status=True)

Run MetaTraitsTransform with optional multiprocessing.

Parameters:
  • data_file (Union[Path, None, str]) – Ignored; uses configured input file list.

  • show_status (bool) – Whether to show progress bar.

Return type:

None

trait_mapping: Dict[str, dict]