Implements the Model Context Protocol server for the JuliaMSI mass
spectrometry imaging engine, covering phases 1–3 of the implementation
plan plus the main phase-4 items.
Tools (20):
session/dataset: msi_open_dataset, msi_close_dataset, msi_dataset_info,
msi_get_dataset_stats
spectra: msi_get_spectrum_at_coord, msi_get_spectrum_by_index
ion images: msi_get_mz_slice, msi_get_multiple_mz_slices,
msi_plan_ion_image, msi_plan_multiple_slices
preprocessing: msi_plan_preprocessing, msi_plan_streaming_pipeline,
msi_plan_analytics
execution: msi_execute_runspec, msi_list_plans,
msi_get_task_status, msi_get_task_result,
msi_cancel_task, msi_list_tasks
maintenance: msi_clean_artifacts
Resources (msi://): dataset/metadata, dataset/stats,
tasks/{task_id}/status, tasks/{task_id}/result
Prompts: analyze_region_of_interest, standard_pipeline, diagnose_task
- Persistent session: one MSIData kept alive between tool calls
- Plan -> execute -> poll async core (SHA-256 RunSpecs + background tasks)
- Results as on-disk artifacts (CSV/PGM/MatrixMarket) with compact previews
- Structured JSON-RPC error mapping with suggested actions
- stdio and Streamable HTTP transports, optional shared-token auth
- Artifact retention (age + size budgets) and glibc malloc_trim cleanup
- 107 tests + end-to-end stdio smoke test; validated on HR2MSI bladder
(imzML) and T9_A1/Col_1 (mzML)
Required JuliaMSI engine fixes are tracked in patches/ (already upstream
on the rel/Windows_Mac_Recompatibility branch and GitHub main).
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
# test/synthetic.jl
|
||||
# ---------------------------------------------------------------------------
|
||||
# Minimal, valid imzML + ibd generator used by the integration tests.
|
||||
#
|
||||
# Layout: `width` × `height` spectra, Float32, uncompressed, centroided, five
|
||||
# peaks per spectrum. One pixel is given a very strong peak at 300.0 Da so the
|
||||
# tests can assert that ion-image extraction actually finds signal.
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
function write_synthetic_imzml(dir::AbstractString;
|
||||
width::Int=4, height::Int=3,
|
||||
mzs::Vector{Float64}=[100.0, 200.0, 300.0, 400.0, 500.0])
|
||||
mkpath(dir)
|
||||
base = joinpath(dir, "synthetic")
|
||||
imzml_path = base * ".imzML"
|
||||
ibd_path = base * ".ibd"
|
||||
|
||||
n = width * height
|
||||
offsets = Vector{Tuple{Int64,Int64,Int64,Int64}}(undef, n) # mz_off, mz_len, int_off, int_len
|
||||
|
||||
open(ibd_path, "w") do io
|
||||
# JuliaMSI's parser ignores arrays whose external offset is 0 (it uses 0
|
||||
# as the "unset" sentinel), so keep a small pad at the start of the ibd.
|
||||
write(io, zeros(UInt8, 16))
|
||||
for k in 1:n
|
||||
x = ((k - 1) % width) + 1
|
||||
y = ((k - 1) ÷ width) + 1
|
||||
intensities = Float64[10.0 + x, 20.0 + y, 30.0, 40.0, 50.0]
|
||||
if (x, y) == (2, 2)
|
||||
intensities[3] = 1000.0
|
||||
elseif (x, y) == (4, 3)
|
||||
intensities[1] = 2000.0
|
||||
end
|
||||
mz_bytes = reinterpret(UInt8, Float32.(mzs))
|
||||
int_bytes = reinterpret(UInt8, Float32.(intensities))
|
||||
mz_off = position(io)
|
||||
write(io, mz_bytes)
|
||||
int_off = position(io)
|
||||
write(io, int_bytes)
|
||||
offsets[k] = (Int64(mz_off), Int64(length(mzs)), Int64(int_off), Int64(length(mzs)))
|
||||
end
|
||||
end
|
||||
|
||||
open(imzml_path, "w") do io
|
||||
write(io, """<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<mzML xmlns="http://psi.hupo.org/ms/mzml" version="1.1.0">
|
||||
<cvList count="1"><cv id="MS" fullName="Mass spectrometry ontology" URI="https://raw.githubusercontent.com/HUPO-PSI/psi-ms-CV/master/psi-ms.obo"/></cvList>
|
||||
<fileDescription><fileContent><cvParam cvRef="MS" accession="MS:1000579" name="MS1 spectrum" value=""/></fileContent></fileDescription>
|
||||
<referenceableParamGroupList count="2">
|
||||
<referenceableParamGroup id="mzArray">
|
||||
<cvParam cvRef="MS" accession="MS:1000514" name="m/z array" value=""/>
|
||||
<cvParam cvRef="MS" accession="MS:1000521" name="32-bit float" value=""/>
|
||||
<cvParam cvRef="MS" accession="MS:1000127" name="centroid spectrum" value=""/>
|
||||
</referenceableParamGroup>
|
||||
<referenceableParamGroup id="intensityArray">
|
||||
<cvParam cvRef="MS" accession="MS:1000515" name="intensity array" value=""/>
|
||||
<cvParam cvRef="MS" accession="MS:1000521" name="32-bit float" value=""/>
|
||||
</referenceableParamGroup>
|
||||
</referenceableParamGroupList>
|
||||
<softwareList count="1"><software id="synthetic" version="1.0"/></softwareList>
|
||||
<scanSettingsList count="1">
|
||||
<scanSettings id="scansettings1">
|
||||
<cvParam cvRef="IMS" accession="IMS:1000042" name="max count of pixels x" value="$(width)"/>
|
||||
<cvParam cvRef="IMS" accession="IMS:1000043" name="max count of pixels y" value="$(height)"/>
|
||||
</scanSettings>
|
||||
</scanSettingsList>
|
||||
<instrumentConfigurationList count="1">
|
||||
<instrumentConfiguration id="ic1"><cvParam cvRef="MS" accession="MS:1000031" name="instrument model" value="Synthetic-MS"/></instrumentConfiguration>
|
||||
</instrumentConfigurationList>
|
||||
<dataProcessingList count="1"><dataProcessing id="dp1"><processingMethod order="1" softwareRef="synthetic"><cvParam cvRef="MS" accession="MS:1000592" name="external calibration" value=""/></processingMethod></dataProcessing></dataProcessingList>
|
||||
<run id="run1" defaultInstrumentConfigurationRef="ic1">
|
||||
<spectrumList count="$(n)" defaultDataProcessingRef="dp1">
|
||||
""")
|
||||
for k in 1:n
|
||||
x = ((k - 1) % width) + 1
|
||||
y = ((k - 1) ÷ width) + 1
|
||||
mz_off, mz_len, int_off, int_len = offsets[k]
|
||||
write(io, """ <spectrum id="spectrum=$(k)" index="$(k-1)" defaultArrayLength="$(mz_len)">
|
||||
<cvParam cvRef="MS" accession="MS:1000511" name="ms level" value="1"/>
|
||||
<cvParam cvRef="MS" accession="MS:1000127" name="centroid spectrum" value=""/>
|
||||
<cvParam cvRef="IMS" accession="IMS:1000050" name="position x" value="$(x)"/>
|
||||
<cvParam cvRef="IMS" accession="IMS:1000051" name="position y" value="$(y)"/>
|
||||
<binaryDataArrayList count="2">
|
||||
<binaryDataArray encodedLength="$(mz_len * 4)">
|
||||
<cvParam cvRef="MS" accession="MS:1000514" name="m/z array" value=""/>
|
||||
<cvParam cvRef="MS" accession="MS:1000521" name="32-bit float" value=""/>
|
||||
<cvParam cvRef="IMS" accession="IMS:1000101" name="external encoded length" value="$(mz_len * 4)"/>
|
||||
<cvParam cvRef="IMS" accession="IMS:1000102" name="external data" value=""/>
|
||||
<cvParam cvRef="IMS" accession="IMS:1000103" name="external offset" value="$(mz_off)"/>
|
||||
<cvParam cvRef="IMS" accession="IMS:1000104" name="external array length" value="$(mz_len)"/>
|
||||
</binaryDataArray>
|
||||
<binaryDataArray encodedLength="$(int_len * 4)">
|
||||
<cvParam cvRef="MS" accession="MS:1000515" name="intensity array" value=""/>
|
||||
<cvParam cvRef="MS" accession="MS:1000521" name="32-bit float" value=""/>
|
||||
<cvParam cvRef="IMS" accession="IMS:1000101" name="external encoded length" value="$(int_len * 4)"/>
|
||||
<cvParam cvRef="IMS" accession="IMS:1000102" name="external data" value=""/>
|
||||
<cvParam cvRef="IMS" accession="IMS:1000103" name="external offset" value="$(int_off)"/>
|
||||
<cvParam cvRef="IMS" accession="IMS:1000104" name="external array length" value="$(int_len)"/>
|
||||
</binaryDataArray>
|
||||
</binaryDataArrayList>
|
||||
</spectrum>
|
||||
""")
|
||||
end
|
||||
write(io, """ </spectrumList>
|
||||
</run>
|
||||
</mzML>
|
||||
""")
|
||||
end
|
||||
|
||||
return imzml_path
|
||||
end
|
||||
Reference in New Issue
Block a user