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.
This commit is contained in:
Tom Kasper
2026-11-03 21:02:19 +01:00
parent 87c64278ba
commit 86af080e87
2 changed files with 34 additions and 0 deletions
+1
View File
@@ -438,6 +438,7 @@ def extract_store(cfg: ExtractConfig, labels: pl.DataFrame, out_dir: Path) -> Pa
labels, cfg.exclude_refs, cfg.exclude_genera labels, cfg.exclude_refs, cfg.exclude_genera
) )
out_dir = Path(out_dir) out_dir = Path(out_dir)
out_dir.mkdir(parents=True, exist_ok=True)
dropped.write_parquet(out_dir / EXCLUDED_NAME) dropped.write_parquet(out_dir / EXCLUDED_NAME)
excluded_ids = set(dropped["read_id"].to_list()) excluded_ids = set(dropped["read_id"].to_list())
labelled = labelled.filter(pl.col("genus").is_not_null() & (pl.col("genus") != "")) labelled = labelled.filter(pl.col("genus").is_not_null() & (pl.col("genus") != ""))
+33
View File
@@ -180,6 +180,39 @@ def test_filter_excluded() -> None:
assert counts4["n_rows_out"] == 5 and "reason" in dropped4.columns 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: def test_config_roundtrip(tmp_path: Path) -> None:
cfg = RunConfig( cfg = RunConfig(
run_id="cnn_1.0M_s4_g11", run_id="cnn_1.0M_s4_g11",