czty commited on
Commit
a1932cc
·
verified ·
1 Parent(s): 67d0c1d

BioOcto code and data release (snapshot 2026-11-27, resumed) (part 29)

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. Biomni/mcp_generated/mcp_bioconductor-scfeatures/app/requirements.txt +1 -0
  2. Biomni/mcp_generated/mcp_bioconductor-scfeatures/docker-compose.yml +22 -0
  3. Biomni/mcp_generated/mcp_bioconductor-scfeatures/environment.yaml +10 -0
  4. Biomni/mcp_generated/mcp_bioconductor-scfeatures/requirements.txt +2 -0
  5. Biomni/mcp_generated/mcp_bioconductor-scider/Dockerfile +40 -0
  6. Biomni/mcp_generated/mcp_bioconductor-scider/app/bioconductor-scider_server.py +465 -0
  7. Biomni/mcp_generated/mcp_bioconductor-scider/app/bioconductor-scider_shim_server.py +55 -0
  8. Biomni/mcp_generated/mcp_bioconductor-scider/app/requirements.txt +1 -0
  9. Biomni/mcp_generated/mcp_bioconductor-scider/docker-compose.yml +22 -0
  10. Biomni/mcp_generated/mcp_bioconductor-scider/environment.yaml +10 -0
  11. Biomni/mcp_generated/mcp_bioconductor-scider/requirements.txt +2 -0
  12. Biomni/mcp_generated/mcp_bioconductor-scmageck/Dockerfile +40 -0
  13. Biomni/mcp_generated/mcp_bioconductor-scmageck/app/bioconductor-scmageck_server.py +277 -0
  14. Biomni/mcp_generated/mcp_bioconductor-scmageck/app/bioconductor-scmageck_shim_server.py +55 -0
  15. Biomni/mcp_generated/mcp_bioconductor-scmageck/docker-compose.yml +22 -0
  16. Biomni/mcp_generated/mcp_bioconductor-scmageck/environment.yaml +10 -0
  17. Biomni/mcp_generated/mcp_bioconductor-scmageck/requirements.txt +2 -0
  18. Biomni/mcp_generated/mcp_bioconductor-scqtltools/Dockerfile +40 -0
  19. Biomni/mcp_generated/mcp_bioconductor-scqtltools/app/bioconductor-scqtltools_server.py +187 -0
  20. Biomni/mcp_generated/mcp_bioconductor-scqtltools/app/bioconductor-scqtltools_shim_server.py +55 -0
  21. Biomni/mcp_generated/mcp_bioconductor-scqtltools/app/requirements.txt +1 -0
  22. Biomni/mcp_generated/mcp_bioconductor-scqtltools/docker-compose.yml +22 -0
  23. Biomni/mcp_generated/mcp_bioconductor-scqtltools/environment.yaml +10 -0
  24. Biomni/mcp_generated/mcp_bioconductor-scqtltools/requirements.txt +2 -0
  25. Biomni/mcp_generated/mcp_bioconductor-scran/Dockerfile +40 -0
  26. Biomni/mcp_generated/mcp_bioconductor-scran/app/bioconductor-scran_server.py +115 -0
  27. Biomni/mcp_generated/mcp_bioconductor-scran/app/bioconductor-scran_shim_server.py +55 -0
  28. Biomni/mcp_generated/mcp_bioconductor-scran/app/requirements.txt +1 -0
  29. Biomni/mcp_generated/mcp_bioconductor-scran/docker-compose.yml +22 -0
  30. Biomni/mcp_generated/mcp_bioconductor-scran/environment.yaml +10 -0
  31. Biomni/mcp_generated/mcp_bioconductor-scran/requirements.txt +2 -0
  32. Biomni/mcp_generated/mcp_bioconductor-screpertoire/Dockerfile +40 -0
  33. Biomni/mcp_generated/mcp_bioconductor-screpertoire/app/bioconductor-screpertoire_server.py +124 -0
  34. Biomni/mcp_generated/mcp_bioconductor-screpertoire/app/bioconductor-screpertoire_shim_server.py +55 -0
  35. Biomni/mcp_generated/mcp_bioconductor-screpertoire/docker-compose.yml +22 -0
  36. Biomni/mcp_generated/mcp_bioconductor-screpertoire/environment.yaml +10 -0
  37. Biomni/mcp_generated/mcp_bioconductor-screpertoire/requirements.txt +2 -0
  38. Biomni/mcp_generated/mcp_bioconductor-scrnaseq/Dockerfile +40 -0
  39. Biomni/mcp_generated/mcp_bioconductor-scrnaseq/app/bioconductor-scrnaseq_server.py +124 -0
  40. Biomni/mcp_generated/mcp_bioconductor-scrnaseq/app/bioconductor-scrnaseq_shim_server.py +55 -0
  41. Biomni/mcp_generated/mcp_bioconductor-scrnaseq/docker-compose.yml +22 -0
  42. Biomni/mcp_generated/mcp_bioconductor-scrnaseq/environment.yaml +10 -0
  43. Biomni/mcp_generated/mcp_bioconductor-scrnaseq/requirements.txt +2 -0
  44. Biomni/mcp_generated/mcp_bioconductor-sctreeviz/Dockerfile +40 -0
  45. Biomni/mcp_generated/mcp_bioconductor-sctreeviz/app/bioconductor-sctreeviz_server.py +230 -0
  46. Biomni/mcp_generated/mcp_bioconductor-sctreeviz/app/bioconductor-sctreeviz_shim_server.py +55 -0
  47. Biomni/mcp_generated/mcp_bioconductor-sctreeviz/app/requirements.txt +1 -0
  48. Biomni/mcp_generated/mcp_bioconductor-sctreeviz/docker-compose.yml +22 -0
  49. Biomni/mcp_generated/mcp_bioconductor-sctreeviz/environment.yaml +10 -0
  50. Biomni/mcp_generated/mcp_bioconductor-sctreeviz/requirements.txt +2 -0
