How mwang87/massquerylanguage works
Purpose and Entry Points
MassQL is a Python reference implementation of a mass-spectrometry query DSL: it parses MassQL statements and evaluates them against MS1/MS2 spectral data. Primary entry points are the Python API, notably massql/msql_engine.py, and the installed massql CLI implemented by massql/msql_cmd.py. Package exposure begins at massql/__init__.py.
Language Definition and Parsing
The language contract is defined by the EBNF grammar in massql/msql.ebnf. massql/msql_parser.py converts query text into an intermediate structured representation; this is the boundary between user-provided DSL syntax and execution logic. Parsed forms are also supported as JSON-oriented output, consistent with the documented parse API.
Query Translation and Execution
massql/msql_engine.py orchestrates query processing: accept query text plus an input filename or supplied MS1/MS2 data frames, parse the query, dispatch filtering, and return result data. massql/msql_translator.py translates parsed query structures into executable query/filter semantics. The central control flow is:
query string → parser → translated/interpreted clauses → engine evaluation → tabular results.
Spectral Data Boundary
massql/msql_fileloading.py is the ingestion boundary for mass-spectrometry files and produces separate MS1 and MS2 data frames. The engine can alternatively receive preloaded frames, separating file-format concerns from query evaluation. Representative fixture formats include tests/test_data/top_down.mgf and tests/test_data/top_down.txt; CLI examples document mzML input.
Filter Evaluation
massql/msql_engine_filters.py contains the domain-specific predicate layer used during evaluation. It applies MassQL constraints over precursor/product masses, neutral loss, tolerance, intensity, retention time, scan metadata, polarity, charge, and mobility. This layer is the key semantic boundary between generic data-frame operations and mass-spectrometry-aware matching.
Extraction and Visualization Outputs
massql/msql_extract.py supports extracting query-relevant spectral information from results/data. massql/msql_visualizer.py produces MS1/MS2 query visualizations, supporting the documented visualization endpoints. These are downstream consumers of parsed queries and loaded/evaluated spectral data rather than primary execution entry points.
Runtime, Packaging, and Integration
The implementation runs on Python (README states Python 3.9 is tested), with dependencies declared in requirements.txt and packaging in setup.py. GitHub Actions publish and validate the package through .github/workflows/publish.yml and test workflows. The README describes Nextflow/ProteoSAFe and hosted web API integration, but the tree contains only Nextflow runtime/cache artifacts under workflow/.nextflow; no workflow source or web-server implementation is present here.
Main entry points: msql_engine.py Query engine · msql_parser.py Query parser · msql_fileloading.py Spectral file loader · msql_engine_filters.py Mass-spec filters
Components 17
Interfaces
- Package exports · Exposes the MassQL library.
massql/__init__.py - Python API · Programmatic query evaluation interface.
massql/msql_engine.py - massql CLI
massql/msql_cmd.py
Query Processing
- MassQL grammar
massql/msql.ebnf - Query parser · Converts query text into structured query forms.
massql/msql_parser.py - Query translator · Turns parsed clauses into executable filter semantics.
massql/msql_translator.py - Query engine · Coordinates parsing, filtering, and tabular results.
massql/msql_engine.py - Mass-spec filters · Applies mass, tolerance, intensity, metadata, polarity, charge, and mobility constraints.
massql/msql_engine_filters.py
Spectral Data
- Spectral file loader · Loads files into separate MS1 and MS2 data frames.
massql/msql_fileloading.py - MS1 data frame
- MS2 data frame
- Example spectral files · Representative MGF and text spectral inputs.
tests/test_data/top_down.mgf
Outputs
- Tabular results
- Spectral extraction
massql/msql_extract.py - Query visualization · Produces MS1/MS2 query visualizations.
massql/msql_visualizer.py
Other components
- Package build · Defines installation and CLI distribution.
setup.py - Dependencies
requirements.txt
Connections 21
- Package exports → Python API: exposes
- Package build → massql CLI: installs
- Dependencies → Python API: runtime dependencies
- massql CLI → Query engine: invokes
- Python API → Query engine: evaluates through
- MassQL grammar → Query parser: defines syntax
- Query parser → Query translator: structured query
- Query translator → Query engine: executable clauses
- Query engine → Mass-spec filters: dispatches predicates
- Spectral file loader → MS1 data frame: loads
- Spectral file loader → MS2 data frame: loads
- Example spectral files → Spectral file loader: example inputs
- MS1 data frame → Query engine: preloaded input
- MS2 data frame → Query engine: preloaded input
- Query engine → Mass-spec filters: MS1/MS2 data
- Mass-spec filters → Tabular results: matched scans
- Query engine → Tabular results: returns
- Query parser → Spectral extraction: query structure
- Tabular results → Spectral extraction: matched data
- Query parser → Query visualization: query structure
- Tabular results → Query visualization: evaluated spectra