File size: 5,402 Bytes
6301da1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e1388bd
 
 
 
 
6301da1
 
 
 
 
 
 
 
 
 
 
1cb676d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6301da1
 
 
 
 
 
 
e1388bd
 
6301da1
 
 
 
 
 
 
e1388bd
 
 
 
6301da1
 
 
 
 
 
 
 
e1388bd
 
6301da1
 
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
"""Make `biotool` reachable from inside an agent's workspace.

The harnesses this targets -- codex, Biomni, our own loop -- give the model a shell and
nothing else, so a tool is only usable if it is on PATH in the working directory. This
writes a small launcher rather than requiring an installed package, which keeps the
integration harness-agnostic: any agent that can run a command can reach the tools.

The launcher pins the interpreter and the source paths, because an agent's shell inherits
whatever environment the harness happened to set, and the benchmark's own solver commonly
creates and activates its own conda environment mid-run.
"""

from __future__ import annotations

import os
import stat
from pathlib import Path

RESEARCH_ROOT = Path(__file__).resolve().parent.parent
DEFAULT_PYTHON = "/home/pengchx3/envs/genebench-sandbox/bin/python"
DEFAULT_C2S_SRC = "/home/pengchx3/text-dna/scdistill/repos/cell2sentence/src"

LAUNCHER = """#!/bin/bash
# Auto-generated by vera.install_tools. Runs the structured biological tools with a
# pinned interpreter, so an agent that switches conda environments mid-run keeps access.
export PYTHONPATH="{research}:${{PYTHONPATH:-}}"
export C2S_SRC="${{C2S_SRC:-{c2s}}}"
# The user's profile points every HF_* variable at a path this job may not be able to
# write; set them together or the override is silently ignored.
CACHE="${{VERA_CACHE:-{cache}}}"
mkdir -p "$CACHE" 2>/dev/null || true
export HF_HOME="$CACHE" HF_HUB_CACHE="$CACHE/hub" HUGGINGFACE_HUB_CACHE="$CACHE/hub"
export HF_DATASETS_CACHE="$CACHE/datasets" HF_ASSETS_CACHE="$CACHE/assets"
export CELLTYPIST_FOLDER="$CACHE/celltypist"
# The experimental arm is baked in at install time, not inherited. The agent runs inside
# a sandbox whose environment the harness does not fully control, so a variable that
# merely "should propagate" would leave the A/B silently measuring nothing -- the exact
# failure class this work is about.
export BIOTOOL_CONFIDENT="{confident}"
exec "{python}" -m vera.biotool "$@"
"""

PROMPT = """A `biotool` command is available in your working directory. It gives you
structured biological tools and pretrained models that the shell alone does not:

  ./biotool list                       show every available tool and model
  ./biotool call <name> '<json args>'  gene, sequence, pathway and structure annotation
  ./biotool taxonomy --fasta F         identify the source organism of sequences by BLAST
  ./biotool celltype --matrix DIR      cell-type composition from expression, using two
                                       independent models, with species auto-detected
  ./biotool references                 reference genomes already staged and indexed here
  ./biotool align --fastq F            align a read sample and report the top loci
  ./biotool breakpoints --fastq R1 R2  align the full library and report, at base
                                       resolution, where reads stop matching the
                                       reference: cut sites, fusion junctions,
                                       integration sites, structural breakpoints
  ./biotool variants --fastq R1 R2     substitutions the reads support, each with its
                     --region chr:a-b  depth and allele fraction, ranked by support

The references listed by `./biotool references` are already indexed, so `breakpoints`
skips the download and the index build.

`breakpoints` reports positions to the base and `variants` reports allele fractions
against the depth actually observed; both are covered by tests, so prefer them over a
hand-written pileup when a coordinate or a variant call has to be exact.

Both report a `competence` field. When it says INCONCLUSIVE the tool is telling you the
evidence does not separate the candidates, and the remaining work is yours -- not that
the top row is the answer.

Dataset, accession and literature lookups are deliberately absent: this benchmark requires
you to solve the problem from the data you were given, and tools that would identify the
source study are blocked."""


def install(workspace: Path, python: str = DEFAULT_PYTHON,
            c2s_src: str = DEFAULT_C2S_SRC, cache: str | None = None,
            confident: bool = False) -> Path:
    """Write an executable `biotool` launcher into `workspace`.

    Args:
        workspace: The agent's working directory.
        python: Interpreter that has the dependencies. Pinned rather than inherited.
        c2s_src: Vendored Cell2Sentence source.
        cache: Writable cache root for model downloads.
        confident: Select the CONFIDENT arm, in which tools report findings alone as
            conventional tool APIs do. The default reports blind spots as well. Written
            into the launcher rather than inherited, so the arm is a property of the
            installed workspace and can be verified by reading it.

    Returns:
        Path to the launcher.
    """
    cache = cache or os.environ.get(
        "VERA_CACHE", "/tmp/galaxy_srv_disk00/pengchx3/hf_biotool")
    target = Path(workspace) / "biotool"
    target.write_text(LAUNCHER.format(research=RESEARCH_ROOT, python=python,
                                      c2s=c2s_src, cache=cache,
                                      confident="1" if confident else "0"))
    target.chmod(target.stat().st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
    return target