rainbow-api 1.5.5__tar.gz → 1.7.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.
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/CHANGELOG.md +224 -0
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/PKG-INFO +6 -3
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/README.md +4 -1
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/pyproject.toml +3 -3
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow/__init__.py +57 -16
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow/_arguments.py +5 -3
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow/_binning.py +64 -4
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow/_version.py +1 -1
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow/agilent/__init__.py +122 -56
- rainbow_api-1.7.0/rainbow/agilent/amx.py +561 -0
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow/agilent/chemstation.py +260 -81
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow/agilent/masshunter.py +562 -131
- rainbow_api-1.7.0/rainbow/agilent/method.py +1206 -0
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow/agilent/openlab.py +129 -42
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow/agilent/sequence.py +78 -1
- rainbow_api-1.7.0/rainbow/agilent/sirslt.py +507 -0
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow/asm.py +329 -49
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow/datadirectory.py +27 -3
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow/waters/__init__.py +14 -4
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow/waters/masslynx.py +118 -56
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow_api.egg-info/PKG-INFO +6 -3
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow_api.egg-info/SOURCES.txt +2 -0
- rainbow_api-1.5.5/rainbow/agilent/method.py +0 -380
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/COPYING +0 -0
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/COPYING.LESSER +0 -0
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/MANIFEST.in +0 -0
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow/_optics.py +0 -0
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow/agilent/_chdelta.pyx +0 -0
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow/agilent/_msprofile.pyx +0 -0
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow/agilent/_uvdelta.pyx +0 -0
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow/agilent/acaml.py +0 -0
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow/datafile.py +0 -0
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow/datasequence.py +0 -0
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow/debug/__init__.py +0 -0
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow/debug/_util.py +0 -0
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow/debug/chemstation_header.py +0 -0
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow/debug/chemstation_text.py +0 -0
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow/debug/dotnet.py +0 -0
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow/debug/ini.py +0 -0
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow/debug/method.py +0 -0
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow/debug/mzxml.py +0 -0
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow/debug/reg.py +0 -0
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow/debug/waters_header.py +0 -0
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow/debug/waters_inf.py +0 -0
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow/debug/xml.py +0 -0
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow_api.egg-info/dependency_links.txt +0 -0
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow_api.egg-info/requires.txt +0 -0
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/rainbow_api.egg-info/top_level.txt +0 -0
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/setup.cfg +0 -0
- {rainbow_api-1.5.5 → rainbow_api-1.7.0}/setup.py +0 -0
|
@@ -3,6 +3,230 @@
|
|
|
3
3
|
All notable changes to `rainbow-api` are documented here. This project adheres
|
|
4
4
|
to [Semantic Versioning](https://semver.org/).
|
|
5
5
|
|
|
6
|
+
## [1.7.0] - 2026-11-28
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
- **The single quad's settings in an OpenLab `.amx`.** `module_settings`
|
|
10
|
+
states an LC/MSD iQ's (driver `LCSQ`): ion source, tune file, the diverter
|
|
11
|
+
timetable, and each time segment with its start, scan type and own rows:
|
|
12
|
+
each scan row (m/z range, scan time, fragmentor, polarity, ionization
|
|
13
|
+
mode, data storage), each SIM ion (m/z, compound, dwell, fragmentor,
|
|
14
|
+
polarity), each fragmentor ramp's points and the source parameters.
|
|
15
|
+
- **A `.sirslt` run's MS file states its method.** Read with
|
|
16
|
+
`centroid=True`, its MS file gets the method's `scan_parameters` and
|
|
17
|
+
`monitored_ions` (with compound names), and `ionization_mode`,
|
|
18
|
+
`fragmentor` and `polarity` where every row states one, in the keys a
|
|
19
|
+
ChemStation MS signal's settings come in (`method.tag_ms_segments`). The
|
|
20
|
+
file's scans are the check: where the method's rows are not what they
|
|
21
|
+
recorded, nothing goes on the file and the rows are kept in
|
|
22
|
+
`method_disagrees`.
|
|
23
|
+
- **A DAD signal's reference in an `.amx`.** `signals` rows state
|
|
24
|
+
`reference_wavelength` and `reference_bandwidth`.
|
|
25
|
+
- **Real OpenLab LC/MS test data**, shared by p3bm in #82:
|
|
26
|
+
`tests/inputs/jade.sirslt` (SIM/Scan), `ochre.sirslt` (two time
|
|
27
|
+
segments), `rose.sirslt` (positive and negative, a fragmentor ramp) and
|
|
28
|
+
`coral.sirslt` (a DAD reference wavelength), each with its `.amx`, and the
|
|
29
|
+
method `mango.amx` (Scan).
|
|
30
|
+
|
|
31
|
+
### Fixed
|
|
32
|
+
- **An `.amx` with a single quad reads.** Its driver part records its model
|
|
33
|
+
as `<msModel>`, not `ModuleType`, so the module had no driver and
|
|
34
|
+
`amx.read` raised a KeyError; `rb.read` and `rb.read_metadata` then stated
|
|
35
|
+
nothing of the run's method. The model is read from either, and a module
|
|
36
|
+
without a driver is listed without settings.
|
|
37
|
+
|
|
38
|
+
## [1.6.0] - 2026-11-27
|
|
39
|
+
|
|
40
|
+
### Added
|
|
41
|
+
- **Agilent OpenLab CDS acquisition methods (`.amx`).**
|
|
42
|
+
`rainbow.agilent.amx.read(path)` reads one, and `rb.read` and
|
|
43
|
+
`rb.read_metadata` read a `.sirslt` folder's (the `.amx` named after the
|
|
44
|
+
folder, else its only one) through the step a .D's sidecars go through
|
|
45
|
+
(`method.state_run`). The settings are read from the method's
|
|
46
|
+
`Agilent/ReportableInformation` part, the same ACAML a .D keeps as
|
|
47
|
+
`acq.macaml`, in the units it states: the driver parts state none, and keep
|
|
48
|
+
some values as codes (the DAD's slit `2` is reported as `4 nm`). The keys a
|
|
49
|
+
.D's `acq.macaml` gives come the same way (`injection_volume`, `flow_rate`,
|
|
50
|
+
`run_time`, `column_temperature`, `modules`, `acq_method`), and
|
|
51
|
+
`acq_method_info` (version, dates, status) and `module_settings` (per
|
|
52
|
+
module: name, model, driver, and the pump's flow, limits, solvents and
|
|
53
|
+
timetable, the DAD's signals, peak width, slit and spectrum, the column
|
|
54
|
+
compartment's temperatures, the sampler's injection volume, speeds and
|
|
55
|
+
wash) are new. Each driver's settings are one table of report parameter IDs
|
|
56
|
+
(`amx.MODULES`); an LC/MSD's goes there once an OpenLab LC/MS method is at
|
|
57
|
+
hand. A value the method does not state is not stated. A run without an
|
|
58
|
+
`.amx` is read as before.
|
|
59
|
+
- **Real `.amx` test data.** `tests/inputs/date.amx`, `pear.amx`,
|
|
60
|
+
`kiwi.amx` and the `tests/inputs/fig.sirslt` folder holding `fig.amx`,
|
|
61
|
+
CC0 from chromConverterExtraTests, anonymised as
|
|
62
|
+
`tests/inputs/README_sirslt.md` describes.
|
|
63
|
+
- **Agilent OpenLab CDS `.sirslt` result folders.** `rb.read` and
|
|
64
|
+
`rb.read_metadata` accept a `.sirslt` folder (or one renamed without the
|
|
65
|
+
suffix, recognized by the `.dx` and `.acaml` inside it; a `.D` folder is
|
|
66
|
+
never taken for one, whatever it holds). The detector signals come from the
|
|
67
|
+
folder's `.dx` archive; the single-quad LC/MS or GC/MS centroid spectrum
|
|
68
|
+
(`MSPeak.bin`, written beside the archive or kept under its `MSData/`) is
|
|
69
|
+
read under `centroid=True`, and flagged as `centroid_available` otherwise.
|
|
70
|
+
MS data that is present but cannot be decoded (no `MSScan.bin`, or no
|
|
71
|
+
`MSData/MSScan.xsd`) warns and is not reported as available. A run with no
|
|
72
|
+
detector signal (a flush) returns its metadata rather than raising.
|
|
73
|
+
- **LC or GC.** A `.sirslt` run's `metadata['technique']` is `'LC'` or `'GC'`,
|
|
74
|
+
read from the instrument in its `.acaml`, else from the MS `Contents.xml`,
|
|
75
|
+
else from a GC injection source or GC-only detector in the manifest (an ECD
|
|
76
|
+
is not counted as one: HPLC electrochemical detectors share the name).
|
|
77
|
+
`rainbow.agilent.sirslt.technique(path)` answers it without reading the data.
|
|
78
|
+
The instrument and its modules are in `metadata['instrument']`, and an MS
|
|
79
|
+
run's spectrometer in `metadata['ms_devices']`.
|
|
80
|
+
- **Real `.sirslt` test data.** `tests/inputs/olive.sirslt` (a UHPLC
|
|
81
|
+
single-quadrupole LC/MS run), `tests/inputs/plum.sirslt` (an HPLC run whose
|
|
82
|
+
DAD spectrum carries the HPLC scale factor) and `tests/inputs/lime.sirslt`
|
|
83
|
+
(an HPLC run with one DAD signal), anonymised as
|
|
84
|
+
`tests/inputs/README_sirslt.md` describes.
|
|
85
|
+
- **`bin_width='recorded'` (`rb.RECORDED`) reads m/z as the file stores
|
|
86
|
+
them.** No width is chosen and nothing is merged: an Agilent .ms file, a
|
|
87
|
+
Waters function and an uncalibrated MassHunter centroid get one column per
|
|
88
|
+
distinct stored m/z, labelled by it unrounded, with
|
|
89
|
+
`metadata["mz_spacing"]`, the smallest gap between two of them as measured
|
|
90
|
+
on the file (not for SIM or MRM). The HRMS profile and a calibrated TOF
|
|
91
|
+
centroid, whose m/z are continuous, stay per scan. `display_precision` does
|
|
92
|
+
not apply.
|
|
93
|
+
- **ChemStation MS files state their method signal by number.**
|
|
94
|
+
`MSD<n>.MS` takes `[Signal n]`'s settings and `metadata["method_signal"]`;
|
|
95
|
+
the ions or range the file recorded are a check. Scan signals state their
|
|
96
|
+
table (`scan_parameters`) and step (`mz_step`). A method of several MS
|
|
97
|
+
detectors is read per detector (`agilent.method.ms_detectors`), each file
|
|
98
|
+
paired with the detector its header names (`method_detector`).
|
|
99
|
+
- **What says an MS file's mode is stated.** `metadata["acquisition_mode_from"]`:
|
|
100
|
+
`scans`, `method report`, `file name` or `one m/z column`.
|
|
101
|
+
|
|
102
|
+
- **Agilent ChemStation LC/MS files state what the method says of their
|
|
103
|
+
signal.** Each MS DataFile's metadata has, where the method's signal it
|
|
104
|
+
holds (`MSD<n>.MS` holds `[Signal n]`) states it,
|
|
105
|
+
`polarity` (`+`/`-`), `ionization_mode`, `fragmentor` (V; where every row
|
|
106
|
+
of the signal's table states the same one) and
|
|
107
|
+
`monitored_ions` (a SIM signal's ions in the method's order, each
|
|
108
|
+
`{mz, fragmentor, compound}`), read from `acq.macaml`, else from the method
|
|
109
|
+
report as run (`acq.txt`, or older ChemStation's `ACQ.M/ACQ.TXT`, UTF-8 or
|
|
110
|
+
UTF-16); see `agilent.method.ms_signals`.
|
|
111
|
+
- **Agilent MassHunter MRM transitions carry their compound names.** A .D
|
|
112
|
+
whose `AcqData/AcqMethod.xml` names the compound for each MRM transition
|
|
113
|
+
now has `metadata["monitored_compounds"]`: one
|
|
114
|
+
`{compound, precursor_mz, product_mz, collision_energy}` per transition, in
|
|
115
|
+
the method's order.
|
|
116
|
+
- **`rb.read_metadata` states an Agilent .D's injection time as `read()`
|
|
117
|
+
does.** It read no data file, so a run with any sidecar came back without
|
|
118
|
+
its `date` (and `utc_offset`, `vialpos`); it now reads them from the
|
|
119
|
+
Chemstation files' headers alone (`chemstation.parse_header`, a few hundred
|
|
120
|
+
bytes per file), and states the method's `technique` too, so its metadata
|
|
121
|
+
equals `read().metadata` for every Agilent fixture. A MassHunter run's own
|
|
122
|
+
`.ch`/`.uv`/`.ms` files, which `read()` parses, are now listed beside its
|
|
123
|
+
`AcqData` files.
|
|
124
|
+
- **Agilent MassHunter MS files state each scan's record.** An MS DataFile
|
|
125
|
+
read from `MSScan.bin` (`MSPeak.bin`, `MSProfile.bin`, ICP-MS) has
|
|
126
|
+
`metadata["scans"]`: one array per field, one entry per row, giving the
|
|
127
|
+
`scan_type` (`Scan`, `SIM`, `MRM`, ...), `monitoring` (SIM or MRM),
|
|
128
|
+
`ms_level`, `polarity` (`+`/`-`), `collision_energy`, `precursor_mz` and
|
|
129
|
+
the measured `mz_range_min`/`mz_range_max`, each where the run's schema
|
|
130
|
+
records it. A simultaneous SIM/Scan run's interleaved scans are told apart
|
|
131
|
+
by it.
|
|
132
|
+
|
|
133
|
+
- **`rb.measurements(datadir)` reads a run's measurements without building
|
|
134
|
+
an ASM document** (also `DataDirectory.measurements()`). One dict per
|
|
135
|
+
measurement `to_asm` writes (DAD spectra aside): its identifier, data file,
|
|
136
|
+
label, technique, detector, m/z, channel metadata and unit, the trace as
|
|
137
|
+
numpy arrays (`times` in minutes, `values` as `from_asm` rebuilds them),
|
|
138
|
+
the sample and injection fields, measurement time, acquisition method, its
|
|
139
|
+
peaks as `peaks_from_asm` reads them, and the measurement document itself.
|
|
140
|
+
The measurements are made by `to_asm`'s own builders and read by
|
|
141
|
+
`from_asm`'s readers, so the two agree (tested field by field on every
|
|
142
|
+
bundled run); no array becomes a Python list, nothing goes through JSON,
|
|
143
|
+
and no trace is rebuilt. What is said only of a document (that it will not
|
|
144
|
+
validate, that a channel is published relabeled or left out) is not said.
|
|
145
|
+
- **A `.sirslt` run states what a `.D` run states after its data files.**
|
|
146
|
+
Both go through one step, `agilent.method.state_run`; a `.sirslt` is laid
|
|
147
|
+
out as a `.D` for it, the archive's `MSData/` as its `AcqData`. Its MS
|
|
148
|
+
files state the acquisition mode their scans state
|
|
149
|
+
(`acquisition_mode`, `acquisition_modes`, `acquisition_mode_from`), and
|
|
150
|
+
the method and sample sidecars it holds (an `MSData/AcqMethod.xml`'s
|
|
151
|
+
`monitored_compounds`) state what they say, in `read` and
|
|
152
|
+
`read_metadata` alike. What the run does not record is not stated: the
|
|
153
|
+
bundled `olive.sirslt` holds no acquisition method, so its MS signal's
|
|
154
|
+
settings and compounds are not stated.
|
|
155
|
+
|
|
156
|
+
### Changed
|
|
157
|
+
- **MassHunter scan records are read in one pass.** `read_scan_table` reads
|
|
158
|
+
MSScan.bin as a numpy structured array (`record_dtype`, from MSScan.xsd),
|
|
159
|
+
in place of a `struct` call per field; the MS parsers, `scan_times` and
|
|
160
|
+
`scan_metadata` use it, and MSPeak.bin is read once and decoded a block
|
|
161
|
+
width at a time. A 13,811-scan centroid read takes about 7 ms in place of
|
|
162
|
+
about 90 ms, with the same result. `read_scan_records` still gives one
|
|
163
|
+
dictionary per record.
|
|
164
|
+
- **A file's scans decide its acquisition mode over the method report.**
|
|
165
|
+
Where the report states another, the scans' mode and records stay, and the
|
|
166
|
+
report's is kept in `metadata["method_disagrees"]`. A MassHunter file whose
|
|
167
|
+
scans all state one of SIM, Scan or MRM is tagged with it.
|
|
168
|
+
- **A method's setting that disagrees with the file is kept apart.** Where a
|
|
169
|
+
SIM signal's ions are not the ones the file recorded (compared at the
|
|
170
|
+
coarser of the .ms 0.05 m/z step and the method's written precision), or a
|
|
171
|
+
Scan range does not hold the file's m/z, nothing of the signal goes on the
|
|
172
|
+
file: `method_disagrees` holds its `signal` number and whole `settings`. A
|
|
173
|
+
single setting the file states otherwise (its polarity) stays the file's,
|
|
174
|
+
the method's kept in `method_disagrees`. The ±0.5 m/z label match is gone.
|
|
175
|
+
- **A Waters function nothing names is not called UV.** Without
|
|
176
|
+
`_FUNCTNS.INF` and a polarity its detector is unstated (None), its axis
|
|
177
|
+
read as recorded. A multi-column one stays in `DataDirectory.datafiles`
|
|
178
|
+
(in no `by_detector` entry), not among the analog traces; ASM has no cube
|
|
179
|
+
for an axis of unknown kind and says so.
|
|
180
|
+
- **A DAD spectrum in a unit rainbow cannot place says so in ASM**, as a
|
|
181
|
+
chromatogram does: published under mAU, unscaled, with the note naming the
|
|
182
|
+
file's unit, which `from_asm` reads back.
|
|
183
|
+
|
|
184
|
+
- **Python 3.11 or later.** rainbow now requires Python 3.11 (was 3.8), the
|
|
185
|
+
oldest release still supported upstream; wheels are built for 3.11 to 3.13.
|
|
186
|
+
On older Python, pip keeps installing rainbow 1.5.5.
|
|
187
|
+
|
|
188
|
+
### Fixed
|
|
189
|
+
- **Reading a sequence's injections one at a time parses its `sequence.acaml`
|
|
190
|
+
once.** `rb.read(path, peaks=True)` and `agilent.injection_peaks` parsed the
|
|
191
|
+
whole document, which holds every injection's results, for each injection:
|
|
192
|
+
384 injections of one sequence with a 27 MB document took 127 s, and now take
|
|
193
|
+
0.5 s. The peaks of the last four documents read are kept by path,
|
|
194
|
+
modification time and size, so a rewritten document is read again, and each
|
|
195
|
+
call gets its own copy. `agilent.sequence.injection_groups(path, name)` reads
|
|
196
|
+
one injection's groups without copying the rest.
|
|
197
|
+
- **A Waters `_extern.inf` Polarity line reads with one tab or three.** The
|
|
198
|
+
line straight after `Instrument Parameters` was split on three tabs, so a
|
|
199
|
+
single-tab export (`Polarity\tES+`) raised an IndexError; one rule now takes
|
|
200
|
+
the last tab-separated field, after a `Parameter File -` line or without
|
|
201
|
+
one (reported in #74).
|
|
202
|
+
- **A `.dx` DAD spectrum is scaled by its manifest's factor.** The spectrum
|
|
203
|
+
was multiplied by a constant `2**-17`, but the manifest records the factor as
|
|
204
|
+
`<ScaleFactor>` and it depends on the detector: `1000 * 2**-27` on a UHPLC
|
|
205
|
+
DAD, `1000 * 2**-21` on an HPLC DAD. The constant read UHPLC spectra 2.4%
|
|
206
|
+
high and HPLC spectra 62x low. With the manifest's factor a spectrum matches
|
|
207
|
+
its run's single-wavelength channels to within about 2%. The `teal` expected
|
|
208
|
+
output is regenerated accordingly (every value x 0.9765625). A manifest that
|
|
209
|
+
records no factor is scaled by `1000 * 2**-27` and now warns, since that is
|
|
210
|
+
64 times too small for an HPLC DAD; it was scaled by `2**-17` without a
|
|
211
|
+
word, so such a spectrum also reads 2.4% lower than before.
|
|
212
|
+
- **MassHunter centroid abundances are float64 and no longer truncated.**
|
|
213
|
+
`MSPeak.bin` intensities were cast to unsigned integers, dropping the
|
|
214
|
+
fractional part the file stores. That affected `.D` GC/MS runs as well as
|
|
215
|
+
`.sirslt` ones: every scan of the `yellow.D` fixture holds fractional
|
|
216
|
+
abundances. Centroid intensities are now always float64, per scan and on a
|
|
217
|
+
`bin_width` grid alike, whatever values a run holds, so code that relied on
|
|
218
|
+
an integer dtype for a `.D` centroid sees float64 instead.
|
|
219
|
+
- **`MSScan.xsd` version 2.1 is read.** Its scan record ends in an optional
|
|
220
|
+
`Padding` element whose type is declared inline, which made the schema
|
|
221
|
+
unreadable; it has no stored bytes and is now skipped. Any other element with
|
|
222
|
+
an inline type, which rainbow cannot size, is refused rather than skipped.
|
|
223
|
+
- **Waters file names are matched regardless of case everywhere.**
|
|
224
|
+
`waters.read_metadata` found a .raw folder's `_FUNC`/`_CHRO` files only by
|
|
225
|
+
their names' exact upper case, so a folder named in lower case (a
|
|
226
|
+
PerkinElmer export) seemed to hold none; it now lists them as they are on
|
|
227
|
+
disk. `waters.read(requested_files=)` matched only lower-case names when
|
|
228
|
+
called directly; it now takes them in any case, as `rb.read` does.
|
|
229
|
+
|
|
6
230
|
## [1.5.5] - 2026-10-17
|
|
7
231
|
|
|
8
232
|
### Added
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: rainbow-api
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.7.0
|
|
4
4
|
Summary: Read chromatography and mass spectrometry binary files
|
|
5
5
|
Author: Evan Shi and Eugene Kwan
|
|
6
6
|
Author-email: evanyshi@cmu.edu
|
|
@@ -8,7 +8,7 @@ License: LGPL-3.0-or-later
|
|
|
8
8
|
Project-URL: Repository, https://github.com/evanyeyeye/rainbow
|
|
9
9
|
Project-URL: Documentation, https://rainbow-api.readthedocs.io
|
|
10
10
|
Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)
|
|
11
|
-
Requires-Python: >=3.
|
|
11
|
+
Requires-Python: >=3.11
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
License-File: COPYING
|
|
14
14
|
License-File: COPYING.LESSER
|
|
@@ -47,6 +47,9 @@ Dynamic: license-file
|
|
|
47
47
|
| **Agilent `.dx`** (OpenLab CDS) | `.UV` | DAD spectrum | |
|
|
48
48
|
| | `.CH` | single-wavelength UV/DAD signals | |
|
|
49
49
|
| | `.IT` | instrument telemetry, as analog data | `telemetry=True` |
|
|
50
|
+
| **Agilent `.sirslt`** (OpenLab CDS result folder) | `.dx` | everything a `.dx` holds (UV/DAD, FID, telemetry) | |
|
|
51
|
+
| | `MSPeak.bin` | single-quad LC/MS or GC/MS centroid spectrum | `centroid=True` |
|
|
52
|
+
| | `.acaml` | instrument, and whether the run is LC or GC (`metadata['technique']`) | |
|
|
50
53
|
| **Waters `.raw`** | `CHRO` | CAD and ELSD, plus miscellaneous analog data | |
|
|
51
54
|
| | `FUNC` | UV and MS | |
|
|
52
55
|
|
|
@@ -87,7 +90,7 @@ datafile = datadir.get_file("DAD1A.uv")
|
|
|
87
90
|
|
|
88
91
|
Here, the `datadir` DataDirectory object contains a DataFile object for `DAD1A.uv`.
|
|
89
92
|
|
|
90
|
-
*rainbow* normally infers the vendor from the path suffix (`.D`/`.dx` for Agilent, `.raw` for Waters). A directory whose name lacks that suffix is identified from its contents instead, so renamed datasets still parse. To force a parser explicitly, pass `format`:
|
|
93
|
+
*rainbow* normally infers the vendor from the path suffix (`.D`/`.dx`/`.sirslt` for Agilent, `.raw` for Waters). A directory whose name lacks that suffix is identified from its contents instead, so renamed datasets still parse. To force a parser explicitly, pass `format`:
|
|
91
94
|
|
|
92
95
|
```python
|
|
93
96
|
datadir = rb.read("Caffeine 3", format="waters")
|
|
@@ -15,6 +15,9 @@
|
|
|
15
15
|
| **Agilent `.dx`** (OpenLab CDS) | `.UV` | DAD spectrum | |
|
|
16
16
|
| | `.CH` | single-wavelength UV/DAD signals | |
|
|
17
17
|
| | `.IT` | instrument telemetry, as analog data | `telemetry=True` |
|
|
18
|
+
| **Agilent `.sirslt`** (OpenLab CDS result folder) | `.dx` | everything a `.dx` holds (UV/DAD, FID, telemetry) | |
|
|
19
|
+
| | `MSPeak.bin` | single-quad LC/MS or GC/MS centroid spectrum | `centroid=True` |
|
|
20
|
+
| | `.acaml` | instrument, and whether the run is LC or GC (`metadata['technique']`) | |
|
|
18
21
|
| **Waters `.raw`** | `CHRO` | CAD and ELSD, plus miscellaneous analog data | |
|
|
19
22
|
| | `FUNC` | UV and MS | |
|
|
20
23
|
|
|
@@ -55,7 +58,7 @@ datafile = datadir.get_file("DAD1A.uv")
|
|
|
55
58
|
|
|
56
59
|
Here, the `datadir` DataDirectory object contains a DataFile object for `DAD1A.uv`.
|
|
57
60
|
|
|
58
|
-
*rainbow* normally infers the vendor from the path suffix (`.D`/`.dx` for Agilent, `.raw` for Waters). A directory whose name lacks that suffix is identified from its contents instead, so renamed datasets still parse. To force a parser explicitly, pass `format`:
|
|
61
|
+
*rainbow* normally infers the vendor from the path suffix (`.D`/`.dx`/`.sirslt` for Agilent, `.raw` for Waters). A directory whose name lacks that suffix is identified from its contents instead, so renamed datasets still parse. To force a parser explicitly, pass `format`:
|
|
59
62
|
|
|
60
63
|
```python
|
|
61
64
|
datadir = rb.read("Caffeine 3", format="waters")
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "rainbow-api"
|
|
7
|
-
version = "1.
|
|
7
|
+
version = "1.7.0"
|
|
8
8
|
description = "Read chromatography and mass spectrometry binary files"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = {text = "LGPL-3.0-or-later"}
|
|
@@ -19,7 +19,7 @@ classifiers = [
|
|
|
19
19
|
# older rainbow instead of installing this and failing at import. No upper
|
|
20
20
|
# bound: a newer interpreter than [tool.cibuildwheel] builds wheels for still
|
|
21
21
|
# installs, just from the sdist.
|
|
22
|
-
requires-python = ">=3.
|
|
22
|
+
requires-python = ">=3.11"
|
|
23
23
|
# What every install needs to read a file, and nothing more. lxml is here for
|
|
24
24
|
# speed, not correctness: the parsers fall back to the standard library and
|
|
25
25
|
# reach the same answer, but rb.read_metadata is about 2.5x slower that way, so
|
|
@@ -73,7 +73,7 @@ include = ["rainbow*"]
|
|
|
73
73
|
# Build CPython wheels for the optional compiled accelerator. The extension
|
|
74
74
|
# is optional, so any platform that can't compile still yields a working
|
|
75
75
|
# (pure-Python-fallback) wheel, and the sdist covers everything else.
|
|
76
|
-
build = "
|
|
76
|
+
build = "cp311-* cp312-* cp313-*"
|
|
77
77
|
skip = "*-musllinux* *_i686 *-win32"
|
|
78
78
|
|
|
79
79
|
[tool.pytest.ini_options]
|
|
@@ -5,9 +5,9 @@ from rainbow.datafile import DataFile
|
|
|
5
5
|
from rainbow.datadirectory import DataDirectory
|
|
6
6
|
from rainbow.datasequence import DataSequence
|
|
7
7
|
from rainbow import agilent, waters
|
|
8
|
-
from rainbow._binning import MZ_FLOORS
|
|
9
|
-
from rainbow.asm import (asm_technique, from_asm, iso_timestamp,
|
|
10
|
-
peaks_from_asm, sequence_from_asm)
|
|
8
|
+
from rainbow._binning import MZ_FLOORS, RECORDED, is_recorded as _is_recorded
|
|
9
|
+
from rainbow.asm import (asm_technique, device_of, from_asm, iso_timestamp,
|
|
10
|
+
measurements, peaks_from_asm, sequence_from_asm)
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
# `debug` is listed although it is not imported above: __getattr__ fetches it on
|
|
@@ -17,9 +17,10 @@ __all__ = [
|
|
|
17
17
|
'DataFile', 'DataDirectory', 'DataSequence',
|
|
18
18
|
'agilent', 'waters', 'debug',
|
|
19
19
|
'read', 'read_sequence', 'read_metadata', 'mz_resolution',
|
|
20
|
-
'from_asm', 'sequence_from_asm', 'peaks_from_asm', '
|
|
20
|
+
'from_asm', 'sequence_from_asm', 'peaks_from_asm', 'measurements', 'device_of',
|
|
21
|
+
'iso_timestamp',
|
|
21
22
|
'asm_technique', 'sniff_vendor',
|
|
22
|
-
'VENDORS', 'MZ_FLOORS',
|
|
23
|
+
'VENDORS', 'MZ_FLOORS', 'RECORDED',
|
|
23
24
|
]
|
|
24
25
|
|
|
25
26
|
|
|
@@ -90,7 +91,7 @@ def _warn_bin_width_floor(datafiles, bin_width, vendor):
|
|
|
90
91
|
an ordinary quadrupole channel that does have a floor, and the flag must not
|
|
91
92
|
silence the warning that channel has earned.
|
|
92
93
|
"""
|
|
93
|
-
if bin_width is None:
|
|
94
|
+
if bin_width is None or _is_recorded(bin_width):
|
|
94
95
|
return
|
|
95
96
|
too_fine = {}
|
|
96
97
|
for datafile in datafiles:
|
|
@@ -146,6 +147,11 @@ def sniff_vendor(path):
|
|
|
146
147
|
or any(re.fullmatch(r'_func\d{3}\.dat', name) for name in lower):
|
|
147
148
|
return 'waters'
|
|
148
149
|
|
|
150
|
+
# Agilent OpenLab .sirslt: a .dx archive beside its .acaml result document.
|
|
151
|
+
exts = {os.path.splitext(name)[1] for name in lower}
|
|
152
|
+
if '.dx' in exts and '.acaml' in exts:
|
|
153
|
+
return 'agilent'
|
|
154
|
+
|
|
149
155
|
# Agilent .D: the AcqData subdirectory or any Chemstation data file.
|
|
150
156
|
if 'acqdata' in lower \
|
|
151
157
|
or any(os.path.splitext(name)[1] in ('.ch', '.uv', '.ms')
|
|
@@ -163,7 +169,8 @@ def _detect_vendor(path):
|
|
|
163
169
|
"""
|
|
164
170
|
Determines which vendor parser to use for a path.
|
|
165
171
|
|
|
166
|
-
The path's extension is tried first (.D/.dx -> Agilent, .raw ->
|
|
172
|
+
The path's extension is tried first (.D/.dx/.sirslt -> Agilent, .raw ->
|
|
173
|
+
Waters),
|
|
167
174
|
which preserves rainbow's historical behavior exactly. If the extension is
|
|
168
175
|
unrecognized and the path is a directory, its contents are sniffed for a
|
|
169
176
|
vendor signature, so datasets whose folders were renamed without the
|
|
@@ -181,7 +188,7 @@ def _detect_vendor(path):
|
|
|
181
188
|
if not isinstance(path, str):
|
|
182
189
|
return None
|
|
183
190
|
ext = os.path.splitext(path)[1].lower()
|
|
184
|
-
if ext in ('.d', '.dx'):
|
|
191
|
+
if ext in ('.d', '.dx', '.sirslt'):
|
|
185
192
|
return 'agilent'
|
|
186
193
|
if ext == '.raw':
|
|
187
194
|
return 'waters'
|
|
@@ -230,7 +237,8 @@ def _unreadable(path, what="read"):
|
|
|
230
237
|
hint = (" It holds injection subdirectories, so it is a sequence "
|
|
231
238
|
"rather than one run: rb.read_sequence() reads that.")
|
|
232
239
|
elif isinstance(path, str) and os.path.isdir(path):
|
|
233
|
-
hint = (" If its name lost the vendor suffix (.D, .dx, .
|
|
240
|
+
hint = (" If its name lost the vendor suffix (.D, .dx, .sirslt, "
|
|
241
|
+
".raw), pass "
|
|
234
242
|
"format='agilent' or format='waters' to name the parser.")
|
|
235
243
|
# A path that does not exist never reaches here: the vendor parsers raise
|
|
236
244
|
# "<path> is not a directory" first, which already says what is wrong.
|
|
@@ -254,10 +262,12 @@ def read(path, display_precision='auto', hrms=False, requested_files=None,
|
|
|
254
262
|
|
|
255
263
|
Agilent HRMS parsing may be slow. Set the flag to enable it.
|
|
256
264
|
|
|
257
|
-
For Agilent .dx archives
|
|
258
|
-
temperature) are skipped unless the
|
|
265
|
+
For Agilent .dx archives and OpenLab .sirslt folders, instrument \
|
|
266
|
+
telemetry traces (e.g. pressure, temperature) are skipped unless the \
|
|
267
|
+
telemetry flag is set.
|
|
259
268
|
|
|
260
|
-
The vendor is normally detected from the path: a .D/.dx path is
|
|
269
|
+
The vendor is normally detected from the path: a .D/.dx/.sirslt path is \
|
|
270
|
+
read as \
|
|
261
271
|
Agilent and a .raw path as Waters. A directory whose name lacks that \
|
|
262
272
|
suffix is identified from its contents instead. Pass ``format`` \
|
|
263
273
|
('agilent' or 'waters') to override detection entirely.
|
|
@@ -292,6 +302,17 @@ def read(path, display_precision='auto', hrms=False, requested_files=None,
|
|
|
292
302
|
default) to keep the per-scan representation, or pass a width to
|
|
293
303
|
project the scans onto one shared m/z grid (see
|
|
294
304
|
:ref:`hrms-data-model`).
|
|
305
|
+
|
|
306
|
+
``'recorded'`` keeps every m/z as the file stores it: no width is
|
|
307
|
+
chosen and nothing is merged. A channel on a shared axis (an
|
|
308
|
+
Agilent .ms, a Waters function, an uncalibrated MassHunter
|
|
309
|
+
centroid) gets one column per distinct m/z it stores, labelled by
|
|
310
|
+
that m/z unrounded (a float32 one as the shortest decimal that
|
|
311
|
+
reads back to it); its ``metadata['mz_spacing']`` is the smallest
|
|
312
|
+
gap between two of them, measured on the file, unless it monitors
|
|
313
|
+
chosen ions (SIM, MRM). A channel whose m/z are continuous (the
|
|
314
|
+
HRMS profile, a calibrated TOF centroid) stays per scan, as with
|
|
315
|
+
no bin_width. ``display_precision`` does not apply.
|
|
295
316
|
peaks (bool, optional): Flag for reading the run's integrated peaks
|
|
296
317
|
into ``DataDirectory.peaks``, as :func:`read_sequence` does for a
|
|
297
318
|
whole sequence. For Agilent they come from the result document of
|
|
@@ -375,9 +396,28 @@ def read(path, display_precision='auto', hrms=False, requested_files=None,
|
|
|
375
396
|
# Warned here, not before the read, because the floor is a property of the
|
|
376
397
|
# channels the parsers actually returned.
|
|
377
398
|
_warn_bin_width_floor(datadir.datafiles, bin_width, vendor)
|
|
399
|
+
if _is_recorded(bin_width):
|
|
400
|
+
_state_recorded_spacing(datadir.datafiles)
|
|
378
401
|
return datadir
|
|
379
402
|
|
|
380
403
|
|
|
404
|
+
def _state_recorded_spacing(datafiles):
|
|
405
|
+
"""Puts ``mz_spacing`` on each MS channel read as recorded that sweeps a
|
|
406
|
+
range on a shared axis: the smallest gap between two distinct m/z it
|
|
407
|
+
stores, measured on this file (:func:`rainbow._binning.recorded_spacing`).
|
|
408
|
+
A selected-ion channel's gaps are the method's choice, and a per-scan
|
|
409
|
+
channel has no shared axis, so neither gets one (as in
|
|
410
|
+
:func:`mz_resolution`)."""
|
|
411
|
+
from rainbow._binning import recorded_spacing
|
|
412
|
+
for datafile in datafiles:
|
|
413
|
+
if datafile.detector != 'MS' or hasattr(datafile, 'mass_labels') \
|
|
414
|
+
or _is_selected_ion(datafile):
|
|
415
|
+
continue
|
|
416
|
+
spacing = recorded_spacing(datafile.ylabels)
|
|
417
|
+
if spacing is not None:
|
|
418
|
+
datafile.metadata['mz_spacing'] = spacing
|
|
419
|
+
|
|
420
|
+
|
|
381
421
|
def _mz_spacings(datadir, only=None):
|
|
382
422
|
"""
|
|
383
423
|
Finest m/z spacing of each MS channel in ``datadir``.
|
|
@@ -492,8 +532,9 @@ def _is_selected_ion(datafile):
|
|
|
492
532
|
as selected-ion.
|
|
493
533
|
"""
|
|
494
534
|
mode = datafile.metadata.get('acquisition_mode')
|
|
495
|
-
if mode in ('SIM', 'Scan'):
|
|
496
|
-
|
|
535
|
+
if mode in ('SIM', 'MRM', 'Scan', 'mixed'):
|
|
536
|
+
# A mixed channel's full scans are a grid to measure.
|
|
537
|
+
return mode in ('SIM', 'MRM')
|
|
497
538
|
# Counted on the labels, not on the width of the data grid. They are the
|
|
498
539
|
# same for an ordinary read (one column per label), but the probe reads
|
|
499
540
|
# labels only, so the grid there is empty and would make every untagged
|
|
@@ -509,8 +550,8 @@ def _needs_the_probe(datadir, measured):
|
|
|
509
550
|
"""Whether any MS channel in ``datadir`` still has no measurement.
|
|
510
551
|
|
|
511
552
|
Every MS channel the first read did not measure has to come from the probe:
|
|
512
|
-
one already on a shared axis (a Chemstation .ms beside a MassHunter
|
|
513
|
-
|
|
553
|
+
one already on a shared axis (a Chemstation .ms read beside a MassHunter
|
|
554
|
+
centroid, or Agilent ICP-MS), and a centroid, whose per-scan peaks are
|
|
514
555
|
not a grid to measure. Asking which channels are still missing covers both
|
|
515
556
|
without naming either, so a channel that stops being measured in the first
|
|
516
557
|
read cannot silently drop out of the answer.
|
|
@@ -15,7 +15,8 @@ columns.
|
|
|
15
15
|
"""
|
|
16
16
|
import math
|
|
17
17
|
|
|
18
|
-
from rainbow._binning import _MAX_LABEL_DECIMALS as MAX_DISPLAY_PRECISION
|
|
18
|
+
from rainbow._binning import (_MAX_LABEL_DECIMALS as MAX_DISPLAY_PRECISION,
|
|
19
|
+
RECORDED)
|
|
19
20
|
|
|
20
21
|
_REMOVED_ARGUMENTS = {
|
|
21
22
|
'precision': (
|
|
@@ -32,7 +33,8 @@ _REMOVED_ARGUMENTS = {
|
|
|
32
33
|
|
|
33
34
|
|
|
34
35
|
def validate_bin_width(bin_width):
|
|
35
|
-
"""Rejects a ``bin_width`` that is not a finite positive number
|
|
36
|
+
"""Rejects a ``bin_width`` that is not a finite positive number or
|
|
37
|
+
``'recorded'`` (:data:`rainbow._binning.RECORDED`).
|
|
36
38
|
|
|
37
39
|
Infinity passes a ``> 0`` test and then divides every m/z to zero, so the
|
|
38
40
|
run comes back as one column labelled NaN, holding the whole signal and
|
|
@@ -40,7 +42,7 @@ def validate_bin_width(bin_width):
|
|
|
40
42
|
the parser's overflow guard, which then reports a width that is too small.
|
|
41
43
|
Both are the collapse that guard exists to refuse, so both are refused here.
|
|
42
44
|
"""
|
|
43
|
-
if bin_width is None:
|
|
45
|
+
if bin_width is None or bin_width == RECORDED:
|
|
44
46
|
return
|
|
45
47
|
if (isinstance(bin_width, bool)
|
|
46
48
|
or not isinstance(bin_width, (int, float))
|
|
@@ -10,11 +10,26 @@ within a scan. This module provides one vectorized implementation of that step.
|
|
|
10
10
|
The bin width is the lossy control: keys closer together than ``bin_width`` are
|
|
11
11
|
merged. The bin labels are the bin centres, optionally rounded to a display
|
|
12
12
|
precision for presentation, which is purely cosmetic and never merges data.
|
|
13
|
+
|
|
14
|
+
``bin_width='recorded'`` (:data:`RECORDED`) bins nothing: each distinct key the
|
|
15
|
+
file stores is a column of its own, labelled by that key exactly as stored, and
|
|
16
|
+
only pairs of one scan at the very same key are summed. Nothing is merged that
|
|
17
|
+
the file keeps apart, and no width is chosen.
|
|
13
18
|
"""
|
|
14
19
|
|
|
15
20
|
import numpy as np
|
|
16
21
|
|
|
17
22
|
|
|
23
|
+
# The bin_width that keeps each stored m/z as the file records it (see the
|
|
24
|
+
# module docstring).
|
|
25
|
+
RECORDED = 'recorded'
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def is_recorded(bin_width):
|
|
29
|
+
"""Whether ``bin_width`` asks for the keys as recorded (:data:`RECORDED`)."""
|
|
30
|
+
return isinstance(bin_width, str) and bin_width == RECORDED
|
|
31
|
+
|
|
32
|
+
|
|
18
33
|
# Finest meaningful m/z bin width per vendor (the m/z grid the binary records;
|
|
19
34
|
# see the per-vendor MS docs). A bin_width below this only inserts empty bins.
|
|
20
35
|
# These describe unit-resolution data, the default assumption for a channel
|
|
@@ -71,7 +86,8 @@ def label_precision(display_precision, bin_width):
|
|
|
71
86
|
widths :func:`rainbow.mz_resolution` recommends.
|
|
72
87
|
|
|
73
88
|
"""
|
|
74
|
-
if display_precision is None or bin_width is None or
|
|
89
|
+
if display_precision is None or bin_width is None or \
|
|
90
|
+
is_recorded(bin_width) or not bin_width > 0:
|
|
75
91
|
return display_precision
|
|
76
92
|
decimals = display_precision
|
|
77
93
|
while decimals < _MAX_LABEL_DECIMALS and 10.0 ** -decimals > bin_width:
|
|
@@ -103,10 +119,13 @@ def bin_datapairs(keys, values, pair_counts, bin_width,
|
|
|
103
119
|
keys (np.ndarray): Flat ylabels (m/z or wavelength), non-negative.
|
|
104
120
|
values (np.ndarray): Flat values paired with :obj:`keys`.
|
|
105
121
|
pair_counts (np.ndarray): Number of pairs at each retention time.
|
|
106
|
-
bin_width (float): Width of each bin, in the keys'
|
|
107
|
-
control: keys within one bin are summed.
|
|
122
|
+
bin_width (float or 'recorded'): Width of each bin, in the keys'
|
|
123
|
+
units. The lossy control: keys within one bin are summed.
|
|
124
|
+
``'recorded'`` makes each distinct stored key its own column,
|
|
125
|
+
labelled by the key as stored, so nothing is merged.
|
|
108
126
|
display_precision (int, optional): Decimals to round the bin-centre
|
|
109
127
|
labels to for display. ``None`` (the default) leaves them unrounded.
|
|
128
|
+
Not applied under ``'recorded'``, whose labels are the data.
|
|
110
129
|
data_dtype (np.dtype, optional): dtype of the output matrix.
|
|
111
130
|
labels_only (bool, optional): Return the bin labels and an empty
|
|
112
131
|
``(num_times, 0)`` matrix, skipping the accumulation. The matrix is
|
|
@@ -120,7 +139,8 @@ def bin_datapairs(keys, values, pair_counts, bin_width,
|
|
|
120
139
|
data values (rows are retention times, columns are ylabels).
|
|
121
140
|
|
|
122
141
|
"""
|
|
123
|
-
|
|
142
|
+
recorded = is_recorded(bin_width)
|
|
143
|
+
if not recorded and not bin_width > 0:
|
|
124
144
|
raise ValueError(f"bin_width must be positive, got {bin_width!r}.")
|
|
125
145
|
|
|
126
146
|
num_times = pair_counts.size
|
|
@@ -129,6 +149,15 @@ def bin_datapairs(keys, values, pair_counts, bin_width,
|
|
|
129
149
|
return (np.empty(0, dtype=np.float64),
|
|
130
150
|
np.zeros((num_times, 0), dtype=data_dtype))
|
|
131
151
|
|
|
152
|
+
if recorded:
|
|
153
|
+
ylabels, columns = recorded_columns(keys)
|
|
154
|
+
if labels_only:
|
|
155
|
+
return ylabels, np.zeros((num_times, 0), dtype=data_dtype)
|
|
156
|
+
rows = np.repeat(np.arange(num_times), pair_counts)
|
|
157
|
+
data = np.zeros(num_times * ylabels.size, dtype=data_dtype)
|
|
158
|
+
np.add.at(data, rows * ylabels.size + columns.ravel(), values)
|
|
159
|
+
return ylabels, data.reshape(num_times, ylabels.size)
|
|
160
|
+
|
|
132
161
|
# Assign each key to a bin of width bin_width (this is the lossy step).
|
|
133
162
|
# A bin_width small enough to send a key past the float64 range, or past
|
|
134
163
|
# what an int64 bin index can hold, would silently wrap: every key would
|
|
@@ -184,3 +213,34 @@ def bin_datapairs(keys, values, pair_counts, bin_width,
|
|
|
184
213
|
np.add.at(data, flat_indices, values)
|
|
185
214
|
|
|
186
215
|
return ylabels, data.reshape(num_times, num_ylabels)
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def recorded_columns(keys):
|
|
219
|
+
"""(labels, each key's column) under :data:`RECORDED`: each distinct
|
|
220
|
+
stored key a column, labelled by the key as the file writes it. A float32
|
|
221
|
+
key is labelled by the shortest decimal that reads back to it (100.08,
|
|
222
|
+
not its float64 widening 100.08000183105469), which is one to one, so the
|
|
223
|
+
columns stay distinct; any other key by its float64 value. The one rule
|
|
224
|
+
for every reader (bin_datapairs, MassHunter's bin_to_grid)."""
|
|
225
|
+
keys = np.asarray(keys)
|
|
226
|
+
labels, columns = np.unique(keys, return_inverse=True)
|
|
227
|
+
if labels.dtype == np.float32:
|
|
228
|
+
labels = np.array([float(str(x)) for x in labels], dtype=np.float64)
|
|
229
|
+
else:
|
|
230
|
+
labels = labels.astype(np.float64)
|
|
231
|
+
return labels, columns.ravel()
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def recorded_spacing(labels):
|
|
235
|
+
"""The smallest gap between two distinct recorded m/z of a channel read
|
|
236
|
+
as recorded (:data:`RECORDED`), measured on its labels, or None for fewer
|
|
237
|
+
than two. A measurement of this file, not a property of its format.
|
|
238
|
+
|
|
239
|
+
Exact: each gap is taken between the labels' shortest decimals (their
|
|
240
|
+
repr), so 800.2 and 800.0 are 0.2 apart, not 0.1999999999998181."""
|
|
241
|
+
from decimal import Decimal
|
|
242
|
+
labels = np.unique(np.asarray(labels, dtype=np.float64))
|
|
243
|
+
if labels.size < 2:
|
|
244
|
+
return None
|
|
245
|
+
exact = [Decimal(repr(float(x))) for x in labels]
|
|
246
|
+
return float(min(b - a for a, b in zip(exact, exact[1:])))
|