病毒蛋白检测管道

一个用于病毒蛋白检测的原型管道,使用ProtBERT嵌入和轻量级分类器。

  • by gouthamyadavalli
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 gouthamyadavalli/bio-mcp

使用说明

生物监测管道

使用ProtBERT嵌入和轻量级分类器进行病毒蛋白检测的原型管道。

快速开始

# 1. Setup
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

# 2. Use it
jupyter notebook exploratory.ipynb

它做什么

  • 胎儿蛋白质序列(NCBI)
  • 嵌入ProtBERT(1024-d矢量)
  • 训练逻辑回归分类器
  • 可选通过FastAPI和MCP提供服务

结构

bio/
├── pipeline/          # Core ML code
├── api/               # REST API (optional)
├── data/              # Real accessions/labels
├── tests/             # Tests
└── exploratory.ipynb  # Notebook walkthrough

用法

选项1:笔记本电脑(推荐)

jupyter notebook exploratory.ipynb

运行所有单元格以查看完整的工作流程。

选项2:Python

from pipeline import ProtBERTEmbedder, train_logistic_regression

# Embed sequences
embedder = ProtBERTEmbedder()
embeddings = embedder.embed(["MTEITAAM...", "MGDVEK..."])

# Train
train_logistic_regression(embeddings, [1, 0], "outputs/model.joblib")

方案3:API

# Start server
uvicorn api.app:app --reload

# Use it
curl -X POST http://localhost:8000/classify \
  -H "Content-Type: application/json" \
  -d '{"sequence": "MTEITAAMVKELRESTGAGMMDCKNALSETQHEG"}'

备注

  • 嵌入/模型比例可能因环境而异;测试可以容忍版本差异。

API(可选)

开始: uvicorn api.app:app --reload

终点: /embed, /classify, /index, /search (参见http://localhost:8000/docs)

MCP(模型上下文协议)

将管道作为MCP服务器公开(适用于Claude Desktop等客户端)。

# Install deps (already in requirements)
pip install -r requirements.txt

# Run the server over stdio
python mcp_server.py

Claude桌面配置(macOS):添加到 ~/Library/Application Support/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "bio-surveillance": {
      "command": "/absolute/path/to/python",  
      "args": ["/absolute/path/to/mcp_server.py"], 
      "cwd": "/Users/goutham/Sem5/Dev/bio",
      "env": {"PYTHONPATH": "/Users/goutham/Sem5/Dev/bio"}
    }
  }
}

工具:嵌入、分类、fetch_fasta_clain、索引、搜索、加载分类器、健康状况、train_classifier_tool、train_from_files_tool、服务器信息。

路径行为:

  • 读取检查客户端CWD和仓库ROOT。
  • 写入(相对)在回购ROOT下进行(例如。, outputs/).

诊断:

  • health 显示cwd/root和快速路径检查。
  • server_info 列出joblib文件和Python信息。

提示:如果更改了服务器代码,请在MCP客户端中重新启动它。

另请参见: MCP示例用法及截图

注意:MCP Python SDK需要Python 3.10+。如果你使用的是Python 3.9,请为MCP使用3.10+venv:

python3.11 -m venv .venv311
source .venv311/bin/activate
pip install -r requirements.txt
python mcp_server.py

分类器快速启动

  • train_from_files_tool() 火车从 data/real_datasets/* 并保存到 outputs/classifier.joblib.
  • 或 train_classifier_tool(sequences, labels) 对于一个快速的本地模型。
  • 已经有模型了吗?呼叫 load_classifier(model_path) 然后 classify(sequence).

测试

python tests/test_pipeline.py
python tests/test_api.py

数据

位于 data/real_datasets/ (加入+标签)。


专为计算生物学工作流程而设计。