rainbow-api 1.5.3__tar.gz → 1.5.4__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.3 → rainbow_api-1.5.4}/CHANGELOG.md +35 -0
  2. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/PKG-INFO +1 -1
  3. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/pyproject.toml +1 -1
  4. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/rainbow/asm.py +140 -12
  5. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/rainbow_api.egg-info/PKG-INFO +1 -1
  6. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/COPYING +0 -0
  7. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/COPYING.LESSER +0 -0
  8. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/MANIFEST.in +0 -0
  9. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/README.md +0 -0
  10. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/rainbow/__init__.py +0 -0
  11. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/rainbow/_arguments.py +0 -0
  12. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/rainbow/_binning.py +0 -0
  13. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/rainbow/agilent/__init__.py +0 -0
  14. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/rainbow/agilent/_chdelta.pyx +0 -0
  15. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/rainbow/agilent/_msprofile.pyx +0 -0
  16. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/rainbow/agilent/_uvdelta.pyx +0 -0
  17. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/rainbow/agilent/acaml.py +0 -0
  18. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/rainbow/agilent/chemstation.py +0 -0
  19. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/rainbow/agilent/masshunter.py +0 -0
  20. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/rainbow/agilent/method.py +0 -0
  21. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/rainbow/agilent/openlab.py +0 -0
  22. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/rainbow/agilent/sequence.py +0 -0
  23. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/rainbow/datadirectory.py +0 -0
  24. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/rainbow/datafile.py +0 -0
  25. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/rainbow/datasequence.py +0 -0
  26. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/rainbow/debug/__init__.py +0 -0
  27. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/rainbow/debug/_util.py +0 -0
  28. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/rainbow/debug/chemstation_header.py +0 -0
  29. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/rainbow/debug/chemstation_text.py +0 -0
  30. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/rainbow/debug/dotnet.py +0 -0
  31. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/rainbow/debug/ini.py +0 -0
  32. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/rainbow/debug/method.py +0 -0
  33. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/rainbow/debug/mzxml.py +0 -0
  34. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/rainbow/debug/reg.py +0 -0
  35. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/rainbow/debug/waters_header.py +0 -0
  36. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/rainbow/debug/waters_inf.py +0 -0
  37. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/rainbow/debug/xml.py +0 -0
  38. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/rainbow/waters/__init__.py +0 -0
  39. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/rainbow/waters/masslynx.py +0 -0
  40. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/rainbow_api.egg-info/SOURCES.txt +0 -0
  41. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/rainbow_api.egg-info/dependency_links.txt +0 -0
  42. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/rainbow_api.egg-info/requires.txt +0 -0
  43. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/rainbow_api.egg-info/top_level.txt +0 -0
  44. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/setup.cfg +0 -0
  45. {rainbow_api-1.5.3 → rainbow_api-1.5.4}/setup.py +0 -0
@@ -3,6 +3,41 @@
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.4] - 2026-10-17
7
+
8
+ ### Added
9
+ - **`rb.from_asm` peaks carry the baseline they were integrated from.** A
10
+ peak's area depends on the line it was measured above, and rainbow read the
11
+ area and dropped the line. An Empower export records it for every peak, and
12
+ each peak `from_asm` returns now has six more keys:
13
+ `baseline_start_code` and `baseline_end_code`, the integration type at each
14
+ edge (`B`, `V`, `S`, `T`, ..., lowercase for an edge moved by hand, a
15
+ group's `Gp` split into `G` and `p`); `start_height` and `end_height`, how
16
+ far the trace sits above the baseline at each edge, in mAU; and
17
+ `baseline_start_time` and `baseline_end_time`, where the baseline under the
18
+ peak's cluster begins and ends, in minutes. The line from
19
+ `(start_time, trace - start_height)` to `(end_time, trace - end_height)`
20
+ reproduces the reported area: within 1% for 99.6% of 11,040 peaks across
21
+ four Empower studies, the misses being edges moved by hand.
22
+
23
+ A height in AU or in Empower's µV is converted to mAU (one with no unit is
24
+ taken to be in mAU), and a baseline time in `s` or `min` to minutes; any
25
+ other unit reads as `None`, as do an absent field and a unitless time. The
26
+ heights are written back on export as `peak value at start` and `peak value
27
+ at end`. The schema defines neither the codes nor
28
+ the baseline times, so they are written as the peak's custom information,
29
+ under the labels Empower uses, and read from either place: an export keeps
30
+ them and still validates.
31
+
32
+ ### Changed
33
+ - **`rb.from_asm` reads a peak's `height` and `area` in mAU and mAU·s, by
34
+ their unit.** They were taken as numbers whatever unit the document named,
35
+ and exported as mAU and mAU·s, so a peak list in AU or in Empower's µV was
36
+ written a thousand times off under a unit it was not in. They are now
37
+ converted from AU or µV (and AU·s or µV·s), as the edge heights are. A unit
38
+ rainbow does not know now reads as `None` where it used to pass through
39
+ unconverted; a value with no unit is still taken to be in mAU.
40
+
6
41
  ## [1.5.3] - 2026-10-01
