Python API¶
The public API, from refbook's top level. The Python guide
shows these in use.
The catalog¶
Catalog
¶
Catalog(source: str | Path, cache: str | Path | None = None)
file
¶
file(name: str) -> Path
A local path to one catalog file; downloaded (and checked) on first use if remote.
stored_collection
¶
stored_collection(digest: str) -> dict | None
The level-2 representation of a collection in the collection store.
sequence_aliases
¶
sequence_aliases() -> dict[str, list[tuple[str, str]]]
sha512t24u -> [(naming_authority, alias)]: refget's aliases of each stored sequence (sequence_aliases.parquet); empty if the catalog has none.
by_identifier
¶
by_identifier() -> dict[tuple[str, str], set[str]]
(naming_authority, alias) -> the stored sequences it names.
edition_names
¶
edition_names() -> dict[str, list[tuple[str, str]]]
sha512t24u -> [(edition, name)]: the editions that use a sequence, under which names.
spans
¶
spans(layer: str) -> dict[str, list[tuple[int, int]]]
root_id -> the spans of a mask layer (layer_
padding
¶
padding(root: str, book: str | None = None) -> tuple[int, int, int, bool]
How pad lays a root out by its placement in book (layer_padding.parquet, a placement per book: a root
can be placed in two, on other parents): (before, root_length, after, reverse), the Ns before it, its
length, the Ns after it, and whether it is reverse-complemented. Without a book, the root's only placement.
blocks_location
¶
blocks_location() -> str
root_blocks.parquet as a path or URL (for engines that open it themselves).
open_blocks
¶
open_blocks() -> pq.ParquetFile
root_blocks.parquet: a local file, or HTTP range reads; never downloaded whole.
Collections¶
resolve
¶
resolve(cat: Catalog, x, level: int = 2, **materialize_options)
A collection at seqcol level 0, 1, 2, or 3 (with bases).
collection
¶
collection(cat: Catalog, x) -> Collection
The level-2 collection that x names or represents (see the module docstring).
Collection
dataclass
¶
Collection(names: tuple[str, ...], lengths: tuple[int, ...], sequences: tuple[str, ...], label: str | None = None)
A collection at level 2. label is the edition or target it is, if any.
Identification¶
identify
¶
identify(header: Header, cat: Catalog) -> Result
A header summarized against every edition, on its per-sequence identities.
sequences
¶
sequences(x: Header | list, cat: Catalog) -> list[dict]
What each entry is: one identity per entry, in order (see the module docstring). x is a Header, or a list of Entry or of dicts with any of name, length, md5 and sq.
Sequences¶
materialize
¶
materialize(cat: Catalog, x, names: list[str] | None = None, *, max_batch_bytes: int = 1 << 30, verify: bool = True, bases: Bases | None = None) -> pa.RecordBatchReader
A collection as a Sequence 0.1 stream. Batches end early at max_batch_bytes of sequence. The schema metadata names the collection; the whole collection also carries its seqcol digest.
fetch
¶
fetch(cat: Catalog, collection, intervals, *, chrom: str = 'chrom', start: str = 'start', end: str = 'end', strand: str | None = None, zero_based: bool | None = None, clip: bool = False, engine: str = 'auto', bases: Bases | None = None, reader: DataFusionBlocks | None = None) -> pa.Table
populate_ref_cache
¶
populate_ref_cache(cat: Catalog, md5s: Iterable[str], root: str | Path, subdirs: int = 2, bases: Bases | None = None) -> dict[str, list[str]]
Write every known MD5's sequence into the cache; report written, present and unknown.
Seqcol¶
seqcol
¶
GA4GH sequence collection (seqcol) digests, representations and comparison.
From the spec (github.com/ga4gh/refget, docs/seqcols/README.md): canonicalize each attribute with RFC-8785, digest it with sha512t24u; the top-level digest covers the inherent attributes, names and sequences. SCHEMA is the schema refbook serves: the spec's extended schema plus named_sequences and sorted_named_sequences. Transient attributes (TRANSIENT) have a level-1 digest but no level-2 value.
Implemented in the Rust core (refbook._core, crates/refbook-core/src/seqcol.rs).
canonical
¶
canonical(item) -> bytes
RFC-8785 canonical JSON of a value made of strings, integers, lists and dicts.
digests
¶
digests(names: list[str], lengths: list[int], sequences: list[str]) -> tuple[str, dict]
(top-level digest, level-1 digests) of a collection; sequences are SQ. ids.
ancillary
¶
ancillary(names: list[str], lengths: list[int], sequences: list[str]) -> dict
Level-2 values of the non-inherent attributes refbook computes.
From the spec: name_length_pairs (5.1), sorted_name_length_pairs (5.2) and sorted_sequences (5.3). named_sequences is the per-element digest of {"name", "sequence"} that footnote F1 suggests; sorted_named_sequences is refbook's: those digests sorted, as 5.2 sorts name-length pairs. Its level-1 digest identifies the named sequence set, whatever the order.
named_set_digest
¶
named_set_digest(names: list[str], sequences: list[str]) -> str
The order-independent identifier of a named sequence set: the level-1 digest of sorted_named_sequences.
level2
¶
level2(names: list[str], lengths: list[int], sequences: list[str]) -> dict
The level-2 representation (/collection?level=2): every attribute but the transient ones.
level1_attributes
¶
level1_attributes(names: list[str], lengths: list[int], sequences: list[str]) -> dict
The level-1 representation (/collection?level=1): the digest of every attribute, transient ones included.
top_level_digest
¶
top_level_digest(collection: dict) -> str | None
The top-level digest of a collection given as its attributes (level 2, or level 1), or None without the inherent attributes.
compare
¶
compare(a: dict, b: dict) -> dict
seqcol's /comparison (spec 3.3) of two collections given as their level-2 attributes. Arrays are counted; an attribute given as a digest is listed only. Shared elements count with multiplicity; the order of fewer than 2 shared elements, or of unbalanced duplicates, is None.