- 按生产 7900 容器黄金清单迁移(compile.manifest 449 条目,0 缺失) - 入口双态:api.app(生产同源 3 路由)/ api.main(裁剪 11 路由族 91 路径) - 修复:advanced/__init__ 空文件(包标记误覆盖,已从主项目恢复) - 修复:api/rag_routes.py 跨环境 site-packages 注入改 LEGACY_GF_SITE_PACKAGES 门控 - 修复:scripts/utils 缺失(动态加载 reasoning_engine) - 影子验证:kg/stats 数据连通(6.2s,与 7900 同源 normalized 后端) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
97 lines
2.6 KiB
Python
Executable File
97 lines
2.6 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
应用 locus ID 到基因符号的映射
|
|
"""
|
|
|
|
import json
|
|
|
|
|
|
def load_gene_list():
|
|
"""加载基因列表"""
|
|
with open('ftspl_gene_list.json') as f:
|
|
return json.load(f)
|
|
|
|
|
|
def create_mapping(gene_list):
|
|
"""创建 locus ID -> gene symbol 映射"""
|
|
mapping = {}
|
|
for gene in gene_list:
|
|
locus = gene['locus_id']
|
|
symbol = gene['symbol']
|
|
# 处理多种格式
|
|
mapping[locus] = symbol
|
|
mapping[locus.replace('.T01', '')] = symbol
|
|
mapping[locus.replace('.01.T01', '')] = symbol
|
|
return mapping
|
|
|
|
|
|
def apply_mapping(data, mapping):
|
|
"""应用映射到实体和关系"""
|
|
# 映射实体 ID
|
|
for e in data.get('entities', []):
|
|
old_id = e['id']
|
|
if old_id in mapping:
|
|
e['id'] = mapping[old_id]
|
|
e['name'] = mapping[old_id]
|
|
|
|
# 映射关系中的 ID
|
|
for r in data.get('relations', []):
|
|
source = r.get('source', '')
|
|
target = r.get('target', '')
|
|
|
|
if source in mapping:
|
|
r['source'] = mapping[source]
|
|
if target in mapping:
|
|
r['target'] = mapping[target]
|
|
|
|
return data
|
|
|
|
|
|
def main():
|
|
print("=" * 70)
|
|
print("Applying Locus ID to Gene Symbol Mapping")
|
|
print("=" * 70)
|
|
|
|
# 加载基因列表
|
|
print("\n1. Loading gene list...")
|
|
gene_list = load_gene_list()
|
|
mapping = create_mapping(gene_list)
|
|
print(f" Created mapping for {len(mapping)} genes")
|
|
|
|
# 显示映射示例
|
|
print("\n2. Mapping examples:")
|
|
for i, (locus, symbol) in enumerate(list(mapping.items())[:5]):
|
|
print(f" {locus} -> {symbol}")
|
|
|
|
# 应用映射到各个结果文件
|
|
files_to_process = [
|
|
('evaluation/auto_results/pmid31286919_phylogeny.json',
|
|
'evaluation/auto_results/pmid31286919_phylogeny_mapped.json'),
|
|
]
|
|
|
|
for input_path, output_path in files_to_process:
|
|
print(f"\n3. Processing: {input_path}")
|
|
|
|
with open(input_path) as f:
|
|
data = json.load(f)
|
|
|
|
# 应用映射
|
|
data = apply_mapping(data, mapping)
|
|
|
|
# 保存
|
|
with open(output_path, 'w') as f:
|
|
json.dump(data, f, indent=2)
|
|
|
|
print(f" ✓ Saved to: {output_path}")
|
|
|
|
# 显示结果
|
|
print(f"\n Mapped relations:")
|
|
for r in data.get('relations', []):
|
|
rel_type = r.get('type') or r.get('relation', '')
|
|
if 'classified' in rel_type.lower():
|
|
print(f" {r['source']} --{rel_type}--> {r['target']}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|