czty commited on
Commit
360b3dd
·
verified ·
1 Parent(s): de8c392

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

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/gtdbtk_identify_and_align_genome_markers_test_server.py +201 -0
  2. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/hicexplorer_find_restriction_sites_test_server.py +78 -0
  3. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/hmmer_build_protein_hmm_test_server.py +92 -0
  4. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/htseq_count_reads_test_server.py +89 -0
  5. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/htslib_bgzip_compress_test_server.py +49 -0
  6. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/humann2_renormalize_gene_families_test_server.py +73 -0
  7. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/illumina-interop_dump_q_metrics_test_server.py +76 -0
  8. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/infernal_build_and_align_cm_test_server.py +118 -0
  9. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/intarna_predict_rna_interaction_test_server.py +74 -0
  10. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/ipython-cluster-helper_normalize_scheduler_resources_test_server.py +96 -0
  11. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/iqtree_infer_protein_tree_test_server.py +82 -0
  12. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/itsxpress_trim_fungal_its_test_server.py +66 -0
  13. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/ivar_consensus_from_pileup_test_server.py +81 -0
  14. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/kallisto_build_transcript_index_test_server.py +64 -0
  15. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/kmc_count_kmers_test_server.py +96 -0
  16. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/krona_taxonomy_chart_test_server.py +60 -0
  17. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/last_align_dna_test_server.py +75 -0
  18. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/locarna_align_rna_test_server.py +65 -0
  19. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/macs2_call_narrow_peak_test_server.py +83 -0
  20. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/mageck_count_sgrna_test_server.py +103 -0
  21. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/mash_sketch_fasta_test_server.py +82 -0
  22. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/maxquant_create_parameter_template_test_server.py +77 -0
  23. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/medaka_vcf_to_tsv_test_server.py +79 -0
  24. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/metagenome-atlas_initialize_project_test_server.py +89 -0
  25. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/mikado_configure_workflow_test_server.py +89 -0
  26. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/miniasm_assemble_overlap_graph_test_server.py +101 -0
  27. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/minimap2_align_dna_test_server.py +84 -0
  28. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/minvar_estimate_minimum_read_length_test_server.py +83 -0
  29. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/mosdepth_coverage_summary_test_server.py +90 -0
  30. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/mothur_summarize_sequences_test_server.py +117 -0
  31. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/msisensor-pro_scan_microsatellites_test_server.py +67 -0
  32. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/msstitch_build_sequence_searchspace_test_server.py +80 -0
  33. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/muscle_align_proteins_test_server.py +83 -0
  34. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/nanopolish_index_and_check_fast5_test_server.py +92 -0
  35. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/ncbi-genome-download_select_assembly_dry_run_test_server.py +66 -0
  36. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/nextalign_align_nucleotides_test_server.py +103 -0
  37. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/nextclade_analyze_sequence_test_server.py +108 -0
  38. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/ngmlr_align_long_reads_test_server.py +101 -0
  39. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/ont-fast5-api_summarize_single_read_fast5_test_server.py +86 -0
  40. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/orthofinder_infer_orthogroups_test_server.py +102 -0
  41. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/paml_pairwise_dn_ds_test_server.py +88 -0
  42. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/parasail-python_global_align_test_server.py +50 -0
  43. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/picard_sort_sam_test_server.py +94 -0
  44. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/portcullis_prepare_splice_inputs_test_server.py +90 -0
  45. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/prank_align_proteins_test_server.py +101 -0
  46. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/prophyle_index_and_classify_reads_test_server.py +98 -0
  47. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/pyfastx_fasta_statistics_test_server.py +76 -0
  48. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/pyranges_merge_genomic_ranges_test_server.py +60 -0
  49. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/pyrodigal_predict_genes_test_server.py +87 -0
  50. Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/pysam_summarize_bam_test_server.py +98 -0
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/gtdbtk_identify_and_align_genome_markers_test_server.py ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import subprocess
3
+ import sys
4
+ import tempfile
5
+ import shutil
6
+ from pathlib import Path
7
+ from mcp.server.fastmcp import FastMCP
8
+
9
+ mcp = FastMCP("gtdbtk-identify-align")
10
+
11
+ def read_database_pointer(pointer_path: str) -> str:
12
+ """Read the database pointer file and return the GTDBTK_DATA_PATH value."""
13
+ with open(pointer_path, "r") as f:
14
+ content = f.read().strip()
15
+ # The file is expected to contain a line like GTDBTK_DATA_PATH=/path/to/db
16
+ for line in content.splitlines():
17
+ line = line.strip()
18
+ if line.startswith("GTDBTK_DATA_PATH="):
19
+ return line.split("=", 1)[1]
20
+ raise ValueError(f"Could not find GTDBTK_DATA_PATH in {pointer_path}")
21
+
22
+ def normalize_gtdbtk_markers(markers_tsv: str, user_msa: str, output_tsv: str) -> dict:
23
+ """
24
+ Normalize the GTDB-Tk marker identification and alignment outputs into a
25
+ structured summary TSV. This is a placeholder implementation that copies
26
+ the marker file and adds alignment metadata.
27
+ """
28
+ # Create output directory
29
+ out_dir = os.path.dirname(output_tsv)
30
+ if out_dir:
31
+ os.makedirs(out_dir, exist_ok=True)
32
+
33
+ # Read markers file (identify output)
34
+ markers_data = []
35
+ if os.path.exists(markers_tsv):
36
+ with open(markers_tsv, "r") as f:
37
+ header = f.readline().strip().split("\t")
38
+ for line in f:
39
+ fields = line.strip().split("\t")
40
+ if len(fields) == len(header):
41
+ markers_data.append(dict(zip(header, fields)))
42
+
43
+ # Read alignment file to get basic stats
44
+ alignment_stats = {"sequences": 0, "length": 0}
45
+ if os.path.exists(user_msa):
46
+ with open(user_msa, "r") as f:
47
+ seq_count = 0
48
+ seq_length = 0
49
+ for line in f:
50
+ if line.startswith(">"):
51
+ seq_count += 1
52
+ else:
53
+ seq_length = max(seq_length, len(line.strip()))
54
+ alignment_stats["sequences"] = seq_count
55
+ alignment_stats["length"] = seq_length
56
+
57
+ # Write normalized output
58
+ with open(output_tsv, "w") as f:
59
+ f.write("genome\tmarkers_found\talignment_sequences\talignment_length\n")
60
+ for marker in markers_data:
61
+ genome = marker.get("genome", "unknown")
62
+ markers_found = marker.get("markers", "0")
63
+ f.write(f"{genome}\t{markers_found}\t{alignment_stats['sequences']}\t{alignment_stats['length']}\n")
64
+
65
+ return {
66
+ "markers_file": markers_tsv,
67
+ "alignment_file": user_msa,
68
+ "output_file": output_tsv,
69
+ "marker_count": len(markers_data),
70
+ "alignment_sequences": alignment_stats["sequences"],
71
+ "alignment_length": alignment_stats["length"]
72
+ }
73
+
74
+ @mcp.tool()
75
+ def identify_and_align_genome_markers(
76
+ genome_dir: str,
77
+ database_pointer: str,
78
+ identify_dir: str,
79
+ align_dir: str,
80
+ output_tsv: str
81
+ ) -> dict:
82
+ """
83
+ Identify GTDB bacterial marker genes in a pinned genome and produce a
84
+ canonically masked user-only alignment using the verified r89 reference package.
85
+ """
86
+ # Step 1: Read database pointer
87
+ gtdbtk_data_path = read_database_pointer(database_pointer)
88
+ env = os.environ.copy()
89
+ env["GTDBTK_DATA_PATH"] = gtdbtk_data_path
90
+
91
+ # Create output directories
92
+ os.makedirs(identify_dir, exist_ok=True)
93
+ os.makedirs(align_dir, exist_ok=True)
94
+
95
+ # Step 2: Run gtdbtk identify
96
+ identify_cmd = [
97
+ "gtdbtk",
98
+ "identify",
99
+ "--genome_dir", genome_dir,
100
+ "--out_dir", identify_dir,
101
+ "--extension", "fna",
102
+ "--cpus", "2"
103
+ ]
104
+ identify_result = subprocess.run(
105
+ identify_cmd,
106
+ capture_output=True,
107
+ text=True,
108
+ env=env,
109
+ check=False
110
+ )
111
+ if identify_result.returncode != 0:
112
+ raise RuntimeError(
113
+ f"gtdbtk identify failed with exit code {identify_result.returncode}\n"
114
+ f"stdout: {identify_result.stdout}\n"
115
+ f"stderr: {identify_result.stderr}"
116
+ )
117
+
118
+ # Locate the markers TSV produced by identify
119
+ markers_tsv = None
120
+ for root, dirs, files in os.walk(identify_dir):
121
+ for fname in files:
122
+ if fname.endswith("_markers_summary.tsv") or fname == "markers_summary.tsv":
123
+ markers_tsv = os.path.join(root, fname)
124
+ break
125
+ if markers_tsv:
126
+ break
127
+ if not markers_tsv:
128
+ # Try common patterns
129
+ candidates = [
130
+ os.path.join(identify_dir, "identify", "markers_summary.tsv"),
131
+ os.path.join(identify_dir, "markers_summary.tsv"),
132
+ os.path.join(identify_dir, "gtdbtk", "identify", "markers_summary.tsv")
133
+ ]
134
+ for cand in candidates:
135
+ if os.path.exists(cand):
136
+ markers_tsv = cand
137
+ break
138
+ if not markers_tsv:
139
+ raise RuntimeError(f"Could not find markers summary TSV in {identify_dir}")
140
+
141
+ # Step 3: Run gtdbtk align
142
+ align_cmd = [
143
+ "gtdbtk",
144
+ "align",
145
+ "--identify_dir", identify_dir,
146
+ "--out_dir", align_dir,
147
+ "--skip_gtdb_refs",
148
+ "--cpus", "2"
149
+ ]
150
+ align_result = subprocess.run(
151
+ align_cmd,
152
+ capture_output=True,
153
+ text=True,
154
+ env=env,
155
+ check=False
156
+ )
157
+ if align_result.returncode != 0:
158
+ raise RuntimeError(
159
+ f"gtdbtk align failed with exit code {align_result.returncode}\n"
160
+ f"stdout: {align_result.stdout}\n"
161
+ f"stderr: {align_result.stderr}"
162
+ )
163
+
164
+ # Locate the user MSA file produced by align
165
+ user_msa = None
166
+ for root, dirs, files in os.walk(align_dir):
167
+ for fname in files:
168
+ if fname.endswith(".fna") or fname.endswith(".fasta") or fname.endswith(".msa"):
169
+ user_msa = os.path.join(root, fname)
170
+ break
171
+ if user_msa:
172
+ break
173
+ if not user_msa:
174
+ # Common patterns
175
+ candidates = [
176
+ os.path.join(align_dir, "align", "user_msa.fasta"),
177
+ os.path.join(align_dir, "user_msa.fasta"),
178
+ os.path.join(align_dir, "gtdbtk", "align", "user_msa.fasta")
179
+ ]
180
+ for cand in candidates:
181
+ if os.path.exists(cand):
182
+ user_msa = cand
183
+ break
184
+ if not user_msa:
185
+ raise RuntimeError(f"Could not find user MSA file in {align_dir}")
186
+
187
+ # Step 4: Normalize markers
188
+ normalize_result = normalize_gtdbtk_markers(markers_tsv, user_msa, output_tsv)
189
+
190
+ return {
191
+ "status": "success",
192
+ "identify_dir": identify_dir,
193
+ "align_dir": align_dir,
194
+ "markers_tsv": markers_tsv,
195
+ "user_msa": user_msa,
196
+ "output_tsv": output_tsv,
197
+ "normalization": normalize_result
198
+ }
199
+
200
+ if __name__ == "__main__":
201
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/hicexplorer_find_restriction_sites_test_server.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+ import subprocess
4
+ import sys
5
+ from pathlib import Path
6
+ from mcp.server.fastmcp import FastMCP
7
+
8
+ mcp = FastMCP("hicexplorer")
9
+
10
+ @mcp.tool()
11
+ def find_restriction_sites(reference_fasta: str, output_bed: str) -> dict:
12
+ """
13
+ Find both-strand ACGT restriction-pattern occurrences and emit sorted BED.
14
+
15
+ Args:
16
+ reference_fasta: Path to the reference FASTA file.
17
+ output_bed: Path where the output BED file will be written.
18
+ """
19
+ # Validate required parameters
20
+ if not reference_fasta:
21
+ raise ValueError("reference_fasta is required")
22
+ if not output_bed:
23
+ raise ValueError("output_bed is required")
24
+
25
+ # Create output parent directories
26
+ output_bed_path = Path(output_bed)
27
+ output_bed_path.parent.mkdir(parents=True, exist_ok=True)
28
+
29
+ # Build the command
30
+ cmd = [
31
+ "findRestSite",
32
+ "-f",
33
+ reference_fasta,
34
+ "-p",
35
+ "ACGT",
36
+ "-o",
37
+ output_bed,
38
+ ]
39
+
40
+ # Execute the command
41
+ try:
42
+ result = subprocess.run(
43
+ cmd,
44
+ capture_output=True,
45
+ text=True,
46
+ check=False,
47
+ shell=False,
48
+ )
49
+ except FileNotFoundError as e:
50
+ raise RuntimeError(f"Executable 'findRestSite' not found: {e}") from e
51
+ except Exception as e:
52
+ raise RuntimeError(f"Failed to execute command: {e}") from e
53
+
54
+ # Check exit code
55
+ if result.returncode != 0:
56
+ error_msg = result.stderr.strip() if result.stderr.strip() else "Unknown error"
57
+ raise RuntimeError(
58
+ f"Command failed with exit code {result.returncode}: {error_msg}"
59
+ )
60
+
61
+ # Verify output file was created
62
+ if not output_bed_path.exists():
63
+ raise RuntimeError(f"Output file {output_bed} was not created")
64
+
65
+ # Return structured metadata
66
+ return {
67
+ "endpoint": "find_restriction_sites",
68
+ "status": "success",
69
+ "command": cmd,
70
+ "exit_code": result.returncode,
71
+ "stdout": result.stdout,
72
+ "stderr": result.stderr,
73
+ "output_bed": str(output_bed_path),
74
+ "output_bed_size": output_bed_path.stat().st_size,
75
+ }
76
+
77
+ if __name__ == "__main__":
78
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/hmmer_build_protein_hmm_test_server.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ import subprocess
3
+ import os
4
+ import json
5
+ import sys
6
+
7
+ mcp = FastMCP("hmmer")
8
+
9
+ @mcp.tool()
10
+ def build_protein_hmm(alignment_file: str, output_hmm: str, output_stats: str) -> dict:
11
+ """
12
+ Build an amino-acid HMM from aligned FASTA, then report deterministic model statistics.
13
+
14
+ Args:
15
+ alignment_file: Path to the aligned FASTA file (input)
16
+ output_hmm: Path where the built HMM will be written
17
+ output_stats: Path where the model statistics (from hmmstat) will be written
18
+ """
19
+ # Create output parent directories
20
+ for path in [output_hmm, output_stats]:
21
+ parent = os.path.dirname(os.path.abspath(path))
22
+ os.makedirs(parent, exist_ok=True)
23
+
24
+ # Step 1: Run hmmbuild
25
+ hmmbuild_cmd = [
26
+ "hmmbuild",
27
+ "--amino",
28
+ "--informat",
29
+ "afa",
30
+ output_hmm,
31
+ alignment_file
32
+ ]
33
+
34
+ try:
35
+ result1 = subprocess.run(
36
+ hmmbuild_cmd,
37
+ capture_output=True,
38
+ text=True,
39
+ check=False
40
+ )
41
+ if result1.returncode != 0:
42
+ raise RuntimeError(
43
+ f"hmmbuild failed with exit code {result1.returncode}\n"
44
+ f"stdout: {result1.stdout}\n"
45
+ f"stderr: {result1.stderr}"
46
+ )
47
+ except FileNotFoundError:
48
+ raise RuntimeError("hmmbuild executable not found. Ensure hmmer is installed and in PATH.")
49
+ except Exception as e:
50
+ raise RuntimeError(f"Error running hmmbuild: {str(e)}")
51
+
52
+ # Step 2: Run hmmstat and capture stdout to output_stats
53
+ hmmstat_cmd = [
54
+ "hmmstat",
55
+ output_hmm
56
+ ]
57
+
58
+ try:
59
+ result2 = subprocess.run(
60
+ hmmstat_cmd,
61
+ capture_output=True,
62
+ text=True,
63
+ check=False
64
+ )
65
+ if result2.returncode != 0:
66
+ raise RuntimeError(
67
+ f"hmmstat failed with exit code {result2.returncode}\n"
68
+ f"stdout: {result2.stdout}\n"
69
+ f"stderr: {result2.stderr}"
70
+ )
71
+
72
+ # Write hmmstat stdout to output_stats
73
+ with open(output_stats, 'w') as f:
74
+ f.write(result2.stdout)
75
+ except FileNotFoundError:
76
+ raise RuntimeError("hmmstat executable not found. Ensure hmmer is installed and in PATH.")
77
+ except Exception as e:
78
+ raise RuntimeError(f"Error running hmmstat: {str(e)}")
79
+
80
+ # Return structured metadata
81
+ return {
82
+ "status": "success",
83
+ "output_hmm": output_hmm,
84
+ "output_stats": output_stats,
85
+ "hmmbuild_stdout": result1.stdout,
86
+ "hmmbuild_stderr": result1.stderr,
87
+ "hmmstat_stdout": result2.stdout,
88
+ "hmmstat_stderr": result2.stderr
89
+ }
90
+
91
+ if __name__ == "__main__":
92
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/htseq_count_reads_test_server.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ import subprocess
3
+ import os
4
+ import json
5
+ import sys
6
+ from pathlib import Path
7
+
8
+ mcp = FastMCP("htseq")
9
+
10
+
11
+ @mcp.tool()
12
+ def count_reads(input_bam: str, features_gtf: str, output_counts: str) -> dict:
13
+ """
14
+ Count reads in a BAM file against features in a GTF file using htseq-count.
15
+
16
+ Args:
17
+ input_bam: Path to the input BAM file.
18
+ features_gtf: Path to the GTF file with features.
19
+ output_counts: Path where the output counts file will be written.
20
+
21
+ Returns:
22
+ A dictionary with metadata about the execution.
23
+ """
24
+ # Create output parent directory if it doesn't exist
25
+ output_path = Path(output_counts)
26
+ output_path.parent.mkdir(parents=True, exist_ok=True)
27
+
28
+ # Build the command exactly as specified in the execution plan
29
+ cmd = [
30
+ "htseq-count",
31
+ "-f",
32
+ "bam",
33
+ "-r",
34
+ "pos",
35
+ "-s",
36
+ "no",
37
+ "-t",
38
+ "exon",
39
+ "-i",
40
+ "gene_id",
41
+ "-c",
42
+ output_counts,
43
+ input_bam,
44
+ features_gtf,
45
+ ]
46
+
47
+ try:
48
+ # Run the command without shell=True
49
+ result = subprocess.run(
50
+ cmd,
51
+ capture_output=True,
52
+ text=True,
53
+ check=False,
54
+ )
55
+
56
+ if result.returncode != 0:
57
+ raise RuntimeError(
58
+ f"htseq-count failed with exit code {result.returncode}\n"
59
+ f"stderr: {result.stderr}"
60
+ )
61
+
62
+ # Verify output file was created
63
+ if not output_path.exists():
64
+ raise RuntimeError(
65
+ f"htseq-count completed but output file {output_counts} was not created"
66
+ )
67
+
68
+ return {
69
+ "endpoint": "count_reads",
70
+ "input_bam": input_bam,
71
+ "features_gtf": features_gtf,
72
+ "output_counts": output_counts,
73
+ "exit_code": result.returncode,
74
+ "stdout": result.stdout,
75
+ "stderr": result.stderr,
76
+ "output_file_exists": True,
77
+ "output_file_size": output_path.stat().st_size,
78
+ }
79
+
80
+ except FileNotFoundError:
81
+ raise RuntimeError(
82
+ "htseq-count executable not found. Please ensure htseq is installed and in PATH."
83
+ )
84
+ except Exception as e:
85
+ raise RuntimeError(f"Error executing htseq-count: {str(e)}")
86
+
87
+
88
+ if __name__ == "__main__":
89
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/htslib_bgzip_compress_test_server.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ import subprocess
3
+ import os
4
+ import json
5
+ from pathlib import Path
6
+
7
+ mcp = FastMCP("htslib")
8
+
9
+ @mcp.tool()
10
+ def bgzip_compress(input_file: str, output_gzip: str) -> dict:
11
+ """
12
+ Compress a file using bgzip (BGZF compression).
13
+
14
+ Args:
15
+ input_file: Path to the input file to compress
16
+ output_gzip: Path where the compressed output will be written
17
+ """
18
+ # Create parent directory for output if it doesn't exist
19
+ output_path = Path(output_gzip)
20
+ output_path.parent.mkdir(parents=True, exist_ok=True)
21
+
22
+ # Build command: bgzip -c {input_file}
23
+ cmd = ["bgzip", "-c", input_file]
24
+
25
+ # Execute the command, capturing stdout as binary
26
+ result = subprocess.run(
27
+ cmd,
28
+ stdout=subprocess.PIPE,
29
+ stderr=subprocess.PIPE,
30
+ check=False
31
+ )
32
+
33
+ # Raise on non-zero exit
34
+ if result.returncode != 0:
35
+ stderr_msg = result.stderr.decode('utf-8', errors='replace') if result.stderr else ""
36
+ raise RuntimeError(f"bgzip failed with exit code {result.returncode}: {stderr_msg}")
37
+
38
+ # Write captured stdout to output file
39
+ with open(output_path, 'wb') as f:
40
+ f.write(result.stdout)
41
+
42
+ # Return structured metadata
43
+ return {
44
+ "status": "success",
45
+ "input_file": input_file,
46
+ "output_gzip": output_gzip,
47
+ "output_size_bytes": len(result.stdout),
48
+ "exit_code": result.returncode
49
+ }
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/humann2_renormalize_gene_families_test_server.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ import subprocess
3
+ import os
4
+ import json
5
+ import sys
6
+
7
+ mcp = FastMCP("humann2")
8
+
9
+ @mcp.tool()
10
+ def renormalize_gene_families(input_tsv: str, output_tsv: str) -> dict:
11
+ """
12
+ Convert a pinned stratified HUMAnN2 gene-family table from raw abundance units to community relative abundance.
13
+
14
+ Args:
15
+ input_tsv: Path to input gene-family table in TSV format
16
+ output_tsv: Path where the renormalized output TSV will be written
17
+ """
18
+ # Create output parent directory if it doesn't exist
19
+ output_dir = os.path.dirname(os.path.abspath(output_tsv))
20
+ os.makedirs(output_dir, exist_ok=True)
21
+
22
+ # Build the command as specified in the execution plan
23
+ cmd = [
24
+ "humann2_renorm_table",
25
+ "-i", input_tsv,
26
+ "-u", "relab",
27
+ "-m", "community",
28
+ "-s", "y",
29
+ "-p",
30
+ "-o", output_tsv
31
+ ]
32
+
33
+ try:
34
+ # Execute the command without shell=True
35
+ result = subprocess.run(
36
+ cmd,
37
+ capture_output=True,
38
+ text=True,
39
+ check=False
40
+ )
41
+
42
+ if result.returncode != 0:
43
+ raise RuntimeError(
44
+ f"humann2_renorm_table failed with exit code {result.returncode}\n"
45
+ f"stderr: {result.stderr}"
46
+ )
47
+
48
+ # Verify output file was created
49
+ if not os.path.isfile(output_tsv):
50
+ raise RuntimeError(f"Output file {output_tsv} was not created")
51
+
52
+ # Return structured metadata
53
+ return {
54
+ "status": "success",
55
+ "input_tsv": input_tsv,
56
+ "output_tsv": output_tsv,
57
+ "command": " ".join(cmd),
58
+ "returncode": result.returncode,
59
+ "stdout": result.stdout,
60
+ "stderr": result.stderr,
61
+ "output_size_bytes": os.path.getsize(output_tsv)
62
+ }
63
+
64
+ except FileNotFoundError:
65
+ raise RuntimeError(
66
+ "humann2_renorm_table executable not found. "
67
+ "Ensure humann2 2.8.1 is installed and available in PATH."
68
+ )
69
+ except Exception as e:
70
+ raise RuntimeError(f"Error executing humann2_renorm_table: {str(e)}")
71
+
72
+ if __name__ == "__main__":
73
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/illumina-interop_dump_q_metrics_test_server.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ import subprocess
3
+ import os
4
+ import json
5
+ import sys
6
+ from pathlib import Path
7
+
8
+ mcp = FastMCP("illumina-interop")
9
+
10
+
11
+ @mcp.tool()
12
+ def dump_q_metrics(run_folder: str, output_csv: str) -> dict:
13
+ """
14
+ Decode Q-score histograms and Q20/Q30 summaries from a deterministic local Illumina run folder.
15
+
16
+ Args:
17
+ run_folder: Path to the Illumina run folder containing InterOp metric files.
18
+ output_csv: Path where the Q-score metrics CSV output will be written.
19
+ """
20
+ # Validate required parameters
21
+ if not run_folder:
22
+ raise ValueError("run_folder is required")
23
+ if not output_csv:
24
+ raise ValueError("output_csv is required")
25
+
26
+ # Create output parent directories
27
+ output_path = Path(output_csv)
28
+ output_path.parent.mkdir(parents=True, exist_ok=True)
29
+
30
+ # Build command according to execution plan
31
+ cmd = [
32
+ "interop_dumptext",
33
+ run_folder,
34
+ "--metric=Q"
35
+ ]
36
+
37
+ # Execute the command
38
+ try:
39
+ result = subprocess.run(
40
+ cmd,
41
+ capture_output=True,
42
+ text=True,
43
+ check=False
44
+ )
45
+ except FileNotFoundError as e:
46
+ raise RuntimeError(f"interop_dumptext executable not found: {e}") from e
47
+ except Exception as e:
48
+ raise RuntimeError(f"Failed to execute interop_dumptext: {e}") from e
49
+
50
+ # Check for non-zero exit
51
+ if result.returncode != 0:
52
+ error_msg = result.stderr.strip() if result.stderr else f"Exit code {result.returncode}"
53
+ raise RuntimeError(f"interop_dumptext failed: {error_msg}")
54
+
55
+ # Write stdout to output_csv
56
+ try:
57
+ with open(output_path, 'w', encoding='utf-8') as f:
58
+ f.write(result.stdout)
59
+ except Exception as e:
60
+ raise RuntimeError(f"Failed to write output to {output_csv}: {e}") from e
61
+
62
+ # Return structured metadata
63
+ return {
64
+ "endpoint": "dump_q_metrics",
65
+ "run_folder": run_folder,
66
+ "output_csv": output_csv,
67
+ "exit_code": result.returncode,
68
+ "stdout_bytes": len(result.stdout.encode('utf-8')),
69
+ "stderr_bytes": len(result.stderr.encode('utf-8')),
70
+ "output_file_size": output_path.stat().st_size if output_path.exists() else 0,
71
+ "status": "success"
72
+ }
73
+
74
+
75
+ if __name__ == "__main__":
76
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/infernal_build_and_align_cm_test_server.py ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ import subprocess
3
+ import os
4
+ import json
5
+ import sys
6
+ from pathlib import Path
7
+
8
+ mcp = FastMCP("infernal")
9
+
10
+ @mcp.tool()
11
+ def build_and_align_cm(
12
+ training_alignment: str,
13
+ query_fasta: str,
14
+ output_cm: str,
15
+ output_stockholm: str
16
+ ) -> str:
17
+ """
18
+ Build a covariance model from a training alignment (without secondary structure annotation)
19
+ and align a query FASTA against it, producing a Stockholm alignment.
20
+
21
+ Args:
22
+ training_alignment: Path to the training alignment file (e.g., Stockholm format).
23
+ query_fasta: Path to the query FASTA file.
24
+ output_cm: Path where the built covariance model will be written.
25
+ output_stockholm: Path where the resulting alignment (Stockholm format) will be written.
26
+ """
27
+ # Create parent directories for output files
28
+ for out_path in [output_cm, output_stockholm]:
29
+ parent = Path(out_path).parent
30
+ if parent and not parent.exists():
31
+ parent.mkdir(parents=True, exist_ok=True)
32
+
33
+ # Step 1: cmbuild --noss -F {output_cm} {training_alignment}
34
+ cmbuild_cmd = [
35
+ "cmbuild",
36
+ "--noss",
37
+ "-F",
38
+ output_cm,
39
+ training_alignment
40
+ ]
41
+ try:
42
+ cmbuild_result = subprocess.run(
43
+ cmbuild_cmd,
44
+ capture_output=True,
45
+ text=True,
46
+ check=False
47
+ )
48
+ except FileNotFoundError as e:
49
+ return json.dumps({
50
+ "success": False,
51
+ "error": f"cmbuild executable not found: {e}",
52
+ "step": 1
53
+ })
54
+ if cmbuild_result.returncode != 0:
55
+ return json.dumps({
56
+ "success": False,
57
+ "error": f"cmbuild failed with exit code {cmbuild_result.returncode}",
58
+ "stderr": cmbuild_result.stderr,
59
+ "stdout": cmbuild_result.stdout,
60
+ "step": 1
61
+ })
62
+
63
+ # Step 2: cmalign -o {output_stockholm} {output_cm} {query_fasta}
64
+ cmalign_cmd = [
65
+ "cmalign",
66
+ "-o",
67
+ output_stockholm,
68
+ output_cm,
69
+ query_fasta
70
+ ]
71
+ try:
72
+ cmalign_result = subprocess.run(
73
+ cmalign_cmd,
74
+ capture_output=True,
75
+ text=True,
76
+ check=False
77
+ )
78
+ except FileNotFoundError as e:
79
+ return json.dumps({
80
+ "success": False,
81
+ "error": f"cmalign executable not found: {e}",
82
+ "step": 2
83
+ })
84
+ if cmalign_result.returncode != 0:
85
+ return json.dumps({
86
+ "success": False,
87
+ "error": f"cmalign failed with exit code {cmalign_result.returncode}",
88
+ "stderr": cmalign_result.stderr,
89
+ "stdout": cmalign_result.stdout,
90
+ "step": 2
91
+ })
92
+
93
+ # Verify output files were created
94
+ if not os.path.isfile(output_cm):
95
+ return json.dumps({
96
+ "success": False,
97
+ "error": f"Expected output CM file not created: {output_cm}",
98
+ "step": 1
99
+ })
100
+ if not os.path.isfile(output_stockholm):
101
+ return json.dumps({
102
+ "success": False,
103
+ "error": f"Expected output Stockholm file not created: {output_stockholm}",
104
+ "step": 2
105
+ })
106
+
107
+ return json.dumps({
108
+ "success": True,
109
+ "output_cm": output_cm,
110
+ "output_stockholm": output_stockholm,
111
+ "cmbuild_stdout": cmbuild_result.stdout,
112
+ "cmbuild_stderr": cmbuild_result.stderr,
113
+ "cmalign_stdout": cmalign_result.stdout,
114
+ "cmalign_stderr": cmalign_result.stderr
115
+ })
116
+
117
+ if __name__ == "__main__":
118
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/intarna_predict_rna_interaction_test_server.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ import subprocess
3
+ import os
4
+ import json
5
+ import sys
6
+ from pathlib import Path
7
+
8
+ mcp = FastMCP("intarna")
9
+
10
+ @mcp.tool()
11
+ def predict_rna_interaction(target_rna: str, query_rna: str, output_csv: str) -> dict:
12
+ """
13
+ Predict RNA-RNA interaction using IntaRNA.
14
+
15
+ Args:
16
+ target_rna: Path to target RNA sequence file (FASTA format)
17
+ query_rna: Path to query RNA sequence file (FASTA format)
18
+ output_csv: Path where the CSV output will be written
19
+
20
+ Returns:
21
+ Dictionary with execution metadata and output file path
22
+ """
23
+ # Create output parent directory if it doesn't exist
24
+ output_path = Path(output_csv)
25
+ output_path.parent.mkdir(parents=True, exist_ok=True)
26
+
27
+ # Build command according to execution plan
28
+ cmd = [
29
+ "IntaRNA",
30
+ "-t", target_rna,
31
+ "-q", query_rna,
32
+ "--noSeed",
33
+ "--outMode=C",
34
+ f"--out={output_csv}"
35
+ ]
36
+
37
+ try:
38
+ # Execute the command
39
+ result = subprocess.run(
40
+ cmd,
41
+ capture_output=True,
42
+ text=True,
43
+ check=False
44
+ )
45
+
46
+ # Check for non-zero exit
47
+ if result.returncode != 0:
48
+ raise RuntimeError(
49
+ f"IntaRNA failed with exit code {result.returncode}\n"
50
+ f"stderr: {result.stderr}"
51
+ )
52
+
53
+ # Verify output file was created
54
+ if not output_path.exists():
55
+ raise RuntimeError(f"Output file was not created: {output_csv}")
56
+
57
+ # Return structured metadata
58
+ return {
59
+ "status": "success",
60
+ "output_file": str(output_path),
61
+ "command": cmd,
62
+ "returncode": result.returncode,
63
+ "stdout": result.stdout,
64
+ "stderr": result.stderr,
65
+ "output_size_bytes": output_path.stat().st_size
66
+ }
67
+
68
+ except FileNotFoundError:
69
+ raise RuntimeError("IntaRNA executable not found in PATH")
70
+ except Exception as e:
71
+ raise RuntimeError(f"Error executing IntaRNA: {str(e)}")
72
+
73
+ if __name__ == "__main__":
74
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/ipython-cluster-helper_normalize_scheduler_resources_test_server.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ import subprocess
3
+ import json
4
+ import os
5
+ import sys
6
+
7
+ mcp = FastMCP("ipython-cluster-helper")
8
+
9
+
10
+ @mcp.tool()
11
+ def normalize_scheduler_resources(resource_json: str, output_json: str) -> dict:
12
+ """
13
+ Normalize scheduler resource specifications (time and memory) using
14
+ ipython-cluster-helper's parser and conversion utilities.
15
+
16
+ Args:
17
+ resource_json: Path to a JSON file containing resource specifications.
18
+ Expected structure: {"time": <string>, "memory": <number>,
19
+ "memory_unit": <string>}
20
+ output_json: Path where the normalized result will be written as JSON.
21
+
22
+ Returns:
23
+ A dictionary with metadata about the invocation, including the
24
+ normalized values.
25
+ """
26
+ # Validate input file exists
27
+ if not os.path.isfile(resource_json):
28
+ raise FileNotFoundError(f"Input resource file not found: {resource_json}")
29
+
30
+ # Create output parent directory if needed
31
+ output_dir = os.path.dirname(os.path.abspath(output_json))
32
+ os.makedirs(output_dir, exist_ok=True)
33
+
34
+ # Read input to validate structure before invoking
35
+ try:
36
+ with open(resource_json, "r") as f:
37
+ resource_data = json.load(f)
38
+ except json.JSONDecodeError as e:
39
+ raise ValueError(f"Invalid JSON in resource file: {e}")
40
+
41
+ # Validate required keys
42
+ required_keys = {"time", "memory", "memory_unit"}
43
+ missing = required_keys - set(resource_data.keys())
44
+ if missing:
45
+ raise ValueError(f"Missing required keys in resource JSON: {missing}")
46
+
47
+ # Build the Python one-liner that exercises the package's utilities
48
+ code = (
49
+ "import json,sys; "
50
+ "from cluster_helper.slurm import SlurmTime,set_timelimit; "
51
+ "from cluster_helper.utils import convert_mb; "
52
+ "c=json.load(open(sys.argv[1])); "
53
+ "d={'parsed':repr(SlurmTime(c['time'])),"
54
+ "'time_limit':set_timelimit({'time':c['time']})['timelimit'],"
55
+ "'memory_in_gb':convert_mb(c['memory'],c['memory_unit'])}; "
56
+ "open(sys.argv[2],'w').write(json.dumps(d,sort_keys=True)+'\\n')"
57
+ )
58
+
59
+ cmd = ["python", "-c", code, resource_json, output_json]
60
+
61
+ try:
62
+ result = subprocess.run(
63
+ cmd,
64
+ capture_output=True,
65
+ text=True,
66
+ check=False,
67
+ )
68
+ except OSError as e:
69
+ raise RuntimeError(f"Failed to execute python: {e}")
70
+
71
+ if result.returncode != 0:
72
+ stderr_msg = result.stderr.strip() if result.stderr else "No stderr output"
73
+ raise RuntimeError(
74
+ f"Command failed with exit code {result.returncode}: {stderr_msg}"
75
+ )
76
+
77
+ # Read the output file to include normalized values in metadata
78
+ try:
79
+ with open(output_json, "r") as f:
80
+ normalized = json.load(f)
81
+ except (OSError, json.JSONDecodeError) as e:
82
+ raise RuntimeError(f"Failed to read output file: {e}")
83
+
84
+ return {
85
+ "endpoint": "normalize_scheduler_resources",
86
+ "input_file": resource_json,
87
+ "output_file": output_json,
88
+ "normalized": normalized,
89
+ "exit_code": result.returncode,
90
+ "stdout": result.stdout,
91
+ "stderr": result.stderr,
92
+ }
93
+
94
+
95
+ if __name__ == "__main__":
96
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/iqtree_infer_protein_tree_test_server.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ import subprocess
3
+ import os
4
+ import json
5
+ from pathlib import Path
6
+
7
+ mcp = FastMCP("iqtree")
8
+
9
+ @mcp.tool()
10
+ def infer_protein_tree(alignment_file: str, output_prefix: str) -> dict:
11
+ """
12
+ Infer a protein tree using IQ-TREE with LG model, one thread, and seed 1.
13
+
14
+ Args:
15
+ alignment_file: Path to the input alignment file (PHYLIP/FASTA/NEXUS/CLUSTAL/MSF format)
16
+ output_prefix: Prefix for all output files generated by IQ-TREE
17
+
18
+ Returns:
19
+ Dictionary containing metadata about the inference run
20
+ """
21
+ # Create output parent directory if it doesn't exist
22
+ output_dir = os.path.dirname(output_prefix)
23
+ if output_dir:
24
+ os.makedirs(output_dir, exist_ok=True)
25
+
26
+ # Build the command
27
+ cmd = [
28
+ "iqtree",
29
+ "-s", alignment_file,
30
+ "-m", "LG",
31
+ "-nt", "1",
32
+ "-seed", "1",
33
+ "-pre", output_prefix
34
+ ]
35
+
36
+ # Execute the command
37
+ try:
38
+ result = subprocess.run(
39
+ cmd,
40
+ capture_output=True,
41
+ text=True,
42
+ check=False
43
+ )
44
+
45
+ if result.returncode != 0:
46
+ raise RuntimeError(
47
+ f"IQ-TREE failed with exit code {result.returncode}\n"
48
+ f"stdout: {result.stdout}\n"
49
+ f"stderr: {result.stderr}"
50
+ )
51
+
52
+ # Collect output file paths based on the prefix
53
+ output_files = []
54
+ prefix = output_prefix
55
+ # Common IQ-TREE output files
56
+ possible_extensions = [
57
+ ".treefile", ".iqtree", ".log", ".ckp.gz",
58
+ ".mldist", ".contree", ".splits.nex", ".trees"
59
+ ]
60
+ for ext in possible_extensions:
61
+ candidate = prefix + ext
62
+ if os.path.exists(candidate):
63
+ output_files.append(candidate)
64
+
65
+ return {
66
+ "status": "success",
67
+ "command": " ".join(cmd),
68
+ "alignment_file": alignment_file,
69
+ "output_prefix": output_prefix,
70
+ "output_files": output_files,
71
+ "stdout": result.stdout,
72
+ "stderr": result.stderr,
73
+ "returncode": result.returncode
74
+ }
75
+
76
+ except FileNotFoundError:
77
+ raise RuntimeError("IQ-TREE executable not found. Please ensure it is installed and in PATH.")
78
+ except Exception as e:
79
+ raise RuntimeError(f"Error executing IQ-TREE: {str(e)}")
80
+
81
+ if __name__ == "__main__":
82
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/itsxpress_trim_fungal_its_test_server.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ import subprocess
3
+ import os
4
+ import json
5
+ from pathlib import Path
6
+
7
+ mcp = FastMCP("itsxpress")
8
+
9
+ @mcp.tool()
10
+ def trim_fungal_its(
11
+ input_fastq: str,
12
+ trimmed_fastq: str,
13
+ log_file: str
14
+ ) -> dict:
15
+ """
16
+ Trim the complete fungal ITS region from one pinned NCBI Saccharomyces cerevisiae rDNA read using one thread.
17
+
18
+ Args:
19
+ input_fastq: Path to input FASTQ file
20
+ trimmed_fastq: Path to output trimmed FASTQ file
21
+ log_file: Path to log file
22
+ """
23
+ # Create parent directories for output files
24
+ for path in [trimmed_fastq, log_file]:
25
+ parent = Path(path).parent
26
+ if parent and not parent.exists():
27
+ parent.mkdir(parents=True, exist_ok=True)
28
+
29
+ # Build command according to execution plan
30
+ cmd = [
31
+ "itsxpress",
32
+ "--fastq", input_fastq,
33
+ "--single_end",
34
+ "--outfile", trimmed_fastq,
35
+ "--region", "ALL",
36
+ "--taxa", "Fungi",
37
+ "--cluster_id", "1.0",
38
+ "--threads", "1",
39
+ "--log", log_file
40
+ ]
41
+
42
+ # Execute command
43
+ result = subprocess.run(
44
+ cmd,
45
+ capture_output=True,
46
+ text=True,
47
+ check=False
48
+ )
49
+
50
+ if result.returncode != 0:
51
+ raise RuntimeError(
52
+ f"itsxpress failed with exit code {result.returncode}\n"
53
+ f"stdout: {result.stdout}\n"
54
+ f"stderr: {result.stderr}"
55
+ )
56
+
57
+ # Return structured metadata
58
+ return {
59
+ "endpoint": "trim_fungal_its",
60
+ "input_fastq": input_fastq,
61
+ "trimmed_fastq": trimmed_fastq,
62
+ "log_file": log_file,
63
+ "exit_code": result.returncode,
64
+ "stdout": result.stdout,
65
+ "stderr": result.stderr
66
+ }
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/ivar_consensus_from_pileup_test_server.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import subprocess
3
+ import sys
4
+ from pathlib import Path
5
+ from mcp.server.fastmcp import FastMCP
6
+
7
+ mcp = FastMCP("ivar-consensus")
8
+
9
+ @mcp.tool()
10
+ def consensus_from_pileup(input_pileup: str, output_prefix: str) -> dict:
11
+ """
12
+ Generate a consensus sequence from a pileup file using ivar consensus.
13
+
14
+ Args:
15
+ input_pileup: Path to the input pileup file (read from stdin)
16
+ output_prefix: Prefix for output files (e.g., output.fa and output.qual.txt)
17
+
18
+ Returns:
19
+ Dictionary with output file paths and metadata
20
+ """
21
+ # Validate input file exists
22
+ input_path = Path(input_pileup)
23
+ if not input_path.exists():
24
+ raise FileNotFoundError(f"Input pileup file not found: {input_pileup}")
25
+
26
+ # Create output parent directory if needed
27
+ output_prefix_path = Path(output_prefix)
28
+ output_dir = output_prefix_path.parent
29
+ if output_dir and not output_dir.exists():
30
+ output_dir.mkdir(parents=True, exist_ok=True)
31
+
32
+ # Build command: ivar consensus -p {output_prefix} -q 0 -t 0 -m 1 < {input_pileup}
33
+ cmd = [
34
+ "ivar",
35
+ "consensus",
36
+ "-p", output_prefix,
37
+ "-q", "0",
38
+ "-t", "0",
39
+ "-m", "1"
40
+ ]
41
+
42
+ # Run command with input file as stdin
43
+ try:
44
+ with open(input_pileup, "rb") as f:
45
+ result = subprocess.run(
46
+ cmd,
47
+ stdin=f,
48
+ capture_output=True,
49
+ text=False,
50
+ check=False
51
+ )
52
+ except OSError as e:
53
+ raise RuntimeError(f"Failed to execute ivar consensus: {e}")
54
+
55
+ # Check exit code
56
+ if result.returncode != 0:
57
+ stderr_text = result.stderr.decode("utf-8", errors="replace") if result.stderr else ""
58
+ raise RuntimeError(
59
+ f"ivar consensus failed with exit code {result.returncode}: {stderr_text}"
60
+ )
61
+
62
+ # Determine output files (ivar consensus produces .fa and .qual.txt)
63
+ fasta_path = f"{output_prefix}.fa"
64
+ qual_path = f"{output_prefix}.qual.txt"
65
+
66
+ # Verify outputs exist
67
+ if not os.path.exists(fasta_path):
68
+ raise RuntimeError(f"Expected output FASTA file not created: {fasta_path}")
69
+
70
+ # Return structured metadata
71
+ return {
72
+ "status": "success",
73
+ "output_fasta": fasta_path,
74
+ "output_quality": qual_path if os.path.exists(qual_path) else None,
75
+ "command": " ".join(cmd),
76
+ "exit_code": result.returncode,
77
+ "stderr": result.stderr.decode("utf-8", errors="replace") if result.stderr else ""
78
+ }
79
+
80
+ if __name__ == "__main__":
81
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/kallisto_build_transcript_index_test_server.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ import subprocess
3
+ import os
4
+ import sys
5
+ import json
6
+ from pathlib import Path
7
+
8
+ mcp = FastMCP("kallisto-index")
9
+
10
+ @mcp.tool()
11
+ def build_transcript_index(transcripts_fasta: str, output_index: str) -> dict:
12
+ """
13
+ Build a kallisto transcript index from a FASTA file.
14
+
15
+ Args:
16
+ transcripts_fasta: Path to the transcript FASTA file
17
+ output_index: Path where the kallisto index will be written
18
+ """
19
+ # Create output parent directory if needed
20
+ output_path = Path(output_index)
21
+ if output_path.parent and not output_path.parent.exists():
22
+ output_path.parent.mkdir(parents=True, exist_ok=True)
23
+
24
+ # Build command according to execution plan
25
+ cmd = [
26
+ "kallisto",
27
+ "index",
28
+ "-i",
29
+ output_index,
30
+ transcripts_fasta
31
+ ]
32
+
33
+ # Execute the command
34
+ try:
35
+ result = subprocess.run(
36
+ cmd,
37
+ capture_output=True,
38
+ text=True,
39
+ check=False
40
+ )
41
+ except FileNotFoundError:
42
+ raise RuntimeError("kallisto executable not found in PATH")
43
+
44
+ if result.returncode != 0:
45
+ error_msg = result.stderr.strip() or result.stdout.strip() or "Unknown error"
46
+ raise RuntimeError(f"kallisto index failed with exit code {result.returncode}: {error_msg}")
47
+
48
+ # Verify output file was created
49
+ if not output_path.exists():
50
+ raise RuntimeError(f"Expected output file {output_index} was not created")
51
+
52
+ # Return structured metadata
53
+ return {
54
+ "status": "success",
55
+ "command": cmd,
56
+ "exit_code": result.returncode,
57
+ "output_index": str(output_path.resolve()),
58
+ "transcripts_fasta": str(Path(transcripts_fasta).resolve()),
59
+ "stdout": result.stdout,
60
+ "stderr": result.stderr
61
+ }
62
+
63
+ if __name__ == "__main__":
64
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/kmc_count_kmers_test_server.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ import subprocess
3
+ import os
4
+ import json
5
+ from pathlib import Path
6
+
7
+ mcp = FastMCP("kmc")
8
+
9
+ @mcp.tool()
10
+ def count_kmers(
11
+ input_fastq: str,
12
+ output_prefix: str,
13
+ working_dir: str,
14
+ output_tsv: str
15
+ ) -> dict:
16
+ """
17
+ Count canonical 3-mers with minimum count 1, one thread, and 2 GB memory,
18
+ then dump text counts.
19
+ """
20
+ # Create working directory if it doesn't exist
21
+ Path(working_dir).mkdir(parents=True, exist_ok=True)
22
+
23
+ # Create parent directory for output_tsv if needed
24
+ output_tsv_path = Path(output_tsv)
25
+ if output_tsv_path.parent and not output_tsv_path.parent.exists():
26
+ output_tsv_path.parent.mkdir(parents=True, exist_ok=True)
27
+
28
+ # Step 1: Run kmc
29
+ kmc_cmd = [
30
+ "kmc",
31
+ "-k3",
32
+ "-ci1",
33
+ "-t1",
34
+ "-m2",
35
+ "-hp",
36
+ input_fastq,
37
+ output_prefix,
38
+ working_dir
39
+ ]
40
+
41
+ try:
42
+ kmc_result = subprocess.run(
43
+ kmc_cmd,
44
+ capture_output=True,
45
+ text=True,
46
+ check=False
47
+ )
48
+ except FileNotFoundError:
49
+ raise RuntimeError("kmc executable not found in PATH")
50
+
51
+ if kmc_result.returncode != 0:
52
+ raise RuntimeError(
53
+ f"kmc failed with exit code {kmc_result.returncode}\n"
54
+ f"stdout: {kmc_result.stdout}\n"
55
+ f"stderr: {kmc_result.stderr}"
56
+ )
57
+
58
+ # Step 2: Run kmc_dump
59
+ kmc_dump_cmd = [
60
+ "kmc_dump",
61
+ output_prefix,
62
+ output_tsv
63
+ ]
64
+
65
+ try:
66
+ dump_result = subprocess.run(
67
+ kmc_dump_cmd,
68
+ capture_output=True,
69
+ text=True,
70
+ check=False
71
+ )
72
+ except FileNotFoundError:
73
+ raise RuntimeError("kmc_dump executable not found in PATH")
74
+
75
+ if dump_result.returncode != 0:
76
+ raise RuntimeError(
77
+ f"kmc_dump failed with exit code {dump_result.returncode}\n"
78
+ f"stdout: {dump_result.stdout}\n"
79
+ f"stderr: {dump_result.stderr}"
80
+ )
81
+
82
+ # Return structured metadata
83
+ return {
84
+ "status": "success",
85
+ "endpoint": "count_kmers",
86
+ "input_fastq": input_fastq,
87
+ "output_prefix": output_prefix,
88
+ "working_dir": working_dir,
89
+ "output_tsv": output_tsv,
90
+ "kmc_command": " ".join(kmc_cmd),
91
+ "kmc_dump_command": " ".join(kmc_dump_cmd),
92
+ "kmc_stdout": kmc_result.stdout,
93
+ "kmc_stderr": kmc_result.stderr,
94
+ "kmc_dump_stdout": dump_result.stdout,
95
+ "kmc_dump_stderr": dump_result.stderr
96
+ }
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/krona_taxonomy_chart_test_server.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ import subprocess
3
+ import os
4
+ import json
5
+ from pathlib import Path
6
+
7
+ mcp = FastMCP("krona")
8
+
9
+ @mcp.tool()
10
+ def taxonomy_chart(input_table: str, output_html: str) -> dict:
11
+ """
12
+ Create a Krona chart from a text file.
13
+
14
+ Args:
15
+ input_table: Path to the input text file containing taxonomy data
16
+ output_html: Path where the output HTML chart will be written
17
+ """
18
+ # Create output parent directory if it doesn't exist
19
+ output_path = Path(output_html)
20
+ output_path.parent.mkdir(parents=True, exist_ok=True)
21
+
22
+ # Build the command
23
+ cmd = [
24
+ "ktImportText",
25
+ "-o",
26
+ output_html,
27
+ input_table
28
+ ]
29
+
30
+ # Execute the command
31
+ try:
32
+ result = subprocess.run(
33
+ cmd,
34
+ capture_output=True,
35
+ text=True,
36
+ check=False
37
+ )
38
+
39
+ if result.returncode != 0:
40
+ raise RuntimeError(
41
+ f"ktImportText failed with exit code {result.returncode}: "
42
+ f"{result.stderr}"
43
+ )
44
+
45
+ # Verify output file was created
46
+ if not output_path.exists():
47
+ raise RuntimeError(f"Output file {output_html} was not created")
48
+
49
+ return {
50
+ "status": "success",
51
+ "output_html": str(output_path),
52
+ "input_table": str(input_table),
53
+ "stdout": result.stdout,
54
+ "stderr": result.stderr
55
+ }
56
+
57
+ except FileNotFoundError:
58
+ raise RuntimeError("ktImportText executable not found. Ensure Krona is properly installed.")
59
+ except Exception as e:
60
+ raise RuntimeError(f"Error executing ktImportText: {str(e)}")
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/last_align_dna_test_server.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ import subprocess
3
+ import os
4
+ import json
5
+ from pathlib import Path
6
+
7
+ mcp = FastMCP("last-align-dna")
8
+
9
+ @mcp.tool()
10
+ def align_dna(
11
+ reference_fasta: str,
12
+ query_fasta: str,
13
+ database_prefix: str,
14
+ output_maf: str
15
+ ) -> str:
16
+ """
17
+ Build a nucleotide LAST database, then align query sequences and capture MAF.
18
+ """
19
+ # Ensure output parent directory exists
20
+ output_path = Path(output_maf)
21
+ output_path.parent.mkdir(parents=True, exist_ok=True)
22
+
23
+ # Step 1: lastdb {database_prefix} {reference_fasta}
24
+ lastdb_cmd = ["lastdb", database_prefix, reference_fasta]
25
+ try:
26
+ result_db = subprocess.run(
27
+ lastdb_cmd,
28
+ capture_output=True,
29
+ text=True,
30
+ check=False
31
+ )
32
+ if result_db.returncode != 0:
33
+ raise RuntimeError(
34
+ f"lastdb failed with exit code {result_db.returncode}: "
35
+ f"stderr: {result_db.stderr}"
36
+ )
37
+ except FileNotFoundError:
38
+ raise RuntimeError("lastdb executable not found in PATH")
39
+
40
+ # Step 2: lastal {database_prefix} {query_fasta}, capture stdout to output_maf
41
+ lastal_cmd = ["lastal", database_prefix, query_fasta]
42
+ try:
43
+ result_al = subprocess.run(
44
+ lastal_cmd,
45
+ capture_output=True,
46
+ text=True,
47
+ check=False
48
+ )
49
+ if result_al.returncode != 0:
50
+ raise RuntimeError(
51
+ f"lastal failed with exit code {result_al.returncode}: "
52
+ f"stderr: {result_al.stderr}"
53
+ )
54
+ # Write captured stdout to output_maf
55
+ with open(output_maf, "w", encoding="utf-8") as f:
56
+ f.write(result_al.stdout)
57
+ except FileNotFoundError:
58
+ raise RuntimeError("lastal executable not found in PATH")
59
+
60
+ # Return structured JSON-serializable metadata
61
+ metadata = {
62
+ "endpoint": "align_dna",
63
+ "status": "success",
64
+ "database_prefix": database_prefix,
65
+ "reference_fasta": reference_fasta,
66
+ "query_fasta": query_fasta,
67
+ "output_maf": output_maf,
68
+ "lastdb_exit_code": result_db.returncode,
69
+ "lastal_exit_code": result_al.returncode,
70
+ "maf_bytes_written": len(result_al.stdout.encode("utf-8"))
71
+ }
72
+ return json.dumps(metadata, indent=2)
73
+
74
+ if __name__ == "__main__":
75
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/locarna_align_rna_test_server.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ import subprocess
3
+ import os
4
+ import json
5
+ from pathlib import Path
6
+
7
+ mcp = FastMCP("locarna-mcp")
8
+
9
+ @mcp.tool()
10
+ def align_rna(input_fasta: str, output_dir: str) -> dict:
11
+ """
12
+ Align RNA sequences using mlocarna (locarna 2.0.1).
13
+
14
+ Args:
15
+ input_fasta: Path to input FASTA file containing RNA sequences
16
+ output_dir: Directory where alignment results will be written
17
+
18
+ Returns:
19
+ Dictionary with execution metadata including output directory path
20
+ """
21
+ # Create output directory if it doesn't exist
22
+ output_path = Path(output_dir)
23
+ output_path.mkdir(parents=True, exist_ok=True)
24
+
25
+ # Build command according to execution plan
26
+ cmd = [
27
+ "mlocarna",
28
+ "--tgtdir", str(output_path),
29
+ "--quiet",
30
+ str(input_fasta)
31
+ ]
32
+
33
+ # Execute the command
34
+ try:
35
+ result = subprocess.run(
36
+ cmd,
37
+ capture_output=True,
38
+ text=True,
39
+ check=False
40
+ )
41
+
42
+ if result.returncode != 0:
43
+ raise RuntimeError(
44
+ f"mlocarna failed with exit code {result.returncode}\n"
45
+ f"stderr: {result.stderr}"
46
+ )
47
+
48
+ # Return structured metadata
49
+ return {
50
+ "status": "success",
51
+ "command": cmd,
52
+ "returncode": result.returncode,
53
+ "output_dir": str(output_path),
54
+ "input_fasta": str(input_fasta),
55
+ "stdout": result.stdout,
56
+ "stderr": result.stderr
57
+ }
58
+
59
+ except FileNotFoundError:
60
+ raise RuntimeError("mlocarna executable not found in PATH")
61
+ except Exception as e:
62
+ raise RuntimeError(f"Error executing mlocarna: {str(e)}")
63
+
64
+ if __name__ == "__main__":
65
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/macs2_call_narrow_peak_test_server.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ import subprocess
3
+ import os
4
+ import json
5
+ import sys
6
+
7
+ mcp = FastMCP("macs2")
8
+
9
+
10
+ @mcp.tool()
11
+ def call_narrow_peak(treatment_bed: str, output_dir: str) -> dict:
12
+ """
13
+ Call one narrow peak with a fixed model-free extension and deterministic single-threaded fixture settings.
14
+
15
+ Args:
16
+ treatment_bed: Path to the treatment BED file.
17
+ output_dir: Directory where output files will be written.
18
+
19
+ Returns:
20
+ JSON-serializable metadata about the invocation.
21
+ """
22
+ # Create output directory if it doesn't exist
23
+ os.makedirs(output_dir, exist_ok=True)
24
+
25
+ # Build the command as a list to avoid shell=True
26
+ command = [
27
+ "bash",
28
+ "-lc",
29
+ "LD_PRELOAD='/225040511/project/Beyond_Prompt-Based_Planning/Biomanus-V2/Experiment1/repairs/libglibc_finite_compat.so' macs2 callpeak -t '{treatment_bed}' -f BED -g 40 -n fixture --outdir '{output_dir}' --nomodel --extsize 10 --keep-dup all --nolambda -p 0.5 --verbose 0".format(
30
+ treatment_bed=treatment_bed, output_dir=output_dir
31
+ ),
32
+ ]
33
+
34
+ try:
35
+ # Execute the command
36
+ result = subprocess.run(
37
+ command,
38
+ capture_output=True,
39
+ text=True,
40
+ check=False,
41
+ )
42
+
43
+ if result.returncode != 0:
44
+ raise RuntimeError(
45
+ f"Command failed with exit code {result.returncode}\n"
46
+ f"stdout: {result.stdout}\n"
47
+ f"stderr: {result.stderr}"
48
+ )
49
+
50
+ # Collect output files that are expected to be generated
51
+ expected_files = [
52
+ "fixture_peaks.xls",
53
+ "fixture_peaks.narrowPeak",
54
+ "fixture_summits.bed",
55
+ "fixture_model.r",
56
+ ]
57
+
58
+ output_files = {}
59
+ for fname in expected_files:
60
+ fpath = os.path.join(output_dir, fname)
61
+ if os.path.exists(fpath):
62
+ output_files[fname] = fpath
63
+
64
+ return {
65
+ "status": "success",
66
+ "command": command,
67
+ "returncode": result.returncode,
68
+ "stdout": result.stdout,
69
+ "stderr": result.stderr,
70
+ "output_dir": output_dir,
71
+ "output_files": output_files,
72
+ }
73
+
74
+ except Exception as e:
75
+ return {
76
+ "status": "error",
77
+ "error": str(e),
78
+ "command": command,
79
+ }
80
+
81
+
82
+ if __name__ == "__main__":
83
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/mageck_count_sgrna_test_server.py ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ import subprocess
3
+ import os
4
+ import json
5
+ import sys
6
+ from pathlib import Path
7
+
8
+ mcp = FastMCP("mageck")
9
+
10
+ @mcp.tool()
11
+ def count_sgrna(library_file: str, input_fastq: str, output_prefix: str) -> dict:
12
+ """
13
+ Count sgRNA reads from FASTQ files using MAGeCK count.
14
+
15
+ Args:
16
+ library_file: Path to the sgRNA library file (CSV/TSV format)
17
+ input_fastq: Path to the input FASTQ file
18
+ output_prefix: Prefix for output files (will create parent directories)
19
+
20
+ Returns:
21
+ Dictionary with execution metadata and output file paths
22
+ """
23
+ # Create output parent directories
24
+ output_path = Path(output_prefix)
25
+ output_path.parent.mkdir(parents=True, exist_ok=True)
26
+
27
+ # Build command exactly as specified in execution_plan
28
+ cmd = [
29
+ "mageck",
30
+ "count",
31
+ "-l",
32
+ library_file,
33
+ "--fastq",
34
+ input_fastq,
35
+ "--sample-label",
36
+ "fixture",
37
+ "--norm-method",
38
+ "none",
39
+ "-n",
40
+ output_prefix
41
+ ]
42
+
43
+ # Execute command without shell=True
44
+ try:
45
+ result = subprocess.run(
46
+ cmd,
47
+ capture_output=True,
48
+ text=True,
49
+ check=False
50
+ )
51
+ except FileNotFoundError:
52
+ return {
53
+ "success": False,
54
+ "error": "mageck executable not found in PATH",
55
+ "command": cmd,
56
+ "returncode": -1,
57
+ "stdout": "",
58
+ "stderr": "mageck executable not found"
59
+ }
60
+
61
+ # Raise on non-zero exit
62
+ if result.returncode != 0:
63
+ raise RuntimeError(
64
+ f"mageck count failed with exit code {result.returncode}\n"
65
+ f"Command: {' '.join(cmd)}\n"
66
+ f"stdout: {result.stdout}\n"
67
+ f"stderr: {result.stderr}"
68
+ )
69
+
70
+ # Collect output files that MAGeCK typically generates
71
+ output_files = []
72
+ # Main count table
73
+ count_file = f"{output_prefix}.count.txt"
74
+ if os.path.exists(count_file):
75
+ output_files.append(count_file)
76
+
77
+ # Normalized count table (though normalization is disabled, file may still be created)
78
+ norm_file = f"{output_prefix}.norm.txt"
79
+ if os.path.exists(norm_file):
80
+ output_files.append(norm_file)
81
+
82
+ # Summary file
83
+ summary_file = f"{output_prefix}.summary.txt"
84
+ if os.path.exists(summary_file):
85
+ output_files.append(summary_file)
86
+
87
+ # Return structured metadata
88
+ return {
89
+ "success": True,
90
+ "command": cmd,
91
+ "returncode": result.returncode,
92
+ "stdout": result.stdout,
93
+ "stderr": result.stderr,
94
+ "output_prefix": output_prefix,
95
+ "output_files": output_files,
96
+ "library_file": library_file,
97
+ "input_fastq": input_fastq,
98
+ "sample_label": "fixture",
99
+ "normalization": "none"
100
+ }
101
+
102
+ if __name__ == "__main__":
103
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/mash_sketch_fasta_test_server.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ import subprocess
3
+ import os
4
+ import json
5
+ import sys
6
+
7
+ mcp = FastMCP("mash-sketch-fasta")
8
+
9
+ @mcp.tool()
10
+ def sketch_fasta(input_fasta: str, output_prefix: str, output_info: str) -> dict:
11
+ """
12
+ Create a Mash sketch from a FASTA file with fixed k=6 and sketch size=10,
13
+ then inspect the derived .msh file and return metadata.
14
+ """
15
+ # Ensure output parent directories exist
16
+ for path in [output_prefix, output_info]:
17
+ parent = os.path.dirname(os.path.abspath(path))
18
+ os.makedirs(parent, exist_ok=True)
19
+
20
+ # Step 1: mash sketch -k 6 -s 10 -o {output_prefix} {input_fasta}
21
+ sketch_cmd = [
22
+ "mash",
23
+ "sketch",
24
+ "-k", "6",
25
+ "-s", "10",
26
+ "-o", output_prefix,
27
+ input_fasta
28
+ ]
29
+ sketch_result = subprocess.run(
30
+ sketch_cmd,
31
+ capture_output=True,
32
+ text=True,
33
+ check=False
34
+ )
35
+ if sketch_result.returncode != 0:
36
+ raise RuntimeError(
37
+ f"mash sketch failed with exit code {sketch_result.returncode}: "
38
+ f"stdout={sketch_result.stdout}, stderr={sketch_result.stderr}"
39
+ )
40
+
41
+ # Derived .msh file path
42
+ msh_path = output_prefix + ".msh"
43
+ if not os.path.exists(msh_path):
44
+ raise RuntimeError(f"Expected sketch file {msh_path} was not created")
45
+
46
+ # Step 2: mash info -t {msh_path}, capture stdout to output_info
47
+ info_cmd = ["mash", "info", "-t", msh_path]
48
+ info_result = subprocess.run(
49
+ info_cmd,
50
+ capture_output=True,
51
+ text=True,
52
+ check=False
53
+ )
54
+ if info_result.returncode != 0:
55
+ raise RuntimeError(
56
+ f"mash info failed with exit code {info_result.returncode}: "
57
+ f"stdout={info_result.stdout}, stderr={info_result.stderr}"
58
+ )
59
+
60
+ # Write captured stdout to output_info path
61
+ with open(output_info, "w") as f:
62
+ f.write(info_result.stdout)
63
+
64
+ # Build structured metadata
65
+ metadata = {
66
+ "endpoint": "sketch_fasta",
67
+ "input_fasta": input_fasta,
68
+ "output_prefix": output_prefix,
69
+ "output_info": output_info,
70
+ "sketch_file": msh_path,
71
+ "kmer_size": 6,
72
+ "sketch_size": 10,
73
+ "info_stdout": info_result.stdout,
74
+ "info_stderr": info_result.stderr,
75
+ "sketch_stdout": sketch_result.stdout,
76
+ "sketch_stderr": sketch_result.stderr
77
+ }
78
+
79
+ return metadata
80
+
81
+ if __name__ == "__main__":
82
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/maxquant_create_parameter_template_test_server.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+ import subprocess
4
+ import sys
5
+ from pathlib import Path
6
+
7
+ from mcp.server.fastmcp import FastMCP
8
+
9
+ mcp = FastMCP("maxquant")
10
+
11
+
12
+ @mcp.tool()
13
+ def create_parameter_template(request_file: str, output_xml: str) -> dict:
14
+ """
15
+ Create a complete default MaxQuant mqpar XML parameter template at the requested output path.
16
+
17
+ Args:
18
+ request_file: Path to the template request file (validated before template creation).
19
+ output_xml: Path where the generated mqpar XML template will be written.
20
+ """
21
+ # Step 1: Validate the template request file
22
+ validate_cmd = ["validate_maxquant_template_request", request_file]
23
+ try:
24
+ validate_result = subprocess.run(
25
+ validate_cmd,
26
+ capture_output=True,
27
+ text=True,
28
+ check=False,
29
+ )
30
+ if validate_result.returncode != 0:
31
+ raise RuntimeError(
32
+ f"Validation failed with exit code {validate_result.returncode}: "
33
+ f"{validate_result.stderr.strip()}"
34
+ )
35
+ except FileNotFoundError as e:
36
+ raise RuntimeError(f"Validation executable not found: {e}")
37
+
38
+ # Step 2: Create the parameter template using maxquant -c
39
+ # Ensure output parent directory exists
40
+ output_path = Path(output_xml)
41
+ output_path.parent.mkdir(parents=True, exist_ok=True)
42
+
43
+ cmd = ["maxquant", "-c", str(output_path)]
44
+ try:
45
+ result = subprocess.run(
46
+ cmd,
47
+ capture_output=True,
48
+ text=True,
49
+ check=False,
50
+ )
51
+ except FileNotFoundError as e:
52
+ raise RuntimeError(f"maxquant executable not found: {e}")
53
+
54
+ if result.returncode != 0:
55
+ raise RuntimeError(
56
+ f"maxquant -c failed with exit code {result.returncode}: "
57
+ f"{result.stderr.strip()}"
58
+ )
59
+
60
+ # Verify output file was created
61
+ if not output_path.exists():
62
+ raise RuntimeError(
63
+ f"maxquant -c did not create the expected output file: {output_path}"
64
+ )
65
+
66
+ return {
67
+ "endpoint": "create_parameter_template",
68
+ "request_file": request_file,
69
+ "output_xml": str(output_path),
70
+ "status": "success",
71
+ "stdout": result.stdout,
72
+ "stderr": result.stderr,
73
+ }
74
+
75
+
76
+ if __name__ == "__main__":
77
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/medaka_vcf_to_tsv_test_server.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ import subprocess
3
+ import os
4
+ import sys
5
+ import shutil
6
+ import json
7
+ from pathlib import Path
8
+
9
+ mcp = FastMCP("medaka")
10
+
11
+ @mcp.tool()
12
+ def vcf_to_tsv(input_vcf: str, output_tsv: str) -> dict:
13
+ """
14
+ Convert a phased VCF file to TSV format using medaka tools vcf2tsv.
15
+
16
+ Args:
17
+ input_vcf: Path to the input VCF file
18
+ output_tsv: Path to the output TSV file (derived by appending .tsv to input)
19
+ """
20
+ # Create output directory if it doesn't exist
21
+ output_dir = os.path.dirname(os.path.abspath(output_tsv))
22
+ os.makedirs(output_dir, exist_ok=True)
23
+
24
+ # Stage the input VCF in the output directory
25
+ staged_vcf = os.path.join(output_dir, os.path.basename(input_vcf))
26
+
27
+ # Step 1: Copy input VCF to staged location
28
+ cp_result = subprocess.run(
29
+ ["cp", input_vcf, staged_vcf],
30
+ capture_output=True,
31
+ text=True,
32
+ check=False
33
+ )
34
+ if cp_result.returncode != 0:
35
+ raise RuntimeError(f"Failed to copy input VCF: {cp_result.stderr}")
36
+
37
+ # Step 2: Run medaka tools vcf2tsv on the staged VCF
38
+ # The tool writes output to {staged_vcf}.tsv
39
+ result = subprocess.run(
40
+ ["medaka", "tools", "vcf2tsv", staged_vcf],
41
+ capture_output=True,
42
+ text=True,
43
+ check=False
44
+ )
45
+
46
+ if result.returncode != 0:
47
+ # Clean up staged file on error
48
+ if os.path.exists(staged_vcf):
49
+ os.remove(staged_vcf)
50
+ raise RuntimeError(f"medaka tools vcf2tsv failed with exit code {result.returncode}: {result.stderr}")
51
+
52
+ # The tool creates {staged_vcf}.tsv, move it to the requested output path
53
+ generated_tsv = staged_vcf + ".tsv"
54
+ if not os.path.exists(generated_tsv):
55
+ # Clean up staged file
56
+ if os.path.exists(staged_vcf):
57
+ os.remove(staged_vcf)
58
+ raise RuntimeError(f"Expected output file {generated_tsv} was not created")
59
+
60
+ # Move the generated TSV to the requested output location
61
+ shutil.move(generated_tsv, output_tsv)
62
+
63
+ # Clean up staged VCF
64
+ if os.path.exists(staged_vcf):
65
+ os.remove(staged_vcf)
66
+
67
+ # Return structured metadata
68
+ return {
69
+ "endpoint": "vcf_to_tsv",
70
+ "input_vcf": input_vcf,
71
+ "output_tsv": output_tsv,
72
+ "status": "success",
73
+ "output_size": os.path.getsize(output_tsv),
74
+ "tool": "medaka",
75
+ "version": "2.2.2"
76
+ }
77
+
78
+ if __name__ == "__main__":
79
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/metagenome-atlas_initialize_project_test_server.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ import subprocess
3
+ import os
4
+ import json
5
+ import sys
6
+ from pathlib import Path
7
+
8
+ mcp = FastMCP("metagenome-atlas")
9
+
10
+ @mcp.tool()
11
+ def initialize_project(reads_dir: str, work_dir: str, output_tsv: str) -> dict:
12
+ """
13
+ Initialize a metagenome project from one paired FASTQ sample using two threads and the default MEGAHIT workflow configuration.
14
+ """
15
+ # Create output parent directories
16
+ Path(output_tsv).parent.mkdir(parents=True, exist_ok=True)
17
+ Path(work_dir).parent.mkdir(parents=True, exist_ok=True)
18
+
19
+ # Step 1: Run atlas init
20
+ cmd1 = [
21
+ "atlas",
22
+ "init",
23
+ reads_dir,
24
+ "-w",
25
+ work_dir,
26
+ "-d",
27
+ os.path.join(work_dir, "databases"),
28
+ "--threads",
29
+ "2"
30
+ ]
31
+
32
+ try:
33
+ result1 = subprocess.run(cmd1, capture_output=True, text=True, check=False)
34
+ if result1.returncode != 0:
35
+ raise RuntimeError(f"atlas init failed with exit code {result1.returncode}: {result1.stderr}")
36
+ except FileNotFoundError:
37
+ raise RuntimeError("atlas executable not found in PATH")
38
+
39
+ # Step 2: Normalize atlas init output
40
+ samples_tsv = os.path.join(work_dir, "samples.tsv")
41
+ config_yaml = os.path.join(work_dir, "config.yaml")
42
+
43
+ # Read the generated files
44
+ try:
45
+ with open(samples_tsv, 'r') as f:
46
+ samples_content = f.read()
47
+ with open(config_yaml, 'r') as f:
48
+ config_content = f.read()
49
+ except FileNotFoundError as e:
50
+ raise RuntimeError(f"Expected output file not found: {e}")
51
+
52
+ # Write normalized summary to output_tsv
53
+ # The normalization here extracts key information from samples.tsv and config.yaml
54
+ # and writes a combined summary TSV
55
+ summary_lines = []
56
+ summary_lines.append("# Atlas Project Initialization Summary")
57
+ summary_lines.append(f"# Work directory: {work_dir}")
58
+ summary_lines.append(f"# Reads directory: {reads_dir}")
59
+ summary_lines.append("")
60
+ summary_lines.append("# Samples:")
61
+ summary_lines.append(samples_content)
62
+ summary_lines.append("")
63
+ summary_lines.append("# Configuration (key settings):")
64
+
65
+ # Extract key config settings
66
+ config_summary = []
67
+ for line in config_content.splitlines():
68
+ if any(key in line.lower() for key in ['assembler', 'threads', 'kmer', 'min_contig', 'coverage']):
69
+ config_summary.append(line)
70
+
71
+ summary_lines.extend(config_summary)
72
+
73
+ with open(output_tsv, 'w') as f:
74
+ f.write('\n'.join(summary_lines))
75
+
76
+ return {
77
+ "status": "success",
78
+ "work_dir": work_dir,
79
+ "reads_dir": reads_dir,
80
+ "output_tsv": output_tsv,
81
+ "samples_tsv": samples_tsv,
82
+ "config_yaml": config_yaml,
83
+ "databases_dir": os.path.join(work_dir, "databases"),
84
+ "threads": 2,
85
+ "message": "Project initialized successfully"
86
+ }
87
+
88
+ if __name__ == "__main__":
89
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/mikado_configure_workflow_test_server.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ import subprocess
3
+ import os
4
+ import json
5
+ import sys
6
+ from pathlib import Path
7
+
8
+ mcp = FastMCP("mikado")
9
+
10
+ @mcp.tool()
11
+ def configure_workflow(
12
+ reference_fasta: str,
13
+ config_json: str,
14
+ seed: int
15
+ ) -> dict:
16
+ """
17
+ Generate a deterministic JSON workflow configuration with a fixed seed and explicit local reference genome.
18
+
19
+ Args:
20
+ reference_fasta: Path to the reference genome FASTA file
21
+ config_json: Path where the output configuration JSON will be written
22
+ seed: Random seed for deterministic configuration generation
23
+ """
24
+ # Create output parent directory if needed
25
+ config_path = Path(config_json)
26
+ if config_path.parent and not config_path.parent.exists():
27
+ config_path.parent.mkdir(parents=True, exist_ok=True)
28
+
29
+ # Build command exactly as specified in execution_plan
30
+ cmd = [
31
+ "mikado",
32
+ "configure",
33
+ "--seed",
34
+ str(seed),
35
+ "--no-files",
36
+ "--reference",
37
+ reference_fasta,
38
+ config_json
39
+ ]
40
+
41
+ # Execute the command
42
+ try:
43
+ result = subprocess.run(
44
+ cmd,
45
+ capture_output=True,
46
+ text=True,
47
+ check=False
48
+ )
49
+ except FileNotFoundError:
50
+ return {
51
+ "success": False,
52
+ "error": f"Executable 'mikado' not found in PATH",
53
+ "command": cmd
54
+ }
55
+
56
+ if result.returncode != 0:
57
+ return {
58
+ "success": False,
59
+ "error": f"Command failed with exit code {result.returncode}",
60
+ "stdout": result.stdout,
61
+ "stderr": result.stderr,
62
+ "command": cmd
63
+ }
64
+
65
+ # Verify output file was created
66
+ if not config_path.exists():
67
+ return {
68
+ "success": False,
69
+ "error": f"Output file {config_json} was not created",
70
+ "stdout": result.stdout,
71
+ "stderr": result.stderr,
72
+ "command": cmd
73
+ }
74
+
75
+ return {
76
+ "success": True,
77
+ "output_file": str(config_path.resolve()),
78
+ "command": cmd,
79
+ "stdout": result.stdout,
80
+ "stderr": result.stderr,
81
+ "parameters": {
82
+ "reference_fasta": reference_fasta,
83
+ "config_json": config_json,
84
+ "seed": seed
85
+ }
86
+ }
87
+
88
+ if __name__ == "__main__":
89
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/miniasm_assemble_overlap_graph_test_server.py ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+ import subprocess
4
+ import sys
5
+ from pathlib import Path
6
+ from typing import Any
7
+
8
+ from mcp.server.fastmcp import FastMCP
9
+
10
+ mcp = FastMCP("miniasm-assemble-overlap-graph")
11
+
12
+
13
+ @mcp.tool()
14
+ def assemble_overlap_graph(
15
+ reads_fasta: str,
16
+ overlaps_paf: str,
17
+ output_gfa: str,
18
+ ) -> dict[str, Any]:
19
+ """
20
+ Assemble an overlap graph from reads and overlaps using miniasm.
21
+
22
+ Args:
23
+ reads_fasta: Path to the input reads FASTA file.
24
+ overlaps_paf: Path to the input overlaps PAF file.
25
+ output_gfa: Path where the output GFA file will be written.
26
+
27
+ Returns:
28
+ A JSON-serializable dictionary with metadata about the execution.
29
+ """
30
+ # Validate required inputs exist
31
+ reads_path = Path(reads_fasta)
32
+ overlaps_path = Path(overlaps_paf)
33
+ if not reads_path.is_file():
34
+ raise FileNotFoundError(f"Reads FASTA file not found: {reads_fasta}")
35
+ if not overlaps_path.is_file():
36
+ raise FileNotFoundError(f"Overlaps PAF file not found: {overlaps_paf}")
37
+
38
+ # Create output parent directory if needed
39
+ output_path = Path(output_gfa)
40
+ output_path.parent.mkdir(parents=True, exist_ok=True)
41
+
42
+ # Build command according to execution plan
43
+ cmd = [
44
+ "miniasm",
45
+ "-1",
46
+ "-2",
47
+ "-f",
48
+ str(reads_path),
49
+ "-m",
50
+ "100",
51
+ "-s",
52
+ "50",
53
+ "-o",
54
+ "50",
55
+ "-c",
56
+ "1",
57
+ "-e",
58
+ "1",
59
+ "-I",
60
+ "0.1",
61
+ str(overlaps_path),
62
+ ]
63
+
64
+ # Run the command, capturing stdout
65
+ try:
66
+ result = subprocess.run(
67
+ cmd,
68
+ capture_output=True,
69
+ text=True,
70
+ check=False,
71
+ )
72
+ except FileNotFoundError:
73
+ raise RuntimeError(
74
+ "miniasm executable not found. Ensure it is installed and in PATH."
75
+ )
76
+
77
+ if result.returncode != 0:
78
+ raise RuntimeError(
79
+ f"miniasm failed with exit code {result.returncode}\n"
80
+ f"stderr: {result.stderr}"
81
+ )
82
+
83
+ # Write stdout to output file
84
+ output_path.write_text(result.stdout)
85
+
86
+ # Return structured metadata
87
+ return {
88
+ "endpoint": "assemble_overlap_graph",
89
+ "status": "success",
90
+ "output_gfa": str(output_path),
91
+ "reads_fasta": str(reads_path),
92
+ "overlaps_paf": str(overlaps_path),
93
+ "command": cmd,
94
+ "exit_code": result.returncode,
95
+ "stdout_size_bytes": len(result.stdout.encode("utf-8")),
96
+ "stderr": result.stderr,
97
+ }
98
+
99
+
100
+ if __name__ == "__main__":
101
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/minimap2_align_dna_test_server.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ import subprocess
3
+ import os
4
+ import json
5
+ import sys
6
+
7
+ mcp = FastMCP("minimap2-align-dna")
8
+
9
+ @mcp.tool()
10
+ def align_dna(reference_file: str, query_file: str, output_sam: str) -> dict:
11
+ """
12
+ Align DNA sequences using minimap2 and produce SAM output.
13
+
14
+ Args:
15
+ reference_file: Path to the reference FASTA file
16
+ query_file: Path to the query FASTA file
17
+ output_sam: Path where the SAM output will be written
18
+ """
19
+ # Create output parent directory if needed
20
+ output_dir = os.path.dirname(os.path.abspath(output_sam))
21
+ os.makedirs(output_dir, exist_ok=True)
22
+
23
+ # Build command according to execution plan
24
+ cmd = [
25
+ "minimap2",
26
+ "-a",
27
+ "-t",
28
+ "1",
29
+ reference_file,
30
+ query_file
31
+ ]
32
+
33
+ # Run the command, capturing stdout
34
+ try:
35
+ result = subprocess.run(
36
+ cmd,
37
+ capture_output=True,
38
+ text=False, # binary mode to preserve exact bytes
39
+ check=False # we'll check return code manually
40
+ )
41
+ except FileNotFoundError:
42
+ return {
43
+ "success": False,
44
+ "error": "minimap2 executable not found in PATH",
45
+ "command": cmd
46
+ }
47
+ except Exception as e:
48
+ return {
49
+ "success": False,
50
+ "error": f"Failed to execute command: {str(e)}",
51
+ "command": cmd
52
+ }
53
+
54
+ if result.returncode != 0:
55
+ return {
56
+ "success": False,
57
+ "error": f"minimap2 exited with code {result.returncode}",
58
+ "stderr": result.stderr.decode('utf-8', errors='replace'),
59
+ "command": cmd
60
+ }
61
+
62
+ # Write stdout to output file
63
+ try:
64
+ with open(output_sam, 'wb') as f:
65
+ f.write(result.stdout)
66
+ except Exception as e:
67
+ return {
68
+ "success": False,
69
+ "error": f"Failed to write output file: {str(e)}",
70
+ "command": cmd
71
+ }
72
+
73
+ # Return structured metadata
74
+ return {
75
+ "success": True,
76
+ "output_sam": output_sam,
77
+ "command": cmd,
78
+ "return_code": result.returncode,
79
+ "stdout_bytes": len(result.stdout),
80
+ "stderr": result.stderr.decode('utf-8', errors='replace') if result.stderr else ""
81
+ }
82
+
83
+ if __name__ == "__main__":
84
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/minvar_estimate_minimum_read_length_test_server.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+ import subprocess
4
+ import sys
5
+ from pathlib import Path
6
+
7
+ from mcp.server.fastmcp import FastMCP
8
+
9
+ mcp = FastMCP("minvar")
10
+
11
+
12
+ @mcp.tool()
13
+ def estimate_minimum_read_length(input_fastq: str, output_json: str) -> dict:
14
+ """
15
+ Estimate the minimum read length for MinVar analysis.
16
+
17
+ Args:
18
+ input_fastq: Path to the input FASTQ file.
19
+ output_json: Path where the JSON output will be written.
20
+
21
+ Returns:
22
+ A dictionary containing the result metadata.
23
+ """
24
+ # Create output parent directories
25
+ output_path = Path(output_json)
26
+ output_path.parent.mkdir(parents=True, exist_ok=True)
27
+
28
+ # Build the command as specified in the execution plan
29
+ code = (
30
+ "import json,sys; "
31
+ "from minvar.prepare import compute_min_len; "
32
+ "v=compute_min_len(sys.argv[1]); "
33
+ "open(sys.argv[2],'w').write(json.dumps({'minimum_length':v},sort_keys=True)+'\\n')"
34
+ )
35
+ cmd = [
36
+ "python",
37
+ "-c",
38
+ code,
39
+ input_fastq,
40
+ output_json,
41
+ ]
42
+
43
+ # Execute the command without shell=True
44
+ try:
45
+ result = subprocess.run(
46
+ cmd,
47
+ capture_output=True,
48
+ text=True,
49
+ check=False,
50
+ )
51
+ except Exception as e:
52
+ return {
53
+ "status": "error",
54
+ "error": f"Failed to execute command: {str(e)}",
55
+ "command": cmd,
56
+ }
57
+
58
+ # Raise on non-zero exit
59
+ if result.returncode != 0:
60
+ error_msg = result.stderr.strip() if result.stderr else "Unknown error"
61
+ return {
62
+ "status": "error",
63
+ "error": f"Command failed with exit code {result.returncode}: {error_msg}",
64
+ "command": cmd,
65
+ }
66
+
67
+ # Read the output JSON to include in the response
68
+ try:
69
+ with open(output_json, "r") as f:
70
+ output_data = json.load(f)
71
+ except Exception as e:
72
+ output_data = {"error": f"Failed to read output file: {str(e)}"}
73
+
74
+ return {
75
+ "status": "success",
76
+ "output_file": str(output_path),
77
+ "result": output_data,
78
+ "command": cmd,
79
+ }
80
+
81
+
82
+ if __name__ == "__main__":
83
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/mosdepth_coverage_summary_test_server.py ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ import subprocess
3
+ import os
4
+ import sys
5
+ import json
6
+ from pathlib import Path
7
+
8
+ mcp = FastMCP("mosdepth-coverage-summary")
9
+
10
+ @mcp.tool()
11
+ def coverage_summary(input_bam: str, output_prefix: str) -> dict:
12
+ """
13
+ Compute coverage summary statistics using mosdepth.
14
+
15
+ Args:
16
+ input_bam: Path to the input BAM or CRAM file.
17
+ output_prefix: Prefix for output files (summary and distribution files will be created).
18
+
19
+ Returns:
20
+ JSON-serializable metadata about the generated output files.
21
+ """
22
+ # Create output parent directories
23
+ output_dir = Path(output_prefix).parent
24
+ if output_dir and not output_dir.exists():
25
+ output_dir.mkdir(parents=True, exist_ok=True)
26
+
27
+ # Build command exactly as specified in execution_plan
28
+ cmd = [
29
+ "mosdepth",
30
+ "-n", # no per-base output
31
+ "-t", "1", # one thread
32
+ output_prefix,
33
+ input_bam
34
+ ]
35
+
36
+ # Execute the command
37
+ try:
38
+ result = subprocess.run(
39
+ cmd,
40
+ capture_output=True,
41
+ text=True,
42
+ check=False,
43
+ shell=False
44
+ )
45
+ except FileNotFoundError:
46
+ raise RuntimeError("mosdepth executable not found in PATH")
47
+ except Exception as e:
48
+ raise RuntimeError(f"Failed to execute mosdepth: {str(e)}")
49
+
50
+ if result.returncode != 0:
51
+ error_msg = result.stderr.strip() if result.stderr else "Unknown error"
52
+ raise RuntimeError(f"mosdepth failed with exit code {result.returncode}: {error_msg}")
53
+
54
+ # Determine output files based on mosdepth naming convention
55
+ summary_file = f"{output_prefix}.mosdepth.summary.txt"
56
+ dist_file = f"{output_prefix}.mosdepth.dist.txt"
57
+
58
+ # Verify output files exist
59
+ missing_files = []
60
+ if not os.path.isfile(summary_file):
61
+ missing_files.append(summary_file)
62
+ if not os.path.isfile(dist_file):
63
+ missing_files.append(dist_file)
64
+
65
+ if missing_files:
66
+ raise RuntimeError(f"Expected output files not created: {', '.join(missing_files)}")
67
+
68
+ # Read summary file content for metadata
69
+ try:
70
+ with open(summary_file, 'r') as f:
71
+ summary_content = f.read()
72
+ except Exception as e:
73
+ summary_content = f"Error reading summary file: {str(e)}"
74
+
75
+ # Return structured metadata
76
+ return {
77
+ "status": "success",
78
+ "command": cmd,
79
+ "exit_code": result.returncode,
80
+ "output_files": {
81
+ "summary": summary_file,
82
+ "distribution": dist_file
83
+ },
84
+ "summary_content": summary_content,
85
+ "stderr": result.stderr if result.stderr else "",
86
+ "stdout": result.stdout if result.stdout else ""
87
+ }
88
+
89
+ if __name__ == "__main__":
90
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/mothur_summarize_sequences_test_server.py ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ import subprocess
3
+ import os
4
+ import sys
5
+ import json
6
+ from pathlib import Path
7
+
8
+ mcp = FastMCP("mothur-summarize-sequences")
9
+
10
+ @mcp.tool()
11
+ def summarize_sequences(input_fasta: str, output_dir: str) -> dict:
12
+ """
13
+ Run mothur summary.seqs on a FASTA file and return summary metadata.
14
+
15
+ Args:
16
+ input_fasta: Path to input FASTA file
17
+ output_dir: Directory where output files will be written
18
+
19
+ Returns:
20
+ Dictionary with output file paths and command execution metadata
21
+ """
22
+ # Create output directory if it doesn't exist
23
+ output_path = Path(output_dir)
24
+ output_path.mkdir(parents=True, exist_ok=True)
25
+
26
+ # Resolve input path to absolute
27
+ input_path = Path(input_fasta).resolve()
28
+ if not input_path.exists():
29
+ raise FileNotFoundError(f"Input FASTA file not found: {input_path}")
30
+
31
+ # Build mothur command string
32
+ # Use forward slashes for paths to avoid escaping issues
33
+ input_str = str(input_path).replace("\\", "/")
34
+ output_str = str(output_path.resolve()).replace("\\", "/")
35
+
36
+ mothur_command = f"#set.dir(output={output_str}); summary.seqs(fasta={input_str}, processors=1)"
37
+
38
+ # Execute mothur
39
+ try:
40
+ result = subprocess.run(
41
+ ["mothur", mothur_command],
42
+ capture_output=True,
43
+ text=True,
44
+ check=False,
45
+ cwd=str(output_path) # Run in output dir to keep files there
46
+ )
47
+ except FileNotFoundError:
48
+ raise RuntimeError("mothur executable not found in PATH")
49
+
50
+ # Check return code
51
+ if result.returncode != 0:
52
+ error_msg = f"mothur failed with exit code {result.returncode}\n"
53
+ error_msg += f"STDOUT:\n{result.stdout}\n"
54
+ error_msg += f"STDERR:\n{result.stderr}"
55
+ raise RuntimeError(error_msg)
56
+
57
+ # Determine output filename based on input basename
58
+ # mothur typically creates <basename>.summary file
59
+ input_basename = input_path.stem
60
+ summary_file = output_path / f"{input_basename}.summary"
61
+
62
+ # Also check for other possible output patterns
63
+ possible_outputs = [
64
+ output_path / f"{input_basename}.summary",
65
+ output_path / f"{input_basename}.summary",
66
+ output_path / f"{input_basename}.summary",
67
+ ]
68
+
69
+ # Find the actual summary file (mothur may add suffixes)
70
+ found_summary = None
71
+ for candidate in output_path.iterdir():
72
+ if candidate.name.startswith(input_basename) and candidate.suffix == ".summary":
73
+ found_summary = candidate
74
+ break
75
+
76
+ if found_summary is None:
77
+ # Try to find any .summary file created recently
78
+ summary_files = list(output_path.glob("*.summary"))
79
+ if summary_files:
80
+ found_summary = max(summary_files, key=lambda p: p.stat().st_mtime)
81
+
82
+ # Parse summary content if found
83
+ summary_data = {}
84
+ if found_summary and found_summary.exists():
85
+ try:
86
+ with open(found_summary, "r") as f:
87
+ lines = f.readlines()
88
+ if lines:
89
+ # Parse header and first data row
90
+ header = lines[0].strip().split("\t")
91
+ if len(lines) > 1:
92
+ values = lines[1].strip().split("\t")
93
+ summary_data = dict(zip(header, values))
94
+ except Exception as e:
95
+ summary_data = {"parse_error": str(e)}
96
+
97
+ # Collect all output files created
98
+ output_files = []
99
+ for f in output_path.iterdir():
100
+ if f.is_file():
101
+ output_files.append(str(f))
102
+
103
+ return {
104
+ "status": "success",
105
+ "command": mothur_command,
106
+ "exit_code": result.returncode,
107
+ "output_dir": str(output_path),
108
+ "input_fasta": str(input_path),
109
+ "summary_file": str(found_summary) if found_summary else None,
110
+ "summary_data": summary_data,
111
+ "output_files": output_files,
112
+ "stdout": result.stdout,
113
+ "stderr": result.stderr
114
+ }
115
+
116
+ if __name__ == "__main__":
117
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/msisensor-pro_scan_microsatellites_test_server.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ import subprocess
3
+ import os
4
+ import json
5
+ from pathlib import Path
6
+
7
+ mcp = FastMCP("msisensor-pro")
8
+
9
+ @mcp.tool()
10
+ def scan_microsatellites(reference_fasta: str, output_table: str) -> dict:
11
+ """
12
+ Scan the reference genome to get microsatellites information.
13
+
14
+ Args:
15
+ reference_fasta: Path to the reference FASTA file
16
+ output_table: Path where the output table will be written
17
+ """
18
+ # Create output parent directory if it doesn't exist
19
+ output_path = Path(output_table)
20
+ output_path.parent.mkdir(parents=True, exist_ok=True)
21
+
22
+ # Build command
23
+ cmd = [
24
+ "msisensor-pro",
25
+ "scan",
26
+ "-d", reference_fasta,
27
+ "-o", output_table,
28
+ "-c", "5"
29
+ ]
30
+
31
+ # Run the command
32
+ try:
33
+ result = subprocess.run(
34
+ cmd,
35
+ capture_output=True,
36
+ text=True,
37
+ check=False
38
+ )
39
+
40
+ if result.returncode != 0:
41
+ raise RuntimeError(
42
+ f"msisensor-pro scan failed with exit code {result.returncode}\n"
43
+ f"stdout: {result.stdout}\n"
44
+ f"stderr: {result.stderr}"
45
+ )
46
+
47
+ # Check if output file was created
48
+ if not output_path.exists():
49
+ raise RuntimeError(f"Output file {output_table} was not created")
50
+
51
+ return {
52
+ "status": "success",
53
+ "command": " ".join(cmd),
54
+ "reference_fasta": reference_fasta,
55
+ "output_table": output_table,
56
+ "output_file_size": output_path.stat().st_size,
57
+ "stdout": result.stdout,
58
+ "stderr": result.stderr
59
+ }
60
+
61
+ except FileNotFoundError:
62
+ raise RuntimeError("msisensor-pro executable not found in PATH")
63
+ except Exception as e:
64
+ raise RuntimeError(f"Error executing msisensor-pro scan: {str(e)}")
65
+
66
+ if __name__ == "__main__":
67
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/msstitch_build_sequence_searchspace_test_server.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ import subprocess
3
+ import os
4
+ import json
5
+ import sqlite3
6
+ import sys
7
+ import tempfile
8
+ from pathlib import Path
9
+
10
+ mcp = FastMCP("msstitch")
11
+
12
+ @mcp.tool()
13
+ def build_sequence_searchspace(input_fasta: str, lookup_db: str, summary_json: str) -> dict:
14
+ """
15
+ Trypsinize protein FASTA into an SQLite lookup and export a stable JSON projection for semantic validation.
16
+
17
+ Args:
18
+ input_fasta: Path to input FASTA file
19
+ lookup_db: Path to output SQLite database file
20
+ summary_json: Path to output JSON summary file
21
+ """
22
+ # Create output parent directories
23
+ for path in [lookup_db, summary_json]:
24
+ parent = os.path.dirname(os.path.abspath(path))
25
+ os.makedirs(parent, exist_ok=True)
26
+
27
+ # Step 1: Create empty SQLite file and run msslookup seqspace
28
+ cmd1 = [
29
+ "bash", "-lc",
30
+ f"touch '{lookup_db}' && msslookup seqspace -i '{input_fasta}' --dbfile '{lookup_db}'"
31
+ ]
32
+
33
+ result1 = subprocess.run(
34
+ cmd1,
35
+ capture_output=True,
36
+ text=True,
37
+ check=False
38
+ )
39
+
40
+ if result1.returncode != 0:
41
+ raise RuntimeError(f"msslookup seqspace failed with exit code {result1.returncode}: {result1.stderr}")
42
+
43
+ # Step 2: Extract sequences from SQLite and write JSON summary
44
+ python_script = """
45
+ import json, sqlite3, sys
46
+ c = sqlite3.connect(sys.argv[1])
47
+ rows = [r[0] for r in c.execute('select seqs from known_searchspace order by seqs')]
48
+ open(sys.argv[2], 'w').write(json.dumps({'known_searchspace': rows, 'count': len(rows)}, sort_keys=True) + '\\n')
49
+ """
50
+
51
+ cmd2 = [
52
+ "python", "-c", python_script,
53
+ lookup_db,
54
+ summary_json
55
+ ]
56
+
57
+ result2 = subprocess.run(
58
+ cmd2,
59
+ capture_output=True,
60
+ text=True,
61
+ check=False
62
+ )
63
+
64
+ if result2.returncode != 0:
65
+ raise RuntimeError(f"JSON summary generation failed with exit code {result2.returncode}: {result2.stderr}")
66
+
67
+ # Read the generated summary for metadata
68
+ with open(summary_json, 'r') as f:
69
+ summary_data = json.load(f)
70
+
71
+ return {
72
+ "status": "success",
73
+ "lookup_db": lookup_db,
74
+ "summary_json": summary_json,
75
+ "sequence_count": summary_data.get("count", 0),
76
+ "known_searchspace": summary_data.get("known_searchspace", [])
77
+ }
78
+
79
+ if __name__ == "__main__":
80
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/muscle_align_proteins_test_server.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ import subprocess
3
+ import os
4
+ import json
5
+ from pathlib import Path
6
+
7
+ mcp = FastMCP("muscle")
8
+
9
+ @mcp.tool()
10
+ def align_proteins(input_file: str, output_file: str) -> dict:
11
+ """
12
+ Align protein sequences using MUSCLE 5.3.
13
+
14
+ Args:
15
+ input_file: Path to input FASTA file
16
+ output_file: Path to output aligned FASTA file
17
+ """
18
+ # Create output parent directories
19
+ output_path = Path(output_file)
20
+ output_path.parent.mkdir(parents=True, exist_ok=True)
21
+
22
+ # Build command
23
+ cmd = [
24
+ "muscle",
25
+ "-align",
26
+ input_file,
27
+ "-output",
28
+ output_file,
29
+ "-threads",
30
+ "1"
31
+ ]
32
+
33
+ # Execute command
34
+ try:
35
+ result = subprocess.run(
36
+ cmd,
37
+ capture_output=True,
38
+ text=True,
39
+ check=False
40
+ )
41
+ except FileNotFoundError:
42
+ return {
43
+ "success": False,
44
+ "error": "MUSCLE executable not found. Please ensure it is installed and in PATH.",
45
+ "command": cmd
46
+ }
47
+
48
+ # Check exit code
49
+ if result.returncode != 0:
50
+ return {
51
+ "success": False,
52
+ "error": f"MUSCLE failed with exit code {result.returncode}",
53
+ "stdout": result.stdout,
54
+ "stderr": result.stderr,
55
+ "command": cmd
56
+ }
57
+
58
+ # Verify output file was created
59
+ if not output_path.exists():
60
+ return {
61
+ "success": False,
62
+ "error": "Output file was not created",
63
+ "stdout": result.stdout,
64
+ "stderr": result.stderr,
65
+ "command": cmd
66
+ }
67
+
68
+ # Return structured metadata
69
+ return {
70
+ "success": True,
71
+ "output_file": str(output_path),
72
+ "input_file": input_file,
73
+ "command": cmd,
74
+ "stdout": result.stdout,
75
+ "stderr": result.stderr,
76
+ "exit_code": result.returncode,
77
+ "output_format": "FASTA",
78
+ "tool": "muscle",
79
+ "version": "5.3"
80
+ }
81
+
82
+ if __name__ == "__main__":
83
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/nanopolish_index_and_check_fast5_test_server.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ import subprocess
3
+ import os
4
+ import json
5
+ import sys
6
+ from pathlib import Path
7
+
8
+ mcp = FastMCP("nanopolish")
9
+
10
+ @mcp.tool()
11
+ def index_and_check_fast5(
12
+ reads_fastq: str,
13
+ input_fast5: str,
14
+ output_txt: str
15
+ ) -> dict:
16
+ """
17
+ Index a FASTQ file and verify FAST5 file accessibility.
18
+
19
+ Args:
20
+ reads_fastq: Path to the input FASTQ file
21
+ input_fast5: Path to the FAST5 file (used for verification)
22
+ output_txt: Path where the fast5-check output will be written
23
+ """
24
+ # Validate input paths
25
+ reads_fastq_path = Path(reads_fastq)
26
+ input_fast5_path = Path(input_fast5)
27
+ output_txt_path = Path(output_txt)
28
+
29
+ if not reads_fastq_path.exists():
30
+ raise FileNotFoundError(f"FASTQ file not found: {reads_fastq_path}")
31
+ if not input_fast5_path.exists():
32
+ raise FileNotFoundError(f"FAST5 file not found: {input_fast5_path}")
33
+
34
+ # Create output directory if it doesn't exist
35
+ output_txt_path.parent.mkdir(parents=True, exist_ok=True)
36
+
37
+ # Step 1: Run nanopolish index
38
+ index_cmd = ["nanopolish", "index", str(reads_fastq_path)]
39
+ try:
40
+ index_result = subprocess.run(
41
+ index_cmd,
42
+ capture_output=True,
43
+ text=True,
44
+ check=False
45
+ )
46
+ if index_result.returncode != 0:
47
+ raise RuntimeError(
48
+ f"nanopolish index failed with exit code {index_result.returncode}\n"
49
+ f"stdout: {index_result.stdout}\n"
50
+ f"stderr: {index_result.stderr}"
51
+ )
52
+ except FileNotFoundError:
53
+ raise RuntimeError("nanopolish executable not found in PATH")
54
+
55
+ # Step 2: Run nanopolish fast5-check
56
+ check_cmd = ["nanopolish", "fast5-check", "-r", str(reads_fastq_path)]
57
+ try:
58
+ check_result = subprocess.run(
59
+ check_cmd,
60
+ capture_output=True,
61
+ text=True,
62
+ check=False
63
+ )
64
+ if check_result.returncode != 0:
65
+ raise RuntimeError(
66
+ f"nanopolish fast5-check failed with exit code {check_result.returncode}\n"
67
+ f"stdout: {check_result.stdout}\n"
68
+ f"stderr: {check_result.stderr}"
69
+ )
70
+ except FileNotFoundError:
71
+ raise RuntimeError("nanopolish executable not found in PATH")
72
+
73
+ # Write stdout to output file
74
+ with open(output_txt_path, 'w') as f:
75
+ f.write(check_result.stdout)
76
+
77
+ # Return structured metadata
78
+ return {
79
+ "status": "success",
80
+ "index_command": " ".join(index_cmd),
81
+ "check_command": " ".join(check_cmd),
82
+ "index_stdout": index_result.stdout,
83
+ "index_stderr": index_result.stderr,
84
+ "check_stdout": check_result.stdout,
85
+ "check_stderr": check_result.stderr,
86
+ "output_file": str(output_txt_path),
87
+ "reads_fastq": str(reads_fastq_path),
88
+ "input_fast5": str(input_fast5_path)
89
+ }
90
+
91
+ if __name__ == "__main__":
92
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/ncbi-genome-download_select_assembly_dry_run_test_server.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ import subprocess
3
+ import os
4
+ import json
5
+ import shutil
6
+ from pathlib import Path
7
+
8
+ mcp = FastMCP("ncbi-genome-download")
9
+
10
+ @mcp.tool()
11
+ def select_assembly_dry_run(
12
+ assembly_summary: str,
13
+ cache_dir: str,
14
+ output_tsv: str
15
+ ) -> dict:
16
+ """
17
+ Select one fixed RefSeq bacterial assembly by accession in dry-run mode from a pinned assembly-summary snapshot.
18
+ """
19
+ # Step 1: Create cache directory
20
+ cache_path = Path(cache_dir) / "ncbi-genome-download"
21
+ cache_path.mkdir(parents=True, exist_ok=True)
22
+
23
+ # Step 2: Copy assembly summary to cache
24
+ source = Path(assembly_summary)
25
+ dest = cache_path / "refseq_bacteria_assembly_summary.txt"
26
+ shutil.copy2(source, dest)
27
+
28
+ # Step 3: Run ncbi-genome-download in dry-run mode
29
+ env = os.environ.copy()
30
+ env["XDG_CACHE_HOME"] = cache_dir
31
+
32
+ cmd = [
33
+ "ncbi-genome-download",
34
+ "bacteria",
35
+ "-s", "refseq",
36
+ "-A", "GCF_036600855.1",
37
+ "-F", "fasta",
38
+ "-n"
39
+ ]
40
+
41
+ result = subprocess.run(
42
+ cmd,
43
+ capture_output=True,
44
+ text=True,
45
+ env=env,
46
+ check=False
47
+ )
48
+
49
+ if result.returncode != 0:
50
+ raise RuntimeError(
51
+ f"ncbi-genome-download failed with exit code {result.returncode}: {result.stderr}"
52
+ )
53
+
54
+ # Write stdout to output_tsv
55
+ output_path = Path(output_tsv)
56
+ output_path.parent.mkdir(parents=True, exist_ok=True)
57
+ output_path.write_text(result.stdout)
58
+
59
+ return {
60
+ "endpoint": "select_assembly_dry_run",
61
+ "status": "success",
62
+ "output_tsv": str(output_path),
63
+ "stdout": result.stdout,
64
+ "stderr": result.stderr,
65
+ "returncode": result.returncode
66
+ }
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/nextalign_align_nucleotides_test_server.py ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+ import subprocess
4
+ import sys
5
+ from pathlib import Path
6
+ from typing import Any
7
+
8
+ from mcp.server.fastmcp import FastMCP
9
+
10
+ mcp = FastMCP("nextalign")
11
+
12
+
13
+ @mcp.tool()
14
+ def align_nucleotides(
15
+ reference_fasta: str,
16
+ query_fasta: str,
17
+ output_fasta: str,
18
+ ) -> dict[str, Any]:
19
+ """
20
+ Align nucleotide sequences using nextalign.
21
+
22
+ Args:
23
+ reference_fasta: Path to the reference FASTA file.
24
+ query_fasta: Path to the query FASTA file.
25
+ output_fasta: Path where the output FASTA file will be written.
26
+
27
+ Returns:
28
+ JSON-serializable metadata about the alignment run.
29
+ """
30
+ # Validate required parameters
31
+ if not reference_fasta:
32
+ raise ValueError("reference_fasta is required")
33
+ if not query_fasta:
34
+ raise ValueError("query_fasta is required")
35
+ if not output_fasta:
36
+ raise ValueError("output_fasta is required")
37
+
38
+ # Resolve paths
39
+ ref_path = Path(reference_fasta).resolve()
40
+ query_path = Path(query_fasta).resolve()
41
+ out_path = Path(output_fasta).resolve()
42
+
43
+ # Check input files exist
44
+ if not ref_path.is_file():
45
+ raise FileNotFoundError(f"Reference FASTA not found: {ref_path}")
46
+ if not query_path.is_file():
47
+ raise FileNotFoundError(f"Query FASTA not found: {query_path}")
48
+
49
+ # Create output parent directory
50
+ out_path.parent.mkdir(parents=True, exist_ok=True)
51
+
52
+ # Build command according to execution plan
53
+ cmd = [
54
+ "nextalign",
55
+ "run",
56
+ "--input-ref",
57
+ str(ref_path),
58
+ "--output-fasta",
59
+ str(out_path),
60
+ "--include-reference",
61
+ "--in-order",
62
+ str(query_path),
63
+ ]
64
+
65
+ # Run the command
66
+ try:
67
+ result = subprocess.run(
68
+ cmd,
69
+ capture_output=True,
70
+ text=True,
71
+ check=False,
72
+ )
73
+ except FileNotFoundError:
74
+ raise RuntimeError(
75
+ "nextalign executable not found. Ensure it is installed and in PATH."
76
+ )
77
+
78
+ if result.returncode != 0:
79
+ error_msg = result.stderr.strip() or result.stdout.strip() or "Unknown error"
80
+ raise RuntimeError(
81
+ f"nextalign failed with exit code {result.returncode}: {error_msg}"
82
+ )
83
+
84
+ # Verify output file was created
85
+ if not out_path.is_file():
86
+ raise RuntimeError(f"Output file was not created: {out_path}")
87
+
88
+ # Return structured metadata
89
+ return {
90
+ "status": "success",
91
+ "command": cmd,
92
+ "exit_code": result.returncode,
93
+ "reference_fasta": str(ref_path),
94
+ "query_fasta": str(query_path),
95
+ "output_fasta": str(out_path),
96
+ "output_size_bytes": out_path.stat().st_size,
97
+ "stdout": result.stdout,
98
+ "stderr": result.stderr,
99
+ }
100
+
101
+
102
+ if __name__ == "__main__":
103
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/nextclade_analyze_sequence_test_server.py ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+ import subprocess
4
+ import sys
5
+ from pathlib import Path
6
+ from typing import Any, Dict
7
+
8
+ from mcp.server.fastmcp import FastMCP
9
+
10
+ mcp = FastMCP("nextclade-analyze")
11
+
12
+
13
+ @mcp.tool()
14
+ def analyze_sequence(
15
+ reference_fasta: str,
16
+ query_fasta: str,
17
+ output_fasta: str,
18
+ output_json: str,
19
+ ) -> Dict[str, Any]:
20
+ """
21
+ Run Nextclade sequence analysis with a local reference and query FASTA.
22
+
23
+ Args:
24
+ reference_fasta: Path to the reference FASTA file (passed as -r).
25
+ query_fasta: Path to the query FASTA file (positional argument).
26
+ output_fasta: Path where the aligned output FASTA will be written (-o).
27
+ output_json: Path where the JSON results will be written (-J).
28
+ """
29
+ # Resolve paths to absolute paths
30
+ ref_path = Path(reference_fasta).resolve()
31
+ query_path = Path(query_fasta).resolve()
32
+ out_fasta_path = Path(output_fasta).resolve()
33
+ out_json_path = Path(output_json).resolve()
34
+
35
+ # Validate input files exist
36
+ if not ref_path.is_file():
37
+ raise FileNotFoundError(f"Reference FASTA not found: {ref_path}")
38
+ if not query_path.is_file():
39
+ raise FileNotFoundError(f"Query FASTA not found: {query_path}")
40
+
41
+ # Create parent directories for outputs
42
+ out_fasta_path.parent.mkdir(parents=True, exist_ok=True)
43
+ out_json_path.parent.mkdir(parents=True, exist_ok=True)
44
+
45
+ # Build the command exactly as specified in the execution plan
46
+ cmd = [
47
+ "nextclade",
48
+ "run",
49
+ "-r",
50
+ str(ref_path),
51
+ "-o",
52
+ str(out_fasta_path),
53
+ "-J",
54
+ str(out_json_path),
55
+ str(query_path),
56
+ ]
57
+
58
+ # Run the command without shell=True
59
+ try:
60
+ result = subprocess.run(
61
+ cmd,
62
+ capture_output=True,
63
+ text=True,
64
+ check=False,
65
+ )
66
+ except FileNotFoundError:
67
+ raise RuntimeError(
68
+ "The 'nextclade' executable was not found. Ensure it is installed and on PATH."
69
+ )
70
+
71
+ # Raise on non-zero exit
72
+ if result.returncode != 0:
73
+ error_msg = result.stderr.strip() or result.stdout.strip() or "Unknown error"
74
+ raise RuntimeError(
75
+ f"nextclade run failed with exit code {result.returncode}: {error_msg}"
76
+ )
77
+
78
+ # Verify output files were created
79
+ if not out_fasta_path.is_file():
80
+ raise RuntimeError(f"Expected output FASTA was not created: {out_fasta_path}")
81
+ if not out_json_path.is_file():
82
+ raise RuntimeError(f"Expected output JSON was not created: {out_json_path}")
83
+
84
+ # Read the JSON output for structured metadata
85
+ try:
86
+ with open(out_json_path, "r", encoding="utf-8") as f:
87
+ json_data = json.load(f)
88
+ except (json.JSONDecodeError, OSError) as e:
89
+ json_data = None
90
+ # We still return success metadata even if JSON parsing fails
91
+
92
+ # Build structured metadata
93
+ metadata: Dict[str, Any] = {
94
+ "status": "success",
95
+ "command": cmd,
96
+ "returncode": result.returncode,
97
+ "output_fasta": str(out_fasta_path),
98
+ "output_json": str(out_json_path),
99
+ "stdout": result.stdout,
100
+ "stderr": result.stderr,
101
+ "json_summary": json_data,
102
+ }
103
+
104
+ return metadata
105
+
106
+
107
+ if __name__ == "__main__":
108
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/ngmlr_align_long_reads_test_server.py ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+ import subprocess
4
+ import sys
5
+ from pathlib import Path
6
+
7
+ from mcp.server.fastmcp import FastMCP
8
+
9
+ mcp = FastMCP("ngmlr-mcp")
10
+
11
+
12
+ @mcp.tool()
13
+ def align_long_reads(
14
+ reference_fasta: str,
15
+ reads_fastq: str,
16
+ output_sam: str,
17
+ ) -> dict:
18
+ """
19
+ Align long reads to a reference genome using ngmlr.
20
+
21
+ Args:
22
+ reference_fasta: Path to the reference genome (FASTA/Q, can be gzipped)
23
+ reads_fastq: Path to the read file (FASTA/Q)
24
+ output_sam: Path to the output SAM file
25
+
26
+ Returns:
27
+ JSON-serializable metadata about the alignment run.
28
+ """
29
+ # Validate required inputs
30
+ ref_path = Path(reference_fasta)
31
+ reads_path = Path(reads_fastq)
32
+ out_path = Path(output_sam)
33
+
34
+ if not ref_path.exists():
35
+ raise FileNotFoundError(f"Reference file not found: {reference_fasta}")
36
+ if not reads_path.exists():
37
+ raise FileNotFoundError(f"Reads file not found: {reads_fastq}")
38
+
39
+ # Create output parent directories
40
+ out_path.parent.mkdir(parents=True, exist_ok=True)
41
+
42
+ # Build command per execution plan
43
+ cmd = [
44
+ "ngmlr",
45
+ "-r",
46
+ str(ref_path),
47
+ "-q",
48
+ str(reads_path),
49
+ "-o",
50
+ str(out_path),
51
+ "-t",
52
+ "1",
53
+ "--skip-write",
54
+ "--no-progress",
55
+ ]
56
+
57
+ # Run the command
58
+ try:
59
+ result = subprocess.run(
60
+ cmd,
61
+ capture_output=True,
62
+ text=True,
63
+ check=False,
64
+ )
65
+ except FileNotFoundError:
66
+ raise RuntimeError(
67
+ "ngmlr executable not found. Please ensure it is installed and in PATH."
68
+ )
69
+
70
+ if result.returncode != 0:
71
+ error_msg = result.stderr.strip() or result.stdout.strip() or "Unknown error"
72
+ raise RuntimeError(
73
+ f"ngmlr failed with exit code {result.returncode}: {error_msg}"
74
+ )
75
+
76
+ # Check output file was created
77
+ if not out_path.exists():
78
+ raise RuntimeError(
79
+ f"ngmlr completed but output file was not created: {output_sam}"
80
+ )
81
+
82
+ # Return structured metadata
83
+ return {
84
+ "endpoint": "align_long_reads",
85
+ "tool": "ngmlr",
86
+ "version": "0.2.7",
87
+ "reference": str(ref_path),
88
+ "reads": str(reads_path),
89
+ "output": str(out_path),
90
+ "threads": 1,
91
+ "skip_write": True,
92
+ "no_progress": True,
93
+ "exit_code": result.returncode,
94
+ "stdout": result.stdout,
95
+ "stderr": result.stderr,
96
+ "output_size_bytes": out_path.stat().st_size,
97
+ }
98
+
99
+
100
+ if __name__ == "__main__":
101
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/ont-fast5-api_summarize_single_read_fast5_test_server.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ import subprocess
3
+ import sys
4
+ import os
5
+ import json
6
+ from pathlib import Path
7
+
8
+ mcp = FastMCP("ont-fast5-api")
9
+
10
+ @mcp.tool()
11
+ def summarize_single_read_fast5(input_fast5: str, output_json: str) -> dict:
12
+ """
13
+ Summarize a single-read FAST5 file by extracting channel metadata, tracking metadata, and raw signal.
14
+
15
+ Args:
16
+ input_fast5: Path to the input single-read FAST5 file
17
+ output_json: Path where the JSON summary will be written
18
+ """
19
+ # Create output parent directory if needed
20
+ output_path = Path(output_json)
21
+ output_path.parent.mkdir(parents=True, exist_ok=True)
22
+
23
+ # Validate input file exists
24
+ if not Path(input_fast5).exists():
25
+ raise FileNotFoundError(f"Input FAST5 file not found: {input_fast5}")
26
+
27
+ # Python code to execute
28
+ python_code = (
29
+ "import json,sys; "
30
+ "from ont_fast5_api.fast5_file import Fast5File; "
31
+ "h=Fast5File(sys.argv[1]); "
32
+ "r=h.get_raw_data(); "
33
+ "d={'channel':h.get_channel_info()['channel_number'],"
34
+ "'read_count':len(h.status.read_info),"
35
+ "'raw':[int(x) for x in r.tolist()],"
36
+ "'tracking':h.get_tracking_id()}; "
37
+ "h.close(); "
38
+ "open(sys.argv[2],'w').write(json.dumps(d,sort_keys=True)+'\\n')"
39
+ )
40
+
41
+ # Build command
42
+ cmd = [
43
+ sys.executable,
44
+ "-c",
45
+ python_code,
46
+ input_fast5,
47
+ output_json
48
+ ]
49
+
50
+ try:
51
+ # Execute the command
52
+ result = subprocess.run(
53
+ cmd,
54
+ capture_output=True,
55
+ text=True,
56
+ check=False
57
+ )
58
+
59
+ # Check for non-zero exit
60
+ if result.returncode != 0:
61
+ raise RuntimeError(
62
+ f"Command failed with exit code {result.returncode}\n"
63
+ f"stderr: {result.stderr}"
64
+ )
65
+
66
+ # Verify output file was created
67
+ if not output_path.exists():
68
+ raise RuntimeError(f"Output file was not created: {output_json}")
69
+
70
+ # Read and validate the output
71
+ with open(output_path, 'r') as f:
72
+ summary = json.load(f)
73
+
74
+ return {
75
+ "status": "success",
76
+ "output_file": str(output_path),
77
+ "summary": summary
78
+ }
79
+
80
+ except subprocess.TimeoutExpired:
81
+ raise RuntimeError("Command timed out")
82
+ except Exception as e:
83
+ raise RuntimeError(f"Error executing command: {str(e)}")
84
+
85
+ if __name__ == "__main__":
86
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/orthofinder_infer_orthogroups_test_server.py ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import shutil
3
+ import subprocess
4
+ import sys
5
+ from pathlib import Path
6
+ from typing import Any, Dict
7
+
8
+ from mcp.server.fastmcp import FastMCP
9
+
10
+ mcp = FastMCP("orthofinder")
11
+
12
+
13
+ @mcp.tool()
14
+ def infer_orthogroups(
15
+ input_dir: str,
16
+ orthogroups_tsv: str,
17
+ statistics_csv: str,
18
+ ) -> Dict[str, Any]:
19
+ """
20
+ Run DIAMOND all-vs-all and stop after orthogroup inference; copy date-named results to stable output paths.
21
+
22
+ Args:
23
+ input_dir: Directory containing FASTA proteomes.
24
+ orthogroups_tsv: Output path for the Orthogroups.csv file (copied from Results_*).
25
+ statistics_csv: Output path for the Statistics_Overall.csv file (copied from Results_*).
26
+ """
27
+ # Validate input directory exists
28
+ input_path = Path(input_dir)
29
+ if not input_path.is_dir():
30
+ raise ValueError(f"Input directory does not exist: {input_dir}")
31
+
32
+ # Create output parent directories
33
+ orthogroups_path = Path(orthogroups_tsv)
34
+ statistics_path = Path(statistics_csv)
35
+ orthogroups_path.parent.mkdir(parents=True, exist_ok=True)
36
+ statistics_path.parent.mkdir(parents=True, exist_ok=True)
37
+
38
+ # Step 1: Run orthofinder with -og to stop after orthogroup inference
39
+ # Use -t 1 -a 1 -S diamond as specified in the execution plan
40
+ cmd = [
41
+ "orthofinder",
42
+ "-f",
43
+ input_dir,
44
+ "-t",
45
+ "1",
46
+ "-a",
47
+ "1",
48
+ "-S",
49
+ "diamond",
50
+ "-og",
51
+ ]
52
+ try:
53
+ result = subprocess.run(
54
+ cmd,
55
+ check=True,
56
+ capture_output=True,
57
+ text=True,
58
+ )
59
+ except subprocess.CalledProcessError as e:
60
+ # Include stderr in the error message for debugging
61
+ raise RuntimeError(
62
+ f"OrthoFinder failed with exit code {e.returncode}\n"
63
+ f"stdout: {e.stdout}\n"
64
+ f"stderr: {e.stderr}"
65
+ ) from e
66
+
67
+ # Step 2: Find the most recent Results_* directory in input_dir
68
+ results_dirs = sorted(
69
+ [p for p in input_path.iterdir() if p.is_dir() and p.name.startswith("Results_")]
70
+ )
71
+ if not results_dirs:
72
+ raise RuntimeError(
73
+ f"No Results_* directory found in {input_dir} after OrthoFinder run"
74
+ )
75
+ result_dir = results_dirs[-1] # tail -1 after sort
76
+
77
+ # Step 3: Copy Orthogroups.csv to orthogroups_tsv
78
+ orthogroups_source = result_dir / "Orthogroups.csv"
79
+ if not orthogroups_source.is_file():
80
+ raise RuntimeError(f"Expected file not found: {orthogroups_source}")
81
+ shutil.copy2(orthogroups_source, orthogroups_path)
82
+
83
+ # Step 4: Copy Statistics_Overall.csv to statistics_csv
84
+ statistics_source = result_dir / "Statistics_Overall.csv"
85
+ if not statistics_source.is_file():
86
+ raise RuntimeError(f"Expected file not found: {statistics_source}")
87
+ shutil.copy2(statistics_source, statistics_path)
88
+
89
+ # Return structured metadata
90
+ return {
91
+ "status": "success",
92
+ "input_dir": str(input_path.resolve()),
93
+ "results_dir": str(result_dir.resolve()),
94
+ "orthogroups_tsv": str(orthogroups_path.resolve()),
95
+ "statistics_csv": str(statistics_path.resolve()),
96
+ "stdout": result.stdout,
97
+ "stderr": result.stderr,
98
+ }
99
+
100
+
101
+ if __name__ == "__main__":
102
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/paml_pairwise_dn_ds_test_server.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ import subprocess
3
+ import os
4
+ import shutil
5
+ import json
6
+ from pathlib import Path
7
+
8
+ mcp = FastMCP("paml")
9
+
10
+ @mcp.tool()
11
+ def pairwise_dn_ds(
12
+ input_sequences: str,
13
+ control_file: str,
14
+ output_results: str,
15
+ output_dn: str
16
+ ) -> str:
17
+ """
18
+ Compute pairwise dN/dS ratios using PAML's yn00 program.
19
+
20
+ Args:
21
+ input_sequences: Path to the input sequence file (PHYLIP format)
22
+ control_file: Path to the control file (will be materialized)
23
+ output_results: Path where the main results file will be written
24
+ output_dn: Path where the dN matrix will be copied
25
+ """
26
+ # Create output parent directories
27
+ for path in [output_results, output_dn]:
28
+ parent = os.path.dirname(os.path.abspath(path))
29
+ os.makedirs(parent, exist_ok=True)
30
+
31
+ # Materialize control file
32
+ control_dir = os.path.dirname(os.path.abspath(control_file))
33
+ os.makedirs(control_dir, exist_ok=True)
34
+
35
+ # Step 1: Copy input sequences to control file directory
36
+ seq_copy = f"{control_file}.seq"
37
+ shutil.copy2(input_sequences, seq_copy)
38
+
39
+ # Step 2: Write control file
40
+ ctl_content = (
41
+ "seqfile = yn00.ctl.seq\n"
42
+ "outfile = results.txt\n"
43
+ "verbose = 0\n"
44
+ "icode = 0\n"
45
+ "weighting = 0\n"
46
+ "commonf3x4 = 0\n"
47
+ )
48
+ ctl_path = os.path.join(control_dir, "yn00.ctl")
49
+ with open(ctl_path, "w") as f:
50
+ f.write(ctl_content)
51
+
52
+ # Step 3: Run yn00
53
+ try:
54
+ result = subprocess.run(
55
+ ["yn00", "yn00.ctl"],
56
+ cwd=control_dir,
57
+ capture_output=True,
58
+ text=True,
59
+ check=False
60
+ )
61
+ if result.returncode != 0:
62
+ raise RuntimeError(f"yn00 failed with exit code {result.returncode}: {result.stderr}")
63
+ except FileNotFoundError:
64
+ raise RuntimeError("yn00 executable not found in PATH")
65
+
66
+ # Step 4: Copy results to output paths
67
+ results_source = os.path.join(control_dir, "results.txt")
68
+ if not os.path.exists(results_source):
69
+ raise RuntimeError("yn00 did not produce results.txt")
70
+ shutil.copy2(results_source, output_results)
71
+
72
+ # Step 5: Copy dN matrix
73
+ dn_source = os.path.join(control_dir, "2YN.dN")
74
+ if not os.path.exists(dn_source):
75
+ raise RuntimeError("yn00 did not produce 2YN.dN")
76
+ shutil.copy2(dn_source, output_dn)
77
+
78
+ # Return structured metadata
79
+ return json.dumps({
80
+ "status": "success",
81
+ "output_results": output_results,
82
+ "output_dn": output_dn,
83
+ "control_file": control_file,
84
+ "input_sequences": input_sequences
85
+ }, indent=2)
86
+
87
+ if __name__ == "__main__":
88
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/parasail-python_global_align_test_server.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ import subprocess
3
+ import json
4
+ import os
5
+ import sys
6
+
7
+ mcp = FastMCP("parasail-python")
8
+
9
+ @mcp.tool()
10
+ def global_align(sequence_a: str, sequence_b: str, output_json: str) -> dict:
11
+ """
12
+ Perform global pairwise sequence alignment using parasail NW trace with gap-open 10 and gap-extension 1.
13
+
14
+ Args:
15
+ sequence_a: Path to FASTA file containing first sequence
16
+ sequence_b: Path to FASTA file containing second sequence
17
+ output_json: Path where JSON output will be written
18
+
19
+ Returns:
20
+ Dictionary with alignment results and metadata
21
+ """
22
+ # Create output directory if needed
23
+ output_dir = os.path.dirname(os.path.abspath(output_json))
24
+ os.makedirs(output_dir, exist_ok=True)
25
+
26
+ # Build command exactly as specified in execution plan
27
+ cmd = [
28
+ "python3.13",
29
+ "-c",
30
+ "import json,parasail,sys; rd=lambda p:''.join(x.strip() for x in open(p) if not x.startswith('>')); r=parasail.nw_trace_striped_16(rd(sys.argv[1]),rd(sys.argv[2]),10,1,parasail.dnafull); d={'score':r.score,'end_query':r.end_query,'end_ref':r.end_ref,'cigar':r.cigar.decode.decode()}; open(sys.argv[3],'w').write(json.dumps(d,sort_keys=True)+'\\n')",
31
+ sequence_a,
32
+ sequence_b,
33
+ output_json
34
+ ]
35
+
36
+ # Execute without shell=True
37
+ result = subprocess.run(cmd, capture_output=True, text=True)
38
+
39
+ if result.returncode != 0:
40
+ raise RuntimeError(f"Alignment failed with exit code {result.returncode}: {result.stderr}")
41
+
42
+ # Read and return the output
43
+ with open(output_json, 'r') as f:
44
+ output_data = json.load(f)
45
+
46
+ return {
47
+ "status": "success",
48
+ "output_file": output_json,
49
+ "result": output_data
50
+ }
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/picard_sort_sam_test_server.py ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+ import subprocess
4
+ import sys
5
+ from pathlib import Path
6
+
7
+ from mcp.server.fastmcp import FastMCP
8
+
9
+ mcp = FastMCP("picard-sort-sam")
10
+
11
+
12
+ @mcp.tool()
13
+ def sort_sam(input_bam: str, output_bam: str, output_sam: str) -> dict:
14
+ """
15
+ Sort a BAM file by coordinate order, create an index, and render the sorted
16
+ BAM as SAM text.
17
+
18
+ Args:
19
+ input_bam: Path to the input BAM file.
20
+ output_bam: Path where the sorted, indexed BAM file will be written.
21
+ output_sam: Path where the SAM text output will be written.
22
+ """
23
+ # Create parent directories for output files
24
+ for path_str in [output_bam, output_sam]:
25
+ path = Path(path_str)
26
+ if path.parent and not path.parent.exists():
27
+ path.parent.mkdir(parents=True, exist_ok=True)
28
+
29
+ # Step 1: Run SortSam
30
+ sort_cmd = [
31
+ "picard",
32
+ "SortSam",
33
+ f"INPUT={input_bam}",
34
+ f"OUTPUT={output_bam}",
35
+ "SORT_ORDER=coordinate",
36
+ "CREATE_INDEX=true",
37
+ "VALIDATION_STRINGENCY=SILENT",
38
+ ]
39
+ try:
40
+ result = subprocess.run(
41
+ sort_cmd,
42
+ check=True,
43
+ capture_output=True,
44
+ text=True,
45
+ )
46
+ except subprocess.CalledProcessError as e:
47
+ raise RuntimeError(
48
+ f"SortSam failed with exit code {e.returncode}\n"
49
+ f"stdout: {e.stdout}\nstderr: {e.stderr}"
50
+ ) from e
51
+
52
+ # Step 2: Run ViewSam and capture stdout to output_sam
53
+ view_cmd = [
54
+ "picard",
55
+ "ViewSam",
56
+ f"I={output_bam}",
57
+ "ALIGNMENT_STATUS=All",
58
+ "PF_STATUS=All",
59
+ ]
60
+ try:
61
+ result = subprocess.run(
62
+ view_cmd,
63
+ check=True,
64
+ capture_output=True,
65
+ text=True,
66
+ )
67
+ except subprocess.CalledProcessError as e:
68
+ raise RuntimeError(
69
+ f"ViewSam failed with exit code {e.returncode}\n"
70
+ f"stdout: {e.stdout}\nstderr: {e.stderr}"
71
+ ) from e
72
+
73
+ # Write captured stdout to output_sam
74
+ with open(output_sam, "w", encoding="utf-8") as f:
75
+ f.write(result.stdout)
76
+
77
+ # Return structured metadata
78
+ return {
79
+ "input_bam": input_bam,
80
+ "output_bam": output_bam,
81
+ "output_sam": output_sam,
82
+ "sort_order": "coordinate",
83
+ "index_created": True,
84
+ "validation_stringency": "SILENT",
85
+ "view_sam_arguments": {
86
+ "alignment_status": "All",
87
+ "pf_status": "All",
88
+ },
89
+ "status": "success",
90
+ }
91
+
92
+
93
+ if __name__ == "__main__":
94
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/portcullis_prepare_splice_inputs_test_server.py ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ import subprocess
3
+ import os
4
+ import json
5
+ import sys
6
+ from pathlib import Path
7
+
8
+ mcp = FastMCP("portcullis")
9
+
10
+ @mcp.tool()
11
+ def prepare_splice_inputs(
12
+ reference_fasta: str,
13
+ input_bam: str,
14
+ output_dir: str
15
+ ) -> str:
16
+ """
17
+ Prepare splice junction analysis inputs by copying and indexing the genome
18
+ and sorting/indexing one BAM file.
19
+
20
+ Args:
21
+ reference_fasta: Path to the reference genome FASTA file
22
+ input_bam: Path to the input BAM file
23
+ output_dir: Directory for output files
24
+
25
+ Returns:
26
+ JSON-serializable metadata about the operation
27
+ """
28
+ # Create output directory if it doesn't exist
29
+ output_path = Path(output_dir)
30
+ output_path.mkdir(parents=True, exist_ok=True)
31
+
32
+ # Build the command
33
+ cmd = [
34
+ "portcullis",
35
+ "prep",
36
+ "-o",
37
+ output_dir,
38
+ "--force",
39
+ "--copy",
40
+ "-t",
41
+ "1",
42
+ reference_fasta,
43
+ input_bam
44
+ ]
45
+
46
+ # Set environment with PATH prepend
47
+ env = os.environ.copy()
48
+ env["PATH"] = "/225040511/miniconda3/envs/bioenv/bin:" + env.get("PATH", "")
49
+
50
+ try:
51
+ # Execute the command
52
+ result = subprocess.run(
53
+ cmd,
54
+ capture_output=True,
55
+ text=True,
56
+ env=env,
57
+ check=False
58
+ )
59
+
60
+ if result.returncode != 0:
61
+ raise RuntimeError(
62
+ f"portcullis prep failed with exit code {result.returncode}\n"
63
+ f"stdout: {result.stdout}\n"
64
+ f"stderr: {result.stderr}"
65
+ )
66
+
67
+ # Return structured metadata
68
+ metadata = {
69
+ "endpoint": "prepare_splice_inputs",
70
+ "tool": "portcullis",
71
+ "version": "1.2.4",
72
+ "command": cmd,
73
+ "returncode": result.returncode,
74
+ "stdout": result.stdout,
75
+ "stderr": result.stderr,
76
+ "output_dir": str(output_path.resolve()),
77
+ "reference_fasta": reference_fasta,
78
+ "input_bam": input_bam,
79
+ "status": "success"
80
+ }
81
+
82
+ return json.dumps(metadata, indent=2)
83
+
84
+ except FileNotFoundError as e:
85
+ raise RuntimeError(f"portcullis executable not found: {e}")
86
+ except Exception as e:
87
+ raise RuntimeError(f"Error executing portcullis prep: {e}")
88
+
89
+ if __name__ == "__main__":
90
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/prank_align_proteins_test_server.py ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+ import subprocess
4
+ import sys
5
+ from pathlib import Path
6
+ from mcp.server.fastmcp import FastMCP
7
+
8
+ mcp = FastMCP("prank-align-proteins")
9
+
10
+ @mcp.tool()
11
+ def align_proteins(input_fasta: str, output_prefix: str) -> dict:
12
+ """
13
+ Align protein sequences using PRANK.
14
+
15
+ Args:
16
+ input_fasta: Path to input FASTA file
17
+ output_prefix: Prefix for output files (FASTA output will be written to {output_prefix}.fasta)
18
+
19
+ Returns:
20
+ JSON-serializable metadata about the alignment run
21
+ """
22
+ # Validate input file exists
23
+ input_path = Path(input_fasta)
24
+ if not input_path.is_file():
25
+ raise FileNotFoundError(f"Input FASTA file not found: {input_fasta}")
26
+
27
+ # Create output parent directory if needed
28
+ output_path = Path(output_prefix)
29
+ output_dir = output_path.parent if output_path.parent != Path('.') else Path('.')
30
+ output_dir.mkdir(parents=True, exist_ok=True)
31
+
32
+ # Build command exactly as specified in execution plan
33
+ cmd = [
34
+ "prank",
35
+ f"-d={input_fasta}",
36
+ f"-o={output_prefix}",
37
+ "-f=fasta",
38
+ "-once",
39
+ "-quiet"
40
+ ]
41
+
42
+ # Execute the command
43
+ try:
44
+ result = subprocess.run(
45
+ cmd,
46
+ capture_output=True,
47
+ text=True,
48
+ check=False,
49
+ shell=False
50
+ )
51
+ except FileNotFoundError:
52
+ raise RuntimeError("PRANK executable 'prank' not found in PATH")
53
+ except Exception as e:
54
+ raise RuntimeError(f"Failed to execute PRANK: {str(e)}")
55
+
56
+ # Check exit code
57
+ if result.returncode != 0:
58
+ error_msg = result.stderr.strip() if result.stderr.strip() else result.stdout.strip()
59
+ raise RuntimeError(f"PRANK failed with exit code {result.returncode}: {error_msg}")
60
+
61
+ # Determine output file paths
62
+ fasta_output = f"{output_prefix}.fasta"
63
+ # PRANK may also produce other files (e.g., .dnd, .xml) but we only report the main FASTA output
64
+
65
+ # Check if output file was created
66
+ if not os.path.isfile(fasta_output):
67
+ # Try alternative naming patterns
68
+ alt_outputs = [
69
+ f"{output_prefix}.best.fas",
70
+ f"{output_prefix}.fas",
71
+ f"{output_prefix}.fasta"
72
+ ]
73
+ for alt in alt_outputs:
74
+ if os.path.isfile(alt):
75
+ fasta_output = alt
76
+ break
77
+ else:
78
+ raise RuntimeError(f"PRANK completed but output FASTA file not found. Expected {fasta_output}")
79
+
80
+ # Collect metadata
81
+ metadata = {
82
+ "endpoint": "align_proteins",
83
+ "tool": "prank",
84
+ "version": "251117",
85
+ "input_fasta": str(input_path.resolve()),
86
+ "output_prefix": str(output_path.resolve()),
87
+ "output_fasta": str(Path(fasta_output).resolve()),
88
+ "exit_code": result.returncode,
89
+ "stdout": result.stdout,
90
+ "stderr": result.stderr,
91
+ "command": cmd,
92
+ "parameters": {
93
+ "input_fasta": input_fasta,
94
+ "output_prefix": output_prefix
95
+ }
96
+ }
97
+
98
+ return metadata
99
+
100
+ if __name__ == "__main__":
101
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/prophyle_index_and_classify_reads_test_server.py ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ import subprocess
3
+ import os
4
+ import sys
5
+ import json
6
+ from pathlib import Path
7
+
8
+ mcp = FastMCP("prophyle")
9
+
10
+
11
+ @mcp.tool()
12
+ def index_and_classify_reads(
13
+ library_dir: str,
14
+ tree_file: str,
15
+ reads_fasta: str,
16
+ index_dir: str,
17
+ output_kraken: str,
18
+ ) -> dict:
19
+ """
20
+ Index a reference library and classify reads using ProPhyle.
21
+
22
+ Args:
23
+ library_dir: Path to the directory containing the reference library (FASTA files).
24
+ tree_file: Path to the phylogenetic tree file (Newick format).
25
+ reads_fasta: Path to the input reads file in FASTA format.
26
+ index_dir: Path to the directory where the index will be created.
27
+ output_kraken: Path to the output file for Kraken-format classification results.
28
+ """
29
+ # Create output parent directories
30
+ for path in [index_dir, output_kraken]:
31
+ parent = Path(path).parent
32
+ if parent and not parent.exists():
33
+ parent.mkdir(parents=True, exist_ok=True)
34
+
35
+ # Step 1: Index
36
+ index_cmd = [
37
+ "prophyle",
38
+ "index",
39
+ "-A",
40
+ "-g",
41
+ library_dir,
42
+ "-j",
43
+ "1",
44
+ "-k",
45
+ "15",
46
+ tree_file,
47
+ index_dir,
48
+ ]
49
+ index_result = subprocess.run(
50
+ index_cmd,
51
+ capture_output=True,
52
+ text=True,
53
+ check=False,
54
+ )
55
+ if index_result.returncode != 0:
56
+ raise RuntimeError(
57
+ f"prophyle index failed with exit code {index_result.returncode}\n"
58
+ f"stdout: {index_result.stdout}\n"
59
+ f"stderr: {index_result.stderr}"
60
+ )
61
+
62
+ # Step 2: Classify
63
+ classify_cmd = [
64
+ "prophyle",
65
+ "classify",
66
+ "-k",
67
+ "15",
68
+ "-f",
69
+ "kraken",
70
+ index_dir,
71
+ reads_fasta,
72
+ ]
73
+ classify_result = subprocess.run(
74
+ classify_cmd,
75
+ capture_output=True,
76
+ text=True,
77
+ check=False,
78
+ )
79
+ if classify_result.returncode != 0:
80
+ raise RuntimeError(
81
+ f"prophyle classify failed with exit code {classify_result.returncode}\n"
82
+ f"stdout: {classify_result.stdout}\n"
83
+ f"stderr: {classify_result.stderr}"
84
+ )
85
+
86
+ # Write stdout to output_kraken
87
+ with open(output_kraken, "w") as f:
88
+ f.write(classify_result.stdout)
89
+
90
+ return {
91
+ "index_dir": index_dir,
92
+ "output_kraken": output_kraken,
93
+ "index_exit_code": index_result.returncode,
94
+ "classify_exit_code": classify_result.returncode,
95
+ "index_stdout": index_result.stdout,
96
+ "index_stderr": index_result.stderr,
97
+ "classify_stderr": classify_result.stderr,
98
+ }
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/pyfastx_fasta_statistics_test_server.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+ import subprocess
4
+ import sys
5
+ from pathlib import Path
6
+ from typing import Any
7
+
8
+ from mcp.server.fastmcp import FastMCP
9
+
10
+ # Initialize FastMCP server
11
+ mcp = FastMCP("pyfastx-fasta-statistics")
12
+
13
+
14
+ @mcp.tool()
15
+ def fasta_statistics(input_fasta: str, output_tsv: str) -> dict[str, Any]:
16
+ """
17
+ Compute detailed statistics for a FASTA file using pyfastx stat.
18
+
19
+ Args:
20
+ input_fasta: Path to the input FASTA file.
21
+ output_tsv: Path where the statistics TSV output will be written.
22
+
23
+ Returns:
24
+ JSON-serializable metadata about the execution.
25
+ """
26
+ # Validate input path
27
+ input_path = Path(input_fasta)
28
+ if not input_path.exists():
29
+ raise FileNotFoundError(f"Input FASTA file not found: {input_fasta}")
30
+
31
+ # Prepare output path
32
+ output_path = Path(output_tsv)
33
+ output_path.parent.mkdir(parents=True, exist_ok=True)
34
+
35
+ # Build command according to execution plan
36
+ command = ["pyfastx", "stat", str(input_path)]
37
+
38
+ # Execute the command without shell=True
39
+ try:
40
+ result = subprocess.run(
41
+ command,
42
+ capture_output=True,
43
+ text=True,
44
+ check=False,
45
+ )
46
+ except FileNotFoundError:
47
+ raise RuntimeError(
48
+ "pyfastx executable not found. Ensure it is installed and in PATH."
49
+ )
50
+
51
+ # Check exit code
52
+ if result.returncode != 0:
53
+ error_msg = result.stderr.strip() or result.stdout.strip() or "Unknown error"
54
+ raise RuntimeError(
55
+ f"pyfastx stat failed with exit code {result.returncode}: {error_msg}"
56
+ )
57
+
58
+ # Write stdout to output file
59
+ output_path.write_text(result.stdout, encoding="utf-8")
60
+
61
+ # Return structured metadata
62
+ return {
63
+ "endpoint": "fasta_statistics",
64
+ "input_fasta": str(input_path),
65
+ "output_tsv": str(output_path),
66
+ "exit_code": result.returncode,
67
+ "stdout_bytes": len(result.stdout.encode("utf-8")),
68
+ "stderr_bytes": len(result.stderr.encode("utf-8")),
69
+ "command": command,
70
+ "success": True,
71
+ }
72
+
73
+
74
+ # Main entry point for MCP server
75
+ if __name__ == "__main__":
76
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/pyranges_merge_genomic_ranges_test_server.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ import subprocess
3
+ import sys
4
+ import os
5
+ import json
6
+
7
+ mcp = FastMCP("pyranges")
8
+
9
+ @mcp.tool()
10
+ def merge_genomic_ranges(input_bed: str, output_tsv: str) -> dict:
11
+ """
12
+ Read BED into PyRanges, merge overlaps, and write the canonical three-column table.
13
+
14
+ Args:
15
+ input_bed: Path to input BED file
16
+ output_tsv: Path to output TSV file
17
+ """
18
+ # Create output parent directories
19
+ output_dir = os.path.dirname(os.path.abspath(output_tsv))
20
+ os.makedirs(output_dir, exist_ok=True)
21
+
22
+ # Build the command
23
+ code = (
24
+ "import sys; "
25
+ "import pyranges as pr; "
26
+ "x=pr.read_bed(sys.argv[1]); "
27
+ "x.merge().df.to_csv(sys.argv[2],sep='\\t',index=False)"
28
+ )
29
+ cmd = [
30
+ "python",
31
+ "-c",
32
+ code,
33
+ input_bed,
34
+ output_tsv
35
+ ]
36
+
37
+ # Execute the command
38
+ result = subprocess.run(
39
+ cmd,
40
+ capture_output=True,
41
+ text=True,
42
+ check=False
43
+ )
44
+
45
+ if result.returncode != 0:
46
+ raise RuntimeError(
47
+ f"Command failed with exit code {result.returncode}: {result.stderr}"
48
+ )
49
+
50
+ return {
51
+ "endpoint": "merge_genomic_ranges",
52
+ "input_bed": input_bed,
53
+ "output_tsv": output_tsv,
54
+ "exit_code": result.returncode,
55
+ "stdout": result.stdout,
56
+ "stderr": result.stderr
57
+ }
58
+
59
+ if __name__ == "__main__":
60
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/pyrodigal_predict_genes_test_server.py ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ import subprocess
3
+ import os
4
+ import json
5
+ from pathlib import Path
6
+
7
+ mcp = FastMCP("pyrodigal-predict-genes")
8
+
9
+ @mcp.tool()
10
+ def predict_genes(
11
+ input_file: str,
12
+ output_gff: str,
13
+ output_proteins: str,
14
+ output_genes: str
15
+ ) -> dict:
16
+ """
17
+ Predict genes using pyrodigal in metagenomic mode with one worker.
18
+
19
+ Args:
20
+ input_file: Path to input FASTA file
21
+ output_gff: Path to output GFF file
22
+ output_proteins: Path to output protein translations file
23
+ output_genes: Path to output nucleotide sequences of genes file
24
+ """
25
+ # Create parent directories for all output files
26
+ for output_path in [output_gff, output_proteins, output_genes]:
27
+ parent_dir = os.path.dirname(os.path.abspath(output_path))
28
+ os.makedirs(parent_dir, exist_ok=True)
29
+
30
+ # Build command according to execution plan
31
+ cmd = [
32
+ "pyrodigal",
33
+ "-p", "meta",
34
+ "-i", input_file,
35
+ "-o", output_gff,
36
+ "-a", output_proteins,
37
+ "-d", output_genes,
38
+ "-j", "1"
39
+ ]
40
+
41
+ # Execute command without shell=True
42
+ result = subprocess.run(
43
+ cmd,
44
+ capture_output=True,
45
+ text=True,
46
+ check=False
47
+ )
48
+
49
+ # Raise on non-zero exit
50
+ if result.returncode != 0:
51
+ raise RuntimeError(
52
+ f"pyrodigal failed with exit code {result.returncode}\n"
53
+ f"stdout: {result.stdout}\n"
54
+ f"stderr: {result.stderr}"
55
+ )
56
+
57
+ # Verify output files were created
58
+ output_files = {
59
+ "gff": output_gff,
60
+ "proteins": output_proteins,
61
+ "genes": output_genes
62
+ }
63
+
64
+ file_sizes = {}
65
+ for key, path in output_files.items():
66
+ if os.path.exists(path):
67
+ file_sizes[key] = os.path.getsize(path)
68
+ else:
69
+ file_sizes[key] = 0
70
+
71
+ # Return structured JSON-serializable metadata
72
+ return {
73
+ "status": "success",
74
+ "command": cmd,
75
+ "returncode": result.returncode,
76
+ "output_files": {
77
+ "gff": output_gff,
78
+ "proteins": output_proteins,
79
+ "genes": output_genes
80
+ },
81
+ "file_sizes": file_sizes,
82
+ "stdout": result.stdout,
83
+ "stderr": result.stderr
84
+ }
85
+
86
+ if __name__ == "__main__":
87
+ mcp.run()
Biomanus-V2/Experiment1/runs/v4_flash_formal_133_20260826/evaluation_generated/direct_prompt/pysam_summarize_bam_test_server.py ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+ import subprocess
4
+ import sys
5
+ from pathlib import Path
6
+
7
+ from mcp.server.fastmcp import FastMCP
8
+
9
+ mcp = FastMCP("pysam")
10
+
11
+
12
+ @mcp.tool()
13
+ def summarize_bam(input_bam: str, output_json: str) -> dict:
14
+ """
15
+ Summarize a BAM file using pinned pysam 0.24.0 (py310h4a09ff2_1).
16
+
17
+ Args:
18
+ input_bam: Path to input BAM file (BAI sidecar is implicit).
19
+ output_json: Path where JSON summary will be written.
20
+
21
+ Returns:
22
+ JSON-serializable metadata about the operation.
23
+ """
24
+ # Validate required parameters
25
+ if not input_bam:
26
+ raise ValueError("input_bam is required")
27
+ if not output_json:
28
+ raise ValueError("output_json is required")
29
+
30
+ input_bam_path = Path(input_bam)
31
+ output_json_path = Path(output_json)
32
+
33
+ # Create output parent directories
34
+ output_json_path.parent.mkdir(parents=True, exist_ok=True)
35
+
36
+ # Python code to execute (from execution_plan)
37
+ python_code = (
38
+ "import json,pysam,sys; "
39
+ "b=pysam.AlignmentFile(sys.argv[1],'rb'); "
40
+ "d={'references':list(b.references),'mapped':b.mapped,'unmapped':b.unmapped,"
41
+ "'records':sum(1 for _ in b.fetch(until_eof=True))}; "
42
+ "open(sys.argv[2],'w').write(json.dumps(d,sort_keys=True)+'\\n')"
43
+ )
44
+
45
+ # Build command exactly as specified in execution_plan
46
+ cmd = [
47
+ "python3.10",
48
+ "-c",
49
+ python_code,
50
+ str(input_bam_path),
51
+ str(output_json_path),
52
+ ]
53
+
54
+ # Execute without shell=True
55
+ try:
56
+ result = subprocess.run(
57
+ cmd,
58
+ capture_output=True,
59
+ text=True,
60
+ check=False,
61
+ )
62
+ except FileNotFoundError as e:
63
+ raise RuntimeError(f"Executable not found: {e}") from e
64
+ except Exception as e:
65
+ raise RuntimeError(f"Failed to execute command: {e}") from e
66
+
67
+ # Raise on non-zero exit
68
+ if result.returncode != 0:
69
+ stderr_msg = result.stderr.strip() if result.stderr else ""
70
+ raise RuntimeError(
71
+ f"Command failed with exit code {result.returncode}: {stderr_msg}"
72
+ )
73
+
74
+ # Verify output file was created
75
+ if not output_json_path.exists():
76
+ raise RuntimeError(f"Output file was not created: {output_json_path}")
77
+
78
+ # Read and validate the output JSON
79
+ try:
80
+ with open(output_json_path, "r") as f:
81
+ summary = json.load(f)
82
+ except (json.JSONDecodeError, OSError) as e:
83
+ raise RuntimeError(f"Failed to read output JSON: {e}") from e
84
+
85
+ # Return structured metadata
86
+ return {
87
+ "endpoint": "summarize_bam",
88
+ "input_bam": str(input_bam_path),
89
+ "output_json": str(output_json_path),
90
+ "exit_code": result.returncode,
91
+ "stdout": result.stdout,
92
+ "stderr": result.stderr,
93
+ "summary": summary,
94
+ }
95
+
96
+
97
+ if __name__ == "__main__":
98
+ mcp.run()