Skip to main content
Glama
systemsomicslab

ms-data-parser

library_match_feature

Read-only

Matches measured MS/MS spectra in .dcl files against a loaded reference library by precursor m/z or spot ID and returns top-scoring candidates as a TSV summary.

Instructions

測定 MS/MS(.dcl)を参照ライブラリ(library_load 済みの store)と照合し、 上位候補を返す。

照合の対象は precursor_mz か spot_id のどちらか一方で指定する。 spot_id(MasterAlignmentID。eic_search 等で引ける)を渡すと、precursor m/z・ RT・極性を同じバッチの .arf2(arf2_path、省略時は現在のデータフォルダ)から取り、 測定スペクトルはアラインメント .dcl(dcl_file、省略時は .arf2 と同じバッチ)の そのスポットの代表 MS/MS を使う。precursor が ARF2 と ±0.01 で合わなければ 照合せず status="dcl_precursor_mismatch"、ID が無ければ spot_not_found。 rt / ion_mode を明示すれば ARF2 の値より優先する。

ion_mode は "positive" / "negative"(大小は問わない——store.candidates() が COLLATE NOCASE で比較するため、PAI2 由来の IonMode.Positive.name のような "Positive" 表記もそのまま渡してよい)。

mz_tol / ms2_tol / rt_tol は明示指定が無ければ store の search_params (.dbs 由来なら実値)を使い、それも無ければ既定値 (_DEFAULT_MZ_TOL / _DEFAULT_MS2_TOL / _DEFAULT_RT_TOL、現在の値は 0.01 / 0.025 / 0.2)を使う。これらは参照ライブラリの候補検索(store.candidates() の precursor m/z 窓・RT 窓)にだけ効く。 .dcl から測定 MS/MS を引く窓は _measured_spectrum 内部の固定既定(dcl/reader.py と同じ mz_tol=0.01/ rt_tol=0.2)を常に使い、ここの引数や store の search_params の影響を受けない (最終レビュー Important 7: .dbs の RtTolerance 既定 100.0 のような ライブラリ用の値を .dcl 側の RT 窓に流用すると、同じ precursor m/z の 別ピークの測定スペクトルを黙って拾ってしまうため、2 つの窓を分離した)。 足切り(relative_amp_cutoff / absolute_amp_cutoff)と質量範囲 (mass_range_begin / mass_range_end)も同じ search_params から採って 採点(match_spectrum)に渡す——検証 CLI(scripts/verify_spectral_match.py) と同じ集合(最終レビュー Important 2)。

.dcl に MS/MS が無い(未取得)場合は status="not_found" を返す—— 「候補と合わなかった」のではなく「照合する測定スペクトルがそもそも無い」ことを 区別するため、dcl_find_msms と同じ文言の方針に揃える。

候補は total_score の降順で返す(rank 列・ranked_by フィールドが 同じ基準を指す)。MS-DIAL の総合スコア(上流 GetTotalScore)で、 rt + precursor_mz + (weighted+simple+reverse)/3 + matched_peaks_percentage の正規化しない和——1 を超える。組み立て方は戻り値の scoring が明示する (RT 項が入ったかは .dbs の IsUseTimeForAnnotationScoring 次第で、 数値だけを見ても分からないため)。同点は候補順を温存する(安定ソート)。

上流の順位付けと完全に同じではない。 MsScanMatchResultContainer.ResultOrder は (IsManuallyModified, IsReferenceMatched, IsAnnotationSuggested, Priority, TotalScore) の辞書順で、TotalScore は最後のタイブレークにすぎない。 支配項の IsReferenceMatched は脂質クラス固有の判定 (Lipidomics/、上流 66,932 行)に依存するため移植していない。実データでは この判定が無いと全候補が True になってゲートとして働かないので、 total_score 単独比較が現実的な最良の近似という位置づけ。 帰結として、上位に化学的にありえない候補が残ることがある (docs/output_format/library.md §14.9)。

top_n は上位何件を返すかの上限(既定 5)。負値を渡すと全件を返す (明示的な仕様ではなく Python のスライス挙動に由来する副作用的な動作 ——件数を絞りたくないだけなら大きな正の値を渡すこと)。

候補一覧は TSV(列名 1 回)で返す。スペクトル座標と alignment は戻り値に 含めない(LLM の文脈を食うため)。座標は session.library.last_match に 持ち、library_plot_mirror がそこから読む。

Input Schema

NameRequiredDescriptionDefault
rtNo
top_nNo
mz_tolNo
rt_tolNo
ms2_tolNo
spot_idNo
dcl_fileNo
ion_modeNo
arf2_pathNo
precursor_mzNo

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.6/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With only readOnlyHint available, the description carries the full burden and does far more than required: it enumerates the exact status codes (`dcl_precursor_mismatch`, `spot_not_found`, `not_found`) and their triggers, documents default tolerance values, discloses that tolerance arguments affect only library candidate search and not the fixed internal `.dcl` spectrum window, and warns that ranking is an approximation of upstream ordering with known false-positive risk.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The purpose and mutual-exclusivity rule are front-loaded, which is good, but the text balloons with internal artifacts that do not help an agent invoke the tool: review-ticket citations ('最終レビュー Important 7'), source file paths (`dcl/reader.py`), and upstream line counts ('上流 66,932 行'). The rationale for split tolerance windows is genuinely useful, but it is buried in an overlong aside.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

There is no output schema and 10 optional parameters, so the description must describe returns — and it does: TSV with header, `total_score`-descending order, rank/ranked_by fields, explicit note that spectrum coordinates are excluded and live in `session.library.last_match`. Combined with the status-code taxonomy, nothing material is missing for correct invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 0%, so the description must compensate — and it does: it explains `spot_id` provenance, `arf2_path`/`dcl_file` fallback behavior, `ion_mode` case-insensitivity and accepted spellings, `rt`/`ion_mode` precedence over ARF2, the tolerance fallback chain with concrete defaults, and `top_n`'s default plus its undocumented negative-value behavior. Nearly every one of the 10 parameters is given meaning beyond its type.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The opening sentence states a precise verb and resource: match measured MS/MS from `.dcl` against a reference library loaded via `library_load`, returning top candidates. It also implicitly distinguishes itself from siblings by naming `library_load` as a prerequisite and `library_plot_mirror` as the downstream consumer of stored coordinates.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It states the key usage constraint clearly — specify exactly one of `precursor_mz` or `spot_id` — and explains that `spot_id` can be obtained via `eic_search`, plus the `library_load` prerequisite. What it lacks is explicit routing against alternatives (e.g., when direct precursor-based matching is preferable to spot-based, or when to use `dcl_find_msms` instead).

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.