Biomni/mcp_generated/mcp_bioconductor-scfeatures/app/requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+
Biomni/mcp_generated/mcp_bioconductor-scfeatures/docker-compose.yml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version: '3.8'
2
+
3
+ services:
4
+ mcp-bioconductor-scfeatures:
5
+ build: .
6
+ image: mcp-bioconductor-scfeatures:latest
7
+ container_name: mcp-bioconductor-scfeatures
8
+ ports:
9
+ - "8000:8000"
10
+ environment:
11
+ - MCP_SERVER_NAME=bioconductor-scfeatures
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
+
Biomni/mcp_generated/mcp_bioconductor-scfeatures/environment.yaml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ name: mcp-tool
3
+ channels:
4
+ - bioconda
5
+ - conda-forge
6
+ - defaults
7
+ dependencies:
8
+ - bioconductor-scfeatures
9
+ - python=3.10
10
+
Biomni/mcp_generated/mcp_bioconductor-scfeatures/requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ fastmcp
2
+ mcp
Biomni/mcp_generated/mcp_bioconductor-scider/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 bioconductor-scider via conda (e.g., from bioconda)
14
+ RUN conda install -c bioconda bioconductor-scider -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/bioconductor-scider_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/bioconductor-scider_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/bioconductor-scider_server.py"]
40
+
Biomni/mcp_generated/mcp_bioconductor-scider/app/bioconductor-scider_server.py ADDED
@@ -0,0 +1,465 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import subprocess
2
+ import tempfile
3
+ from pathlib import Path
4
+ from typing import Literal, Optional
5
+
6
+ # It is assumed that the mcp package is installed and its decorator is available.
7
+ # from mcp import tool as mcp_tool
8
+ # For the purpose of this example, we will use a dummy decorator.
9
+ class mcp:
10
+ def tool(func):
11
+ return func
12
+
13
+ TEST_USE_METHODS = Literal[
14
+ "wilcox", "bimod", "roc", "t", "negbinom", "poisson", "LR", "MAST", "DESeq2"
15
+ ]
16
+
17
+ def _execute_r_script(r_script_content: str, command_name: str) -> dict:
18
+ """
19
+ A helper function to execute an R script using a temporary file.
20
+
21
+ Args:
22
+ r_script_content: A string containing the R code to execute.
23
+ command_name: The name of the scider function being called, for error reporting.
24
+
25
+ Returns:
26
+ A dictionary containing the execution results.
27
+ """
28
+ try:
29
+ with tempfile.NamedTemporaryFile(
30
+ mode="w", suffix=".R", delete=False
31
+ ) as r_script_file:
32
+ r_script_path = Path(r_script_file.name)
33
+ r_script_file.write(r_script_content)
34
+
35
+ command = ["Rscript", str(r_script_path)]
36
+ process = subprocess.run(
37
+ command, capture_output=True, text=True, check=True
38
+ )
39
+
40
+ return {
41
+ "command_executed": " ".join(command),
42
+ "stdout": process.stdout,
43
+ "stderr": process.stderr,
44
+ }
45
+ except FileNotFoundError:
46
+ return {
47
+ "command_executed": " ".join(command) if 'command' in locals() else "Rscript not found",
48
+ "stdout": "",
49
+ "stderr": "Rscript not found. Please ensure R and Rscript are in your system's PATH.",
50
+ "error": "Prerequisite not met."
51
+ }
52
+ except subprocess.CalledProcessError as e:
53
+ return {
54
+ "command_executed": " ".join(e.cmd),
55
+ "stdout": e.stdout,
56
+ "stderr": e.stderr,
57
+ "error": f"R script execution failed for {command_name}.",
58
+ "return_code": e.returncode,
59
+ }
60
+ finally:
61
+ if "r_script_path" in locals() and r_script_path.exists():
62
+ r_script_path.unlink()
63
+
64
+
65
+ @mcp.tool
66
+ def recluster(
67
+ input_rds: Path,
68
+ output_rds: Path,
69
+ recluster_method: Literal["Default", "SNN", "hclust"] = "Default",
70
+ resolution: float = 0.5,
71
+ num_pc: int = 10,
72
+ ):
73
+ """
74
+ Re-clusters a Seurat object using methods from the scider package.
75
+
76
+ Args:
77
+ input_rds: Path to the input Seurat object saved as an RDS file.
78
+ output_rds: Path to save the re-clustered Seurat object as an RDS file.
79
+ recluster_method: Method to use for reclustering.
80
+ resolution: Resolution parameter for clustering.
81
+ num_pc: Number of principal components to use.
82
+ """
83
+ if not input_rds.is_file():
84
+ raise FileNotFoundError(f"Input file not found: {input_rds}")
85
+
86
+ output_rds.parent.mkdir(parents=True, exist_ok=True)
87
+
88
+ r_script = f"""
89
+ library(scider)
90
+ library(Seurat)
91
+
92
+ seurat_object <- readRDS("{input_rds.resolve()}")
93
+
94
+ updated_object <- recluster(
95
+ object = seurat_object,
96
+ recluster_method = "{recluster_method}",
97
+ resolution = {resolution},
98
+ num_pc = {num_pc}
99
+ )
100
+
101
+ saveRDS(updated_object, file = "{output_rds.resolve()}")
102
+ print("Reclustering completed successfully.")
103
+ """
104
+
105
+ result = _execute_r_script(r_script, "recluster")
106
+ if "error" not in result:
107
+ result["output_files"] = [str(output_rds.resolve())]
108
+ return result
109
+
110
+
111
+ @mcp.tool
112
+ def find_isc(
113
+ input_rds: Path,
114
+ output_rds: Path,
115
+ species: Literal["human", "mouse"] = "human",
116
+ tissue: str = "Default",
117
+ isc_genes_default: str = "Default",
118
+ isc_genes_user: Optional[Path] = None,
119
+ isc_method: Literal["Default", "Average"] = "Default",
120
+ isc_threshold: float = 0.5,
121
+ assay: str = "RNA",
122
+ slot: str = "data",
123
+ ):
124
+ """
125
+ Calculates the In-Situ Co-expression (ISC) score for a Seurat object.
126
+
127
+ Args:
128
+ input_rds: Path to the input Seurat object saved as an RDS file.
129
+ output_rds: Path to save the updated Seurat object as an RDS file.
130
+ species: Species of the sample ('human' or 'mouse').
131
+ tissue: Tissue type for default gene lists.
132
+ isc_genes_default: Default ISC gene list to use.
133
+ isc_genes_user: Path to a file with a user-provided list of ISC genes.
134
+ isc_method: Method for ISC calculation.
135
+ isc_threshold: Threshold for ISC score.
136
+ assay: Assay to use from the Seurat object.
137
+ slot: Slot to use from the assay.
138
+ """
139
+ if not input_rds.is_file():
140
+ raise FileNotFoundError(f"Input file not found: {input_rds}")
141
+ if isc_genes_user and not isc_genes_user.is_file():
142
+ raise FileNotFoundError(f"User ISC genes file not found: {isc_genes_user}")
143
+
144
+ output_rds.parent.mkdir(parents=True, exist_ok=True)
145
+
146
+ isc_genes_user_r = f"'{isc_genes_user.resolve()}'" if isc_genes_user else "NULL"
147
+
148
+ r_script = f"""
149
+ library(scider)
150
+ library(Seurat)
151
+
152
+ seurat_object <- readRDS("{input_rds.resolve()}")
153
+
154
+ updated_object <- findISC(
155
+ object = seurat_object,
156
+ species = "{species}",
157
+ tissue = "{tissue}",
158
+ ISC_genes_default = "{isc_genes_default}",
159
+ ISC_genes_user = {isc_genes_user_r},
160
+ ISC_method = "{isc_method}",
161
+ ISC_threshold = {isc_threshold},
162
+ assay = "{assay}",
163
+ slot = "{slot}"
164
+ )
165
+
166
+ saveRDS(updated_object, file = "{output_rds.resolve()}")
167
+ print("ISC calculation completed successfully.")
168
+ """
169
+
170
+ result = _execute_r_script(r_script, "findISC")
171
+ if "error" not in result:
172
+ result["output_files"] = [str(output_rds.resolve())]
173
+ return result
174
+
175
+
176
+ @mcp.tool
177
+ def find_de_genes(
178
+ input_rds: Path,
179
+ output_rds: Path,
180
+ logfc_threshold: float = 0.25,
181
+ test_use: TEST_USE_METHODS = "wilcox",
182
+ min_pct: float = 0.1,
183
+ min_diff_pct: Optional[float] = None,
184
+ only_pos: bool = False,
185
+ max_cells_per_ident: Optional[int] = None,
186
+ random_seed: int = 1,
187
+ min_cells_group: int = 3,
188
+ pseudocount_use: int = 1,
189
+ verbose: bool = True,
190
+ assay: str = "RNA",
191
+ slot: str = "data",
192
+ ):
193
+ """
194
+ Finds differentially expressed (DE) genes between cell clusters.
195
+
196
+ Args:
197
+ input_rds: Path to the input Seurat object saved as an RDS file.
198
+ output_rds: Path to save the updated Seurat object as an RDS file.
199
+ logfc_threshold: Log-fold change threshold.
200
+ test_use: Statistical test to use.
201
+ min_pct: Minimum percentage of cells expressing the gene in either group.
202
+ min_diff_pct: Minimum percentage difference between the two groups. Defaults to -Inf.
203
+ only_pos: Only return positive markers.
204
+ max_cells_per_ident: Max cells per identity to subsample. Defaults to Inf.
205
+ random_seed: Random seed for reproducibility.
206
+ min_cells_group: Minimum number of cells in a group.
207
+ pseudocount_use: Pseudocount to add to averaged expression values.
208
+ verbose: Print progress and informational messages.
209
+ assay: Assay to use from the Seurat object.
210
+ slot: Slot to use from the assay.
211
+ """
212
+ if not input_rds.is_file():
213
+ raise FileNotFoundError(f"Input file not found: {input_rds}")
214
+
215
+ output_rds.parent.mkdir(parents=True, exist_ok=True)
216
+
217
+ min_diff_pct_r = str(min_diff_pct) if min_diff_pct is not None else "-Inf"
218
+ max_cells_per_ident_r = (
219
+ str(max_cells_per_ident) if max_cells_per_ident is not None else "Inf"
220
+ )
221
+
222
+ r_script = f"""
223
+ library(scider)
224
+ library(Seurat)
225
+
226
+ seurat_object <- readRDS("{input_rds.resolve()}")
227
+
228
+ updated_object <- findDEgenes(
229
+ object = seurat_object,
230
+ logfc.threshold = {logfc_threshold},
231
+ test.use = "{test_use}",
232
+ min.pct = {min_pct},
233
+ min.diff.pct = {min_diff_pct_r},
234
+ only.pos = {str(only_pos).upper()},
235
+ max.cells.per.ident = {max_cells_per_ident_r},
236
+ random.seed = {random_seed},
237
+ min.cells.group = {min_cells_group},
238
+ pseudocount.use = {pseudocount_use},
239
+ verbose = {str(verbose).upper()},
240
+ assay = "{assay}",
241
+ slot = "{slot}"
242
+ )
243
+
244
+ saveRDS(updated_object, file = "{output_rds.resolve()}")
245
+ print("DE gene analysis completed successfully.")
246
+ """
247
+
248
+ result = _execute_r_script(r_script, "findDEgenes")
249
+ if "error" not in result:
250
+ result["output_files"] = [str(output_rds.resolve())]
251
+ return result
252
+
253
+
254
+ @mcp.tool
255
+ def find_dr_genes(
256
+ input_rds: Path,
257
+ output_rds: Path,
258
+ logfc_threshold: float = 0.25,
259
+ test_use: TEST_USE_METHODS = "wilcox",
260
+ min_pct: float = 0.1,
261
+ min_diff_pct: Optional[float] = None,
262
+ only_pos: bool = False,
263
+ max_cells_per_ident: Optional[int] = None,
264
+ random_seed: int = 1,
265
+ min_cells_group: int = 3,
266
+ pseudocount_use: int = 1,
267
+ verbose: bool = True,
268
+ assay: str = "RNA",
269
+ slot: str = "data",
270
+ ):
271
+ """
272
+ Finds differentially regulated (DR) genes between cell clusters.
273
+
274
+ Args:
275
+ input_rds: Path to the input Seurat object saved as an RDS file.
276
+ output_rds: Path to save the updated Seurat object as an RDS file.
277
+ logfc_threshold: Log-fold change threshold.
278
+ test_use: Statistical test to use.
279
+ min_pct: Minimum percentage of cells expressing the gene in either group.
280
+ min_diff_pct: Minimum percentage difference between the two groups. Defaults to -Inf.
281
+ only_pos: Only return positive markers.
282
+ max_cells_per_ident: Max cells per identity to subsample. Defaults to Inf.
283
+ random_seed: Random seed for reproducibility.
284
+ min_cells_group: Minimum number of cells in a group.
285
+ pseudocount_use: Pseudocount to add to averaged expression values.
286
+ verbose: Print progress and informational messages.
287
+ assay: Assay to use from the Seurat object.
288
+ slot: Slot to use from the assay.
289
+ """
290
+ if not input_rds.is_file():
291
+ raise FileNotFoundError(f"Input file not found: {input_rds}")
292
+
293
+ output_rds.parent.mkdir(parents=True, exist_ok=True)
294
+
295
+ min_diff_pct_r = str(min_diff_pct) if min_diff_pct is not None else "-Inf"
296
+ max_cells_per_ident_r = (
297
+ str(max_cells_per_ident) if max_cells_per_ident is not None else "Inf"
298
+ )
299
+
300
+ r_script = f"""
301
+ library(scider)
302
+ library(Seurat)
303
+
304
+ seurat_object <- readRDS("{input_rds.resolve()}")
305
+
306
+ updated_object <- findDRgenes(
307
+ object = seurat_object,
308
+ logfc.threshold = {logfc_threshold},
309
+ test.use = "{test_use}",
310
+ min.pct = {min_pct},
311
+ min.diff.pct = {min_diff_pct_r},
312
+ only.pos = {str(only_pos).upper()},
313
+ max.cells.per.ident = {max_cells_per_ident_r},
314
+ random.seed = {random_seed},
315
+ min.cells.group = {min_cells_group},
316
+ pseudocount.use = {pseudocount_use},
317
+ verbose = {str(verbose).upper()},
318
+ assay = "{assay}",
319
+ slot = "{slot}"
320
+ )
321
+
322
+ saveRDS(updated_object, file = "{output_rds.resolve()}")
323
+ print("DR gene analysis completed successfully.")
324
+ """
325
+
326
+ result = _execute_r_script(r_script, "findDRgenes")
327
+ if "error" not in result:
328
+ result["output_files"] = [str(output_rds.resolve())]
329
+ return result
330
+
331
+
332
+ @mcp.tool
333
+ def run_scider(
334
+ input_rds: Path,
335
+ output_dir: Path,
336
+ project: str = "scider",
337
+ method: Literal["DE", "DR", "ISC"] = "DE",
338
+ de_method: TEST_USE_METHODS = "wilcox",
339
+ dr_method: TEST_USE_METHODS = "wilcox",
340
+ logfc_threshold: float = 0.25,
341
+ test_use: TEST_USE_METHODS = "wilcox",
342
+ min_pct: float = 0.1,
343
+ min_diff_pct: Optional[float] = None,
344
+ return_thresh: float = 0.01,
345
+ only_pos: bool = False,
346
+ max_cells_per_ident: Optional[int] = None,
347
+ random_seed: int = 1,
348
+ min_cells_group: int = 3,
349
+ pseudocount_use: int = 1,
350
+ verbose: bool = True,
351
+ assay: str = "RNA",
352
+ slot: str = "data",
353
+ isc_method: Literal["Default", "Average"] = "Default",
354
+ isc_threshold: float = 0.5,
355
+ recluster_method: Literal["Default", "SNN", "hclust"] = "Default",
356
+ resolution: float = 0.5,
357
+ num_pc: int = 10,
358
+ species: Literal["human", "mouse"] = "human",
359
+ tissue: str = "Default",
360
+ isc_genes_default: str = "Default",
361
+ isc_genes_user: Optional[Path] = None,
362
+ marker_genes_default: str = "Default",
363
+ marker_genes_user: Optional[Path] = None,
364
+ ):
365
+ """
366
+ Run the main scider pipeline for cell type identification.
367
+
368
+ Args:
369
+ input_rds: Path to the input Seurat object saved as an RDS file.
370
+ output_dir: Directory to save the output files.
371
+ project: Name for the project.
372
+ method: Main analysis method to run ('DE', 'DR', or 'ISC').
373
+ de_method: Test to use for DE analysis.
374
+ dr_method: Test to use for DR analysis.
375
+ logfc_threshold: Log-fold change threshold.
376
+ test_use: Statistical test to use (often same as de_method).
377
+ min_pct: Minimum percentage of cells expressing a gene.
378
+ min_diff_pct: Minimum percentage difference. Defaults to -Inf.
379
+ return_thresh: P-value threshold for returning genes.
380
+ only_pos: Only return positive markers.
381
+ max_cells_per_ident: Max cells to subsample. Defaults to Inf.
382
+ random_seed: Random seed for reproducibility.
383
+ min_cells_group: Minimum number of cells in a group.
384
+ pseudocount_use: Pseudocount for expression averaging.
385
+ verbose: Print progress messages.
386
+ assay: Assay to use from the Seurat object.
387
+ slot: Slot to use from the assay.
388
+ isc_method: Method for ISC calculation.
389
+ isc_threshold: Threshold for ISC score.
390
+ recluster_method: Method for reclustering.
391
+ resolution: Resolution for clustering.
392
+ num_pc: Number of principal components.
393
+ species: Species of the sample.
394
+ tissue: Tissue type for default gene lists.
395
+ isc_genes_default: Default ISC gene list.
396
+ isc_genes_user: Path to user-provided ISC genes.
397
+ marker_genes_default: Default marker gene list.
398
+ marker_genes_user: Path to user-provided marker genes.
399
+ """
400
+ if not input_rds.is_file():
401
+ raise FileNotFoundError(f"Input file not found: {input_rds}")
402
+ if isc_genes_user and not isc_genes_user.is_file():
403
+ raise FileNotFoundError(f"User ISC genes file not found: {isc_genes_user}")
404
+ if marker_genes_user and not marker_genes_user.is_file():
405
+ raise FileNotFoundError(f"User marker genes file not found: {marker_genes_user}")
406
+
407
+ output_dir.mkdir(parents=True, exist_ok=True)
408
+
409
+ min_diff_pct_r = str(min_diff_pct) if min_diff_pct is not None else "-Inf"
410
+ max_cells_per_ident_r = (
411
+ str(max_cells_per_ident) if max_cells_per_ident is not None else "Inf"
412
+ )
413
+ isc_genes_user_r = f"'{isc_genes_user.resolve()}'" if isc_genes_user else "NULL"
414
+ marker_genes_user_r = (
415
+ f"'{marker_genes_user.resolve()}'" if marker_genes_user else "NULL"
416
+ )
417
+
418
+ r_script = f"""
419
+ library(scider)
420
+ library(Seurat)
421
+
422
+ seurat_object <- readRDS("{input_rds.resolve()}")
423
+
424
+ runScider(
425
+ object = seurat_object,
426
+ method = "{method}",
427
+ de.method = "{de_method}",
428
+ dr.method = "{dr_method}",
429
+ logfc.threshold = {logfc_threshold},
430
+ test.use = "{test_use}",
431
+ min.pct = {min_pct},
432
+ min.diff.pct = {min_diff_pct_r},
433
+ return.thresh = {return_thresh},
434
+ only.pos = {str(only_pos).upper()},
435
+ max.cells.per.ident = {max_cells_per_ident_r},
436
+ random.seed = {random_seed},
437
+ min.cells.group = {min_cells_group},
438
+ pseudocount.use = {pseudocount_use},
439
+ verbose = {str(verbose).upper()},
440
+ assay = "{assay}",
441
+ slot = "{slot}",
442
+ ISC_method = "{isc_method}",
443
+ ISC_threshold = {isc_threshold},
444
+ recluster_method = "{recluster_method}",
445
+ resolution = {resolution},
446
+ num_pc = {num_pc},
447
+ species = "{species}",
448
+ tissue = "{tissue}",
449
+ ISC_genes_default = "{isc_genes_default}",
450
+ ISC_genes_user = {isc_genes_user_r},
451
+ marker_genes_default = "{marker_genes_default}",
452
+ marker_genes_user = {marker_genes_user_r},
453
+ output_dir = "{output_dir.resolve()}",
454
+ project = "{project}"
455
+ )
456
+
457
+ print("scider analysis completed successfully.")
458
+ """
459
+
460
+ result = _execute_r_script(r_script, "runScider")
461
+ if "error" not in result:
462
+ result["output_files"] = [
463
+ str(f) for f in output_dir.resolve().glob(f"{project}*")
464
+ ]
465
+ return result
Biomni/mcp_generated/mcp_bioconductor-scider/app/bioconductor-scider_shim_server.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_bioconductor-scider/app/bioconductor-scider_server.py')
11
+ LOCAL_SERVER = Path(__file__).with_name(SOURCE_SERVER.name)
12
+ SERVER_NAME = 'biosci_bioconductor_scider'
13
+
14
+
15
+ class _ShimMCP:
16
+ @staticmethod
17
+ def tool(*args, **kwargs):
18
+ if args and callable(args[0]) and len(args) == 1 and not kwargs:
19
+ return args[0]
20
+ def _decorator(fn):
21
+ return fn
22
+ return _decorator
23
+
24
+
25
+ def _resolve_source_server():
26
+ if LOCAL_SERVER.exists() and LOCAL_SERVER.name != Path(__file__).name:
27
+ return LOCAL_SERVER
28
+ return SOURCE_SERVER
29
+
30
+
31
+ def _load_functions():
32
+ source_server = _resolve_source_server()
33
+ code = source_server.read_text(encoding="utf-8")
34
+ tree = ast.parse(code, filename=str(source_server))
35
+ function_names = [n.name for n in tree.body if isinstance(n, ast.FunctionDef) and not n.name.startswith("_")]
36
+ namespace = {
37
+ "__name__": "__mcp_source__",
38
+ "mcp": _ShimMCP(),
39
+ }
40
+ exec(compile(code, str(source_server), "exec"), namespace, namespace)
41
+ loaded = []
42
+ for name in function_names:
43
+ fn = namespace.get(name)
44
+ if callable(fn):
45
+ loaded.append(fn)
46
+ return loaded
47
+
48
+
49
+ mcp = FastMCP(SERVER_NAME)
50
+ for _fn in _load_functions():
51
+ mcp.tool()(_fn)
52
+
53
+
54
+ if __name__ == "__main__":
55
+ mcp.run(transport="stdio")
Biomni/mcp_generated/mcp_bioconductor-scider/app/requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+
Biomni/mcp_generated/mcp_bioconductor-scider/docker-compose.yml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version: '3.8'
2
+
3
+ services:
4
+ mcp-bioconductor-scider:
5
+ build: .
6
+ image: mcp-bioconductor-scider:latest
7
+ container_name: mcp-bioconductor-scider
8
+ ports:
9
+ - "8000:8000"
10
+ environment:
11
+ - MCP_SERVER_NAME=bioconductor-scider
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
+
Biomni/mcp_generated/mcp_bioconductor-scider/environment.yaml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ name: mcp-tool
3
+ channels:
4
+ - bioconda
5
+ - conda-forge
6
+ - defaults
7
+ dependencies:
8
+ - bioconductor-scider
9
+ - python=3.10
10
+
Biomni/mcp_generated/mcp_bioconductor-scider/requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ fastmcp
2
+ mcp
Biomni/mcp_generated/mcp_bioconductor-scmageck/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 bioconductor-scmageck via conda (e.g., from bioconda)
14
+ RUN conda install -c bioconda bioconductor-scmageck -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 bioconductor-scmageck_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/bioconductor-scmageck_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/bioconductor-scmageck_server.py"]
40
+
Biomni/mcp_generated/mcp_bioconductor-scmageck/app/bioconductor-scmageck_server.py ADDED
@@ -0,0 +1,277 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import subprocess
2
+ from pathlib import Path
3
+ from typing import Optional, List, Dict, Any
4
+ import tempfile
5
+
6
+ from mcp.server.fastmcp import FastMCP
7
+
8
+ SERVER_NAME = 'local_bioconductor_scmageck'
9
+ mcp = FastMCP(SERVER_NAME)
10
+
11
+ @mcp.tool()
12
+ def scmageck_eff_estimate(
13
+ count_matrix_path: str,
14
+ barcode_file_path: str,
15
+ output_rds_path: str,
16
+ neg_control: str = "non-target",
17
+ perturb_gene: Optional[str] = None,
18
+ cell_column: str = "cell",
19
+ barcode_column: str = "barcode",
20
+ gene_column: str = "gene"
21
+ ):
22
+ """
23
+ Estimate the efficiency of guides using the scmageck_eff_estimate function.
24
+
25
+ Args:
26
+ count_matrix_path: Path to the gene expression count matrix (CSV/TSV or RDS).
27
+ barcode_file_path: Path to the barcode-to-cell mapping file (CSV/TSV).
28
+ output_rds_path: Path where the resulting RDS object will be saved.
29
+ neg_control: Name of the negative control gene/guide.
30
+ perturb_gene: Specific gene to estimate efficiency for. If None, estimates for all.
31
+ cell_column: Column name for cell identifiers in barcode file.
32
+ barcode_column: Column name for barcode identifiers in barcode file.
33
+ gene_column: Column name for gene identifiers in barcode file.
34
+ """
35
+ # Validate inputs
36
+ count_path = Path(count_matrix_path)
37
+ bc_path = Path(barcode_file_path)
38
+ out_path = Path(output_rds_path)
39
+
40
+ if not count_path.exists():
41
+ return {"error": f"Count matrix not found: {count_matrix_path}"}
42
+ if not bc_path.exists():
43
+ return {"error": f"Barcode file not found: {barcode_file_path}"}
44
+
45
+ # Ensure output directory exists
46
+ out_path.parent.mkdir(parents=True, exist_ok=True)
47
+
48
+ # Construct R script
49
+ perturb_gene_cmd = f'"{perturb_gene}"' if perturb_gene else "NULL"
50
+
51
+ r_script = f"""
52
+ library(scmageck)
53
+
54
+ # Load data
55
+ if (grepl(".rds$", "{count_path}", ignore.case = TRUE)) {{
56
+ counts <- readRDS("{count_path}")
57
+ }} else {{
58
+ counts <- read.table("{count_path}", header = TRUE, sep = ",", row.names = 1)
59
+ }}
60
+
61
+ barcodes <- read.table("{bc_path}", header = TRUE, sep = ",")
62
+
63
+ # Run efficiency estimation
64
+ eff_result <- scmageck_eff_estimate(
65
+ count_mat = counts,
66
+ barcode_df = barcodes,
67
+ negctrl = "{neg_control}",
68
+ perturb_gene = {perturb_gene_cmd},
69
+ cell_col = "{cell_column}",
70
+ bc_col = "{barcode_column}",
71
+ gene_col = "{gene_column}"
72
+ )
73
+
74
+ saveRDS(eff_result, file = "{out_path}")
75
+ """
76
+
77
+ try:
78
+ process = subprocess.run(
79
+ ["Rscript", "-e", r_script],
80
+ capture_output=True,
81
+ text=True,
82
+ check=True
83
+ )
84
+ return {
85
+ "command_executed": f"scmageck_eff_estimate on {count_matrix_path}",
86
+ "stdout": process.stdout,
87
+ "stderr": process.stderr,
88
+ "output_files": [str(out_path)]
89
+ }
90
+ except subprocess.CalledProcessError as e:
91
+ return {
92
+ "error": "R execution failed",
93
+ "stdout": e.stdout,
94
+ "stderr": e.stderr,
95
+ "command_executed": e.cmd
96
+ }
97
+
98
+ @mcp.tool()
99
+ def scmageck_lr(
100
+ expression_matrix_path: str,
101
+ perturbation_matrix_path: str,
102
+ output_csv_path: str,
103
+ lambda_val: float = 0.01,
104
+ n_cores: int = 1
105
+ ):
106
+ """
107
+ Perform Linear Regression analysis to identify gene targets using scmageck_lr.
108
+
109
+ Args:
110
+ expression_matrix_path: Path to the expression matrix (RDS or CSV).
111
+ perturbation_matrix_path: Path to the perturbation matrix (RDS or CSV).
112
+ output_csv_path: Path to save the regression results (CSV).
113
+ lambda_val: Penalty parameter for regression.
114
+ n_cores: Number of CPU cores to use.
115
+ """
116
+ expr_path = Path(expression_matrix_path)
117
+ pert_path = Path(perturbation_matrix_path)
118
+ out_path = Path(output_csv_path)
119
+
120
+ if not expr_path.exists() or not pert_path.exists():
121
+ return {"error": "Input expression or perturbation matrix not found."}
122
+
123
+ r_script = f"""
124
+ library(scmageck)
125
+
126
+ # Load matrices
127
+ load_mat <- function(p) {{
128
+ if (grepl(".rds$", p, ignore.case = TRUE)) return(readRDS(p))
129
+ return(as.matrix(read.table(p, header = TRUE, row.names = 1, sep = ",")))
130
+ }}
131
+
132
+ expr_mat <- load_mat("{expr_path}")
133
+ pert_mat <- load_mat("{pert_path}")
134
+
135
+ # Run LR
136
+ lr_result <- scmageck_lr(
137
+ m_matrix = expr_mat,
138
+ g_matrix = pert_mat,
139
+ lambda = {lambda_val}
140
+ )
141
+
142
+ # Handle result (scmageck_lr returns a list or matrix depending on version)
143
+ write.csv(lr_result, file = "{out_path}")
144
+ """
145
+
146
+ try:
147
+ process = subprocess.run(
148
+ ["Rscript", "-e", r_script],
149
+ capture_output=True,
150
+ text=True,
151
+ check=True
152
+ )
153
+ return {
154
+ "command_executed": "scmageck_lr",
155
+ "stdout": process.stdout,
156
+ "stderr": process.stderr,
157
+ "output_files": [str(out_path)]
158
+ }
159
+ except subprocess.CalledProcessError as e:
160
+ return {
161
+ "error": "R execution failed",
162
+ "stdout": e.stdout,
163
+ "stderr": e.stderr
164
+ }
165
+
166
+ @mcp.tool()
167
+ def scmageck_optim_perturb(
168
+ rds_input_path: str,
169
+ output_rds_path: str,
170
+ max_iter: int = 100,
171
+ threshold: float = 1e-4
172
+ ):
173
+ """
174
+ Optimize the perturbation matrix using the scmageck_optim_perturb function.
175
+
176
+ Args:
177
+ rds_input_path: Path to an RDS file containing the scmageck object/list.
178
+ output_rds_path: Path to save the optimized RDS object.
179
+ max_iter: Maximum number of iterations for optimization.
180
+ threshold: Convergence threshold.
181
+ """
182
+ in_path = Path(rds_input_path)
183
+ out_path = Path(output_rds_path)
184
+
185
+ if not in_path.exists():
186
+ return {"error": f"Input RDS file not found: {rds_input_path}"}
187
+
188
+ r_script = f"""
189
+ library(scmageck)
190
+
191
+ obj <- readRDS("{in_path}")
192
+
193
+ # Run optimization
194
+ # Note: scmageck_optim_perturb parameters may vary by version;
195
+ # usually takes the result of eff_estimate
196
+ optim_result <- scmageck_optim_perturb(
197
+ eff_obj = obj,
198
+ max_iter = {max_iter},
199
+ tol = {threshold}
200
+ )
201
+
202
+ saveRDS(optim_result, file = "{out_path}")
203
+ """
204
+
205
+ try:
206
+ process = subprocess.run(
207
+ ["Rscript", "-e", r_script],
208
+ capture_output=True,
209
+ text=True,
210
+ check=True
211
+ )
212
+ return {
213
+ "command_executed": "scmageck_optim_perturb",
214
+ "stdout": process.stdout,
215
+ "stderr": process.stderr,
216
+ "output_files": [str(out_path)]
217
+ }
218
+ except subprocess.CalledProcessError as e:
219
+ return {
220
+ "error": "R execution failed",
221
+ "stdout": e.stdout,
222
+ "stderr": e.stderr
223
+ }
224
+
225
+ @mcp.tool()
226
+ def scmageck_get_score(
227
+ rds_input_path: str,
228
+ output_csv_path: str
229
+ ):
230
+ """
231
+ Extract scores/p-values from a processed scmageck RDS object.
232
+
233
+ Args:
234
+ rds_input_path: Path to the RDS file generated by scmageck_lr or eff_estimate.
235
+ output_csv_path: Path to save the extracted scores as CSV.
236
+ """
237
+ in_path = Path(rds_input_path)
238
+ out_path = Path(output_csv_path)
239
+
240
+ if not in_path.exists():
241
+ return {"error": "Input RDS file not found."}
242
+
243
+ r_script = f"""
244
+ library(scmageck)
245
+ obj <- readRDS("{in_path}")
246
+
247
+ # Extracting score logic depends on the object structure
248
+ if (is.list(obj) && "score" %in% names(obj)) {{
249
+ write.csv(obj$score, file = "{out_path}")
250
+ }} else {{
251
+ # Fallback for matrix results
252
+ write.csv(as.data.frame(obj), file = "{out_path}")
253
+ }}
254
+ """
255
+
256
+ try:
257
+ process = subprocess.run(
258
+ ["Rscript", "-e", r_script],
259
+ capture_output=True,
260
+ text=True,
261
+ check=True
262
+ )
263
+ return {
264
+ "command_executed": "scmageck_get_score",
265
+ "stdout": process.stdout,
266
+ "stderr": process.stderr,
267
+ "output_files": [str(out_path)]
268
+ }
269
+ except subprocess.CalledProcessError as e:
270
+ return {
271
+ "error": "R execution failed",
272
+ "stdout": e.stdout,
273
+ "stderr": e.stderr
274
+ }
275
+
276
+ if __name__ == "__main__":
277
+ mcp.run(transport="stdio")
Biomni/mcp_generated/mcp_bioconductor-scmageck/app/bioconductor-scmageck_shim_server.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_help_txt/mcp_bioconductor-scmageck/app/bioconductor-scmageck_server.py')
11
+ LOCAL_SERVER = Path(__file__).with_name(SOURCE_SERVER.name)
12
+ SERVER_NAME = 'biosci_bioconductor_scmageck'
13
+
14
+
15
+ class _ShimMCP:
16
+ @staticmethod
17
+ def tool(*args, **kwargs):
18
+ if args and callable(args[0]) and len(args) == 1 and not kwargs:
19
+ return args[0]
20
+ def _decorator(fn):
21
+ return fn
22
+ return _decorator
23
+
24
+
25
+ def _resolve_source_server():
26
+ if LOCAL_SERVER.exists() and LOCAL_SERVER.name != Path(__file__).name:
27
+ return LOCAL_SERVER
28
+ return SOURCE_SERVER
29
+
30
+
31
+ def _load_functions():
32
+ source_server = _resolve_source_server()
33
+ code = source_server.read_text(encoding="utf-8")
34
+ tree = ast.parse(code, filename=str(source_server))
35
+ function_names = [n.name for n in tree.body if isinstance(n, ast.FunctionDef) and not n.name.startswith("_")]
36
+ namespace = {
37
+ "__name__": "__mcp_source__",
38
+ "mcp": _ShimMCP(),
39
+ }
40
+ exec(compile(code, str(source_server), "exec"), namespace, namespace)
41
+ loaded = []
42
+ for name in function_names:
43
+ fn = namespace.get(name)
44
+ if callable(fn):
45
+ loaded.append(fn)
46
+ return loaded
47
+
48
+
49
+ mcp = FastMCP(SERVER_NAME)
50
+ for _fn in _load_functions():
51
+ mcp.tool()(_fn)
52
+
53
+
54
+ if __name__ == "__main__":
55
+ mcp.run(transport="stdio")
Biomni/mcp_generated/mcp_bioconductor-scmageck/docker-compose.yml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version: '3.8'
2
+
3
+ services:
4
+ mcp-bioconductor-scmageck:
5
+ build: .
6
+ image: mcp-bioconductor-scmageck:latest
7
+ container_name: mcp-bioconductor-scmageck
8
+ ports:
9
+ - "8000:8000"
10
+ environment:
11
+ - MCP_SERVER_NAME=bioconductor-scmageck
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
+
Biomni/mcp_generated/mcp_bioconductor-scmageck/environment.yaml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ name: mcp-tool
3
+ channels:
4
+ - bioconda
5
+ - conda-forge
6
+ - defaults
7
+ dependencies:
8
+ - bioconductor-scmageck
9
+ - python=3.10
10
+
Biomni/mcp_generated/mcp_bioconductor-scmageck/requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ fastmcp
2
+ mcp
Biomni/mcp_generated/mcp_bioconductor-scqtltools/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 bioconductor-scqtltools via conda (e.g., from bioconda)
14
+ RUN conda install -c bioconda bioconductor-scqtltools -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/bioconductor-scqtltools_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/bioconductor-scqtltools_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/bioconductor-scqtltools_server.py"]
40
+
Biomni/mcp_generated/mcp_bioconductor-scqtltools/app/bioconductor-scqtltools_server.py ADDED
@@ -0,0 +1,187 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import subprocess
2
+ import logging
3
+ import shlex
4
+ from pathlib import Path
5
+ from typing import Optional, List
6
+
7
+ # MCP decorator is used to define the tool.
8
+ # It is assumed that the 'mcp' library is available in the execution environment.
9
+ # from some_mcp_library import mcp
10
+
11
+ logger = logging.getLogger(__name__)
12
+
13
+ from mcp.server.fastmcp import FastMCP
14
+
15
+ SERVER_NAME = 'local_bioconductor_scqtltools'
16
+ mcp = FastMCP(SERVER_NAME)
17
+
18
+ @mcp.tool()
19
+ def run_scqtl_pipeline(
20
+ sce_file: Path,
21
+ genotype_file: Path,
22
+ gene_info_file: Path,
23
+ output_dir: Path,
24
+ sample_id: str,
25
+ cell_type_id: str,
26
+ covariate_file: Optional[Path] = None,
27
+ cis_dist: int = 1000000,
28
+ n_cores: int = 1,
29
+ n_perm: int = 1000,
30
+ fdr_threshold: float = 0.05,
31
+ min_samps_per_cell_type: int = 10,
32
+ min_cells_per_samp: int = 5,
33
+ min_counts_per_gene: int = 10,
34
+ min_genes_per_cell: int = 100,
35
+ run_interaction: bool = False,
36
+ interaction_cov: Optional[str] = None,
37
+ run_tensorqtl: bool = False,
38
+ tensorqtl_mode: str = "cis",
39
+ use_long_format: bool = False,
40
+ verbose: bool = True,
41
+ ) -> dict:
42
+ """
43
+ Runs the scQTL-Tools pipeline for single-cell eQTL analysis.
44
+
45
+ This tool identifies expression quantitative trait loci (eQTLs) in single-cell
46
+ RNA-seq data by associating genetic variants with gene expression levels.
47
+ It wraps the 'scqtl-pipeline' command-line tool.
48
+
49
+ Args:
50
+ sce_file: Path to the SingleCellExperiment object file (.rds).
51
+ genotype_file: Path to the genotype file in VCF format.
52
+ gene_info_file: Path to the gene information file in GTF format.
53
+ output_dir: Path to the directory where output files will be saved.
54
+ sample_id: The identifier for the sample being analyzed.
55
+ cell_type_id: The identifier for the cell type being analyzed.
56
+ covariate_file: Optional path to a file containing covariates.
57
+ cis_dist: The maximum distance (in bp) between a SNP and a gene to be considered a cis-eQTL.
58
+ n_cores: Number of CPU cores to use for parallel processing.
59
+ n_perm: Number of permutations to perform for calculating empirical p-values.
60
+ fdr_threshold: The False Discovery Rate threshold for calling significant eQTLs.
61
+ min_samps_per_cell_type: Minimum number of samples required per cell type.
62
+ min_cells_per_samp: Minimum number of cells required per sample.
63
+ min_counts_per_gene: Minimum total counts required for a gene to be included.
64
+ min_genes_per_cell: Minimum number of expressed genes required for a cell to be included.
65
+ run_interaction: If True, perform an interaction analysis.
66
+ interaction_cov: The name of the covariate to use for interaction analysis. Required if run_interaction is True.
67
+ run_tensorqtl: If True, use tensorQTL for the analysis.
68
+ tensorqtl_mode: The mode for tensorQTL analysis ('cis', 'cis_nominal', 'cis_independent').
69
+ use_long_format: If True, output results in a long format.
70
+ verbose: If True, enable verbose logging.
71
+
72
+ Returns:
73
+ A dictionary containing the execution command, stdout, stderr, and a list of output files.
74
+ """
75
+ # --- Input Validation ---
76
+ if not sce_file.is_file():
77
+ raise FileNotFoundError(f"Input SCE file not found: {sce_file}")
78
+ if not genotype_file.is_file():
79
+ raise FileNotFoundError(f"Input genotype file not found: {genotype_file}")
80
+ if not gene_info_file.is_file():
81
+ raise FileNotFoundError(f"Input gene info file not found: {gene_info_file}")
82
+ if covariate_file and not covariate_file.is_file():
83
+ raise FileNotFoundError(f"Input covariate file not found: {covariate_file}")
84
+
85
+ if n_cores <= 0:
86
+ raise ValueError("n_cores must be a positive integer.")
87
+ if n_perm < 0:
88
+ raise ValueError("n_perm must be a non-negative integer.")
89
+ if not (0.0 < fdr_threshold <= 1.0):
90
+ raise ValueError("fdr_threshold must be between 0 and 1.")
91
+
92
+ if run_interaction and not interaction_cov:
93
+ raise ValueError("interaction_cov must be provided when run_interaction is True.")
94
+
95
+ allowed_tensorqtl_modes = ["cis", "cis_nominal", "cis_independent"]
96
+ if tensorqtl_mode not in allowed_tensorqtl_modes:
97
+ raise ValueError(f"tensorqtl_mode must be one of {allowed_tensorqtl_modes}, but got '{tensorqtl_mode}'.")
98
+
99
+ # --- File Path Handling ---
100
+ try:
101
+ output_dir.mkdir(parents=True, exist_ok=True)
102
+ except OSError as e:
103
+ logger.error(f"Failed to create output directory {output_dir}: {e}")
104
+ raise
105
+
106
+ # --- Command Construction ---
107
+ base_cmd = "scqtl-pipeline"
108
+ cmd = [base_cmd]
109
+
110
+ # Add arguments, assuming CLI flags use hyphens (e.g., --sce-file)
111
+ cmd.extend(["--sce-file", str(sce_file)])
112
+ cmd.extend(["--genotype-file", str(genotype_file)])
113
+ cmd.extend(["--gene-info-file", str(gene_info_file)])
114
+ cmd.extend(["--output-dir", str(output_dir)])
115
+ cmd.extend(["--sample-id", sample_id])
116
+ cmd.extend(["--cell-type-id", cell_type_id])
117
+
118
+ if covariate_file:
119
+ cmd.extend(["--covariate-file", str(covariate_file)])
120
+
121
+ cmd.extend(["--cis-dist", str(cis_dist)])
122
+ cmd.extend(["--n-cores", str(n_cores)])
123
+ cmd.extend(["--n-perm", str(n_perm)])
124
+ cmd.extend(["--fdr-threshold", str(fdr_threshold)])
125
+ cmd.extend(["--min-samps-per-cell-type", str(min_samps_per_cell_type)])
126
+ cmd.extend(["--min-cells-per-samp", str(min_cells_per_samp)])
127
+ cmd.extend(["--min-counts-per-gene", str(min_counts_per_gene)])
128
+ cmd.extend(["--min-genes-per-cell", str(min_genes_per_cell)])
129
+
130
+ if run_interaction:
131
+ cmd.append("--run-interaction")
132
+ if interaction_cov:
133
+ cmd.extend(["--interaction-cov", interaction_cov])
134
+
135
+ if run_tensorqtl:
136
+ cmd.append("--run-tensorqtl")
137
+ cmd.extend(["--tensorqtl-mode", tensorqtl_mode])
138
+
139
+ if use_long_format:
140
+ cmd.append("--use-long-format")
141
+
142
+ if verbose:
143
+ cmd.append("--verbose")
144
+
145
+ command_executed = shlex.join(cmd)
146
+ logger.info(f"Executing command: {command_executed}")
147
+
148
+ # --- Subprocess Execution ---
149
+ try:
150
+ result = subprocess.run(
151
+ cmd,
152
+ capture_output=True,
153
+ text=True,
154
+ check=True,
155
+ )
156
+
157
+ output_files = [str(p) for p in output_dir.glob("**/*") if p.is_file()]
158
+
159
+ return {
160
+ "command_executed": command_executed,
161
+ "stdout": result.stdout,
162
+ "stderr": result.stderr,
163
+ "output_files": output_files,
164
+ }
165
+
166
+ except FileNotFoundError:
167
+ error_message = f"Error: Command '{base_cmd}' not found. Please ensure 'scqtl-pipeline' is installed and in your system's PATH."
168
+ logger.error(error_message)
169
+ return {
170
+ "command_executed": command_executed,
171
+ "stdout": "",
172
+ "stderr": error_message,
173
+ "output_files": [],
174
+ }
175
+ except subprocess.CalledProcessError as e:
176
+ logger.error(f"Command failed with exit code {e.returncode}")
177
+ logger.error(f"stdout: {e.stdout}")
178
+ logger.error(f"stderr: {e.stderr}")
179
+ return {
180
+ "command_executed": command_executed,
181
+ "stdout": e.stdout,
182
+ "stderr": e.stderr,
183
+ "output_files": [],
184
+ }
185
+
186
+ if __name__ == "__main__":
187
+ mcp.run(transport="stdio")
Biomni/mcp_generated/mcp_bioconductor-scqtltools/app/bioconductor-scqtltools_shim_server.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_bioconductor-scqtltools/app/bioconductor-scqtltools_server.py')
11
+ LOCAL_SERVER = Path(__file__).with_name(SOURCE_SERVER.name)
12
+ SERVER_NAME = 'biosci_bioconductor_scqtltools'
13
+
14
+
15
+ class _ShimMCP:
16
+ @staticmethod
17
+ def tool(*args, **kwargs):
18
+ if args and callable(args[0]) and len(args) == 1 and not kwargs:
19
+ return args[0]
20
+ def _decorator(fn):
21
+ return fn
22
+ return _decorator
23
+
24
+
25
+ def _resolve_source_server():
26
+ if LOCAL_SERVER.exists() and LOCAL_SERVER.name != Path(__file__).name:
27
+ return LOCAL_SERVER
28
+ return SOURCE_SERVER
29
+
30
+
31
+ def _load_functions():
32
+ source_server = _resolve_source_server()
33
+ code = source_server.read_text(encoding="utf-8")
34
+ tree = ast.parse(code, filename=str(source_server))
35
+ function_names = [n.name for n in tree.body if isinstance(n, ast.FunctionDef) and not n.name.startswith("_")]
36
+ namespace = {
37
+ "__name__": "__mcp_source__",
38
+ "mcp": _ShimMCP(),
39
+ }
40
+ exec(compile(code, str(source_server), "exec"), namespace, namespace)
41
+ loaded = []
42
+ for name in function_names:
43
+ fn = namespace.get(name)
44
+ if callable(fn):
45
+ loaded.append(fn)
46
+ return loaded
47
+
48
+
49
+ mcp = FastMCP(SERVER_NAME)
50
+ for _fn in _load_functions():
51
+ mcp.tool()(_fn)
52
+
53
+
54
+ if __name__ == "__main__":
55
+ mcp.run(transport="stdio")
Biomni/mcp_generated/mcp_bioconductor-scqtltools/app/requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+
Biomni/mcp_generated/mcp_bioconductor-scqtltools/docker-compose.yml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version: '3.8'
2
+
3
+ services:
4
+ mcp-bioconductor-scqtltools:
5
+ build: .
6
+ image: mcp-bioconductor-scqtltools:latest
7
+ container_name: mcp-bioconductor-scqtltools
8
+ ports:
9
+ - "8000:8000"
10
+ environment:
11
+ - MCP_SERVER_NAME=bioconductor-scqtltools
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
+
Biomni/mcp_generated/mcp_bioconductor-scqtltools/environment.yaml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ name: mcp-tool
3
+ channels:
4
+ - bioconda
5
+ - conda-forge
6
+ - defaults
7
+ dependencies:
8
+ - bioconductor-scqtltools
9
+ - python=3.10
10
+
Biomni/mcp_generated/mcp_bioconductor-scqtltools/requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ fastmcp
2
+ mcp
Biomni/mcp_generated/mcp_bioconductor-scran/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 bioconductor-scran via conda (e.g., from bioconda)
14
+ RUN conda install -c bioconda bioconductor-scran -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/bioconductor-scran_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/bioconductor-scran_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/bioconductor-scran_server.py"]
40
+
Biomni/mcp_generated/mcp_bioconductor-scran/app/bioconductor-scran_server.py ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import subprocess
2
+ import tempfile
3
+ from pathlib import Path
4
+ from typing import Optional, List
5
+
6
+ # MCP decorator is omitted as per instructions.
7
+ from mcp.server.fastmcp import FastMCP
8
+
9
+ SERVER_NAME = 'local_bioconductor_scran'
10
+ mcp = FastMCP(SERVER_NAME)
11
+
12
+ @mcp.tool()
13
+
14
+ def scran_normalize(
15
+ input_sce_rds: Path,
16
+ output_sce_rds: Path,
17
+ clusters_csv: Optional[Path] = None,
18
+ min_mean: float = 0.1,
19
+ bpparam_workers: int = 1,
20
+ ) -> dict:
21
+ """
22
+ Performs normalization of single-cell RNA-seq data using scran's deconvolution method.
23
+
24
+ This tool serves as a wrapper for a hypothetical R script that utilizes the
25
+ 'scran' Bioconductor package. 'scran' itself is an R library without a native
26
+ command-line interface. This function assumes an R script ('run_scran.R')
27
+ exists that can take command-line arguments to perform normalization.
28
+
29
+ Args:
30
+ input_sce_rds (Path): Path to the input SingleCellExperiment object saved as an RDS file.
31
+ This object should contain the raw count matrix.
32
+ output_sce_rds (Path): Path to save the output SingleCellExperiment object (in RDS format)
33
+ with the calculated size factors added.
34
+ clusters_csv (Optional[Path]): Path to a CSV file containing cell cluster assignments.
35
+ If provided, normalization is performed per cluster.
36
+ The CSV should have two columns: cell_barcode, cluster_id.
37
+ min_mean (float): The minimum mean expression for a gene to be used for normalization.
38
+ Corresponds to the 'min.mean' parameter in scran's computeSumFactors.
39
+ Defaults to 0.1.
40
+ bpparam_workers (int): Number of worker processes to use for parallel computation.
41
+ Defaults to 1 (no parallelization).
42
+
43
+ Returns:
44
+ dict: A dictionary containing the executed command, stdout, stderr, and a list
45
+ of output files.
46
+ """
47
+ # --- Input Validation ---
48
+ if not input_sce_rds.is_file():
49
+ raise FileNotFoundError(f"Input RDS file not found: {input_sce_rds}")
50
+ if clusters_csv and not clusters_csv.is_file():
51
+ raise FileNotFoundError(f"Clusters CSV file not found: {clusters_csv}")
52
+ if min_mean < 0:
53
+ raise ValueError("min_mean must be a non-negative number.")
54
+ if bpparam_workers < 1:
55
+ raise ValueError("bpparam_workers must be at least 1.")
56
+
57
+ # --- Command Construction ---
58
+ # This assumes a hypothetical R script 'run_scran.R' that we have created
59
+ # to expose scran functionality to the command line.
60
+ cmd = [
61
+ "Rscript",
62
+ "run_scran.R",
63
+ "normalize",
64
+ "--input",
65
+ str(input_sce_rds),
66
+ "--output",
67
+ str(output_sce_rds),
68
+ "--min-mean",
69
+ str(min_mean),
70
+ "--workers",
71
+ str(bpparam_workers),
72
+ ]
73
+
74
+ if clusters_csv:
75
+ cmd.extend(["--clusters", str(clusters_csv)])
76
+
77
+ # --- Subprocess Execution ---
78
+ command_executed = " ".join(cmd)
79
+ try:
80
+ # In a real scenario, the R script would need to be in the PATH or specified with its full path.
81
+ # For this example, we assume it's available.
82
+ result = subprocess.run(
83
+ cmd,
84
+ capture_output=True,
85
+ text=True,
86
+ check=True,
87
+ )
88
+ stdout = result.stdout
89
+ stderr = result.stderr
90
+ except FileNotFoundError:
91
+ # This error would be raised if 'Rscript' or 'run_scran.R' is not found.
92
+ return {
93
+ "command_executed": command_executed,
94
+ "stdout": "",
95
+ "stderr": "Error: 'Rscript' or the wrapper 'run_scran.R' not found. Please ensure R and the necessary wrapper script are in the system's PATH.",
96
+ "output_files": [],
97
+ }
98
+ except subprocess.CalledProcessError as e:
99
+ return {
100
+ "command_executed": command_executed,
101
+ "stdout": e.stdout,
102
+ "stderr": e.stderr,
103
+ "output_files": [],
104
+ }
105
+
106
+ # --- Return Structured Output ---
107
+ return {
108
+ "command_executed": command_executed,
109
+ "stdout": stdout,
110
+ "stderr": stderr,
111
+ "output_files": [str(output_sce_rds)],
112
+ }
113
+
114
+ if __name__ == "__main__":
115
+ mcp.run(transport="stdio")
Biomni/mcp_generated/mcp_bioconductor-scran/app/bioconductor-scran_shim_server.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_bioconductor-scran/app/bioconductor-scran_server.py')
11
+ LOCAL_SERVER = Path(__file__).with_name(SOURCE_SERVER.name)
12
+ SERVER_NAME = 'biosci_bioconductor_scran'
13
+
14
+
15
+ class _ShimMCP:
16
+ @staticmethod
17
+ def tool(*args, **kwargs):
18
+ if args and callable(args[0]) and len(args) == 1 and not kwargs:
19
+ return args[0]
20
+ def _decorator(fn):
21
+ return fn
22
+ return _decorator
23
+
24
+
25
+ def _resolve_source_server():
26
+ if LOCAL_SERVER.exists() and LOCAL_SERVER.name != Path(__file__).name:
27
+ return LOCAL_SERVER
28
+ return SOURCE_SERVER
29
+
30
+
31
+ def _load_functions():
32
+ source_server = _resolve_source_server()
33
+ code = source_server.read_text(encoding="utf-8")
34
+ tree = ast.parse(code, filename=str(source_server))
35
+ function_names = [n.name for n in tree.body if isinstance(n, ast.FunctionDef) and not n.name.startswith("_")]
36
+ namespace = {
37
+ "__name__": "__mcp_source__",
38
+ "mcp": _ShimMCP(),
39
+ }
40
+ exec(compile(code, str(source_server), "exec"), namespace, namespace)
41
+ loaded = []
42
+ for name in function_names:
43
+ fn = namespace.get(name)
44
+ if callable(fn):
45
+ loaded.append(fn)
46
+ return loaded
47
+
48
+
49
+ mcp = FastMCP(SERVER_NAME)
50
+ for _fn in _load_functions():
51
+ mcp.tool()(_fn)
52
+
53
+
54
+ if __name__ == "__main__":
55
+ mcp.run(transport="stdio")
Biomni/mcp_generated/mcp_bioconductor-scran/app/requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+
Biomni/mcp_generated/mcp_bioconductor-scran/docker-compose.yml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version: '3.8'
2
+
3
+ services:
4
+ mcp-bioconductor-scran:
5
+ build: .
6
+ image: mcp-bioconductor-scran:latest
7
+ container_name: mcp-bioconductor-scran
8
+ ports:
9
+ - "8000:8000"
10
+ environment:
11
+ - MCP_SERVER_NAME=bioconductor-scran
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
+
Biomni/mcp_generated/mcp_bioconductor-scran/environment.yaml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ name: mcp-tool
3
+ channels:
4
+ - bioconda
5
+ - conda-forge
6
+ - defaults
7
+ dependencies:
8
+ - bioconductor-scran
9
+ - python=3.10
10
+
Biomni/mcp_generated/mcp_bioconductor-scran/requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ fastmcp
2
+ mcp
Biomni/mcp_generated/mcp_bioconductor-screpertoire/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 bioconductor-screpertoire via conda (e.g., from bioconda)
14
+ RUN conda install -c bioconda bioconductor-screpertoire -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 bioconductor-screpertoire_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/bioconductor-screpertoire_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/bioconductor-screpertoire_server.py"]
40
+
Biomni/mcp_generated/mcp_bioconductor-screpertoire/app/bioconductor-screpertoire_server.py ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import subprocess
2
+ from pathlib import Path
3
+ from typing import List, Optional
4
+
5
+ # MCP-ready code for the Rscript command-line tool.
6
+ # This tool is often used to execute scripts from Bioconductor packages
7
+ # like 'bioconductor-screpertoire'.
8
+
9
+ # @mcp.tool() is a placeholder for the actual decorator.
10
+ # In a real MCP environment, you would import it:
11
+ # from mcp import tool as mcp_tool
12
+ class mcp:
13
+ @staticmethod
14
+ def tool(func):
15
+ return func
16
+
17
+ @mcp.tool
18
+ def rscript(
19
+ file: Optional[Path] = None,
20
+ expressions: Optional[List[str]] = None,
21
+ script_args: Optional[List[str]] = None,
22
+ verbose: bool = False,
23
+ default_packages: Optional[str] = None,
24
+ save: bool = False,
25
+ no_environ: bool = False,
26
+ no_site_file: bool = False,
27
+ no_init_file: bool = False,
28
+ restore: bool = False,
29
+ vanilla: bool = False,
30
+ ):
31
+ """
32
+ Executes an R script or R expressions using the Rscript command-line tool.
33
+
34
+ This tool serves as a wrapper for Rscript, allowing execution of R code from
35
+ the command line. You must provide either a script file or a list of R
36
+ expressions to execute.
37
+
38
+ Args:
39
+ file: Path to the R script file to be executed. Mutually exclusive with 'expressions'.
40
+ expressions: A list of R expressions to execute using the '-e' flag. Mutually exclusive with 'file'.
41
+ script_args: A list of arguments to be passed to the R script specified by 'file'.
42
+ verbose: If True, corresponds to the --verbose flag, printing information on progress.
43
+ default_packages: A comma-separated list of package names to be loaded by default (e.g., "utils,graphics").
44
+ save: If True, corresponds to the --save flag to save the workspace at the end of the session. Ignored if 'vanilla' is True.
45
+ no_environ: If True, corresponds to the --no-environ flag. Do not read site and user environment files. Ignored if 'vanilla' is True.
46
+ no_site_file: If True, corresponds to the --no-site-file flag. Do not read the site-wide Rprofile. Ignored if 'vanilla' is True.
47
+ no_init_file: If True, corresponds to the --no-init-file flag. Do not read the user R profile. Ignored if 'vanilla' is True.
48
+ restore: If True, corresponds to the --restore flag to restore previously saved objects at startup. Ignored if 'vanilla' is True.
49
+ vanilla: If True, combines --no-save, --no-restore, --no-site-file, --no-init-file, and --no-environ for a clean session.
50
+
51
+ Returns:
52
+ A dictionary containing the command executed, stdout, stderr, and a list of output files.
53
+ Note: Rscript itself does not define output files; any generated files are the responsibility of the R code being executed.
54
+ """
55
+ # 1. Input Validation
56
+ if file and expressions:
57
+ raise ValueError("Cannot specify both 'file' and 'expressions'. They are mutually exclusive.")
58
+ if not file and not expressions:
59
+ raise ValueError("Must specify either 'file' or 'expressions' to execute.")
60
+
61
+ if file:
62
+ if not file.is_file():
63
+ raise FileNotFoundError(f"The specified R script file does not exist: {file}")
64
+
65
+ if script_args and not file:
66
+ raise ValueError("'script_args' can only be provided when a 'file' is specified.")
67
+
68
+ # 2. Command Construction
69
+ cmd = ["Rscript"]
70
+
71
+ if vanilla:
72
+ cmd.append("--vanilla")
73
+ else:
74
+ if save:
75
+ cmd.append("--save")
76
+ if no_environ:
77
+ cmd.append("--no-environ")
78
+ if no_site_file:
79
+ cmd.append("--no-site-file")
80
+ if no_init_file:
81
+ cmd.append("--no-init-file")
82
+ if restore:
83
+ cmd.append("--restore")
84
+
85
+ if verbose:
86
+ cmd.append("--verbose")
87
+
88
+ if default_packages:
89
+ cmd.append(f"--default-packages={default_packages}")
90
+
91
+ if expressions:
92
+ for expr in expressions:
93
+ cmd.extend(["-e", expr])
94
+ elif file:
95
+ cmd.append(str(file))
96
+ if script_args:
97
+ cmd.extend(script_args)
98
+
99
+ # 3. Subprocess Execution
100
+ command_executed = " ".join(cmd)
101
+ try:
102
+ result = subprocess.run(
103
+ cmd,
104
+ capture_output=True,
105
+ text=True,
106
+ check=True
107
+ )
108
+ return {
109
+ "command_executed": command_executed,
110
+ "stdout": result.stdout,
111
+ "stderr": result.stderr,
112
+ "output_files": []
113
+ }
114
+ except FileNotFoundError:
115
+ raise RuntimeError("Rscript executable not found. Please ensure R is installed and in your system's PATH.")
116
+ except subprocess.CalledProcessError as e:
117
+ # Return a structured error response for failed executions
118
+ return {
119
+ "command_executed": command_executed,
120
+ "stdout": e.stdout,
121
+ "stderr": e.stderr,
122
+ "error": f"Rscript execution failed with return code {e.returncode}",
123
+ "output_files": []
124
+ }
Biomni/mcp_generated/mcp_bioconductor-screpertoire/app/bioconductor-screpertoire_shim_server.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_help_txt/mcp_bioconductor-screpertoire/app/bioconductor-screpertoire_server.py')
11
+ LOCAL_SERVER = Path(__file__).with_name(SOURCE_SERVER.name)
12
+ SERVER_NAME = 'biosci_bioconductor_screpertoire'
13
+
14
+
15
+ class _ShimMCP:
16
+ @staticmethod
17
+ def tool(*args, **kwargs):
18
+ if args and callable(args[0]) and len(args) == 1 and not kwargs:
19
+ return args[0]
20
+ def _decorator(fn):
21
+ return fn
22
+ return _decorator
23
+
24
+
25
+ def _resolve_source_server():
26
+ if LOCAL_SERVER.exists() and LOCAL_SERVER.name != Path(__file__).name:
27
+ return LOCAL_SERVER
28
+ return SOURCE_SERVER
29
+
30
+
31
+ def _load_functions():
32
+ source_server = _resolve_source_server()
33
+ code = source_server.read_text(encoding="utf-8")
34
+ tree = ast.parse(code, filename=str(source_server))
35
+ function_names = [n.name for n in tree.body if isinstance(n, ast.FunctionDef) and not n.name.startswith("_")]
36
+ namespace = {
37
+ "__name__": "__mcp_source__",
38
+ "mcp": _ShimMCP(),
39
+ }
40
+ exec(compile(code, str(source_server), "exec"), namespace, namespace)
41
+ loaded = []
42
+ for name in function_names:
43
+ fn = namespace.get(name)
44
+ if callable(fn):
45
+ loaded.append(fn)
46
+ return loaded
47
+
48
+
49
+ mcp = FastMCP(SERVER_NAME)
50
+ for _fn in _load_functions():
51
+ mcp.tool()(_fn)
52
+
53
+
54
+ if __name__ == "__main__":
55
+ mcp.run(transport="stdio")
Biomni/mcp_generated/mcp_bioconductor-screpertoire/docker-compose.yml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version: '3.8'
2
+
3
+ services:
4
+ mcp-bioconductor-screpertoire:
5
+ build: .
6
+ image: mcp-bioconductor-screpertoire:latest
7
+ container_name: mcp-bioconductor-screpertoire
8
+ ports:
9
+ - "8000:8000"
10
+ environment:
11
+ - MCP_SERVER_NAME=bioconductor-screpertoire
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
+
Biomni/mcp_generated/mcp_bioconductor-screpertoire/environment.yaml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ name: mcp-tool
3
+ channels:
4
+ - bioconda
5
+ - conda-forge
6
+ - defaults
7
+ dependencies:
8
+ - bioconductor-screpertoire
9
+ - python=3.10
10
+
Biomni/mcp_generated/mcp_bioconductor-screpertoire/requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ fastmcp
2
+ mcp
Biomni/mcp_generated/mcp_bioconductor-scrnaseq/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 bioconductor-scrnaseq via conda (e.g., from bioconda)
14
+ RUN conda install -c bioconda bioconductor-scrnaseq -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 bioconductor-scrnaseq_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/bioconductor-scrnaseq_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/bioconductor-scrnaseq_server.py"]
40
+
Biomni/mcp_generated/mcp_bioconductor-scrnaseq/app/bioconductor-scrnaseq_server.py ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 in the MCP environment.
6
+ # No need to import it in the final code.
7
+
8
+ from mcp.server.fastmcp import FastMCP
9
+
10
+ SERVER_NAME = 'local_bioconductor_scrnaseq'
11
+ mcp = FastMCP(SERVER_NAME)
12
+
13
+ @mcp.tool()
14
+ def run_rscript(
15
+ script_file: Optional[Path] = None,
16
+ expressions: Optional[List[str]] = None,
17
+ script_args: Optional[List[str]] = None,
18
+ verbose: bool = False,
19
+ default_packages: Optional[str] = None,
20
+ save: bool = False,
21
+ no_environ: bool = False,
22
+ no_site_file: bool = False,
23
+ no_init_file: bool = False,
24
+ restore: bool = False,
25
+ vanilla: bool = False,
26
+ ) -> Dict[str, Any]:
27
+ """
28
+ Executes an R script or R expressions using the Rscript command-line tool.
29
+
30
+ This tool serves as a wrapper for Rscript, allowing execution of R code from
31
+ the command line. It is commonly used to run scripts that utilize libraries
32
+ from repositories like Bioconductor (e.g., for scRNA-seq analysis). You must
33
+ provide either a script file to run or a list of expressions to evaluate.
34
+
35
+ Args:
36
+ script_file: Path to the R script file to be executed. Mutually exclusive with 'expressions'.
37
+ expressions: A list of R expressions to be executed. Mutually exclusive with 'script_file'.
38
+ script_args: A list of arguments to be passed to the R script itself.
39
+ verbose: If True, prints information on progress. Corresponds to --verbose.
40
+ default_packages: A comma-separated list of package names to be loaded by default, or 'NULL'. Corresponds to --default-packages.
41
+ save: If True, saves the workspace at the end of the session. Corresponds to --save.
42
+ no_environ: If True, does not read the site and user environment files. Corresponds to --no-environ.
43
+ no_site_file: If True, does not read the site-wide Rprofile. Corresponds to --no-site-file.
44
+ no_init_file: If True, does not read the user R profile. Corresponds to --no-init-file.
45
+ restore: If True, restores previously saved objects at startup. Corresponds to --restore.
46
+ vanilla: If True, combines --no-save, --no-restore, --no-site-file, --no-init-file, and --no-environ.
47
+
48
+ Returns:
49
+ A dictionary containing the executed command, stdout, stderr, and a list of output files.
50
+ The 'output_files' list will be empty as Rscript itself does not define output files;
51
+ any files created are determined by the R code being executed.
52
+ """
53
+ # 1. Input Validation
54
+ if script_file is None and (expressions is None or not expressions):
55
+ raise ValueError("Either 'script_file' or a non-empty 'expressions' list must be provided.")
56
+ if script_file is not None and expressions is not None:
57
+ raise ValueError("'script_file' and 'expressions' are mutually exclusive and cannot be used together.")
58
+ if script_file and not script_file.is_file():
59
+ raise FileNotFoundError(f"Input script file not found or is not a file: {script_file}")
60
+
61
+ # 2. Command Construction
62
+ cmd = ["Rscript"]
63
+
64
+ if verbose:
65
+ cmd.append("--verbose")
66
+ if default_packages:
67
+ cmd.append(f"--default-packages={default_packages}")
68
+ if save:
69
+ cmd.append("--save")
70
+ if no_environ:
71
+ cmd.append("--no-environ")
72
+ if no_site_file:
73
+ cmd.append("--no-site-file")
74
+ if no_init_file:
75
+ cmd.append("--no-init-file")
76
+ if restore:
77
+ cmd.append("--restore")
78
+ if vanilla:
79
+ cmd.append("--vanilla")
80
+
81
+ if expressions:
82
+ for expr in expressions:
83
+ cmd.extend(["-e", expr])
84
+ elif script_file:
85
+ cmd.append(str(script_file))
86
+
87
+ if script_args:
88
+ cmd.extend(script_args)
89
+
90
+ command_executed = " ".join(cmd)
91
+
92
+ # 3. Subprocess Execution and Error Handling
93
+ try:
94
+ result = subprocess.run(
95
+ cmd,
96
+ capture_output=True,
97
+ text=True,
98
+ check=True,
99
+ )
100
+ stdout = result.stdout
101
+ stderr = result.stderr
102
+ except FileNotFoundError:
103
+ # This error is caught if 'Rscript' is not in the system's PATH
104
+ raise RuntimeError("Rscript not found. Please ensure R is installed and in your system's PATH.")
105
+ except subprocess.CalledProcessError as e:
106
+ # This error is caught if Rscript returns a non-zero exit code
107
+ return {
108
+ "error": "Rscript execution failed with a non-zero exit code.",
109
+ "command_executed": command_executed,
110
+ "stdout": e.stdout,
111
+ "stderr": e.stderr,
112
+ "return_code": e.returncode,
113
+ }
114
+
115
+ # 4. Structured Result Return
116
+ return {
117
+ "command_executed": command_executed,
118
+ "stdout": stdout,
119
+ "stderr": stderr,
120
+ "output_files": []
121
+ }
122
+
123
+ if __name__ == "__main__":
124
+ mcp.run(transport="stdio")
Biomni/mcp_generated/mcp_bioconductor-scrnaseq/app/bioconductor-scrnaseq_shim_server.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_help_txt/mcp_bioconductor-scrnaseq/app/bioconductor-scrnaseq_server.py')
11
+ LOCAL_SERVER = Path(__file__).with_name(SOURCE_SERVER.name)
12
+ SERVER_NAME = 'biosci_bioconductor_scrnaseq'
13
+
14
+
15
+ class _ShimMCP:
16
+ @staticmethod
17
+ def tool(*args, **kwargs):
18
+ if args and callable(args[0]) and len(args) == 1 and not kwargs:
19
+ return args[0]
20
+ def _decorator(fn):
21
+ return fn
22
+ return _decorator
23
+
24
+
25
+ def _resolve_source_server():
26
+ if LOCAL_SERVER.exists() and LOCAL_SERVER.name != Path(__file__).name:
27
+ return LOCAL_SERVER
28
+ return SOURCE_SERVER
29
+
30
+
31
+ def _load_functions():
32
+ source_server = _resolve_source_server()
33
+ code = source_server.read_text(encoding="utf-8")
34
+ tree = ast.parse(code, filename=str(source_server))
35
+ function_names = [n.name for n in tree.body if isinstance(n, ast.FunctionDef) and not n.name.startswith("_")]
36
+ namespace = {
37
+ "__name__": "__mcp_source__",
38
+ "mcp": _ShimMCP(),
39
+ }
40
+ exec(compile(code, str(source_server), "exec"), namespace, namespace)
41
+ loaded = []
42
+ for name in function_names:
43
+ fn = namespace.get(name)
44
+ if callable(fn):
45
+ loaded.append(fn)
46
+ return loaded
47
+
48
+
49
+ mcp = FastMCP(SERVER_NAME)
50
+ for _fn in _load_functions():
51
+ mcp.tool()(_fn)
52
+
53
+
54
+ if __name__ == "__main__":
55
+ mcp.run(transport="stdio")
Biomni/mcp_generated/mcp_bioconductor-scrnaseq/docker-compose.yml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version: '3.8'
2
+
3
+ services:
4
+ mcp-bioconductor-scrnaseq:
5
+ build: .
6
+ image: mcp-bioconductor-scrnaseq:latest
7
+ container_name: mcp-bioconductor-scrnaseq
8
+ ports:
9
+ - "8000:8000"
10
+ environment:
11
+ - MCP_SERVER_NAME=bioconductor-scrnaseq
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
+
Biomni/mcp_generated/mcp_bioconductor-scrnaseq/environment.yaml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ name: mcp-tool
3
+ channels:
4
+ - bioconda
5
+ - conda-forge
6
+ - defaults
7
+ dependencies:
8
+ - bioconductor-scrnaseq
9
+ - python=3.10
10
+
Biomni/mcp_generated/mcp_bioconductor-scrnaseq/requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ fastmcp
2
+ mcp
Biomni/mcp_generated/mcp_bioconductor-sctreeviz/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 bioconductor-sctreeviz via conda (e.g., from bioconda)
14
+ RUN conda install -c bioconda bioconductor-sctreeviz -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/bioconductor-sctreeviz_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/bioconductor-sctreeviz_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/bioconductor-sctreeviz_server.py"]
40
+
Biomni/mcp_generated/mcp_bioconductor-sctreeviz/app/bioconductor-sctreeviz_server.py ADDED
@@ -0,0 +1,230 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import subprocess
2
+ import tempfile
3
+ from pathlib import Path
4
+ from typing import List, Optional, Dict, Any
5
+ import logging
6
+ import shlex
7
+
8
+ # Set up logging
9
+ logging.basicConfig(level=logging.INFO)
10
+ logger = logging.getLogger(__name__)
11
+
12
+ # Mock mcp.tool decorator for standalone execution
13
+ def mcp_tool_mock():
14
+ def decorator(func):
15
+ def wrapper(*args, **kwargs):
16
+ return func(*args, **kwargs)
17
+ return wrapper
18
+ return decorator
19
+
20
+ mcp = type('mcp', (), {'tool': mcp_tool_mock})()
21
+
22
+
23
+ from mcp.server.fastmcp import FastMCP
24
+
25
+ SERVER_NAME = 'local_bioconductor_sctreeviz'
26
+ mcp = FastMCP(SERVER_NAME)
27
+
28
+ @mcp.tool()
29
+ def generate_cluster_tree(
30
+ sce_rds: Path,
31
+ output_plot: Path,
32
+ cluster_steps: str = "2,4,6,8",
33
+ assay_name: str = "logcounts",
34
+ dimred_name: str = "PCA",
35
+ cluster_prefix: str = "sctv_cluster_",
36
+ ) -> Dict[str, Any]:
37
+ """
38
+ Generates a cluster tree visualization from a SingleCellExperiment object.
39
+
40
+ This tool uses the scTreeViz R package to perform clustering at multiple
41
+ resolutions and visualize the resulting hierarchy as a 'clustree' plot.
42
+ It requires a pre-processed SingleCellExperiment object saved as an .rds file,
43
+ which must contain a dimensionality reduction result (e.g., PCA).
44
+
45
+ Args:
46
+ sce_rds: Path to the input SingleCellExperiment object saved as an RDS file.
47
+ This object must contain a dimensionality reduction result specified
48
+ by `dimred_name`.
49
+ output_plot: Path to save the output plot. The file extension (e.g., .png,
50
+ .pdf, .svg) determines the output format.
51
+ cluster_steps: A comma-separated string of integer 'steps' for the
52
+ `igraph::cluster_walktrap` algorithm, used to generate
53
+ clusters at different resolutions.
54
+ assay_name: The name of the assay in the SCE object to use for building the graph.
55
+ dimred_name: The name of the dimensionality reduction result in the SCE
56
+ object to use for building the SNN graph.
57
+ cluster_prefix: The prefix for the new cluster columns added to the
58
+ colData of the SCE object.
59
+
60
+ Returns:
61
+ A dictionary containing the executed command, stdout, stderr, and a list
62
+ of output files.
63
+ """
64
+ # 1. Input validation
65
+ if not sce_rds.is_file():
66
+ raise FileNotFoundError(f"Input file not found: {sce_rds}")
67
+
68
+ if not output_plot.parent.exists():
69
+ logger.info(f"Output directory {output_plot.parent} does not exist. Creating it.")
70
+ output_plot.parent.mkdir(parents=True, exist_ok=True)
71
+
72
+ try:
73
+ # Validate that cluster_steps contains comma-separated integers
74
+ [int(s.strip()) for s in cluster_steps.split(',')]
75
+ except ValueError:
76
+ raise ValueError("`cluster_steps` must be a comma-separated string of integers.")
77
+
78
+ # 2. R script generation
79
+ r_script_content = f"""
80
+ # Load necessary libraries
81
+ if (!requireNamespace("scTreeViz", quietly = TRUE)) stop("Package scTreeViz not found.")
82
+ if (!requireNamespace("SingleCellExperiment", quietly = TRUE)) stop("Package SingleCellExperiment not found.")
83
+ if (!requireNamespace("scran", quietly = TRUE)) stop("Package scran not found.")
84
+ if (!requireNamespace("igraph", quietly = TRUE)) stop("Package igraph not found.")
85
+ if (!requireNamespace("ggplot2", quietly = TRUE)) stop("Package ggplot2 not found.")
86
+
87
+ library(scTreeViz)
88
+ library(SingleCellExperiment)
89
+ library(scran)
90
+ library(igraph)
91
+ library(ggplot2)
92
+
93
+ # --- Get arguments from command line ---
94
+ args <- commandArgs(trailingOnly=TRUE)
95
+ sce_rds_path <- args[1]
96
+ output_plot_path <- args[2]
97
+ cluster_steps_str <- args[3]
98
+ assay_name <- args[4]
99
+ dimred_name <- args[5]
100
+ cluster_prefix <- args[6]
101
+
102
+ cat("--- scTreeViz Analysis Parameters ---\\n")
103
+ cat("Input SCE RDS: ", sce_rds_path, "\\n")
104
+ cat("Output Plot: ", output_plot_path, "\\n")
105
+ cat("Cluster Steps: ", cluster_steps_str, "\\n")
106
+ cat("Assay Name: ", assay_name, "\\n")
107
+ cat("DimRed Name: ", dimred_name, "\\n")
108
+ cat("Cluster Prefix: ", cluster_prefix, "\\n")
109
+ cat("-------------------------------------\\n\\n")
110
+
111
+ # --- Main analysis ---
112
+ tryCatch({{
113
+ # Read input SingleCellExperiment object
114
+ cat("Reading SCE object from:", sce_rds_path, "\\n")
115
+ sce <- readRDS(sce_rds_path)
116
+
117
+ # Check for dimensionality reduction result
118
+ if (!dimred_name %in% reducedDimNames(sce)) {{
119
+ stop(paste0("Dimensionality reduction '", dimred_name, "' not found in the SCE object."))
120
+ }}
121
+
122
+ # Build SNN graph
123
+ cat("Building SNN graph using '", dimred_name, "'...\\n")
124
+ g <- buildSNNGraph(sce, use.dimred=dimred_name, assay.type=assay_name)
125
+
126
+ # Parse cluster steps
127
+ steps_vec <- as.integer(strsplit(cluster_steps_str, ",")[[1]])
128
+
129
+ # Perform clustering for each step value
130
+ cat("Performing clustering for steps:", paste(steps_vec, collapse=", "), "\\n")
131
+ for (s in steps_vec) {{
132
+ set.seed(42) # for reproducibility
133
+ col_name <- paste0(cluster_prefix, "s", s)
134
+ clust <- igraph::cluster_walktrap(g, steps=s)$membership
135
+ sce[[col_name]] <- as.factor(clust)
136
+ }}
137
+
138
+ # Get the names of the cluster columns we just created
139
+ clust_cols <- grep(paste0("^", cluster_prefix), colnames(colData(sce)), value = TRUE)
140
+ if (length(clust_cols) == 0) {{
141
+ stop("No cluster columns were generated. Check cluster_prefix and clustering steps.")
142
+ }}
143
+ cat("Generated cluster columns:", paste(clust_cols, collapse=", "), "\\n")
144
+
145
+ # Create the TreeViz object
146
+ cat("Creating TreeViz object...\\n")
147
+ sctv <- TreeViz(sce, colData_cols = clust_cols)
148
+
149
+ # Generate the clustree plot
150
+ cat("Generating clustree plot...\\n")
151
+ p <- sctv_clustree(sctv, prefix = cluster_prefix)
152
+
153
+ # Save the plot
154
+ cat("Saving plot to:", output_plot_path, "\\n")
155
+ ggsave(output_plot_path, plot = p, width = 10, height = 8, dpi = 300)
156
+
157
+ cat("\\n--- Analysis successfully completed! ---\\n")
158
+
159
+ }}, error = function(e) {{
160
+ cat("Error during scTreeViz analysis:\\n")
161
+ message(e)
162
+ quit(status = 1)
163
+ }})
164
+ """
165
+
166
+ # 3. Subprocess execution
167
+ command = []
168
+ result_dict = {
169
+ "command_executed": "",
170
+ "stdout": "",
171
+ "stderr": "",
172
+ "output_files": [],
173
+ }
174
+
175
+ try:
176
+ with tempfile.NamedTemporaryFile(mode='w', delete=False, suffix=".R") as r_script_file:
177
+ r_script_file.write(r_script_content)
178
+ r_script_path = r_script_file.name
179
+
180
+ command = [
181
+ "Rscript",
182
+ r_script_path,
183
+ str(sce_rds),
184
+ str(output_plot),
185
+ cluster_steps,
186
+ assay_name,
187
+ dimred_name,
188
+ cluster_prefix,
189
+ ]
190
+
191
+ command_str = " ".join(shlex.quote(c) for c in command)
192
+ logger.info(f"Executing command: {command_str}")
193
+ result_dict["command_executed"] = command_str
194
+
195
+ process = subprocess.run(
196
+ command,
197
+ capture_output=True,
198
+ text=True,
199
+ check=True,
200
+ )
201
+
202
+ result_dict["stdout"] = process.stdout
203
+ result_dict["stderr"] = process.stderr
204
+ if output_plot.exists():
205
+ result_dict["output_files"].append(str(output_plot))
206
+
207
+ logger.info(f"Successfully generated cluster tree plot: {output_plot}")
208
+
209
+ except FileNotFoundError:
210
+ error_msg = "Rscript not found. Please ensure R is installed and in your PATH."
211
+ logger.error(error_msg)
212
+ result_dict["stderr"] = error_msg
213
+ raise RuntimeError(error_msg) from None
214
+ except subprocess.CalledProcessError as e:
215
+ logger.error(f"Error executing scTreeViz R script.")
216
+ logger.error(f"Return code: {e.returncode}")
217
+ logger.error(f"Stdout: {e.stdout}")
218
+ logger.error(f"Stderr: {e.stderr}")
219
+ result_dict["stdout"] = e.stdout
220
+ result_dict["stderr"] = e.stderr
221
+ raise
222
+ finally:
223
+ # Clean up the temporary R script
224
+ if 'r_script_path' in locals() and Path(r_script_path).exists():
225
+ Path(r_script_path).unlink()
226
+
227
+ return result_dict
228
+
229
+ if __name__ == "__main__":
230
+ mcp.run(transport="stdio")
Biomni/mcp_generated/mcp_bioconductor-sctreeviz/app/bioconductor-sctreeviz_shim_server.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_bioconductor-sctreeviz/app/bioconductor-sctreeviz_server.py')
11
+ LOCAL_SERVER = Path(__file__).with_name(SOURCE_SERVER.name)
12
+ SERVER_NAME = 'biosci_bioconductor_sctreeviz'
13
+
14
+
15
+ class _ShimMCP:
16
+ @staticmethod
17
+ def tool(*args, **kwargs):
18
+ if args and callable(args[0]) and len(args) == 1 and not kwargs:
19
+ return args[0]
20
+ def _decorator(fn):
21
+ return fn
22
+ return _decorator
23
+
24
+
25
+ def _resolve_source_server():
26
+ if LOCAL_SERVER.exists() and LOCAL_SERVER.name != Path(__file__).name:
27
+ return LOCAL_SERVER
28
+ return SOURCE_SERVER
29
+
30
+
31
+ def _load_functions():
32
+ source_server = _resolve_source_server()
33
+ code = source_server.read_text(encoding="utf-8")
34
+ tree = ast.parse(code, filename=str(source_server))
35
+ function_names = [n.name for n in tree.body if isinstance(n, ast.FunctionDef) and not n.name.startswith("_")]
36
+ namespace = {
37
+ "__name__": "__mcp_source__",
38
+ "mcp": _ShimMCP(),
39
+ }
40
+ exec(compile(code, str(source_server), "exec"), namespace, namespace)
41
+ loaded = []
42
+ for name in function_names:
43
+ fn = namespace.get(name)
44
+ if callable(fn):
45
+ loaded.append(fn)
46
+ return loaded
47
+
48
+
49
+ mcp = FastMCP(SERVER_NAME)
50
+ for _fn in _load_functions():
51
+ mcp.tool()(_fn)
52
+
53
+
54
+ if __name__ == "__main__":
55
+ mcp.run(transport="stdio")
Biomni/mcp_generated/mcp_bioconductor-sctreeviz/app/requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+
Biomni/mcp_generated/mcp_bioconductor-sctreeviz/docker-compose.yml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version: '3.8'
2
+
3
+ services:
4
+ mcp-bioconductor-sctreeviz:
5
+ build: .
6
+ image: mcp-bioconductor-sctreeviz:latest
7
+ container_name: mcp-bioconductor-sctreeviz
8
+ ports:
9
+ - "8000:8000"
10
+ environment:
11
+ - MCP_SERVER_NAME=bioconductor-sctreeviz
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
+
Biomni/mcp_generated/mcp_bioconductor-sctreeviz/environment.yaml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ name: mcp-tool
3
+ channels:
4
+ - bioconda
5
+ - conda-forge
6
+ - defaults
7
+ dependencies:
8
+ - bioconductor-sctreeviz
9
+ - python=3.10
10
+
Biomni/mcp_generated/mcp_bioconductor-sctreeviz/requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ fastmcp
2
+ mcp