Download patch_v2.py from karatedava/peptidetab-transfer: direct link, hf CLI and curl.
- Browser
- Download file 1.97 kB
-
https://huggingface.co/datasets/karatedava/peptidetab-transfer/resolve/main/patch_v2.py
- Command line
-
hf download hf://datasets/karatedava/peptidetab-transfer/patch_v2.py
-
curl -L -o patch_v2.py https://huggingface.co/datasets/karatedava/peptidetab-transfer/resolve/main/patch_v2.py
1.97 kB
| 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) | |