7
42
 
8
43
  ### Fixed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rainbow-api
3
- Version: 1.5.3
3
+ Version: 1.5.4
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.3"
7
+ version = "1.5.4"
8
8
  description = "Read chromatography and mass spectrometry binary files"
9
9
  readme = "README.md"
10
10
  license = {text = "LGPL-3.0-or-later"}
@@ -1982,6 +1982,8 @@ def _asm_peak(index, peak, options=None):
1982
1982
  ("height_percent", "relative peak height", "%", 1.0),
1983
1983
  ("symmetry", "asymmetry factor measured at 5 % height",
1984
1984
  "(unitless)", 1.0),
1985
+ ("start_height", "peak value at start", "mAU", 1.0),
1986
+ ("end_height", "peak value at end", "mAU", 1.0),
1985
1987
  )
1986
1988
  for source, target, unit, scale in mapping:
1987
1989
  value = peak.get(source)
@@ -1989,9 +1991,45 @@ def _asm_peak(index, peak, options=None):
1989
1991
  # rather than fail the whole export.
1990
1992
  if isinstance(value, (int, float)) and not isinstance(value, bool):
1991
1993
  entry[target] = _quantity(value * scale, unit, options)
1994
+ custom = _peak_baseline_custom(peak, options)
1995
+ if custom:
1996
+ entry["custom information aggregate document"] = {
1997
+ "custom information document": custom}
1992
1998
  return entry
1993
1999
 
1994
2000
 
2001
+ # A peak's baseline fields the schema has no place for, as ``(key, label)``.
2002
+ # Empower writes them on the peak itself under these labels; rainbow writes
2003
+ # them as custom information under the same labels, so a document it exports
2004
+ # validates, and reads them from either place.
2005
+ _PEAK_BASELINE_CODES = (
2006
+ ("baseline_start_code", "peak baseline start code"),
2007
+ ("baseline_end_code", "peak baseline end code"),
2008
+ )
2009
+ _PEAK_BASELINE_TIMES = (
2010
+ ("baseline_start_time", "baseline value at start of peak"),
2011
+ ("baseline_end_time", "baseline value at end of peak"),
2012
+ )
2013
+
2014
+
2015
+ def _peak_baseline_custom(peak, options):
2016
+ """A peak's baseline codes and times as custom information documents."""
2017
+ entries = []
2018
+ for key, label in _PEAK_BASELINE_CODES:
2019
+ code = peak.get(key)
2020
+ if isinstance(code, str) and code.strip():
2021
+ entries.append({"datum label": label,
2022
+ "scalar string datum": code.strip()})
2023
+ for key, label in _PEAK_BASELINE_TIMES:
2024
+ time = peak.get(key)
2025
+ if isinstance(time, (int, float)) and not isinstance(time, bool):
2026
+ seconds = _quantity(time * _SECONDS_PER_MINUTE, "s", options)
2027
+ entries.append({"datum label": label,
2028
+ "scalar double datum": seconds["value"],
2029
+ "unit": "s"})
2030
+ return [dict({"@index": i + 1}, **e) for i, e in enumerate(entries)]
2031
+
2032
+
1995
2033
  def _peak_groups_by_channel(peaks):
1996
2034
  """Indexes an injection's peak groups by channel (e.g. ``DAD1A``)."""
1997
2035
  groups = {}
@@ -2184,8 +2222,10 @@ def from_asm(document, name="asm"):
2184
2222
  # view. Choosing per injection and keeping the first answer lost the
2185
2223
  # identifier whenever an earlier injection supplied only a name.
2186
2224
  _absorb_samples(_measurements_of(documents), metadata)
2225
+ said = set()
2187
2226
  for lc_document in documents:
2188
- _absorb_lc_document(lc_document, metadata, datafiles, peak_groups)
2227
+ _absorb_lc_document(lc_document, metadata, datafiles, peak_groups,
2228
+ said)
2189
2229
  return _directory(name, datafiles, metadata, peak_groups)
2190
2230
 
2191
2231
 
@@ -2344,13 +2384,14 @@ def sequence_from_asm(document, name="asm"):
2344
2384
 
