Skip to content

Python API

Other packages import apb-export only from apb_export.api.

Exports of APB2 results in the formats downstream tools read.

APB2 owns conversion and persistence: ParseRuleCompiler reads vendor files into ParsedLevels, read_parsed_levels loads a stored result, write_parsed_levels writes one. Each target's packaged export rule declares what that tool reads; Exporter applies one and writes the target's format: HDF5 through APB2, one .h5ad per level in a .h5ads directory, a .csv long table, a .txt Perseus table, or a QPX Parquet directory. The command composes conversion, annotation and export.

A plugin package adds a target through the apb_export.targets entry-point group.

Exporter

Bind one packaged target's export rule and the layer that becomes X.

extension property

The target's file suffix: .h5ad, .h5mu, .csv or .txt, or the directory suffix .qpx or .h5ads.

levels property

The APB2 levels the target reads; the command asks APB2 for exactly these.

__init__(target, abundance=None)

Choose the target and, for a one-level target, the layer that becomes X.

Parameters:

Name Type Description Default
target str

One of :meth:targets.

required
abundance str | None

A layer of the target's level; APB2's primary layer when None.

None

Raises:

Type Description
ValueError

The target is neither packaged nor installed by a plugin, or abundance is given for a target that writes several levels.

export(parsed)

Build the target's export from an APB2 result.

Parameters:

Name Type Description Default
parsed ParsedLevels

An APB2 result holding the levels the target requires.

required

Returns:

Type Description
ParsedLevels

A ParsedLevels for APB2's writer, one level per level the target reads, with a

ParsedLevels

directed feature relation for each of the target's feature links.

Raises:

Type Description
ValueError

The result lacks a level or field the target requires.

UnresolvedField

apb-catalog finds an answer ambiguous or the vendor rule unreviewed.

targets() staticmethod

The packaged targets and those of installed plugins, by name.

write(exported, output)

Write an export in its target's format.

HDF5 exports use APB2's writer with unprefixed variable names and its sidecar. QPX exports contain Parquet tables and an export manifest in a new directory. .csv exports are the long table and .txt exports the Perseus table, both without a sidecar.

Parameters:

Name Type Description Default
exported ParsedLevels

What :meth:export returned.

required
output Path

The new .h5ad/.h5mu/.csv/.txt file or .qpx directory.

required