File size: 14,573 Bytes
360b3dd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/usr/bin/env python3
"""Build the second 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/batch2"
REVIEW_JSON = ROOT / "data/curation/test_batch2_native_review.json"
REVIEW_MD = ROOT / "reports/test_batch2_native_review.md"


def build_cases() -> list[dict]:
    cases: list[dict] = []

    for package, version, build, executable, endpoint, command in [
        ("bedtools", "2.31.1", "h13024bc_3", "bedtools", "intersect_bed", ["bedtools", "intersect", "-a", "{input_a}", "-b", "{input_b}"]),
        ("bedops", "2.4.42", "hd6d6fdc_1", "bedops", "intersect_bed", ["bedops", "--intersect", "{input_a}", "{input_b}"]),
    ]:
        env = ENV_ROOT / f"{package}-{version}-{build}"
        case = base(package, version, build, endpoint)
        case.update({
            "fixture_bindings": {"input_a": "data/fixtures/regions_a.bed", "input_b": "data/fixtures/regions_b.bed"},
            "arguments": {},
            "native": {"environment": str(env), "command": ["bash", "-lc", " ".join([str(env / f"bin/{executable}"), *command[1:]]) + " > '{output_file}'"]},
            "outputs": {"output_file": f"{package}/intersections.bed"},
            "validators": [validator("output_nonempty", "output_file", "nonempty"), validator("output_bed", "output_file", "bed")],
            "semantic_oracle": {"kind": "normalized_text_equal", "target": "output_file"},
        })
        attach_generation_interface(case, executable, "intersect" if package == "bedtools" else None, [
            {"name": "input_a", "value_type": "path", "required": True, "native_binding": "-a" if package == "bedtools" else "positional"},
            {"name": "input_b", "value_type": "path", "required": True, "native_binding": "-b" if package == "bedtools" else "positional"},
            {"name": "output_file", "value_type": "path", "required": True, "native_binding": "stdout"},
        ], "The deterministic intersection is captured from stdout.")
        attach_execution_plan(case, [{"command": command, "capture_stdout_to": "output_file"}])
        cases.append(case)

    env = ENV_ROOT / "cutadapt-5.2-py311hc303176_2"
    case = base("cutadapt", "5.2", "py311hc303176_2", "trim_front_adapter")
    case.update({
        "fixture_bindings": {"input_fastq": "data/fixtures/crispresso_reads.fastq"}, "arguments": {},
        "native": {"environment": str(env), "command": [str(env / "bin/cutadapt"), "-g", "^ACGTTGCA", "-o", "{output_fastq}", "{input_fastq}"]},
        "outputs": {"output_fastq": "cutadapt/trimmed.fastq"},
        "validators": [validator("output_fastq", "output_fastq", "fastq")],
        "semantic_oracle": {"kind": "normalized_text_equal", "target": "output_fastq"},
    })
    attach_generation_interface(case, "cutadapt", None, [
        {"name": "input_fastq", "value_type": "path", "required": True, "native_binding": "positional"},
        {"name": "output_fastq", "value_type": "path", "required": True, "native_binding": "-o"},
    ], "The anchored front adapter ^ACGTTGCA is fixed by the endpoint.")
    attach_execution_plan(case, [{"command": ["cutadapt", "-g", "^ACGTTGCA", "-o", "{output_fastq}", "{input_fastq}"]}])
    cases.append(case)

    env = ENV_ROOT / "fastp-1.3.6-h43da1c4_0"
    case = base("fastp", "1.3.6", "h43da1c4_0", "preprocess_reads")
    case.update({
        "fixture_bindings": {"input_fastq": "data/fixtures/crispresso_reads.fastq"}, "arguments": {},
        "native": {"environment": str(env), "command": [str(env / "bin/fastp"), "-i", "{input_fastq}", "-o", "{output_fastq}", "--json", "{report_json}", "--html", "{report_html}", "--thread", "1", "--disable_adapter_trimming", "--disable_quality_filtering", "--length_required", "1"]},
        "outputs": {"output_fastq": "fastp/cleaned.fastq", "report_json": "fastp/report.json", "report_html": "fastp/report.html"},
        "validators": [validator("output_fastq", "output_fastq", "fastq"), validator("report_json", "report_json", "json"), validator("report_html", "report_html", "nonempty")],
        "semantic_oracle": {"kind": "normalized_text_equal", "target": "output_fastq"},
    })
    attach_generation_interface(case, "fastp", None, [
        {"name": "input_fastq", "value_type": "path", "required": True, "native_binding": "-i"},
        {"name": "output_fastq", "value_type": "path", "required": True, "native_binding": "-o"},
        {"name": "report_json", "value_type": "path", "required": True, "native_binding": "--json"},
        {"name": "report_html", "value_type": "path", "required": True, "native_binding": "--html"},
    ], "Single-threaded minimal filtering is fixed; adapter and quality filtering are disabled.")
    attach_execution_plan(case, [{"command": ["fastp", "-i", "{input_fastq}", "-o", "{output_fastq}", "--json", "{report_json}", "--html", "{report_html}", "--thread", "1", "--disable_adapter_trimming", "--disable_quality_filtering", "--length_required", "1"]}])
    cases.append(case)

    env = ENV_ROOT / "minimap2-2.31-h118bc1c_0"
    case = base("minimap2", "2.31", "h118bc1c_0", "align_dna")
    case.update({
        "fixture_bindings": {"reference_file": "data/fixtures/dna_reference.fa", "query_file": "data/fixtures/dna_queries.fa"}, "arguments": {},
        "native": {"environment": str(env), "command": ["bash", "-lc", f"{env / 'bin/minimap2'} -a -t 1 '{{reference_file}}' '{{query_file}}' > '{{output_sam}}'"]},
        "outputs": {"output_sam": "minimap2/alignments.sam"},
        "validators": [validator("output_sam", "output_sam", "sam")],
        "semantic_oracle": {"kind": "sam_records_equal", "target": "output_sam"},
    })
    attach_generation_interface(case, "minimap2", None, [
        {"name": "reference_file", "value_type": "path", "required": True, "native_binding": "positional"},
        {"name": "query_file", "value_type": "path", "required": True, "native_binding": "positional"},
        {"name": "output_sam", "value_type": "path", "required": True, "native_binding": "stdout"},
    ], "SAM mode and one thread are fixed; SAM headers are ignored by the semantic oracle.")
    attach_execution_plan(case, [{"command": ["minimap2", "-a", "-t", "1", "{reference_file}", "{query_file}"], "capture_stdout_to": "output_sam"}])
    cases.append(case)

    env = ENV_ROOT / "mosdepth-0.3.14-h05c3d44_1"
    case = base("mosdepth", "0.3.14", "h05c3d44_1", "coverage_summary")
    case.update({
        "fixture_bindings": {"input_bam": "data/fixtures/second_batch_alignments.bam", "input_bai": "data/fixtures/second_batch_alignments.bam.bai"}, "arguments": {},
        "native": {"environment": str(env), "command": [str(env / "bin/mosdepth"), "-n", "-t", "1", "{output_prefix}", "{input_bam}"]},
        "outputs": {"output_prefix": "mosdepth/coverage", "summary_file": "mosdepth/coverage.mosdepth.summary.txt", "distribution_file": "mosdepth/coverage.mosdepth.global.dist.txt"},
        "validators": [validator("summary_nonempty", "summary_file", "nonempty"), validator("distribution_nonempty", "distribution_file", "nonempty")],
        "semantic_oracle": {"kind": "normalized_text_equal", "target": "summary_file"},
        "runner_notes": "input_bai and the two derived text outputs are not endpoint arguments.",
    })
    attach_generation_interface(case, "mosdepth", None, [
        {"name": "input_bam", "value_type": "path", "required": True, "native_binding": "positional"},
        {"name": "output_prefix", "value_type": "path", "required": True, "native_binding": "positional"},
    ], "No per-base output and one thread are fixed; summary/distribution filenames derive from output_prefix.")
    attach_execution_plan(case, [{"command": ["mosdepth", "-n", "-t", "1", "{output_prefix}", "{input_bam}"]}])
    cases.append(case)

    env = ENV_ROOT / "emboss-6.6.0-h0f19ade_14"
    case = base("emboss", "6.6.0", "h0f19ade_14", "convert_fasta")
    case.update({
        "fixture_bindings": {"input_file": "data/fixtures/proteins_multi.faa"}, "arguments": {},
        "native": {"environment": str(env), "command": [str(env / "bin/seqret"), "-sequence", "{input_file}", "-outseq", "{output_file}", "-auto"]},
        "outputs": {"output_file": "emboss/output.faa"},
        "validators": [validator("output_fasta", "output_file", "fasta")],
        "semantic_oracle": {"kind": "fasta_records_equal", "target": "output_file"},
    })
    attach_generation_interface(case, "seqret", None, [
        {"name": "input_file", "value_type": "path", "required": True, "native_binding": "-sequence"},
        {"name": "output_file", "value_type": "path", "required": True, "native_binding": "-outseq"},
    ], "Automatic non-interactive mode is fixed; the case environment PATH is required by the packaged wrapper.")
    attach_execution_plan(case, [{"command": ["seqret", "-sequence", "{input_file}", "-outseq", "{output_file}", "-auto"]}])
    cases.append(case)

    env = ENV_ROOT / "gffread-0.12.9-hf426362_0"
    case = base("gffread", "0.12.9", "hf426362_0", "extract_transcripts")
    case.update({
        "fixture_bindings": {"annotation_file": "data/fixtures/test_transcript_model.gff3", "reference_file": "data/fixtures/reference.fa"}, "arguments": {},
        "native": {"environment": str(env), "command": [str(env / "bin/gffread"), "{annotation_file}", "-g", "{reference_file}", "-w", "{output_fasta}"]},
        "outputs": {"output_fasta": "gffread/transcripts.fa"},
        "validators": [validator("output_fasta", "output_fasta", "fasta")],
        "semantic_oracle": {"kind": "fasta_records_equal", "target": "output_fasta"},
    })
    attach_generation_interface(case, "gffread", None, [
        {"name": "annotation_file", "value_type": "path", "required": True, "native_binding": "positional"},
        {"name": "reference_file", "value_type": "path", "required": True, "native_binding": "-g"},
        {"name": "output_fasta", "value_type": "path", "required": True, "native_binding": "-w"},
    ])
    attach_execution_plan(case, [{"command": ["gffread", "{annotation_file}", "-g", "{reference_file}", "-w", "{output_fasta}"]}])
    cases.append(case)

    env = ENV_ROOT / "htslib-1.24-ha79157c_0"
    case = base("htslib", "1.24", "ha79157c_0", "bgzip_compress")
    case.update({
        "fixture_bindings": {"input_file": "data/fixtures/reference.fa"}, "arguments": {},
        "native": {"environment": str(env), "command": ["bash", "-lc", f"{env / 'bin/bgzip'} -c '{{input_file}}' > '{{output_gzip}}'"]},
        "outputs": {"output_gzip": "htslib/reference.fa.gz"},
        "validators": [validator("output_nonempty", "output_gzip", "nonempty"), validator("valid_gzip", "output_gzip", "gzip")],
        "semantic_oracle": {"kind": "gzip_content_equal", "target": "output_gzip"},
    })
    attach_generation_interface(case, "bgzip", None, [
        {"name": "input_file", "value_type": "path", "required": True, "native_binding": "positional"},
        {"name": "output_gzip", "value_type": "path", "required": True, "native_binding": "stdout"},
    ], "Compressed bytes may contain container metadata; the oracle compares decompressed content.")
    attach_execution_plan(case, [{"command": ["bgzip", "-c", "{input_file}"], "capture_stdout_to": "output_gzip", "stdout_mode": "binary"}])
    cases.append(case)

    env = ENV_ROOT / "vt-2015.11.10-h5ef6573_4"
    case = base("vt", "2015.11.10", "h5ef6573_4", "normalize_vcf")
    case.update({
        "fixture_bindings": {"input_vcf": "data/fixtures/variants.vcf", "reference_file": "data/fixtures/reference.fa"}, "arguments": {},
        "native": {"environment": str(env), "command": [str(env / "bin/vt"), "normalize", "{input_vcf}", "-r", "{reference_file}", "-o", "{output_vcf}"]},
        "outputs": {"output_vcf": "vt/normalized.vcf"},
        "validators": [validator("output_vcf", "output_vcf", "vcf")],
        "semantic_oracle": {"kind": "vcf_records_equal", "target": "output_vcf"},
    })
    attach_generation_interface(case, "vt", "normalize", [
        {"name": "input_vcf", "value_type": "path", "required": True, "native_binding": "positional"},
        {"name": "reference_file", "value_type": "path", "required": True, "native_binding": "-r"},
        {"name": "output_vcf", "value_type": "path", "required": True, "native_binding": "-o"},
    ])
    attach_execution_plan(case, [{"command": ["vt", "normalize", "{input_vcf}", "-r", "{reference_file}", "-o", "{output_vcf}"]}])
    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_batch2_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 2 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())