2345
2385
  injections = []
2346
2386
  taken = set()
2387
+ said = set()
2347
2388
  for index, lc_document in enumerate(documents):
2348
2389
  injection_metadata = {}
2349
2390
  datafiles = []
2350
2391
  peak_groups = []
2351
2392
  _absorb_samples(_measurements_of([lc_document]), injection_metadata)
2352
2393
  _absorb_lc_document(
2353
- lc_document, injection_metadata, datafiles, peak_groups)
2394
+ lc_document, injection_metadata, datafiles, peak_groups, said)
2354
2395
  # The injection identifier is the name the injection was exported
2355
2396
  # under, so it restores the caller's own name. The sample identifier is
2356
2397
  # the fallback because a sequence's replicates share one, which used to
@@ -2412,8 +2453,13 @@ def _measurements_of(lc_documents):
2412
2453
  return measurements
2413
2454
 
2414
2455
 
2415
- def _absorb_lc_document(lc_document, metadata, datafiles, peak_groups):
2416
- """Reads one liquid chromatography document into datafiles and metadata."""
2456
+ def _absorb_lc_document(lc_document, metadata, datafiles, peak_groups,
2457
+ said=None):
2458
+ """Reads one liquid chromatography document into datafiles and metadata.
2459
+
2460
+ ``said`` collects the read's warnings about peaks' custom information, so
2461
+ one complaint repeated across peaks and documents is made once.
2462
+ """
2417
2463
  if not isinstance(lc_document, dict):
2418
2464
  return
2419
2465
  analyst = _text(lc_document.get("analyst"))
@@ -2439,7 +2485,7 @@ def _absorb_lc_document(lc_document, metadata, datafiles, peak_groups):
2439
2485
  if datafile is None:
2440
2486
  continue # a measurement rainbow did not write (no UV cube)
2441
2487
  datafiles.append(datafile)
2442
- group = _peaks_from_measurement(measurement)
2488
+ group = _peaks_from_measurement(measurement, said)
2443
2489
  if group:
2444
2490
  peak_groups.append(group)
2445
2491
 
@@ -2864,7 +2910,7 @@ def _processing_document(processed_data):
2864
2910
  }
2865
2911
 
2866
2912
 
2867
- def _peak_lists(measurement):
2913
+ def _peak_lists(measurement, said=None):
2868
2914
  """Every non-empty ``(processing, peaks)`` a measurement carries, in order.
2869
2915
 
2870
2916
  A measurement may hold more than one processed data document: an Empower or
@@ -2884,13 +2930,13 @@ def _peak_lists(measurement):
2884
2930
  if isinstance(peak, dict)]
2885
2931
  if asm_peaks:
2886
2932
  lists.append((_processing_document(document),
2887
- [_peak_from_asm(peak) for peak in asm_peaks]))
2933
+ [_peak_from_asm(peak, said) for peak in asm_peaks]))
2888
2934
  return lists
2889
2935
 
2890
2936
 
2891
- def _peaks_from_measurement(measurement):
2937
+ def _peaks_from_measurement(measurement, said=None):
2892
2938
  """Reconstructs a peak group from a measurement's processed data, or None."""
2893
- lists = _peak_lists(measurement)
2939
+ lists = _peak_lists(measurement, said)
2894
2940
  if not lists:
2895
2941
  return None
2896
2942
  processing, peaks = lists[0]
@@ -2946,7 +2992,7 @@ def _wavelength_from_label(label):
2946
2992
  return float(match.group(1)) if match else None
2947
2993
 
2948
2994
 
2949
- def _peak_from_asm(peak):
2995
+ def _peak_from_asm(peak, said=None):
2950
2996
  """Reconstructs a peak's measures, times back from seconds to minutes."""
2951
2997
  def value(key):
2952
2998
  # A foreign writer may spell a measure as text, or as something else
@@ -2967,14 +3013,96 @@ def _peak_from_asm(peak):
2967
3013
  "retention_time": minutes("retention time"),
2968
3014
  "start_time": minutes("peak start"),
2969
3015
  "end_time": minutes("peak end"),
2970
- "area": value("peak area"),
3016
+ "area": _peak_measure_in_mau(peak.get("peak area"), ".s"),
2971
3017
  "area_percent": value("relative peak area"),
2972
- "height": value("peak height"),
3018
+ "height": _peak_measure_in_mau(peak.get("peak height")),
2973
3019
  "height_percent": value("relative peak height"),
2974
3020
  "symmetry": value("asymmetry factor measured at 5 % height"),
