wnetdeconv
Spectral deconvolution via Wasserstein optimal transport.
Given an empirical spectrum and a library of theoretical component spectra,
wnetdeconv finds the mixture proportions that minimise the total Wasserstein
transport cost between the empirical signal and the weighted sum of components.
The inner problem at each set of proportions is solved exactly as a min-cost
flow (via pylmcf / LEMON), giving an
exact piecewise-linear objective with exact gradients — suitable for gradient-
based outer optimisation with scipy.
Supports 1-D spectra (NMR chemical shift, m/z) and higher-dimensional data (e.g. m/z + retention time).
Installation
pip install wnetdeconv
Dependencies: pylmcf, wnet, numpy, scipy.
Optional: pyopenms for loading featureXML files.
Concepts
Spectra as distributions
A spectrum is a set of (position, intensity) pairs. In 1-D (NMR chemical
shift, m/z) use Spectrum_1D; for higher-dimensional data (m/z + retention
time) use Spectrum with a (d, n) positions array.
from wnetdeconv import Spectrum_1D
empirical = Spectrum_1D([1.0, 2.0, 3.0], [10.0, 25.0, 15.0])
component = Spectrum_1D([1.0, 2.0, 3.0], [1.0, 2.0, 1.0])
Transport cost
Matching a unit of intensity from an empirical peak at position p to a
theoretical peak at position q costs distance(p, q). Peaks that cannot
be matched cheaply are instead routed to a trash node at a fixed penalty.
max_distance caps the farthest match considered; anything farther is cheaper
to trash. trash_cost (or the asymmetric pair
experimental_trash_cost / theoretical_trash_cost) sets that penalty.
Scaling
Internally all intensities and costs are scaled to integers for the MCF solver.
Intensities are quantised automatically by a p95-quantile policy
(wnet.scaling.WNetDeconvScaler); cost quantisation is chosen by the network
itself against its integer budget. Construction raises ValueError if
quantisation would silently discard more than 20% of any spectrum's total
intensity (see allow_intensity_loss). Pass scale_factor to override the
automatic scaling explicitly. The scipy ftol stop criterion is derived from
the actual scale factors, so the outer loop stops as soon as further improvement
is below the resolution the integer network can deliver.
The former precision parameter is deprecated and has no effect; passing a
non-default value raises a DeprecationWarning.
Solvers
DeconvSolver — unconstrained baseline
Solves the network at a given point and exposes total_cost() and
gradient(). Optimisation (via optimize(), L-BFGS-B) minimises cost with
only non-negativity bounds.
from wnetdeconv import DeconvSolver, Spectrum_1D
from wnet.distances import DistanceMetric
emp = Spectrum_1D([1.0, 100.0], [10.0, 30.0])
t1 = Spectrum_1D([1.0], [2.0]) # optimal proportion: 5
t2 = Spectrum_1D([100.0], [3.0]) # optimal proportion: 10
solver = DeconvSolver(
empirical_spectrum=emp,
theoretical_spectra=[t1, t2],
distance=DistanceMetric.LINF,
max_distance=10.0,
trash_cost=100.0,
)
result = solver.optimize()
print(result.x) # ~[5. 10.] (exact up to intensity quantization)
You can also drive the solver manually — useful when embedding it in your own optimisation loop:
solver.set_point([5.0, 10.0])
print(solver.total_cost()) # 0.0
print(solver.gradient()) # [200. 300.]
Note that the gradient is not zero at the optimum: the objective is piecewise
linear, and at a kink gradient() reports the right-derivative (here, the cost
of trashing the surplus theoretical mass that one more unit of each proportion
would add).
ConstrainedSolver — total-mass equality
Adds the constraint Σ wₛ · Iₛ = I_emp so that the mixture exactly accounts
for all empirical intensity. Uses SLSQP. Drop-in replacement for
DeconvSolver; call optimize() the same way.
from wnetdeconv import ConstrainedSolver
solver = ConstrainedSolver(
empirical_spectrum=emp,
theoretical_spectra=[t1, t2],
distance=DistanceMetric.LINF,
max_distance=10.0,
trash_cost=100.0,
)
result = solver.optimize()
optimize_cutting_plane() — kink-safe alternative optimizer
The objective is convex piecewise linear in the proportions, and descent
methods (L-BFGS-B, SLSQP) can stall on the kinks between linear pieces when
several components' spectra overlap heavily. optimize_cutting_plane()
(on DeconvSolver and ConstrainedSolver) runs Kelley's cutting-plane
method instead: each evaluation contributes a supporting plane and the next
iterate minimizes the accumulated plane model over the feasible polytope (a
small LP per iteration). It returns the best evaluated point together with
a model lower bound and gap; the mass-balance constraint is carried natively
by the LP. Typically converges in 10-40 evaluations and never returns a
point with higher cost than it evaluated. By default (polish=True) the
answer is then refined by the class's descent optimizer warm-started from
the cutting-plane point, and the cheaper of the two is returned — the plane
model navigates the kinks, the descent finishes the final linear piece, and
the comparison makes the combination monotone (never worse than either
stage alone).
Key parameters
| Parameter | Applies to | Description |
|---|---|---|
max_distance |
all | Maximum peak-to-peak match distance. Also sets the sparsity of the internal network in 1-D. |
trash_cost |
all | Symmetric penalty for unmatched peaks. |
experimental_trash_cost |
DeconvSolver |
Per-unit penalty for discarding empirical mass. |
theoretical_trash_cost |
DeconvSolver |
Per-unit penalty for discarding theoretical mass. |
precision |
all | Deprecated, no effect; non-default values raise DeprecationWarning. |
scale_factor |
all | Override automatic intensity/cost quantisation. |
smooth_sigma |
MagnetsteinSolver |
Gaussian pre-smoothing width in position units (default 0 = off). On evenly gridded profile 1H NMR, ~0.02 ppm (a typical linewidth) consistently helps when mixture and reference lineshapes differ (e.g. field-inhomogeneity distortion); much wider blurs small components away. Leave off for centroided data. |
Distance metrics
From wnet.distances.DistanceMetric:
L1— sum of absolute coordinate differences (Manhattan / taxicab)L2— Euclidean distanceLINF— maximum absolute coordinate difference (Chebyshev); dual of the W₁ earth-mover distance used by masserstein
Loading MS data (featureXML)
from wnetdeconv import Spectrum
emp = Spectrum.FromFeatureXML("sample.featureXML") # requires pyopenms
Architecture
wnetdeconv
├── Spectrum / Spectrum_1D — data containers (extend wnet.Distribution)
├── DeconvSolver — core: builds WassersteinNetwork, exposes cost + gradient
├── ConstrainedSolver — adds total-mass equality, uses SLSQP
│ └── MagnetsteinSolver — magnetstein-style: all spectra normalised to sum 1;
│ with MTD_th, defaults to independent two-sided trash
│ (dualdeconv3/4 semantics; independent_trash=False
│ restores the annihilating model)
├── MassersteinSolver2 — reproduces masserstein's dualdeconv2 (one-sided trash)
└── MassersteinSolver4 — reproduces dualdeconv4 (independent two-sided trash);
requires wnet >= 1.3.0 (independent trash)
The underlying min-cost flow is provided by wnet (network construction) and pylmcf (LEMON-based MCF algorithms, including warm-restart Network Simplex).
Related work
Sister paper: WNetAlign applies the same truncated Wasserstein / network simplex machinery to MS and NMR spectral alignment:
Król J, Bochenek M, Jopa S, Kazimierczuk K, Gambin A, Startek MP (2026). WNetAlign: fast and accurate spectra alignment using truncated Wasserstein distance and network simplex. Briefings in Bioinformatics, 27(3), bbag247. https://doi.org/10.1093/bib/bbag247
License
MIT
Metadata
Release files for wnetdeconv 0.11.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| wnetdeconv-0.11.0.tar.gz | 36.1 kB | Details |
Built distributions (wheels)
Total release size: 1.6 MB
Release files / wnetdeconv-0.11.0.tar.gz
| Download URL | wnetdeconv-0.11.0.tar.gz |
|---|---|
| Size | 36.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5c5fa3d00cbbd519bfa19f14818032290ec50ed014ae5cc583131f1d2f60e7de
|
|
BLAKE2b-256 checksum How to use checksums |
138d7483ca81924aa332160e5e86d47085603df53567f75cc7ac5746dd29d0c3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 3, 2026.
Transparency logRelease files / wnetdeconv-0.11.0-cp315-abi3t-win_arm64.whl
| Download URL | wnetdeconv-0.11.0-cp315-abi3t-win_arm64.whl |
|---|---|
| Size | 412.5 kB |
| Tags | CPython 3.15 Windows ARM64 abi3t |
|
SHA-256 checksum How to use checksums |
9b52240f53ae17fca5ae4587d3ee06a45131b75d24bdc8fa788340609d7290a5
|
|
BLAKE2b-256 checksum How to use checksums |
40f5d44375116584cf50ecde072c165e1721f18612f9082d50cefa36c6ffc3b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 3, 2026.
Transparency logRelease files / wnetdeconv-0.11.0-cp315-abi3t-win_amd64.whl
| Download URL | wnetdeconv-0.11.0-cp315-abi3t-win_amd64.whl |
|---|---|
| Size | 231.0 kB |
| Tags | CPython 3.15 Windows x86-64 abi3t |
|
SHA-256 checksum How to use checksums |
a81441844309f2d0aa709418a47f4714e24ad409770b5bfe63557665e4f566f4
|
|
BLAKE2b-256 checksum How to use checksums |
26731d38ccf5fa2269ae5bc542ea0cb4ae95af8c02451bf82eeb96bb2757e48d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 3, 2026.
Transparency logRelease files / wnetdeconv-0.11.0-cp315-abi3t-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | wnetdeconv-0.11.0-cp315-abi3t-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 33.7 kB |
| Tags | CPython 3.15 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 abi3t |
|
SHA-256 checksum How to use checksums |
fa1b43cae59c81d1951250d7cbba79f7ac75cf38dab1fb2705e11bbe9e862acb
|
|
BLAKE2b-256 checksum How to use checksums |
58d45576c8e66db92702d992fa8dc164bf8517518ffcb9bfa778eadebe7c0a80
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 3, 2026.
Transparency logRelease files / wnetdeconv-0.11.0-cp315-abi3t-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
| Download URL | wnetdeconv-0.11.0-cp315-abi3t-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl |
|---|---|
| Size | 34.2 kB |
| Tags | CPython 3.15 Linux glibc 2.24+ ARM64 Linux glibc 2.28+ ARM64 abi3t |
|
SHA-256 checksum How to use checksums |
5262ab2c28c337230911e92533c15e1bf800fff982f6d002c949ae94544e807d
|
|
BLAKE2b-256 checksum How to use checksums |
89c1ae04d494133baf15027e7bb884633c2e5493381a0c8b30ba868d84758290
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 3, 2026.
Transparency logRelease files / wnetdeconv-0.11.0-cp315-abi3t-macosx_11_0_arm64.whl
| Download URL | wnetdeconv-0.11.0-cp315-abi3t-macosx_11_0_arm64.whl |
|---|---|
| Size | 33.8 kB |
| Tags | CPython 3.15 abi3t macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
b368eeade6547ebba1b8be03657260964929988051ce774d450e9a719c4da3eb
|
|
BLAKE2b-256 checksum How to use checksums |
b1f6db4a82525cfb9ca7f0a78c92c4af2a1cd7c041c11c45e3e7e7fb38394ffd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 3, 2026.
Transparency logRelease files / wnetdeconv-0.11.0-cp315-abi3t-macosx_10_15_x86_64.whl
| Download URL | wnetdeconv-0.11.0-cp315-abi3t-macosx_10_15_x86_64.whl |
|---|---|
| Size | 33.3 kB |
| Tags | CPython 3.15 abi3t macOS 10.15+ x86-64 |
|
SHA-256 checksum How to use checksums |
f12fe735c9f93045dcf642cfd8ae8e4951b9b8d7f9f80cdfdab8b721eb942a1d
|
|
BLAKE2b-256 checksum How to use checksums |
f27d23efe10fb2830daa0d1933deb9ee4ee37b0e72b9f7896375e5d5e89edbfc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 3, 2026.
Transparency logRelease files / wnetdeconv-0.11.0-cp310-abi3-win_arm64.whl
| Download URL | wnetdeconv-0.11.0-cp310-abi3-win_arm64.whl |
|---|---|
| Size | 398.5 kB |
| Tags | CPython 3.10 Windows ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
bee8ed97586536ead2672f54acb0f07801dd406dd830640a539da18e133d654a
|
|
BLAKE2b-256 checksum How to use checksums |
39e332c421b95a3ea53de1b7f837f4832a3381076aef17fec73a10fad1e7ff0a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 3, 2026.
Transparency logRelease files / wnetdeconv-0.11.0-cp310-abi3-win_amd64.whl
| Download URL | wnetdeconv-0.11.0-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 223.6 kB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
4df094f432f7f94ee1e59ff5c83f5f6e1a842ac28e743e0260777583a5906afb
|
|
BLAKE2b-256 checksum How to use checksums |
6d590c79104c117acf62c1aba43bc6b924994625cc056aee21b8e0be95470910
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 3, 2026.
Transparency logRelease files / wnetdeconv-0.11.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
| Download URL | wnetdeconv-0.11.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl |
|---|---|
| Size | 33.6 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ ARM64 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
2bd236e351da30bf4d925b81ba60ca73f252928521a1d399b17b2f0bf6089cfb
|
|
BLAKE2b-256 checksum How to use checksums |
2fff70684de07c1070a8b0e80f47c18a17d0215a41e565458ee19e086bd9b732
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 3, 2026.
Transparency logRelease files / wnetdeconv-0.11.0-cp310-abi3-manylinux2010_x86_64.manylinux_2_12_x86_64.manylinux_2_28_x86_64.whl
| Download URL | wnetdeconv-0.11.0-cp310-abi3-manylinux2010_x86_64.manylinux_2_12_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 33.1 kB |
| Tags | CPython 3.10 Linux glibc 2.12+ x86-64 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
b79b91f88e5a21e78600a1b10f4e6b474fe3e2e8aec3a7cf39f1a0693ca88a73
|
|
BLAKE2b-256 checksum How to use checksums |
bae058848ff263ea6c0a09a8575c2d62c58770cd891745af62560fd869ff5ce8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 3, 2026.
Transparency logRelease files / wnetdeconv-0.11.0-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | wnetdeconv-0.11.0-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 33.5 kB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
20d3cf14b44beb34e2a6aa0aa76414ede9bec0a1bfb187ad43b2cd274b132666
|
|
BLAKE2b-256 checksum How to use checksums |
6a5bf7c3063927680830e1c931943de34f4c81edabd5e40e0d99089e9d697f7e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 3, 2026.
Transparency logRelease files / wnetdeconv-0.11.0-cp310-abi3-macosx_10_15_x86_64.whl
| Download URL | wnetdeconv-0.11.0-cp310-abi3-macosx_10_15_x86_64.whl |
|---|---|
| Size | 32.8 kB |
| Tags | CPython 3.10 abi3 macOS 10.15+ x86-64 |
|
SHA-256 checksum How to use checksums |
554c94205bad52c1a31cbe64cd36bb5b1bc53e44f1a01705c4c45fba2f58d324
|
|
BLAKE2b-256 checksum How to use checksums |
0a8ad9665509ba371ce94687244d8bd9c8fe7b8a10e79426689bd0d52377717d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 3, 2026.
Transparency log