Skip to main content

Module chebi_parse

Module chebi_parse 

Source
Expand description

ChEBI compounds.tsv local parser (AST-03). ChEBI compounds.tsv local parser (AST-03).

§Format

Parses one documented ChEBI FTP-style bulk TSV from a caller-selected local byte slice (or path). No network I/O. Tiny synthetic fixtures only in tests.

Required header (tab-separated):

ID	STATUS	CHEBI_ACCESSION	SOURCE	PARENT_ID	NAME	DEFINITION
ColumnNotes
IDInteger string (e.g. 15377)
STATUSPreserved as text (C / E / D …); D → quarantine
CHEBI_ACCESSIONe.g. CHEBI:15377 (must match ID)
SOURCEFree text; may be empty
PARENT_IDInteger or empty → None
NAMERequired non-empty (after trim) for acceptance
DEFINITIONMay be empty; preserved

Optional trailing columns are accepted and ignored.

§Quarantine vs error

  • Oversize whole input (max_bytes) → ParseError::ByteBudgetExceeded
  • Oversize single line (max_line_bytes) → ParseError::LineTooLong
  • Header mismatch / missing → ParseError::BadHeader
  • Cancel flag set → ParseError::Cancelled
  • Deleted / malformed / empty-name rows → QuarantinedRow (others continue)

Cold construction: String fields are intentional. Hot-path Quin mapping is AST-04.

Structs§

ChebiRecord
One accepted ChEBI compound row from compounds.tsv.
ParseBudgets
Caller-supplied parse ceilings for one compounds.tsv pass.
ParseReport
Result of a successful (possibly partially quarantined) parse pass.
QuarantinedRow
One quarantined source row (not accepted into the normalized set).

Enums§

ParseError
Fail-closed errors for the cold-construction ChEBI TSV parser.

Constants§

COMPOUNDS_HEADER
Documented ChEBI FTP-style compounds.tsv header (seven required columns).
RAW_PREVIEW_MAX
Maximum bytes retained in QuarantinedRow::raw_preview.
REQUIRED_COLUMNS
Minimum columns required; trailing extras are ignored.

Functions§

accession_ok
Validate accession shape: CHEBI: + decimal digits (case-sensitive prefix).
bounded_preview
Build a bounded preview from a raw line (no NUL expansion; chars truncated).
header_matches
Return true when fields starts with the documented header names.
parse_compounds_tsv
Parse ChEBI FTP-style compounds.tsv bytes into accepted records and quarantined rows.
parse_compounds_tsv_path
Convenience: read a caller-selected local path then parse (no network).