3021
+ # How the integration drew the baseline under this peak. A height is
3022
+ # how far the trace sits above the baseline at that edge, in mAU, so
3023
+ # the line runs from (start, trace - start height) to (end, trace - end
3024
+ # height).
3025
+ "start_height": _peak_measure_in_mau(
3026
+ peak.get("peak value at start")),
3027
+ "end_height": _peak_measure_in_mau(peak.get("peak value at end")),
3028
+ **_peak_baseline_fields(peak, said),
2975
3029
  }
2976
3030
 
2977
3031
 
3032
+ # The units a peak's height, edge heights and area are read in, as mAU per
3033
+ # unit (an area's unit is one of these times seconds). Empower's own unit for a
3034
+ # UV height is the microvolt, one of which is one microabsorbance unit. Kept
3035
+ # apart from _ABSORBANCE_TO_MAU so that a cube labelled in microvolts exports
3036
+ # as it did before. The micro sign and the Greek mu are both in use.
3037
+ _PEAK_VALUE_TO_MAU = dict(_ABSORBANCE_TO_MAU, **{"\u00b5v": 0.001,
3038
+ "\u03bcv": 0.001})
3039
+
3040
+
3041
+ def _peak_measure_in_mau(quantity, per=""):
3042
+ """
3043
+ A peak's height (or, with ``per=".s"``, its area) in mAU, or None.
3044
+
3045
+ The export labels these mAU and mAU.s, so a value read in AU or microvolts
3046
+ has to be converted to match, or it is written a thousand times off under
3047
+ a unit it is not in. A unit rainbow does not know reads as None rather than
3048
+ as a number in the wrong unit. A value with no unit at all is taken to be
3049
+ in the schema's own mAU, as rainbow has always read it.
3050
+
3051
+ """
3052
+ number = _number(quantity)
3053
+ unit = quantity.get("unit") if isinstance(quantity, dict) else None
3054
+ if number is None or unit is None:
3055
+ return number
3056
+ key = _absorbance_unit_key(unit) if isinstance(unit, str) else ""
3057
+ scale = _PEAK_VALUE_TO_MAU.get(key[:len(key) - len(per)]) \
3058
+ if key.endswith(per) else None
3059
+ if scale is None:
3060
+ return None
3061
+ # Unscaled when already mAU, so an integer stays the integer it was.
3062
+ return number if scale == 1.0 else number * scale
3063
+
3064
+
3065
+ # The units a baseline time is read in, as units per minute. Any other unit,
3066
+ # or none, gives None: the field's name reads as a signal value, and the unit
3067
+ # is the only thing that says a writer filled it with a time.
3068
+ _TIME_UNITS_PER_MINUTE = {"s": _SECONDS_PER_MINUTE, "min": 1.0}
3069
+
3070
+
3071
+ def _peak_baseline_fields(peak, said=None):
3072
+ """
3073
+ A peak's baseline codes and times, read from the peak or its custom
3074
+ information.
3075
+
3076
+ A code is the integration type at each edge (B, V, S, T, ..., lowercase
3077
+ where the edge was moved by hand; Empower splits a group's "Gp" into "G"
3078
+ and "p"). A time is where the baseline under the peak's cluster begins or
3079
+ ends, in minutes like the peak's other times. Empower writes both on the
3080
+ peak, where the schema does not define them; rainbow writes them as custom
3081
+ information, where it does.
3082
+
3083
+ """
3084
+ custom = {}
3085
+ if "custom information aggregate document" in peak:
3086
+ custom = _custom_fields(peak, set() if said is None else said)
3087
+
3088
+ def field(label):
3089
+ value = peak.get(label)
3090
+ return value if value is not None else custom.get(label)
3091
+
3092
+ fields = {}
3093
+ for key, label in _PEAK_BASELINE_CODES:
3094
+ fields[key] = (_text(field(label)) or "").strip() or None
3095
+ for key, label in _PEAK_BASELINE_TIMES:
3096
+ quantity = field(label)
3097
+ number = _number(quantity)
3098
+ unit = quantity.get("unit") if isinstance(quantity, dict) else None
3099
+ per_minute = _TIME_UNITS_PER_MINUTE.get(unit) \
3100
+ if isinstance(unit, str) else None
3101
+ fields[key] = number / per_minute \
3102
+ if number is not None and per_minute else None
3103
+ return fields
3104
+
3105
+
2978
3106
  def _instrument_from_device_system(device_system):
2979
3107
  """Reconstructs the instrument dict from a device system document, or None."""
2980
3108
  if not isinstance(device_system, dict):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rainbow-api
3
- Version: 1.5.3
3
+ Version: 1.5.4
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