diff --git a/docs/02a-m2-pdb-evidence.md b/docs/02a-m2-pdb-evidence.md index db5b311..8fe8a44 100644 --- a/docs/02a-m2-pdb-evidence.md +++ b/docs/02a-m2-pdb-evidence.md @@ -408,6 +408,7 @@ Written to `runs//m2_pdb/`: | `proteins.tsv` | every protein, all score components, best hit, rank, selected, reason, retrieval status | | `top50.tsv` | the selected set | | `no_pdb_hit.tsv` | proteins with no qualifying hit — the input to the Foldseek step (issue #9) | +| `pdb_search_failed.tsv` | proteins whose PDB search failed — neither a hit nor a miss; `counts.pdb_search_failed` in `run.json` and the stdout summary report them (issue #69) | | `run.json` | timestamps, parameters, weights, endpoints, counts, cache path, and every failed query with its error | ## Scoring profiles diff --git a/s2f/m2_triage/__main__.py b/s2f/m2_triage/__main__.py index 25e5ce7..ce83b18 100644 --- a/s2f/m2_triage/__main__.py +++ b/s2f/m2_triage/__main__.py @@ -752,6 +752,11 @@ def run(args: argparse.Namespace) -> int: _write_tsv(out_dir / "hits.tsv", HIT_COLUMNS, hit_rows) _write_tsv(out_dir / f"top{args.top}.tsv", columns, [r for r in protein_rows if r["selected"]]) _write_tsv(out_dir / "no_pdb_hit.tsv", columns, [r for r in protein_rows if r["no_pdb_hit"]]) + # A failed search is not a miss (docs/02a), so it gets its own table rather than + # vanishing from both (#69). + _write_tsv( + out_dir / "pdb_search_failed.tsv", columns, [r for r in protein_rows if r["pdb_search_failed"]] + ) status_counts: dict[str, int] = {} for score in ranked: @@ -874,6 +879,7 @@ def run(args: argparse.Namespace) -> int: "selected": sum(1 for r in protein_rows if r["selected"]), "disqualified_human_homolog": sum(1 for s in ranked if s.disqualified), "no_pdb_hit": sum(1 for r in protein_rows if r["no_pdb_hit"]), + "pdb_search_failed": sum(1 for r in protein_rows if r["pdb_search_failed"]), "retrieval_status": status_counts, "specialty_rows_without_protein": len(bundle.specialty_without_protein), "table_rows_without_sequence": len(bundle.table_rows_without_sequence), @@ -936,14 +942,22 @@ def run(args: argparse.Namespace) -> int: } (out_dir / "run.json").write_text(json.dumps(manifest, indent=2) + "\n", encoding="utf-8") - print( + counts = manifest["counts"] + summary = ( f"{len(ranked)} proteins scored from {len(sequences)} unique sequences; " - f"{manifest['counts']['selected']} selected, {manifest['counts']['no_pdb_hit']} without a PDB hit." + f"{counts['selected']} selected, {counts['no_pdb_hit']} without a PDB hit" ) + if counts["pdb_search_failed"]: + # Failed proteins are neither hits nor misses; say so in the same line (#69). + summary += f", {counts['pdb_search_failed']} not known (PDB search failed)" + print(summary + ".") print(f"Wrote {out_dir}") failed = len(manifest["failures"]["search"]) if failed: - print(f"Warning: {failed} sequence searches failed (recorded as query-failed in run.json).") + print( + f"Warning: {failed} sequence searches failed, covering {counts['pdb_search_failed']} proteins " + "(recorded as query-failed in run.json and listed in pdb_search_failed.tsv)." + ) return 0 diff --git a/tests/test_m2_dry_run.py b/tests/test_m2_dry_run.py index b6b6e29..eb25993 100644 --- a/tests/test_m2_dry_run.py +++ b/tests/test_m2_dry_run.py @@ -88,3 +88,31 @@ def test_limit_restricts_work_without_breaking_the_manifest(tmp_path: Path) -> N assert manifest["counts"]["proteins_loaded"] == 4 assert manifest["counts"]["proteins_scored"] == 1 assert manifest["parameters"]["limit"] == 1 + + +def test_every_failed_search_is_counted_not_hidden(tmp_path: Path, capsys) -> None: + # An empty cache in offline mode: every sequence search fails (#69). + run_dir = tmp_path / "run" + assert main(["--dry-run", "--run", str(run_dir), "--cache", str(tmp_path / "cold.sqlite")]) == 0 + + out = run_dir / "m2_pdb" + manifest = json.loads((out / "run.json").read_text()) + counts = manifest["counts"] + assert len(manifest["failures"]["search"]) == counts["unique_sequences"] == 3 + # A failed search is never a miss, but it is counted. + assert counts["no_pdb_hit"] == 0 + assert counts["pdb_search_failed"] == counts["proteins_scored"] == 4 + assert len(_read_tsv(out / "pdb_search_failed.tsv")) == 4 + assert _read_tsv(out / "no_pdb_hit.tsv") == [] + + summary = next(line for line in capsys.readouterr().out.splitlines() if "proteins scored" in line) + assert "0 without a PDB hit, 4 not known (PDB search failed)" in summary + + +def test_a_clean_run_reports_no_failed_searches(tmp_path: Path, capsys) -> None: + run_dir = tmp_path / "run" + main(["--dry-run", "--run", str(run_dir)]) + counts = json.loads((run_dir / "m2_pdb" / "run.json").read_text())["counts"] + assert counts["pdb_search_failed"] == 0 + assert _read_tsv(run_dir / "m2_pdb" / "pdb_search_failed.tsv") == [] + assert "search failed" not in capsys.readouterr().out