seismicrna.core.io package

Subpackages

Submodules

class seismicrna.core.io.batch.MutsBatchIO(*args, region: Region, **kwargs)

Bases: MutsBatch, ReadBatchIO, ABC

Pickled file of a batch of mutational data.

class seismicrna.core.io.batch.ReadBatchIO(*, batch: int, **kwargs)

Bases: ReadBatch, BrickleIO, ABC

Pickled file of a batch of data.

classmethod btype()
class seismicrna.core.io.brickle.BrickleIO

Bases: FileIO, ABC

Brotli-compressed file of a pickled object (brickle).

classmethod load(file: Path, **kwargs)

Load from a compressed pickle file.

save(top: Path, *args, **kwargs)

Save to a pickle file compressed with Brotli.

class seismicrna.core.io.brickle.RefBrickleIO(*args, ref: str, **kwargs)

Bases: SampleBrickleIO, RefFileIO, ABC

class seismicrna.core.io.brickle.RegBrickleIO(*args, reg: str, **kwargs)

Bases: RefBrickleIO, RegFileIO, ABC

class seismicrna.core.io.brickle.SampleBrickleIO(*args, sample: str, branches: dict[str, str], **kwargs)

Bases: SampleFileIO, BrickleIO, ABC

seismicrna.core.io.brickle.load_brickle(file: str | Path, data_type: type[BrickleIO], checksum: str)

Unpickle and return an object from a Brotli-compressed file.

Parameters:
  • file (str | Path) – Path to the Brotli-compressed pickle file.

  • data_type (type[BrickleIO]) – Expected type of the loaded object; must be a subclass of BrickleIO.

  • checksum (str) – Expected SHA-512 checksum of the file’s raw bytes; pass an empty string to skip checksum verification.

Returns:

The loaded object.

Return type:

BrickleIO

seismicrna.core.io.brickle.save_brickle(item: BrickleIO, file: str | Path, brotli_level: int = 10, force: bool = False)

Pickle an object, compress with Brotli, and save to a file.

Parameters:
  • item (BrickleIO) – Object to pickle and compress.

  • file (str | Path) – Path at which to save the compressed pickle file.

  • brotli_level (int) – Brotli compression quality (0–11); higher means better compression but slower.

  • force (bool = False) – Overwrite the file if it already exists.

Returns:

SHA-512 checksum of the written data.

Return type:

str

exception seismicrna.core.io.checksum.BadChecksumError

Bases: ValueError

A file or piece of data has the wrong checksum.

seismicrna.core.io.checksum.calc_sha512_bytes(data: bytes)

Calculate the SHA-512 checksum of a bytestring.

Parameters:

data (bytes) – Data of which to calculate the checksum

Return type:

SHA-512 checksum as a hexadecimal string.

seismicrna.core.io.checksum.calc_sha512_path(path: str | Path, chunk_size: int = 8192)

Calculate the SHA-512 checksum of a file.

Parameters:
  • path (str | Path) – File path

  • chunk_size (int) – Size of chunks to read when processing a file

Return type:

SHA-512 checksum as a hexadecimal string.

class seismicrna.core.io.file.FileIO

Bases: HasFilePath, ABC

Object that can be saved to and loaded from a file path.

abstractmethod classmethod load(file: Path)

Load an object from a file.

abstractmethod save(top: Path, **kwargs)

Save the object to a file.

class seismicrna.core.io.file.RefFileIO

Bases: SampleFileIO, HasRefFilePath, ABC

class seismicrna.core.io.file.RegFileIO

Bases: RefFileIO, HasRegFilePath, ABC

class seismicrna.core.io.file.SampleFileIO

Bases: FileIO, HasSampleFilePath, ABC