rainbow-api 1.5.0__tar.gz → 1.5.2__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.
Files changed (45) hide show
  1. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/CHANGELOG.md +46 -0
  2. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/PKG-INFO +1 -1
  3. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/pyproject.toml +1 -1
  4. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/rainbow/agilent/chemstation.py +8 -2
  5. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/rainbow/agilent/sequence.py +6 -1
  6. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/rainbow/asm.py +138 -13
  7. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/rainbow_api.egg-info/PKG-INFO +1 -1
  8. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/COPYING +0 -0
  9. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/COPYING.LESSER +0 -0
  10. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/MANIFEST.in +0 -0
  11. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/README.md +0 -0
  12. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/rainbow/__init__.py +0 -0
  13. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/rainbow/_arguments.py +0 -0
  14. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/rainbow/_binning.py +0 -0
  15. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/rainbow/agilent/__init__.py +0 -0
  16. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/rainbow/agilent/_chdelta.pyx +0 -0
  17. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/rainbow/agilent/_msprofile.pyx +0 -0
  18. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/rainbow/agilent/_uvdelta.pyx +0 -0
  19. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/rainbow/agilent/acaml.py +0 -0
  20. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/rainbow/agilent/masshunter.py +0 -0
  21. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/rainbow/agilent/method.py +0 -0
  22. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/rainbow/agilent/openlab.py +0 -0
  23. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/rainbow/datadirectory.py +0 -0
  24. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/rainbow/datafile.py +0 -0
  25. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/rainbow/datasequence.py +0 -0
  26. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/rainbow/debug/__init__.py +0 -0
  27. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/rainbow/debug/_util.py +0 -0
  28. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/rainbow/debug/chemstation_header.py +0 -0
  29. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/rainbow/debug/chemstation_text.py +0 -0
  30. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/rainbow/debug/dotnet.py +0 -0
  31. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/rainbow/debug/ini.py +0 -0
  32. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/rainbow/debug/method.py +0 -0
  33. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/rainbow/debug/mzxml.py +0 -0
  34. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/rainbow/debug/reg.py +0 -0
  35. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/rainbow/debug/waters_header.py +0 -0
  36. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/rainbow/debug/waters_inf.py +0 -0
  37. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/rainbow/debug/xml.py +0 -0
  38. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/rainbow/waters/__init__.py +0 -0
  39. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/rainbow/waters/masslynx.py +0 -0
  40. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/rainbow_api.egg-info/SOURCES.txt +0 -0
  41. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/rainbow_api.egg-info/dependency_links.txt +0 -0
  42. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/rainbow_api.egg-info/requires.txt +0 -0
  43. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/rainbow_api.egg-info/top_level.txt +0 -0
  44. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/setup.cfg +0 -0
  45. {rainbow_api-1.5.0 → rainbow_api-1.5.2}/setup.py +0 -0
