rainbow-api 1.5.0__tar.gz → 1.5.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.
Files changed (45) hide show
  1. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/CHANGELOG.md +29 -0
  2. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/PKG-INFO +1 -1
  3. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/pyproject.toml +1 -1
  4. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/rainbow/agilent/sequence.py +6 -1
  5. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/rainbow/asm.py +138 -13
  6. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/rainbow_api.egg-info/PKG-INFO +1 -1
  7. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/COPYING +0 -0
  8. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/COPYING.LESSER +0 -0
  9. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/MANIFEST.in +0 -0
  10. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/README.md +0 -0
  11. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/rainbow/__init__.py +0 -0
  12. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/rainbow/_arguments.py +0 -0
  13. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/rainbow/_binning.py +0 -0
  14. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/rainbow/agilent/__init__.py +0 -0
  15. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/rainbow/agilent/_chdelta.pyx +0 -0
  16. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/rainbow/agilent/_msprofile.pyx +0 -0
  17. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/rainbow/agilent/_uvdelta.pyx +0 -0
  18. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/rainbow/agilent/acaml.py +0 -0
  19. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/rainbow/agilent/chemstation.py +0 -0
  20. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/rainbow/agilent/masshunter.py +0 -0
  21. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/rainbow/agilent/method.py +0 -0
  22. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/rainbow/agilent/openlab.py +0 -0
  23. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/rainbow/datadirectory.py +0 -0
  24. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/rainbow/datafile.py +0 -0
  25. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/rainbow/datasequence.py +0 -0
  26. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/rainbow/debug/__init__.py +0 -0
  27. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/rainbow/debug/_util.py +0 -0
  28. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/rainbow/debug/chemstation_header.py +0 -0
  29. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/rainbow/debug/chemstation_text.py +0 -0
  30. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/rainbow/debug/dotnet.py +0 -0
  31. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/rainbow/debug/ini.py +0 -0
  32. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/rainbow/debug/method.py +0 -0
  33. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/rainbow/debug/mzxml.py +0 -0
  34. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/rainbow/debug/reg.py +0 -0
  35. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/rainbow/debug/waters_header.py +0 -0
  36. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/rainbow/debug/waters_inf.py +0 -0
  37. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/rainbow/debug/xml.py +0 -0
  38. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/rainbow/waters/__init__.py +0 -0
  39. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/rainbow/waters/masslynx.py +0 -0
  40. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/rainbow_api.egg-info/SOURCES.txt +0 -0
  41. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/rainbow_api.egg-info/dependency_links.txt +0 -0
  42. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/rainbow_api.egg-info/requires.txt +0 -0
  43. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/rainbow_api.egg-info/top_level.txt +0 -0
  44. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/setup.cfg +0 -0
  45. {rainbow_api-1.5.0 → rainbow_api-1.5.1}/setup.py +0 -0
@@ -3,6 +3,35 @@
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.1] - 2026-08-27
7
+
8
+ ### Fixed
9
+ - **`rb.from_asm` dropped a peak's compound name.** A processing method that
10
+ identified a peak writes the compound under `written name`; rainbow read
11
+ every quantity on the peak and discarded the name, leaving a peak list of
12
+ anonymous retention times with no way to follow a component across the
13
+ injections of a study. It is now read as the peak's `name`, and written back
14
+ on export.
15
+ - **`rb.from_asm` kept only the first of several integrations.** An Agilent
16
+ OpenLab or Empower export writes one processed data document per result
17
+ version, so a channel can arrive with the same run integrated up to six
18
+ times, under different processing methods and at different dates. rainbow
19
+ read the first and dropped the rest without a word, and the peak lists
20
+ genuinely differ: a reintegration finds or loses whole peaks. Every peak list
21
+ is now read. The first is still the group's `peaks`, so existing code is
22
+ unaffected; the rest are in the group's new `alternates`, each labelled with
23
+ the integration that produced it, and the group's new `processing` records
24
+ which integration the default peaks came from. Document order is not
25
+ processing order, so a group that carries alternates now warns. Re-export
26
+ writes them all back.
27
+ - **A channel of an OpenLab export had no wavelength.** rainbow read the
28
+ wavelength only from the device control document's `detector wavelength
29
+ setting`, which that exporter does not write, so every channel came back with
30
+ an empty y-axis label and a three-signal injection was three
31
+ indistinguishable traces. The wavelength is now also read from the cube
32
+ label, which is where that exporter names it, and the label itself is kept as
33
+ the channel's and the peak group's `description`.
34
+
6
35
  ## [1.5.0] - 2026-08-27
7
36
 
8
37
  ### 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.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
@@ -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.1"
8
8
  description = "Read chromatography and mass spectrometry binary files"
9
9
  readme = "README.md"
10
10
  license = {text = "LGPL-3.0-or-later"}
@@ -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.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
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes