rainbow-api 1.3.0__tar.gz → 1.3.1__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.3.0/rainbow_api.egg-info → rainbow_api-1.3.1}/PKG-INFO +3 -1
- {rainbow_api-1.3.0 → rainbow_api-1.3.1}/pyproject.toml +6 -1
- {rainbow_api-1.3.0 → rainbow_api-1.3.1}/rainbow/agilent/__init__.py +29 -3
- {rainbow_api-1.3.0 → rainbow_api-1.3.1}/rainbow/agilent/_msprofile.pyx +7 -11
- {rainbow_api-1.3.0 → rainbow_api-1.3.1}/rainbow/agilent/masshunter.py +9 -4
- {rainbow_api-1.3.0 → rainbow_api-1.3.1/rainbow_api.egg-info}/PKG-INFO +3 -1
- {rainbow_api-1.3.0 → rainbow_api-1.3.1}/rainbow_api.egg-info/requires.txt +3 -0
- {rainbow_api-1.3.0 → rainbow_api-1.3.1}/tests/test_binning.py +7 -7
- {rainbow_api-1.3.0 → rainbow_api-1.3.1}/tests/test_masshunter.py +31 -0
- {rainbow_api-1.3.0 → rainbow_api-1.3.1}/COPYING +0 -0
- {rainbow_api-1.3.0 → rainbow_api-1.3.1}/COPYING.LESSER +0 -0
- {rainbow_api-1.3.0 → rainbow_api-1.3.1}/MANIFEST.in +0 -0
- {rainbow_api-1.3.0 → rainbow_api-1.3.1}/README.md +0 -0
- {rainbow_api-1.3.0 → rainbow_api-1.3.1}/rainbow/__init__.py +0 -0
- {rainbow_api-1.3.0 → rainbow_api-1.3.1}/rainbow/_binning.py +0 -0
- {rainbow_api-1.3.0 → rainbow_api-1.3.1}/rainbow/agilent/_chdelta.pyx +0 -0
- {rainbow_api-1.3.0 → rainbow_api-1.3.1}/rainbow/agilent/_uvdelta.pyx +0 -0
- {rainbow_api-1.3.0 → rainbow_api-1.3.1}/rainbow/agilent/chemstation.py +0 -0
- {rainbow_api-1.3.0 → rainbow_api-1.3.1}/rainbow/agilent/openlab.py +0 -0
- {rainbow_api-1.3.0 → rainbow_api-1.3.1}/rainbow/datadirectory.py +0 -0
- {rainbow_api-1.3.0 → rainbow_api-1.3.1}/rainbow/datafile.py +0 -0
- {rainbow_api-1.3.0 → rainbow_api-1.3.1}/rainbow/waters/__init__.py +0 -0
- {rainbow_api-1.3.0 → rainbow_api-1.3.1}/rainbow/waters/masslynx.py +0 -0
- {rainbow_api-1.3.0 → rainbow_api-1.3.1}/rainbow_api.egg-info/SOURCES.txt +0 -0
- {rainbow_api-1.3.0 → rainbow_api-1.3.1}/rainbow_api.egg-info/dependency_links.txt +0 -0
- {rainbow_api-1.3.0 → rainbow_api-1.3.1}/rainbow_api.egg-info/top_level.txt +0 -0
- {rainbow_api-1.3.0 → rainbow_api-1.3.1}/setup.cfg +0 -0
- {rainbow_api-1.3.0 → rainbow_api-1.3.1}/setup.py +0 -0
- {rainbow_api-1.3.0 → rainbow_api-1.3.1}/tests/test_accelerator.py +0 -0
- {rainbow_api-1.3.0 → rainbow_api-1.3.1}/tests/test_agilent.py +0 -0
- {rainbow_api-1.3.0 → rainbow_api-1.3.1}/tests/test_datadirectory.py +0 -0
- {rainbow_api-1.3.0 → rainbow_api-1.3.1}/tests/test_datafile.py +0 -0
- {rainbow_api-1.3.0 → rainbow_api-1.3.1}/tests/test_read.py +0 -0
- {rainbow_api-1.3.0 → rainbow_api-1.3.1}/tests/test_waters.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: rainbow-api
|
|
3
|
-
Version: 1.3.
|
|
3
|
+
Version: 1.3.1
|
|
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
|
|
@@ -17,6 +17,8 @@ Requires-Dist: lxml
|
|
|
17
17
|
Requires-Dist: pandas
|
|
18
18
|
Provides-Extra: test
|
|
19
19
|
Requires-Dist: pytest; extra == "test"
|
|
20
|
+
Provides-Extra: hrms
|
|
21
|
+
Requires-Dist: python-lzf; extra == "hrms"
|
|
20
22
|
Dynamic: license-file
|
|
21
23
|
|
|
22
24
|
# rainbow
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "rainbow-api"
|
|
7
|
-
version = "1.3.
|
|
7
|
+
version = "1.3.1"
|
|
8
8
|
description = "Read chromatography and mass spectrometry binary files"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = {text = "COPYING.LESSER"}
|
|
@@ -24,6 +24,11 @@ dependencies = [
|
|
|
24
24
|
|
|
25
25
|
[project.optional-dependencies]
|
|
26
26
|
test = ["pytest"]
|
|
27
|
+
# Agilent MassHunter profile data (MSProfile.bin) can carry LZF-compressed
|
|
28
|
+
# segments whose decode needs python-lzf. It is only imported when such a
|
|
29
|
+
# segment is actually encountered, so the base install stays pure-Python;
|
|
30
|
+
# install rainbow-api[hrms] to parse those files (read(..., hrms=True)).
|
|
31
|
+
hrms = ["python-lzf"]
|
|
27
32
|
|
|
28
33
|
[project.urls]
|
|
29
34
|
Repository = "https://github.com/evanyeyeye/rainbow"
|
|
@@ -45,9 +45,14 @@ def read(path, precision='auto', hrms=False, requested_files=None,
|
|
|
45
45
|
|
|
46
46
|
metadata = chemstation.parse_metadata(path, datafiles)
|
|
47
47
|
|
|
48
|
-
# Surface unread MassHunter centroid data so the
|
|
49
|
-
# discoverable: a .D with
|
|
50
|
-
# parsed when
|
|
48
|
+
# Surface unread MassHunter profile/centroid data so the hrms and centroid
|
|
49
|
+
# flags are discoverable: a .D with MSProfile.bin holds a profile spectrum
|
|
50
|
+
# parsed only when hrms=True, and MSPeak.bin a centroid spectrum parsed only
|
|
51
|
+
# when centroid=True. Otherwise read() returns an empty DataDirectory with
|
|
52
|
+
# no hint that the flag is what's missing.
|
|
53
|
+
if not hrms and os.path.isfile(
|
|
54
|
+
os.path.join(path, "AcqData", "MSProfile.bin")):
|
|
55
|
+
metadata['hrms_available'] = True
|
|
51
56
|
if not centroid and os.path.isfile(
|
|
52
57
|
os.path.join(path, "AcqData", "MSPeak.bin")):
|
|
53
58
|
metadata['centroid_available'] = True
|
|
@@ -72,6 +77,27 @@ def read_metadata(path):
|
|
|
72
77
|
|
|
73
78
|
datafiles = []
|
|
74
79
|
metadata = chemstation.parse_metadata(path, datafiles)
|
|
80
|
+
|
|
81
|
+
# MassHunter acquisitions (a .D with an AcqData subfolder) keep their data
|
|
82
|
+
# in MSProfile.bin (profile/HRMS) and/or MSPeak.bin (centroid), which the
|
|
83
|
+
# Chemstation .uv/.ch/.ms scan below never finds - so they used to come
|
|
84
|
+
# back with an empty datafile list. Mirror masshunter.parse_allfiles'
|
|
85
|
+
# detection to surface the datafile names and the flags needed to read
|
|
86
|
+
# them (hrms / centroid), without parsing the binaries.
|
|
87
|
+
acqdata_path = os.path.join(path, "AcqData")
|
|
88
|
+
if os.path.isdir(acqdata_path):
|
|
89
|
+
acqdata_files = set(os.listdir(acqdata_path))
|
|
90
|
+
if {"MSScan.xsd", "MSScan.bin"} <= acqdata_files:
|
|
91
|
+
mh_datafiles = []
|
|
92
|
+
if "MSProfile.bin" in acqdata_files:
|
|
93
|
+
mh_datafiles.append("MSProfile.bin")
|
|
94
|
+
metadata['hrms_available'] = True
|
|
95
|
+
if "MSPeak.bin" in acqdata_files:
|
|
96
|
+
mh_datafiles.append("MSPeak.bin")
|
|
97
|
+
metadata['centroid_available'] = True
|
|
98
|
+
if mh_datafiles:
|
|
99
|
+
return {'datafiles': mh_datafiles, 'metadata': metadata}
|
|
100
|
+
|
|
75
101
|
if len(metadata) == 1:
|
|
76
102
|
datadir = read(path)
|
|
77
103
|
if datadir:
|
|
@@ -24,11 +24,12 @@ from libc.string cimport memcpy
|
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
cdef inline int _width_size(int flag) except -1:
|
|
27
|
-
"""Bytes for an RLE width flag (1/2/3
|
|
27
|
+
"""Bytes for an RLE width flag (1/2/3 -> 1/2/4); raise on anything else.
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
The flag is ``(-value) % 4``, so it is always 0-3; 0 means a corrupt
|
|
30
|
+
stream. A zero or out-of-range flag raises here, mirroring the ValueError
|
|
31
|
+
the pure-Python reference reports rather than reading at a bogus width
|
|
32
|
+
(this module disables Cython's automatic bounds checks).
|
|
32
33
|
"""
|
|
33
34
|
if flag == 1:
|
|
34
35
|
return 1
|
|
@@ -36,8 +37,6 @@ cdef inline int _width_size(int flag) except -1:
|
|
|
36
37
|
return 2
|
|
37
38
|
elif flag == 3:
|
|
38
39
|
return 4
|
|
39
|
-
elif flag == 4:
|
|
40
|
-
return 8
|
|
41
40
|
raise ValueError("Malformed MSProfile.bin RLE segment.")
|
|
42
41
|
|
|
43
42
|
|
|
@@ -88,23 +87,20 @@ def decompress_inten_list(const unsigned char[::1] comp_view, int num_mz):
|
|
|
88
87
|
cdef signed char v1
|
|
89
88
|
cdef short v2
|
|
90
89
|
cdef int v4
|
|
91
|
-
cdef long long v8
|
|
92
90
|
|
|
93
91
|
while off < n:
|
|
94
92
|
if off + cur_size > n:
|
|
95
93
|
raise ValueError("Malformed MSProfile.bin RLE segment.")
|
|
94
|
+
# _width_size guarantees cur_size is 1, 2, or 4.
|
|
96
95
|
if cur_size == 1:
|
|
97
96
|
memcpy(&v1, &comp_view[off], 1)
|
|
98
97
|
value = v1
|
|
99
98
|
elif cur_size == 2:
|
|
100
99
|
memcpy(&v2, &comp_view[off], 2)
|
|
101
100
|
value = v2
|
|
102
|
-
|
|
101
|
+
else:
|
|
103
102
|
memcpy(&v4, &comp_view[off], 4)
|
|
104
103
|
value = v4
|
|
105
|
-
else:
|
|
106
|
-
memcpy(&v8, &comp_view[off], 8)
|
|
107
|
-
value = v8
|
|
108
104
|
off += cur_size
|
|
109
105
|
|
|
110
106
|
if value >= 0:
|
|
@@ -228,6 +228,11 @@ def parse_msdata(path, precision='auto', bin_width=None):
|
|
|
228
228
|
the shared grid.
|
|
229
229
|
|
|
230
230
|
"""
|
|
231
|
+
if bin_width is not None and (
|
|
232
|
+
isinstance(bin_width, bool)
|
|
233
|
+
or not isinstance(bin_width, (int, float)) or bin_width <= 0):
|
|
234
|
+
raise Exception(f"Invalid bin_width: {bin_width}.")
|
|
235
|
+
|
|
231
236
|
# The profile is always a high-resolution TOF trace, so 'auto' precision
|
|
232
237
|
# means 4 decimals.
|
|
233
238
|
if precision == 'auto':
|
|
@@ -964,8 +969,9 @@ def decompress_inten_list(comp_view, num_mz):
|
|
|
964
969
|
- A non-negative value is a literal intensity.
|
|
965
970
|
- A negative value -v encodes ``divmod(v, 4)``: the quotient is a run
|
|
966
971
|
of zero intensities to emit, and the remainder is the new width flag
|
|
967
|
-
(1, 2, 3 -> 1-, 2-, 4-byte
|
|
968
|
-
|
|
972
|
+
(1, 2, 3 -> 1-, 2-, 4-byte) to switch to for subsequent values. The
|
|
973
|
+
remainder is always 0-3, and 0 is malformed, so the only widths are
|
|
974
|
+
1, 2, and 4 bytes.
|
|
969
975
|
|
|
970
976
|
Most scans open with an ``0xffffffff`` token, read as -1 at the 4-byte
|
|
971
977
|
starting width, which emits no zeros and switches to 1-byte values; this is
|
|
@@ -993,9 +999,8 @@ def decompress_inten_list(comp_view, num_mz):
|
|
|
993
999
|
1: struct.Struct('<b').unpack,
|
|
994
1000
|
2: struct.Struct('<h').unpack,
|
|
995
1001
|
3: struct.Struct('<i').unpack,
|
|
996
|
-
4: struct.Struct('<q').unpack,
|
|
997
1002
|
}
|
|
998
|
-
sizes = {1: 1, 2: 2, 3: 4
|
|
1003
|
+
sizes = {1: 1, 2: 2, 3: 4}
|
|
999
1004
|
|
|
1000
1005
|
init_zero_repeat = struct.unpack('<i', comp_view[4:8])[0]
|
|
1001
1006
|
cur_idx = -init_zero_repeat
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: rainbow-api
|
|
3
|
-
Version: 1.3.
|
|
3
|
+
Version: 1.3.1
|
|
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
|
|
@@ -17,6 +17,8 @@ Requires-Dist: lxml
|
|
|
17
17
|
Requires-Dist: pandas
|
|
18
18
|
Provides-Extra: test
|
|
19
19
|
Requires-Dist: pytest; extra == "test"
|
|
20
|
+
Provides-Extra: hrms
|
|
21
|
+
Requires-Dist: python-lzf; extra == "hrms"
|
|
20
22
|
Dynamic: license-file
|
|
21
23
|
|
|
22
24
|
# rainbow
|
|
@@ -9,13 +9,13 @@ import pytest
|
|
|
9
9
|
from rainbow._binning import bin_datapairs
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
def _bin_datapairs_reference(keys, values, pair_counts,
|
|
12
|
+
def _bin_datapairs_reference(keys, values, pair_counts, precision, data_dtype):
|
|
13
13
|
"""Original (pre-optimization) binning, kept as a parity oracle.
|
|
14
14
|
|
|
15
15
|
Mirrors the per-scan np.unique / searchsorted / np.add.at loop that the
|
|
16
16
|
Waters _FUNC.DAT and Agilent .ms decoders both used before bin_datapairs.
|
|
17
17
|
"""
|
|
18
|
-
keys = np.round(keys,
|
|
18
|
+
keys = np.round(keys, precision)
|
|
19
19
|
num_times = pair_counts.size
|
|
20
20
|
ylabels = np.unique(keys)
|
|
21
21
|
ylabels.sort()
|
|
@@ -57,7 +57,7 @@ def test_honors_output_dtype():
|
|
|
57
57
|
|
|
58
58
|
|
|
59
59
|
def test_respects_precision():
|
|
60
|
-
# Keys arrive already rounded to `
|
|
60
|
+
# Keys arrive already rounded to `precision` (the decoders round first).
|
|
61
61
|
keys = np.round(np.array([100.14, 100.16, 100.16]), 1)
|
|
62
62
|
values = np.array([1, 2, 4], dtype=np.int64)
|
|
63
63
|
ylabels, data = bin_datapairs(keys, values, np.array([3]), 1)
|
|
@@ -74,8 +74,8 @@ def test_empty_input():
|
|
|
74
74
|
|
|
75
75
|
|
|
76
76
|
@pytest.mark.parametrize("data_dtype", [np.int64, np.uint32])
|
|
77
|
-
@pytest.mark.parametrize("
|
|
78
|
-
def test_matches_reference_on_random_data(data_dtype,
|
|
77
|
+
@pytest.mark.parametrize("precision", [0, 1, 2])
|
|
78
|
+
def test_matches_reference_on_random_data(data_dtype, precision):
|
|
79
79
|
rng = np.random.RandomState(0)
|
|
80
80
|
for _ in range(20):
|
|
81
81
|
num_times = rng.randint(1, 8)
|
|
@@ -86,9 +86,9 @@ def test_matches_reference_on_random_data(data_dtype, prec):
|
|
|
86
86
|
keys = (rng.rand(n) * 900 + 100).astype(np.float32)
|
|
87
87
|
values = rng.randint(0, 5000, size=n).astype(data_dtype)
|
|
88
88
|
y_ref, d_ref = _bin_datapairs_reference(
|
|
89
|
-
keys.copy(), values.copy(), pair_counts,
|
|
89
|
+
keys.copy(), values.copy(), pair_counts, precision, data_dtype)
|
|
90
90
|
y, d = bin_datapairs(
|
|
91
|
-
np.round(keys,
|
|
91
|
+
np.round(keys, precision), values, pair_counts, precision,
|
|
92
92
|
data_dtype=data_dtype)
|
|
93
93
|
np.testing.assert_array_equal(y, y_ref)
|
|
94
94
|
np.testing.assert_array_equal(d, d_ref)
|
|
@@ -571,6 +571,37 @@ def test_centroid_flag_end_to_end():
|
|
|
571
571
|
assert "centroid_available" not in with_centroid.metadata
|
|
572
572
|
|
|
573
573
|
|
|
574
|
+
def test_read_metadata_locates_masshunter_datafiles():
|
|
575
|
+
""" read_metadata routes a MassHunter .D to its AcqData binaries instead of
|
|
576
|
+
returning an empty datafile list (the Chemstation .uv/.ch/.ms scan never
|
|
577
|
+
finds them). It reports the bin names plus the flags needed to read them,
|
|
578
|
+
without parsing the binaries. """
|
|
579
|
+
# gold.D carries both a profile spectrum and a peak-picked centroid list.
|
|
580
|
+
both = rb.read_metadata(GOLD_D)
|
|
581
|
+
assert both["datafiles"] == ["MSProfile.bin", "MSPeak.bin"]
|
|
582
|
+
assert both["metadata"].get("hrms_available")
|
|
583
|
+
assert both["metadata"].get("centroid_available")
|
|
584
|
+
|
|
585
|
+
# amber.D has only MSProfile.bin, so no centroid is advertised.
|
|
586
|
+
profile_only = rb.read_metadata(AMBER_D)
|
|
587
|
+
assert profile_only["datafiles"] == ["MSProfile.bin"]
|
|
588
|
+
assert profile_only["metadata"].get("hrms_available")
|
|
589
|
+
assert "centroid_available" not in profile_only["metadata"]
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
def test_hrms_flag_advertises_profile():
|
|
593
|
+
""" hrms=True adds the MSProfile.bin DataFile; by default it is not parsed
|
|
594
|
+
but a metadata note advertises that profile/HRMS data is available (mirrors
|
|
595
|
+
centroid_available). amber.D is run-length encoded, so no python-lzf. """
|
|
596
|
+
default = rb.read(AMBER_D)
|
|
597
|
+
assert "MSProfile.bin" not in [df.name for df in default.datafiles]
|
|
598
|
+
assert default.metadata.get("hrms_available")
|
|
599
|
+
|
|
600
|
+
with_hrms = rb.read(AMBER_D, hrms=True)
|
|
601
|
+
assert "MSProfile.bin" in [df.name for df in with_hrms.datafiles]
|
|
602
|
+
assert "hrms_available" not in with_hrms.metadata
|
|
603
|
+
|
|
604
|
+
|
|
574
605
|
def test_centroid_truncation_is_graceful():
|
|
575
606
|
""" A truncated MSPeak.bin segment is skipped rather than crashing. """
|
|
576
607
|
centroid = masshunter.parse_mspeakdata(os.path.join(COPPER_D, "AcqData"))
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|