Skip to content

genoABO Workflow: Loading to Output

Trace a genotype file through marker identification, normalization, phase resolution, inference, and QC. See Usage for commands and output schemas and Inference methods for the decision rules.

Overview

genoABO reads four ABO markers (rs8176719, rs8176746, rs8176747, rs505922) from a cohort genotype file, detects the genome build, normalizes alleles to biological marker states, infers haplotypes and diplotypes, and writes per-sample ABO calls with QC metrics. Indexed VCF/BCF fetches those sites by region. Unindexed VCF is scanned into an in-memory cache. PGEN and BGEN parse full variant-metadata indexes, then read genotypes only for the matched markers.

The package is organized into four modules plus YAML registries:

flowchart TB
    Input[Genotype file]
    Readers[readers/]
    Core[core/]
    Methods[methods/]
    CLI[cli/]
    Data[data/*.yaml]
    OutABO["PREFIX.abo.tsv"]
    OutQC["PREFIX.qc.tsv"]
    OutSum["PREFIX.summary.txt"]
    OutRep["PREFIX.report.html"]

    Input --> Readers
    Readers --> Core
    Core --> Data
    Core --> Methods
    Methods --> CLI
    CLI --> OutABO
    CLI --> OutQC
    CLI --> OutSum
    CLI --> OutRep
Module Role
readers/ Format detection and indexed marker fetch (VCF, BGEN, PGEN, PLINK1)
core/ Types, YAML registry, build detection, genotype interpretation, normalization, haplotype logic
methods/ Inference methods and ABOCaller orchestration
cli/ Command-line interface, output writers, citations
data/ YAML single source of truth for coordinates, states, methods

Entry points

Both paths run the same pipeline via ABOCaller. See Usage for the full CLI and Python API.

Entry Code path
CLI genoabo DATA -o PREFIX → cli/cli_main.py → ABOCaller.call() → cli/cli_qc.py writers
Python API from genoabo import ABOCaller → methods/methods_caller.py

Pipeline stages

The orchestrator is ABOCaller._run() in methods/methods_caller.py. Stages run in this order:

Step Module What happens
1. Format detection readers/ open_reader(path, format) auto-detects VCF/BCF, PGEN, PLINK1, or BGEN from file extensions and companion files (.pvar/.psam, .bim/.fam, .sample)
2. Sample list readers/ reader.samples() returns the cohort SampleID list. The caller uses the FID/IID pair and rejects duplicate pairs
3. Marker probe readers/ + core/ Build a MarkerQuery from assemblies.yaml and markers.yaml. Check the location and allele pair of each candidate
4. Build detection core/ detect_build() matches observed positions and VCF ##reference= / similar header tokens; returns build + confidence. Ambiguous results raise an error unless --build is set explicitly. Chromosome-length scoring exists in detect_build but the caller does not pass contig lengths. PGEN/BGEN headers are not assembly metadata
5. Full marker fetch readers/ Fetch all four markers at the resolved build
6. Method selection methods/ select_method() applies the auto-selection hierarchy from data/methods.yaml, or honors --method / --strict-method
7. Inspection report core/ + cli/ inspect_markers() builds an InspectReport (positions, call rates, recommended method). Printed with --inspect; also embedded in QC output
8. Per-sample normalization core/ For each sample and marker, interpret_genotype() selects the genotype source and normalize_marker() maps its alleles to biological states
9. Phase resolution methods/ + core/ Use phased states when the sample's contributing markers support them. Otherwise, use copy counts
10. Inference methods/ + core/ get_method(name).call_sample() applies method rules (methods/methods_infer.py); haplotype/diplotype logic lives in core/core_haplotype.py
11. Output cli/ write_abo_tsv, write_qc_tsv, write_summary, and write_report write the four output files

Per-sample sub-flow

For each sample, marker data passes through normalization before method-specific inference:

flowchart LR
    GT[GenotypeCall per marker]
    Geno[interpret_genotype]
    Norm[normalize_marker]
    Method[Apply method and resolve phase]
    Inference[Infer diplotype and phenotype]
    Call[ABOCall]

    GT --> Geno --> Norm --> Method --> Inference --> Call

Readers parse the file format. Normalization interprets genotype values and maps alleles to biological states. The selected method uses those states to infer a diplotype and phenotype.

Genotype source and phase resolution

The selected genotype source determines which allele copies reach normalization and whether phase is available. Phase is resolved per sample using the markers that contribute to its call. The CLI reports mixed when a run contains phased and unphased calls. See Genotype and phase options for source precedence and phase set handling.

Marker identification (probe and fetch)

genoABO gathers all records at the registered position across equivalent contig names, such as 9, chr9, and NC_000009.12 for GRCh38. It verifies the allele pair in either orientation using markers.yaml. An exact rsID breaks a tie between compatible records when it identifies one unique record. Remaining ties leave the marker unavailable. The same rules apply to indexed and unindexed files.

QC and output

Each call carries a QC status, confidence and, where applicable, a reason. The CLI aggregates sample-level results with the marker inspection metrics. For file formats and fields, see Usage.

Tests by workflow branch

YAML registries

All coordinates and biological mappings live in src/genoabo/data/, loaded at runtime via importlib.resources:

File Used in Purpose
assemblies.yaml Steps 3–5 Build aliases, chromosome lengths (registry / unused caller signal), marker coordinates per assembly
markers.yaml Steps 3 and 8 Biological states and REF/ALT → state normalization rules
methods.yaml Step 6 Method metadata, required markers, auto-selection hierarchy, report logic
alleles.yaml Reference Examples of ISBT allele names and selected markers
citations.yaml CLI / report Full bibliographic records for --method-info and the HTML report
report.yaml HTML report Pipeline narrative, column dictionary, confidence table, limitations

Error handling and early exit

Condition Behavior
Ambiguous build with --build auto RuntimeError; CLI exits with code 1
--strict-method with missing required markers Error for a user-selected method, or for --method auto when no entry matches; no substitution of a smaller method
--inspect Pipeline succeeds after step 7; inspection printed; no .abo.tsv / .qc.tsv / .summary.txt / .report.html
Unreadable input format Error from open_reader()

When build detection conflicts (e.g. mixed GRCh37/GRCh38 signal), set --build hg19, --build hg38, or --build chm13 explicitly.