ptr-ms-analysis 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ptr_ms_analysis-0.1.0/LICENSE +21 -0
- ptr_ms_analysis-0.1.0/PKG-INFO +156 -0
- ptr_ms_analysis-0.1.0/README.md +143 -0
- ptr_ms_analysis-0.1.0/pyproject.toml +31 -0
- ptr_ms_analysis-0.1.0/setup.cfg +4 -0
- ptr_ms_analysis-0.1.0/src/ptr_ms_analysis/__init__.py +3 -0
- ptr_ms_analysis-0.1.0/src/ptr_ms_analysis/analyze.py +2002 -0
- ptr_ms_analysis-0.1.0/src/ptr_ms_analysis/formula_id.py +322 -0
- ptr_ms_analysis-0.1.0/src/ptr_ms_analysis/gen_rate_constants.py +242 -0
- ptr_ms_analysis-0.1.0/src/ptr_ms_analysis/ptrms.py +889 -0
- ptr_ms_analysis-0.1.0/src/ptr_ms_analysis/reference/__init__.py +0 -0
- ptr_ms_analysis-0.1.0/src/ptr_ms_analysis/reference/hcn-calibration.md +80 -0
- ptr_ms_analysis-0.1.0/src/ptr_ms_analysis/reference/ionicon-h5-format.md +125 -0
- ptr_ms_analysis-0.1.0/src/ptr_ms_analysis/reference/ptr-ms-chemistry.md +125 -0
- ptr_ms_analysis-0.1.0/src/ptr_ms_analysis/reference/ptrlibrary.csv +921 -0
- ptr_ms_analysis-0.1.0/src/ptr_ms_analysis/reference/rate_constants.json +3688 -0
- ptr_ms_analysis-0.1.0/src/ptr_ms_analysis/viz.py +2099 -0
- ptr_ms_analysis-0.1.0/src/ptr_ms_analysis.egg-info/PKG-INFO +156 -0
- ptr_ms_analysis-0.1.0/src/ptr_ms_analysis.egg-info/SOURCES.txt +26 -0
- ptr_ms_analysis-0.1.0/src/ptr_ms_analysis.egg-info/dependency_links.txt +1 -0
- ptr_ms_analysis-0.1.0/src/ptr_ms_analysis.egg-info/entry_points.txt +2 -0
- ptr_ms_analysis-0.1.0/src/ptr_ms_analysis.egg-info/requires.txt +2 -0
- ptr_ms_analysis-0.1.0/src/ptr_ms_analysis.egg-info/top_level.txt +1 -0
- ptr_ms_analysis-0.1.0/tests/test_analysis_settings.py +118 -0
- ptr_ms_analysis-0.1.0/tests/test_auto_peak_settings.py +98 -0
- ptr_ms_analysis-0.1.0/tests/test_package_smoke.py +93 -0
- ptr_ms_analysis-0.1.0/tests/test_ptrms_provenance.py +38 -0
- ptr_ms_analysis-0.1.0/tests/test_resolve_k.py +212 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dan Saattrup Smart
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ptr-ms-analysis
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Open-source reprocessor for IONICON IoniTOF PTR-MS / PTR-TOF .h5 files — a PTR-MS Viewer replacement.
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Homepage, https://pypi.org/project/ptr-ms-analysis/
|
|
7
|
+
Requires-Python: >=3.9
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: h5py>=3.0
|
|
11
|
+
Requires-Dist: numpy>=1.20
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
# ptr-ms-analysis
|
|
15
|
+
|
|
16
|
+
Open-source reprocessor for IONICON IoniTOF PTR-MS / PTR-TOF `.h5` files — a
|
|
17
|
+
replacement for the proprietary PTR-MS Viewer. Extracts product-ion peaks from the
|
|
18
|
+
raw mass spectra, transmission-corrects them, converts to concentration (ppb and
|
|
19
|
+
µg/m³), and summarises per time segment.
|
|
20
|
+
|
|
21
|
+
**Agent-driven by design.** The CLI does the deterministic physics and detects
|
|
22
|
+
candidate peaks (with compound assignments + artifact flags) and time segments; an
|
|
23
|
+
agent assigns chemistry and curates segments. Humans talk to the agent, not to this
|
|
24
|
+
CLI. The commands below describe the complete package interface.
|
|
25
|
+
|
|
26
|
+
## Install / run
|
|
27
|
+
|
|
28
|
+
It's a proper package that ships its own dependencies (h5py + numpy) and reference
|
|
29
|
+
data. Install it **once** and `ptr` is on PATH everywhere. Recommended via `pipx`
|
|
30
|
+
(isolated environment for the CLI and its dependencies):
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pipx install ptr-ms-analysis
|
|
34
|
+
ptr inspect FILE.h5
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
**If `pipx` isn't installed yet**, install it first, then re-run the command above:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
brew install pipx && pipx ensurepath # macOS (Homebrew)
|
|
41
|
+
python3 -m pip install --user pipx && python3 -m pipx ensurepath # Linux / macOS (no brew)
|
|
42
|
+
py -m pip install --user pipx; py -m pipx ensurepath # Windows (PowerShell)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`pipx ensurepath` puts pipx's bin dir on PATH — open a new shell afterwards. Alternatives
|
|
46
|
+
that skip pipx entirely are `uv tool install ptr-ms-analysis` and
|
|
47
|
+
`python3 -m pip install ptr-ms-analysis` in a virtual environment. Works identically on
|
|
48
|
+
macOS, Linux, and Windows (pipx makes a real `ptr.exe`). Requires Python ≥ 3.9.
|
|
49
|
+
|
|
50
|
+
## Commands (all discovery output is JSON)
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
ptr inspect FILE.h5 # metadata, calibration, concentration-K, Vm
|
|
54
|
+
ptr peaks FILE.h5 # peaks + a ready-to-use suggested_label + top formula (--full for all candidates)
|
|
55
|
+
ptr segments FILE.h5 # stable plateaus (high=sample / low=bg)
|
|
56
|
+
# agent curates peaks + ranges into cfg.json, then:
|
|
57
|
+
ptr viz FILE.h5 --config cfg.json --out results.csv # serve review; 'Done' -> writes CSV
|
|
58
|
+
ptr viz FILE.h5 --config cfg.json --html review.html # portable standalone HTML instead
|
|
59
|
+
ptr analyze FILE.h5 \ # no review: curated config -> Viewer-style CSV
|
|
60
|
+
--config cfg.json --include-cycle-rows --out results.csv
|
|
61
|
+
ptr analyze FILE.h5 --auto-peaks --auto-segments --out results.csv # zero-curation fallback (auto-labels, drops noise)
|
|
62
|
+
ptr calibrate FILE.h5 viewer.csv # fit concentration constant K -> pass via --K
|
|
63
|
+
ptr compare results.csv viewer.csv --per-mass # accuracy vs a Viewer export
|
|
64
|
+
ptr rates benzaldehyde # browse proton-transfer rate constants (k)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
`viz` opens a browser review app for an existing peak list + ranges so an expert can
|
|
68
|
+
visually check and tweak peaks / segments / calibration. K, molar volume, kinetic and
|
|
69
|
+
humidity controls, R windowing, and peak/interval edits recompute from embedded preview
|
|
70
|
+
data; primary m/z, R_phys, and whole-run window mode require raw HDF5 re-extraction and
|
|
71
|
+
are prominently marked stale until Done. **It is the default final step** for analysing
|
|
72
|
+
a file: the agent curates a config from `peaks`/`segments` first, then opens `viz` on that
|
|
73
|
+
best solution — ideally nothing needs changing and *Done* is a one-click confirmation.
|
|
74
|
+
By default it serves a localhost app that live-saves every edit into the `--config` file
|
|
75
|
+
and, when the expert clicks *Done*, runs the full-precision analysis and writes the
|
|
76
|
+
`--out` CSV; `--html review.html` writes a portable offline file instead (edits exported
|
|
77
|
+
via a Download button).
|
|
78
|
+
A first-time user gets an automatic guided tour of the interface (skippable, remembered in
|
|
79
|
+
the browser). The agent can also add a `"checklist"` array to the config — short points for
|
|
80
|
+
the reviewer to confirm (an ambiguous segment, a relabelled background channel, a
|
|
81
|
+
calibration caveat) — which the app shows as a tickable list, so review notes live in the
|
|
82
|
+
app instead of a wall of chat text. `viz` does not detect peaks/segments. Skip it and run `analyze` directly only for a
|
|
83
|
+
headless/no-browser run or a hand-off file. There is no one-shot command; the delivered
|
|
84
|
+
CSV always comes from `analyze`, never the browser.
|
|
85
|
+
|
|
86
|
+
An analysis config may include an `analyze` object with `R`, `R_phys`, `K`,
|
|
87
|
+
`molar_volume`, `primary_mz`, `kinetic`, `k_anchor`, `humidity_correct`, `humidity_p`,
|
|
88
|
+
`humidity_ref`, and `whole_run_windows`. Omitted CLI options do not replace these
|
|
89
|
+
curated values: precedence is **CLI override > `analyze` config > legacy default**.
|
|
90
|
+
The same resolver is used by `analyze`, browser initial state, live-save, and Done.
|
|
91
|
+
Unknown top-level and nested config fields survive browser round trips.
|
|
92
|
+
|
|
93
|
+
By default `analyze` integrates each interval with each isolated peak's apex/window
|
|
94
|
+
**re-centred on that interval's own spectrum** — peaks drift between intervals (mass-cal
|
|
95
|
+
drift; a compound may be absent in a background), so one whole-run window sits off-peak
|
|
96
|
+
elsewhere. Clustered peaks are Gaussian/deconvolved fitted components at fixed model
|
|
97
|
+
centres, so their centre is not a measured apex and may not be a visible local maximum in
|
|
98
|
+
every interval. The delivered CSV is unchanged in shape (still one row per compound ×
|
|
99
|
+
interval); only each row's numbers reflect its interval's real peak. Set
|
|
100
|
+
`whole_run_windows: true` or pass `--no-per-interval` for one whole-run window per
|
|
101
|
+
compound. Manual peak windows remain manual. The Methods card reports these effective
|
|
102
|
+
values, their provenance, and whether the transmission curve and concentration are
|
|
103
|
+
available. Browser numbers are preview values: R windowing and other embedded-data
|
|
104
|
+
controls update live, while primary m/z, R_phys, and whole-run window mode are marked
|
|
105
|
+
stale and are applied only by the authoritative **Done**/`analyze` re-extraction.
|
|
106
|
+
|
|
107
|
+
Add `--pretty` to any command for indented JSON. `analyze` peak/segment sources:
|
|
108
|
+
`--config file.json` (curated, preferred), or `--auto-peaks`/`--auto-segments`
|
|
109
|
+
(zero-curation — auto-labels confident IDs, drops noise artifacts, consolidates
|
|
110
|
+
backgrounds). `--K` / `--molar-volume`
|
|
111
|
+
override the file-derived calibration to match a specific Viewer project. `--kinetic`
|
|
112
|
+
applies per-compound rate-constant (k) sensitivities from the bundled 218-compound
|
|
113
|
+
PTR Library table for physically resolved absolute concentrations. Low-proton-affinity
|
|
114
|
+
compounds (HCN, formaldehyde, formic acid…) are
|
|
115
|
+
auto-flagged: `analyze` always reports a humidity diagnostic for them, and
|
|
116
|
+
`--humidity-correct` (with a calibrated `--humidity-p`) normalises the humidity swing.
|
|
117
|
+
|
|
118
|
+
## Reference data attribution
|
|
119
|
+
|
|
120
|
+
The bundled `ptrlibrary.csv` is the PTR Library compiled by Demetrios Pagonis,
|
|
121
|
+
Kanako Sekimoto, and Joost de Gouw. It is redistributed with permission, upstream
|
|
122
|
+
attribution, publication references, and the source citations in individual records.
|
|
123
|
+
The MIT licence for this package does not relicense the CSV or its cited data. The
|
|
124
|
+
derived `rate_constants.json` is generated from that CSV by the bundled generator and
|
|
125
|
+
carries the same attribution.
|
|
126
|
+
|
|
127
|
+
## How it works
|
|
128
|
+
|
|
129
|
+
Everything instrument-specific (mass calibration, transmission, concentration constant
|
|
130
|
+
K, molar volume from drift temperature) is read from the `.h5`. Isolated peaks use an
|
|
131
|
+
apex-centred resolution window; overlapping peaks are separated by linear Gaussian
|
|
132
|
+
deconvolution. Time segments are found by log-space plateau detection on a composite VOC
|
|
133
|
+
signal. Compound identification enumerates candidate molecular formulas offline (no
|
|
134
|
+
external database) and ranks them by exact-mass error, the measured vs predicted
|
|
135
|
+
¹³C(M+1)/heteroatom(M+2, e.g. S/Cl) isotope pattern, and plausibility (integer DBE,
|
|
136
|
+
nitrogen rule, element ratios) — so near-isobars are told apart by composition, not
|
|
137
|
+
"nearest mass". Candidate rankings cannot determine structural isomers; names and
|
|
138
|
+
isomer labels come from the bundled PTR Library mapping. Proton-transfer rate constants
|
|
139
|
+
come from the bundled 218-compound table when the formula is known. The entries are
|
|
140
|
+
compiled from the **PTR Library** (Pagonis, Sekimoto & de Gouw, *J. Am. Soc. Mass
|
|
141
|
+
Spectrom.* 2019, doi.org/10.1007/s13361-019-02209-3; tinyurl.com/PTRLibrary), with
|
|
142
|
+
measured k where available (else Su-Chesnavich capture-theory k, flagged
|
|
143
|
+
`k_estimated`), plus proton affinity, isomer names, and fragmentation flags. Use
|
|
144
|
+
`ptr rates` to browse the bundled values. The installed package also includes the
|
|
145
|
+
ionisation, compound-assignment, and HCN/humidity reference documents.
|
|
146
|
+
|
|
147
|
+
## Accuracy
|
|
148
|
+
|
|
149
|
+
Median error vs PTR-MS Viewer on two reference exports — breath (396 points, default K):
|
|
150
|
+
Raw 2.4 %, Corrected 5.0 %, Conc 3.1 %, Conc[µg] 3.2 %; bitter-almonds (16 points,
|
|
151
|
+
calibrated K): Raw 0.7 %, Corrected 3.1 %, Conc 2.6 %, Conc[µg] 2.5 %.
|
|
152
|
+
|
|
153
|
+
Concentration carries one calibration constant K not uniquely fixed by the raw file (a
|
|
154
|
+
Viewer project uses its own sensitivity). Default K is the file's own acquisition
|
|
155
|
+
calibration; run `calibrate FILE.h5 reference.csv` and pass `--K` to match a specific
|
|
156
|
+
Viewer project exactly. Raw and Corrected are file-derived and robust.
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# ptr-ms-analysis
|
|
2
|
+
|
|
3
|
+
Open-source reprocessor for IONICON IoniTOF PTR-MS / PTR-TOF `.h5` files — a
|
|
4
|
+
replacement for the proprietary PTR-MS Viewer. Extracts product-ion peaks from the
|
|
5
|
+
raw mass spectra, transmission-corrects them, converts to concentration (ppb and
|
|
6
|
+
µg/m³), and summarises per time segment.
|
|
7
|
+
|
|
8
|
+
**Agent-driven by design.** The CLI does the deterministic physics and detects
|
|
9
|
+
candidate peaks (with compound assignments + artifact flags) and time segments; an
|
|
10
|
+
agent assigns chemistry and curates segments. Humans talk to the agent, not to this
|
|
11
|
+
CLI. The commands below describe the complete package interface.
|
|
12
|
+
|
|
13
|
+
## Install / run
|
|
14
|
+
|
|
15
|
+
It's a proper package that ships its own dependencies (h5py + numpy) and reference
|
|
16
|
+
data. Install it **once** and `ptr` is on PATH everywhere. Recommended via `pipx`
|
|
17
|
+
(isolated environment for the CLI and its dependencies):
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pipx install ptr-ms-analysis
|
|
21
|
+
ptr inspect FILE.h5
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
**If `pipx` isn't installed yet**, install it first, then re-run the command above:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
brew install pipx && pipx ensurepath # macOS (Homebrew)
|
|
28
|
+
python3 -m pip install --user pipx && python3 -m pipx ensurepath # Linux / macOS (no brew)
|
|
29
|
+
py -m pip install --user pipx; py -m pipx ensurepath # Windows (PowerShell)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
`pipx ensurepath` puts pipx's bin dir on PATH — open a new shell afterwards. Alternatives
|
|
33
|
+
that skip pipx entirely are `uv tool install ptr-ms-analysis` and
|
|
34
|
+
`python3 -m pip install ptr-ms-analysis` in a virtual environment. Works identically on
|
|
35
|
+
macOS, Linux, and Windows (pipx makes a real `ptr.exe`). Requires Python ≥ 3.9.
|
|
36
|
+
|
|
37
|
+
## Commands (all discovery output is JSON)
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
ptr inspect FILE.h5 # metadata, calibration, concentration-K, Vm
|
|
41
|
+
ptr peaks FILE.h5 # peaks + a ready-to-use suggested_label + top formula (--full for all candidates)
|
|
42
|
+
ptr segments FILE.h5 # stable plateaus (high=sample / low=bg)
|
|
43
|
+
# agent curates peaks + ranges into cfg.json, then:
|
|
44
|
+
ptr viz FILE.h5 --config cfg.json --out results.csv # serve review; 'Done' -> writes CSV
|
|
45
|
+
ptr viz FILE.h5 --config cfg.json --html review.html # portable standalone HTML instead
|
|
46
|
+
ptr analyze FILE.h5 \ # no review: curated config -> Viewer-style CSV
|
|
47
|
+
--config cfg.json --include-cycle-rows --out results.csv
|
|
48
|
+
ptr analyze FILE.h5 --auto-peaks --auto-segments --out results.csv # zero-curation fallback (auto-labels, drops noise)
|
|
49
|
+
ptr calibrate FILE.h5 viewer.csv # fit concentration constant K -> pass via --K
|
|
50
|
+
ptr compare results.csv viewer.csv --per-mass # accuracy vs a Viewer export
|
|
51
|
+
ptr rates benzaldehyde # browse proton-transfer rate constants (k)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`viz` opens a browser review app for an existing peak list + ranges so an expert can
|
|
55
|
+
visually check and tweak peaks / segments / calibration. K, molar volume, kinetic and
|
|
56
|
+
humidity controls, R windowing, and peak/interval edits recompute from embedded preview
|
|
57
|
+
data; primary m/z, R_phys, and whole-run window mode require raw HDF5 re-extraction and
|
|
58
|
+
are prominently marked stale until Done. **It is the default final step** for analysing
|
|
59
|
+
a file: the agent curates a config from `peaks`/`segments` first, then opens `viz` on that
|
|
60
|
+
best solution — ideally nothing needs changing and *Done* is a one-click confirmation.
|
|
61
|
+
By default it serves a localhost app that live-saves every edit into the `--config` file
|
|
62
|
+
and, when the expert clicks *Done*, runs the full-precision analysis and writes the
|
|
63
|
+
`--out` CSV; `--html review.html` writes a portable offline file instead (edits exported
|
|
64
|
+
via a Download button).
|
|
65
|
+
A first-time user gets an automatic guided tour of the interface (skippable, remembered in
|
|
66
|
+
the browser). The agent can also add a `"checklist"` array to the config — short points for
|
|
67
|
+
the reviewer to confirm (an ambiguous segment, a relabelled background channel, a
|
|
68
|
+
calibration caveat) — which the app shows as a tickable list, so review notes live in the
|
|
69
|
+
app instead of a wall of chat text. `viz` does not detect peaks/segments. Skip it and run `analyze` directly only for a
|
|
70
|
+
headless/no-browser run or a hand-off file. There is no one-shot command; the delivered
|
|
71
|
+
CSV always comes from `analyze`, never the browser.
|
|
72
|
+
|
|
73
|
+
An analysis config may include an `analyze` object with `R`, `R_phys`, `K`,
|
|
74
|
+
`molar_volume`, `primary_mz`, `kinetic`, `k_anchor`, `humidity_correct`, `humidity_p`,
|
|
75
|
+
`humidity_ref`, and `whole_run_windows`. Omitted CLI options do not replace these
|
|
76
|
+
curated values: precedence is **CLI override > `analyze` config > legacy default**.
|
|
77
|
+
The same resolver is used by `analyze`, browser initial state, live-save, and Done.
|
|
78
|
+
Unknown top-level and nested config fields survive browser round trips.
|
|
79
|
+
|
|
80
|
+
By default `analyze` integrates each interval with each isolated peak's apex/window
|
|
81
|
+
**re-centred on that interval's own spectrum** — peaks drift between intervals (mass-cal
|
|
82
|
+
drift; a compound may be absent in a background), so one whole-run window sits off-peak
|
|
83
|
+
elsewhere. Clustered peaks are Gaussian/deconvolved fitted components at fixed model
|
|
84
|
+
centres, so their centre is not a measured apex and may not be a visible local maximum in
|
|
85
|
+
every interval. The delivered CSV is unchanged in shape (still one row per compound ×
|
|
86
|
+
interval); only each row's numbers reflect its interval's real peak. Set
|
|
87
|
+
`whole_run_windows: true` or pass `--no-per-interval` for one whole-run window per
|
|
88
|
+
compound. Manual peak windows remain manual. The Methods card reports these effective
|
|
89
|
+
values, their provenance, and whether the transmission curve and concentration are
|
|
90
|
+
available. Browser numbers are preview values: R windowing and other embedded-data
|
|
91
|
+
controls update live, while primary m/z, R_phys, and whole-run window mode are marked
|
|
92
|
+
stale and are applied only by the authoritative **Done**/`analyze` re-extraction.
|
|
93
|
+
|
|
94
|
+
Add `--pretty` to any command for indented JSON. `analyze` peak/segment sources:
|
|
95
|
+
`--config file.json` (curated, preferred), or `--auto-peaks`/`--auto-segments`
|
|
96
|
+
(zero-curation — auto-labels confident IDs, drops noise artifacts, consolidates
|
|
97
|
+
backgrounds). `--K` / `--molar-volume`
|
|
98
|
+
override the file-derived calibration to match a specific Viewer project. `--kinetic`
|
|
99
|
+
applies per-compound rate-constant (k) sensitivities from the bundled 218-compound
|
|
100
|
+
PTR Library table for physically resolved absolute concentrations. Low-proton-affinity
|
|
101
|
+
compounds (HCN, formaldehyde, formic acid…) are
|
|
102
|
+
auto-flagged: `analyze` always reports a humidity diagnostic for them, and
|
|
103
|
+
`--humidity-correct` (with a calibrated `--humidity-p`) normalises the humidity swing.
|
|
104
|
+
|
|
105
|
+
## Reference data attribution
|
|
106
|
+
|
|
107
|
+
The bundled `ptrlibrary.csv` is the PTR Library compiled by Demetrios Pagonis,
|
|
108
|
+
Kanako Sekimoto, and Joost de Gouw. It is redistributed with permission, upstream
|
|
109
|
+
attribution, publication references, and the source citations in individual records.
|
|
110
|
+
The MIT licence for this package does not relicense the CSV or its cited data. The
|
|
111
|
+
derived `rate_constants.json` is generated from that CSV by the bundled generator and
|
|
112
|
+
carries the same attribution.
|
|
113
|
+
|
|
114
|
+
## How it works
|
|
115
|
+
|
|
116
|
+
Everything instrument-specific (mass calibration, transmission, concentration constant
|
|
117
|
+
K, molar volume from drift temperature) is read from the `.h5`. Isolated peaks use an
|
|
118
|
+
apex-centred resolution window; overlapping peaks are separated by linear Gaussian
|
|
119
|
+
deconvolution. Time segments are found by log-space plateau detection on a composite VOC
|
|
120
|
+
signal. Compound identification enumerates candidate molecular formulas offline (no
|
|
121
|
+
external database) and ranks them by exact-mass error, the measured vs predicted
|
|
122
|
+
¹³C(M+1)/heteroatom(M+2, e.g. S/Cl) isotope pattern, and plausibility (integer DBE,
|
|
123
|
+
nitrogen rule, element ratios) — so near-isobars are told apart by composition, not
|
|
124
|
+
"nearest mass". Candidate rankings cannot determine structural isomers; names and
|
|
125
|
+
isomer labels come from the bundled PTR Library mapping. Proton-transfer rate constants
|
|
126
|
+
come from the bundled 218-compound table when the formula is known. The entries are
|
|
127
|
+
compiled from the **PTR Library** (Pagonis, Sekimoto & de Gouw, *J. Am. Soc. Mass
|
|
128
|
+
Spectrom.* 2019, doi.org/10.1007/s13361-019-02209-3; tinyurl.com/PTRLibrary), with
|
|
129
|
+
measured k where available (else Su-Chesnavich capture-theory k, flagged
|
|
130
|
+
`k_estimated`), plus proton affinity, isomer names, and fragmentation flags. Use
|
|
131
|
+
`ptr rates` to browse the bundled values. The installed package also includes the
|
|
132
|
+
ionisation, compound-assignment, and HCN/humidity reference documents.
|
|
133
|
+
|
|
134
|
+
## Accuracy
|
|
135
|
+
|
|
136
|
+
Median error vs PTR-MS Viewer on two reference exports — breath (396 points, default K):
|
|
137
|
+
Raw 2.4 %, Corrected 5.0 %, Conc 3.1 %, Conc[µg] 3.2 %; bitter-almonds (16 points,
|
|
138
|
+
calibrated K): Raw 0.7 %, Corrected 3.1 %, Conc 2.6 %, Conc[µg] 2.5 %.
|
|
139
|
+
|
|
140
|
+
Concentration carries one calibration constant K not uniquely fixed by the raw file (a
|
|
141
|
+
Viewer project uses its own sensitivity). Default K is the file's own acquisition
|
|
142
|
+
calibration; run `calibrate FILE.h5 reference.csv` and pass `--K` to match a specific
|
|
143
|
+
Viewer project exactly. Raw and Corrected are file-derived and robust.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "ptr-ms-analysis"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Open-source reprocessor for IONICON IoniTOF PTR-MS / PTR-TOF .h5 files — a PTR-MS Viewer replacement."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
dependencies = ["h5py>=3.0", "numpy>=1.20"]
|
|
14
|
+
|
|
15
|
+
[project.scripts]
|
|
16
|
+
ptr = "ptr_ms_analysis.analyze:main"
|
|
17
|
+
|
|
18
|
+
[project.urls]
|
|
19
|
+
Homepage = "https://pypi.org/project/ptr-ms-analysis/"
|
|
20
|
+
|
|
21
|
+
[tool.setuptools.packages.find]
|
|
22
|
+
where = ["src"]
|
|
23
|
+
|
|
24
|
+
[tool.setuptools.package-data]
|
|
25
|
+
ptr_ms_analysis = ["reference/*.json", "reference/*.csv", "reference/*.md"]
|
|
26
|
+
|
|
27
|
+
[dependency-groups]
|
|
28
|
+
dev = [
|
|
29
|
+
"pytest>=8.4.2",
|
|
30
|
+
"ruff>=0.16.4",
|
|
31
|
+
]
|