BamStore
quantnado.dataset.store_bam.BamStore
¶
BamStore(
store_path: Path | str,
chromsizes: dict[str, int] | Path | str,
sample_names: list[str],
*,
chunk_len: int | None = None,
construction_compression: str = DEFAULT_CONSTRUCTION_COMPRESSION,
overwrite: bool = True,
resume: bool = False,
read_only: bool = False,
stranded: "str | list[str] | dict[str, str] | None" = None,
)
Bases: BaseStore
Zarr-backed BAM signal store for per-chromosome, per-sample data and metadata.
Use from_bam_files to create a new store, or open to load an existing one.
By default, open attaches in read-only mode to prevent accidental data corruption.
To modify the store, pass read_only=False.
Example: # Read-only (default) store = BamStore.open("/path/to/store.zarr") print(store.sample_names)
# Writable
store = BamStore.open("/path/to/store.zarr", read_only=False)
store.add_metadata_column(...)
Source code in quantnado/dataset/store_bam.py
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 | |
library_sizes
property
¶
Total mapped reads per sample as a pd.Series indexed by sample name.
Returns None for stores built before library-size tracking was added.
Use :func:quantnado.get_library_sizes to get a helpful error in that case.
open
classmethod
¶
Open an existing BAM Zarr store for reading (default) or writing.
Args: store_path: Path to the Zarr store directory. read_only: If True (default), disables all write operations.
Returns: BamStore instance attached to the on-disk store.
Raises: FileNotFoundError: If the store or required attributes are missing. ValueError: If the store is missing required metadata.
Source code in quantnado/dataset/store_bam.py
process_samples
¶
Process BAM files and write signal data to the zarr store.
Samples are processed sequentially to minimise peak memory. Each sample's chromosomes are streamed directly to disk so only a single chromosome's array is ever resident in memory at a time.
Within each sample, chromosome processing is parallelised using
max_workers threads (bamnado releases the GIL).
Source code in quantnado/dataset/store_bam.py
from_bam_files
classmethod
¶
from_bam_files(
bam_files: list[str],
chromsizes: str | Path | dict[str, int] | None = None,
store_path: Path | str | None = None,
metadata: DataFrame
| Path
| str
| list[Path | str]
| None = None,
bam_sample_names: list[str] | None = None,
*,
filter_chromosomes: bool = True,
overwrite: bool = True,
resume: bool = False,
sample_column: str = "sample_id",
chunk_len: int | None = None,
construction_compression: str = DEFAULT_CONSTRUCTION_COMPRESSION,
local_staging: bool = False,
staging_dir: Path | str | None = None,
max_workers: int = 1,
log_file: Path | None = None,
test: bool = False,
stranded: "str | list[str] | dict[str, str] | None" = None,
) -> "BamStore"
Create BamStore from list of BAM files and optionally attach metadata.
If chunk_len is omitted, a filesystem-aware value is derived from quantnado.utils.estimate_chunk_len using the destination store path.
If local_staging is enabled or staging_dir is provided, construction is performed under scratch storage and then published to the final store path.
construction_compression controls build-time compression only and does not affect reader compatibility.
max_workers controls chromosome-level parallelism within each sample. Samples are processed sequentially to keep memory usage low.
Source code in quantnado/dataset/store_bam.py
778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 | |