Reading POD5 Files¶
escapepod.Reader gives efficient, memory-mapped access to a single POD5
file. escapepod.DatasetReader presents many files as one stream.
Opening a file¶
1 2 3 | |
Reader accepts a str or any os.PathLike (e.g. pathlib.Path). Use it as a
context manager so the underlying file is released promptly:
1 2 3 4 | |
File information¶
Reader exposes file-level metadata as properties:
1 2 3 4 5 6 7 8 9 | |
Iterating over reads¶
Iterating the reader yields ReadData objects — one per
read, metadata only:
1 2 | |
reader.reads() returns the same reads as a list. Pass a selection of read
IDs to restrict it:
1 2 3 | |
By default a requested ID that isn't in the file raises KeyError; pass
missing_ok=True to silently skip it.
reader.read_ids() returns just the IDs as a list[str].
Looking up specific reads¶
1 2 3 | |
Repeated lookups build and reuse an in-memory index. Call
reader.build_index() up front to pay that cost once (it returns the number of
reads indexed and persists the index in the .p5s sidecar); reader.has_index
reports whether a sidecar exists.
Sidecar annotations¶
Per-read annotations recorded with escpod annotate (e.g. demux barcode
assignments) live in the .p5s sidecar next to the POD5 and are exposed as
plain dicts:
reader.annotation_names() # e.g. ["barcode", "condition"]
barcodes = reader.annotation() # dict[read_id, label]; name= if several
conditions = reader.annotation("condition") # derived from the design
reader.design() # {"key_columns": …, "value_columns": …,
# "rows": [...]} or None
Numeric columns (e.g. a demux classifier's confidence/margin scores) live alongside the string annotations, under their own accessors — a separate Arrow type, so a separate pair of methods:
reader.score_names() # e.g. ["ldx_confidence", "ldx_crf_margin"]
scores = reader.score("ldx_confidence") # dict[read_id, float]
Unassigned/unscored reads are absent from the dict. A sidecar that does not
match the POD5 (stale, or copied from another file) raises instead of
returning wrong answers. The sidecar itself is a plain Arrow IPC table, so
pyarrow.ipc.open_file("reads.pod5.p5s").read_all() works too.
Accessing signal data¶
Signal is stored separately from metadata and is fetched on demand from the
reader — it is not an attribute of ReadData. Request it per read:
1 2 3 4 | |
get_signal returns raw ADC counts as int16. get_signal_pa applies the
read's calibration ((adc + offset) * scale) and returns float32 picoamps.
Both take an optional max_samples, decoding only that many leading samples
instead of the whole read (a read shorter than max_samples comes back
whole) — cheaper than slicing after the fact when only a prefix is needed:
1 | |
For many reads at once, the bulk variants decode in parallel and return
(read_id, signal) tuples; they take the same max_samples:
1 2 3 4 5 | |
reader.prefetch_signal() is an optional hint that warms the signal region of
the file; reader.byte_count(read) reports the compressed on-disk size of a
read's signal.
Reads as a DataFrame¶
Pull every read's metadata into a table in one call:
1 2 3 | |
All three accept the same selection / missing_ok arguments as reads().
Columns include read_id, channel, well, num_samples,
calibration_offset, calibration_scale, end_reason, and the rest of the
read metadata fields.
1 2 3 | |
The ReadData object¶
Each read is a ReadData with the POD5 read fields as read-only properties:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | |
If you already hold a raw ADC array, read.calibrate_signal_array(adc) converts
it to picoamps using that read's calibration:
1 2 | |
Reading many files (DatasetReader)¶
DatasetReader reads a single file, a directory (scanned for *.pod5), or a
list mixing both, and presents every read across all files as one stream — the
escapepod analogue of pod5.DatasetReader.
1 2 3 4 5 6 7 8 | |
Control the directory scan with keyword arguments:
1 | |
DatasetReader offers the same reading surface as Reader —
reads()/read_ids(), to_dict()/to_pandas()/to_polars(),
get_signal()/get_signal_pa() and their bulk get_signals* forms,
byte_count(), iteration, and len() — plus paths, file_count,
read_count, and run_infos properties.