#!/usr/bin/env python3 """Build the third ten method-blind native-validated Test cases.""" from __future__ import annotations import hashlib import json from pathlib import Path from build_test_batch1_cases import ENV_ROOT, OUT_ROOT, ROOT, base from promote_second_batch_cases import attach_execution_plan, attach_generation_interface, validator PROBE_ROOT = ROOT / "runs/test_136_native_curation/batch3" REVIEW_JSON = ROOT / "data/curation/test_batch3_native_review.json" REVIEW_MD = ROOT / "reports/test_batch3_native_review.md" def build_cases() -> list[dict]: cases: list[dict] = [] reads = "data/fixtures/test_third_batch_reads.fastq" trims = [ ("adapterremoval", "3.0.1", "pl5321h0f5e619_0", "adapterremoval3", "trim_adapters", ["adapterremoval3", "--in-file1", "{input_fastq}", "--out-file1", "{output_fastq}", "--adapter1", "ACGTTGCA", "--min-length", "1", "--threads", "1"]), ("atropos", "1.1.32", "py310h1fe012e_4", "atropos", "trim_adapters", ["atropos", "trim", "-se", "{input_fastq}", "-o", "{output_fastq}", "-a", "ACGTTGCA", "--threads", "2", "--minimum-length", "1"]), ] for package, version, build, executable, endpoint, command in trims: env = ENV_ROOT / f"{package}-{version}-{build}" native = [str(env / f"bin/{executable}"), *command[1:]] case = base(package, version, build, endpoint) case.update({ "fixture_bindings": {"input_fastq": reads}, "arguments": {}, "native": {"environment": str(env), "command": native}, "outputs": {"output_fastq": f"{package}/trimmed.fastq"}, "validators": [validator("output_fastq", "output_fastq", "fastq")], "semantic_oracle": {"kind": "normalized_text_equal", "target": "output_fastq"}, }) attach_generation_interface(case, executable, "trim" if package == "atropos" else None, [ {"name": "input_fastq", "value_type": "path", "required": True, "native_binding": "-se" if package == "atropos" else "--in-file1"}, {"name": "output_fastq", "value_type": "path", "required": True, "native_binding": "-o" if package == "atropos" else "--out-file1"}, ], "The adapter ACGTTGCA, minimum retained length, and thread count are fixed.") attach_execution_plan(case, [{"command": command}]) cases.append(case) env = ENV_ROOT / "trim-galore-2.3.0-hf1b6044_0" case = base("trim-galore", "2.3.0", "hf1b6044_0", "trim_adapters") trim_command = ["trim_galore", "-a", "ACGTTGCA", "-q", "0", "--length", "1", "--cores", "1", "--basename", "trimmed", "--output_dir", "{output_dir}", "{input_fastq}"] case.update({ "fixture_bindings": {"input_fastq": reads}, "arguments": {}, "native": {"environment": str(env), "command": [str(env / "bin/trim_galore"), *trim_command[1:]]}, "outputs": {"output_dir": "trim-galore", "output_fastq": "trim-galore/trimmed_trimmed.fq", "report_json": "trim-galore/test_third_batch_reads.fastq_trimming_report.json"}, "validators": [validator("output_fastq", "output_fastq", "fastq"), validator("report_json", "report_json", "json")], "semantic_oracle": {"kind": "normalized_text_equal", "target": "output_fastq"}, "runner_notes": "output_fastq and report_json are deterministic filenames derived inside output_dir.", }) attach_generation_interface(case, "trim_galore", None, [ {"name": "input_fastq", "value_type": "path", "required": True, "native_binding": "positional"}, {"name": "output_dir", "value_type": "path", "required": True, "native_binding": "--output_dir"}, ], "The adapter, quality threshold, minimum length, basename, and one core are fixed; output files are derived.") attach_execution_plan(case, [{"make_directories": ["output_dir"], "command": trim_command}]) cases.append(case) env = ENV_ROOT / "cdbtools-0.99-h077b44d_12" case = base("cdbtools", "0.99", "h077b44d_12", "extract_fasta_record") case.update({ "fixture_bindings": {"input_fasta": "data/fixtures/reference.fa"}, "arguments": {}, "native": {"environment": str(env), "command": ["bash", "-lc", f"{env / 'bin/cdbfasta'} '{{input_fasta}}' -o '{{index_file}}' && {env / 'bin/cdbyank'} -a chrTiny '{{index_file}}' > '{{output_fasta}}'"]}, "outputs": {"index_file": "cdbtools/reference.cidx", "output_fasta": "cdbtools/extracted.fa"}, "validators": [validator("index_nonempty", "index_file", "nonempty"), validator("output_fasta", "output_fasta", "fasta")], "semantic_oracle": {"kind": "fasta_records_equal", "target": "output_fasta"}, }) attach_generation_interface(case, "cdbfasta", None, [ {"name": "input_fasta", "value_type": "path", "required": True, "native_binding": "positional"}, {"name": "index_file", "value_type": "path", "required": True, "native_binding": "-o"}, {"name": "output_fasta", "value_type": "path", "required": True, "native_binding": "cdbyank stdout"}, ], "Index with cdbfasta, then retrieve the fixed chrTiny key with cdbyank.") attach_execution_plan(case, [ {"command": ["cdbfasta", "{input_fasta}", "-o", "{index_file}"]}, {"command": ["cdbyank", "-a", "chrTiny", "{index_file}"], "capture_stdout_to": "output_fasta"}, ]) cases.append(case) env = ENV_ROOT / "cyvcf2-0.34.0-py310h344de0f_0" case = base("cyvcf2", "0.34.0", "py310h344de0f_0", "read_vcf_records") case.update({ "fixture_bindings": {"input_vcf": "data/fixtures/tabix_variants.vcf.gz", "input_index": "data/fixtures/tabix_variants.vcf.gz.tbi"}, "arguments": {}, "native": {"environment": str(env), "command": ["bash", "-lc", f"{env / 'bin/cyvcf2'} --no-inds '{{input_vcf}}' > '{{output_vcf}}'"]}, "outputs": {"output_vcf": "cyvcf2/records.vcf"}, "validators": [validator("output_vcf", "output_vcf", "vcf")], "semantic_oracle": {"kind": "vcf_records_equal", "target": "output_vcf"}, "runner_notes": "input_index is copied beside input_vcf but is not an endpoint argument.", }) attach_generation_interface(case, "cyvcf2", None, [ {"name": "input_vcf", "value_type": "path", "required": True, "native_binding": "positional"}, {"name": "output_vcf", "value_type": "path", "required": True, "native_binding": "stdout"}, ], "Genotype columns are suppressed; the adjacent tabix index is an implicit fixture dependency.") attach_execution_plan(case, [{"command": ["cyvcf2", "--no-inds", "{input_vcf}"], "capture_stdout_to": "output_vcf"}]) cases.append(case) env = ENV_ROOT / "pyfastx-2.3.1-py310hfe4f656_0" case = base("pyfastx", "2.3.1", "py310hfe4f656_0", "fasta_statistics") case.update({ "fixture_bindings": {"input_fasta": "data/fixtures/reference.fa"}, "arguments": {}, "native": {"environment": str(env), "command": ["bash", "-lc", f"{env / 'bin/pyfastx'} stat '{{input_fasta}}' > '{{output_tsv}}'"]}, "outputs": {"output_tsv": "pyfastx/stat.tsv"}, "validators": [validator("stats_nonempty", "output_tsv", "nonempty"), validator("stats_header", "output_tsv", "regex", pattern=r"^fileName\s+seqType")], "semantic_oracle": {"kind": "normalized_text_equal", "target": "output_tsv"}, }) attach_generation_interface(case, "pyfastx", "stat", [ {"name": "input_fasta", "value_type": "path", "required": True, "native_binding": "positional"}, {"name": "output_tsv", "value_type": "path", "required": True, "native_binding": "stdout"}, ]) attach_execution_plan(case, [{"command": ["pyfastx", "stat", "{input_fasta}"], "capture_stdout_to": "output_tsv"}]) cases.append(case) env = ENV_ROOT / "mash-2.3-hf85e966_11" case = base("mash", "2.3", "hf85e966_11", "sketch_fasta") case.update({ "fixture_bindings": {"input_fasta": "data/fixtures/reference.fa"}, "arguments": {}, "native": {"environment": str(env), "command": ["bash", "-lc", f"{env / 'bin/mash'} sketch -k 6 -s 10 -o '{{output_prefix}}' '{{input_fasta}}' && {env / 'bin/mash'} info -t '{{output_msh}}' > '{{output_info}}'"]}, "outputs": {"output_prefix": "mash/reference", "output_msh": "mash/reference.msh", "output_info": "mash/info.tsv"}, "validators": [validator("sketch_nonempty", "output_msh", "nonempty"), validator("info_nonempty", "output_info", "nonempty"), validator("info_header", "output_info", "regex", pattern=r"^#Hashes\s+Length")], "semantic_oracle": {"kind": "tsv_equal_ignore_columns", "target": "output_info", "ignore_columns": [2]}, "runner_notes": "output_msh is derived by appending .msh to output_prefix; the oracle ignores the path-bearing ID column in mash info.", }) attach_generation_interface(case, "mash", "sketch", [ {"name": "input_fasta", "value_type": "path", "required": True, "native_binding": "positional"}, {"name": "output_prefix", "value_type": "path", "required": True, "native_binding": "-o"}, {"name": "output_info", "value_type": "path", "required": True, "native_binding": "mash info stdout"}, ], "Use fixed k=6 and sketch size=10, then inspect the derived .msh file.") attach_execution_plan(case, [ {"command": ["mash", "sketch", "-k", "6", "-s", "10", "-o", "{output_prefix}", "{input_fasta}"]}, {"command": ["mash", "info", "-t", {"format": "{output_prefix}.msh"}], "capture_stdout_to": "output_info"}, ]) cases.append(case) env = ENV_ROOT / "htseq-2.1.2-py311h0e292b2_3" case = base("htseq", "2.1.2", "py311h0e292b2_3", "count_reads") case.update({ "fixture_bindings": {"input_bam": "data/fixtures/second_batch_alignments.bam", "features_gtf": "data/fixtures/test_third_batch_features.gtf"}, "arguments": {}, "native": {"environment": str(env), "command": [str(env / "bin/htseq-count"), "-f", "bam", "-r", "pos", "-s", "no", "-t", "exon", "-i", "gene_id", "-c", "{output_counts}", "{input_bam}", "{features_gtf}"]}, "outputs": {"output_counts": "htseq/counts.tsv"}, "validators": [validator("counts_nonempty", "output_counts", "nonempty"), validator("gene_a", "output_counts", "regex", pattern=r"^geneA\s+12$")], "semantic_oracle": {"kind": "normalized_text_equal", "target": "output_counts"}, }) attach_generation_interface(case, "htseq-count", None, [ {"name": "input_bam", "value_type": "path", "required": True, "native_binding": "positional"}, {"name": "features_gtf", "value_type": "path", "required": True, "native_binding": "positional"}, {"name": "output_counts", "value_type": "path", "required": True, "native_binding": "-c"}, ], "BAM input, position order, unstranded union counting, exon features, and gene_id grouping are fixed.") attach_execution_plan(case, [{"command": ["htseq-count", "-f", "bam", "-r", "pos", "-s", "no", "-t", "exon", "-i", "gene_id", "-c", "{output_counts}", "{input_bam}", "{features_gtf}"]}]) cases.append(case) env = ENV_ROOT / "freebayes-1.3.10-hbefcdb2_0" case = base("freebayes", "1.3.10", "hbefcdb2_0", "call_variants") case.update({ "fixture_bindings": {"reference_fasta": "data/fixtures/second_batch_reference.fa", "reference_fai": "data/fixtures/second_batch_reference.fa.fai", "input_bam": "data/fixtures/second_batch_alignments.bam", "input_bai": "data/fixtures/second_batch_alignments.bam.bai"}, "arguments": {}, "native": {"environment": str(env), "command": ["bash", "-lc", f"{env / 'bin/freebayes'} -f '{{reference_fasta}}' '{{input_bam}}' > '{{output_vcf}}'"]}, "outputs": {"output_vcf": "freebayes/calls.vcf"}, "validators": [validator("output_vcf", "output_vcf", "vcf")], "semantic_oracle": {"kind": "vcf_records_equal", "target": "output_vcf"}, "runner_notes": "reference_fai and input_bai are adjacent implicit dependencies, not endpoint arguments.", }) attach_generation_interface(case, "freebayes", None, [ {"name": "reference_fasta", "value_type": "path", "required": True, "native_binding": "-f"}, {"name": "input_bam", "value_type": "path", "required": True, "native_binding": "positional"}, {"name": "output_vcf", "value_type": "path", "required": True, "native_binding": "stdout"}, ]) attach_execution_plan(case, [{"command": ["freebayes", "-f", "{reference_fasta}", "{input_bam}"], "capture_stdout_to": "output_vcf"}]) cases.append(case) env = ENV_ROOT / "kmc-3.2.4-h5ca1c30_4" case = base("kmc", "3.2.4", "h5ca1c30_4", "count_kmers") case.update({ "fixture_bindings": {"input_fastq": reads}, "arguments": {}, "native": {"environment": str(env), "command": ["bash", "-lc", f"mkdir -p '{{working_dir}}' && {env / 'bin/kmc'} -k3 -ci1 -t1 -m2 -hp '{{input_fastq}}' '{{output_prefix}}' '{{working_dir}}' && {env / 'bin/kmc_dump'} '{{output_prefix}}' '{{output_tsv}}'"]}, "outputs": {"output_prefix": "kmc/counts", "working_dir": "kmc/tmp", "db_pre": "kmc/counts.kmc_pre", "db_suf": "kmc/counts.kmc_suf", "output_tsv": "kmc/counts.tsv"}, "validators": [validator("db_pre_nonempty", "db_pre", "nonempty"), validator("db_suf_nonempty", "db_suf", "nonempty"), validator("counts_nonempty", "output_tsv", "nonempty")], "semantic_oracle": {"kind": "normalized_text_equal", "target": "output_tsv"}, "runner_notes": "db_pre and db_suf derive from output_prefix; working_dir is scratch space.", }) attach_generation_interface(case, "kmc", None, [ {"name": "input_fastq", "value_type": "path", "required": True, "native_binding": "positional"}, {"name": "output_prefix", "value_type": "path", "required": True, "native_binding": "positional"}, {"name": "working_dir", "value_type": "path", "required": True, "native_binding": "positional"}, {"name": "output_tsv", "value_type": "path", "required": True, "native_binding": "kmc_dump positional"}, ], "Count canonical 3-mers with minimum count 1, one thread, and 2 GB memory, then dump text counts.") attach_execution_plan(case, [ {"make_directories": ["working_dir"], "command": ["kmc", "-k3", "-ci1", "-t1", "-m2", "-hp", "{input_fastq}", "{output_prefix}", "{working_dir}"]}, {"command": ["kmc_dump", "{output_prefix}", "{output_tsv}"]}, ]) cases.append(case) return cases def main() -> int: cases = build_cases() OUT_ROOT.mkdir(parents=True, exist_ok=True) for case in cases: (OUT_ROOT / f"{case['package']}.json").write_text(json.dumps(case, ensure_ascii=False, indent=2) + "\n", encoding="utf-8") evidence = [] for case in cases: files = [] for path in sorted((PROBE_ROOT / case["package"]).glob("*")): if path.is_file() and path.stat().st_size: files.append({"path": str(path.relative_to(ROOT)), "size": path.stat().st_size, "sha256": hashlib.sha256(path.read_bytes()).hexdigest()}) evidence.append({"package": case["package"], "case_id": case["case_id"], "endpoint": case["endpoint"], "environment": case["native"]["environment"], "native_command": case["native"]["command"], "validators": case["validators"], "semantic_oracle": case["semantic_oracle"], "outputs": files, "review_decision": "pending"}) payload = {"scope": "test_batch3_method_blind_native_review", "case_count": len(cases), "method_generation_started": False, "cases": evidence} REVIEW_JSON.parent.mkdir(parents=True, exist_ok=True) REVIEW_JSON.write_text(json.dumps(payload, ensure_ascii=False, indent=2) + "\n", encoding="utf-8") lines = ["# Test batch 3 native review", "", "No Direct Prompt or Contract IR artifact was generated before this review.", "", "| Package | Endpoint | Native outputs | Decision |", "|---|---|---:|---|"] for row in evidence: lines.append(f"| {row['package']} | `{row['endpoint']}` | {len(row['outputs'])} | pending |") REVIEW_MD.parent.mkdir(parents=True, exist_ok=True) REVIEW_MD.write_text("\n".join(lines) + "\n", encoding="utf-8") print(json.dumps({"cases": len(cases), "review_json": str(REVIEW_JSON), "review_md": str(REVIEW_MD)}, indent=2)) return 0 if __name__ == "__main__": raise SystemExit(main())