From 86af080e87203e7399943aab82aefb74c3ff4f38 Mon Sep 17 00:00:00 2001 From: Tom Kasper Date: Tue, 3 Nov 2026 21:02:19 +0100 Subject: [PATCH] Create store out_dir before writing excluded_reads.parquet extract_store wrote the excluded-reads parquet before the shard writer created the output directory, so any fresh --out path failed with 'No such file or directory'. Add the mkdir (the docstring already promised 'created as needed') plus a regression test. --- src/custom_models/store.py | 1 + tests/test_pipeline.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/custom_models/store.py b/src/custom_models/store.py index 770b024..6bc9da8 100644 --- a/src/custom_models/store.py +++ b/src/custom_models/store.py @@ -438,6 +438,7 @@ def extract_store(cfg: ExtractConfig, labels: pl.DataFrame, out_dir: Path) -> Pa labels, cfg.exclude_refs, cfg.exclude_genera ) out_dir = Path(out_dir) + out_dir.mkdir(parents=True, exist_ok=True) dropped.write_parquet(out_dir / EXCLUDED_NAME) excluded_ids = set(dropped["read_id"].to_list()) labelled = labelled.filter(pl.col("genus").is_not_null() & (pl.col("genus") != "")) diff --git a/tests/test_pipeline.py b/tests/test_pipeline.py index 9a41490..271eeed 100644 --- a/tests/test_pipeline.py +++ b/tests/test_pipeline.py @@ -180,6 +180,39 @@ def test_filter_excluded() -> None: assert counts4["n_rows_out"] == 5 and "reason" in dropped4.columns +def test_extract_store_creates_missing_out_dir(tmp_path: Path) -> None: + """Regression: extract_store must create out_dir before writing artifacts. + + The excluded-reads parquet is written before the shard writer gets to + mkdir; a fresh nested --out used to die with "No such file or directory". + """ + import polars as pl + + from custom_models.store import EXCLUDED_NAME, ExtractConfig, extract_store + + labels = pl.DataFrame( + { + "read_id": ["r1"], + "ref_name": ["DCS_Lambda"], + "genus": ["escherichia"], + "species": ["escherichia_coli"], + "identity": [0.99], + "aligned_len": [1000], + "query_len": [1000], + "source_run": ["run1"], + } + ) + cfg = ExtractConfig( + pod5_paths=(tmp_path / "never-read.pod5",), exclude_refs=("dcs",) + ) + # the only labelled read is excluded -> zero usable reads; the ValueError + # fires after the (previously failing) excluded_reads.parquet write + with pytest.raises(ValueError, match="non-null genus"): + extract_store(cfg, labels, tmp_path / "nested" / "store") + assert (tmp_path / "nested" / "store").is_dir() + assert (tmp_path / "nested" / "store" / EXCLUDED_NAME).is_file() + + def test_config_roundtrip(tmp_path: Path) -> None: cfg = RunConfig( run_id="cnn_1.0M_s4_g11",