SKILL.md
Version Compatibility
Reference examples tested with: pandas 2.2+, xcms 4.0+
Before using code patterns, verify installed versions match. If versions differ:
- Python:
pip show <package>thenhelp(module.function)to check signatures - R:
packageVersion('<pkg>')then?function_nameto verify parameters - CLI:
<tool> --versionthen<tool> --helpto confirm flags
If code throws ImportError, AttributeError, or TypeError, introspect the installed package and adapt the example to match the actual API rather than retrying.
Metabolite Annotation
Database Matching by m/z
Goal: Generate putative metabolite identifications by matching observed m/z values against HMDB.
Approach: Convert m/z to neutral mass by subtracting adduct mass, then query HMDB within a specified ppm tolerance.
"Annotate my metabolomics features with compound identities" → Match detected features against metabolite databases by exact mass, MS/MS spectra, and retention time to assign compound identities with confidence levels.
library(MetaboAnalystR)
# Load feature table
features <- read.csv('feature_table.csv')
# Search HMDB by exact mass
search_hmdb <- function(mz, adduct = '[M+H]+', ppm = 10) {
# Calculate neutral mass from m/z
adduct_masses <- list(
'[M+H]+' = 1.007276,
'[M+Na]+' = 22.989218,
'[M-H]-' = -1.007276,
'[M+Cl]-' = 34.969402
)
neutral_mass <- mz - adduct_masses[[adduct]]
# Query HMDB (or local database)
# Returns putative matches
matches <- QueryHMDB(neutral_mass, ppm)
return(matches)
}
# Apply to all features
annotations <- lapply(features$mz, function(m) search_hmdb(m, '[M+H]+', 10))
MS/MS Spectral Matching
from matchms import calculate_scores
from matchms.importing import load_from_mgf
from matchms.similarity import CosineGreedy
# Load query spectra
queries = list(load_from_mgf('sample_msms.mgf'))
# Load reference library (e.g., GNPS, MassBank)
references = list(load_from_mgf('reference_library.mgf'))
# Calculate similarity scores
similarity = CosineGreedy(tolerance=0.01)
scores = calculate_scores(references, queries, similarity)
# Get best matches
for query_idx, query in enumerate(queries):
best_match_idx = scores.scores[:, query_idx].argmax()
best_score = scores.scores[best_match_idx, query_idx]
if best_score > 0.7:
ref = references[best_match_idx]
print(f'{query.get("precursor_mz")}: {ref.get("compound_name")} (score={best_score:.2f})')
