File size: 1,974 Bytes
a22c3c7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os, ast

# ---- part3: env caps + precomputed clusters (idempotent) ----
p3 = "scripts/run_part3_validation.py"
s = open(p3).read()
if "PT_CLUSTERS_CSV" not in s:
    assert "MAX_EMB = 6000" in s, "MAX_EMB line not found"
    s = s.replace(
        "MAX_EMB = 6000",
        'MAX_EMB = int(os.environ.get("PT_MAX_EMB", "6000"))\n'
        'CLUSTERS_CSV = os.environ.get("PT_CLUSTERS_CSV", "")')
    needle = ('    seq_to_cluster, method = M.assign_clusters(all_seqs, '
              'method="cd-hit", identity=IDENTITY)')
    assert needle in s, "cluster call not found"
    repl = (
        "    if CLUSTERS_CSV and os.path.exists(CLUSTERS_CSV):\n"
        "        _c = pd.read_csv(CLUSTERS_CSV)\n"
        "        seq_to_cluster = dict(zip(_c['sequence'], _c['cluster_id']))\n"
        "        _n = max(seq_to_cluster.values()) + 1\n"
        "        for _x in all_seqs:\n"
        "            if _x not in seq_to_cluster:\n"
        "                seq_to_cluster[_x] = _n\n"
        "                _n += 1\n"
        "        method = 'cd-hit@0.9-precomputed'\n"
        "    else:\n"
        "        seq_to_cluster, method = M.assign_clusters(all_seqs, method='cd-hit', identity=IDENTITY)")
    s = s.replace(needle, repl, 1)
ast.parse(s)
open(p3, "w").write(s)

# ---- external: env caps (idempotent) ----
p4 = "scripts/run_external_validation.py"
s4 = open(p4).read()
if "PT_MAX_TRAIN_EMB" not in s:
    assert "MAX_TRAIN_EMB = 8000" in s and "MAX_TEST_EMB = 1800" in s
    s4 = s4.replace("MAX_TRAIN_EMB = 8000",
                    'MAX_TRAIN_EMB = int(os.environ.get("PT_MAX_TRAIN_EMB", "8000"))')
    s4 = s4.replace("MAX_TEST_EMB = 1800",
                    'MAX_TEST_EMB = int(os.environ.get("PT_MAX_TEST_EMB", "1800"))')
ast.parse(s4)
open(p4, "w").write(s4)

print("part3:", "PT_CLUSTERS_CSV" in s, "PT_MAX_EMB" in s, flush=True)
print("external:", "PT_MAX_TRAIN_EMB" in s4, "PT_MAX_TEST_EMB" in s4, flush=True)
print("PATCH_OK", flush=True)