BioOcto code and data release (snapshot 2026-11-27) (part 5)
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_bactopia/Dockerfile +40 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bactopia/app/bactopia_server.py +279 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bactopia/app/bactopia_shim_server.py +45 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bactopia/app/requirements.txt +1 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bactopia/docker-compose.yml +22 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bactopia/environment.yaml +10 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bactopia/requirements.txt +2 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_barrnap/Dockerfile +40 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_barrnap/app/barrnap_server.py +336 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_barrnap/app/barrnap_shim_server.py +45 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_barrnap/app/requirements.txt +1 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_barrnap/docker-compose.yml +22 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_barrnap/environment.yaml +10 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_barrnap/requirements.txt +2 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bcbio-gff/Dockerfile +40 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bcbio-gff/app/bcbio-gff_server.py +192 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bcbio-gff/app/bcbio-gff_shim_server.py +45 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bcbio-gff/app/requirements.txt +1 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bcbio-gff/docker-compose.yml +22 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bcbio-gff/environment.yaml +10 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bcbio-gff/requirements.txt +2 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bcbio-nextgen/Dockerfile +40 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bcbio-nextgen/app/bcbio-nextgen_server.py +268 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bcbio-nextgen/app/bcbio-nextgen_shim_server.py +45 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bcbio-nextgen/docker-compose.yml +22 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bcbio-nextgen/environment.yaml +10 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bcbio-nextgen/requirements.txt +2 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bedops/Dockerfile +40 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bedops/app/bedops_server.py +450 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bedops/app/bedops_shim_server.py +45 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bedops/app/requirements.txt +1 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bedops/docker-compose.yml +22 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bedops/environment.yaml +10 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bedops/requirements.txt +2 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bin2cell/Dockerfile +40 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bin2cell/app/bin2cell_server.py +278 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bin2cell/app/bin2cell_shim_server.py +45 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bin2cell/app/requirements.txt +1 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bin2cell/docker-compose.yml +22 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bin2cell/environment.yaml +10 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bin2cell/requirements.txt +2 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioawk/Dockerfile +40 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioawk/app/bioawk_server.py +120 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioawk/app/bioawk_shim_server.py +45 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioawk/app/requirements.txt +1 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioawk/docker-compose.yml +22 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioawk/environment.yaml +10 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioawk/requirements.txt +2 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_biobambam/Dockerfile +40 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_biobambam/app/biobambam_server.py +489 -0
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bactopia/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 bactopia via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda bactopia -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/bactopia_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/bactopia_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 |
+
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
from typing import Optional, List, Union
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
@mcp.tool()
|
| 7 |
+
def bactopia_run(
|
| 8 |
+
sample: str,
|
| 9 |
+
outdir: str,
|
| 10 |
+
datasets: str,
|
| 11 |
+
r1: Optional[str] = None,
|
| 12 |
+
r2: Optional[str] = None,
|
| 13 |
+
se: Optional[str] = None,
|
| 14 |
+
fastqs: Optional[str] = None,
|
| 15 |
+
accession: Optional[str] = None,
|
| 16 |
+
accessions: Optional[str] = None,
|
| 17 |
+
profile: str = "conda",
|
| 18 |
+
cpus: int = 2,
|
| 19 |
+
max_memory: int = 8,
|
| 20 |
+
resume: bool = False,
|
| 21 |
+
) -> dict:
|
| 22 |
+
"""
|
| 23 |
+
Run the main Bactopia analysis pipeline for a bacterial genome.
|
| 24 |
+
|
| 25 |
+
Args:
|
| 26 |
+
sample: Name of the sample.
|
| 27 |
+
outdir: Directory to store output results.
|
| 28 |
+
datasets: Path to the Bactopia datasets directory.
|
| 29 |
+
r1: Path to forward reads (Paired-end).
|
| 30 |
+
r2: Path to reverse reads (Paired-end).
|
| 31 |
+
se: Path to single-end reads.
|
| 32 |
+
fastqs: Path to a FOFN (file-of-filenames) for multiple samples.
|
| 33 |
+
accession: A single ENA/SRA accession (e.g., SRX000000).
|
| 34 |
+
accessions: A file containing a list of ENA/SRA accessions.
|
| 35 |
+
profile: Nextflow profile to use (e.g., conda, docker, singularity).
|
| 36 |
+
cpus: Number of CPUs to allocate.
|
| 37 |
+
max_memory: Maximum memory in GB to allocate.
|
| 38 |
+
resume: Whether to resume a previous run.
|
| 39 |
+
"""
|
| 40 |
+
# Input validation
|
| 41 |
+
out_path = Path(outdir)
|
| 42 |
+
ds_path = Path(datasets)
|
| 43 |
+
|
| 44 |
+
if not ds_path.exists():
|
| 45 |
+
return {"error": f"Datasets directory not found at {datasets}"}
|
| 46 |
+
|
| 47 |
+
cmd = ["bactopia", "--sample", sample, "--outdir", str(out_path), "--datasets", str(ds_path)]
|
| 48 |
+
|
| 49 |
+
# Input source logic
|
| 50 |
+
if r1 and r2:
|
| 51 |
+
if not Path(r1).exists() or not Path(r2).exists():
|
| 52 |
+
return {"error": "R1 or R2 file does not exist"}
|
| 53 |
+
cmd += ["--R1", r1, "--R2", r2]
|
| 54 |
+
elif se:
|
| 55 |
+
if not Path(se).exists():
|
| 56 |
+
return {"error": "Single-end file does not exist"}
|
| 57 |
+
cmd += ["--SE", se]
|
| 58 |
+
elif fastqs:
|
| 59 |
+
if not Path(fastqs).exists():
|
| 60 |
+
return {"error": "Fastqs list file does not exist"}
|
| 61 |
+
cmd += ["--fastqs", fastqs]
|
| 62 |
+
elif accession:
|
| 63 |
+
cmd += ["--accession", accession]
|
| 64 |
+
elif accessions:
|
| 65 |
+
if not Path(accessions).exists():
|
| 66 |
+
return {"error": "Accessions list file does not exist"}
|
| 67 |
+
cmd += ["--accessions", accessions]
|
| 68 |
+
else:
|
| 69 |
+
return {"error": "No input source provided (R1/R2, SE, fastqs, accession, or accessions required)"}
|
| 70 |
+
|
| 71 |
+
# Performance and Nextflow options
|
| 72 |
+
cmd += ["-profile", profile]
|
| 73 |
+
cmd += ["--max_cpus", str(cpus)]
|
| 74 |
+
cmd += ["--max_memory", f"{max_memory}.GB"]
|
| 75 |
+
|
| 76 |
+
if resume:
|
| 77 |
+
cmd.append("-resume")
|
| 78 |
+
|
| 79 |
+
try:
|
| 80 |
+
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
| 81 |
+
return {
|
| 82 |
+
"command_executed": " ".join(cmd),
|
| 83 |
+
"stdout": result.stdout,
|
| 84 |
+
"stderr": result.stderr,
|
| 85 |
+
"output_directory": str(out_path.absolute())
|
| 86 |
+
}
|
| 87 |
+
except subprocess.CalledProcessError as e:
|
| 88 |
+
return {
|
| 89 |
+
"command_executed": " ".join(cmd),
|
| 90 |
+
"error": str(e),
|
| 91 |
+
"stdout": e.stdout,
|
| 92 |
+
"stderr": e.stderr
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
@mcp.tool()
|
| 96 |
+
def bactopia_prepare(
|
| 97 |
+
path: str,
|
| 98 |
+
recursive: bool = False,
|
| 99 |
+
extension: str = ".fastq.gz",
|
| 100 |
+
output_file: Optional[str] = None
|
| 101 |
+
) -> dict:
|
| 102 |
+
"""
|
| 103 |
+
Prepare a FASTQ list (FOFN) for Bactopia from a directory of sequencing files.
|
| 104 |
+
|
| 105 |
+
Args:
|
| 106 |
+
path: Directory containing FASTQ files.
|
| 107 |
+
recursive: Search for FASTQs in subdirectories.
|
| 108 |
+
extension: File extension to look for.
|
| 109 |
+
output_file: Optional path to save the generated list.
|
| 110 |
+
"""
|
| 111 |
+
input_path = Path(path)
|
| 112 |
+
if not input_path.is_dir():
|
| 113 |
+
return {"error": f"Path {path} is not a directory"}
|
| 114 |
+
|
| 115 |
+
cmd = ["bactopia", "prepare", str(input_path), "--extension", extension]
|
| 116 |
+
if recursive:
|
| 117 |
+
cmd.append("--recursive")
|
| 118 |
+
|
| 119 |
+
try:
|
| 120 |
+
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
| 121 |
+
|
| 122 |
+
if output_file:
|
| 123 |
+
out_p = Path(output_file)
|
| 124 |
+
out_p.write_text(result.stdout)
|
| 125 |
+
return {
|
| 126 |
+
"command_executed": " ".join(cmd),
|
| 127 |
+
"stdout": "File list generated and saved.",
|
| 128 |
+
"output_file": str(out_p.absolute())
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
return {
|
| 132 |
+
"command_executed": " ".join(cmd),
|
| 133 |
+
"stdout": result.stdout,
|
| 134 |
+
"stderr": result.stderr
|
| 135 |
+
}
|
| 136 |
+
except subprocess.CalledProcessError as e:
|
| 137 |
+
return {
|
| 138 |
+
"command_executed": " ".join(cmd),
|
| 139 |
+
"error": str(e),
|
| 140 |
+
"stdout": e.stdout,
|
| 141 |
+
"stderr": e.stderr
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
@mcp.tool()
|
| 145 |
+
def bactopia_search(
|
| 146 |
+
query: str,
|
| 147 |
+
limit: int = 10,
|
| 148 |
+
output_file: Optional[str] = None
|
| 149 |
+
) -> dict:
|
| 150 |
+
"""
|
| 151 |
+
Search for bacterial genome accessions in ENA/SRA.
|
| 152 |
+
|
| 153 |
+
Args:
|
| 154 |
+
query: Search query (e.g., "Staphylococcus aureus").
|
| 155 |
+
limit: Maximum number of results to return.
|
| 156 |
+
output_file: Optional path to save the accession list.
|
| 157 |
+
"""
|
| 158 |
+
cmd = ["bactopia", "search", query, "--limit", str(limit)]
|
| 159 |
+
|
| 160 |
+
try:
|
| 161 |
+
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
| 162 |
+
|
| 163 |
+
if output_file:
|
| 164 |
+
out_p = Path(output_file)
|
| 165 |
+
out_p.write_text(result.stdout)
|
| 166 |
+
return {
|
| 167 |
+
"command_executed": " ".join(cmd),
|
| 168 |
+
"stdout": f"Search results saved to {output_file}",
|
| 169 |
+
"output_file": str(out_p.absolute())
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
return {
|
| 173 |
+
"command_executed": " ".join(cmd),
|
| 174 |
+
"stdout": result.stdout,
|
| 175 |
+
"stderr": result.stderr
|
| 176 |
+
}
|
| 177 |
+
except subprocess.CalledProcessError as e:
|
| 178 |
+
return {
|
| 179 |
+
"command_executed": " ".join(cmd),
|
| 180 |
+
"error": str(e),
|
| 181 |
+
"stdout": e.stdout,
|
| 182 |
+
"stderr": e.stderr
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
@mcp.tool()
|
| 186 |
+
def bactopia_datasets(
|
| 187 |
+
outdir: str,
|
| 188 |
+
species: Optional[str] = None,
|
| 189 |
+
include_genus: bool = False,
|
| 190 |
+
limit: int = 100
|
| 191 |
+
) -> dict:
|
| 192 |
+
"""
|
| 193 |
+
Download and setup Bactopia datasets/databases.
|
| 194 |
+
|
| 195 |
+
Args:
|
| 196 |
+
outdir: Directory to save the datasets.
|
| 197 |
+
species: Optional species name to download specific datasets (e.g., "Salmonella enterica").
|
| 198 |
+
include_genus: Include genus-level datasets.
|
| 199 |
+
limit: Limit the number of genomes used for building datasets.
|
| 200 |
+
"""
|
| 201 |
+
out_path = Path(outdir)
|
| 202 |
+
cmd = ["bactopia", "datasets", "--outdir", str(out_path)]
|
| 203 |
+
|
| 204 |
+
if species:
|
| 205 |
+
cmd += ["--species", species]
|
| 206 |
+
if include_genus:
|
| 207 |
+
cmd.append("--include_genus")
|
| 208 |
+
cmd += ["--limit", str(limit)]
|
| 209 |
+
|
| 210 |
+
try:
|
| 211 |
+
# This can be a long-running process
|
| 212 |
+
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
| 213 |
+
return {
|
| 214 |
+
"command_executed": " ".join(cmd),
|
| 215 |
+
"stdout": result.stdout,
|
| 216 |
+
"stderr": result.stderr,
|
| 217 |
+
"datasets_path": str(out_path.absolute())
|
| 218 |
+
}
|
| 219 |
+
except subprocess.CalledProcessError as e:
|
| 220 |
+
return {
|
| 221 |
+
"command_executed": " ".join(cmd),
|
| 222 |
+
"error": str(e),
|
| 223 |
+
"stdout": e.stdout,
|
| 224 |
+
"stderr": e.stderr
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
@mcp.tool()
|
| 228 |
+
def bactopia_tool(
|
| 229 |
+
tool_name: str,
|
| 230 |
+
bactopia_dir: str,
|
| 231 |
+
outdir: str,
|
| 232 |
+
profile: str = "conda",
|
| 233 |
+
cpus: int = 2,
|
| 234 |
+
extra_params: Optional[List[str]] = None
|
| 235 |
+
) -> dict:
|
| 236 |
+
"""
|
| 237 |
+
Run a Bactopia Tool (comparative analysis) on existing Bactopia outputs.
|
| 238 |
+
Common tools include: pangenome, roary, iqtree, pirate, summary, etc.
|
| 239 |
+
|
| 240 |
+
Args:
|
| 241 |
+
tool_name: Name of the Bactopia Tool to run.
|
| 242 |
+
bactopia_dir: Directory containing previous Bactopia results.
|
| 243 |
+
outdir: Directory to store tool results.
|
| 244 |
+
profile: Nextflow profile to use.
|
| 245 |
+
cpus: Number of CPUs to allocate.
|
| 246 |
+
extra_params: List of additional command line arguments for the specific tool.
|
| 247 |
+
"""
|
| 248 |
+
b_path = Path(bactopia_dir)
|
| 249 |
+
o_path = Path(outdir)
|
| 250 |
+
|
| 251 |
+
if not b_path.exists():
|
| 252 |
+
return {"error": f"Bactopia results directory not found at {bactopia_dir}"}
|
| 253 |
+
|
| 254 |
+
cmd = [
|
| 255 |
+
"bactopia", tool_name,
|
| 256 |
+
"--bactopia", str(b_path),
|
| 257 |
+
"--outdir", str(o_path),
|
| 258 |
+
"-profile", profile,
|
| 259 |
+
"--max_cpus", str(cpus)
|
| 260 |
+
]
|
| 261 |
+
|
| 262 |
+
if extra_params:
|
| 263 |
+
cmd.extend(extra_params)
|
| 264 |
+
|
| 265 |
+
try:
|
| 266 |
+
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
| 267 |
+
return {
|
| 268 |
+
"command_executed": " ".join(cmd),
|
| 269 |
+
"stdout": result.stdout,
|
| 270 |
+
"stderr": result.stderr,
|
| 271 |
+
"output_directory": str(o_path.absolute())
|
| 272 |
+
}
|
| 273 |
+
except subprocess.CalledProcessError as e:
|
| 274 |
+
return {
|
| 275 |
+
"command_executed": " ".join(cmd),
|
| 276 |
+
"error": str(e),
|
| 277 |
+
"stdout": e.stdout,
|
| 278 |
+
"stderr": e.stderr
|
| 279 |
+
}
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bactopia/app/bactopia_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_bactopia/app/bactopia_server.py')
|
| 11 |
+
SERVER_NAME = 'biosci_bactopia'
|
| 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_bactopia/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bactopia/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-bactopia:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-bactopia:latest
|
| 7 |
+
container_name: mcp-bactopia
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=bactopia
|
| 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_bactopia/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- bactopia
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bactopia/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_barrnap/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 barrnap via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda barrnap -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/barrnap_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/barrnap_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)"
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import tempfile
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
from typing import Optional, List
|
| 5 |
+
|
| 6 |
+
# Helper function to execute barrnap commands and handle output.
|
| 7 |
+
# This function is internal and not exposed as an MCP tool.
|
| 8 |
+
def _run_barrnap_command(
|
| 9 |
+
command_args: List[str],
|
| 10 |
+
output_gff_path: Optional[Path] = None,
|
| 11 |
+
debug: bool = False,
|
| 12 |
+
quiet: bool = False,
|
| 13 |
+
) -> dict:
|
| 14 |
+
"""
|
| 15 |
+
Internal helper to execute barrnap commands.
|
| 16 |
+
Captures stdout, stderr, and handles CalledProcessError.
|
| 17 |
+
If output_gff_path is provided, stdout is written to that file.
|
| 18 |
+
"""
|
| 19 |
+
cmd = ["barrnap"] + command_args
|
| 20 |
+
|
| 21 |
+
if debug:
|
| 22 |
+
cmd.append("--debug")
|
| 23 |
+
if quiet:
|
| 24 |
+
cmd.append("--quiet")
|
| 25 |
+
|
| 26 |
+
stdout_capture = ""
|
| 27 |
+
stderr_capture = ""
|
| 28 |
+
output_files_generated = []
|
| 29 |
+
|
| 30 |
+
try:
|
| 31 |
+
# barrnap writes GFF to stdout by default.
|
| 32 |
+
# If output_gff_path is provided, we capture stdout and write it to the file.
|
| 33 |
+
process = subprocess.run(
|
| 34 |
+
cmd,
|
| 35 |
+
capture_output=True,
|
| 36 |
+
text=True,
|
| 37 |
+
check=True
|
| 38 |
+
)
|
| 39 |
+
stdout_capture = process.stdout
|
| 40 |
+
stderr_capture = process.stderr
|
| 41 |
+
|
| 42 |
+
if output_gff_path:
|
| 43 |
+
output_gff_path.write_text(stdout_capture)
|
| 44 |
+
output_files_generated.append(str(output_gff_path))
|
| 45 |
+
stdout_capture = f"GFF output written to {output_gff_path}"
|
| 46 |
+
|
| 47 |
+
except subprocess.CalledProcessError as e:
|
| 48 |
+
return {
|
| 49 |
+
"command_executed": " ".join(e.cmd),
|
| 50 |
+
"stdout": e.stdout,
|
| 51 |
+
"stderr": e.stderr,
|
| 52 |
+
"error": str(e),
|
| 53 |
+
"returncode": e.returncode,
|
| 54 |
+
"output_files": [],
|
| 55 |
+
}
|
| 56 |
+
except FileNotFoundError:
|
| 57 |
+
return {
|
| 58 |
+
"command_executed": " ".join(cmd),
|
| 59 |
+
"stdout": "",
|
| 60 |
+
"stderr": "barrnap command not found. Please ensure barrnap is installed and in your PATH.",
|
| 61 |
+
"error": "barrnap not found",
|
| 62 |
+
"returncode": 127,
|
| 63 |
+
"output_files": [],
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
return {
|
| 67 |
+
"command_executed": " ".join(cmd),
|
| 68 |
+
"stdout": stdout_capture,
|
| 69 |
+
"stderr": stderr_capture,
|
| 70 |
+
"output_files": output_files_generated,
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
@mcp.tool()
|
| 74 |
+
def barrnap_annotate(
|
| 75 |
+
fasta_file: Path,
|
| 76 |
+
output_gff_file: Path,
|
| 77 |
+
kingdom: Optional[str] = "bac",
|
| 78 |
+
enable_all_rna: bool = False,
|
| 79 |
+
disable_rrna: bool = False,
|
| 80 |
+
enable_trna: bool = False,
|
| 81 |
+
enable_ncrna: bool = False,
|
| 82 |
+
enable_mrna: bool = False,
|
| 83 |
+
threads: int = 1,
|
| 84 |
+
fast: bool = False,
|
| 85 |
+
evalue: Optional[float] = None,
|
| 86 |
+
incseq: bool = False,
|
| 87 |
+
incseqreg: bool = False,
|
| 88 |
+
outseq_file: Optional[Path] = None,
|
| 89 |
+
add_ids: bool = False,
|
| 90 |
+
db_directory: Optional[Path] = None,
|
| 91 |
+
debug: bool = False,
|
| 92 |
+
quiet: bool = False,
|
| 93 |
+
) -> dict:
|
| 94 |
+
"""
|
| 95 |
+
Annotates RNA features (rRNA, tRNA, tmRNA, ncRNA, mRNA) in microbial genomes
|
| 96 |
+
(bacteria, archaea, fungi) from an input FASTA file.
|
| 97 |
+
Outputs results in GFF3 format to the specified output file.
|
| 98 |
+
|
| 99 |
+
Args:
|
| 100 |
+
fasta_file: Path to the input FASTA file containing genomic sequences.
|
| 101 |
+
output_gff_file: Path to the output GFF3 file where annotations will be written.
|
| 102 |
+
kingdom: The database to use for annotation. Choices: "bac" (Bacteria),
|
| 103 |
+
"arc" (Archaea), "fun" (Fungi). Defaults to "bac".
|
| 104 |
+
enable_all_rna: If True, enables scanning for all RNA types (rRNA, tRNA, tmRNA, ncRNA, mRNA).
|
| 105 |
+
This is equivalent to `--all`.
|
| 106 |
+
disable_rrna: If True, disables rRNA scanning. This is equivalent to `--no-rrna`.
|
| 107 |
+
enable_trna: If True, enables tRNA scanning. This is equivalent to `--trna`.
|
| 108 |
+
enable_ncrna: If True, enables ncRNA scanning. This is equivalent to `--ncrna`.
|
| 109 |
+
enable_mrna: If True, enables mRNA scanning (including CDS, RBS, sig_pep, terminator).
|
| 110 |
+
This is equivalent to `--mrna`.
|
| 111 |
+
threads: Number of CPUs to use for the search. Must be at least 1. Defaults to 1.
|
| 112 |
+
fast: If True, uses simpler HMMs instead of CMs, which is faster but less accurate.
|
| 113 |
+
This is equivalent to `--fast`.
|
| 114 |
+
evalue: E-value cutoff for hits to keep. Must be greater than 0 if provided.
|
| 115 |
+
This is equivalent to `--evalue`.
|
| 116 |
+
incseq: If True, includes the full input sequences in the output GFF.
|
| 117 |
+
This is equivalent to `--incseq`.
|
| 118 |
+
incseqreg: If True, includes `##sequence-region` headers in the GFF.
|
| 119 |
+
This is equivalent to `--incseqreg`.
|
| 120 |
+
outseq_file: Path to a FASTA file where hit sequences will be written.
|
| 121 |
+
This is equivalent to `--outseq`.
|
| 122 |
+
add_ids: If True, adds unique ID= tags to each GFF3 feature.
|
| 123 |
+
This is equivalent to `--addids`.
|
| 124 |
+
db_directory: Path to a different database folder to use.
|
| 125 |
+
This is equivalent to `--dbdir`.
|
| 126 |
+
debug: If True, writes all temporary files to '.' and prints debug information.
|
| 127 |
+
This is equivalent to `--debug`.
|
| 128 |
+
quiet: If True, suppresses all messages to stderr. This is equivalent to `--quiet`.
|
| 129 |
+
|
| 130 |
+
Returns:
|
| 131 |
+
A dictionary containing:
|
| 132 |
+
- "command_executed": The full command string executed.
|
| 133 |
+
- "stdout": Standard output from the tool.
|
| 134 |
+
- "stderr": Standard error from the tool.
|
| 135 |
+
- "output_files": A list of paths to generated output files (GFF3 and optional FASTA).
|
| 136 |
+
"""
|
| 137 |
+
# Input validation
|
| 138 |
+
if not fasta_file.is_file():
|
| 139 |
+
raise ValueError(f"Input FASTA file not found: {fasta_file}")
|
| 140 |
+
if not output_gff_file.parent.is_dir():
|
| 141 |
+
raise ValueError(f"Output GFF directory does not exist: {output_gff_file.parent}")
|
| 142 |
+
|
| 143 |
+
valid_kingdoms = {"bac", "arc", "fun"}
|
| 144 |
+
if kingdom is not None and kingdom not in valid_kingdoms:
|
| 145 |
+
raise ValueError(f"Invalid kingdom: '{kingdom}'. Must be one of {', '.join(valid_kingdoms)}.")
|
| 146 |
+
|
| 147 |
+
if threads < 1:
|
| 148 |
+
raise ValueError(f"Number of threads must be at least 1, got {threads}.")
|
| 149 |
+
|
| 150 |
+
if evalue is not None and evalue <= 0:
|
| 151 |
+
raise ValueError(f"E-value cutoff must be greater than 0, got {evalue}.")
|
| 152 |
+
|
| 153 |
+
if outseq_file and not outseq_file.parent.is_dir():
|
| 154 |
+
raise ValueError(f"Output FASTA directory for hit sequences does not exist: {outseq_file.parent}")
|
| 155 |
+
|
| 156 |
+
if db_directory and not db_directory.is_dir():
|
| 157 |
+
raise ValueError(f"Database directory not found: {db_directory}")
|
| 158 |
+
|
| 159 |
+
command_args = [str(fasta_file)]
|
| 160 |
+
|
| 161 |
+
# Database management
|
| 162 |
+
if db_directory:
|
| 163 |
+
command_args.extend(["--dbdir", str(db_directory)])
|
| 164 |
+
|
| 165 |
+
# Search options
|
| 166 |
+
if kingdom:
|
| 167 |
+
command_args.extend(["--kingdom", kingdom])
|
| 168 |
+
if enable_all_rna:
|
| 169 |
+
command_args.append("--all")
|
| 170 |
+
if disable_rrna:
|
| 171 |
+
command_args.append("--no-rrna")
|
| 172 |
+
if enable_trna:
|
| 173 |
+
command_args.append("--trna")
|
| 174 |
+
if enable_ncrna:
|
| 175 |
+
command_args.append("--ncrna")
|
| 176 |
+
if enable_mrna:
|
| 177 |
+
command_args.append("--mrna")
|
| 178 |
+
|
| 179 |
+
# Speed options
|
| 180 |
+
if threads > 1: # barrnap default is 1 thread, so only add if > 1
|
| 181 |
+
command_args.extend(["--threads", str(threads)])
|
| 182 |
+
if fast:
|
| 183 |
+
command_args.append("--fast")
|
| 184 |
+
|
| 185 |
+
# Filtering options
|
| 186 |
+
if evalue is not None:
|
| 187 |
+
command_args.extend(["--evalue", str(evalue)])
|
| 188 |
+
|
| 189 |
+
# Output options
|
| 190 |
+
if incseq:
|
| 191 |
+
command_args.append("--incseq")
|
| 192 |
+
if incseqreg:
|
| 193 |
+
command_args.append("--incseqreg")
|
| 194 |
+
if outseq_file:
|
| 195 |
+
command_args.extend(["--outseq", str(outseq_file)])
|
| 196 |
+
if add_ids:
|
| 197 |
+
command_args.append("--addids")
|
| 198 |
+
|
| 199 |
+
result = _run_barrnap_command(
|
| 200 |
+
command_args=command_args,
|
| 201 |
+
output_gff_path=output_gff_file,
|
| 202 |
+
debug=debug,
|
| 203 |
+
quiet=quiet,
|
| 204 |
+
)
|
| 205 |
+
|
| 206 |
+
# Add outseq_file to output_files if it was generated by barrnap
|
| 207 |
+
if outseq_file and outseq_file.exists() and str(outseq_file) not in result["output_files"]:
|
| 208 |
+
result["output_files"].append(str(outseq_file))
|
| 209 |
+
|
| 210 |
+
return result
|
| 211 |
+
|
| 212 |
+
@mcp.tool()
|
| 213 |
+
def barrnap_list_databases(
|
| 214 |
+
db_directory: Optional[Path] = None,
|
| 215 |
+
debug: bool = False,
|
| 216 |
+
quiet: bool = False,
|
| 217 |
+
) -> dict:
|
| 218 |
+
"""
|
| 219 |
+
Lists the installed barrnap databases and their contents.
|
| 220 |
+
|
| 221 |
+
Args:
|
| 222 |
+
db_directory: Path to a different database folder to use.
|
| 223 |
+
This is equivalent to `--dbdir`.
|
| 224 |
+
debug: If True, writes all temporary files to '.' and prints debug information.
|
| 225 |
+
This is equivalent to `--debug`.
|
| 226 |
+
quiet: If True, suppresses all messages to stderr. This is equivalent to `--quiet`.
|
| 227 |
+
|
| 228 |
+
Returns:
|
| 229 |
+
A dictionary containing:
|
| 230 |
+
- "command_executed": The full command string executed.
|
| 231 |
+
- "stdout": Standard output from the tool, listing databases.
|
| 232 |
+
- "stderr": Standard error from the tool.
|
| 233 |
+
- "output_files": An empty list, as no files are generated.
|
| 234 |
+
"""
|
| 235 |
+
command_args = ["--listdb"]
|
| 236 |
+
|
| 237 |
+
if db_directory:
|
| 238 |
+
if not db_directory.is_dir():
|
| 239 |
+
raise ValueError(f"Database directory not found: {db_directory}")
|
| 240 |
+
command_args.extend(["--dbdir", str(db_directory)])
|
| 241 |
+
|
| 242 |
+
return _run_barrnap_command(
|
| 243 |
+
command_args=command_args,
|
| 244 |
+
debug=debug,
|
| 245 |
+
quiet=quiet,
|
| 246 |
+
)
|
| 247 |
+
|
| 248 |
+
@mcp.tool()
|
| 249 |
+
def barrnap_update_databases(
|
| 250 |
+
db_directory: Optional[Path] = None,
|
| 251 |
+
debug: bool = False,
|
| 252 |
+
quiet: bool = False,
|
| 253 |
+
) -> dict:
|
| 254 |
+
"""
|
| 255 |
+
Updates barrnap databases from the internet.
|
| 256 |
+
|
| 257 |
+
Args:
|
| 258 |
+
db_directory: Path to a different database folder to use.
|
| 259 |
+
This is equivalent to `--dbdir`.
|
| 260 |
+
debug: If True, writes all temporary files to '.' and prints debug information.
|
| 261 |
+
This is equivalent to `--debug`.
|
| 262 |
+
quiet: If True, suppresses all messages to stderr. This is equivalent to `--quiet`.
|
| 263 |
+
|
| 264 |
+
Returns:
|
| 265 |
+
A dictionary containing:
|
| 266 |
+
- "command_executed": The full command string executed.
|
| 267 |
+
- "stdout": Standard output from the tool, typically update messages.
|
| 268 |
+
- "stderr": Standard error from the tool.
|
| 269 |
+
- "output_files": An empty list, as no files are generated.
|
| 270 |
+
"""
|
| 271 |
+
command_args = ["--updatedb"]
|
| 272 |
+
|
| 273 |
+
if db_directory:
|
| 274 |
+
if not db_directory.is_dir():
|
| 275 |
+
raise ValueError(f"Database directory not found: {db_directory}")
|
| 276 |
+
command_args.extend(["--dbdir", str(db_directory)])
|
| 277 |
+
|
| 278 |
+
return _run_barrnap_command(
|
| 279 |
+
command_args=command_args,
|
| 280 |
+
debug=debug,
|
| 281 |
+
quiet=quiet,
|
| 282 |
+
)
|
| 283 |
+
|
| 284 |
+
@mcp.tool()
|
| 285 |
+
def barrnap_get_version(
|
| 286 |
+
debug: bool = False,
|
| 287 |
+
quiet: bool = False,
|
| 288 |
+
) -> dict:
|
| 289 |
+
"""
|
| 290 |
+
Prints the barrnap version in the format 'barrnap X.Y'.
|
| 291 |
+
|
| 292 |
+
Args:
|
| 293 |
+
debug: If True, writes all temporary files to '.' and prints debug information.
|
| 294 |
+
This is equivalent to `--debug`.
|
| 295 |
+
quiet: If True, suppresses all messages to stderr. This is equivalent to `--quiet`.
|
| 296 |
+
|
| 297 |
+
Returns:
|
| 298 |
+
A dictionary containing:
|
| 299 |
+
- "command_executed": The full command string executed.
|
| 300 |
+
- "stdout": Standard output from the tool, containing the version string.
|
| 301 |
+
- "stderr": Standard error from the tool.
|
| 302 |
+
- "output_files": An empty list, as no files are generated.
|
| 303 |
+
"""
|
| 304 |
+
command_args = ["--version"]
|
| 305 |
+
return _run_barrnap_command(
|
| 306 |
+
command_args=command_args,
|
| 307 |
+
debug=debug,
|
| 308 |
+
quiet=quiet,
|
| 309 |
+
)
|
| 310 |
+
|
| 311 |
+
@mcp.tool()
|
| 312 |
+
def barrnap_get_citation(
|
| 313 |
+
debug: bool = False,
|
| 314 |
+
quiet: bool = False,
|
| 315 |
+
) -> dict:
|
| 316 |
+
"""
|
| 317 |
+
Prints the barrnap citation information.
|
| 318 |
+
|
| 319 |
+
Args:
|
| 320 |
+
debug: If True, writes all temporary files to '.' and prints debug information.
|
| 321 |
+
This is equivalent to `--debug`.
|
| 322 |
+
quiet: If True, suppresses all messages to stderr. This is equivalent to `--quiet`.
|
| 323 |
+
|
| 324 |
+
Returns:
|
| 325 |
+
A dictionary containing:
|
| 326 |
+
- "command_executed": The full command string executed.
|
| 327 |
+
- "stdout": Standard output from the tool, containing the citation.
|
| 328 |
+
- "stderr": Standard error from the tool.
|
| 329 |
+
- "output_files": An empty list, as no files are generated.
|
| 330 |
+
"""
|
| 331 |
+
command_args = ["--citation"]
|
| 332 |
+
return _run_barrnap_command(
|
| 333 |
+
command_args=command_args,
|
| 334 |
+
debug=debug,
|
| 335 |
+
quiet=quiet,
|
| 336 |
+
)
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_barrnap/app/barrnap_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_barrnap/app/barrnap_server.py')
|
| 11 |
+
SERVER_NAME = 'biosci_barrnap'
|
| 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_barrnap/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_barrnap/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-barrnap:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-barrnap:latest
|
| 7 |
+
container_name: mcp-barrnap
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=barrnap
|
| 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_barrnap/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- barrnap
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_barrnap/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bcbio-gff/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 bcbio-gff via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda bcbio-gff -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/bcbio-gff_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/bcbio-gff_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/bcbio-gff_server.py"]
|
| 40 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bcbio-gff/app/bcbio-gff_server.py
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import tempfile
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
from typing import List, Dict
|
| 5 |
+
|
| 6 |
+
# Note: The 'bcbio-gff' package is primarily a Python library. It also
|
| 7 |
+
# installs several command-line utility scripts. The documentation provided
|
| 8 |
+
# did not include the '--help' output for these scripts. The following MCP
|
| 9 |
+
# tools are based on inferred, common-sense arguments for these utilities.
|
| 10 |
+
# The actual command-line interface may differ.
|
| 11 |
+
|
| 12 |
+
@mcp.tool()
|
| 13 |
+
def gff_to_bed(
|
| 14 |
+
gff_file: Path
|
| 15 |
+
) -> Dict:
|
| 16 |
+
"""
|
| 17 |
+
Converts a GFF file to a BED file using `gff_to_bed.py`.
|
| 18 |
+
|
| 19 |
+
This tool assumes the script takes a single GFF file as input and prints
|
| 20 |
+
the resulting BED formatted data to standard output.
|
| 21 |
+
"""
|
| 22 |
+
if not gff_file.is_file():
|
| 23 |
+
raise FileNotFoundError(f"Input GFF file not found: {gff_file}")
|
| 24 |
+
|
| 25 |
+
cmd = ["gff_to_bed.py", str(gff_file)]
|
| 26 |
+
|
| 27 |
+
try:
|
| 28 |
+
result = subprocess.run(
|
| 29 |
+
cmd,
|
| 30 |
+
capture_output=True,
|
| 31 |
+
text=True,
|
| 32 |
+
check=True
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
with tempfile.NamedTemporaryFile(
|
| 36 |
+
mode="w", delete=False, suffix=".bed", prefix="output_"
|
| 37 |
+
) as tmp_out:
|
| 38 |
+
tmp_out.write(result.stdout)
|
| 39 |
+
output_path = tmp_out.name
|
| 40 |
+
|
| 41 |
+
return {
|
| 42 |
+
"command_executed": " ".join(cmd),
|
| 43 |
+
"stdout": result.stdout,
|
| 44 |
+
"stderr": result.stderr,
|
| 45 |
+
"output_files": [output_path]
|
| 46 |
+
}
|
| 47 |
+
except FileNotFoundError:
|
| 48 |
+
raise RuntimeError("gff_to_bed.py not found. Ensure bcbio-gff scripts are in your PATH.")
|
| 49 |
+
except subprocess.CalledProcessError as e:
|
| 50 |
+
return {
|
| 51 |
+
"command_executed": " ".join(e.cmd),
|
| 52 |
+
"stdout": e.stdout,
|
| 53 |
+
"stderr": e.stderr,
|
| 54 |
+
"output_files": [],
|
| 55 |
+
"error": "Tool execution failed."
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
@mcp.tool()
|
| 59 |
+
def gff_filter_by_attribute(
|
| 60 |
+
gff_file: Path,
|
| 61 |
+
attribute_key: str,
|
| 62 |
+
attribute_value: str
|
| 63 |
+
) -> Dict:
|
| 64 |
+
"""
|
| 65 |
+
Filters a GFF file by a given attribute key-value pair using `gff_filter_by_attribute.py`.
|
| 66 |
+
|
| 67 |
+
This tool assumes the script takes an attribute key, an attribute value, and an
|
| 68 |
+
input GFF file as arguments, and prints the filtered GFF to standard output.
|
| 69 |
+
"""
|
| 70 |
+
if not gff_file.is_file():
|
| 71 |
+
raise FileNotFoundError(f"Input GFF file not found: {gff_file}")
|
| 72 |
+
|
| 73 |
+
cmd = ["gff_filter_by_attribute.py", attribute_key, attribute_value, str(gff_file)]
|
| 74 |
+
|
| 75 |
+
try:
|
| 76 |
+
result = subprocess.run(
|
| 77 |
+
cmd,
|
| 78 |
+
capture_output=True,
|
| 79 |
+
text=True,
|
| 80 |
+
check=True
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
with tempfile.NamedTemporaryFile(
|
| 84 |
+
mode="w", delete=False, suffix=".gff", prefix="filtered_"
|
| 85 |
+
) as tmp_out:
|
| 86 |
+
tmp_out.write(result.stdout)
|
| 87 |
+
output_path = tmp_out.name
|
| 88 |
+
|
| 89 |
+
return {
|
| 90 |
+
"command_executed": " ".join(cmd),
|
| 91 |
+
"stdout": result.stdout,
|
| 92 |
+
"stderr": result.stderr,
|
| 93 |
+
"output_files": [output_path]
|
| 94 |
+
}
|
| 95 |
+
except FileNotFoundError:
|
| 96 |
+
raise RuntimeError("gff_filter_by_attribute.py not found. Ensure bcbio-gff scripts are in your PATH.")
|
| 97 |
+
except subprocess.CalledProcessError as e:
|
| 98 |
+
return {
|
| 99 |
+
"command_executed": " ".join(e.cmd),
|
| 100 |
+
"stdout": e.stdout,
|
| 101 |
+
"stderr": e.stderr,
|
| 102 |
+
"output_files": [],
|
| 103 |
+
"error": "Tool execution failed."
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
@mcp.tool()
|
| 107 |
+
def gff_filter_by_type(
|
| 108 |
+
gff_file: Path,
|
| 109 |
+
feature_type: str
|
| 110 |
+
) -> Dict:
|
| 111 |
+
"""
|
| 112 |
+
Filters a GFF file by a feature type (e.g., 'gene', 'mRNA') using `gff_filter_by_type.py`.
|
| 113 |
+
|
| 114 |
+
This tool assumes the script takes an input GFF file and a feature type as
|
| 115 |
+
arguments, and prints the filtered GFF to standard output.
|
| 116 |
+
"""
|
| 117 |
+
if not gff_file.is_file():
|
| 118 |
+
raise FileNotFoundError(f"Input GFF file not found: {gff_file}")
|
| 119 |
+
|
| 120 |
+
cmd = ["gff_filter_by_type.py", str(gff_file), feature_type]
|
| 121 |
+
|
| 122 |
+
try:
|
| 123 |
+
result = subprocess.run(
|
| 124 |
+
cmd,
|
| 125 |
+
capture_output=True,
|
| 126 |
+
text=True,
|
| 127 |
+
check=True
|
| 128 |
+
)
|
| 129 |
+
|
| 130 |
+
with tempfile.NamedTemporaryFile(
|
| 131 |
+
mode="w", delete=False, suffix=".gff", prefix="filtered_type_"
|
| 132 |
+
) as tmp_out:
|
| 133 |
+
tmp_out.write(result.stdout)
|
| 134 |
+
output_path = tmp_out.name
|
| 135 |
+
|
| 136 |
+
return {
|
| 137 |
+
"command_executed": " ".join(cmd),
|
| 138 |
+
"stdout": result.stdout,
|
| 139 |
+
"stderr": result.stderr,
|
| 140 |
+
"output_files": [output_path]
|
| 141 |
+
}
|
| 142 |
+
except FileNotFoundError:
|
| 143 |
+
raise RuntimeError("gff_filter_by_type.py not found. Ensure bcbio-gff scripts are in your PATH.")
|
| 144 |
+
except subprocess.CalledProcessError as e:
|
| 145 |
+
return {
|
| 146 |
+
"command_executed": " ".join(e.cmd),
|
| 147 |
+
"stdout": e.stdout,
|
| 148 |
+
"stderr": e.stderr,
|
| 149 |
+
"output_files": [],
|
| 150 |
+
"error": "Tool execution failed."
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
@mcp.tool()
|
| 154 |
+
def gff_stats(
|
| 155 |
+
gff_file: Path
|
| 156 |
+
) -> Dict:
|
| 157 |
+
"""
|
| 158 |
+
Calculates statistics on features in a GFF file using `gff_stats.py`.
|
| 159 |
+
|
| 160 |
+
This tool assumes the script takes a single GFF file as input and prints
|
| 161 |
+
statistics to standard output.
|
| 162 |
+
"""
|
| 163 |
+
if not gff_file.is_file():
|
| 164 |
+
raise FileNotFoundError(f"Input GFF file not found: {gff_file}")
|
| 165 |
+
|
| 166 |
+
cmd = ["gff_stats.py", str(gff_file)]
|
| 167 |
+
|
| 168 |
+
try:
|
| 169 |
+
result = subprocess.run(
|
| 170 |
+
cmd,
|
| 171 |
+
capture_output=True,
|
| 172 |
+
text=True,
|
| 173 |
+
check=True
|
| 174 |
+
)
|
| 175 |
+
|
| 176 |
+
# The output is statistics text, not a structured file, so we return it directly.
|
| 177 |
+
return {
|
| 178 |
+
"command_executed": " ".join(cmd),
|
| 179 |
+
"stdout": result.stdout,
|
| 180 |
+
"stderr": result.stderr,
|
| 181 |
+
"output_files": []
|
| 182 |
+
}
|
| 183 |
+
except FileNotFoundError:
|
| 184 |
+
raise RuntimeError("gff_stats.py not found. Ensure bcbio-gff scripts are in your PATH.")
|
| 185 |
+
except subprocess.CalledProcessError as e:
|
| 186 |
+
return {
|
| 187 |
+
"command_executed": " ".join(e.cmd),
|
| 188 |
+
"stdout": e.stdout,
|
| 189 |
+
"stderr": e.stderr,
|
| 190 |
+
"output_files": [],
|
| 191 |
+
"error": "Tool execution failed."
|
| 192 |
+
}
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bcbio-gff/app/bcbio-gff_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_bcbio-gff/app/bcbio-gff_server.py')
|
| 11 |
+
SERVER_NAME = 'biosci_bcbio_gff'
|
| 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_bcbio-gff/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bcbio-gff/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-bcbio-gff:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-bcbio-gff:latest
|
| 7 |
+
container_name: mcp-bcbio-gff
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=bcbio-gff
|
| 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_bcbio-gff/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- bcbio-gff
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bcbio-gff/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bcbio-nextgen/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 bcbio-nextgen via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda bcbio-nextgen -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/bcbio-nextgen_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/bcbio-nextgen_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/bcbio-nextgen_server.py"]
|
| 40 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bcbio-nextgen/app/bcbio-nextgen_server.py
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import List, Optional, Dict, Any
|
| 2 |
+
import subprocess
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
@mcp.tool()
|
| 7 |
+
def bcbio_nextgen_run(
|
| 8 |
+
config_file: str,
|
| 9 |
+
num_cores: int = 1,
|
| 10 |
+
parallel_type: str = "local",
|
| 11 |
+
scheduler: Optional[str] = None,
|
| 12 |
+
queue: Optional[str] = None,
|
| 13 |
+
resources: Optional[str] = None,
|
| 14 |
+
tag: Optional[str] = None,
|
| 15 |
+
workdir: Optional[str] = None,
|
| 16 |
+
timeout: int = 15,
|
| 17 |
+
retries: int = 0,
|
| 18 |
+
) -> Dict[str, Any]:
|
| 19 |
+
"""
|
| 20 |
+
Run a bcbio-nextgen analysis pipeline using a provided configuration file.
|
| 21 |
+
|
| 22 |
+
Args:
|
| 23 |
+
config_file: Path to the YAML configuration file defining the analysis.
|
| 24 |
+
num_cores: Number of local cores to use for parallel execution.
|
| 25 |
+
parallel_type: Type of parallel execution (local, ipython, cluster, etc.).
|
| 26 |
+
scheduler: Scheduler for cluster execution (e.g., sge, slurm, torque, pbspro, lsf).
|
| 27 |
+
queue: Queue to submit jobs to on a cluster.
|
| 28 |
+
resources: Specific resource requirements for the scheduler (e.g., 'mem=16,vmem=20').
|
| 29 |
+
tag: Optional tag to identify this specific run.
|
| 30 |
+
workdir: Directory to use for processing (defaults to current directory).
|
| 31 |
+
timeout: Time in minutes to wait for ipython cluster startup.
|
| 32 |
+
retries: Number of times to retry failed steps.
|
| 33 |
+
"""
|
| 34 |
+
config_path = Path(config_file)
|
| 35 |
+
if not config_path.exists():
|
| 36 |
+
return {"error": f"Configuration file not found: {config_file}"}
|
| 37 |
+
|
| 38 |
+
cmd = ["bcbio_nextgen.py", str(config_path.absolute())]
|
| 39 |
+
|
| 40 |
+
cmd.extend(["-n", str(num_cores)])
|
| 41 |
+
cmd.extend(["-t", parallel_type])
|
| 42 |
+
|
| 43 |
+
if scheduler:
|
| 44 |
+
cmd.extend(["-s", scheduler])
|
| 45 |
+
if queue:
|
| 46 |
+
cmd.extend(["-q", queue])
|
| 47 |
+
if resources:
|
| 48 |
+
cmd.extend(["-r", resources])
|
| 49 |
+
if tag:
|
| 50 |
+
cmd.extend(["--tag", tag])
|
| 51 |
+
if timeout != 15:
|
| 52 |
+
cmd.extend(["--timeout", str(timeout)])
|
| 53 |
+
if retries > 0:
|
| 54 |
+
cmd.extend(["--retries", str(retries)])
|
| 55 |
+
|
| 56 |
+
# Handle working directory
|
| 57 |
+
original_dir = os.getcwd()
|
| 58 |
+
if workdir:
|
| 59 |
+
work_path = Path(workdir)
|
| 60 |
+
if not work_path.exists():
|
| 61 |
+
work_path.mkdir(parents=True, exist_ok=True)
|
| 62 |
+
os.chdir(work_path)
|
| 63 |
+
|
| 64 |
+
try:
|
| 65 |
+
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
| 66 |
+
return {
|
| 67 |
+
"command_executed": " ".join(cmd),
|
| 68 |
+
"stdout": result.stdout,
|
| 69 |
+
"stderr": result.stderr,
|
| 70 |
+
"status": "success"
|
| 71 |
+
}
|
| 72 |
+
except subprocess.CalledProcessError as e:
|
| 73 |
+
return {
|
| 74 |
+
"command_executed": " ".join(cmd),
|
| 75 |
+
"stdout": e.stdout,
|
| 76 |
+
"stderr": e.stderr,
|
| 77 |
+
"error": str(e),
|
| 78 |
+
"status": "failed"
|
| 79 |
+
}
|
| 80 |
+
finally:
|
| 81 |
+
os.chdir(original_dir)
|
| 82 |
+
|
| 83 |
+
@mcp.tool()
|
| 84 |
+
def bcbio_nextgen_template(
|
| 85 |
+
template_name: str,
|
| 86 |
+
metadata_csv: str,
|
| 87 |
+
input_files: List[str],
|
| 88 |
+
out_dir: Optional[str] = None,
|
| 89 |
+
) -> Dict[str, Any]:
|
| 90 |
+
"""
|
| 91 |
+
Create a bcbio-nextgen processing description from a template and input files.
|
| 92 |
+
|
| 93 |
+
Args:
|
| 94 |
+
template_name: Name of the template to use (e.g., 'freebayes-variant', 'gatk-variant').
|
| 95 |
+
metadata_csv: Path to a CSV file containing sample metadata.
|
| 96 |
+
input_files: List of paths to input BAM or FASTQ files.
|
| 97 |
+
out_dir: Directory to write the generated configuration (defaults to current directory).
|
| 98 |
+
"""
|
| 99 |
+
metadata_path = Path(metadata_csv)
|
| 100 |
+
if not metadata_path.exists():
|
| 101 |
+
return {"error": f"Metadata file not found: {metadata_csv}"}
|
| 102 |
+
|
| 103 |
+
# Validate input files
|
| 104 |
+
valid_inputs = []
|
| 105 |
+
for f in input_files:
|
| 106 |
+
p = Path(f)
|
| 107 |
+
if p.exists():
|
| 108 |
+
valid_inputs.append(str(p.absolute()))
|
| 109 |
+
else:
|
| 110 |
+
return {"error": f"Input file not found: {f}"}
|
| 111 |
+
|
| 112 |
+
cmd = ["bcbio_nextgen.py", "-w", "template", template_name, str(metadata_path.absolute())]
|
| 113 |
+
cmd.extend(valid_inputs)
|
| 114 |
+
|
| 115 |
+
# Handle output directory
|
| 116 |
+
original_dir = os.getcwd()
|
| 117 |
+
if out_dir:
|
| 118 |
+
out_path = Path(out_dir)
|
| 119 |
+
if not out_path.exists():
|
| 120 |
+
out_path.mkdir(parents=True, exist_ok=True)
|
| 121 |
+
os.chdir(out_path)
|
| 122 |
+
|
| 123 |
+
try:
|
| 124 |
+
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
| 125 |
+
return {
|
| 126 |
+
"command_executed": " ".join(cmd),
|
| 127 |
+
"stdout": result.stdout,
|
| 128 |
+
"stderr": result.stderr,
|
| 129 |
+
"status": "success",
|
| 130 |
+
"info": "Configuration files generated in the output directory."
|
| 131 |
+
}
|
| 132 |
+
except subprocess.CalledProcessError as e:
|
| 133 |
+
return {
|
| 134 |
+
"command_executed": " ".join(cmd),
|
| 135 |
+
"stdout": e.stdout,
|
| 136 |
+
"stderr": e.stderr,
|
| 137 |
+
"error": str(e),
|
| 138 |
+
"status": "failed"
|
| 139 |
+
}
|
| 140 |
+
finally:
|
| 141 |
+
os.chdir(original_dir)
|
| 142 |
+
|
| 143 |
+
@mcp.tool()
|
| 144 |
+
def bcbio_nextgen_upgrade(
|
| 145 |
+
tooldir: Optional[str] = None,
|
| 146 |
+
tools: bool = False,
|
| 147 |
+
data: bool = False,
|
| 148 |
+
genomes: Optional[List[str]] = None,
|
| 149 |
+
aligners: Optional[List[str]] = None,
|
| 150 |
+
cores: int = 1,
|
| 151 |
+
) -> Dict[str, Any]:
|
| 152 |
+
"""
|
| 153 |
+
Upgrade bcbio-nextgen software, third-party tools, or genome data.
|
| 154 |
+
|
| 155 |
+
Args:
|
| 156 |
+
tooldir: Directory where tools are installed.
|
| 157 |
+
tools: If True, upgrade third-party software tools.
|
| 158 |
+
data: If True, upgrade/install genome data.
|
| 159 |
+
genomes: List of genome builds to install/upgrade (e.g., ['hg38', 'mm10']).
|
| 160 |
+
aligners: List of aligners to install data for (e.g., ['bwa', 'bowtie2']).
|
| 161 |
+
cores: Number of cores to use for data downloads and indexing.
|
| 162 |
+
"""
|
| 163 |
+
cmd = ["bcbio_nextgen.py", "upgrade"]
|
| 164 |
+
|
| 165 |
+
if tooldir:
|
| 166 |
+
cmd.extend(["--tooldir", tooldir])
|
| 167 |
+
if tools:
|
| 168 |
+
cmd.append("--tools")
|
| 169 |
+
if data:
|
| 170 |
+
cmd.append("--data")
|
| 171 |
+
|
| 172 |
+
if genomes:
|
| 173 |
+
for g in genomes:
|
| 174 |
+
cmd.extend(["--genomes", g])
|
| 175 |
+
|
| 176 |
+
if aligners:
|
| 177 |
+
for a in aligners:
|
| 178 |
+
cmd.extend(["--aligners", a])
|
| 179 |
+
|
| 180 |
+
cmd.extend(["--cores", str(cores)])
|
| 181 |
+
|
| 182 |
+
try:
|
| 183 |
+
# Upgrades can take a long time, but we capture output
|
| 184 |
+
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
| 185 |
+
return {
|
| 186 |
+
"command_executed": " ".join(cmd),
|
| 187 |
+
"stdout": result.stdout,
|
| 188 |
+
"stderr": result.stderr,
|
| 189 |
+
"status": "success"
|
| 190 |
+
}
|
| 191 |
+
except subprocess.CalledProcessError as e:
|
| 192 |
+
return {
|
| 193 |
+
"command_executed": " ".join(cmd),
|
| 194 |
+
"stdout": e.stdout,
|
| 195 |
+
"stderr": e.stderr,
|
| 196 |
+
"error": str(e),
|
| 197 |
+
"status": "failed"
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
@mcp.tool()
|
| 201 |
+
def bcbio_nextgen_install(
|
| 202 |
+
install_path: str,
|
| 203 |
+
tooldir: str,
|
| 204 |
+
genomes: List[str],
|
| 205 |
+
aligners: List[str],
|
| 206 |
+
nodata: bool = False,
|
| 207 |
+
isolate: bool = False,
|
| 208 |
+
) -> Dict[str, Any]:
|
| 209 |
+
"""
|
| 210 |
+
Run the bcbio-nextgen installer script to set up the environment.
|
| 211 |
+
|
| 212 |
+
Args:
|
| 213 |
+
install_path: Path to install bcbio-nextgen data and code.
|
| 214 |
+
tooldir: Path to install third-party software tools.
|
| 215 |
+
genomes: List of genome builds to install (e.g., ['hg38']).
|
| 216 |
+
aligners: List of aligners to prepare (e.g., ['bwa']).
|
| 217 |
+
nodata: If True, do not install genome data.
|
| 218 |
+
isolate: If True, install into an isolated environment.
|
| 219 |
+
"""
|
| 220 |
+
# Note: This assumes bcbio_nextgen_install.py is in the PATH or current directory
|
| 221 |
+
# In a real environment, users might need to download it first.
|
| 222 |
+
cmd = ["python", "bcbio_nextgen_install.py", install_path, "--tooldir=" + tooldir]
|
| 223 |
+
|
| 224 |
+
for g in genomes:
|
| 225 |
+
cmd.extend(["--genomes", g])
|
| 226 |
+
for a in aligners:
|
| 227 |
+
cmd.extend(["--aligners", a])
|
| 228 |
+
|
| 229 |
+
if nodata:
|
| 230 |
+
cmd.append("--nodata")
|
| 231 |
+
if isolate:
|
| 232 |
+
cmd.append("--isolate")
|
| 233 |
+
|
| 234 |
+
try:
|
| 235 |
+
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
| 236 |
+
return {
|
| 237 |
+
"command_executed": " ".join(cmd),
|
| 238 |
+
"stdout": result.stdout,
|
| 239 |
+
"stderr": result.stderr,
|
| 240 |
+
"status": "success"
|
| 241 |
+
}
|
| 242 |
+
except subprocess.CalledProcessError as e:
|
| 243 |
+
return {
|
| 244 |
+
"command_executed": " ".join(cmd),
|
| 245 |
+
"stdout": e.stdout,
|
| 246 |
+
"stderr": e.stderr,
|
| 247 |
+
"error": str(e),
|
| 248 |
+
"status": "failed"
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
@mcp.tool()
|
| 252 |
+
def bcbio_nextgen_version() -> Dict[str, Any]:
|
| 253 |
+
"""
|
| 254 |
+
Check the installed version of bcbio-nextgen.
|
| 255 |
+
"""
|
| 256 |
+
cmd = ["bcbio_nextgen.py", "--version"]
|
| 257 |
+
try:
|
| 258 |
+
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
| 259 |
+
return {
|
| 260 |
+
"command_executed": " ".join(cmd),
|
| 261 |
+
"stdout": result.stdout.strip(),
|
| 262 |
+
"status": "success"
|
| 263 |
+
}
|
| 264 |
+
except subprocess.CalledProcessError as e:
|
| 265 |
+
return {
|
| 266 |
+
"error": str(e),
|
| 267 |
+
"status": "failed"
|
| 268 |
+
}
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bcbio-nextgen/app/bcbio-nextgen_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_bcbio-nextgen/app/bcbio-nextgen_server.py')
|
| 11 |
+
SERVER_NAME = 'biosci_bcbio_nextgen'
|
| 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_bcbio-nextgen/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-bcbio-nextgen:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-bcbio-nextgen:latest
|
| 7 |
+
container_name: mcp-bcbio-nextgen
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=bcbio-nextgen
|
| 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_bcbio-nextgen/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- bcbio-nextgen
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bcbio-nextgen/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bedops/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 bedops via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda bedops -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/bedops_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/bedops_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/bedops_server.py"]
|
| 40 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bedops/app/bedops_server.py
ADDED
|
@@ -0,0 +1,450 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
from typing import List, Optional, Union
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
def _run_command(command: List[str]):
|
| 7 |
+
"""Internal helper to execute subprocess commands safely."""
|
| 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 |
+
"exit_code": e.returncode
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
@mcp.tool()
|
| 31 |
+
def bedops(
|
| 32 |
+
operation: str,
|
| 33 |
+
input_files: List[str],
|
| 34 |
+
chrom: Optional[str] = None,
|
| 35 |
+
ec: bool = False,
|
| 36 |
+
header: bool = False,
|
| 37 |
+
range_val: Optional[str] = None,
|
| 38 |
+
overlap_criteria: Optional[str] = None,
|
| 39 |
+
chop_bp: int = 0,
|
| 40 |
+
stagger: int = 0,
|
| 41 |
+
exclude: bool = False
|
| 42 |
+
):
|
| 43 |
+
"""
|
| 44 |
+
Perform set operations on BED or Starch files.
|
| 45 |
+
|
| 46 |
+
Args:
|
| 47 |
+
operation: One of: 'complement' (-c), 'difference' (-d), 'element-of' (-e), 'intersect' (-i), 'merge' (-m), 'not-element-of' (-n), 'partition' (-p), 'symmdiff' (-s), 'everything' (-u), 'chop' (-w).
|
| 48 |
+
input_files: List of paths to sorted BED or Starch files.
|
| 49 |
+
chrom: Process data for given chromosome only.
|
| 50 |
+
ec: Enable error checking (slower).
|
| 51 |
+
header: Accept headers (VCF, GFF, SAM, BED, WIG) in input.
|
| 52 |
+
range_val: Add 'L:R' bp to coordinates or 'S' for symmetric padding.
|
| 53 |
+
overlap_criteria: For -e or -n, specify bp or percentage (e.g., '1' or '50%').
|
| 54 |
+
chop_bp: For -w, specify window size in bp.
|
| 55 |
+
stagger: For -w, specify stagger distance in nt.
|
| 56 |
+
exclude: For -w, exclude original elements.
|
| 57 |
+
"""
|
| 58 |
+
# Map operation names to flags
|
| 59 |
+
op_map = {
|
| 60 |
+
"complement": "-c", "difference": "-d", "element-of": "-e",
|
| 61 |
+
"intersect": "-i", "merge": "-m", "not-element-of": "-n",
|
| 62 |
+
"partition": "-p", "symmdiff": "-s", "everything": "-u", "chop": "-w"
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
if operation not in op_map:
|
| 66 |
+
raise ValueError(f"Invalid operation. Must be one of: {list(op_map.keys())}")
|
| 67 |
+
|
| 68 |
+
cmd = ["bedops"]
|
| 69 |
+
|
| 70 |
+
# Process Flags
|
| 71 |
+
if chrom: cmd.extend(["--chrom", chrom])
|
| 72 |
+
if ec: cmd.append("--ec")
|
| 73 |
+
if header: cmd.append("--header")
|
| 74 |
+
if range_val: cmd.extend(["--range", range_val])
|
| 75 |
+
|
| 76 |
+
# Operation and its specific arguments
|
| 77 |
+
cmd.append(op_map[operation])
|
| 78 |
+
|
| 79 |
+
if operation in ["element-of", "not-element-of"] and overlap_criteria:
|
| 80 |
+
cmd.append(overlap_criteria)
|
| 81 |
+
|
| 82 |
+
if operation == "chop":
|
| 83 |
+
if chop_bp > 0: cmd.append(str(chop_bp))
|
| 84 |
+
if stagger > 0: cmd.extend(["--stagger", str(stagger)])
|
| 85 |
+
if exclude: cmd.append("-x")
|
| 86 |
+
|
| 87 |
+
# Validate and add files
|
| 88 |
+
for f in input_files:
|
| 89 |
+
path = Path(f)
|
| 90 |
+
if not path.exists():
|
| 91 |
+
raise FileNotFoundError(f"Input file not found: {f}")
|
| 92 |
+
cmd.append(str(path.resolve()))
|
| 93 |
+
|
| 94 |
+
return _run_command(cmd)
|
| 95 |
+
|
| 96 |
+
@mcp.tool()
|
| 97 |
+
def bedmap(
|
| 98 |
+
reference_file: str,
|
| 99 |
+
map_file: str,
|
| 100 |
+
operations: List[str],
|
| 101 |
+
chrom: Optional[str] = None,
|
| 102 |
+
ec: bool = False,
|
| 103 |
+
header: bool = False,
|
| 104 |
+
range_val: Optional[str] = None,
|
| 105 |
+
bp_ovr: Optional[int] = None,
|
| 106 |
+
fraction_both: Optional[float] = None,
|
| 107 |
+
exact: bool = False,
|
| 108 |
+
faster: bool = False,
|
| 109 |
+
delim: str = "|",
|
| 110 |
+
echo: bool = False,
|
| 111 |
+
echo_map: bool = False,
|
| 112 |
+
indicator: bool = False
|
| 113 |
+
):
|
| 114 |
+
"""
|
| 115 |
+
Map overlapping BED elements and compute statistical operations.
|
| 116 |
+
|
| 117 |
+
Args:
|
| 118 |
+
reference_file: The target regions.
|
| 119 |
+
map_file: The features to map onto reference regions.
|
| 120 |
+
operations: List of stats to compute (e.g., '--mean', '--max', '--min', '--count', '--sum').
|
| 121 |
+
chrom: Process data for given chromosome only.
|
| 122 |
+
ec: Enable error checking.
|
| 123 |
+
header: Accept headers in input.
|
| 124 |
+
range_val: Add 'L:R' bp to reference coordinates.
|
| 125 |
+
bp_ovr: Require at least N bp overlap.
|
| 126 |
+
fraction_both: Require overlap of at least fraction of both elements.
|
| 127 |
+
exact: Require exact coordinate match.
|
| 128 |
+
faster: Use faster overlap detection (requires specific criteria).
|
| 129 |
+
delim: Delimiter for output columns.
|
| 130 |
+
echo: Echo reference element.
|
| 131 |
+
echo_map: Echo mapped elements.
|
| 132 |
+
indicator: Output 1 if overlap exists, 0 otherwise.
|
| 133 |
+
"""
|
| 134 |
+
cmd = ["bedmap"]
|
| 135 |
+
if chrom: cmd.extend(["--chrom", chrom])
|
| 136 |
+
if ec: cmd.append("--ec")
|
| 137 |
+
if header: cmd.append("--header")
|
| 138 |
+
if range_val: cmd.extend(["--range", range_val])
|
| 139 |
+
if bp_ovr is not None: cmd.extend(["--bp-ovr", str(bp_ovr)])
|
| 140 |
+
if fraction_both is not None: cmd.extend(["--fraction-both", str(fraction_both)])
|
| 141 |
+
if exact: cmd.append("--exact")
|
| 142 |
+
if faster: cmd.append("--faster")
|
| 143 |
+
cmd.extend(["--delim", delim])
|
| 144 |
+
if echo: cmd.append("--echo")
|
| 145 |
+
if echo_map: cmd.append("--echo-map")
|
| 146 |
+
if indicator: cmd.append("--indicator")
|
| 147 |
+
|
| 148 |
+
cmd.extend(operations)
|
| 149 |
+
|
| 150 |
+
ref_path = Path(reference_file)
|
| 151 |
+
map_path = Path(map_file)
|
| 152 |
+
if not ref_path.exists() or not map_path.exists():
|
| 153 |
+
raise FileNotFoundError("Reference or Map file not found.")
|
| 154 |
+
|
| 155 |
+
cmd.extend([str(ref_path.resolve()), str(map_path.resolve())])
|
| 156 |
+
return _run_command(cmd)
|
| 157 |
+
|
| 158 |
+
@mcp.tool()
|
| 159 |
+
def sort_bed(
|
| 160 |
+
input_file: str,
|
| 161 |
+
max_mem: Optional[str] = None,
|
| 162 |
+
tmpdir: Optional[str] = None,
|
| 163 |
+
check_sort: bool = False
|
| 164 |
+
):
|
| 165 |
+
"""
|
| 166 |
+
Sort BED data lexicographically. Required for most BEDOPS tools.
|
| 167 |
+
|
| 168 |
+
Args:
|
| 169 |
+
input_file: Path to the BED file to sort.
|
| 170 |
+
max_mem: Limit system memory (e.g., '2G').
|
| 171 |
+
tmpdir: Custom temporary directory.
|
| 172 |
+
check_sort: Check if the file is already sorted.
|
| 173 |
+
"""
|
| 174 |
+
cmd = ["sort-bed"]
|
| 175 |
+
if max_mem: cmd.extend(["--max-mem", max_mem])
|
| 176 |
+
if tmpdir: cmd.extend(["--tmpdir", tmpdir])
|
| 177 |
+
if check_sort: cmd.append("--check")
|
| 178 |
+
|
| 179 |
+
path = Path(input_file)
|
| 180 |
+
if not path.exists():
|
| 181 |
+
raise FileNotFoundError(f"Input file not found: {input_file}")
|
| 182 |
+
|
| 183 |
+
cmd.append(str(path.resolve()))
|
| 184 |
+
return _run_command(cmd)
|
| 185 |
+
|
| 186 |
+
@mcp.tool()
|
| 187 |
+
def closest_features(
|
| 188 |
+
reference_file: str,
|
| 189 |
+
query_file: str,
|
| 190 |
+
chrom: Optional[str] = None,
|
| 191 |
+
ec: bool = False,
|
| 192 |
+
dist: bool = False,
|
| 193 |
+
closest: bool = False,
|
| 194 |
+
opp: bool = False
|
| 195 |
+
):
|
| 196 |
+
"""
|
| 197 |
+
Find nearest features between two BED files.
|
| 198 |
+
|
| 199 |
+
Args:
|
| 200 |
+
reference_file: Reference BED file.
|
| 201 |
+
query_file: Query BED file.
|
| 202 |
+
chrom: Process data for given chromosome only.
|
| 203 |
+
ec: Enable error checking.
|
| 204 |
+
dist: Output signed distances.
|
| 205 |
+
closest: Output only the single closest feature.
|
| 206 |
+
opp: Find closest feature in opposite direction.
|
| 207 |
+
"""
|
| 208 |
+
cmd = ["closest-features"]
|
| 209 |
+
if chrom: cmd.extend(["--chrom", chrom])
|
| 210 |
+
if ec: cmd.append("--ec")
|
| 211 |
+
if dist: cmd.append("--dist")
|
| 212 |
+
if closest: cmd.append("--closest")
|
| 213 |
+
if opp: cmd.append("--opp")
|
| 214 |
+
|
| 215 |
+
ref_path = Path(reference_file)
|
| 216 |
+
query_path = Path(query_file)
|
| 217 |
+
if not ref_path.exists() or not query_path.exists():
|
| 218 |
+
raise FileNotFoundError("Reference or Query file not found.")
|
| 219 |
+
|
| 220 |
+
cmd.extend([str(ref_path.resolve()), str(query_path.resolve())])
|
| 221 |
+
return _run_command(cmd)
|
| 222 |
+
|
| 223 |
+
@mcp.tool()
|
| 224 |
+
def bedextract(
|
| 225 |
+
input_file: str,
|
| 226 |
+
chromosome: Optional[str] = None,
|
| 227 |
+
list_chromosomes: bool = False
|
| 228 |
+
):
|
| 229 |
+
"""
|
| 230 |
+
Efficiently extract features from a BED file.
|
| 231 |
+
|
| 232 |
+
Args:
|
| 233 |
+
input_file: Path to sorted BED file.
|
| 234 |
+
chromosome: Extract features for this chromosome.
|
| 235 |
+
list_chromosomes: List all chromosomes in the file.
|
| 236 |
+
"""
|
| 237 |
+
cmd = ["bedextract"]
|
| 238 |
+
path = Path(input_file)
|
| 239 |
+
if not path.exists():
|
| 240 |
+
raise FileNotFoundError(f"Input file not found: {input_file}")
|
| 241 |
+
|
| 242 |
+
if list_chromosomes:
|
| 243 |
+
cmd.append("--list-chromosomes")
|
| 244 |
+
cmd.append(str(path.resolve()))
|
| 245 |
+
elif chromosome:
|
| 246 |
+
cmd.append(chromosome)
|
| 247 |
+
cmd.append(str(path.resolve()))
|
| 248 |
+
else:
|
| 249 |
+
raise ValueError("Must specify either a chromosome or list_chromosomes=True")
|
| 250 |
+
|
| 251 |
+
return _run_command(cmd)
|
| 252 |
+
|
| 253 |
+
@mcp.tool()
|
| 254 |
+
def starch(
|
| 255 |
+
input_file: str,
|
| 256 |
+
output_file: str,
|
| 257 |
+
bzip2: bool = False,
|
| 258 |
+
gzip: bool = False,
|
| 259 |
+
note: Optional[str] = None
|
| 260 |
+
):
|
| 261 |
+
"""
|
| 262 |
+
Compress BED data into Starch format.
|
| 263 |
+
|
| 264 |
+
Args:
|
| 265 |
+
input_file: Path to sorted BED file.
|
| 266 |
+
output_file: Path to save the .starch file.
|
| 267 |
+
bzip2: Use bzip2 backend (default).
|
| 268 |
+
gzip: Use gzip backend.
|
| 269 |
+
note: Add a custom note to metadata.
|
| 270 |
+
"""
|
| 271 |
+
cmd = ["starch"]
|
| 272 |
+
if bzip2: cmd.append("--bzip2")
|
| 273 |
+
if gzip: cmd.append("--gzip")
|
| 274 |
+
if note: cmd.extend(["--note", note])
|
| 275 |
+
|
| 276 |
+
path = Path(input_file)
|
| 277 |
+
if not path.exists():
|
| 278 |
+
raise FileNotFoundError(f"Input file not found: {input_file}")
|
| 279 |
+
|
| 280 |
+
cmd.append(str(path.resolve()))
|
| 281 |
+
|
| 282 |
+
# starch outputs to stdout, so we redirect in the shell or capture
|
| 283 |
+
result = _run_command(cmd)
|
| 284 |
+
if result["status"] == "success":
|
| 285 |
+
with open(output_file, "w") as f:
|
| 286 |
+
f.write(result["stdout"])
|
| 287 |
+
result["output_files"] = [str(Path(output_file).resolve())]
|
| 288 |
+
return result
|
| 289 |
+
|
| 290 |
+
@mcp.tool()
|
| 291 |
+
def unstarch(
|
| 292 |
+
starch_file: str,
|
| 293 |
+
chromosome: Optional[str] = None,
|
| 294 |
+
list_chromosomes: bool = False,
|
| 295 |
+
is_starch: bool = False,
|
| 296 |
+
metadata: bool = False
|
| 297 |
+
):
|
| 298 |
+
"""
|
| 299 |
+
Extract data or metadata from a Starch archive.
|
| 300 |
+
|
| 301 |
+
Args:
|
| 302 |
+
starch_file: Path to .starch file.
|
| 303 |
+
chromosome: Extract data for specific chromosome.
|
| 304 |
+
list_chromosomes: List chromosomes in archive.
|
| 305 |
+
is_starch: Verify if file is a valid starch archive.
|
| 306 |
+
metadata: Show archive metadata.
|
| 307 |
+
"""
|
| 308 |
+
cmd = ["unstarch"]
|
| 309 |
+
if list_chromosomes: cmd.append("--list-chromosomes")
|
| 310 |
+
if is_starch: cmd.append("--is-starch")
|
| 311 |
+
if metadata: cmd.append("--metadata")
|
| 312 |
+
|
| 313 |
+
path = Path(starch_file)
|
| 314 |
+
if not path.exists():
|
| 315 |
+
raise FileNotFoundError(f"Starch file not found: {starch_file}")
|
| 316 |
+
|
| 317 |
+
if chromosome and not (list_chromosomes or is_starch or metadata):
|
| 318 |
+
cmd.append(chromosome)
|
| 319 |
+
|
| 320 |
+
cmd.append(str(path.resolve()))
|
| 321 |
+
return _run_command(cmd)
|
| 322 |
+
|
| 323 |
+
@mcp.tool()
|
| 324 |
+
def vcf2bed(input_file: str, custom_variants: bool = False):
|
| 325 |
+
"""Convert VCF to BED format."""
|
| 326 |
+
cmd = ["vcf2bed"]
|
| 327 |
+
if custom_variants: cmd.append("--custom-variants")
|
| 328 |
+
|
| 329 |
+
path = Path(input_file)
|
| 330 |
+
if not path.exists(): raise FileNotFoundError(f"File not found: {input_file}")
|
| 331 |
+
|
| 332 |
+
# vcf2bed reads from stdin
|
| 333 |
+
with open(path, 'r') as f:
|
| 334 |
+
try:
|
| 335 |
+
result = subprocess.run(cmd, stdin=f, capture_output=True, text=True, check=True)
|
| 336 |
+
return {"command_executed": f"vcf2bed < {input_file}", "stdout": result.stdout, "stderr": result.stderr}
|
| 337 |
+
except subprocess.CalledProcessError as e:
|
| 338 |
+
return {"status": "error", "stderr": e.stderr}
|
| 339 |
+
|
| 340 |
+
@mcp.tool()
|
| 341 |
+
def bam2bed(input_file: str, split: bool = False):
|
| 342 |
+
"""Convert BAM to BED format."""
|
| 343 |
+
cmd = ["bam2bed"]
|
| 344 |
+
if split: cmd.append("--split")
|
| 345 |
+
|
| 346 |
+
path = Path(input_file)
|
| 347 |
+
if not path.exists(): raise FileNotFoundError(f"File not found: {input_file}")
|
| 348 |
+
|
| 349 |
+
with open(path, 'rb') as f:
|
| 350 |
+
try:
|
| 351 |
+
result = subprocess.run(cmd, stdin=f, capture_output=True, text=True, check=True)
|
| 352 |
+
return {"command_executed": f"bam2bed < {input_file}", "stdout": result.stdout, "stderr": result.stderr}
|
| 353 |
+
except subprocess.CalledProcessError as e:
|
| 354 |
+
return {"status": "error", "stderr": e.stderr}
|
| 355 |
+
|
| 356 |
+
@mcp.tool()
|
| 357 |
+
def gff2bed(input_file: str):
|
| 358 |
+
"""Convert GFF to BED format."""
|
| 359 |
+
path = Path(input_file)
|
| 360 |
+
if not path.exists(): raise FileNotFoundError(f"File not found: {input_file}")
|
| 361 |
+
with open(path, 'r') as f:
|
| 362 |
+
result = subprocess.run(["gff2bed"], stdin=f, capture_output=True, text=True, check=True)
|
| 363 |
+
return {"stdout": result.stdout, "stderr": result.stderr}
|
| 364 |
+
|
| 365 |
+
@mcp.tool()
|
| 366 |
+
def gtf2bed(input_file: str):
|
| 367 |
+
"""Convert GTF to BED format."""
|
| 368 |
+
path = Path(input_file)
|
| 369 |
+
if not path.exists(): raise FileNotFoundError(f"File not found: {input_file}")
|
| 370 |
+
with open(path, 'r') as f:
|
| 371 |
+
result = subprocess.run(["gtf2bed"], stdin=f, capture_output=True, text=True, check=True)
|
| 372 |
+
return {"stdout": result.stdout, "stderr": result.stderr}
|
| 373 |
+
|
| 374 |
+
@mcp.tool()
|
| 375 |
+
def sam2bed(input_file: str):
|
| 376 |
+
"""Convert SAM to BED format."""
|
| 377 |
+
path = Path(input_file)
|
| 378 |
+
if not path.exists(): raise FileNotFoundError(f"File not found: {input_file}")
|
| 379 |
+
with open(path, 'r') as f:
|
| 380 |
+
result = subprocess.run(["sam2bed"], stdin=f, capture_output=True, text=True, check=True)
|
| 381 |
+
return {"stdout": result.stdout, "stderr": result.stderr}
|
| 382 |
+
|
| 383 |
+
@mcp.tool()
|
| 384 |
+
def wig2bed(input_file: str):
|
| 385 |
+
"""Convert WIG to BED format."""
|
| 386 |
+
path = Path(input_file)
|
| 387 |
+
if not path.exists(): raise FileNotFoundError(f"File not found: {input_file}")
|
| 388 |
+
with open(path, 'r') as f:
|
| 389 |
+
result = subprocess.run(["wig2bed"], stdin=f, capture_output=True, text=True, check=True)
|
| 390 |
+
return {"stdout": result.stdout, "stderr": result.stderr}
|
| 391 |
+
|
| 392 |
+
@mcp.tool()
|
| 393 |
+
def starchcat(
|
| 394 |
+
input_starch_files: List[str],
|
| 395 |
+
output_file: str,
|
| 396 |
+
note: Optional[str] = None
|
| 397 |
+
):
|
| 398 |
+
"""
|
| 399 |
+
Merge multiple Starch archives into one.
|
| 400 |
+
|
| 401 |
+
Args:
|
| 402 |
+
input_starch_files: List of .starch files to merge.
|
| 403 |
+
output_file: Path for the merged starch archive.
|
| 404 |
+
note: Custom note for metadata.
|
| 405 |
+
"""
|
| 406 |
+
cmd = ["starchcat"]
|
| 407 |
+
if note: cmd.extend(["--note", note])
|
| 408 |
+
|
| 409 |
+
for f in input_starch_files:
|
| 410 |
+
path = Path(f)
|
| 411 |
+
if not path.exists():
|
| 412 |
+
raise FileNotFoundError(f"Input file not found: {f}")
|
| 413 |
+
cmd.append(str(path.resolve()))
|
| 414 |
+
|
| 415 |
+
result = _run_command(cmd)
|
| 416 |
+
if result["status"] == "success":
|
| 417 |
+
with open(output_file, "w") as f:
|
| 418 |
+
f.write(result["stdout"])
|
| 419 |
+
result["output_files"] = [str(Path(output_file).resolve())]
|
| 420 |
+
return result
|
| 421 |
+
|
| 422 |
+
@mcp.tool()
|
| 423 |
+
def starchstrip(
|
| 424 |
+
starch_file: str,
|
| 425 |
+
output_file: str,
|
| 426 |
+
chromosomes: List[str]
|
| 427 |
+
):
|
| 428 |
+
"""
|
| 429 |
+
Filter a Starch archive to include only specific chromosomes.
|
| 430 |
+
|
| 431 |
+
Args:
|
| 432 |
+
starch_file: Input .starch file.
|
| 433 |
+
output_file: Path for the stripped starch archive.
|
| 434 |
+
chromosomes: List of chromosomes to keep.
|
| 435 |
+
"""
|
| 436 |
+
cmd = ["starchstrip"]
|
| 437 |
+
for c in chromosomes:
|
| 438 |
+
cmd.extend(["--chrom", c])
|
| 439 |
+
|
| 440 |
+
path = Path(starch_file)
|
| 441 |
+
if not path.exists():
|
| 442 |
+
raise FileNotFoundError(f"Starch file not found: {starch_file}")
|
| 443 |
+
cmd.append(str(path.resolve()))
|
| 444 |
+
|
| 445 |
+
result = _run_command(cmd)
|
| 446 |
+
if result["status"] == "success":
|
| 447 |
+
with open(output_file, "w") as f:
|
| 448 |
+
f.write(result["stdout"])
|
| 449 |
+
result["output_files"] = [str(Path(output_file).resolve())]
|
| 450 |
+
return result
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bedops/app/bedops_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_bedops/app/bedops_server.py')
|
| 11 |
+
SERVER_NAME = 'biosci_bedops'
|
| 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_bedops/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bedops/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-bedops:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-bedops:latest
|
| 7 |
+
container_name: mcp-bedops
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=bedops
|
| 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_bedops/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- bedops
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bedops/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bin2cell/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 bin2cell via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda bin2cell -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/bin2cell_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/bin2cell_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/bin2cell_server.py"]
|
| 40 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bin2cell/app/bin2cell_server.py
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
from typing import Optional, List
|
| 4 |
+
|
| 5 |
+
@mcp.tool()
|
| 6 |
+
def bin2cell_prepare_bins(
|
| 7 |
+
input_dir: str,
|
| 8 |
+
output_h5ad: str,
|
| 9 |
+
bin_size: int = 2,
|
| 10 |
+
destripe: bool = True,
|
| 11 |
+
):
|
| 12 |
+
"""
|
| 13 |
+
Reads Visium HD data from a SpaceRanger output directory and optionally performs destriping
|
| 14 |
+
to correct for technical effects in 2um bin data.
|
| 15 |
+
|
| 16 |
+
Args:
|
| 17 |
+
input_dir: Path to the SpaceRanger output directory (containing 'outs' folder).
|
| 18 |
+
output_h5ad: Path where the processed bin-level AnnData object will be saved.
|
| 19 |
+
bin_size: Resolution of bins to load (default is 2um).
|
| 20 |
+
destripe: Whether to apply the destriping correction for variable bin dimensions.
|
| 21 |
+
"""
|
| 22 |
+
# Input validation
|
| 23 |
+
input_path = Path(input_dir)
|
| 24 |
+
if not input_path.exists():
|
| 25 |
+
return {"error": f"Input directory {input_dir} does not exist."}
|
| 26 |
+
|
| 27 |
+
output_path = Path(output_h5ad)
|
| 28 |
+
if not output_path.parent.exists():
|
| 29 |
+
output_path.parent.mkdir(parents=True, exist_ok=True)
|
| 30 |
+
|
| 31 |
+
if bin_size <= 0:
|
| 32 |
+
return {"error": "bin_size must be a positive integer."}
|
| 33 |
+
|
| 34 |
+
# Construct Python command
|
| 35 |
+
# We use a python script string to execute the library functions
|
| 36 |
+
destripe_cmd = "b2c.pp.destripe(adata)" if destripe else "pass"
|
| 37 |
+
python_script = f"""
|
| 38 |
+
import bin2cell as b2c
|
| 39 |
+
import scanpy as sc
|
| 40 |
+
import os
|
| 41 |
+
|
| 42 |
+
try:
|
| 43 |
+
# Load Visium HD data
|
| 44 |
+
adata = b2c.pp.read_visium_hd_folder('{input_dir}', bin_size={bin_size})
|
| 45 |
+
|
| 46 |
+
# Perform destriping if requested
|
| 47 |
+
if {destripe}:
|
| 48 |
+
b2c.pp.destripe(adata)
|
| 49 |
+
|
| 50 |
+
# Save the result
|
| 51 |
+
adata.write('{output_h5ad}')
|
| 52 |
+
print("Successfully prepared bin data.")
|
| 53 |
+
except Exception as e:
|
| 54 |
+
print(f"Error: {{str(e)}}")
|
| 55 |
+
exit(1)
|
| 56 |
+
"""
|
| 57 |
+
|
| 58 |
+
try:
|
| 59 |
+
result = subprocess.run(
|
| 60 |
+
["python", "-c", python_script],
|
| 61 |
+
capture_output=True,
|
| 62 |
+
text=True,
|
| 63 |
+
check=True
|
| 64 |
+
)
|
| 65 |
+
return {
|
| 66 |
+
"command_executed": f"bin2cell.pp.read_visium_hd_folder and destripe={destripe}",
|
| 67 |
+
"stdout": result.stdout,
|
| 68 |
+
"stderr": result.stderr,
|
| 69 |
+
"output_files": [output_h5ad]
|
| 70 |
+
}
|
| 71 |
+
except subprocess.CalledProcessError as e:
|
| 72 |
+
return {
|
| 73 |
+
"error": "Failed to prepare bin data",
|
| 74 |
+
"stdout": e.stdout,
|
| 75 |
+
"stderr": e.stderr,
|
| 76 |
+
"command_executed": e.cmd
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
@mcp.tool()
|
| 80 |
+
def bin2cell_run_stardist(
|
| 81 |
+
image_path: str,
|
| 82 |
+
output_mask_path: str,
|
| 83 |
+
model_name: str = "2D_versatile_he",
|
| 84 |
+
prob_thresh: float = 0.5,
|
| 85 |
+
nms_thresh: float = 0.3,
|
| 86 |
+
):
|
| 87 |
+
"""
|
| 88 |
+
Performs cell segmentation on a morphology image using StarDist.
|
| 89 |
+
|
| 90 |
+
Args:
|
| 91 |
+
image_path: Path to the high-resolution morphology image (e.g., tissue_hires_image.png).
|
| 92 |
+
output_mask_path: Path where the resulting segmentation mask (.tif) will be saved.
|
| 93 |
+
model_name: StarDist model to use (default: '2D_versatile_he').
|
| 94 |
+
prob_thresh: Probability threshold for StarDist detection.
|
| 95 |
+
nms_thresh: Non-maximum suppression threshold for StarDist.
|
| 96 |
+
"""
|
| 97 |
+
# Input validation
|
| 98 |
+
img_path = Path(image_path)
|
| 99 |
+
if not img_path.exists():
|
| 100 |
+
return {"error": f"Image file {image_path} does not exist."}
|
| 101 |
+
|
| 102 |
+
out_mask = Path(output_mask_path)
|
| 103 |
+
if not out_mask.parent.exists():
|
| 104 |
+
out_mask.parent.mkdir(parents=True, exist_ok=True)
|
| 105 |
+
|
| 106 |
+
python_script = f"""
|
| 107 |
+
import bin2cell as b2c
|
| 108 |
+
import cv2
|
| 109 |
+
import numpy as np
|
| 110 |
+
|
| 111 |
+
try:
|
| 112 |
+
# Run StarDist segmentation via bin2cell wrapper
|
| 113 |
+
# Note: bin2cell.tl.stardist handles the model loading and prediction
|
| 114 |
+
b2c.tl.stardist(
|
| 115 |
+
'{image_path}',
|
| 116 |
+
'{output_mask_path}',
|
| 117 |
+
model='{model_name}',
|
| 118 |
+
prob_thresh={prob_thresh},
|
| 119 |
+
nms_thresh={nms_thresh}
|
| 120 |
+
)
|
| 121 |
+
print("Successfully generated segmentation mask.")
|
| 122 |
+
except Exception as e:
|
| 123 |
+
print(f"Error: {{str(e)}}")
|
| 124 |
+
exit(1)
|
| 125 |
+
"""
|
| 126 |
+
|
| 127 |
+
try:
|
| 128 |
+
result = subprocess.run(
|
| 129 |
+
["python", "-c", python_script],
|
| 130 |
+
capture_output=True,
|
| 131 |
+
text=True,
|
| 132 |
+
check=True
|
| 133 |
+
)
|
| 134 |
+
return {
|
| 135 |
+
"command_executed": f"bin2cell.tl.stardist on {image_path}",
|
| 136 |
+
"stdout": result.stdout,
|
| 137 |
+
"stderr": result.stderr,
|
| 138 |
+
"output_files": [output_mask_path]
|
| 139 |
+
}
|
| 140 |
+
except subprocess.CalledProcessError as e:
|
| 141 |
+
return {
|
| 142 |
+
"error": "StarDist segmentation failed",
|
| 143 |
+
"stdout": e.stdout,
|
| 144 |
+
"stderr": e.stderr,
|
| 145 |
+
"command_executed": e.cmd
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
@mcp.tool()
|
| 149 |
+
def bin2cell_extract_cells(
|
| 150 |
+
bin_h5ad_path: str,
|
| 151 |
+
mask_path: str,
|
| 152 |
+
output_cell_h5ad_path: str,
|
| 153 |
+
qc_metrics: bool = True,
|
| 154 |
+
):
|
| 155 |
+
"""
|
| 156 |
+
Groups subcellular bins into cells based on a segmentation mask and generates a cell-level AnnData object.
|
| 157 |
+
|
| 158 |
+
Args:
|
| 159 |
+
bin_h5ad_path: Path to the bin-level AnnData object (output from bin2cell_prepare_bins).
|
| 160 |
+
mask_path: Path to the segmentation mask file (output from bin2cell_run_stardist).
|
| 161 |
+
output_cell_h5ad_path: Path where the final cell-level AnnData object will be saved.
|
| 162 |
+
qc_metrics: Whether to calculate standard scanpy QC metrics for the new cell object.
|
| 163 |
+
"""
|
| 164 |
+
# Input validation
|
| 165 |
+
bin_path = Path(bin_h5ad_path)
|
| 166 |
+
if not bin_path.exists():
|
| 167 |
+
return {"error": f"Bin h5ad file {bin_h5ad_path} does not exist."}
|
| 168 |
+
|
| 169 |
+
m_path = Path(mask_path)
|
| 170 |
+
if not m_path.exists():
|
| 171 |
+
return {"error": f"Mask file {mask_path} does not exist."}
|
| 172 |
+
|
| 173 |
+
out_cell_path = Path(output_cell_h5ad_path)
|
| 174 |
+
if not out_cell_path.parent.exists():
|
| 175 |
+
out_cell_path.parent.mkdir(parents=True, exist_ok=True)
|
| 176 |
+
|
| 177 |
+
python_script = f"""
|
| 178 |
+
import bin2cell as b2c
|
| 179 |
+
import scanpy as sc
|
| 180 |
+
|
| 181 |
+
try:
|
| 182 |
+
# Load the bin-level data
|
| 183 |
+
adata_bins = sc.read_h5ad('{bin_h5ad_path}')
|
| 184 |
+
|
| 185 |
+
# Extract cells based on the mask
|
| 186 |
+
adata_cells = b2c.tl.extract_cells(adata_bins, '{mask_path}')
|
| 187 |
+
|
| 188 |
+
# Calculate QC metrics if requested
|
| 189 |
+
if {qc_metrics}:
|
| 190 |
+
sc.pp.calculate_qc_metrics(adata_cells, inplace=True)
|
| 191 |
+
|
| 192 |
+
# Save the cell-level object
|
| 193 |
+
adata_cells.write('{output_cell_h5ad_path}')
|
| 194 |
+
print("Successfully extracted cells from bins.")
|
| 195 |
+
except Exception as e:
|
| 196 |
+
print(f"Error: {{str(e)}}")
|
| 197 |
+
exit(1)
|
| 198 |
+
"""
|
| 199 |
+
|
| 200 |
+
try:
|
| 201 |
+
result = subprocess.run(
|
| 202 |
+
["python", "-c", python_script],
|
| 203 |
+
capture_output=True,
|
| 204 |
+
text=True,
|
| 205 |
+
check=True
|
| 206 |
+
)
|
| 207 |
+
return {
|
| 208 |
+
"command_executed": f"bin2cell.tl.extract_cells using mask {mask_path}",
|
| 209 |
+
"stdout": result.stdout,
|
| 210 |
+
"stderr": result.stderr,
|
| 211 |
+
"output_files": [output_cell_h5ad_path]
|
| 212 |
+
}
|
| 213 |
+
except subprocess.CalledProcessError as e:
|
| 214 |
+
return {
|
| 215 |
+
"error": "Cell extraction failed",
|
| 216 |
+
"stdout": e.stdout,
|
| 217 |
+
"stderr": e.stderr,
|
| 218 |
+
"command_executed": e.cmd
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
@mcp.tool()
|
| 222 |
+
def bin2cell_visualize_segmentation(
|
| 223 |
+
bin_h5ad_path: str,
|
| 224 |
+
output_image_path: str,
|
| 225 |
+
basis: str = "spatial",
|
| 226 |
+
):
|
| 227 |
+
"""
|
| 228 |
+
Generates a visualization of the bin-to-cell assignments.
|
| 229 |
+
|
| 230 |
+
Args:
|
| 231 |
+
bin_h5ad_path: Path to the bin-level AnnData object containing cell assignments.
|
| 232 |
+
output_image_path: Path to save the visualization plot (e.g., .png or .pdf).
|
| 233 |
+
basis: The coordinate system to use for plotting (default: 'spatial').
|
| 234 |
+
"""
|
| 235 |
+
bin_path = Path(bin_h5ad_path)
|
| 236 |
+
if not bin_path.exists():
|
| 237 |
+
return {"error": f"Bin h5ad file {bin_h5ad_path} does not exist."}
|
| 238 |
+
|
| 239 |
+
python_script = f"""
|
| 240 |
+
import scanpy as sc
|
| 241 |
+
import matplotlib.pyplot as plt
|
| 242 |
+
import bin2cell as b2c
|
| 243 |
+
|
| 244 |
+
try:
|
| 245 |
+
adata = sc.read_h5ad('{bin_h5ad_path}')
|
| 246 |
+
if 'cell_id' not in adata.obs.columns:
|
| 247 |
+
print("Error: cell_id not found in adata.obs. Run extract_cells first.")
|
| 248 |
+
exit(1)
|
| 249 |
+
|
| 250 |
+
# Plotting logic
|
| 251 |
+
sc.pl.embedding(adata, basis='{basis}', color='cell_id', show=False)
|
| 252 |
+
plt.savefig('{output_image_path}')
|
| 253 |
+
print("Successfully saved visualization.")
|
| 254 |
+
except Exception as e:
|
| 255 |
+
print(f"Error: {{str(e)}}")
|
| 256 |
+
exit(1)
|
| 257 |
+
"""
|
| 258 |
+
|
| 259 |
+
try:
|
| 260 |
+
result = subprocess.run(
|
| 261 |
+
["python", "-c", python_script],
|
| 262 |
+
capture_output=True,
|
| 263 |
+
text=True,
|
| 264 |
+
check=True
|
| 265 |
+
)
|
| 266 |
+
return {
|
| 267 |
+
"command_executed": f"Visualization of cell_id on {basis}",
|
| 268 |
+
"stdout": result.stdout,
|
| 269 |
+
"stderr": result.stderr,
|
| 270 |
+
"output_files": [output_image_path]
|
| 271 |
+
}
|
| 272 |
+
except subprocess.CalledProcessError as e:
|
| 273 |
+
return {
|
| 274 |
+
"error": "Visualization failed",
|
| 275 |
+
"stdout": e.stdout,
|
| 276 |
+
"stderr": e.stderr,
|
| 277 |
+
"command_executed": e.cmd
|
| 278 |
+
}
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bin2cell/app/bin2cell_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_bin2cell/app/bin2cell_server.py')
|
| 11 |
+
SERVER_NAME = 'biosci_bin2cell'
|
| 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_bin2cell/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bin2cell/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-bin2cell:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-bin2cell:latest
|
| 7 |
+
container_name: mcp-bin2cell
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=bin2cell
|
| 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_bin2cell/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- bin2cell
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bin2cell/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioawk/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 bioawk via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda bioawk -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/bioawk_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/bioawk_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/bioawk_server.py"]
|
| 40 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioawk/app/bioawk_server.py
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
from typing import Optional, List, Dict, Any
|
| 4 |
+
|
| 5 |
+
# @mcp.tool() is a placeholder for the actual decorator.
|
| 6 |
+
# The user prompt says "NO NEED to import mcp".
|
| 7 |
+
def tool(*args, **kwargs):
|
| 8 |
+
def decorator(f):
|
| 9 |
+
return f
|
| 10 |
+
return decorator
|
| 11 |
+
|
| 12 |
+
mcp = type("mcp", (), {"tool": tool})
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
@mcp.tool()
|
| 16 |
+
def bioawk(
|
| 17 |
+
program: Optional[str] = None,
|
| 18 |
+
program_file: Optional[Path] = None,
|
| 19 |
+
input_files: Optional[List[Path]] = None,
|
| 20 |
+
format: Optional[str] = None,
|
| 21 |
+
tab_separator: bool = False,
|
| 22 |
+
retain_header: bool = False,
|
| 23 |
+
variables: Optional[List[str]] = None,
|
| 24 |
+
field_separator: Optional[str] = None,
|
| 25 |
+
) -> Dict[str, Any]:
|
| 26 |
+
"""
|
| 27 |
+
Executes the bioawk tool, a variant of awk for processing biological data formats.
|
| 28 |
+
|
| 29 |
+
bioawk extends awk by understanding common bioinformatics formats, making it easy
|
| 30 |
+
to parse and manipulate files like FASTA, FASTQ, SAM, VCF, etc.
|
| 31 |
+
|
| 32 |
+
Args:
|
| 33 |
+
program: The awk program script to execute, provided as a string.
|
| 34 |
+
program_file: A file containing the awk program script.
|
| 35 |
+
Exactly one of 'program' or 'program_file' must be provided.
|
| 36 |
+
input_files: A list of input files to process. If not provided,
|
| 37 |
+
bioawk will read from standard input.
|
| 38 |
+
format: The format of the input data. Supported formats include:
|
| 39 |
+
fasta, fastq, sam, vcf, bed, gff, gtf, psl, blast, hmmer, cigar.
|
| 40 |
+
If not specified, bioawk defaults to 'fasta'.
|
| 41 |
+
tab_separator: Use tab as the input and output field separator (-t).
|
| 42 |
+
retain_header: Retain the header in the output (-H).
|
| 43 |
+
variables: A list of variable assignments in 'var=value' format (-v).
|
| 44 |
+
field_separator: The input field separator, equivalent to awk's -F option.
|
| 45 |
+
|
| 46 |
+
Returns:
|
| 47 |
+
A dictionary containing the executed command, stdout, and stderr.
|
| 48 |
+
"""
|
| 49 |
+
# 1. Input Validation
|
| 50 |
+
if not (program or program_file) or (program and program_file):
|
| 51 |
+
raise ValueError("Exactly one of 'program' or 'program_file' must be provided.")
|
| 52 |
+
|
| 53 |
+
if program_file and not program_file.is_file():
|
| 54 |
+
raise FileNotFoundError(f"Program file not found: {program_file}")
|
| 55 |
+
|
| 56 |
+
if input_files:
|
| 57 |
+
for file_path in input_files:
|
| 58 |
+
if not file_path.is_file():
|
| 59 |
+
raise FileNotFoundError(f"Input file not found: {file_path}")
|
| 60 |
+
|
| 61 |
+
VALID_FORMATS = {
|
| 62 |
+
"fasta", "fastq", "sam", "vcf", "bed", "gff",
|
| 63 |
+
"gtf", "psl", "blast", "hmmer", "cigar"
|
| 64 |
+
}
|
| 65 |
+
if format and format.lower() not in VALID_FORMATS:
|
| 66 |
+
raise ValueError(f"Invalid format '{format}'. Must be one of {VALID_FORMATS}")
|
| 67 |
+
|
| 68 |
+
if variables:
|
| 69 |
+
for var in variables:
|
| 70 |
+
if "=" not in var:
|
| 71 |
+
raise ValueError(f"Invalid variable assignment '{var}'. Must be in 'var=value' format.")
|
| 72 |
+
|
| 73 |
+
# 2. Command Construction
|
| 74 |
+
cmd = ["bioawk"]
|
| 75 |
+
|
| 76 |
+
if format:
|
| 77 |
+
cmd.extend(["-c", format])
|
| 78 |
+
if tab_separator:
|
| 79 |
+
cmd.append("-t")
|
| 80 |
+
if retain_header:
|
| 81 |
+
cmd.append("-H")
|
| 82 |
+
if field_separator:
|
| 83 |
+
cmd.extend(["-F", field_separator])
|
| 84 |
+
if variables:
|
| 85 |
+
for var in variables:
|
| 86 |
+
cmd.extend(["-v", var])
|
| 87 |
+
|
| 88 |
+
if program_file:
|
| 89 |
+
cmd.extend(["-f", str(program_file)])
|
| 90 |
+
elif program:
|
| 91 |
+
cmd.append(program)
|
| 92 |
+
|
| 93 |
+
if input_files:
|
| 94 |
+
cmd.extend([str(p) for p in input_files])
|
| 95 |
+
|
| 96 |
+
# 3. Subprocess Execution
|
| 97 |
+
command_executed = " ".join(cmd)
|
| 98 |
+
try:
|
| 99 |
+
result = subprocess.run(
|
| 100 |
+
cmd,
|
| 101 |
+
capture_output=True,
|
| 102 |
+
text=True,
|
| 103 |
+
check=True,
|
| 104 |
+
)
|
| 105 |
+
return {
|
| 106 |
+
"command_executed": command_executed,
|
| 107 |
+
"stdout": result.stdout,
|
| 108 |
+
"stderr": result.stderr,
|
| 109 |
+
}
|
| 110 |
+
except FileNotFoundError:
|
| 111 |
+
# This error is raised if the 'bioawk' command itself is not found.
|
| 112 |
+
raise RuntimeError("bioawk command not found. Please ensure it is installed and in your PATH.")
|
| 113 |
+
except subprocess.CalledProcessError as e:
|
| 114 |
+
# This error is raised if bioawk returns a non-zero exit code.
|
| 115 |
+
return {
|
| 116 |
+
"command_executed": command_executed,
|
| 117 |
+
"stdout": e.stdout,
|
| 118 |
+
"stderr": e.stderr,
|
| 119 |
+
"error": f"bioawk failed with exit code {e.returncode}"
|
| 120 |
+
}
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioawk/app/bioawk_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_bioawk/app/bioawk_server.py')
|
| 11 |
+
SERVER_NAME = 'biosci_bioawk'
|
| 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_bioawk/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioawk/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-bioawk:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-bioawk:latest
|
| 7 |
+
container_name: mcp-bioawk
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=bioawk
|
| 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_bioawk/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- bioawk
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioawk/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_biobambam/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 biobambam via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda biobambam -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/biobambam_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/biobambam_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/biobambam_server.py"]
|
| 40 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_biobambam/app/bi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ort(
|
| 7 |
+
input_file: str,
|
| 8 |
+
output_file: str,
|
| 9 |
+
memory_limit: str = "1G",
|
| 10 |
+
tmp_prefix: Optional[str] = None,
|
| 11 |
+
create_index: bool = False,
|
| 12 |
+
index_filename: Optional[str] = None,
|
| 13 |
+
sort_order: str = "coordinate",
|
| 14 |
+
threads: int = 1,
|
| 15 |
+
compression_level: int = 1,
|
| 16 |
+
recalculate_md_nm: bool = False,
|
| 17 |
+
reference_file: Optional[str] = None,
|
| 18 |
+
verbose: bool = False,
|
| 19 |
+
) -> dict:
|
| 20 |
+
"""
|
| 21 |
+
Sorts BAM files by coordinate or query name using bamsort.
|
| 22 |
+
|
| 23 |
+
Args:
|
| 24 |
+
input_file: Path to the input BAM file.
|
| 25 |
+
output_file: Path for the sorted output BAM file.
|
| 26 |
+
memory_limit: Main memory to use (e.g., '1G', '512M').
|
| 27 |
+
tmp_prefix: Temporary file prefix.
|
| 28 |
+
create_index: Whether to create an index for the output BAM file.
|
| 29 |
+
index_filename: Name for the index file.
|
| 30 |
+
sort_order: Sort order ('coordinate' or 'queryname').
|
| 31 |
+
threads: Number of threads to use.
|
| 32 |
+
compression_level: Compression level (0-9).
|
| 33 |
+
recalculate_md_nm: Recalculate MD and NM tags (requires reference).
|
| 34 |
+
reference_file: Reference FASTA file for MD/NM recalculation.
|
| 35 |
+
verbose: Enable verbose output.
|
| 36 |
+
"""
|
| 37 |
+
in_path = Path(input_file)
|
| 38 |
+
out_path = Path(output_file)
|
| 39 |
+
|
| 40 |
+
if not in_path.exists():
|
| 41 |
+
return {"error": f"Input file {input_file} does not exist"}
|
| 42 |
+
if sort_order not in ["coordinate", "queryname"]:
|
| 43 |
+
return {"error": "sort_order must be 'coordinate' or 'queryname'"}
|
| 44 |
+
if not (0 <= compression_level <= 9):
|
| 45 |
+
return {"error": "compression_level must be between 0 and 9"}
|
| 46 |
+
|
| 47 |
+
cmd = ["bamsort", f"I={input_file}", f"O={output_file}"]
|
| 48 |
+
cmd.append(f"M={memory_limit}")
|
| 49 |
+
cmd.append(f"sortorder={sort_order}")
|
| 50 |
+
cmd.append(f"threads={threads}")
|
| 51 |
+
cmd.append(f"level={compression_level}")
|
| 52 |
+
|
| 53 |
+
if tmp_prefix: cmd.append(f"T={tmp_prefix}")
|
| 54 |
+
if create_index: cmd.append("index=1")
|
| 55 |
+
if index_filename: cmd.append(f"indexfilename={index_filename}")
|
| 56 |
+
if recalculate_md_nm:
|
| 57 |
+
if not reference_file:
|
| 58 |
+
return {"error": "reference_file is required for recalculate_md_nm"}
|
| 59 |
+
cmd.append("calmd=1")
|
| 60 |
+
cmd.append(f"reference={reference_file}")
|
| 61 |
+
if verbose: cmd.append("verbose=1")
|
| 62 |
+
|
| 63 |
+
try:
|
| 64 |
+
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
| 65 |
+
return {
|
| 66 |
+
"command_executed": " ".join(cmd),
|
| 67 |
+
"stdout": result.stdout,
|
| 68 |
+
"stderr": result.stderr,
|
| 69 |
+
"output_files": [output_file]
|
| 70 |
+
}
|
| 71 |
+
except subprocess.CalledProcessError as e:
|
| 72 |
+
return {"error": e.stderr, "command_executed": " ".join(cmd), "return_code": e.returncode}
|
| 73 |
+
|
| 74 |
+
@mcp.tool()
|
| 75 |
+
def bammarkduplicates(
|
| 76 |
+
input_file: str,
|
| 77 |
+
output_file: str,
|
| 78 |
+
metrics_file: Optional[str] = None,
|
| 79 |
+
tmp_prefix: Optional[str] = None,
|
| 80 |
+
create_index: bool = False,
|
| 81 |
+
index_filename: Optional[str] = None,
|
| 82 |
+
remove_duplicates: bool = False,
|
| 83 |
+
compression_level: int = 1,
|
| 84 |
+
verbose: bool = False,
|
| 85 |
+
) -> dict:
|
| 86 |
+
"""
|
| 87 |
+
Marks or removes duplicate reads in a coordinate-sorted BAM file.
|
| 88 |
+
|
| 89 |
+
Args:
|
| 90 |
+
input_file: Input BAM file (must be coordinate sorted).
|
| 91 |
+
output_file: Output BAM file with duplicates marked.
|
| 92 |
+
metrics_file: Path for the output metrics file.
|
| 93 |
+
tmp_prefix: Temporary file prefix.
|
| 94 |
+
create_index: Create index for output BAM.
|
| 95 |
+
index_filename: Name for the index file.
|
| 96 |
+
remove_duplicates: Remove duplicate reads instead of marking.
|
| 97 |
+
compression_level: Compression level (0-9).
|
| 98 |
+
verbose: Enable verbose output.
|
| 99 |
+
"""
|
| 100 |
+
if not Path(input_file).exists():
|
| 101 |
+
return {"error": f"Input file {input_file} does not exist"}
|
| 102 |
+
|
| 103 |
+
cmd = ["bammarkduplicates", f"I={input_file}", f"O={output_file}"]
|
| 104 |
+
cmd.append(f"level={compression_level}")
|
| 105 |
+
|
| 106 |
+
if metrics_file: cmd.append(f"M={metrics_file}")
|
| 107 |
+
if tmp_prefix: cmd.append(f"T={tmp_prefix}")
|
| 108 |
+
if create_index: cmd.append("index=1")
|
| 109 |
+
if index_filename: cmd.append(f"indexfilename={index_filename}")
|
| 110 |
+
if remove_duplicates: cmd.append("rmdup=1")
|
| 111 |
+
if verbose: cmd.append("verbose=1")
|
| 112 |
+
|
| 113 |
+
try:
|
| 114 |
+
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
| 115 |
+
outputs = [output_file]
|
| 116 |
+
if metrics_file: outputs.append(metrics_file)
|
| 117 |
+
return {
|
| 118 |
+
"command_executed": " ".join(cmd),
|
| 119 |
+
"stdout": result.stdout,
|
| 120 |
+
"stderr": result.stderr,
|
| 121 |
+
"output_files": outputs
|
| 122 |
+
}
|
| 123 |
+
except subprocess.CalledProcessError as e:
|
| 124 |
+
return {"error": e.stderr, "command_executed": " ".join(cmd)}
|
| 125 |
+
|
| 126 |
+
@mcp.tool()
|
| 127 |
+
def bamsormadup(
|
| 128 |
+
input_file: str,
|
| 129 |
+
output_file: str,
|
| 130 |
+
tmp_prefix: Optional[str] = None,
|
| 131 |
+
memory_limit: str = "1G",
|
| 132 |
+
threads: int = 1,
|
| 133 |
+
compression_level: int = 1,
|
| 134 |
+
create_index: bool = False,
|
| 135 |
+
index_filename: Optional[str] = None,
|
| 136 |
+
remove_duplicates: bool = False,
|
| 137 |
+
verbose: bool = False,
|
| 138 |
+
) -> dict:
|
| 139 |
+
"""
|
| 140 |
+
Combined sorting and duplicate marking in a single pass.
|
| 141 |
+
|
| 142 |
+
Args:
|
| 143 |
+
input_file: Input BAM file.
|
| 144 |
+
output_file: Output BAM file.
|
| 145 |
+
tmp_prefix: Temporary file prefix.
|
| 146 |
+
memory_limit: Memory limit.
|
| 147 |
+
threads: Number of threads.
|
| 148 |
+
compression_level: Compression level (0-9).
|
| 149 |
+
create_index: Create index for output.
|
| 150 |
+
index_filename: Index filename.
|
| 151 |
+
remove_duplicates: Remove duplicates.
|
| 152 |
+
verbose: Enable verbose output.
|
| 153 |
+
"""
|
| 154 |
+
if not Path(input_file).exists():
|
| 155 |
+
return {"error": f"Input file {input_file} does not exist"}
|
| 156 |
+
|
| 157 |
+
cmd = ["bamsormadup", f"I={input_file}", f"O={output_file}"]
|
| 158 |
+
cmd.append(f"M={memory_limit}")
|
| 159 |
+
cmd.append(f"threads={threads}")
|
| 160 |
+
cmd.append(f"level={compression_level}")
|
| 161 |
+
|
| 162 |
+
if tmp_prefix: cmd.append(f"T={tmp_prefix}")
|
| 163 |
+
if create_index: cmd.append("index=1")
|
| 164 |
+
if index_filename: cmd.append(f"indexfilename={index_filename}")
|
| 165 |
+
if remove_duplicates: cmd.append("rmdup=1")
|
| 166 |
+
if verbose: cmd.append("verbose=1")
|
| 167 |
+
|
| 168 |
+
try:
|
| 169 |
+
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
| 170 |
+
return {
|
| 171 |
+
"command_executed": " ".join(cmd),
|
| 172 |
+
"stdout": result.stdout,
|
| 173 |
+
"stderr": result.stderr,
|
| 174 |
+
"output_files": [output_file]
|
| 175 |
+
}
|
| 176 |
+
except subprocess.CalledProcessError as e:
|
| 177 |
+
return {"error": e.stderr, "command_executed": " ".join(cmd)}
|
| 178 |
+
|
| 179 |
+
@mcp.tool()
|
| 180 |
+
def bamtofastq(
|
| 181 |
+
input_file: str,
|
| 182 |
+
fastq_1: str,
|
| 183 |
+
fastq_2: Optional[str] = None,
|
| 184 |
+
singles: Optional[str] = None,
|
| 185 |
+
orphans_1: Optional[str] = None,
|
| 186 |
+
orphans_2: Optional[str] = None,
|
| 187 |
+
collate: bool = False,
|
| 188 |
+
gzip: bool = False,
|
| 189 |
+
compression_level: int = 1,
|
| 190 |
+
reads_per_file: int = 0,
|
| 191 |
+
verbose: bool = False,
|
| 192 |
+
) -> dict:
|
| 193 |
+
"""
|
| 194 |
+
Converts BAM files to FASTQ format.
|
| 195 |
+
|
| 196 |
+
Args:
|
| 197 |
+
input_file: Input BAM file.
|
| 198 |
+
fastq_1: Output FASTQ file (Read 1).
|
| 199 |
+
fastq_2: Output FASTQ file (Read 2).
|
| 200 |
+
singles: Output FASTQ for single-end reads.
|
| 201 |
+
orphans_1: Output FASTQ for orphan Read 1.
|
| 202 |
+
orphans_2: Output FASTQ for orphan Read 2.
|
| 203 |
+
collate: Collate reads by name before conversion.
|
| 204 |
+
gzip: Compress output with gzip.
|
| 205 |
+
compression_level: Gzip compression level (1-9).
|
| 206 |
+
reads_per_file: Split output into files with N reads (0 = no split).
|
| 207 |
+
verbose: Enable verbose output.
|
| 208 |
+
"""
|
| 209 |
+
if not Path(input_file).exists():
|
| 210 |
+
return {"error": f"Input file {input_file} does not exist"}
|
| 211 |
+
|
| 212 |
+
cmd = ["bamtofastq", f"filename={input_file}", f"F={fastq_1}"]
|
| 213 |
+
outputs = [fastq_1]
|
| 214 |
+
|
| 215 |
+
if fastq_2:
|
| 216 |
+
cmd.append(f"F2={fastq_2}")
|
| 217 |
+
outputs.append(fastq_2)
|
| 218 |
+
if singles:
|
| 219 |
+
cmd.append(f"S={singles}")
|
| 220 |
+
outputs.append(singles)
|
| 221 |
+
if orphans_1:
|
| 222 |
+
cmd.append(f"O={orphans_1}")
|
| 223 |
+
outputs.append(orphans_1)
|
| 224 |
+
if orphans_2:
|
| 225 |
+
cmd.append(f"O2={orphans_2}")
|
| 226 |
+
outputs.append(orphans_2)
|
| 227 |
+
if collate: cmd.append("collate=1")
|
| 228 |
+
if gzip: cmd.append("gz=1")
|
| 229 |
+
if compression_level != 1: cmd.append(f"level={compression_level}")
|
| 230 |
+
if reads_per_file > 0: cmd.append(f"readsperfile={reads_per_file}")
|
| 231 |
+
if verbose: cmd.append("verbose=1")
|
| 232 |
+
|
| 233 |
+
try:
|
| 234 |
+
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
| 235 |
+
return {
|
| 236 |
+
"command_executed": " ".join(cmd),
|
| 237 |
+
"stdout": result.stdout,
|
| 238 |
+
"stderr": result.stderr,
|
| 239 |
+
"output_files": outputs
|
| 240 |
+
}
|
| 241 |
+
except subprocess.CalledProcessError as e:
|
| 242 |
+
return {"error": e.stderr, "command_executed": " ".join(cmd)}
|
| 243 |
+
|
| 244 |
+
@mcp.tool()
|
| 245 |
+
def bamcollate2(
|
| 246 |
+
input_file: str,
|
| 247 |
+
output_file: str,
|
| 248 |
+
tmp_prefix: Optional[str] = None,
|
| 249 |
+
compression_level: int = 1,
|
| 250 |
+
verbose: bool = False,
|
| 251 |
+
) -> dict:
|
| 252 |
+
"""
|
| 253 |
+
Collates a BAM file by read name.
|
| 254 |
+
|
| 255 |
+
Args:
|
| 256 |
+
input_file: Input BAM file.
|
| 257 |
+
output_file: Output collated BAM file.
|
| 258 |
+
tmp_prefix: Temporary file prefix.
|
| 259 |
+
compression_level: Compression level (0-9).
|
| 260 |
+
verbose: Enable verbose output.
|
| 261 |
+
"""
|
| 262 |
+
if not Path(input_file).exists():
|
| 263 |
+
return {"error": f"Input file {input_file} does not exist"}
|
| 264 |
+
|
| 265 |
+
cmd = ["bamcollate2", f"I={input_file}", f"O={output_file}"]
|
| 266 |
+
cmd.append(f"level={compression_level}")
|
| 267 |
+
if tmp_prefix: cmd.append(f"T={tmp_prefix}")
|
| 268 |
+
if verbose: cmd.append("verbose=1")
|
| 269 |
+
|
| 270 |
+
try:
|
| 271 |
+
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
| 272 |
+
return {
|
| 273 |
+
"command_executed": " ".join(cmd),
|
| 274 |
+
"stdout": result.stdout,
|
| 275 |
+
"stderr": result.stderr,
|
| 276 |
+
"output_files": [output_file]
|
| 277 |
+
}
|
| 278 |
+
except subprocess.CalledProcessError as e:
|
| 279 |
+
return {"error": e.stderr, "command_executed": " ".join(cmd)}
|
| 280 |
+
|
| 281 |
+
@mcp.tool()
|
| 282 |
+
def bamadapterclip(
|
| 283 |
+
input_file: str,
|
| 284 |
+
output_file: str,
|
| 285 |
+
threads: int = 1,
|
| 286 |
+
compression_level: int = 1,
|
| 287 |
+
verbose: bool = False,
|
| 288 |
+
) -> dict:
|
| 289 |
+
"""
|
| 290 |
+
Clips adapter sequences from reads in a BAM file.
|
| 291 |
+
|
| 292 |
+
Args:
|
| 293 |
+
input_file: Input BAM file.
|
| 294 |
+
output_file: Output clipped BAM file.
|
| 295 |
+
threads: Number of threads.
|
| 296 |
+
compression_level: Compression level (0-9).
|
| 297 |
+
verbose: Enable verbose output.
|
| 298 |
+
"""
|
| 299 |
+
if not Path(input_file).exists():
|
| 300 |
+
return {"error": f"Input file {input_file} does not exist"}
|
| 301 |
+
|
| 302 |
+
cmd = ["bamadapterclip", f"I={input_file}", f"O={output_file}"]
|
| 303 |
+
cmd.append(f"threads={threads}")
|
| 304 |
+
cmd.append(f"level={compression_level}")
|
| 305 |
+
if verbose: cmd.append("verbose=1")
|
| 306 |
+
|
| 307 |
+
try:
|
| 308 |
+
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
| 309 |
+
return {
|
| 310 |
+
"command_executed": " ".join(cmd),
|
| 311 |
+
"stdout": result.stdout,
|
| 312 |
+
"stderr": result.stderr,
|
| 313 |
+
"output_files": [output_file]
|
| 314 |
+
}
|
| 315 |
+
except subprocess.CalledProcessError as e:
|
| 316 |
+
return {"error": e.stderr, "command_executed": " ".join(cmd)}
|
| 317 |
+
|
| 318 |
+
@mcp.tool()
|
| 319 |
+
def bamreset(
|
| 320 |
+
input_file: str,
|
| 321 |
+
output_file: str,
|
| 322 |
+
compression_level: int = 1,
|
| 323 |
+
reset_flags: bool = False,
|
| 324 |
+
verbose: bool = False,
|
| 325 |
+
) -> dict:
|
| 326 |
+
"""
|
| 327 |
+
Resets alignment information in a BAM file.
|
| 328 |
+
|
| 329 |
+
Args:
|
| 330 |
+
input_file: Input BAM file.
|
| 331 |
+
output_file: Output reset BAM file.
|
| 332 |
+
compression_level: Compression level (0-9).
|
| 333 |
+
reset_flags: Reset flags to 0.
|
| 334 |
+
verbose: Enable verbose output.
|
| 335 |
+
"""
|
| 336 |
+
if not Path(input_file).exists():
|
| 337 |
+
return {"error": f"Input file {input_file} does not exist"}
|
| 338 |
+
|
| 339 |
+
cmd = ["bamreset", f"I={input_file}", f"O={output_file}"]
|
| 340 |
+
cmd.append(f"level={compression_level}")
|
| 341 |
+
if reset_flags: cmd.append("resetflags=1")
|
| 342 |
+
if verbose: cmd.append("verbose=1")
|
| 343 |
+
|
| 344 |
+
try:
|
| 345 |
+
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
| 346 |
+
return {
|
| 347 |
+
"command_executed": " ".join(cmd),
|
| 348 |
+
"stdout": result.stdout,
|
| 349 |
+
"stderr": result.stderr,
|
| 350 |
+
"output_files": [output_file]
|
| 351 |
+
}
|
| 352 |
+
except subprocess.CalledProcessError as e:
|
| 353 |
+
return {"error": e.stderr, "command_executed": " ".join(cmd)}
|
| 354 |
+
|
| 355 |
+
@mcp.tool()
|
| 356 |
+
def bamchecksort(
|
| 357 |
+
input_file: str,
|
| 358 |
+
verbose: bool = False,
|
| 359 |
+
) -> dict:
|
| 360 |
+
"""
|
| 361 |
+
Checks if a BAM file is sorted.
|
| 362 |
+
|
| 363 |
+
Args:
|
| 364 |
+
input_file: Input BAM file.
|
| 365 |
+
verbose: Enable verbose output.
|
| 366 |
+
"""
|
| 367 |
+
if not Path(input_file).exists():
|
| 368 |
+
return {"error": f"Input file {input_file} does not exist"}
|
| 369 |
+
|
| 370 |
+
cmd = ["bamchecksort", f"I={input_file}"]
|
| 371 |
+
if verbose: cmd.append("verbose=1")
|
| 372 |
+
|
| 373 |
+
try:
|
| 374 |
+
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
| 375 |
+
return {
|
| 376 |
+
"command_executed": " ".join(cmd),
|
| 377 |
+
"stdout": result.stdout,
|
| 378 |
+
"stderr": result.stderr,
|
| 379 |
+
"is_sorted": "sorted" in result.stdout.lower() or result.returncode == 0
|
| 380 |
+
}
|
| 381 |
+
except subprocess.CalledProcessError as e:
|
| 382 |
+
return {"error": e.stderr, "command_executed": " ".join(cmd), "is_sorted": False}
|
| 383 |
+
|
| 384 |
+
@mcp.tool()
|
| 385 |
+
def bamrecompress(
|
| 386 |
+
input_file: str,
|
| 387 |
+
output_file: str,
|
| 388 |
+
compression_level: int = 1,
|
| 389 |
+
threads: int = 1,
|
| 390 |
+
verbose: bool = False,
|
| 391 |
+
) -> dict:
|
| 392 |
+
"""
|
| 393 |
+
Recompresses a BAM file.
|
| 394 |
+
|
| 395 |
+
Args:
|
| 396 |
+
input_file: Input BAM file.
|
| 397 |
+
output_file: Output recompressed BAM file.
|
| 398 |
+
compression_level: Compression level (0-9).
|
| 399 |
+
threads: Number of threads.
|
| 400 |
+
verbose: Enable verbose output.
|
| 401 |
+
"""
|
| 402 |
+
if not Path(input_file).exists():
|
| 403 |
+
return {"error": f"Input file {input_file} does not exist"}
|
| 404 |
+
|
| 405 |
+
cmd = ["bamrecompress", f"I={input_file}", f"O={output_file}"]
|
| 406 |
+
cmd.append(f"level={compression_level}")
|
| 407 |
+
cmd.append(f"threads={threads}")
|
| 408 |
+
if verbose: cmd.append("verbose=1")
|
| 409 |
+
|
| 410 |
+
try:
|
| 411 |
+
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
| 412 |
+
return {
|
| 413 |
+
"command_executed": " ".join(cmd),
|
| 414 |
+
"stdout": result.stdout,
|
| 415 |
+
"stderr": result.stderr,
|
| 416 |
+
"output_files": [output_file]
|
| 417 |
+
}
|
| 418 |
+
except subprocess.CalledProcessError as e:
|
| 419 |
+
return {"error": e.stderr, "command_executed": " ".join(cmd)}
|
| 420 |
+
|
| 421 |
+
@mcp.tool()
|
| 422 |
+
def bamfilterrg(
|
| 423 |
+
input_file: str,
|
| 424 |
+
output_file: str,
|
| 425 |
+
read_group: str,
|
| 426 |
+
compression_level: int = 1,
|
| 427 |
+
verbose: bool = False,
|
| 428 |
+
) -> dict:
|
| 429 |
+
"""
|
| 430 |
+
Filters a BAM file by read group.
|
| 431 |
+
|
| 432 |
+
Args:
|
| 433 |
+
input_file: Input BAM file.
|
| 434 |
+
output_file: Output filtered BAM file.
|
| 435 |
+
read_group: Read group ID to keep.
|
| 436 |
+
compression_level: Compression level (0-9).
|
| 437 |
+
verbose: Enable verbose output.
|
| 438 |
+
"""
|
| 439 |
+
if not Path(input_file).exists():
|
| 440 |
+
return {"error": f"Input file {input_file} does not exist"}
|
| 441 |
+
|
| 442 |
+
cmd = ["bamfilterrg", f"I={input_file}", f"O={output_file}", f"rg={read_group}"]
|
| 443 |
+
cmd.append(f"level={compression_level}")
|
| 444 |
+
if verbose: cmd.append("verbose=1")
|
| 445 |
+
|
| 446 |
+
try:
|
| 447 |
+
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
| 448 |
+
return {
|
| 449 |
+
"command_executed": " ".join(cmd),
|
| 450 |
+
"stdout": result.stdout,
|
| 451 |
+
"stderr": result.stderr,
|
| 452 |
+
"output_files": [output_file]
|
| 453 |
+
}
|
| 454 |
+
except subprocess.CalledProcessError as e:
|
| 455 |
+
return {"error": e.stderr, "command_executed": " ".join(cmd)}
|
| 456 |
+
|
| 457 |
+
@mcp.tool()
|
| 458 |
+
def bamfillquery(
|
| 459 |
+
input_file: str,
|
| 460 |
+
output_file: str,
|
| 461 |
+
compression_level: int = 1,
|
| 462 |
+
verbose: bool = False,
|
| 463 |
+
) -> dict:
|
| 464 |
+
"""
|
| 465 |
+
Fills query information in a BAM file.
|
| 466 |
+
|
| 467 |
+
Args:
|
| 468 |
+
input_file: Input BAM file.
|
| 469 |
+
output_file: Output BAM file.
|
| 470 |
+
compression_level: Compression level (0-9).
|
| 471 |
+
verbose: Enable verbose output.
|
| 472 |
+
"""
|
| 473 |
+
if not Path(input_file).exists():
|
| 474 |
+
return {"error": f"Input file {input_file} does not exist"}
|
| 475 |
+
|
| 476 |
+
cmd = ["bamfillquery", f"I={input_file}", f"O={output_file}"]
|
| 477 |
+
cmd.append(f"level={compression_level}")
|
| 478 |
+
if verbose: cmd.append("verbose=1")
|
| 479 |
+
|
| 480 |
+
try:
|
| 481 |
+
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
| 482 |
+
return {
|
| 483 |
+
"command_executed": " ".join(cmd),
|
| 484 |
+
"stdout": result.stdout,
|
| 485 |
+
"stderr": result.stderr,
|
| 486 |
+
"output_files": [output_file]
|
| 487 |
+
}
|
| 488 |
+
except subprocess.CalledProcessError as e:
|
| 489 |
+
return {"error": e.stderr, "command_executed": " ".join(cmd)}
|