@@ -3,6 +3,52 @@
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.5.2] - 2026-09-09
7
+
8
+ ### Fixed
9
+ - **A ChemStation `.ms` file with busy scans failed to read at all.** Reading
10
+ an Agilent `.D` whose MS scans hold more than 16383 mz-intensity pairs raised
11
+ `ValueError: strides is incompatible with shape of requested array and size
12
+ of buffer`, and nothing in the run could be read. `parse_ms` held each scan's
13
+ pair count in a numpy `uint16` array, so the multiply that turns a pair count
14
+ into a byte count was `uint16` arithmetic and wrapped at 65536: a busy scan
15
+ asked for a fraction of its own bytes, and the reader carried on from inside
16
+ it. numpy 1 widened that multiply and hid the wrap, so this reaches anyone
17
+ who has moved to numpy 2. How busy a scan is tracks how many ions it
18
+ detected, which is why it presented as large or intense files failing while
19
+ smaller ones from the same batch read: in the reported case a run whose
20
+ busiest scan held 12705 pairs read, and one holding 25201 did not. Reported
21
+ with both files in [#75](https://github.com/evanyeyeye/rainbow/issues/75).
22
+
23
+ ## [1.5.1] - 2026-08-27
24
+
25
+ ### Fixed
26
+ - **`rb.from_asm` dropped a peak's compound name.** A processing method that
27
+ identified a peak writes the compound under `written name`; rainbow read
28
+ every quantity on the peak and discarded the name, leaving a peak list of
29
+ anonymous retention times with no way to follow a component across the
30
+ injections of a study. It is now read as the peak's `name`, and written back
31
+ on export.
32
+ - **`rb.from_asm` kept only the first of several integrations.** An Agilent
33
+ OpenLab or Empower export writes one processed data document per result
34
+ version, so a channel can arrive with the same run integrated up to six
35
+ times, under different processing methods and at different dates. rainbow
36
+ read the first and dropped the rest without a word, and the peak lists
37
+ genuinely differ: a reintegration finds or loses whole peaks. Every peak list
38
+ is now read. The first is still the group's `peaks`, so existing code is
39
+ unaffected; the rest are in the group's new `alternates`, each labelled with
40
+ the integration that produced it, and the group's new `processing` records
41
+ which integration the default peaks came from. Document order is not
42
+ processing order, so a group that carries alternates now warns. Re-export
43
+ writes them all back.
44
+ - **A channel of an OpenLab export had no wavelength.** rainbow read the
45
+ wavelength only from the device control document's `detector wavelength
46
+ setting`, which that exporter does not write, so every channel came back with
47
+ an empty y-axis label and a three-signal injection was three
48
+ indistinguishable traces. The wavelength is now also read from the cube
49
+ label, which is where that exporter names it, and the label itself is kept as
50
+ the channel's and the peak group's `description`.
51
+
6
52
  ## [1.5.0] - 2026-08-27
7
53
 
8
54
  ### Added
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rainbow-api
3
- Version: 1.5.0
3
+ Version: 1.5.2
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
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "rainbow-api"
7
- version = "1.5.0"
7
+ version = "1.5.2"
8
8
  description = "Read chromatography and mass spectrometry binary files"
9
9
  readme = "README.md"
10
10
  license = {text = "LGPL-3.0-or-later"}
@@ -842,9 +842,15 @@ def parse_ms(path, display_precision=0, bin_width=1.0, labels_only=False):
842
842
  f.read(2)
843
843
  times[i] = int_unpack(f.read(4))[0]
844
844
  f.read(6)
845
- pair_counts[i] = short_unpack(f.read(2))[0]
845
+ # The multiply below has to happen on a Python int. Read back out of
846
+ # pair_counts it would be a numpy uint16, which wraps at 65536 under
847
+ # NEP 50, so a scan of more than 16383 pairs would ask for its byte
848
+ # count modulo 65536 and the reader would resume inside that scan.
849
+ # numpy 1 widened the multiply to int64, which hid this.
850
+ pair_count = short_unpack(f.read(2))[0]
851
+ pair_counts[i] = pair_count
846
852
  f.read(4)
847
- pair_bytes = f.read(pair_counts[i] * 4)
853
+ pair_bytes = f.read(pair_count * 4)
848
854
  pair_bytearr.extend(pair_bytes)
849
855
  f.read(10)
850
856
 
@@ -298,7 +298,12 @@ def _peak(element):
298
298
  values = {}
299
299
  for child in element:
300
300
  values[_local(child.tag)] = child
301
- peak = {}
301
+ # ChemStation names a peak's compound outside the <Peak>, in an
302
+ # <InjectionCompound> that refers back to it by id, and leaves it empty
303
+ # unless the processing method identified the peak. The key is present
304
+ # either way so that a peak read from a sequence and one read from an ASM
305
+ # document (where the name rides on the peak itself) have the same shape.
306
+ peak = {"name": None}
302
307
  for key, tag in _PEAK_MEASURES.items():
303
308
  child = values.get(tag)
304
309
  peak[key] = _value(child) if child is not None else None
@@ -1761,19 +1761,65 @@ def _add_injection_document(measurement, metadata, identifier, technique,
1761
1761
 
1762
1762
 
1763
1763
  def _add_processed_data(measurement, group, options):
1764
- """Adds a processed data document carrying the channel's peak list."""
1765
- peaks = [_asm_peak(i + 1, peak, options)
1766
- for i, peak in enumerate(group["peaks"])]
1764
+ """Adds the processed data documents carrying the channel's peak lists.
1765
+
1766
+ A channel read back from a document that integrated the same run more than
1767
+ once keeps the extra integrations in ``group["alternates"]``; they are
1768
+ written out alongside the one in ``group["peaks"]``, in the order they were
1769
+ read, so a round trip does not quietly reduce six result versions to one.
1770
+ """
1771
+ documents = [(group.get("processing"), group["peaks"])]
1772
+ for alternate in group.get("alternates") or []:
1773
+ documents.append((alternate.get("processing"), alternate["peaks"]))
1767
1774
  measurement[_PROCESSED_DATA] = {
1768
1775
  "processed data document": [
1769
- {"@index": 1, "peak list": {"peak": peaks}},
1776
+ _asm_processed_data(index + 1, processing, peaks, options)
1777
+ for index, (processing, peaks) in enumerate(documents)
1770
1778
  ],
1771
1779
  }
1772
1780
 
1773
1781
 
1782
+ # What a processed data document records about the integration that produced
1783
+ # it, and the key each field is written under.
1784
+ _PROCESSING_FIELDS = (
1785
+ ("identifier", "processed data identifier"),
1786
+ ("group_identifier", "group identifier"),
1787
+ ("time", "data processing time"),
1788
+ )
1789
+ _PROCESSING_METHOD_FIELDS = (
1790
+ ("method_name", "method name"),
1791
+ ("method_version", "method version"),
1792
+ ("type", "data processing type"),
1793
+ )
1794
+
1795
+
1796
+ def _asm_processed_data(index, processing, peaks, options):
1797
+ """One processed data document: a peak list and where it came from."""
1798
+ document = {"@index": index}
1799
+ for source, target in _PROCESSING_FIELDS:
1800
+ value = (processing or {}).get(source)
1801
+ if isinstance(value, str) and value:
1802
+ document[target] = value
1803
+ method = {}
1804
+ for source, target in _PROCESSING_METHOD_FIELDS:
1805
+ value = (processing or {}).get(source)
1806
+ if isinstance(value, str) and value:
1807
+ method[target] = value
1808
+ if method:
1809
+ document["data processing document"] = method
1810
+ document["peak list"] = {
1811
+ "peak": [_asm_peak(i + 1, peak, options)
1812
+ for i, peak in enumerate(peaks)],
1813
+ }
1814
+ return document
1815
+
1816
+
1774
1817
  def _asm_peak(index, peak, options=None):
1775
1818
  """One ASM peak, with retention/start/end times in seconds."""
1776
1819
  entry = {"@index": index}
1820
+ name = peak.get("name")
1821
+ if isinstance(name, str) and name:
1822
+ entry["written name"] = name
1777
1823
  mapping = (
1778
1824
  ("retention_time", "retention time", "s", _SECONDS_PER_MINUTE),
1779
1825
  ("start_time", "peak start", "s", _SECONDS_PER_MINUTE),
@@ -2315,6 +2361,15 @@ def _datafile_from_measurement(measurement):
2315
2361
  control = _first(_first(measurement.get(
2316
2362
  "device control aggregate document")).get("device control document"))
2317
2363
  wavelength = _number(control.get("detector wavelength setting"))
2364
+ label = _text(_first(measurement.get(_CHROMATOGRAM_CUBE)).get("label"))
2365
+ if wavelength is None:
2366
+ # See _wavelength_from_label: an exporter that leaves the device
2367
+ # control document without a wavelength setting can still name the
2368
+ # wavelength in the cube label. Read that way the channel keeps a
2369
+ # numeric y-axis label rather than the empty one it used to get.
2370
+ wavelength = _wavelength_from_label(label)
2371
+ if label:
2372
+ file_metadata["description"] = label
2318
2373
 
2319
2374
  # A cube's inlined values are declared numeric, but nothing stops another
2320
2375
  # writer putting text (or nulls) there. The channel is skipped the way an
@@ -2390,36 +2445,101 @@ def _is_absorbance(cube):
2390
2445
  return _first(measures).get("concept") == "absorbance"
2391
2446
 
2392
2447
 
2448
+ def _processing_document(processed_data):
2449
+ """The provenance of one processed data document: which integration ran."""
2450
+ processing = _first(processed_data.get("data processing document"))
2451
+ return {
2452
+ "identifier": _text(processed_data.get("processed data identifier")),
2453
+ "group_identifier": _text(processed_data.get("group identifier")),
2454
+ "time": _text(processed_data.get("data processing time")),
2455
+ "method_name": _text(processing.get("method name")),
2456
+ "method_version": _text(processing.get("method version")),
2457
+ "type": _text(processing.get("data processing type")),
2458
+ }
2459
+
2460
+
2461
+ def _peak_lists(measurement):
2462
+ """Every non-empty ``(processing, peaks)`` a measurement carries, in order.
2463
+
2464
+ A measurement may hold more than one processed data document: an Empower or
2465
+ OpenLab export writes one per result version, so a single channel arrives
2466
+ with the same run integrated several times, under different processing
2467
+ methods and at different times. They are not interchangeable, and they are
2468
+ not ordered by date, so the caller has to be able to see all of them.
2469
+ """
2470
+ processed = _first(measurement.get(_PROCESSED_DATA))
2471
+ lists = []
2472
+ for document in _as_documents(processed.get("processed data document")):
2473
+ if not isinstance(document, dict):
2474
+ continue
2475
+ asm_peaks = [peak for peak
2476
+ in _as_documents(
2477
+ _first(document.get("peak list")).get("peak"))
2478
+ if isinstance(peak, dict)]
2479
+ if asm_peaks:
2480
+ lists.append((_processing_document(document),
2481
+ [_peak_from_asm(peak) for peak in asm_peaks]))
2482
+ return lists
2483
+
2484
+
2393
2485
  def _peaks_from_measurement(measurement):
2394
2486
  """Reconstructs a peak group from a measurement's processed data, or None."""
2395
- processed = _first(measurement.get(_PROCESSED_DATA))
2396
- document = _first(processed.get("processed data document"))
2397
- asm_peaks = [peak for peak
2398
- in _as_documents(_first(document.get("peak list")).get("peak"))
2399
- if isinstance(peak, dict)]
2400
- if not asm_peaks:
2487
+ lists = _peak_lists(measurement)
2488
+ if not lists:
2401
2489
  return None
2490
+ processing, peaks = lists[0]
2402
2491
 
2403
2492
  channel = _text(measurement.get("measurement identifier"))
2404
2493
  if channel is None:
2405
2494
  # An unkeyed group is dropped by _peak_groups_by_channel on the way
2406
2495
  # back out, so these peaks are read and then silently discarded.
2407
2496
  warnings.warn(
2408
- f"a peak list of {len(asm_peaks)} peaks has no usable measurement "
2497
+ f"a peak list of {len(peaks)} peaks has no usable measurement "
2409
2498
  "identifier; it cannot be joined to a channel and will be lost on "
2410
2499
  "re-export.")
2411
2500
  control = _first(_first(measurement.get(
2412
2501
  "device control aggregate document")).get("device control document"))
2413
2502
  wavelength = _number(control.get("detector wavelength setting"))
2503
+ label = _text(_first(measurement.get(_CHROMATOGRAM_CUBE)).get("label"))
2504
+ if wavelength is None:
2505
+ # An exporter that records no detector wavelength setting may still
2506
+ # name the wavelength in the cube label, which is the only thing
2507
+ # telling one channel of a multi-signal run from another.
2508
+ wavelength = _wavelength_from_label(label)
2509
+ if len(lists) > 1:
2510
+ warnings.warn(
2511
+ f"{channel or 'a channel'} carries {len(lists)} processed data "
2512
+ "documents (the same run integrated more than once). The first is "
2513
+ "used; the rest are in the group's 'alternates'. Document order "
2514
+ "is not processing order, so check 'processing' to see which "
2515
+ "integration these peaks came from.")
2414
2516
  return {
2415
2517
  "signal": _channel_key(channel) if channel else None,
2416
2518
  "wavelength": wavelength,
2417
- "description": None,
2519
+ "description": label,
2418
2520
  "channel_file": channel,
2419
- "peaks": [_peak_from_asm(peak) for peak in asm_peaks],
2521
+ "peaks": peaks,
2522
+ "processing": processing,
2523
+ "alternates": [{"processing": other, "peaks": other_peaks}
2524
+ for other, other_peaks in lists[1:]],
2420
2525
  }
2421
2526
 
2422
2527
 
2528
+ # A cube label such as "DAD.0.0, DAD: Signal A, 246.0 nm/Bw:4.0 nm Ref 360.0
2529
+ # nm/Bw:100.0 nm" names three wavelengths: the signal, the bandwidth it was
2530
+ # collected over, and a reference channel. The signal is the one the trace is
2531
+ # measured at and the one written first, so the leftmost match is taken and the
2532
+ # rest of the label ignored. A ChemStation-style "Sig=254,4" label carries no
2533
+ # "nm" and is left to the wavelength setting, which ChemStation does record.
2534
+ _LABEL_WAVELENGTH_RE = re.compile(r"(\d+(?:\.\d+)?)\s*nm")
2535
+
2536
+
2537
+ def _wavelength_from_label(label):
2538
+ """The signal wavelength a cube label names, in nm, or None."""
2539
+ match = _LABEL_WAVELENGTH_RE.search(label) if label else None
2540
+ return float(match.group(1)) if match else None
2541
+
2542
+
2423
2543
  def _peak_from_asm(peak):
2424
2544
  """Reconstructs a peak's measures, times back from seconds to minutes."""
2425
2545
  def value(key):
@@ -2433,6 +2553,11 @@ def _peak_from_asm(peak):
2433
2553
  return seconds / _SECONDS_PER_MINUTE if seconds is not None else None
2434
2554
 
2435
2555
  return {
2556
+ # The compound the integration assigned this peak to, when the
2557
+ # processing method identified one. Without it a peak list is a set of
2558
+ # anonymous retention times, and there is no way to follow one
2559
+ # component across the injections of a study.
2560
+ "name": _text(peak.get("written name")),
2436
2561
  "retention_time": minutes("retention time"),
2437
2562
  "start_time": minutes("peak start"),
2438
2563
  "end_time": minutes("peak end"),
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rainbow-api
3
- Version: 1.5.0
3
+ Version: 1.5.2
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
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes