Skip to content

Exporters

Driven adapters that write domain objects to external file formats. Exporters are the inverse of readers: they consume immutable domain objects and produce a flat wire representation suitable for downstream tools or long-term storage.

Overview

Ports implemented

Exporter Port Output
BedRegionExporter RegionExporter BED 4 (chrom, start, end, name)
TsvVariantExporter VariantExporter TSV with dynamic columns

BedRegionExporter

Writes GenomicPosition objects to BED format. Handles the coordinate conversion from the domain's 1-based inclusive to BED's 0-based half-open: start0 = start − 1, end is unchanged. An optional padding value extends each region symmetrically. Output is sorted by (chrom, start) by default.

TsvVariantExporter

Writes VariantAnnotation objects to a tab-separated file. Column layout is discovered dynamically from the actual data present in the variant list — no schema needs to be declared in advance:

  • Core columns are always written (variant ID, chrom, position, alleles, type, zygosity, consequence on the canonical transcript, HGVS).
  • For each classification source found (e.g. clinvar): {source}_id, {source}_sig, {source}_evidence.
  • For each score name found (e.g. cadd_phred): one column per score.
  • For each allele frequency population found: {pop}_af, {pop}_ac, {pop}_an.
  • For each extra Metadata.data key: meta_{key}.

Column display names can be overridden via column_names (a dict[str, str] mapping internal key → display label). By default these are loaded from the adjacent tsv.toml.

Multi-value fields (e.g. multiple gene symbols or SO consequence terms) are joined with mv_separator (default |). Floats are rounded to float_precision decimal places (default 4).

BED

iris.adapters.driven.exporters.bed

BED format exporter for genomic regions.

BedRegionExporter

Bases: RegionExporter

Exports GenomicPosition objects to BED format (0-based half-open).

export

export(positions, handle)

Write positions to handle in BED format.

Source code in src/iris/adapters/driven/exporters/bed.py
def export(self, positions: Sequence[GenomicPosition], handle: TextIO) -> None:
    """Write positions to handle in BED format."""
    rows = [self._to_bed_row(p) for p in positions if p.start is not None]
    if self.sort:
        rows.sort(key=lambda r: (r[0], r[1]))
    writer = csv.writer(handle, delimiter="\t", lineterminator="\n")
    writer.writerows(rows)

TSV

iris.adapters.driven.exporters.tsv

TSV format exporter for variant annotations.

TsvVariantExporter

Bases: VariantExporter

Exports VariantAnnotation objects to tab-separated value format.

All data present in the supplied variants is exported automatically. Column display names are resolved from column_names (internal_key → label); any key not listed is used verbatim. By default column_names is loaded from the adjacent tsv.toml.

export

export(variants, handle)

Write variants to handle in TSV format with all available columns.

Source code in src/iris/adapters/driven/exporters/tsv.py
def export(self, variants: Sequence[VariantAnnotation], handle: TextIO) -> None:
    """Write variants to handle in TSV format with all available columns."""
    if not variants:
        return
    internal_cols = self._discover_columns(variants)
    display = [self.column_names.get(col, col) for col in internal_cols]
    rename = dict(zip(internal_cols, display))

    writer = csv.DictWriter(
        handle, fieldnames=display, delimiter="\t", lineterminator="\n", extrasaction="ignore"
    )
    writer.writeheader()
    for va in variants:
        row = self._build_row(va)
        writer.writerow({rename.get(k, k): v for k, v in row.items()})