Skip to content

Python Package Overview

LEAF can be used as a Python package for scripted targeted analyses, batch processing pipelines, and integration into existing computational workflows.

When to use the package vs the UI

Web UI recommended forPython package recommended for
Performing exploratory or interactive analysisRunning batch analyses on many datasets with shared parameters
Reviewing peak quality and adjusting integrations manuallyReproducing an analysis as part of a manuscript or pipeline
Producing visualizations for inspectionIntegrating LEAF results with downstream Python tools (pandas, scikit-learn, etc.)
One-off or ad hoc workEmbedding LEAF in a multi-step workflow (Snakemake, Nextflow, custom scripts)

The two interfaces operate on the same underlying file formats: a .msd produced by the UI can be loaded by the Python package, and vice versa.

Installation

The Python package is installed by the same wheel that provides the leaf command-line tool. See Install the wheel + CLI for installation instructions.

To verify the package is importable:

python
from importlib.metadata import version

import leaf

print(version("leaf"))

Public surface

The package re-exports four classes intended for scripted use:

python
from leaf.analyzer import Samples, Extractor, PeakPicking, QCReport
NameRole
SamplesCentral data container — sparse intensity tensors, sample/metabolite indices, peak dictionary. The result of every extraction. Persisted via Samples.load(path) / samples.save(path).
ExtractorRAW / mzML extraction. Constructor takes a folder or file list plus a metabolite CSV; extract_metabolites(...) returns a Samples.
PeakPickingPeak detection on an existing Samples. Constructor takes the Samples; run(...) returns a quantification DataFrame.
QCReportEQC / IQC sample analysis (separate from the per-compound verdicts produced by leaf.analyzer.score).

For per-compound quality verdicts (good / warning / poor — the same colours the web UI shows), use the orchestrator in leaf.analyzer.score:

python
from leaf.analyzer.score import score_dataset, ScoringConfig

Public surface

The names above are stable as of LEAF 0.5; signatures and module paths may change before 1.0. The formal class reference (parameters, return types, methods) lives upstream in LEAF's developer docs. This manual covers usage patterns only — see Recipes for runnable examples.

Next

Recipes — common scripted-analysis tasks

LEAF is developed by the Morscher Lab.