BioOcto code and data release (snapshot 2026-11-27) (part 10)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mitos/app/mitos_server.py +176 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mitos/app/mitos_shim_server.py +45 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mitos/app/requirements.txt +1 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mitos/docker-compose.yml +22 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mitos/environment.yaml +10 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mitos/requirements.txt +2 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mlst/requirements.txt +2 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mmseqs2/Dockerfile +40 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mmseqs2/app/mmseqs2_server.py +432 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mmseqs2/app/mmseqs2_shim_server.py +45 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mmseqs2/app/requirements.txt +1 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mmseqs2/docker-compose.yml +22 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mmseqs2/environment.yaml +10 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mmseqs2/requirements.txt +2 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mmtf-python/Dockerfile +40 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mmtf-python/app/mmtf-python_server.py +106 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mmtf-python/app/mmtf-python_shim_server.py +45 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mmtf-python/app/requirements.txt +1 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mmtf-python/docker-compose.yml +22 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mmtf-python/environment.yaml +10 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mmtf-python/requirements.txt +2 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mobivision-m/Dockerfile +40 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mobivision-m/app/mobivision-m_server.py +209 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mobivision-m/app/mobivision-m_shim_server.py +45 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mobivision-m/app/requirements.txt +1 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mobivision-m/docker-compose.yml +22 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mobivision-m/environment.yaml +10 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mobivision-m/requirements.txt +2 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_moments/Dockerfile +40 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_moments/app/moments_server.py +445 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_moments/app/moments_shim_server.py +45 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_moments/app/requirements.txt +1 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_moments/docker-compose.yml +22 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_moments/environment.yaml +10 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_moments/requirements.txt +2 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mosdepth/Dockerfile +40 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mosdepth/app/mosdepth_server.py +200 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mosdepth/app/mosdepth_shim_server.py +45 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mosdepth/app/requirements.txt +1 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mosdepth/docker-compose.yml +22 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mosdepth/environment.yaml +10 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mosdepth/requirements.txt +2 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mothur/Dockerfile +40 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mothur/app/mothur_server.py +303 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mothur/app/mothur_shim_server.py +45 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mothur/app/requirements.txt +1 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mothur/docker-compose.yml +22 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mothur/environment.yaml +10 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mothur/requirements.txt +2 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_msisensor-pro/Dockerfile +40 -0
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mitos/app/mitos_server.py
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
from typing import Optional, List, Dict, Any
|
| 4 |
+
|
| 5 |
+
@mcp.tool()
|
| 6 |
+
def run_mitos(
|
| 7 |
+
input_fasta: str,
|
| 8 |
+
reference_dir: str,
|
| 9 |
+
output_dir: str,
|
| 10 |
+
genetic_code: int = 2,
|
| 11 |
+
evalue: float = 0.01,
|
| 12 |
+
cutoff: float = 50.0,
|
| 13 |
+
sensitive: bool = False,
|
| 14 |
+
best: bool = False,
|
| 15 |
+
fragment: bool = False,
|
| 16 |
+
linear: bool = False,
|
| 17 |
+
prefix: str = "mitos_result",
|
| 18 |
+
cpu: int = 1
|
| 19 |
+
) -> Dict[str, Any]:
|
| 20 |
+
"""
|
| 21 |
+
Run the MITOS/MITOS2 pipeline for metazoan mitochondrial genome annotation.
|
| 22 |
+
|
| 23 |
+
Args:
|
| 24 |
+
input_fasta: Path to the input FASTA file containing the mitochondrial sequence.
|
| 25 |
+
reference_dir: Path to the MITOS reference data directory (e.g., RefSeq63, RefSeq81).
|
| 26 |
+
output_dir: Directory where results will be stored.
|
| 27 |
+
genetic_code: NCBI genetic code (e.g., 2 for Vertebrate Mito, 5 for Invertebrate Mito).
|
| 28 |
+
evalue: E-value threshold for BLAST/HMMER searches.
|
| 29 |
+
cutoff: Cutoff value for HMMER/Infernal.
|
| 30 |
+
sensitive: Use sensitive mode (slower but more thorough).
|
| 31 |
+
best: Only report the best hits for each feature.
|
| 32 |
+
fragment: Allow fragmented features.
|
| 33 |
+
linear: Treat the input sequence as linear (default is circular).
|
| 34 |
+
prefix: Prefix for the output files.
|
| 35 |
+
cpu: Number of CPU cores to use.
|
| 36 |
+
"""
|
| 37 |
+
# Input validation
|
| 38 |
+
input_path = Path(input_fasta)
|
| 39 |
+
if not input_path.exists():
|
| 40 |
+
return {"error": f"Input FASTA file not found: {input_fasta}"}
|
| 41 |
+
|
| 42 |
+
ref_path = Path(reference_dir)
|
| 43 |
+
if not ref_path.exists() or not ref_path.is_dir():
|
| 44 |
+
return {"error": f"Reference directory not found or is not a directory: {reference_dir}"}
|
| 45 |
+
|
| 46 |
+
out_path = Path(output_dir)
|
| 47 |
+
out_path.mkdir(parents=True, exist_ok=True)
|
| 48 |
+
|
| 49 |
+
# Construct command
|
| 50 |
+
# Note: runmitos.py is the standard executable name for MITOS/MITOS2
|
| 51 |
+
cmd = [
|
| 52 |
+
"runmitos.py",
|
| 53 |
+
"-i", str(input_path.absolute()),
|
| 54 |
+
"-r", str(ref_path.absolute()),
|
| 55 |
+
"-o", str(out_path.absolute()),
|
| 56 |
+
"-c", str(genetic_code),
|
| 57 |
+
"-e", str(evalue),
|
| 58 |
+
"--cutoff", str(cutoff),
|
| 59 |
+
"--prefix", prefix,
|
| 60 |
+
"--cpu", str(cpu)
|
| 61 |
+
]
|
| 62 |
+
|
| 63 |
+
if sensitive:
|
| 64 |
+
cmd.append("--sensitive")
|
| 65 |
+
if best:
|
| 66 |
+
cmd.append("--best")
|
| 67 |
+
if fragment:
|
| 68 |
+
cmd.append("--fragment")
|
| 69 |
+
if linear:
|
| 70 |
+
cmd.append("--linear")
|
| 71 |
+
|
| 72 |
+
try:
|
| 73 |
+
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
| 74 |
+
|
| 75 |
+
# Collect list of generated files
|
| 76 |
+
output_files = [str(p) for p in out_path.glob(f"{prefix}*")]
|
| 77 |
+
|
| 78 |
+
return {
|
| 79 |
+
"command_executed": " ".join(cmd),
|
| 80 |
+
"stdout": result.stdout,
|
| 81 |
+
"stderr": result.stderr,
|
| 82 |
+
"output_files": output_files,
|
| 83 |
+
"status": "success"
|
| 84 |
+
}
|
| 85 |
+
except subprocess.CalledProcessError as e:
|
| 86 |
+
return {
|
| 87 |
+
"command_executed": " ".join(cmd),
|
| 88 |
+
"stdout": e.stdout,
|
| 89 |
+
"stderr": e.stderr,
|
| 90 |
+
"error": "MITOS execution failed",
|
| 91 |
+
"returncode": e.returncode
|
| 92 |
+
}
|
| 93 |
+
except Exception as e:
|
| 94 |
+
return {"error": str(e)}
|
| 95 |
+
|
| 96 |
+
@mcp.tool()
|
| 97 |
+
def mitos_check_ref(
|
| 98 |
+
reference_dir: str
|
| 99 |
+
) -> Dict[str, Any]:
|
| 100 |
+
"""
|
| 101 |
+
Validate the MITOS reference data directory to ensure all required databases and files are present.
|
| 102 |
+
|
| 103 |
+
Args:
|
| 104 |
+
reference_dir: Path to the MITOS reference data directory to check.
|
| 105 |
+
"""
|
| 106 |
+
ref_path = Path(reference_dir)
|
| 107 |
+
if not ref_path.exists():
|
| 108 |
+
return {"error": f"Reference directory does not exist: {reference_dir}"}
|
| 109 |
+
|
| 110 |
+
cmd = ["mitos_check_ref.py", "-r", str(ref_path.absolute())]
|
| 111 |
+
|
| 112 |
+
try:
|
| 113 |
+
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
| 114 |
+
return {
|
| 115 |
+
"command_executed": " ".join(cmd),
|
| 116 |
+
"stdout": result.stdout,
|
| 117 |
+
"stderr": result.stderr,
|
| 118 |
+
"status": "success"
|
| 119 |
+
}
|
| 120 |
+
except subprocess.CalledProcessError as e:
|
| 121 |
+
return {
|
| 122 |
+
"command_executed": " ".join(cmd),
|
| 123 |
+
"stdout": e.stdout,
|
| 124 |
+
"stderr": e.stderr,
|
| 125 |
+
"error": "Reference check failed. The directory may be incomplete or corrupted.",
|
| 126 |
+
"returncode": e.returncode
|
| 127 |
+
}
|
| 128 |
+
except Exception as e:
|
| 129 |
+
return {"error": str(e)}
|
| 130 |
+
|
| 131 |
+
@mcp.tool()
|
| 132 |
+
def mitos_list_genetic_codes() -> Dict[str, Any]:
|
| 133 |
+
"""
|
| 134 |
+
Returns a reference list of NCBI genetic codes commonly used with MITOS.
|
| 135 |
+
"""
|
| 136 |
+
codes = {
|
| 137 |
+
"1": "Standard",
|
| 138 |
+
"2": "Vertebrate Mitochondrial",
|
| 139 |
+
"3": "Yeast Mitochondrial",
|
| 140 |
+
"4": "Mold, Protozoan, and Coelenterate Mitochondrial; Mycoplasma/Spiroplasma",
|
| 141 |
+
"5": "Invertebrate Mitochondrial",
|
| 142 |
+
"6": "Ciliate, Dasycladacean and Hexamita Nuclear",
|
| 143 |
+
"9": "Echinoderm and Flatworm Mitochondrial",
|
| 144 |
+
"10": "Euplotid Nuclear",
|
| 145 |
+
"11": "Bacterial, Archaeal and Plant Plastid",
|
| 146 |
+
"13": "Ascidian Mitochondrial",
|
| 147 |
+
"14": "Alternative Flatworm Mitochondrial",
|
| 148 |
+
"16": "Chlorophycean Mitochondrial",
|
| 149 |
+
"21": "Trematode Mitochondrial",
|
| 150 |
+
"22": "Scenedesmus obliquus Mitochondrial",
|
| 151 |
+
"23": "Thraustochytrium Mitochondrial",
|
| 152 |
+
"24": "Pterobranchia Mitochondrial",
|
| 153 |
+
"25": "Candidate Division SR1 and Gracilibacteria"
|
| 154 |
+
}
|
| 155 |
+
return {
|
| 156 |
+
"genetic_codes": codes,
|
| 157 |
+
"usage_tip": "Use the integer key as the 'genetic_code' parameter in run_mitos."
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
@mcp.tool()
|
| 161 |
+
def mitos_version() -> Dict[str, Any]:
|
| 162 |
+
"""
|
| 163 |
+
Check the installed version of MITOS.
|
| 164 |
+
"""
|
| 165 |
+
try:
|
| 166 |
+
# Try running runmitos.py with version flag
|
| 167 |
+
result = subprocess.run(["runmitos.py", "--version"], capture_output=True, text=True)
|
| 168 |
+
# Some versions might use -v or print to stderr
|
| 169 |
+
version_info = result.stdout.strip() or result.stderr.strip()
|
| 170 |
+
|
| 171 |
+
return {
|
| 172 |
+
"version": version_info,
|
| 173 |
+
"status": "success"
|
| 174 |
+
}
|
| 175 |
+
except Exception as e:
|
| 176 |
+
return {"error": f"Could not determine MITOS version: {str(e)}"}
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mitos/app/mitos_shim_server.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import ast
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
from mcp.server.fastmcp import FastMCP
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
SOURCE_SERVER = Path('/225040511/project/BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mitos/app/mitos_server.py')
|
| 11 |
+
SERVER_NAME = 'biosci_mitos'
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class _ShimMCP:
|
| 15 |
+
@staticmethod
|
| 16 |
+
def tool():
|
| 17 |
+
def _decorator(fn):
|
| 18 |
+
return fn
|
| 19 |
+
return _decorator
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def _load_functions():
|
| 23 |
+
code = SOURCE_SERVER.read_text(encoding="utf-8")
|
| 24 |
+
tree = ast.parse(code, filename=str(SOURCE_SERVER))
|
| 25 |
+
function_names = [n.name for n in tree.body if isinstance(n, ast.FunctionDef) and not n.name.startswith("_")]
|
| 26 |
+
namespace = {
|
| 27 |
+
"__name__": "__mcp_source__",
|
| 28 |
+
"mcp": _ShimMCP(),
|
| 29 |
+
}
|
| 30 |
+
exec(compile(code, str(SOURCE_SERVER), "exec"), namespace, namespace)
|
| 31 |
+
loaded = []
|
| 32 |
+
for name in function_names:
|
| 33 |
+
fn = namespace.get(name)
|
| 34 |
+
if callable(fn):
|
| 35 |
+
loaded.append(fn)
|
| 36 |
+
return loaded
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
mcp = FastMCP(SERVER_NAME)
|
| 40 |
+
for _fn in _load_functions():
|
| 41 |
+
mcp.tool()(_fn)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
if __name__ == "__main__":
|
| 45 |
+
mcp.run(transport="stdio")
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mitos/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mitos/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-mitos:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-mitos:latest
|
| 7 |
+
container_name: mcp-mitos
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=mitos
|
| 12 |
+
volumes:
|
| 13 |
+
- ./workspace:/app/workspace
|
| 14 |
+
- ./output:/app/output
|
| 15 |
+
restart: unless-stopped
|
| 16 |
+
healthcheck:
|
| 17 |
+
test: ["CMD", "python", "-c", "import sys; sys.exit(0)"]
|
| 18 |
+
interval: 30s
|
| 19 |
+
timeout: 10s
|
| 20 |
+
retries: 3
|
| 21 |
+
start_period: 5s
|
| 22 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mitos/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- mitos
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mitos/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mlst/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mmseqs2/Dockerfile
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# Install system dependencies
|
| 5 |
+
RUN apt-get update && apt-get install -y default-jre wget curl && apt-get clean && rm -rf /var/lib/apt/lists/*
|
| 6 |
+
|
| 7 |
+
# Install Miniconda
|
| 8 |
+
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O /tmp/miniconda.sh && bash /tmp/miniconda.sh -b -p /opt/conda && rm /tmp/miniconda.sh
|
| 9 |
+
|
| 10 |
+
# Add conda to PATH
|
| 11 |
+
ENV PATH="/opt/conda/bin:$PATH"
|
| 12 |
+
|
| 13 |
+
# Install mmseqs2 via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda mmseqs2 -y && conda clean -a
|
| 15 |
+
|
| 16 |
+
# Install Python dependencies
|
| 17 |
+
RUN pip install uv
|
| 18 |
+
RUN uv pip install --system fastmcp
|
| 19 |
+
|
| 20 |
+
# Create app directory
|
| 21 |
+
WORKDIR /app
|
| 22 |
+
|
| 23 |
+
# Copy your MCP server
|
| 24 |
+
COPY app/mmseqs2_server.py /app/
|
| 25 |
+
|
| 26 |
+
# Create workspace and output directories
|
| 27 |
+
RUN mkdir -p /app/workspace /app/output
|
| 28 |
+
|
| 29 |
+
# Make sure the server script is executable
|
| 30 |
+
RUN chmod +x /app/mmseqs2_server.py
|
| 31 |
+
|
| 32 |
+
# Expose port for MCP over HTTP (optional)
|
| 33 |
+
EXPOSE 8000
|
| 34 |
+
|
| 35 |
+
# Health check
|
| 36 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 CMD python -c "import sys; sys.exit(0)"
|
| 37 |
+
|
| 38 |
+
# Default command runs the MCP server via stdio
|
| 39 |
+
CMD ["python", "/app/mmseqs2_server.py"]
|
| 40 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mmseqs2/app/mmseqs2_server.py
ADDED
|
@@ -0,0 +1,432 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
from typing import Optional, List, Union
|
| 4 |
+
import tempfile
|
| 5 |
+
|
| 6 |
+
def run_command(command: List[str]) -> dict:
|
| 7 |
+
"""Helper to execute subprocess commands and return structured output."""
|
| 8 |
+
try:
|
| 9 |
+
result = subprocess.run(
|
| 10 |
+
command,
|
| 11 |
+
check=True,
|
| 12 |
+
capture_output=True,
|
| 13 |
+
text=True
|
| 14 |
+
)
|
| 15 |
+
return {
|
| 16 |
+
"command_executed": " ".join(command),
|
| 17 |
+
"stdout": result.stdout,
|
| 18 |
+
"stderr": result.stderr,
|
| 19 |
+
"status": "success"
|
| 20 |
+
}
|
| 21 |
+
except subprocess.CalledProcessError as e:
|
| 22 |
+
return {
|
| 23 |
+
"command_executed": " ".join(command),
|
| 24 |
+
"stdout": e.stdout,
|
| 25 |
+
"stderr": e.stderr,
|
| 26 |
+
"status": "error",
|
| 27 |
+
"error_message": str(e)
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
@mcp.tool()
|
| 31 |
+
def mmseqs_createdb(
|
| 32 |
+
input_fasta: str,
|
| 33 |
+
output_db: str,
|
| 34 |
+
db_type: int = 0,
|
| 35 |
+
shuffle: bool = True,
|
| 36 |
+
createdb_mode: int = 0,
|
| 37 |
+
write_lookup: int = 1,
|
| 38 |
+
v: int = 3
|
| 39 |
+
):
|
| 40 |
+
"""
|
| 41 |
+
Create an MMseqs2 database from a FASTA/FASTQ file.
|
| 42 |
+
db_type: 0: auto, 1: amino acid, 2: nucleotides.
|
| 43 |
+
"""
|
| 44 |
+
input_path = Path(input_fasta)
|
| 45 |
+
if not input_path.exists():
|
| 46 |
+
raise FileNotFoundError(f"Input file {input_fasta} not found.")
|
| 47 |
+
|
| 48 |
+
cmd = [
|
| 49 |
+
"mmseqs", "createdb",
|
| 50 |
+
str(input_path),
|
| 51 |
+
output_db,
|
| 52 |
+
"--dbtype", str(db_type),
|
| 53 |
+
"--shuffle", str(int(shuffle)),
|
| 54 |
+
"--createdb-mode", str(createdb_mode),
|
| 55 |
+
"--write-lookup", str(write_lookup),
|
| 56 |
+
"-v", str(v)
|
| 57 |
+
]
|
| 58 |
+
|
| 59 |
+
return run_command(cmd)
|
| 60 |
+
|
| 61 |
+
@mcp.tool()
|
| 62 |
+
def mmseqs_search(
|
| 63 |
+
query_db: str,
|
| 64 |
+
target_db: str,
|
| 65 |
+
result_db: str,
|
| 66 |
+
tmp_dir: str,
|
| 67 |
+
s: float = 5.7,
|
| 68 |
+
threads: int = 1,
|
| 69 |
+
v: int = 3,
|
| 70 |
+
max_seqs: int = 300,
|
| 71 |
+
min_seq_id: float = 0.0,
|
| 72 |
+
c: float = 0.0,
|
| 73 |
+
cov_mode: int = 0,
|
| 74 |
+
alignment_mode: int = 3,
|
| 75 |
+
e: float = 0.001
|
| 76 |
+
):
|
| 77 |
+
"""
|
| 78 |
+
Search a query database against a target database.
|
| 79 |
+
s: sensitivity (higher is slower but more sensitive).
|
| 80 |
+
c: coverage threshold.
|
| 81 |
+
cov_mode: 0: coverage of query and target, 1: coverage of query, 2: coverage of target.
|
| 82 |
+
"""
|
| 83 |
+
for db in [query_db, target_db]:
|
| 84 |
+
if not Path(db).exists():
|
| 85 |
+
raise FileNotFoundError(f"Database {db} not found.")
|
| 86 |
+
|
| 87 |
+
Path(tmp_dir).mkdir(parents=True, exist_ok=True)
|
| 88 |
+
|
| 89 |
+
cmd = [
|
| 90 |
+
"mmseqs", "search",
|
| 91 |
+
query_db,
|
| 92 |
+
target_db,
|
| 93 |
+
result_db,
|
| 94 |
+
tmp_dir,
|
| 95 |
+
"-s", str(s),
|
| 96 |
+
"--threads", str(threads),
|
| 97 |
+
"-v", str(v),
|
| 98 |
+
"--max-seqs", str(max_seqs),
|
| 99 |
+
"--min-seq-id", str(min_seq_id),
|
| 100 |
+
"-c", str(c),
|
| 101 |
+
"--cov-mode", str(cov_mode),
|
| 102 |
+
"--alignment-mode", str(alignment_mode),
|
| 103 |
+
"-e", str(e)
|
| 104 |
+
]
|
| 105 |
+
|
| 106 |
+
return run_command(cmd)
|
| 107 |
+
|
| 108 |
+
@mcp.tool()
|
| 109 |
+
def mmseqs_cluster(
|
| 110 |
+
input_db: str,
|
| 111 |
+
result_db: str,
|
| 112 |
+
tmp_dir: str,
|
| 113 |
+
min_seq_id: float = 0.0,
|
| 114 |
+
c: float = 0.8,
|
| 115 |
+
cov_mode: int = 0,
|
| 116 |
+
cluster_mode: int = 0,
|
| 117 |
+
threads: int = 1,
|
| 118 |
+
v: int = 3,
|
| 119 |
+
s: float = 1.2
|
| 120 |
+
):
|
| 121 |
+
"""
|
| 122 |
+
Cluster sequences in a database.
|
| 123 |
+
cluster_mode: 0: Set cover, 1: Connected component, 2: Greedy clustering, 3: Greedy clustering (CD-HIT style).
|
| 124 |
+
"""
|
| 125 |
+
if not Path(input_db).exists():
|
| 126 |
+
raise FileNotFoundError(f"Input database {input_db} not found.")
|
| 127 |
+
|
| 128 |
+
Path(tmp_dir).mkdir(parents=True, exist_ok=True)
|
| 129 |
+
|
| 130 |
+
cmd = [
|
| 131 |
+
"mmseqs", "cluster",
|
| 132 |
+
input_db,
|
| 133 |
+
result_db,
|
| 134 |
+
tmp_dir,
|
| 135 |
+
"--min-seq-id", str(min_seq_id),
|
| 136 |
+
"-c", str(c),
|
| 137 |
+
"--cov-mode", str(cov_mode),
|
| 138 |
+
"--cluster-mode", str(cluster_mode),
|
| 139 |
+
"--threads", str(threads),
|
| 140 |
+
"-v", str(v),
|
| 141 |
+
"-s", str(s)
|
| 142 |
+
]
|
| 143 |
+
|
| 144 |
+
return run_command(cmd)
|
| 145 |
+
|
| 146 |
+
@mcp.tool()
|
| 147 |
+
def mmseqs_easy_search(
|
| 148 |
+
query_fasta: str,
|
| 149 |
+
target_fasta: str,
|
| 150 |
+
output_alignment: str,
|
| 151 |
+
tmp_dir: str,
|
| 152 |
+
s: float = 5.7,
|
| 153 |
+
min_seq_id: float = 0.0,
|
| 154 |
+
c: float = 0.0,
|
| 155 |
+
cov_mode: int = 0,
|
| 156 |
+
threads: int = 1,
|
| 157 |
+
v: int = 3
|
| 158 |
+
):
|
| 159 |
+
"""
|
| 160 |
+
One-step search from FASTA files to an alignment result.
|
| 161 |
+
"""
|
| 162 |
+
if not Path(query_fasta).exists():
|
| 163 |
+
raise FileNotFoundError(f"Query file {query_fasta} not found.")
|
| 164 |
+
if not Path(target_fasta).exists():
|
| 165 |
+
raise FileNotFoundError(f"Target file {target_fasta} not found.")
|
| 166 |
+
|
| 167 |
+
Path(tmp_dir).mkdir(parents=True, exist_ok=True)
|
| 168 |
+
|
| 169 |
+
cmd = [
|
| 170 |
+
"mmseqs", "easy-search",
|
| 171 |
+
query_fasta,
|
| 172 |
+
target_fasta,
|
| 173 |
+
output_alignment,
|
| 174 |
+
tmp_dir,
|
| 175 |
+
"-s", str(s),
|
| 176 |
+
"--min-seq-id", str(min_seq_id),
|
| 177 |
+
"-c", str(c),
|
| 178 |
+
"--cov-mode", str(cov_mode),
|
| 179 |
+
"--threads", str(threads),
|
| 180 |
+
"-v", str(v)
|
| 181 |
+
]
|
| 182 |
+
|
| 183 |
+
return run_command(cmd)
|
| 184 |
+
|
| 185 |
+
@mcp.tool()
|
| 186 |
+
def mmseqs_easy_cluster(
|
| 187 |
+
input_fasta: str,
|
| 188 |
+
output_prefix: str,
|
| 189 |
+
tmp_dir: str,
|
| 190 |
+
min_seq_id: float = 0.0,
|
| 191 |
+
c: float = 0.8,
|
| 192 |
+
cov_mode: int = 0,
|
| 193 |
+
cluster_mode: int = 0,
|
| 194 |
+
threads: int = 1,
|
| 195 |
+
v: int = 3
|
| 196 |
+
):
|
| 197 |
+
"""
|
| 198 |
+
One-step clustering from a FASTA file.
|
| 199 |
+
"""
|
| 200 |
+
if not Path(input_fasta).exists():
|
| 201 |
+
raise FileNotFoundError(f"Input file {input_fasta} not found.")
|
| 202 |
+
|
| 203 |
+
Path(tmp_dir).mkdir(parents=True, exist_ok=True)
|
| 204 |
+
|
| 205 |
+
cmd = [
|
| 206 |
+
"mmseqs", "easy-cluster",
|
| 207 |
+
input_fasta,
|
| 208 |
+
output_prefix,
|
| 209 |
+
tmp_dir,
|
| 210 |
+
"--min-seq-id", str(min_seq_id),
|
| 211 |
+
"-c", str(c),
|
| 212 |
+
"--cov-mode", str(cov_mode),
|
| 213 |
+
"--cluster-mode", str(cluster_mode),
|
| 214 |
+
"--threads", str(threads),
|
| 215 |
+
"-v", str(v)
|
| 216 |
+
]
|
| 217 |
+
|
| 218 |
+
return run_command(cmd)
|
| 219 |
+
|
| 220 |
+
@mcp.tool()
|
| 221 |
+
def mmseqs_easy_linclust(
|
| 222 |
+
input_fasta: str,
|
| 223 |
+
output_prefix: str,
|
| 224 |
+
tmp_dir: str,
|
| 225 |
+
min_seq_id: float = 0.0,
|
| 226 |
+
c: float = 0.8,
|
| 227 |
+
cov_mode: int = 0,
|
| 228 |
+
threads: int = 1,
|
| 229 |
+
v: int = 3
|
| 230 |
+
):
|
| 231 |
+
"""
|
| 232 |
+
Linear time clustering for very large datasets.
|
| 233 |
+
"""
|
| 234 |
+
if not Path(input_fasta).exists():
|
| 235 |
+
raise FileNotFoundError(f"Input file {input_fasta} not found.")
|
| 236 |
+
|
| 237 |
+
Path(tmp_dir).mkdir(parents=True, exist_ok=True)
|
| 238 |
+
|
| 239 |
+
cmd = [
|
| 240 |
+
"mmseqs", "easy-linclust",
|
| 241 |
+
input_fasta,
|
| 242 |
+
output_prefix,
|
| 243 |
+
tmp_dir,
|
| 244 |
+
"--min-seq-id", str(min_seq_id),
|
| 245 |
+
"-c", str(c),
|
| 246 |
+
"--cov-mode", str(cov_mode),
|
| 247 |
+
"--threads", str(threads),
|
| 248 |
+
"-v", str(v)
|
| 249 |
+
]
|
| 250 |
+
|
| 251 |
+
return run_command(cmd)
|
| 252 |
+
|
| 253 |
+
@mcp.tool()
|
| 254 |
+
def mmseqs_convertalis(
|
| 255 |
+
query_db: str,
|
| 256 |
+
target_db: str,
|
| 257 |
+
result_db: str,
|
| 258 |
+
output_file: str,
|
| 259 |
+
format_mode: int = 0,
|
| 260 |
+
format_output: str = "query,target,pident,alnlen,mismatch,gapopen,qstart,qend,tstart,tend,evalue,bits",
|
| 261 |
+
threads: int = 1
|
| 262 |
+
):
|
| 263 |
+
"""
|
| 264 |
+
Convert alignment results into TSV or other formats.
|
| 265 |
+
format_mode: 0: BLAST-TAB, 1: SAM, 2: BLAST-TAB + header, 3: BLAST-XML, 4: BLAST-TAB + query/target seqs.
|
| 266 |
+
"""
|
| 267 |
+
for db in [query_db, target_db, result_db]:
|
| 268 |
+
if not Path(db).exists():
|
| 269 |
+
raise FileNotFoundError(f"Database {db} not found.")
|
| 270 |
+
|
| 271 |
+
cmd = [
|
| 272 |
+
"mmseqs", "convertalis",
|
| 273 |
+
query_db,
|
| 274 |
+
target_db,
|
| 275 |
+
result_db,
|
| 276 |
+
output_file,
|
| 277 |
+
"--format-mode", str(format_mode),
|
| 278 |
+
"--format-output", format_output,
|
| 279 |
+
"--threads", str(threads)
|
| 280 |
+
]
|
| 281 |
+
|
| 282 |
+
return run_command(cmd)
|
| 283 |
+
|
| 284 |
+
@mcp.tool()
|
| 285 |
+
def mmseqs_createtsv(
|
| 286 |
+
input_db: str,
|
| 287 |
+
output_tsv: str,
|
| 288 |
+
threads: int = 1,
|
| 289 |
+
first_seq_id: bool = False
|
| 290 |
+
):
|
| 291 |
+
"""
|
| 292 |
+
Convert a database to a TSV file.
|
| 293 |
+
"""
|
| 294 |
+
if not Path(input_db).exists():
|
| 295 |
+
raise FileNotFoundError(f"Input database {input_db} not found.")
|
| 296 |
+
|
| 297 |
+
cmd = [
|
| 298 |
+
"mmseqs", "createtsv",
|
| 299 |
+
input_db,
|
| 300 |
+
output_tsv,
|
| 301 |
+
"--threads", str(threads),
|
| 302 |
+
"--first-seq-id", str(int(first_seq_id))
|
| 303 |
+
]
|
| 304 |
+
|
| 305 |
+
return run_command(cmd)
|
| 306 |
+
|
| 307 |
+
@mcp.tool()
|
| 308 |
+
def mmseqs_taxonomy(
|
| 309 |
+
query_db: str,
|
| 310 |
+
target_db: str,
|
| 311 |
+
result_db: str,
|
| 312 |
+
tmp_dir: str,
|
| 313 |
+
tax_db: str,
|
| 314 |
+
threads: int = 1,
|
| 315 |
+
v: int = 3,
|
| 316 |
+
lca_mode: int = 3
|
| 317 |
+
):
|
| 318 |
+
"""
|
| 319 |
+
Assign taxonomy to sequences using a reference database.
|
| 320 |
+
lca_mode: 1: LCA, 2: Top hit, 3: Weighted LCA.
|
| 321 |
+
"""
|
| 322 |
+
for db in [query_db, target_db, tax_db]:
|
| 323 |
+
if not Path(db).exists():
|
| 324 |
+
raise FileNotFoundError(f"Database {db} not found.")
|
| 325 |
+
|
| 326 |
+
Path(tmp_dir).mkdir(parents=True, exist_ok=True)
|
| 327 |
+
|
| 328 |
+
cmd = [
|
| 329 |
+
"mmseqs", "taxonomy",
|
| 330 |
+
query_db,
|
| 331 |
+
target_db,
|
| 332 |
+
result_db,
|
| 333 |
+
tmp_dir,
|
| 334 |
+
tax_db,
|
| 335 |
+
"--threads", str(threads),
|
| 336 |
+
"-v", str(v),
|
| 337 |
+
"--lca-mode", str(lca_mode)
|
| 338 |
+
]
|
| 339 |
+
|
| 340 |
+
return run_command(cmd)
|
| 341 |
+
|
| 342 |
+
@mcp.tool()
|
| 343 |
+
def mmseqs_align(
|
| 344 |
+
query_db: str,
|
| 345 |
+
target_db: str,
|
| 346 |
+
result_db: str,
|
| 347 |
+
output_db: str,
|
| 348 |
+
threads: int = 1,
|
| 349 |
+
v: int = 3,
|
| 350 |
+
a: bool = False,
|
| 351 |
+
alignment_mode: int = 3
|
| 352 |
+
):
|
| 353 |
+
"""
|
| 354 |
+
Align two databases.
|
| 355 |
+
a: add backtrace (needed for alignment output).
|
| 356 |
+
"""
|
| 357 |
+
for db in [query_db, target_db, result_db]:
|
| 358 |
+
if not Path(db).exists():
|
| 359 |
+
raise FileNotFoundError(f"Database {db} not found.")
|
| 360 |
+
|
| 361 |
+
cmd = [
|
| 362 |
+
"mmseqs", "align",
|
| 363 |
+
query_db,
|
| 364 |
+
target_db,
|
| 365 |
+
result_db,
|
| 366 |
+
output_db,
|
| 367 |
+
"--threads", str(threads),
|
| 368 |
+
"-v", str(v),
|
| 369 |
+
"-a", str(int(a)),
|
| 370 |
+
"--alignment-mode", str(alignment_mode)
|
| 371 |
+
]
|
| 372 |
+
|
| 373 |
+
return run_command(cmd)
|
| 374 |
+
|
| 375 |
+
@mcp.tool()
|
| 376 |
+
def mmseqs_createindex(
|
| 377 |
+
input_db: str,
|
| 378 |
+
tmp_dir: str,
|
| 379 |
+
threads: int = 1,
|
| 380 |
+
v: int = 3,
|
| 381 |
+
check_compatible: int = 0
|
| 382 |
+
):
|
| 383 |
+
"""
|
| 384 |
+
Create an index for a database to speed up searches.
|
| 385 |
+
"""
|
| 386 |
+
if not Path(input_db).exists():
|
| 387 |
+
raise FileNotFoundError(f"Input database {input_db} not found.")
|
| 388 |
+
|
| 389 |
+
Path(tmp_dir).mkdir(parents=True, exist_ok=True)
|
| 390 |
+
|
| 391 |
+
cmd = [
|
| 392 |
+
"mmseqs", "createindex",
|
| 393 |
+
input_db,
|
| 394 |
+
tmp_dir,
|
| 395 |
+
"--threads", str(threads),
|
| 396 |
+
"-v", str(v),
|
| 397 |
+
"--check-compatible", str(check_compatible)
|
| 398 |
+
]
|
| 399 |
+
|
| 400 |
+
return run_command(cmd)
|
| 401 |
+
|
| 402 |
+
@mcp.tool()
|
| 403 |
+
def mmseqs_map(
|
| 404 |
+
query_db: str,
|
| 405 |
+
target_db: str,
|
| 406 |
+
result_db: str,
|
| 407 |
+
tmp_dir: str,
|
| 408 |
+
threads: int = 1,
|
| 409 |
+
v: int = 3,
|
| 410 |
+
min_seq_id: float = 0.0
|
| 411 |
+
):
|
| 412 |
+
"""
|
| 413 |
+
Map sequences (fast search for high identity).
|
| 414 |
+
"""
|
| 415 |
+
for db in [query_db, target_db]:
|
| 416 |
+
if not Path(db).exists():
|
| 417 |
+
raise FileNotFoundError(f"Database {db} not found.")
|
| 418 |
+
|
| 419 |
+
Path(tmp_dir).mkdir(parents=True, exist_ok=True)
|
| 420 |
+
|
| 421 |
+
cmd = [
|
| 422 |
+
"mmseqs", "map",
|
| 423 |
+
query_db,
|
| 424 |
+
target_db,
|
| 425 |
+
result_db,
|
| 426 |
+
tmp_dir,
|
| 427 |
+
"--threads", str(threads),
|
| 428 |
+
"-v", str(v),
|
| 429 |
+
"--min-seq-id", str(min_seq_id)
|
| 430 |
+
]
|
| 431 |
+
|
| 432 |
+
return run_command(cmd)
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mmseqs2/app/mmseqs2_shim_server.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import ast
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
from mcp.server.fastmcp import FastMCP
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
SOURCE_SERVER = Path('/225040511/project/BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mmseqs2/app/mmseqs2_server.py')
|
| 11 |
+
SERVER_NAME = 'biosci_mmseqs2'
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class _ShimMCP:
|
| 15 |
+
@staticmethod
|
| 16 |
+
def tool():
|
| 17 |
+
def _decorator(fn):
|
| 18 |
+
return fn
|
| 19 |
+
return _decorator
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def _load_functions():
|
| 23 |
+
code = SOURCE_SERVER.read_text(encoding="utf-8")
|
| 24 |
+
tree = ast.parse(code, filename=str(SOURCE_SERVER))
|
| 25 |
+
function_names = [n.name for n in tree.body if isinstance(n, ast.FunctionDef) and not n.name.startswith("_")]
|
| 26 |
+
namespace = {
|
| 27 |
+
"__name__": "__mcp_source__",
|
| 28 |
+
"mcp": _ShimMCP(),
|
| 29 |
+
}
|
| 30 |
+
exec(compile(code, str(SOURCE_SERVER), "exec"), namespace, namespace)
|
| 31 |
+
loaded = []
|
| 32 |
+
for name in function_names:
|
| 33 |
+
fn = namespace.get(name)
|
| 34 |
+
if callable(fn):
|
| 35 |
+
loaded.append(fn)
|
| 36 |
+
return loaded
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
mcp = FastMCP(SERVER_NAME)
|
| 40 |
+
for _fn in _load_functions():
|
| 41 |
+
mcp.tool()(_fn)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
if __name__ == "__main__":
|
| 45 |
+
mcp.run(transport="stdio")
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mmseqs2/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mmseqs2/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-mmseqs2:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-mmseqs2:latest
|
| 7 |
+
container_name: mcp-mmseqs2
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=mmseqs2
|
| 12 |
+
volumes:
|
| 13 |
+
- ./workspace:/app/workspace
|
| 14 |
+
- ./output:/app/output
|
| 15 |
+
restart: unless-stopped
|
| 16 |
+
healthcheck:
|
| 17 |
+
test: ["CMD", "python", "-c", "import sys; sys.exit(0)"]
|
| 18 |
+
interval: 30s
|
| 19 |
+
timeout: 10s
|
| 20 |
+
retries: 3
|
| 21 |
+
start_period: 5s
|
| 22 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mmseqs2/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- mmseqs2
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mmseqs2/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mmtf-python/Dockerfile
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# Install system dependencies
|
| 5 |
+
RUN apt-get update && apt-get install -y default-jre wget curl && apt-get clean && rm -rf /var/lib/apt/lists/*
|
| 6 |
+
|
| 7 |
+
# Install Miniconda
|
| 8 |
+
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O /tmp/miniconda.sh && bash /tmp/miniconda.sh -b -p /opt/conda && rm /tmp/miniconda.sh
|
| 9 |
+
|
| 10 |
+
# Add conda to PATH
|
| 11 |
+
ENV PATH="/opt/conda/bin:$PATH"
|
| 12 |
+
|
| 13 |
+
# Install mmtf-python via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda mmtf-python -y && conda clean -a
|
| 15 |
+
|
| 16 |
+
# Install Python dependencies
|
| 17 |
+
RUN pip install uv
|
| 18 |
+
RUN uv pip install --system fastmcp
|
| 19 |
+
|
| 20 |
+
# Create app directory
|
| 21 |
+
WORKDIR /app
|
| 22 |
+
|
| 23 |
+
# Copy your MCP server
|
| 24 |
+
COPY app/mmtf-python_server.py /app/
|
| 25 |
+
|
| 26 |
+
# Create workspace and output directories
|
| 27 |
+
RUN mkdir -p /app/workspace /app/output
|
| 28 |
+
|
| 29 |
+
# Make sure the server script is executable
|
| 30 |
+
RUN chmod +x /app/mmtf-python_server.py
|
| 31 |
+
|
| 32 |
+
# Expose port for MCP over HTTP (optional)
|
| 33 |
+
EXPOSE 8000
|
| 34 |
+
|
| 35 |
+
# Health check
|
| 36 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 CMD python -c "import sys; sys.exit(0)"
|
| 37 |
+
|
| 38 |
+
# Default command runs the MCP server via stdio
|
| 39 |
+
CMD ["python", "/app/mmtf-python_server.py"]
|
| 40 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mmtf-python/app/mmtf-python_server.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
from typing import List
|
| 4 |
+
|
| 5 |
+
# MCP decorator placeholder
|
| 6 |
+
# In a real MCP environment, this would be:
|
| 7 |
+
# from mcp import mcp
|
| 8 |
+
# @mcp.tool()
|
| 9 |
+
def mcp_tool_decorator():
|
| 10 |
+
def decorator(func):
|
| 11 |
+
return func
|
| 12 |
+
return decorator
|
| 13 |
+
|
| 14 |
+
@mcp_tool_decorator()
|
| 15 |
+
def fetch_mmtf(
|
| 16 |
+
pdb_id: str,
|
| 17 |
+
output_file: Path,
|
| 18 |
+
):
|
| 19 |
+
"""
|
| 20 |
+
Fetches a PDB entry in MMTF format from the RCSB PDB and saves it to a file.
|
| 21 |
+
|
| 22 |
+
This tool acts as a command-line wrapper for the 'mmtf-python' library,
|
| 23 |
+
which does not have its own executable. It uses the library's `fetch` and
|
| 24 |
+
`write_mmtf` functions to download and save the specified structure.
|
| 25 |
+
|
| 26 |
+
Args:
|
| 27 |
+
pdb_id (str): The 4-character PDB ID to fetch (e.g., '1AQ1').
|
| 28 |
+
output_file (Path): The path to save the output MMTF file.
|
| 29 |
+
"""
|
| 30 |
+
# --- Input Validation ---
|
| 31 |
+
if not pdb_id or len(pdb_id) != 4 or not pdb_id.isalnum():
|
| 32 |
+
raise ValueError("pdb_id must be a 4-character alphanumeric string.")
|
| 33 |
+
|
| 34 |
+
if not output_file.parent.exists():
|
| 35 |
+
try:
|
| 36 |
+
output_file.parent.mkdir(parents=True, exist_ok=True)
|
| 37 |
+
except OSError as e:
|
| 38 |
+
raise OSError(f"Failed to create output directory {output_file.parent}: {e}")
|
| 39 |
+
|
| 40 |
+
# --- Command-line script construction ---
|
| 41 |
+
# This Python one-liner imports the necessary functions from the mmtf library,
|
| 42 |
+
# fetches the data for the given PDB ID, and writes it to the specified output file.
|
| 43 |
+
py_command = (
|
| 44 |
+
f"from mmtf import fetch, write_mmtf; "
|
| 45 |
+
f"mmtf_data = fetch('{pdb_id}'); "
|
| 46 |
+
f"write_mmtf('{str(output_file)}', mmtf_data)"
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
cmd = ["python", "-c", py_command]
|
| 50 |
+
command_executed = " ".join(cmd)
|
| 51 |
+
|
| 52 |
+
# --- Subprocess Execution ---
|
| 53 |
+
try:
|
| 54 |
+
process = subprocess.run(
|
| 55 |
+
cmd,
|
| 56 |
+
capture_output=True,
|
| 57 |
+
text=True,
|
| 58 |
+
check=True,
|
| 59 |
+
encoding='utf-8'
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
if not output_file.exists() or output_file.stat().st_size == 0:
|
| 63 |
+
# This case handles situations where the command succeeds (exit code 0)
|
| 64 |
+
# but the output file is not created or is empty, which can happen
|
| 65 |
+
# if the PDB ID is valid but has no MMTF data available.
|
| 66 |
+
error_message = (
|
| 67 |
+
f"Command executed successfully, but the output file was not created or is empty. "
|
| 68 |
+
f"This may indicate that MMTF data is not available for PDB ID '{pdb_id}'.\n"
|
| 69 |
+
f"Stderr: {process.stderr}"
|
| 70 |
+
)
|
| 71 |
+
return {
|
| 72 |
+
"error": error_message,
|
| 73 |
+
"command_executed": command_executed,
|
| 74 |
+
"stdout": process.stdout,
|
| 75 |
+
"stderr": process.stderr,
|
| 76 |
+
"return_code": 0,
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
return {
|
| 80 |
+
"command_executed": command_executed,
|
| 81 |
+
"stdout": process.stdout,
|
| 82 |
+
"stderr": process.stderr,
|
| 83 |
+
"output_files": [str(output_file)]
|
| 84 |
+
}
|
| 85 |
+
except FileNotFoundError:
|
| 86 |
+
# This error occurs if the 'python' executable is not found in the system's PATH.
|
| 87 |
+
return {
|
| 88 |
+
"error": "Python executable not found. Ensure Python is installed and in the system's PATH.",
|
| 89 |
+
"command_executed": command_executed,
|
| 90 |
+
}
|
| 91 |
+
except subprocess.CalledProcessError as e:
|
| 92 |
+
# This catches non-zero exit codes from the subprocess, which typically indicate
|
| 93 |
+
# an error within the mmtf-python library (e.g., PDB ID not found, network issues).
|
| 94 |
+
return {
|
| 95 |
+
"error": f"Execution failed with return code {e.returncode}.",
|
| 96 |
+
"command_executed": command_executed,
|
| 97 |
+
"stdout": e.stdout,
|
| 98 |
+
"stderr": e.stderr,
|
| 99 |
+
"return_code": e.returncode,
|
| 100 |
+
}
|
| 101 |
+
except Exception as e:
|
| 102 |
+
# Catch any other unexpected errors during execution.
|
| 103 |
+
return {
|
| 104 |
+
"error": f"An unexpected error occurred: {str(e)}",
|
| 105 |
+
"command_executed": command_executed,
|
| 106 |
+
}
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mmtf-python/app/mmtf-python_shim_server.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import ast
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
from mcp.server.fastmcp import FastMCP
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
SOURCE_SERVER = Path('/225040511/project/BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mmtf-python/app/mmtf-python_server.py')
|
| 11 |
+
SERVER_NAME = 'biosci_mmtf_python'
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class _ShimMCP:
|
| 15 |
+
@staticmethod
|
| 16 |
+
def tool():
|
| 17 |
+
def _decorator(fn):
|
| 18 |
+
return fn
|
| 19 |
+
return _decorator
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def _load_functions():
|
| 23 |
+
code = SOURCE_SERVER.read_text(encoding="utf-8")
|
| 24 |
+
tree = ast.parse(code, filename=str(SOURCE_SERVER))
|
| 25 |
+
function_names = [n.name for n in tree.body if isinstance(n, ast.FunctionDef) and not n.name.startswith("_")]
|
| 26 |
+
namespace = {
|
| 27 |
+
"__name__": "__mcp_source__",
|
| 28 |
+
"mcp": _ShimMCP(),
|
| 29 |
+
}
|
| 30 |
+
exec(compile(code, str(SOURCE_SERVER), "exec"), namespace, namespace)
|
| 31 |
+
loaded = []
|
| 32 |
+
for name in function_names:
|
| 33 |
+
fn = namespace.get(name)
|
| 34 |
+
if callable(fn):
|
| 35 |
+
loaded.append(fn)
|
| 36 |
+
return loaded
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
mcp = FastMCP(SERVER_NAME)
|
| 40 |
+
for _fn in _load_functions():
|
| 41 |
+
mcp.tool()(_fn)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
if __name__ == "__main__":
|
| 45 |
+
mcp.run(transport="stdio")
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mmtf-python/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mmtf-python/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-mmtf-python:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-mmtf-python:latest
|
| 7 |
+
container_name: mcp-mmtf-python
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=mmtf-python
|
| 12 |
+
volumes:
|
| 13 |
+
- ./workspace:/app/workspace
|
| 14 |
+
- ./output:/app/output
|
| 15 |
+
restart: unless-stopped
|
| 16 |
+
healthcheck:
|
| 17 |
+
test: ["CMD", "python", "-c", "import sys; sys.exit(0)"]
|
| 18 |
+
interval: 30s
|
| 19 |
+
timeout: 10s
|
| 20 |
+
retries: 3
|
| 21 |
+
start_period: 5s
|
| 22 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mmtf-python/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- mmtf-python
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mmtf-python/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mobivision-m/Dockerfile
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# Install system dependencies
|
| 5 |
+
RUN apt-get update && apt-get install -y default-jre wget curl && apt-get clean && rm -rf /var/lib/apt/lists/*
|
| 6 |
+
|
| 7 |
+
# Install Miniconda
|
| 8 |
+
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O /tmp/miniconda.sh && bash /tmp/miniconda.sh -b -p /opt/conda && rm /tmp/miniconda.sh
|
| 9 |
+
|
| 10 |
+
# Add conda to PATH
|
| 11 |
+
ENV PATH="/opt/conda/bin:$PATH"
|
| 12 |
+
|
| 13 |
+
# Install mobivision-m via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda mobivision-m -y && conda clean -a
|
| 15 |
+
|
| 16 |
+
# Install Python dependencies
|
| 17 |
+
RUN pip install uv
|
| 18 |
+
RUN uv pip install --system fastmcp
|
| 19 |
+
|
| 20 |
+
# Create app directory
|
| 21 |
+
WORKDIR /app
|
| 22 |
+
|
| 23 |
+
# Copy your MCP server
|
| 24 |
+
COPY app/mobivision-m_server.py /app/
|
| 25 |
+
|
| 26 |
+
# Create workspace and output directories
|
| 27 |
+
RUN mkdir -p /app/workspace /app/output
|
| 28 |
+
|
| 29 |
+
# Make sure the server script is executable
|
| 30 |
+
RUN chmod +x /app/mobivision-m_server.py
|
| 31 |
+
|
| 32 |
+
# Expose port for MCP over HTTP (optional)
|
| 33 |
+
EXPOSE 8000
|
| 34 |
+
|
| 35 |
+
# Health check
|
| 36 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 CMD python -c "import sys; sys.exit(0)"
|
| 37 |
+
|
| 38 |
+
# Default command runs the MCP server via stdio
|
| 39 |
+
CMD ["python", "/app/mobivision-m_server.py"]
|
| 40 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mobivision-m/app/mobivision-m_server.py
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
from typing import Optional, Dict, Any, List
|
| 4 |
+
|
| 5 |
+
# Helper function to run commands and handle errors
|
| 6 |
+
def _run_command(cmd: List[str], cwd: Optional[Path] = None) -> Dict[str, Any]:
|
| 7 |
+
"""
|
| 8 |
+
Executes a shell command and captures its output.
|
| 9 |
+
"""
|
| 10 |
+
try:
|
| 11 |
+
process = subprocess.run(
|
| 12 |
+
cmd,
|
| 13 |
+
cwd=cwd,
|
| 14 |
+
capture_output=True,
|
| 15 |
+
text=True,
|
| 16 |
+
check=True
|
| 17 |
+
)
|
| 18 |
+
return {
|
| 19 |
+
"command_executed": " ".join(cmd),
|
| 20 |
+
"stdout": process.stdout,
|
| 21 |
+
"stderr": process.stderr,
|
| 22 |
+
"output_files": [], # To be populated by specific tools
|
| 23 |
+
}
|
| 24 |
+
except subprocess.CalledProcessError as e:
|
| 25 |
+
return {
|
| 26 |
+
"command_executed": " ".join(cmd),
|
| 27 |
+
"stdout": e.stdout,
|
| 28 |
+
"stderr": e.stderr,
|
| 29 |
+
"error": f"Command failed with exit code {e.returncode}: {e}",
|
| 30 |
+
"returncode": e.returncode,
|
| 31 |
+
"output_files": [],
|
| 32 |
+
}
|
| 33 |
+
except FileNotFoundError:
|
| 34 |
+
return {
|
| 35 |
+
"command_executed": " ".join(cmd),
|
| 36 |
+
"stdout": "",
|
| 37 |
+
"stderr": "Error: 'mobivision-M' command not found. Please ensure MobiVision-M is installed and in your system's PATH.",
|
| 38 |
+
"error": "Tool not found",
|
| 39 |
+
"returncode": 127,
|
| 40 |
+
"output_files": [],
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
@mcp.tool()
|
| 44 |
+
def mkindex(
|
| 45 |
+
index_name: str,
|
| 46 |
+
fasta_file: Path,
|
| 47 |
+
gtf_file: Path,
|
| 48 |
+
output_dir: Path,
|
| 49 |
+
) -> Dict[str, Any]:
|
| 50 |
+
"""
|
| 51 |
+
Creates a STAR index for single-microbe RNA sequencing analysis using MobiVision-M.
|
| 52 |
+
|
| 53 |
+
This subcommand generates a STAR index from a reference FASTA file and a GTF annotation file,
|
| 54 |
+
which is essential for subsequent alignment and quantification steps.
|
| 55 |
+
|
| 56 |
+
Args:
|
| 57 |
+
index_name: A unique name or identifier for the generated STAR index.
|
| 58 |
+
fasta_file: Path to the input FASTA file containing the reference genome sequence.
|
| 59 |
+
This file must exist.
|
| 60 |
+
gtf_file: Path to the input GTF file containing gene annotations for the reference genome.
|
| 61 |
+
This file must exist.
|
| 62 |
+
output_dir: Path to the directory where the STAR index files will be created.
|
| 63 |
+
The directory will be created if it does not exist.
|
| 64 |
+
|
| 65 |
+
Returns:
|
| 66 |
+
A dictionary containing the command executed, stdout, stderr, and a list of
|
| 67 |
+
generated output files. In case of an error, an 'error' key will be present.
|
| 68 |
+
"""
|
| 69 |
+
# Input validation
|
| 70 |
+
if not isinstance(index_name, str) or not index_name:
|
| 71 |
+
raise ValueError("Index name must be a non-empty string.")
|
| 72 |
+
if not fasta_file.is_file():
|
| 73 |
+
raise ValueError(f"Input FASTA file not found: {fasta_file}")
|
| 74 |
+
if not gtf_file.is_file():
|
| 75 |
+
raise ValueError(f"Input GTF file not found: {gtf_file}")
|
| 76 |
+
|
| 77 |
+
# Ensure output directory exists
|
| 78 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
| 79 |
+
if not output_dir.is_dir():
|
| 80 |
+
raise ValueError(f"Output path is not a directory or could not be created: {output_dir}")
|
| 81 |
+
|
| 82 |
+
cmd = [
|
| 83 |
+
"mobivision-M",
|
| 84 |
+
"mkindex",
|
| 85 |
+
"-n", index_name,
|
| 86 |
+
"-f", str(fasta_file),
|
| 87 |
+
"-g", str(gtf_file),
|
| 88 |
+
"-o", str(output_dir),
|
| 89 |
+
]
|
| 90 |
+
|
| 91 |
+
result = _run_command(cmd)
|
| 92 |
+
if "error" not in result:
|
| 93 |
+
# List all files created within the output directory
|
| 94 |
+
result["output_files"] = [str(p) for p in output_dir.rglob("*") if p.is_file()]
|
| 95 |
+
return result
|
| 96 |
+
|
| 97 |
+
@mcp.tool()
|
| 98 |
+
def quantify(
|
| 99 |
+
input_data_dir: Path,
|
| 100 |
+
star_index_dir: Path,
|
| 101 |
+
sample_name: str,
|
| 102 |
+
output_dir: Path,
|
| 103 |
+
threads: int = 1,
|
| 104 |
+
) -> Dict[str, Any]:
|
| 105 |
+
"""
|
| 106 |
+
Quantifies single-microbe RNA sequencing data using a pre-built STAR index with MobiVision-M.
|
| 107 |
+
|
| 108 |
+
This subcommand performs barcoding, adaptor-removing, alignment, re-assignment of multi-loci
|
| 109 |
+
mapped reads, and initial statistical analysis for single-microbe RNA-seq data.
|
| 110 |
+
|
| 111 |
+
Args:
|
| 112 |
+
input_data_dir: Path to the directory containing raw sequencing data (e.g., FASTQ files).
|
| 113 |
+
This directory must exist.
|
| 114 |
+
star_index_dir: Path to the STAR index directory previously created by `mkindex`.
|
| 115 |
+
This directory must exist.
|
| 116 |
+
sample_name: The name of the sample being processed. This will often be used in output filenames.
|
| 117 |
+
output_dir: Path to the directory where quantification results will be stored.
|
| 118 |
+
The directory will be created if it does not exist.
|
| 119 |
+
threads: Number of threads (CPU cores) to use for processing. Must be a positive integer.
|
| 120 |
+
Defaults to 1.
|
| 121 |
+
|
| 122 |
+
Returns:
|
| 123 |
+
A dictionary containing the command executed, stdout, stderr, and a list of
|
| 124 |
+
generated output files. In case of an error, an 'error' key will be present.
|
| 125 |
+
"""
|
| 126 |
+
# Input validation
|
| 127 |
+
if not input_data_dir.is_dir():
|
| 128 |
+
raise ValueError(f"Input data directory not found: {input_data_dir}")
|
| 129 |
+
if not star_index_dir.is_dir():
|
| 130 |
+
raise ValueError(f"STAR index directory not found: {star_index_dir}")
|
| 131 |
+
if not isinstance(sample_name, str) or not sample_name:
|
| 132 |
+
raise ValueError("Sample name must be a non-empty string.")
|
| 133 |
+
if not isinstance(threads, int) or threads <= 0:
|
| 134 |
+
raise ValueError("Number of threads must be a positive integer.")
|
| 135 |
+
|
| 136 |
+
# Ensure output directory exists
|
| 137 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
| 138 |
+
if not output_dir.is_dir():
|
| 139 |
+
raise ValueError(f"Output path is not a directory or could not be created: {output_dir}")
|
| 140 |
+
|
| 141 |
+
cmd = [
|
| 142 |
+
"mobivision-M",
|
| 143 |
+
"quantify",
|
| 144 |
+
"-f", str(input_data_dir),
|
| 145 |
+
"-t", str(threads),
|
| 146 |
+
"-i", str(star_index_dir),
|
| 147 |
+
"-s", sample_name,
|
| 148 |
+
"-o", str(output_dir),
|
| 149 |
+
]
|
| 150 |
+
|
| 151 |
+
result = _run_command(cmd)
|
| 152 |
+
if "error" not in result:
|
| 153 |
+
# List all files created within the output directory
|
| 154 |
+
result["output_files"] = [str(p) for p in output_dir.rglob("*") if p.is_file()]
|
| 155 |
+
return result
|
| 156 |
+
|
| 157 |
+
@mcp.tool()
|
| 158 |
+
def rcmicrobe(
|
| 159 |
+
input_result_dir: Path,
|
| 160 |
+
output_dir: Path,
|
| 161 |
+
threads: int = 1,
|
| 162 |
+
enable_cr2_2: bool = False,
|
| 163 |
+
) -> Dict[str, Any]:
|
| 164 |
+
"""
|
| 165 |
+
Re-calls microbes from an analyzed result directory generated by MobiVision-M.
|
| 166 |
+
|
| 167 |
+
This subcommand allows for re-analysis or re-calling of microbes based on a previously
|
| 168 |
+
quantified result, potentially with different parameters or algorithms.
|
| 169 |
+
|
| 170 |
+
Args:
|
| 171 |
+
input_result_dir: Path to the input analysis result directory from a previous `quantify` run.
|
| 172 |
+
This directory must exist.
|
| 173 |
+
output_dir: Path to the directory where re-called microbe results will be stored.
|
| 174 |
+
The directory will be created if it does not exist.
|
| 175 |
+
threads: Number of threads (CPU cores) to use for processing. Must be a positive integer.
|
| 176 |
+
Defaults to 1.
|
| 177 |
+
enable_cr2_2: If True, enables a specific 'cr2.2' re-calling algorithm or mode.
|
| 178 |
+
Defaults to False.
|
| 179 |
+
|
| 180 |
+
Returns:
|
| 181 |
+
A dictionary containing the command executed, stdout, stderr, and a list of
|
| 182 |
+
generated output files. In case of an error, an 'error' key will be present.
|
| 183 |
+
"""
|
| 184 |
+
# Input validation
|
| 185 |
+
if not input_result_dir.is_dir():
|
| 186 |
+
raise ValueError(f"Input result directory not found: {input_result_dir}")
|
| 187 |
+
if not isinstance(threads, int) or threads <= 0:
|
| 188 |
+
raise ValueError("Number of threads must be a positive integer.")
|
| 189 |
+
|
| 190 |
+
# Ensure output directory exists
|
| 191 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
| 192 |
+
if not output_dir.is_dir():
|
| 193 |
+
raise ValueError(f"Output path is not a directory or could not be created: {output_dir}")
|
| 194 |
+
|
| 195 |
+
cmd = [
|
| 196 |
+
"mobivision-M",
|
| 197 |
+
"rcmicrobe",
|
| 198 |
+
"-i", str(input_result_dir),
|
| 199 |
+
"-o", str(output_dir),
|
| 200 |
+
"-t", str(threads),
|
| 201 |
+
]
|
| 202 |
+
if enable_cr2_2:
|
| 203 |
+
cmd.append("--cr2.2")
|
| 204 |
+
|
| 205 |
+
result = _run_command(cmd)
|
| 206 |
+
if "error" not in result:
|
| 207 |
+
# List all files created within the output directory
|
| 208 |
+
result["output_files"] = [str(p) for p in output_dir.rglob("*") if p.is_file()]
|
| 209 |
+
return result
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mobivision-m/app/mobivision-m_shim_server.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import ast
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
from mcp.server.fastmcp import FastMCP
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
SOURCE_SERVER = Path('/225040511/project/BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mobivision-m/app/mobivision-m_server.py')
|
| 11 |
+
SERVER_NAME = 'biosci_mobivision_m'
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class _ShimMCP:
|
| 15 |
+
@staticmethod
|
| 16 |
+
def tool():
|
| 17 |
+
def _decorator(fn):
|
| 18 |
+
return fn
|
| 19 |
+
return _decorator
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def _load_functions():
|
| 23 |
+
code = SOURCE_SERVER.read_text(encoding="utf-8")
|
| 24 |
+
tree = ast.parse(code, filename=str(SOURCE_SERVER))
|
| 25 |
+
function_names = [n.name for n in tree.body if isinstance(n, ast.FunctionDef) and not n.name.startswith("_")]
|
| 26 |
+
namespace = {
|
| 27 |
+
"__name__": "__mcp_source__",
|
| 28 |
+
"mcp": _ShimMCP(),
|
| 29 |
+
}
|
| 30 |
+
exec(compile(code, str(SOURCE_SERVER), "exec"), namespace, namespace)
|
| 31 |
+
loaded = []
|
| 32 |
+
for name in function_names:
|
| 33 |
+
fn = namespace.get(name)
|
| 34 |
+
if callable(fn):
|
| 35 |
+
loaded.append(fn)
|
| 36 |
+
return loaded
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
mcp = FastMCP(SERVER_NAME)
|
| 40 |
+
for _fn in _load_functions():
|
| 41 |
+
mcp.tool()(_fn)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
if __name__ == "__main__":
|
| 45 |
+
mcp.run(transport="stdio")
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mobivision-m/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mobivision-m/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-mobivision-m:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-mobivision-m:latest
|
| 7 |
+
container_name: mcp-mobivision-m
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=mobivision-m
|
| 12 |
+
volumes:
|
| 13 |
+
- ./workspace:/app/workspace
|
| 14 |
+
- ./output:/app/output
|
| 15 |
+
restart: unless-stopped
|
| 16 |
+
healthcheck:
|
| 17 |
+
test: ["CMD", "python", "-c", "import sys; sys.exit(0)"]
|
| 18 |
+
interval: 30s
|
| 19 |
+
timeout: 10s
|
| 20 |
+
retries: 3
|
| 21 |
+
start_period: 5s
|
| 22 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mobivision-m/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- mobivision-m
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mobivision-m/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_moments/Dockerfile
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# Install system dependencies
|
| 5 |
+
RUN apt-get update && apt-get install -y default-jre wget curl && apt-get clean && rm -rf /var/lib/apt/lists/*
|
| 6 |
+
|
| 7 |
+
# Install Miniconda
|
| 8 |
+
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O /tmp/miniconda.sh && bash /tmp/miniconda.sh -b -p /opt/conda && rm /tmp/miniconda.sh
|
| 9 |
+
|
| 10 |
+
# Add conda to PATH
|
| 11 |
+
ENV PATH="/opt/conda/bin:$PATH"
|
| 12 |
+
|
| 13 |
+
# Install moments via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda moments -y && conda clean -a
|
| 15 |
+
|
| 16 |
+
# Install Python dependencies
|
| 17 |
+
RUN pip install uv
|
| 18 |
+
RUN uv pip install --system fastmcp
|
| 19 |
+
|
| 20 |
+
# Create app directory
|
| 21 |
+
WORKDIR /app
|
| 22 |
+
|
| 23 |
+
# Copy your MCP server
|
| 24 |
+
COPY app/moments_server.py /app/
|
| 25 |
+
|
| 26 |
+
# Create workspace and output directories
|
| 27 |
+
RUN mkdir -p /app/workspace /app/output
|
| 28 |
+
|
| 29 |
+
# Make sure the server script is executable
|
| 30 |
+
RUN chmod +x /app/moments_server.py
|
| 31 |
+
|
| 32 |
+
# Expose port for MCP over HTTP (optional)
|
| 33 |
+
EXPOSE 8000
|
| 34 |
+
|
| 35 |
+
# Health check
|
| 36 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 CMD python -c "import sys; sys.exit(0)"
|
| 37 |
+
|
| 38 |
+
# Default command runs the MCP server via stdio
|
| 39 |
+
CMD ["python", "/app/moments_server.py"]
|
| 40 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_moments/app/moments_server.py
ADDED
|
@@ -0,0 +1,445 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import sys
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
from typing import Optional, List, Union
|
| 5 |
+
import json
|
| 6 |
+
import tempfile
|
| 7 |
+
|
| 8 |
+
@mcp.tool()
|
| 9 |
+
def moments_vcf_to_sfs(
|
| 10 |
+
vcf_path: str,
|
| 11 |
+
pop_info_path: str,
|
| 12 |
+
populations: List[str],
|
| 13 |
+
projections: List[int],
|
| 14 |
+
output_path: str,
|
| 15 |
+
polarized: bool = False,
|
| 16 |
+
):
|
| 17 |
+
"""
|
| 18 |
+
Parses a VCF file and generates a Site Frequency Spectrum (SFS).
|
| 19 |
+
|
| 20 |
+
:param vcf_path: Path to the input VCF file.
|
| 21 |
+
:param pop_info_path: Path to the population information file (mapping individuals to populations).
|
| 22 |
+
:param populations: List of population IDs to include in the SFS.
|
| 23 |
+
:param projections: List of sample sizes (number of chromosomes) to project down to for each population.
|
| 24 |
+
:param output_path: Path to save the resulting SFS file (usually .fs).
|
| 25 |
+
:param polarized: Whether the SFS should be polarized (requires ancestral allele information in VCF).
|
| 26 |
+
"""
|
| 27 |
+
vcf_p = Path(vcf_path)
|
| 28 |
+
pop_p = Path(pop_info_path)
|
| 29 |
+
out_p = Path(output_path)
|
| 30 |
+
|
| 31 |
+
if not vcf_p.exists():
|
| 32 |
+
return {"error": f"VCF file not found: {vcf_path}"}
|
| 33 |
+
if not pop_p.exists():
|
| 34 |
+
return {"error": f"Population info file not found: {pop_info_path}"}
|
| 35 |
+
if len(populations) != len(projections):
|
| 36 |
+
return {"error": "The number of populations must match the number of projections."}
|
| 37 |
+
|
| 38 |
+
# Construct Python script to run moments
|
| 39 |
+
python_script = f"""
|
| 40 |
+
import moments
|
| 41 |
+
import sys
|
| 42 |
+
|
| 43 |
+
try:
|
| 44 |
+
sfs = moments.Spectrum.from_vcf(
|
| 45 |
+
'{vcf_path}',
|
| 46 |
+
popfile='{pop_info_path}',
|
| 47 |
+
populations={populations},
|
| 48 |
+
projections={projections},
|
| 49 |
+
polarized={polarized}
|
| 50 |
+
)
|
| 51 |
+
sfs.to_file('{output_path}')
|
| 52 |
+
print("Successfully created SFS.")
|
| 53 |
+
except Exception as e:
|
| 54 |
+
print(f"Error: {{str(e)}}", file=sys.stderr)
|
| 55 |
+
sys.exit(1)
|
| 56 |
+
"""
|
| 57 |
+
|
| 58 |
+
try:
|
| 59 |
+
result = subprocess.run(
|
| 60 |
+
[sys.executable, "-c", python_script],
|
| 61 |
+
capture_output=True,
|
| 62 |
+
text=True,
|
| 63 |
+
check=True
|
| 64 |
+
)
|
| 65 |
+
return {
|
| 66 |
+
"command_executed": f"moments.Spectrum.from_vcf('{vcf_path}', ...)",
|
| 67 |
+
"stdout": result.stdout,
|
| 68 |
+
"stderr": result.stderr,
|
| 69 |
+
"output_files": [output_path]
|
| 70 |
+
}
|
| 71 |
+
except subprocess.CalledProcessError as e:
|
| 72 |
+
return {
|
| 73 |
+
"error": "Failed to parse VCF to SFS",
|
| 74 |
+
"stdout": e.stdout,
|
| 75 |
+
"stderr": e.stderr
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
@mcp.tool()
|
| 79 |
+
def moments_vcf_to_ld_stats(
|
| 80 |
+
vcf_path: str,
|
| 81 |
+
pop_info_path: str,
|
| 82 |
+
populations: List[str],
|
| 83 |
+
output_path: str,
|
| 84 |
+
bins: Optional[List[float]] = None,
|
| 85 |
+
use_cache: bool = True,
|
| 86 |
+
):
|
| 87 |
+
"""
|
| 88 |
+
Computes Linkage Disequilibrium (LD) statistics from a VCF file.
|
| 89 |
+
|
| 90 |
+
:param vcf_path: Path to the input VCF file.
|
| 91 |
+
:param pop_info_path: Path to the population information file.
|
| 92 |
+
:param populations: List of population IDs to include.
|
| 93 |
+
:param output_path: Path to save the computed LD statistics (usually .hdf5 or .p).
|
| 94 |
+
:param bins: Recombination distance bins (list of floats). If None, default bins are used.
|
| 95 |
+
:param use_cache: Whether to use caching for intermediate steps.
|
| 96 |
+
"""
|
| 97 |
+
vcf_p = Path(vcf_path)
|
| 98 |
+
pop_p = Path(pop_info_path)
|
| 99 |
+
|
| 100 |
+
if not vcf_p.exists():
|
| 101 |
+
return {"error": f"VCF file not found: {vcf_path}"}
|
| 102 |
+
if not pop_p.exists():
|
| 103 |
+
return {"error": f"Population info file not found: {pop_info_path}"}
|
| 104 |
+
|
| 105 |
+
bins_str = str(bins) if bins is not None else "None"
|
| 106 |
+
|
| 107 |
+
python_script = f"""
|
| 108 |
+
import moments.LD
|
| 109 |
+
import sys
|
| 110 |
+
|
| 111 |
+
try:
|
| 112 |
+
ld_stats = moments.LD.Parsing.compute_ld_statistics(
|
| 113 |
+
'{vcf_path}',
|
| 114 |
+
pop_file='{pop_info_path}',
|
| 115 |
+
pops={populations},
|
| 116 |
+
bins={bins_str},
|
| 117 |
+
use_cache={use_cache}
|
| 118 |
+
)
|
| 119 |
+
# moments.LD statistics are typically saved using pickle or hdf5
|
| 120 |
+
import pickle
|
| 121 |
+
with open('{output_path}', 'wb') as f:
|
| 122 |
+
pickle.dump(ld_stats, f)
|
| 123 |
+
print("Successfully computed LD statistics.")
|
| 124 |
+
except Exception as e:
|
| 125 |
+
print(f"Error: {{str(e)}}", file=sys.stderr)
|
| 126 |
+
sys.exit(1)
|
| 127 |
+
"""
|
| 128 |
+
|
| 129 |
+
try:
|
| 130 |
+
result = subprocess.run(
|
| 131 |
+
[sys.executable, "-c", python_script],
|
| 132 |
+
capture_output=True,
|
| 133 |
+
text=True,
|
| 134 |
+
check=True
|
| 135 |
+
)
|
| 136 |
+
return {
|
| 137 |
+
"command_executed": "moments.LD.Parsing.compute_ld_statistics(...)",
|
| 138 |
+
"stdout": result.stdout,
|
| 139 |
+
"stderr": result.stderr,
|
| 140 |
+
"output_files": [output_path]
|
| 141 |
+
}
|
| 142 |
+
except subprocess.CalledProcessError as e:
|
| 143 |
+
return {
|
| 144 |
+
"error": "Failed to compute LD statistics",
|
| 145 |
+
"stdout": e.stdout,
|
| 146 |
+
"stderr": e.stderr
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
@mcp.tool()
|
| 150 |
+
def moments_simulate_sfs_demes(
|
| 151 |
+
demes_path: str,
|
| 152 |
+
sample_sizes: List[int],
|
| 153 |
+
output_path: str,
|
| 154 |
+
sampled_demes: Optional[List[str]] = None,
|
| 155 |
+
):
|
| 156 |
+
"""
|
| 157 |
+
Simulates an SFS from a demographic model specified in a Demes file.
|
| 158 |
+
|
| 159 |
+
:param demes_path: Path to the Demes YAML file.
|
| 160 |
+
:param sample_sizes: List of sample sizes for each population.
|
| 161 |
+
:param output_path: Path to save the simulated SFS.
|
| 162 |
+
:param sampled_demes: List of deme IDs to sample. If None, all leaf demes are sampled.
|
| 163 |
+
"""
|
| 164 |
+
if not Path(demes_path).exists():
|
| 165 |
+
return {"error": f"Demes file not found: {demes_path}"}
|
| 166 |
+
|
| 167 |
+
sampled_demes_str = str(sampled_demes) if sampled_demes is not None else "None"
|
| 168 |
+
|
| 169 |
+
python_script = f"""
|
| 170 |
+
import moments
|
| 171 |
+
import sys
|
| 172 |
+
|
| 173 |
+
try:
|
| 174 |
+
sfs = moments.Spectrum.from_demes(
|
| 175 |
+
'{demes_path}',
|
| 176 |
+
sampled_demes={sampled_demes_str},
|
| 177 |
+
sample_sizes={sample_sizes}
|
| 178 |
+
)
|
| 179 |
+
sfs.to_file('{output_path}')
|
| 180 |
+
print("Successfully simulated SFS from Demes.")
|
| 181 |
+
except Exception as e:
|
| 182 |
+
print(f"Error: {{str(e)}}", file=sys.stderr)
|
| 183 |
+
sys.exit(1)
|
| 184 |
+
"""
|
| 185 |
+
|
| 186 |
+
try:
|
| 187 |
+
result = subprocess.run(
|
| 188 |
+
[sys.executable, "-c", python_script],
|
| 189 |
+
capture_output=True,
|
| 190 |
+
text=True,
|
| 191 |
+
check=True
|
| 192 |
+
)
|
| 193 |
+
return {
|
| 194 |
+
"command_executed": "moments.Spectrum.from_demes(...)",
|
| 195 |
+
"stdout": result.stdout,
|
| 196 |
+
"stderr": result.stderr,
|
| 197 |
+
"output_files": [output_path]
|
| 198 |
+
}
|
| 199 |
+
except subprocess.CalledProcessError as e:
|
| 200 |
+
return {
|
| 201 |
+
"error": "Failed to simulate SFS from Demes",
|
| 202 |
+
"stdout": e.stdout,
|
| 203 |
+
"stderr": e.stderr
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
@mcp.tool()
|
| 207 |
+
def moments_infer_sfs(
|
| 208 |
+
sfs_path: str,
|
| 209 |
+
model_file: str,
|
| 210 |
+
model_func_name: str,
|
| 211 |
+
p0: List[float],
|
| 212 |
+
lower_bound: List[float],
|
| 213 |
+
upper_bound: List[float],
|
| 214 |
+
output_path: str,
|
| 215 |
+
maxiter: int = 100,
|
| 216 |
+
verbose: int = 1,
|
| 217 |
+
):
|
| 218 |
+
"""
|
| 219 |
+
Fits a demographic model to an observed SFS using log-likelihood optimization.
|
| 220 |
+
|
| 221 |
+
:param sfs_path: Path to the observed SFS file.
|
| 222 |
+
:param model_file: Path to a Python script containing the demographic model function.
|
| 223 |
+
:param model_func_name: Name of the function in model_file that returns a simulated SFS.
|
| 224 |
+
:param p0: Initial parameter guesses.
|
| 225 |
+
:param lower_bound: Lower bounds for parameters.
|
| 226 |
+
:param upper_bound: Upper bounds for parameters.
|
| 227 |
+
:param output_path: Path to save the optimized parameters and results (JSON).
|
| 228 |
+
:param maxiter: Maximum number of optimization iterations.
|
| 229 |
+
:param verbose: Verbosity level for optimization.
|
| 230 |
+
"""
|
| 231 |
+
if not Path(sfs_path).exists():
|
| 232 |
+
return {"error": f"SFS file not found: {sfs_path}"}
|
| 233 |
+
if not Path(model_file).exists():
|
| 234 |
+
return {"error": f"Model file not found: {model_file}"}
|
| 235 |
+
|
| 236 |
+
python_script = f"""
|
| 237 |
+
import moments
|
| 238 |
+
import sys
|
| 239 |
+
import json
|
| 240 |
+
import importlib.util
|
| 241 |
+
|
| 242 |
+
# Load the user-defined model
|
| 243 |
+
spec = importlib.util.spec_from_file_location("user_model", "{model_file}")
|
| 244 |
+
user_model = importlib.util.module_from_spec(spec)
|
| 245 |
+
spec.loader.exec_module(user_model)
|
| 246 |
+
model_func = getattr(user_model, "{model_func_name}")
|
| 247 |
+
|
| 248 |
+
try:
|
| 249 |
+
data = moments.Spectrum.from_file('{sfs_path}')
|
| 250 |
+
ns = data.sample_sizes
|
| 251 |
+
|
| 252 |
+
# Wrap model to ensure it uses correct sample sizes
|
| 253 |
+
def func_to_optimize(params):
|
| 254 |
+
return model_func(params, ns)
|
| 255 |
+
|
| 256 |
+
popt = moments.Inference.optimize_log(
|
| 257 |
+
{p0}, data, func_to_optimize,
|
| 258 |
+
lower_bound={lower_bound},
|
| 259 |
+
upper_bound={upper_bound},
|
| 260 |
+
maxiter={maxiter},
|
| 261 |
+
verbose={verbose}
|
| 262 |
+
)
|
| 263 |
+
|
| 264 |
+
model_sfs = func_to_optimize(popt)
|
| 265 |
+
ll = moments.Inference.ll_multinom(model_sfs, data)
|
| 266 |
+
|
| 267 |
+
results = {{
|
| 268 |
+
"optimized_params": popt.tolist(),
|
| 269 |
+
"max_log_likelihood": float(ll),
|
| 270 |
+
"model_func": "{model_func_name}"
|
| 271 |
+
}}
|
| 272 |
+
|
| 273 |
+
with open('{output_path}', 'w') as f:
|
| 274 |
+
json.dump(results, f, indent=4)
|
| 275 |
+
print("Successfully completed SFS inference.")
|
| 276 |
+
except Exception as e:
|
| 277 |
+
print(f"Error: {{str(e)}}", file=sys.stderr)
|
| 278 |
+
sys.exit(1)
|
| 279 |
+
"""
|
| 280 |
+
|
| 281 |
+
try:
|
| 282 |
+
result = subprocess.run(
|
| 283 |
+
[sys.executable, "-c", python_script],
|
| 284 |
+
capture_output=True,
|
| 285 |
+
text=True,
|
| 286 |
+
check=True
|
| 287 |
+
)
|
| 288 |
+
return {
|
| 289 |
+
"command_executed": "moments.Inference.optimize_log(...)",
|
| 290 |
+
"stdout": result.stdout,
|
| 291 |
+
"stderr": result.stderr,
|
| 292 |
+
"output_files": [output_path]
|
| 293 |
+
}
|
| 294 |
+
except subprocess.CalledProcessError as e:
|
| 295 |
+
return {
|
| 296 |
+
"error": "Failed SFS inference",
|
| 297 |
+
"stdout": e.stdout,
|
| 298 |
+
"stderr": e.stderr
|
| 299 |
+
}
|
| 300 |
+
|
| 301 |
+
@mcp.tool()
|
| 302 |
+
def moments_simulate_two_locus(
|
| 303 |
+
sample_size: int,
|
| 304 |
+
theta: float,
|
| 305 |
+
rho: float,
|
| 306 |
+
output_path: str,
|
| 307 |
+
gamma: float = 0.0,
|
| 308 |
+
sel_type: str = "additive",
|
| 309 |
+
):
|
| 310 |
+
"""
|
| 311 |
+
Simulates a two-locus frequency spectrum.
|
| 312 |
+
|
| 313 |
+
:param sample_size: Number of chromosomes to sample.
|
| 314 |
+
:param theta: Population-scaled mutation rate (4Nu).
|
| 315 |
+
:param rho: Population-scaled recombination rate (4Nr).
|
| 316 |
+
:param output_path: Path to save the two-locus spectrum.
|
| 317 |
+
:param gamma: Population-scaled selection coefficient (2Ns).
|
| 318 |
+
:param sel_type: Type of selection ('additive', 'dominant', etc.).
|
| 319 |
+
"""
|
| 320 |
+
if sample_size <= 0:
|
| 321 |
+
return {"error": "Sample size must be positive."}
|
| 322 |
+
if theta < 0 or rho < 0:
|
| 323 |
+
return {"error": "Theta and Rho must be non-negative."}
|
| 324 |
+
|
| 325 |
+
python_script = f"""
|
| 326 |
+
import moments.TwoLocus
|
| 327 |
+
import sys
|
| 328 |
+
|
| 329 |
+
try:
|
| 330 |
+
# Simulate steady state two-locus spectrum
|
| 331 |
+
tls = moments.TwoLocus.TLS.steady_state(
|
| 332 |
+
{sample_size}, theta={theta}, rho={rho}, gamma={gamma}, sel_type='{sel_type}'
|
| 333 |
+
)
|
| 334 |
+
tls.to_file('{output_path}')
|
| 335 |
+
print("Successfully simulated Two-Locus spectrum.")
|
| 336 |
+
except Exception as e:
|
| 337 |
+
print(f"Error: {{str(e)}}", file=sys.stderr)
|
| 338 |
+
sys.exit(1)
|
| 339 |
+
"""
|
| 340 |
+
|
| 341 |
+
try:
|
| 342 |
+
result = subprocess.run(
|
| 343 |
+
[sys.executable, "-c", python_script],
|
| 344 |
+
capture_output=True,
|
| 345 |
+
text=True,
|
| 346 |
+
check=True
|
| 347 |
+
)
|
| 348 |
+
return {
|
| 349 |
+
"command_executed": "moments.TwoLocus.TLS.steady_state(...)",
|
| 350 |
+
"stdout": result.stdout,
|
| 351 |
+
"stderr": result.stderr,
|
| 352 |
+
"output_files": [output_path]
|
| 353 |
+
}
|
| 354 |
+
except subprocess.CalledProcessError as e:
|
| 355 |
+
return {
|
| 356 |
+
"error": "Failed to simulate Two-Locus spectrum",
|
| 357 |
+
"stdout": e.stdout,
|
| 358 |
+
"stderr": e.stderr
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
@mcp.tool()
|
| 362 |
+
def moments_ld_infer_demography(
|
| 363 |
+
ld_stats_path: str,
|
| 364 |
+
model_file: str,
|
| 365 |
+
model_func_name: str,
|
| 366 |
+
p0: List[float],
|
| 367 |
+
lower_bound: List[float],
|
| 368 |
+
upper_bound: List[float],
|
| 369 |
+
output_path: str,
|
| 370 |
+
maxiter: int = 100,
|
| 371 |
+
):
|
| 372 |
+
"""
|
| 373 |
+
Fits a demographic model to LD statistics.
|
| 374 |
+
|
| 375 |
+
:param ld_stats_path: Path to the computed LD statistics (pickle file).
|
| 376 |
+
:param model_file: Path to a Python script containing the LD demographic model.
|
| 377 |
+
:param model_func_name: Name of the function in model_file.
|
| 378 |
+
:param p0: Initial parameter guesses.
|
| 379 |
+
:param lower_bound: Lower bounds for parameters.
|
| 380 |
+
:param upper_bound: Upper bounds for parameters.
|
| 381 |
+
:param output_path: Path to save the optimized parameters (JSON).
|
| 382 |
+
:param maxiter: Maximum number of optimization iterations.
|
| 383 |
+
"""
|
| 384 |
+
if not Path(ld_stats_path).exists():
|
| 385 |
+
return {"error": f"LD stats file not found: {ld_stats_path}"}
|
| 386 |
+
if not Path(model_file).exists():
|
| 387 |
+
return {"error": f"Model file not found: {model_file}"}
|
| 388 |
+
|
| 389 |
+
python_script = f"""
|
| 390 |
+
import moments.LD
|
| 391 |
+
import sys
|
| 392 |
+
import json
|
| 393 |
+
import pickle
|
| 394 |
+
import importlib.util
|
| 395 |
+
|
| 396 |
+
# Load the user-defined model
|
| 397 |
+
spec = importlib.util.spec_from_file_location("user_model", "{model_file}")
|
| 398 |
+
user_model = importlib.util.module_from_spec(spec)
|
| 399 |
+
spec.loader.exec_module(user_model)
|
| 400 |
+
model_func = getattr(user_model, "{model_func_name}")
|
| 401 |
+
|
| 402 |
+
try:
|
| 403 |
+
with open('{ld_stats_path}', 'rb') as f:
|
| 404 |
+
data = pickle.load(f)
|
| 405 |
+
|
| 406 |
+
popt = moments.LD.Inference.optimize_log(
|
| 407 |
+
{p0}, data, model_func,
|
| 408 |
+
lower_bound={lower_bound},
|
| 409 |
+
upper_bound={upper_bound},
|
| 410 |
+
maxiter={maxiter},
|
| 411 |
+
verbose=True
|
| 412 |
+
)
|
| 413 |
+
|
| 414 |
+
results = {{
|
| 415 |
+
"optimized_params": popt.tolist(),
|
| 416 |
+
"model_func": "{model_func_name}"
|
| 417 |
+
}}
|
| 418 |
+
|
| 419 |
+
with open('{output_path}', 'w') as f:
|
| 420 |
+
json.dump(results, f, indent=4)
|
| 421 |
+
print("Successfully completed LD inference.")
|
| 422 |
+
except Exception as e:
|
| 423 |
+
print(f"Error: {{str(e)}}", file=sys.stderr)
|
| 424 |
+
sys.exit(1)
|
| 425 |
+
"""
|
| 426 |
+
|
| 427 |
+
try:
|
| 428 |
+
result = subprocess.run(
|
| 429 |
+
[sys.executable, "-c", python_script],
|
| 430 |
+
capture_output=True,
|
| 431 |
+
text=True,
|
| 432 |
+
check=True
|
| 433 |
+
)
|
| 434 |
+
return {
|
| 435 |
+
"command_executed": "moments.LD.Inference.optimize_log(...)",
|
| 436 |
+
"stdout": result.stdout,
|
| 437 |
+
"stderr": result.stderr,
|
| 438 |
+
"output_files": [output_path]
|
| 439 |
+
}
|
| 440 |
+
except subprocess.CalledProcessError as e:
|
| 441 |
+
return {
|
| 442 |
+
"error": "Failed LD inference",
|
| 443 |
+
"stdout": e.stdout,
|
| 444 |
+
"stderr": e.stderr
|
| 445 |
+
}
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_moments/app/moments_shim_server.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import ast
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
from mcp.server.fastmcp import FastMCP
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
SOURCE_SERVER = Path('/225040511/project/BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_moments/app/moments_server.py')
|
| 11 |
+
SERVER_NAME = 'biosci_moments'
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class _ShimMCP:
|
| 15 |
+
@staticmethod
|
| 16 |
+
def tool():
|
| 17 |
+
def _decorator(fn):
|
| 18 |
+
return fn
|
| 19 |
+
return _decorator
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def _load_functions():
|
| 23 |
+
code = SOURCE_SERVER.read_text(encoding="utf-8")
|
| 24 |
+
tree = ast.parse(code, filename=str(SOURCE_SERVER))
|
| 25 |
+
function_names = [n.name for n in tree.body if isinstance(n, ast.FunctionDef) and not n.name.startswith("_")]
|
| 26 |
+
namespace = {
|
| 27 |
+
"__name__": "__mcp_source__",
|
| 28 |
+
"mcp": _ShimMCP(),
|
| 29 |
+
}
|
| 30 |
+
exec(compile(code, str(SOURCE_SERVER), "exec"), namespace, namespace)
|
| 31 |
+
loaded = []
|
| 32 |
+
for name in function_names:
|
| 33 |
+
fn = namespace.get(name)
|
| 34 |
+
if callable(fn):
|
| 35 |
+
loaded.append(fn)
|
| 36 |
+
return loaded
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
mcp = FastMCP(SERVER_NAME)
|
| 40 |
+
for _fn in _load_functions():
|
| 41 |
+
mcp.tool()(_fn)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
if __name__ == "__main__":
|
| 45 |
+
mcp.run(transport="stdio")
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_moments/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_moments/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-moments:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-moments:latest
|
| 7 |
+
container_name: mcp-moments
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=moments
|
| 12 |
+
volumes:
|
| 13 |
+
- ./workspace:/app/workspace
|
| 14 |
+
- ./output:/app/output
|
| 15 |
+
restart: unless-stopped
|
| 16 |
+
healthcheck:
|
| 17 |
+
test: ["CMD", "python", "-c", "import sys; sys.exit(0)"]
|
| 18 |
+
interval: 30s
|
| 19 |
+
timeout: 10s
|
| 20 |
+
retries: 3
|
| 21 |
+
start_period: 5s
|
| 22 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_moments/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- moments
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_moments/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mosdepth/Dockerfile
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# Install system dependencies
|
| 5 |
+
RUN apt-get update && apt-get install -y default-jre wget curl && apt-get clean && rm -rf /var/lib/apt/lists/*
|
| 6 |
+
|
| 7 |
+
# Install Miniconda
|
| 8 |
+
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O /tmp/miniconda.sh && bash /tmp/miniconda.sh -b -p /opt/conda && rm /tmp/miniconda.sh
|
| 9 |
+
|
| 10 |
+
# Add conda to PATH
|
| 11 |
+
ENV PATH="/opt/conda/bin:$PATH"
|
| 12 |
+
|
| 13 |
+
# Install mosdepth via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda mosdepth -y && conda clean -a
|
| 15 |
+
|
| 16 |
+
# Install Python dependencies
|
| 17 |
+
RUN pip install uv
|
| 18 |
+
RUN uv pip install --system fastmcp
|
| 19 |
+
|
| 20 |
+
# Create app directory
|
| 21 |
+
WORKDIR /app
|
| 22 |
+
|
| 23 |
+
# Copy your MCP server
|
| 24 |
+
COPY app/mosdepth_server.py /app/
|
| 25 |
+
|
| 26 |
+
# Create workspace and output directories
|
| 27 |
+
RUN mkdir -p /app/workspace /app/output
|
| 28 |
+
|
| 29 |
+
# Make sure the server script is executable
|
| 30 |
+
RUN chmod +x /app/mosdepth_server.py
|
| 31 |
+
|
| 32 |
+
# Expose port for MCP over HTTP (optional)
|
| 33 |
+
EXPOSE 8000
|
| 34 |
+
|
| 35 |
+
# Health check
|
| 36 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 CMD python -c "import sys; sys.exit(0)"
|
| 37 |
+
|
| 38 |
+
# Default command runs the MCP server via stdio
|
| 39 |
+
CMD ["python", "/app/mosdepth_server.py"]
|
| 40 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mosdepth/app/mosdepth_server.py
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import logging
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
from typing import List, Optional
|
| 5 |
+
|
| 6 |
+
# Set up logging
|
| 7 |
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 8 |
+
|
| 9 |
+
# This is a placeholder for the MCP decorator.
|
| 10 |
+
# The actual @mcp.tool decorator will be provided by the MCP environment.
|
| 11 |
+
class mcp:
|
| 12 |
+
@staticmethod
|
| 13 |
+
def tool(func):
|
| 14 |
+
return func
|
| 15 |
+
|
| 16 |
+
@mcp.tool
|
| 17 |
+
def mosdepth(
|
| 18 |
+
prefix: str,
|
| 19 |
+
input_files: List[Path],
|
| 20 |
+
threads: Optional[int] = None,
|
| 21 |
+
chrom: Optional[List[str]] = None,
|
| 22 |
+
by: Optional[str] = None,
|
| 23 |
+
no_per_base: bool = False,
|
| 24 |
+
fasta: Optional[Path] = None,
|
| 25 |
+
flag: int = 1796,
|
| 26 |
+
include_flag: int = 0,
|
| 27 |
+
quantize: Optional[str] = None,
|
| 28 |
+
mapq: int = 0,
|
| 29 |
+
d4: bool = False,
|
| 30 |
+
fast_mode: bool = False,
|
| 31 |
+
use_median: bool = False,
|
| 32 |
+
no_median: bool = False,
|
| 33 |
+
roc: Optional[str] = None,
|
| 34 |
+
thresholds: Optional[str] = None,
|
| 35 |
+
distribution_file: Optional[Path] = None,
|
| 36 |
+
long_reads: bool = False,
|
| 37 |
+
specific_regions: Optional[Path] = None,
|
| 38 |
+
precision: int = 4,
|
| 39 |
+
) -> dict:
|
| 40 |
+
"""
|
| 41 |
+
Calculates depth from BAM/CRAM files using mosdepth.
|
| 42 |
+
|
| 43 |
+
mosdepth is a fast BAM/CRAM depth calculator for WGS, exome, or targeted sequencing.
|
| 44 |
+
This tool wraps the `mosdepth` command-line tool, providing access to its full functionality.
|
| 45 |
+
"""
|
| 46 |
+
# --- Input Validation ---
|
| 47 |
+
if not prefix:
|
| 48 |
+
raise ValueError("Output prefix must be provided and cannot be empty.")
|
| 49 |
+
|
| 50 |
+
if not input_files:
|
| 51 |
+
raise ValueError("At least one input BAM or CRAM file must be provided.")
|
| 52 |
+
|
| 53 |
+
for file_path in input_files:
|
| 54 |
+
if not file_path.is_file():
|
| 55 |
+
raise FileNotFoundError(f"Input file not found: {file_path}")
|
| 56 |
+
|
| 57 |
+
is_cram = any(str(f).lower().endswith(".cram") for f in input_files)
|
| 58 |
+
if is_cram and not fasta:
|
| 59 |
+
raise ValueError("A FASTA reference file (--fasta) is required for CRAM inputs.")
|
| 60 |
+
|
| 61 |
+
if fasta and not fasta.is_file():
|
| 62 |
+
raise FileNotFoundError(f"FASTA file not found: {fasta}")
|
| 63 |
+
|
| 64 |
+
if threads is not None and threads < 0:
|
| 65 |
+
raise ValueError(f"Number of threads must be a non-negative integer, but got {threads}.")
|
| 66 |
+
|
| 67 |
+
if mapq < 0:
|
| 68 |
+
raise ValueError(f"Mapping quality threshold (--mapq) must be non-negative, but got {mapq}.")
|
| 69 |
+
|
| 70 |
+
# Check for mutually exclusive arguments
|
| 71 |
+
if sum([bool(by), bool(quantize), bool(d4)]) > 1:
|
| 72 |
+
raise ValueError("Options --by, --quantize, and --d4 are mutually exclusive.")
|
| 73 |
+
|
| 74 |
+
# Check for dependent arguments
|
| 75 |
+
if roc and not by:
|
| 76 |
+
raise ValueError("--roc requires --by to be specified.")
|
| 77 |
+
if thresholds and not roc:
|
| 78 |
+
raise ValueError("--thresholds requires --roc to be specified.")
|
| 79 |
+
|
| 80 |
+
if by:
|
| 81 |
+
try:
|
| 82 |
+
# Check if 'by' is a window size (integer)
|
| 83 |
+
window_size = int(by)
|
| 84 |
+
if window_size <= 0:
|
| 85 |
+
raise ValueError
|
| 86 |
+
except ValueError:
|
| 87 |
+
# If not an integer, assume it's a BED file path
|
| 88 |
+
by_path = Path(by)
|
| 89 |
+
if not by_path.is_file():
|
| 90 |
+
raise FileNotFoundError(f"BED file specified with --by not found: {by_path}")
|
| 91 |
+
|
| 92 |
+
if specific_regions and not specific_regions.is_file():
|
| 93 |
+
raise FileNotFoundError(f"BED file for --specific-regions not found: {specific_regions}")
|
| 94 |
+
|
| 95 |
+
# --- Command Construction ---
|
| 96 |
+
cmd = ["mosdepth"]
|
| 97 |
+
|
| 98 |
+
if threads is not None:
|
| 99 |
+
cmd.extend(["-t", str(threads)])
|
| 100 |
+
if chrom:
|
| 101 |
+
for c in chrom:
|
| 102 |
+
cmd.extend(["-c", c])
|
| 103 |
+
if by:
|
| 104 |
+
cmd.extend(["--by", str(by)])
|
| 105 |
+
if no_per_base:
|
| 106 |
+
cmd.append("--no-per-base")
|
| 107 |
+
if fasta:
|
| 108 |
+
cmd.extend(["-f", str(fasta)])
|
| 109 |
+
if flag != 1796:
|
| 110 |
+
cmd.extend(["-F", str(flag)])
|
| 111 |
+
if include_flag != 0:
|
| 112 |
+
cmd.extend(["-i", str(include_flag)])
|
| 113 |
+
if quantize:
|
| 114 |
+
cmd.extend(["--quantize", quantize])
|
| 115 |
+
if mapq != 0:
|
| 116 |
+
cmd.extend(["-Q", str(mapq)])
|
| 117 |
+
if d4:
|
| 118 |
+
cmd.append("--d4")
|
| 119 |
+
if fast_mode:
|
| 120 |
+
cmd.append("--fast-mode")
|
| 121 |
+
if use_median:
|
| 122 |
+
cmd.append("--use-median")
|
| 123 |
+
if no_median:
|
| 124 |
+
cmd.append("--no-median")
|
| 125 |
+
if roc:
|
| 126 |
+
cmd.extend(["--roc", roc])
|
| 127 |
+
if thresholds:
|
| 128 |
+
cmd.extend(["--thresholds", thresholds])
|
| 129 |
+
if distribution_file:
|
| 130 |
+
cmd.extend(["--distribution-file", str(distribution_file)])
|
| 131 |
+
if long_reads:
|
| 132 |
+
cmd.append("--long-reads")
|
| 133 |
+
if specific_regions:
|
| 134 |
+
cmd.extend(["--specific-regions", str(specific_regions)])
|
| 135 |
+
if precision != 4:
|
| 136 |
+
cmd.extend(["--precision", str(precision)])
|
| 137 |
+
|
| 138 |
+
# Positional arguments
|
| 139 |
+
cmd.append(prefix)
|
| 140 |
+
cmd.extend([str(p) for p in input_files])
|
| 141 |
+
|
| 142 |
+
command_executed = " ".join(cmd)
|
| 143 |
+
logging.info(f"Executing command: {command_executed}")
|
| 144 |
+
|
| 145 |
+
# --- Subprocess Execution ---
|
| 146 |
+
try:
|
| 147 |
+
result = subprocess.run(
|
| 148 |
+
cmd,
|
| 149 |
+
check=True,
|
| 150 |
+
capture_output=True,
|
| 151 |
+
text=True,
|
| 152 |
+
)
|
| 153 |
+
except FileNotFoundError:
|
| 154 |
+
logging.error("mosdepth not found. Please ensure it is installed and in your PATH.")
|
| 155 |
+
raise
|
| 156 |
+
except subprocess.CalledProcessError as e:
|
| 157 |
+
logging.error(f"mosdepth execution failed with exit code {e.returncode}.")
|
| 158 |
+
logging.error(f"Stderr: {e.stderr}")
|
| 159 |
+
logging.error(f"Stdout: {e.stdout}")
|
| 160 |
+
raise e
|
| 161 |
+
|
| 162 |
+
# --- Output File Discovery ---
|
| 163 |
+
output_files = []
|
| 164 |
+
expected_files = [
|
| 165 |
+
Path(f"{prefix}.mosdepth.global.dist.txt"),
|
| 166 |
+
]
|
| 167 |
+
if not no_per_base:
|
| 168 |
+
expected_files.extend([
|
| 169 |
+
Path(f"{prefix}.per-base.bed.gz"),
|
| 170 |
+
Path(f"{prefix}.per-base.bed.gz.csi"),
|
| 171 |
+
])
|
| 172 |
+
if by:
|
| 173 |
+
expected_files.extend([
|
| 174 |
+
Path(f"{prefix}.mosdepth.region.dist.txt"),
|
| 175 |
+
Path(f"{prefix}.regions.bed.gz"),
|
| 176 |
+
Path(f"{prefix}.regions.bed.gz.csi"),
|
| 177 |
+
])
|
| 178 |
+
if quantize:
|
| 179 |
+
expected_files.extend([
|
| 180 |
+
Path(f"{prefix}.quantized.bed.gz"),
|
| 181 |
+
Path(f"{prefix}.quantized.bed.gz.csi"),
|
| 182 |
+
])
|
| 183 |
+
if d4:
|
| 184 |
+
expected_files.append(Path(f"{prefix}.d4"))
|
| 185 |
+
if distribution_file:
|
| 186 |
+
expected_files.append(distribution_file)
|
| 187 |
+
|
| 188 |
+
for f in expected_files:
|
| 189 |
+
if f.exists():
|
| 190 |
+
output_files.append(str(f.resolve()))
|
| 191 |
+
else:
|
| 192 |
+
logging.warning(f"Expected output file not found: {f}")
|
| 193 |
+
|
| 194 |
+
# --- Structured Result Return ---
|
| 195 |
+
return {
|
| 196 |
+
"command_executed": command_executed,
|
| 197 |
+
"stdout": result.stdout,
|
| 198 |
+
"stderr": result.stderr,
|
| 199 |
+
"output_files": output_files,
|
| 200 |
+
}
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mosdepth/app/mosdepth_shim_server.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import ast
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
from mcp.server.fastmcp import FastMCP
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
SOURCE_SERVER = Path('/225040511/project/BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mosdepth/app/mosdepth_server.py')
|
| 11 |
+
SERVER_NAME = 'biosci_mosdepth'
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class _ShimMCP:
|
| 15 |
+
@staticmethod
|
| 16 |
+
def tool():
|
| 17 |
+
def _decorator(fn):
|
| 18 |
+
return fn
|
| 19 |
+
return _decorator
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def _load_functions():
|
| 23 |
+
code = SOURCE_SERVER.read_text(encoding="utf-8")
|
| 24 |
+
tree = ast.parse(code, filename=str(SOURCE_SERVER))
|
| 25 |
+
function_names = [n.name for n in tree.body if isinstance(n, ast.FunctionDef) and not n.name.startswith("_")]
|
| 26 |
+
namespace = {
|
| 27 |
+
"__name__": "__mcp_source__",
|
| 28 |
+
"mcp": _ShimMCP(),
|
| 29 |
+
}
|
| 30 |
+
exec(compile(code, str(SOURCE_SERVER), "exec"), namespace, namespace)
|
| 31 |
+
loaded = []
|
| 32 |
+
for name in function_names:
|
| 33 |
+
fn = namespace.get(name)
|
| 34 |
+
if callable(fn):
|
| 35 |
+
loaded.append(fn)
|
| 36 |
+
return loaded
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
mcp = FastMCP(SERVER_NAME)
|
| 40 |
+
for _fn in _load_functions():
|
| 41 |
+
mcp.tool()(_fn)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
if __name__ == "__main__":
|
| 45 |
+
mcp.run(transport="stdio")
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mosdepth/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mosdepth/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-mosdepth:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-mosdepth:latest
|
| 7 |
+
container_name: mcp-mosdepth
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=mosdepth
|
| 12 |
+
volumes:
|
| 13 |
+
- ./workspace:/app/workspace
|
| 14 |
+
- ./output:/app/output
|
| 15 |
+
restart: unless-stopped
|
| 16 |
+
healthcheck:
|
| 17 |
+
test: ["CMD", "python", "-c", "import sys; sys.exit(0)"]
|
| 18 |
+
interval: 30s
|
| 19 |
+
timeout: 10s
|
| 20 |
+
retries: 3
|
| 21 |
+
start_period: 5s
|
| 22 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mosdepth/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- mosdepth
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mosdepth/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mothur/Dockerfile
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# Install system dependencies
|
| 5 |
+
RUN apt-get update && apt-get install -y default-jre wget curl && apt-get clean && rm -rf /var/lib/apt/lists/*
|
| 6 |
+
|
| 7 |
+
# Install Miniconda
|
| 8 |
+
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O /tmp/miniconda.sh && bash /tmp/miniconda.sh -b -p /opt/conda && rm /tmp/miniconda.sh
|
| 9 |
+
|
| 10 |
+
# Add conda to PATH
|
| 11 |
+
ENV PATH="/opt/conda/bin:$PATH"
|
| 12 |
+
|
| 13 |
+
# Install mothur via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda mothur -y && conda clean -a
|
| 15 |
+
|
| 16 |
+
# Install Python dependencies
|
| 17 |
+
RUN pip install uv
|
| 18 |
+
RUN uv pip install --system fastmcp
|
| 19 |
+
|
| 20 |
+
# Create app directory
|
| 21 |
+
WORKDIR /app
|
| 22 |
+
|
| 23 |
+
# Copy your MCP server
|
| 24 |
+
COPY app/mothur_server.py /app/
|
| 25 |
+
|
| 26 |
+
# Create workspace and output directories
|
| 27 |
+
RUN mkdir -p /app/workspace /app/output
|
| 28 |
+
|
| 29 |
+
# Make sure the server script is executable
|
| 30 |
+
RUN chmod +x /app/mothur_server.py
|
| 31 |
+
|
| 32 |
+
# Expose port for MCP over HTTP (optional)
|
| 33 |
+
EXPOSE 8000
|
| 34 |
+
|
| 35 |
+
# Health check
|
| 36 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 CMD python -c "import sys; sys.exit(0)"
|
| 37 |
+
|
| 38 |
+
# Default command runs the MCP server via stdio
|
| 39 |
+
CMD ["python", "/app/mothur_server.py"]
|
| 40 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mothur/app/mothur_server.py
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import tempfile
|
| 3 |
+
import logging
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from typing import List, Optional, Dict, Any
|
| 6 |
+
|
| 7 |
+
# Configure logging
|
| 8 |
+
logging.basicConfig(level=logging.INFO)
|
| 9 |
+
|
| 10 |
+
def _build_mothur_command_string(command_name: str, params: Dict[str, Any]) -> str:
|
| 11 |
+
"""Builds a mothur-compatible command string from a dictionary of parameters."""
|
| 12 |
+
param_list = []
|
| 13 |
+
for key, value in params.items():
|
| 14 |
+
if value is None:
|
| 15 |
+
continue
|
| 16 |
+
if isinstance(value, bool):
|
| 17 |
+
param_list.append(f"{key}={str(value).lower()}")
|
| 18 |
+
elif isinstance(value, Path):
|
| 19 |
+
# Use absolute paths to ensure mothur can find the files
|
| 20 |
+
param_list.append(f"{key}={str(value.resolve())}")
|
| 21 |
+
else:
|
| 22 |
+
param_list.append(f"{key}={value}")
|
| 23 |
+
return f"{command_name}({','.join(param_list)})"
|
| 24 |
+
|
| 25 |
+
def _run_mothur(command_str: str) -> Dict[str, Any]:
|
| 26 |
+
"""
|
| 27 |
+
Executes a mothur command string in an isolated temporary directory.
|
| 28 |
+
|
| 29 |
+
Args:
|
| 30 |
+
command_str: The mothur command to execute (e.g., "unique.seqs(fasta=...)").
|
| 31 |
+
|
| 32 |
+
Returns:
|
| 33 |
+
A dictionary containing execution details and output file paths.
|
| 34 |
+
"""
|
| 35 |
+
with tempfile.TemporaryDirectory() as temp_dir_str:
|
| 36 |
+
temp_dir = Path(temp_dir_str)
|
| 37 |
+
|
| 38 |
+
# Prepend set.dir to control output location reliably
|
| 39 |
+
full_command_str = f"set.dir(output={temp_dir.resolve()});{command_str}"
|
| 40 |
+
|
| 41 |
+
# The '#command' syntax is mothur's way of running a batch command
|
| 42 |
+
cmd = ["mothur", f"#{full_command_str}"]
|
| 43 |
+
command_executed = " ".join(cmd)
|
| 44 |
+
|
| 45 |
+
try:
|
| 46 |
+
result = subprocess.run(
|
| 47 |
+
cmd,
|
| 48 |
+
capture_output=True,
|
| 49 |
+
text=True,
|
| 50 |
+
check=True,
|
| 51 |
+
cwd=temp_dir, # Run from temp_dir for safety
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
# Discover all files created in the output directory
|
| 55 |
+
output_files = [str(p.resolve()) for p in temp_dir.glob("*") if p.is_file()]
|
| 56 |
+
|
| 57 |
+
return {
|
| 58 |
+
"command_executed": command_executed,
|
| 59 |
+
"stdout": result.stdout,
|
| 60 |
+
"stderr": result.stderr,
|
| 61 |
+
"output_files": output_files,
|
| 62 |
+
}
|
| 63 |
+
except FileNotFoundError:
|
| 64 |
+
logging.error("mothur executable not found. Please ensure it is in your PATH.")
|
| 65 |
+
raise
|
| 66 |
+
except subprocess.CalledProcessError as e:
|
| 67 |
+
logging.error(f"Mothur command failed with exit code {e.returncode}")
|
| 68 |
+
logging.error(f"STDOUT: {e.stdout}")
|
| 69 |
+
logging.error(f"STDERR: {e.stderr}")
|
| 70 |
+
return {
|
| 71 |
+
"command_executed": command_executed,
|
| 72 |
+
"stdout": e.stdout,
|
| 73 |
+
"stderr": e.stderr,
|
| 74 |
+
"error": "Mothur command failed.",
|
| 75 |
+
"return_code": e.returncode,
|
| 76 |
+
"output_files": []
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
@mcp.tool()
|
| 80 |
+
def make_contigs(
|
| 81 |
+
ffastq: Optional[Path] = None,
|
| 82 |
+
rfastq: Optional[Path] = None,
|
| 83 |
+
file: Optional[Path] = None,
|
| 84 |
+
fname: Optional[Path] = None,
|
| 85 |
+
oligos: Optional[Path] = None,
|
| 86 |
+
processors: int = 1,
|
| 87 |
+
bdiffs: int = 0,
|
| 88 |
+
pdiffs: int = 0,
|
| 89 |
+
checkorient: bool = True,
|
| 90 |
+
insert: int = 25,
|
| 91 |
+
trimoverlap: bool = False,
|
| 92 |
+
deltaq: int = 6,
|
| 93 |
+
maxee: float = 1.0,
|
| 94 |
+
) -> Dict[str, Any]:
|
| 95 |
+
"""
|
| 96 |
+
Assembles paired-end DNA sequences into contigs.
|
| 97 |
+
|
| 98 |
+
This command aligns and merges paired-end reads from FASTQ files to create longer,
|
| 99 |
+
contiguous sequences for further analysis.
|
| 100 |
+
"""
|
| 101 |
+
# Input validation
|
| 102 |
+
if not ((ffastq and rfastq) or file or fname):
|
| 103 |
+
raise ValueError("You must provide one of the following: 'file', 'fname', or both 'ffastq' and 'rfastq'.")
|
| 104 |
+
if (ffastq and not rfastq) or (rfastq and not ffastq):
|
| 105 |
+
raise ValueError("'ffastq' and 'rfastq' must be provided together.")
|
| 106 |
+
|
| 107 |
+
if ffastq and not ffastq.is_file(): raise FileNotFoundError(f"File not found: {ffastq}")
|
| 108 |
+
if rfastq and not rfastq.is_file(): raise FileNotFoundError(f"File not found: {rfastq}")
|
| 109 |
+
if file and not file.is_file(): raise FileNotFoundError(f"File not found: {file}")
|
| 110 |
+
if fname and not fname.is_file(): raise FileNotFoundError(f"File not found: {fname}")
|
| 111 |
+
if oligos and not oligos.is_file(): raise FileNotFoundError(f"File not found: {oligos}")
|
| 112 |
+
|
| 113 |
+
params = {
|
| 114 |
+
"ffastq": ffastq,
|
| 115 |
+
"rfastq": rfastq,
|
| 116 |
+
"file": file,
|
| 117 |
+
"fname": fname,
|
| 118 |
+
"oligos": oligos,
|
| 119 |
+
"processors": processors,
|
| 120 |
+
"bdiffs": bdiffs,
|
| 121 |
+
"pdiffs": pdiffs,
|
| 122 |
+
"checkorient": checkorient,
|
| 123 |
+
"insert": insert,
|
| 124 |
+
"trimoverlap": trimoverlap,
|
| 125 |
+
"deltaq": deltaq,
|
| 126 |
+
"maxee": maxee,
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
command_str = _build_mothur_command_string("make.contigs", params)
|
| 130 |
+
return _run_mothur(command_str)
|
| 131 |
+
|
| 132 |
+
@mcp.tool()
|
| 133 |
+
def screen_seqs(
|
| 134 |
+
fasta: Path,
|
| 135 |
+
count: Optional[Path] = None,
|
| 136 |
+
group: Optional[Path] = None,
|
| 137 |
+
taxonomy: Optional[Path] = None,
|
| 138 |
+
qfile: Optional[Path] = None,
|
| 139 |
+
contigsreport: Optional[Path] = None,
|
| 140 |
+
summary: Optional[Path] = None,
|
| 141 |
+
start: Optional[int] = None,
|
| 142 |
+
end: Optional[int] = None,
|
| 143 |
+
maxambig: int = 0,
|
| 144 |
+
maxhomop: int = 8,
|
| 145 |
+
minlength: Optional[int] = None,
|
| 146 |
+
maxlength: Optional[int] = None,
|
| 147 |
+
processors: int = 1,
|
| 148 |
+
) -> Dict[str, Any]:
|
| 149 |
+
"""
|
| 150 |
+
Removes sequences that do not meet specified quality criteria.
|
| 151 |
+
|
| 152 |
+
This command filters sequences based on length, number of ambiguous bases,
|
| 153 |
+
and homopolymer length to improve the quality of the dataset.
|
| 154 |
+
"""
|
| 155 |
+
# Input validation
|
| 156 |
+
if not fasta.is_file(): raise FileNotFoundError(f"FASTA file not found: {fasta}")
|
| 157 |
+
if count and not count.is_file(): raise FileNotFoundError(f"Count file not found: {count}")
|
| 158 |
+
if group and not group.is_file(): raise FileNotFoundError(f"Group file not found: {group}")
|
| 159 |
+
if taxonomy and not taxonomy.is_file(): raise FileNotFoundError(f"Taxonomy file not found: {taxonomy}")
|
| 160 |
+
if qfile and not qfile.is_file(): raise FileNotFoundError(f"Quality file not found: {qfile}")
|
| 161 |
+
if contigsreport and not contigsreport.is_file(): raise FileNotFoundError(f"Contigs report file not found: {contigsreport}")
|
| 162 |
+
if summary and not summary.is_file(): raise FileNotFoundError(f"Summary file not found: {summary}")
|
| 163 |
+
|
| 164 |
+
params = {
|
| 165 |
+
"fasta": fasta,
|
| 166 |
+
"count": count,
|
| 167 |
+
"group": group,
|
| 168 |
+
"taxonomy": taxonomy,
|
| 169 |
+
"qfile": qfile,
|
| 170 |
+
"contigsreport": contigsreport,
|
| 171 |
+
"summary": summary,
|
| 172 |
+
"start": start,
|
| 173 |
+
"end": end,
|
| 174 |
+
"maxambig": maxambig,
|
| 175 |
+
"maxhomop": maxhomop,
|
| 176 |
+
"minlength": minlength,
|
| 177 |
+
"maxlength": maxlength,
|
| 178 |
+
"processors": processors,
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
command_str = _build_mothur_command_string("screen.seqs", params)
|
| 182 |
+
return _run_mothur(command_str)
|
| 183 |
+
|
| 184 |
+
@mcp.tool()
|
| 185 |
+
def unique_seqs(
|
| 186 |
+
fasta: Optional[Path] = None,
|
| 187 |
+
count: Optional[Path] = None,
|
| 188 |
+
format: str = "name",
|
| 189 |
+
) -> Dict[str, Any]:
|
| 190 |
+
"""
|
| 191 |
+
Finds the unique sequences in a dataset and generates a count/name file.
|
| 192 |
+
|
| 193 |
+
This command dereplicates a FASTA file, keeping only the unique sequences and
|
| 194 |
+
creating a corresponding file that tracks the abundance of each unique sequence.
|
| 195 |
+
"""
|
| 196 |
+
# Input validation
|
| 197 |
+
if not fasta and not count:
|
| 198 |
+
raise ValueError("Either 'fasta' or 'count' file must be provided.")
|
| 199 |
+
if fasta and count:
|
| 200 |
+
raise ValueError("Provide either 'fasta' or 'count', not both.")
|
| 201 |
+
if fasta and not fasta.is_file():
|
| 202 |
+
raise FileNotFoundError(f"FASTA file not found: {fasta}")
|
| 203 |
+
if count and not count.is_file():
|
| 204 |
+
raise FileNotFoundError(f"Count file not found: {count}")
|
| 205 |
+
|
| 206 |
+
valid_formats = ["name", "count"]
|
| 207 |
+
if format not in valid_formats:
|
| 208 |
+
raise ValueError(f"Invalid format '{format}'. Must be one of {valid_formats}.")
|
| 209 |
+
|
| 210 |
+
params = {
|
| 211 |
+
"fasta": fasta,
|
| 212 |
+
"count": count,
|
| 213 |
+
"format": format,
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
command_str = _build_mothur_command_string("unique.seqs", params)
|
| 217 |
+
return _run_mothur(command_str)
|
| 218 |
+
|
| 219 |
+
@mcp.tool()
|
| 220 |
+
def dist_seqs(
|
| 221 |
+
fasta: Path,
|
| 222 |
+
cutoff: float = 0.25,
|
| 223 |
+
output: str = "lt",
|
| 224 |
+
processors: int = 1,
|
| 225 |
+
calc: str = "onegap",
|
| 226 |
+
countends: bool = True,
|
| 227 |
+
) -> Dict[str, Any]:
|
| 228 |
+
"""
|
| 229 |
+
Calculates pairwise distances between DNA sequences.
|
| 230 |
+
|
| 231 |
+
This command generates a distance matrix from an aligned FASTA file, which is a
|
| 232 |
+
prerequisite for clustering sequences into OTUs.
|
| 233 |
+
"""
|
| 234 |
+
# Input validation
|
| 235 |
+
if not fasta.is_file():
|
| 236 |
+
raise FileNotFoundError(f"FASTA file not found: {fasta}")
|
| 237 |
+
|
| 238 |
+
valid_outputs = ["lt", "square", "column"]
|
| 239 |
+
if output not in valid_outputs:
|
| 240 |
+
raise ValueError(f"Invalid output format '{output}'. Must be one of {valid_outputs}.")
|
| 241 |
+
|
| 242 |
+
valid_calcs = ["onegap", "nogap"]
|
| 243 |
+
if calc not in valid_calcs:
|
| 244 |
+
raise ValueError(f"Invalid calc method '{calc}'. Must be one of {valid_calcs}.")
|
| 245 |
+
|
| 246 |
+
params = {
|
| 247 |
+
"fasta": fasta,
|
| 248 |
+
"cutoff": cutoff,
|
| 249 |
+
"output": output,
|
| 250 |
+
"processors": processors,
|
| 251 |
+
"calc": calc,
|
| 252 |
+
"countends": countends,
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
command_str = _build_mothur_command_string("dist.seqs", params)
|
| 256 |
+
return _run_mothur(command_str)
|
| 257 |
+
|
| 258 |
+
@mcp.tool()
|
| 259 |
+
def cluster(
|
| 260 |
+
phylip: Optional[Path] = None,
|
| 261 |
+
column: Optional[Path] = None,
|
| 262 |
+
name: Optional[Path] = None,
|
| 263 |
+
count: Optional[Path] = None,
|
| 264 |
+
method: str = "furthest",
|
| 265 |
+
cutoff: Optional[float] = None,
|
| 266 |
+
precision: int = 100,
|
| 267 |
+
) -> Dict[str, Any]:
|
| 268 |
+
"""
|
| 269 |
+
Assigns sequences to OTUs based on a distance matrix.
|
| 270 |
+
|
| 271 |
+
This command uses one of several clustering algorithms (furthest neighbor,
|
| 272 |
+
nearest neighbor, or average neighbor) to group sequences into OTUs.
|
| 273 |
+
"""
|
| 274 |
+
# Input validation
|
| 275 |
+
if not phylip and not column:
|
| 276 |
+
raise ValueError("Either a 'phylip' or 'column' formatted distance file must be provided.")
|
| 277 |
+
if phylip and column:
|
| 278 |
+
raise ValueError("Provide either 'phylip' or 'column', not both.")
|
| 279 |
+
if phylip and not phylip.is_file():
|
| 280 |
+
raise FileNotFoundError(f"Phylip file not found: {phylip}")
|
| 281 |
+
if column and not column.is_file():
|
| 282 |
+
raise FileNotFoundError(f"Column file not found: {column}")
|
| 283 |
+
if name and not name.is_file():
|
| 284 |
+
raise FileNotFoundError(f"Name file not found: {name}")
|
| 285 |
+
if count and not count.is_file():
|
| 286 |
+
raise FileNotFoundError(f"Count file not found: {count}")
|
| 287 |
+
|
| 288 |
+
valid_methods = ["furthest", "nearest", "average"]
|
| 289 |
+
if method not in valid_methods:
|
| 290 |
+
raise ValueError(f"Invalid method '{method}'. Must be one of {valid_methods}.")
|
| 291 |
+
|
| 292 |
+
params = {
|
| 293 |
+
"phylip": phylip,
|
| 294 |
+
"column": column,
|
| 295 |
+
"name": name,
|
| 296 |
+
"count": count,
|
| 297 |
+
"method": method,
|
| 298 |
+
"cutoff": cutoff,
|
| 299 |
+
"precision": precision,
|
| 300 |
+
}
|
| 301 |
+
|
| 302 |
+
command_str = _build_mothur_command_string("cluster", params)
|
| 303 |
+
return _run_mothur(command_str)
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mothur/app/mothur_shim_server.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import ast
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
from mcp.server.fastmcp import FastMCP
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
SOURCE_SERVER = Path('/225040511/project/BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mothur/app/mothur_server.py')
|
| 11 |
+
SERVER_NAME = 'biosci_mothur'
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class _ShimMCP:
|
| 15 |
+
@staticmethod
|
| 16 |
+
def tool():
|
| 17 |
+
def _decorator(fn):
|
| 18 |
+
return fn
|
| 19 |
+
return _decorator
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def _load_functions():
|
| 23 |
+
code = SOURCE_SERVER.read_text(encoding="utf-8")
|
| 24 |
+
tree = ast.parse(code, filename=str(SOURCE_SERVER))
|
| 25 |
+
function_names = [n.name for n in tree.body if isinstance(n, ast.FunctionDef) and not n.name.startswith("_")]
|
| 26 |
+
namespace = {
|
| 27 |
+
"__name__": "__mcp_source__",
|
| 28 |
+
"mcp": _ShimMCP(),
|
| 29 |
+
}
|
| 30 |
+
exec(compile(code, str(SOURCE_SERVER), "exec"), namespace, namespace)
|
| 31 |
+
loaded = []
|
| 32 |
+
for name in function_names:
|
| 33 |
+
fn = namespace.get(name)
|
| 34 |
+
if callable(fn):
|
| 35 |
+
loaded.append(fn)
|
| 36 |
+
return loaded
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
mcp = FastMCP(SERVER_NAME)
|
| 40 |
+
for _fn in _load_functions():
|
| 41 |
+
mcp.tool()(_fn)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
if __name__ == "__main__":
|
| 45 |
+
mcp.run(transport="stdio")
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mothur/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mothur/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-mothur:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-mothur:latest
|
| 7 |
+
container_name: mcp-mothur
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=mothur
|
| 12 |
+
volumes:
|
| 13 |
+
- ./workspace:/app/workspace
|
| 14 |
+
- ./output:/app/output
|
| 15 |
+
restart: unless-stopped
|
| 16 |
+
healthcheck:
|
| 17 |
+
test: ["CMD", "python", "-c", "import sys; sys.exit(0)"]
|
| 18 |
+
interval: 30s
|
| 19 |
+
timeout: 10s
|
| 20 |
+
retries: 3
|
| 21 |
+
start_period: 5s
|
| 22 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mothur/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- mothur
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_mothur/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_msisensor-pro/Dockerfile
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# Install system dependencies
|
| 5 |
+
RUN apt-get update && apt-get install -y default-jre wget curl && apt-get clean && rm -rf /var/lib/apt/lists/*
|
| 6 |
+
|
| 7 |
+
# Install Miniconda
|
| 8 |
+
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O /tmp/miniconda.sh && bash /tmp/miniconda.sh -b -p /opt/conda && rm /tmp/miniconda.sh
|
| 9 |
+
|
| 10 |
+
# Add conda to PATH
|
| 11 |
+
ENV PATH="/opt/conda/bin:$PATH"
|
| 12 |
+
|
| 13 |
+
# Install msisensor-pro via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda msisensor-pro -y && conda clean -a
|
| 15 |
+
|
| 16 |
+
# Install Python dependencies
|
| 17 |
+
RUN pip install uv
|
| 18 |
+
RUN uv pip install --system fastmcp
|
| 19 |
+
|
| 20 |
+
# Create app directory
|
| 21 |
+
WORKDIR /app
|
| 22 |
+
|
| 23 |
+
# Copy your MCP server
|
| 24 |
+
COPY app/msisensor-pro_server.py /app/
|
| 25 |
+
|
| 26 |
+
# Create workspace and output directories
|
| 27 |
+
RUN mkdir -p /app/workspace /app/output
|
| 28 |
+
|
| 29 |
+
# Make sure the server script is executable
|
| 30 |
+
RUN chmod +x /app/msisensor-pro_server.py
|
| 31 |
+
|
| 32 |
+
# Expose port for MCP over HTTP (optional)
|
| 33 |
+
EXPOSE 8000
|
| 34 |
+
|
| 35 |
+
# Health check
|
| 36 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 CMD python -c "import sys; sys.exit(0)"
|
| 37 |
+
|
| 38 |
+
# Default command runs the MCP server via stdio
|
| 39 |
+
CMD ["python", "/app/msisensor-pro_server.py"]
|
| 40 |
+
|