密码转换器MCP
基于变换器的神经网络用于蛋白质序列的高级密码子优化
目录
概述
CodonTransformer MCP通过全面的模型上下文协议(MCP)服务器提供最先进的密码子优化功能。该工具利用基于变压器的神经网络来优化蛋白质序列,以在目标生物体中表达,支持所有生命王国中的164多种生物体。
特性
- 高级AI优化:使用CodonTransformer的BigBird骨干进行序列优化
- 多组织支持:164多种生物,包括细菌、古菌、植物、动物和真菌
- API双重设计:快速同步操作和后台异步处理
- 序列变体:生成具有可控多样性的多样化DNA序列
- 批处理:通过全面的统计数据高效处理多个序列
- 跨生物体分析:比较不同物种的密码子优化
- 完整的作业管理:后台任务监控,包括日志和取消
目录结构
./
├── README.md # This file
├── env/ # Conda environment
├── src/
│ ├── server.py # MCP server (16 tools)
│ └── jobs/ # Job management system
├── scripts/
│ ├── single_sequence_optimization.py # Single protein optimization
│ ├── multi_sequence_generation.py # Variant generation
│ ├── batch_optimization.py # Batch CSV processing
│ ├── organism_comparison.py # Cross-organism analysis
│ └── lib/ # Shared utilities
├── examples/
│ └── data/ # Demo data files
├── configs/ # Configuration templates
├── jobs/ # Background job storage
└── repo/ # Original CodonTransformer repository______________________________________________________________________
安装
先决条件
- Conda或Mamba(建议使用曼巴以加快安装速度)
- Python 3.10+
- 4GB+RAM(型号需要~2-3GB)
- 2GB以上的磁盘空间用于模型缓存
创建环境
根据步骤3中的环境设置,执行以下命令:
# Navigate to the MCP directory
cd /home/xux/Desktop/NucleicMCP/NucleicMCP/tool-mcps/codontransformer_mcp
# Check if mamba is available (preferred)
if command -v mamba &> /dev/null; then
PKG_MGR="mamba"
else
PKG_MGR="conda"
fi
echo "Using package manager: $PKG_MGR"
# Create conda environment
$PKG_MGR create -p ./env python=3.10 pip -y
# Activate environment
$PKG_MGR activate ./env安装依赖项
# Install core MCP dependencies
pip install fastmcp loguru --ignore-installed
# Install CodonTransformer dependencies
pip install biopython>=1.83,=2.0.1,=1.26.4,=1.16.3,=2.0.0,=0.1.12,=2.2.1,=1.2.2,=1.13.1,=2.0.0,=4.66.2,=4.40.0,"
Get results when complete:
Use get_job_result with job_id ""批量处理大型数据集
Process large CSV file:
Use submit_batch_optimization with input_file @examples/data/sample_dataset.csv
Monitor with:
Use get_job_log with job_id "" and tail 20使用@引用
在克劳德代码中,使用 @ 引用文件和目录:
| 参考 | 说明 |
|---|---|
@examples/data/sample_dataset.csv | 参考示例CSV文件 |
@configs/single_sequence_config.json | 参考配置文件 |
@results/ | 参考输出目录 |
______________________________________________________________________
与Gemini CLI一起使用
配置
增添 ~/.gemini/settings.json:
{
"mcpServers": {
"CodonTransformer": {
"command": "/home/xux/Desktop/NucleicMCP/NucleicMCP/tool-mcps/codontransformer_mcp/env/bin/python",
"args": ["/home/xux/Desktop/NucleicMCP/NucleicMCP/tool-mcps/codontransformer_mcp/src/server.py"]
}
}
}示例提示
# Start Gemini CLI
gemini
# Example prompts (same as Claude Code)
> What tools are available?
> Use optimize_single_sequence with protein "MSEKYIV" and organism "Homo sapiens"
> Use submit_batch_optimization with input_file "examples/data/sample_dataset.csv"______________________________________________________________________
可用工具
快速操作(同步API)
这些工具会立即返回结果(\10分钟):
| 工具 | 描述 | 用例 |
|---|---|---|
submit_sequence_variants | 大规模变体生成 | 生成100+个变体 |
submit_batch_optimization | 大型CSV处理 | 处理100多个序列 |
submit_organism_comparison | 广泛的生物体分析 | 比较许多生物体 |
submit_batch_variants | 多蛋白变体生成 | 具有变体的多种蛋白质 |
作业管理工具
| 工具 | 说明 |
|---|---|
get_job_status | 检查作业进度和状态 |
get_job_result | 完成后获取结果 |
get_job_log | 查看带有尾部支持的执行日志 |
cancel_job | 取消正在运行的作业 |
list_jobs | 列出所有具有状态筛选的作业 |
实用工具
| 工具 | 说明 |
|---|---|
validate_protein_sequence | 验证蛋白质序列格式 |
get_supported_organisms | 列出可用的目标生物 |
get_example_data | 获取示例数据集和格式 |
______________________________________________________________________
例子
示例1:单序列优化
目标: 优化大肠杆菌表达的单个蛋白质序列
使用脚本:
python scripts/single_sequence_optimization.py \
--protein "MSEKYIV" \
--organism "Escherichia coli general" \
--output results/single_example/使用MCP(克劳德代码):
Use optimize_single_sequence with protein "MSEKYIV" and organism "Escherichia coli general"预期产量:
- 优化的DNA序列:“ATGTCCGAAATACATTGTC”
- GC含量:~45-50%
- 处理时间:~2-3秒
示例2:生成序列变体
目标: 为同一蛋白质创建不同的DNA序列
使用脚本:
python scripts/multi_sequence_generation.py \
--protein "MSEKYIV" \
--num-sequences 10 \
--temperature 0.7 \
--output variants.fasta使用MCP(克劳德代码):
Use generate_sequence_variants with protein "MSEKYIV", num_sequences 10, temperature 0.7, output_file "variants.fasta"预期产量:
- 10种不同的DNA序列
- 多样性度量(平均成对距离)
- 包含所有变体的FASTA文件
示例3:批处理
目标: 处理CSV文件中的多个序列
使用脚本:
python scripts/batch_optimization.py \
--input examples/data/sample_dataset.csv \
--output results/batch_example.csv使用MCP(克劳德代码):
Use optimize_batch_sequences with input_file @examples/data/sample_dataset.csv and output_file "results/batch_example.csv"预期产量:
- 包含所有优化序列的CSV文件
- 处理统计(每个序列的时间、成功率)
- 摘要报告
示例4:跨生物体比较
目标: 比较不同生物体的优化
使用脚本:
python scripts/organism_comparison.py \
--protein "MSEKYIV" \
--organisms "Escherichia coli general,Homo sapiens,Saccharomyces cerevisiae" \
--output comparison.csv使用MCP(克劳德代码):
Use compare_organisms with protein "MSEKYIV" and organisms ["Escherichia coli general", "Homo sapiens", "Saccharomyces cerevisiae"]预期产量:
- CSV与GC内容差异的比较
- 序列相似性分析
- 特定于生物体的优化统计
示例5:大规模背景处理
目标: 在后台生成1000个变体
使用MCP(克劳德代码):
Submit large variant generation:
Use submit_sequence_variants with protein "MSEKYIV", num_sequences 1000, temperature 0.8
Check progress:
Use get_job_status with job_id ""
View logs:
Use get_job_log with job_id "" and tail 50
Get final results:
Use get_job_result with job_id ""______________________________________________________________________
演示数据
这 examples/data/ 目录包含用于测试的示例数据:
| 文件 | 描述 | 与一起使用 |
|---|---|---|
sample_dataset.csv | 来自不同生物体的蛋白质序列样本 | optimize_batch_sequences |
sample_predictions.csv | 示例预测输出 | 参考格式 |
CodonTransformer_inference_template.xlsx | 批量设置Excel模板 | 批量处理指南 |
sample_single.txt | 单序列示例 | optimize_single_sequence |
test_proteins.csv | 其他测试蛋白 | 各种工具 |
样本数据集格式
这 sample_dataset.csv 包含:
- 蛋白质序列:优化蛋白质序列
- 生物体:每个序列的目标生物体
- 预测dna:示例输出列(输入为空)
示例行:
protein_sequence,organism,predicted_dna
MSEKYIV,Escherichia coli general,
MKLLVVDD,Homo sapiens,______________________________________________________________________
配置文件
这 configs/ 目录包含配置模板:
| 配置 | 描述 | 参数 |
|---|---|---|
single_sequence_config.json | 单序列优化 | deterministic, temperature, organism |
multi_sequence_config.json | 变量生成设置 | num_sequences, temperature, top_p |
batch_optimization_config.json | 批处理参数 | max_sequences, organism_override |
organism_comparison_config.json | 跨生物体分析 | organisms, plot_options |
配置示例
{
"model": {
"name": "adibvafa/CodonTransformer",
"attention_type": "original_full",
"device": "auto"
},
"prediction": {
"deterministic": true,
"temperature": 0.2,
"top_p": 0.95
},
"defaults": {
"protein": "MSEKYIV",
"organism": "Escherichia coli general"
}
}______________________________________________________________________
故障排除
环境问题
问题: 找不到环境或激活失败
# Recreate environment
$PKG_MGR create -p ./env python=3.10 -y
$PKG_MGR activate ./env
pip install fastmcp loguru biopython torch transformers问题: 导入错误或缺少依赖项
# Verify CodonTransformer installation
python -c "from transformers import AutoTokenizer, AutoModelForCausalLM; print('CodonTransformer dependencies OK')"问题: 模型下载问题
# Check internet connection and HuggingFace cache
python -c "
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained('adibvafa/CodonTransformer')
print('Model download successful')
"MCP问题
问题: 在Claude代码中找不到服务器
# Check MCP registration
claude mcp list
# Re-add if needed
claude mcp remove CodonTransformer
claude mcp add CodonTransformer -- $(pwd)/env/bin/python $(pwd)/src/server.py问题: 工具无法工作或服务器启动失败
# Test server directly
$PKG_MGR activate ./env
python src/server.py --help
# Check tool registration
python -c "
import sys; sys.path.append('src')
from server import mcp
print('Available tools:', list(mcp.list_tools().keys()))
"问题: 权限被拒绝或路径问题
# Check paths and permissions
ls -la src/server.py
which python
$PKG_MGR list工作问题
问题: 作业处于待处理状态
# Check job directory and permissions
ls -la jobs/
find jobs/ -name "*.log" -exec tail -5 {} \;问题: 作业失败,出现错误
Use get_job_log with job_id "" and tail 100 to see detailed error information问题: 内存不足错误
# Reduce batch sizes or use CPU mode
export CUDA_VISIBLE_DEVICES="" # Force CPU mode
python scripts/batch_optimization.py --max-sequences 10 # Smaller batches性能问题
问题: 处理速度慢或超时
# Check GPU availability
python -c "import torch; print('CUDA available:', torch.cuda.is_available())"
# Monitor resources
top -p $(pgrep -f server.py)问题: 模型加载时间过长
# Check HuggingFace cache
ls -la ~/.cache/huggingface/transformers/
du -sh ~/.cache/huggingface/常见错误消息
- “无效的蛋白质序列”:仅使用标准氨基酸字母(A-Z,无X或\*)
- “不支持生物体”:使用
get_supported_organisms查看可用选项 - “找不到作业”:检查job_id拼写并使用
list_jobs查看所有工作 - “找不到文件”:使用绝对路径或确保文件存在
ls -la
______________________________________________________________________
发展
运行测试
# Activate environment
$PKG_MGR activate ./env
# Test basic functionality
python -c "
import sys; sys.path.append('scripts')
from single_sequence_optimization import main
print('Scripts working correctly')
"
# Test MCP server
python src/server.py --help正在启动开发服务器
# Run MCP server in dev mode
$PKG_MGR activate ./env
fastmcp dev src/server.py
# Or run directly
python src/server.py性能基准
根据步骤7测试:
| 操作 | 测试输入 | 处理时间 | 性能 |
|---|---|---|---|
| 单次优化 | “MKLLVVDD”(8 AA) | ~2-3秒 | ✅ 快速 |
| 变体生成 | 3个变体 | ~4-5秒 | ✅ 快速 |
| 批处理 | 2个序列 | ~3-4秒 | ✅ 快速(13.2序列/秒) |
| 生物体比较 | 2个生物体 | ~5-6秒 | ✅ 快速 |
______________________________________________________________________
许可证
该项目根据其原始许可条款集成了CodonTransformer。有关许可证的详细信息,请参阅原始存储库。
学分
基于 密码转换器 Adibvafa Fallahpour。
CodonTransformer参考:
Fallahpour, A., Nasiri, E., Abbasi, J., Wong, H. S., Zheng, J., Garg, A., & Galarneau, L. (2024).
CodonTransformer: The Global Codon Optimization Benchmark. arXiv preprint arXiv:2411.16265.______________________________________________________________________
支持和社区
- 问题:通过原始CodonTransformer存储库报告错误或请求功能
- 文档:中的其他示例和教程
examples/目录 - 演出:监控作业日志以寻找优化机会
- 更新:定期检查新的CodonTransformer模型版本
该MCP服务器通过自然语言接口提供最先进的密码子优化的生产就绪访问,使研究人员和从业者能够访问先进的蛋白质工程。
