1) 4 个生成器工作区根改为按 __file__ 推导 + CLOUDLAB_ROOT 覆盖,兑现解压即用 2) 顶层顺序执行脚本加 import 防护,避免误加载重写门户/清单 3) 修复 2 处 SyntaxWarning,收紧隐藏文件排除判断 4) 新增 校验归档.py / 修订记录.json / 根 .gitignore / .gitattributes 5) 补齐归档说明与规划文档的诚实边界与状态更新
119 lines
5.2 KiB
Python
119 lines
5.2 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
"""环境 / 数据 / 模块自检。运行:python verify.py"""
|
||
import sys
|
||
from pathlib import Path
|
||
|
||
ROOT = Path(__file__).resolve().parent
|
||
sys.path.insert(0, str(ROOT))
|
||
|
||
ok_all = True
|
||
|
||
|
||
def chk(label, cond, extra=""):
|
||
global ok_all
|
||
flag = "OK " if cond else "FAIL"
|
||
if not cond:
|
||
ok_all = False
|
||
print(f" [{flag}] {label}" + (f" {extra}" if extra else ""))
|
||
return cond
|
||
|
||
|
||
def main():
|
||
print("=" * 62)
|
||
print(" InSilicoLab 环境自检")
|
||
print("=" * 62)
|
||
print("\n1) Python 与依赖")
|
||
chk("Python >= 3.8", sys.version_info >= (3, 8), sys.version.split()[0])
|
||
for mod, required in (("numpy", True), ("matplotlib", True),
|
||
("scipy", False), ("Bio", False), ("pandas", False)):
|
||
try:
|
||
m = __import__(mod)
|
||
chk(f"{mod}({'必需' if required else '可选增强'})", True,
|
||
getattr(m, "__version__", ""))
|
||
except ImportError:
|
||
chk(f"{mod}({'必需' if required else '可选增强'})", not required,
|
||
"缺失,将使用纯 Python 降级实现" if not required else "请 pip install")
|
||
|
||
print("\n2) 内置数据完整性")
|
||
D = ROOT / "data"
|
||
need = ["HBB_cds.fasta", "HBB_HbS_cds.fasta", "HBB_WT_prot.fasta",
|
||
"HBB_HbS_prot.fasta", "HBB_WT_beta_1A00.pdb", "HBB_HbS_beta_2HBS.pdb",
|
||
"1CRN.pdb", "mini_genome.fasta", "BLOSUM62.txt"]
|
||
for f in need:
|
||
chk(f"data/{f}", (D / f).exists() and (D / f).stat().st_size > 0,
|
||
f"{(D / f).stat().st_size} B" if (D / f).exists() else "")
|
||
|
||
print("\n3) 关键数据内容校验(防止编号/解析错位)")
|
||
from insilicolab import read_fasta, data_path
|
||
cds = read_fasta(data_path("HBB_cds.fasta"))[0][1]
|
||
hbs = read_fasta(data_path("HBB_HbS_cds.fasta"))[0][1]
|
||
chk("HBB CDS 长度 444 nt", len(cds) == 444, str(len(cds)))
|
||
chk("c.20 为 A 且位于 GAG 密码子", cds[18:21] == "GAG" and cds[19] == "A")
|
||
chk("HbS 为 c.20A>T / GTG", hbs[18:21] == "GTG" and hbs[19] == "T")
|
||
from insilicolab.seq import translate
|
||
chk("翻译 E6V 正确", translate(cds, to_stop=True)[6] == "E" and
|
||
translate(hbs, to_stop=True)[6] == "V")
|
||
from insilicolab.structure import read_pdb
|
||
wt = read_pdb(data_path("HBB_WT_beta_1A00.pdb"))
|
||
hb = read_pdb(data_path("HBB_HbS_beta_2HBS.pdb"))
|
||
d6w = {r["id"]: r["name"] for r in wt}.get(6)
|
||
d6h = {r["id"]: r["name"] for r in hb}.get(6)
|
||
chk("PDB 1A00 res6 = GLU", d6w == "GLU", str(d6w))
|
||
chk("PDB 2HBS res6 = VAL", d6h == "VAL", str(d6h))
|
||
|
||
print("\n4) 模块级 smoke test")
|
||
from insilicolab import seq as S, variant as V, crispr as C
|
||
from insilicolab import structure as T, dynamics as DY, circuits as CI, omics as OM
|
||
import numpy as np
|
||
chk("seq 六框/酶切", len(S.find_orfs(cds)) > 0 and "DdeI" in S.restriction_map(cds))
|
||
chk("variant RFLP 可区分", V.rflp_compare(cds, hbs)["distinguishable"])
|
||
st = C.edit_strategy("T", "A")
|
||
chk("crispr 判定 T->A 必须先导编辑",
|
||
st["type"].startswith("颠换") and st["prime_editing"] and not st["cbe"] and not st["abe"])
|
||
chk("crispr sgRNA 设计", len(C.design_sgrnas(cds, 20)) > 0)
|
||
sup = T.superpose_structures(wt, hb)
|
||
chk("structure 叠合 RMSD < 1 A", sup["rmsd"] < 1.0, f"{sup['rmsd']:.3f} A")
|
||
kab = T.kabsch(np.random.RandomState(0).rand(30, 3) * 10,
|
||
np.random.RandomState(0).rand(30, 3) * 10)
|
||
chk("structure Kabsch 返回 3x3 旋转矩阵", kab.shape == (3, 3))
|
||
g = DY.compare_flexibility(wt, hb)
|
||
chk("dynamics GNM 有预测结果", g["gnm_a"]["msf"].shape[0] == len(wt))
|
||
chk("circuits 双稳态", CI.bistability_scan()["bistable_region"].any())
|
||
d = OM.simulate_expression(); de = OM.differential_expression(d)
|
||
chk("omics 流程自检 precision=1.0", de["validation"]["precision"] == 1.0,
|
||
str(de["validation"]))
|
||
|
||
print("\n5) 优化模块(v9.0)自检")
|
||
import glob
|
||
try:
|
||
from insilicolab import rotamer as RO, ss_predict as SP
|
||
k = RO.self_test_kabsch()
|
||
chk("rotamer Kabsch 已知旋转复原", k < 1e-9, f"{k:.2e} A")
|
||
ext = sorted(glob.glob(str(ROOT / "validation/external_structures/chains/*.pdb")))
|
||
obs, _ = RO.chi1_observations(ext)
|
||
lib = RO.build_rotamer_library(obs)
|
||
chk("外部 rotamer 库归一化", abs(sum(lib["probability"]) - 1.0) < 1e-9,
|
||
f"{len(obs)} 个 VAL")
|
||
smp = SP.load_samples(ext)
|
||
chk("二级结构样本序列/标签对齐",
|
||
len(smp) > 0 and all(len(x["seq"]) == len(x["labels"]) for x in smp),
|
||
f"{len(smp)} 结构")
|
||
chk("优化基准 / 回归基线文件存在",
|
||
(ROOT / "protein/results/优化基准.json").exists() and
|
||
(ROOT / "tests/baseline.json").exists())
|
||
except ImportError as e:
|
||
chk("优化模块可导入(需 biopython)", False, str(e))
|
||
|
||
print("\n" + "=" * 62)
|
||
if ok_all:
|
||
print(" ✅ 全部通过。现在运行:python run_all.py")
|
||
else:
|
||
print(" ❌ 存在失败项,请按上面提示修复后再运行 run_all.py")
|
||
print("=" * 62)
|
||
return 0 if ok_all else 1
|
||
|
||
|
||
if __name__ == "__main__":
|
||
sys.exit(main())
|