rainbow-api 1.0.9__tar.gz → 1.0.11__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 (23) hide show
  1. rainbow_api-1.0.11/COPYING.LESSER +165 -0
  2. {rainbow_api-1.0.9/rainbow_api.egg-info → rainbow_api-1.0.11}/PKG-INFO +7 -5
  3. {rainbow_api-1.0.9 → rainbow_api-1.0.11}/README.md +1 -1
  4. {rainbow_api-1.0.9 → rainbow_api-1.0.11}/pyproject.toml +3 -3
  5. {rainbow_api-1.0.9 → rainbow_api-1.0.11}/rainbow/agilent/chemstation.py +12 -8
  6. {rainbow_api-1.0.9 → rainbow_api-1.0.11}/rainbow/waters/masslynx.py +139 -32
  7. {rainbow_api-1.0.9 → rainbow_api-1.0.11/rainbow_api.egg-info}/PKG-INFO +7 -5
  8. {rainbow_api-1.0.9 → rainbow_api-1.0.11}/rainbow_api.egg-info/SOURCES.txt +1 -0
  9. {rainbow_api-1.0.9 → rainbow_api-1.0.11}/tests/test_waters.py +8 -0
  10. {rainbow_api-1.0.9 → rainbow_api-1.0.11}/COPYING +0 -0
  11. {rainbow_api-1.0.9 → rainbow_api-1.0.11}/rainbow/__init__.py +0 -0
  12. {rainbow_api-1.0.9 → rainbow_api-1.0.11}/rainbow/agilent/__init__.py +0 -0
  13. {rainbow_api-1.0.9 → rainbow_api-1.0.11}/rainbow/agilent/masshunter.py +0 -0
  14. {rainbow_api-1.0.9 → rainbow_api-1.0.11}/rainbow/datadirectory.py +0 -0
  15. {rainbow_api-1.0.9 → rainbow_api-1.0.11}/rainbow/datafile.py +0 -0
  16. {rainbow_api-1.0.9 → rainbow_api-1.0.11}/rainbow/waters/__init__.py +0 -0
  17. {rainbow_api-1.0.9 → rainbow_api-1.0.11}/rainbow_api.egg-info/dependency_links.txt +0 -0
  18. {rainbow_api-1.0.9 → rainbow_api-1.0.11}/rainbow_api.egg-info/requires.txt +0 -0
  19. {rainbow_api-1.0.9 → rainbow_api-1.0.11}/rainbow_api.egg-info/top_level.txt +0 -0
  20. {rainbow_api-1.0.9 → rainbow_api-1.0.11}/setup.cfg +0 -0
  21. {rainbow_api-1.0.9 → rainbow_api-1.0.11}/tests/test_agilent.py +0 -0
  22. {rainbow_api-1.0.9 → rainbow_api-1.0.11}/tests/test_datadirectory.py +0 -0
  23. {rainbow_api-1.0.9 → rainbow_api-1.0.11}/tests/test_datafile.py +0 -0
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
@@ -1,24 +1,26 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: rainbow-api
3
- Version: 1.0.9
3
+ Version: 1.0.11
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
7
- License: COPYING
7
+ License: COPYING.LESSER
8
8
  Project-URL: Repository, https://github.com/evanyeyeye/rainbow
9
9
  Project-URL: Documentation, https://rainbow-api.readthedocs.io
10
- Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
10
+ Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)
11
11
  Description-Content-Type: text/markdown
12
12
  License-File: COPYING
13
+ License-File: COPYING.LESSER
13
14
  Requires-Dist: numpy
14
15
  Requires-Dist: matplotlib
15
16
  Requires-Dist: lxml
16
17
  Requires-Dist: pandas
18
+ Dynamic: license-file
17
19
 
18
20
  # rainbow
19
21
  [![PyPI](https://img.shields.io/pypi/v/rainbow-api)](https://pypi.org/project/rainbow-api)
20
22
  [![Documentation Status](https://readthedocs.org/projects/rainbow-api/badge/?version=latest)](https://rainbow-api.readthedocs.io/en/latest/?badge=latest)
21
- [![PyPI - Downloads](https://img.shields.io/pypi/dm/rainbow-api)](https://pypi.org/project/rainbow-api)
23
+ [![PyPI - Downloads](https://static.pepy.tech/badge/rainbow-api)](https://pypi.org/project/rainbow-api)
22
24
 
23
25
  *rainbow* provides programmatic access to the raw data encoded in chromatography and mass spectrometry binary files. This library supports the following vendors and detectors:
24
26
 
@@ -1,7 +1,7 @@
1
1
  # rainbow
2
2
  [![PyPI](https://img.shields.io/pypi/v/rainbow-api)](https://pypi.org/project/rainbow-api)
3
3
  [![Documentation Status](https://readthedocs.org/projects/rainbow-api/badge/?version=latest)](https://rainbow-api.readthedocs.io/en/latest/?badge=latest)
4
- [![PyPI - Downloads](https://img.shields.io/pypi/dm/rainbow-api)](https://pypi.org/project/rainbow-api)
4
+ [![PyPI - Downloads](https://static.pepy.tech/badge/rainbow-api)](https://pypi.org/project/rainbow-api)
5
5
 
6
6
  *rainbow* provides programmatic access to the raw data encoded in chromatography and mass spectrometry binary files. This library supports the following vendors and detectors:
7
7
 
@@ -4,16 +4,16 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "rainbow-api"
7
- version = "1.0.9"
7
+ version = "1.0.11"
8
8
  description = "Read chromatography and mass spectrometry binary files"
9
9
  readme = "README.md"
10
- license = {text = "COPYING"}
10
+ license = {text = "COPYING.LESSER"}
11
11
  authors = [
12
12
  {name = "Evan Shi and Eugene Kwan"},
13
13
  {email = "evanyshi@cmu.edu"}
14
14
  ]
15
15
  classifiers = [
16
- "License :: OSI Approved :: GNU General Public License v3 (GPLv3)"
16
+ "License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)"
17
17
  ]
18
18
  dependencies = [
19
19
  "numpy",
@@ -5,6 +5,7 @@ Methods for parsing Agilent Chemstation files.
5
5
 
6
6
  import os
7
7
  import struct
8
+ from collections import Counter
8
9
  import numpy as np
9
10
  from lxml import etree
10
11
  from rainbow.datafile import DataFile
@@ -651,7 +652,7 @@ def parse_ms(path, prec=0):
651
652
  data = np.zeros((num_times, ylabels.size), dtype=np.uint32)
652
653
  cur_index = 0
653
654
  for i in range(num_times):
654
- stop_index = cur_index + pair_counts[i]
655
+ stop_index = cur_index + int(pair_counts[i])
655
656
  np.add.at(
656
657
  data[i],
657
658
  mz_indices[cur_index:stop_index],
@@ -847,13 +848,16 @@ def parse_metadata(path, datafiles):
847
848
  metadata['vendor'] = "Agilent"
848
849
 
849
850
  # Scan each DataFile for the date and vial position.
850
- # These may be stored in multiple files but the values are constant.
851
- # In MS files, the time may be saved in a different format.
852
- for datafile in datafiles:
853
- if 'date' not in metadata and 'date' in datafile.metadata:
854
- metadata['date'] = datafile.metadata['date']
855
- if 'vialpos' not in metadata and 'vialpos' in datafile.metadata:
856
- metadata['vialpos'] = datafile.metadata['vialpos']
851
+ # These may be stored in multiple files but the values are constant.
852
+ # In MS files, the time may be saved in a different format.
853
+ # Get the most common values if they differ across files
854
+ dates = Counter(datafile.metadata['date'] for datafile in datafiles if 'date' in datafile.metadata)
855
+ vialposs = Counter(datafile.metadata['vialpos'] for datafile in datafiles if 'vialpos' in datafile.metadata)
856
+ if dates:
857
+ metadata['date'] = dates.most_common(1)[0][0]
858
+ if vialposs:
859
+ metadata['vialpos'] = vialposs.most_common(1)[0][0]
860
+
857
861
  if 'date' in metadata and 'vialpos' in metadata:
858
862
  return metadata
859
863
 
@@ -1,6 +1,8 @@
1
1
  """
2
2
  Methods for parsing Waters Masslynx files.
3
-
3
+
4
+ Patched to support case-insensitive filenames (e.g. Perkin-Elmer GC-MS).
5
+
4
6
  """
5
7
  import os
6
8
  import re
@@ -8,6 +10,44 @@ import numpy as np
8
10
  from rainbow.datafile import DataFile
9
11
  import pandas as pd
10
12
 
13
+
14
+ def _find_file(directory, target_name):
15
+ """
16
+ Case-insensitive file lookup in a directory.
17
+
18
+ Args:
19
+ directory (str): Path to the directory.
20
+ target_name (str): Filename to search for (case-insensitive).
21
+
22
+ Returns:
23
+ The actual filename as it exists on disk, or None if not found.
24
+
25
+ """
26
+ target_lower = target_name.lower()
27
+ for fn in os.listdir(directory):
28
+ if fn.lower() == target_lower:
29
+ return fn
30
+ return None
31
+
32
+
33
+ def _find_file_path(directory, target_name):
34
+ """
35
+ Case-insensitive file lookup that returns the full path.
36
+
37
+ Args:
38
+ directory (str): Path to the directory.
39
+ target_name (str): Filename to search for (case-insensitive).
40
+
41
+ Returns:
42
+ Full path to the file, or None if not found.
43
+
44
+ """
45
+ fn = _find_file(directory, target_name)
46
+ if fn is not None:
47
+ return os.path.join(directory, fn)
48
+ return None
49
+
50
+
11
51
  """
12
52
  SPECTRUM PARSING METHODS
13
53
 
@@ -38,42 +78,61 @@ def parse_spectrum(path, prec=0, requested_files=None):
38
78
  # Future work may find useful metadata there.
39
79
  polarities = []
40
80
  calib_nums = []
41
- if '_extern.inf' in os.listdir(path):
81
+ extern_inf = _find_file(path, '_extern.inf')
82
+ if extern_inf is not None:
42
83
  # Parse MS polarities from _extern.inf.
43
- with open(os.path.join(path, '_extern.inf'), 'rb') as f:
84
+ with open(os.path.join(path, extern_inf), 'rb') as f:
44
85
  lines = f.read().decode('ascii', 'ignore').splitlines()
45
86
  for i in range(len(lines)):
46
- if not lines[i].startswith("Instrument Parameters"):
47
- continue
48
- if lines[i + 1].startswith("Polarity"):
49
- polarity = lines[i + 1].split('\t\t\t')[1][-1]
50
- else:
51
- try:
52
- polarity = lines[i + 2].split('\t')[1][-1]
53
- except Exception:
54
- raise Exception("Waters HRMS data is not supported.")
55
- polarities.append(polarity)
87
+ # Waters format: "Instrument Parameters" trigger
88
+ if lines[i].startswith("Instrument Parameters"):
89
+ if lines[i + 1].startswith("Polarity"):
90
+ polarity = lines[i + 1].split('\t\t\t')[1][-1]
91
+ else:
92
+ try:
93
+ polarity = lines[i + 2].split('\t')[1][-1]
94
+ except Exception:
95
+ raise Exception("Waters HRMS data is not supported.")
96
+ polarities.append(polarity)
97
+ # PE/TurboMass format: "Function N:" trigger
98
+ elif re.match(r'^Function\s+\d+', lines[i]):
99
+ for j in range(i + 1, min(i + 5, len(lines))):
100
+ if lines[j].strip().startswith("Polarity"):
101
+ pol_value = lines[j].split('\t')[-1].strip()
102
+ polarity = pol_value[-1] # last char: + or -
103
+ polarities.append(polarity)
104
+ break
56
105
 
57
106
  # Parse mz calibration values from _HEADER.txt.
58
107
  # There are a separate list of values for each MS spectrum.
59
- with open(os.path.join(path, '_HEADER.TXT'), 'r') as f:
60
- lines = f.read().splitlines()
61
- for line in lines:
62
- if not line.startswith("$$ Cal Function"):
63
- continue
64
- calib_nums.append(
65
- [float(num) for num in line.split(': ')[1].split(',')[:-1]])
108
+ # PE exports may omit _HEADER.TXT; skip calibration instead of failing.
109
+ header_txt = _find_file_path(path, '_HEADER.TXT')
110
+ if header_txt is not None:
111
+ with open(header_txt, 'r') as f:
112
+ lines = f.read().splitlines()
113
+ for line in lines:
114
+ if not line.startswith("$$ Cal Function"):
115
+ continue
116
+ calib_nums.append(
117
+ [float(num) for num in line.split(': ')[1].split(',')[:-1]])
66
118
 
67
119
  # The raw spectrum data is stored in _FUNC .DAT files.
68
120
  # Each MS spectrum has an assigned polarity,
69
121
  # but may not have calibration values.
70
- funcdat_files = sorted(fn for fn in os.listdir(path) if re.match(r'^_FUNC\d{3}.DAT$', fn))
71
- assert (os.path.getsize(os.path.join(path, "_FUNCTNS.INF")) == 32 * 13 * len(funcdat_files))
122
+ funcdat_files = sorted(
123
+ fn for fn in os.listdir(path)
124
+ if re.match(r'^_FUNC\d{3}\.DAT$', fn, re.IGNORECASE))
125
+ # Waters validates _FUNCTNS.INF size; PE exports may omit this file entirely.
126
+ functns_inf = _find_file_path(path, '_FUNCTNS.INF')
127
+ if functns_inf is not None:
128
+ assert (os.path.getsize(functns_inf) == 32 * 13 * len(funcdat_files))
72
129
  for funcdat_index, funcdat_file in enumerate(funcdat_files):
73
130
  if requested_files and funcdat_file.lower() not in requested_files:
74
131
  continue
75
132
  polarity = None
76
133
  calib = None
134
+ # polarities/calib_nums may be shorter than funcdat_files when metadata
135
+ # is missing or only partially parsed; spectra parse without calib/polarity.
77
136
  if funcdat_index < len(polarities):
78
137
  polarity = polarities[funcdat_index]
79
138
  if funcdat_index < len(calib_nums):
@@ -107,7 +166,13 @@ def parse_function(path, prec=0, polarity=None, calib=None):
107
166
  # Extract the retention times, "pair" counts,
108
167
  # and _FUNC .DAT data format from the _FUNC .IDX file.
109
168
  # A "pair" refers to a data pair of mz-intensity or wavelength-absorbance.
110
- times, pair_counts, bytes_per_pair = parse_funcidx(path[:-3] + 'IDX')
169
+ dat_dir = os.path.dirname(path)
170
+ dat_base = os.path.basename(path)
171
+ root, _ = os.path.splitext(dat_base)
172
+ idx_path = _find_file_path(dat_dir, root + '.IDX')
173
+ if idx_path is None:
174
+ idx_path = path[:-3] + 'IDX' # fallback to original behavior
175
+ times, pair_counts, bytes_per_pair = parse_funcidx(idx_path)
111
176
  if bytes_per_pair not in {2, 4, 6, 8}:
112
177
  raise Exception("The {bytes_per_pair}-bytes format is not supported.")
113
178
 
@@ -153,10 +218,15 @@ def parse_funcidx(path):
153
218
  times = np.ndarray(num_times, '<f', raw_bytes, 12, 22).copy()
154
219
 
155
220
  # Calculate the _FUNC .DAT file format based on the bytes per pair.
221
+ base = os.path.basename(path)
222
+ root, _ = os.path.splitext(base)
223
+ dat_path = _find_file_path(os.path.dirname(path), root + '.DAT')
224
+ if dat_path is None:
225
+ dat_path = path[:-3] + 'DAT' # fallback
156
226
  nonzero = pair_counts != 0
157
227
  final_offset = offsets[nonzero][-1]
158
228
  final_paircount = pair_counts[nonzero][-1]
159
- dat_size = os.path.getsize(path[:-3] + 'DAT')
229
+ dat_size = os.path.getsize(dat_path)
160
230
  bytes_per_pair = (dat_size - final_offset) // final_paircount
161
231
 
162
232
  return times, pair_counts, bytes_per_pair
@@ -186,7 +256,9 @@ def parse_funcdat2(path, pair_counts, prec=0, calib=None):
186
256
  # Extract the mz values from the _FUNCTNS.INF file.
187
257
  # This code makes the assumption that in this format the
188
258
  # number of mz values is constant at each retention time.
189
- inf_path = os.path.join(os.path.dirname(path), '_FUNCTNS.INF')
259
+ inf_path = _find_file_path(os.path.dirname(path), '_FUNCTNS.INF')
260
+ if inf_path is None:
261
+ inf_path = os.path.join(os.path.dirname(path), '_FUNCTNS.INF')
190
262
  func_index = int(re.findall(r"\d+", os.path.basename(path))[0]) - 1
191
263
  mzs = parse_funcinf(inf_path)[func_index]
192
264
  ylabels = mzs[mzs != 0.0]
@@ -231,8 +303,10 @@ def parse_funcdat4(path, pair_counts, prec=0, calib=None):
231
303
  # Extract the mz values from the _FUNCTNS.INF file.
232
304
  # This code makes the assumption that in this format the
233
305
  # number of mz values is constant at each retention time.
234
- inf_path = os.path.join(os.path.dirname(path), '_FUNCTNS.INF')
235
- func_index = int(re.findall("\d+", os.path.basename(path))[0]) - 1
306
+ inf_path = _find_file_path(os.path.dirname(path), '_FUNCTNS.INF')
307
+ if inf_path is None:
308
+ inf_path = os.path.join(os.path.dirname(path), '_FUNCTNS.INF')
309
+ func_index = int(re.findall(r"\d+", os.path.basename(path))[0]) - 1
236
310
  mzs = parse_funcinf(inf_path)[func_index]
237
311
  ylabels = mzs[mzs != 0.0]
238
312
 
@@ -527,15 +601,19 @@ def parse_analog(path, requested_files=None):
527
601
  """
528
602
  datafiles = []
529
603
 
530
- if '_CHROMS.INF' not in os.listdir(path):
604
+ chroms_inf = _find_file_path(path, '_CHROMS.INF')
605
+ if chroms_inf is None:
531
606
  return datafiles
532
607
 
533
- analog_info = parse_chroinf(os.path.join(path, '_CHROMS.INF'))
608
+ analog_info = parse_chroinf(chroms_inf)
534
609
  for i in range(len(analog_info)):
535
610
  fn = f"_CHRO{i + 1:0>3}.DAT"
611
+ actual_fn = _find_file(path, fn)
612
+ if actual_fn is None:
613
+ continue
536
614
  if requested_files and fn.lower() not in requested_files:
537
615
  continue
538
- datafile = parse_chrodat(os.path.join(path, fn), *analog_info[i])
616
+ datafile = parse_chrodat(os.path.join(path, actual_fn), *analog_info[i])
539
617
  if datafile:
540
618
  datafiles.append(datafile)
541
619
  return datafiles
@@ -648,7 +726,11 @@ def parse_metadata(path):
648
726
  metadata = {}
649
727
  metadata['vendor'] = "Waters"
650
728
 
651
- with open(os.path.join(path, '_HEADER.TXT'), 'r') as f:
729
+ header_txt = _find_file_path(path, '_HEADER.TXT')
730
+ if header_txt is None:
731
+ return metadata
732
+
733
+ with open(header_txt, 'r') as f:
652
734
  lines = f.read().splitlines()
653
735
  for line in lines:
654
736
  if line.startswith("$$ Acquired Date"):
@@ -669,7 +751,10 @@ def parse_metadata(path):
669
751
 
670
752
 
671
753
  def parse_compound_names(path):
672
- with open(os.path.join(path, "_FUNC001.CMP"), "rb") as f:
754
+ cmp_file = _find_file_path(path, '_FUNC001.CMP')
755
+ if cmp_file is None:
756
+ cmp_file = os.path.join(path, "_FUNC001.CMP")
757
+ with open(cmp_file, "rb") as f:
673
758
  data = f.read().decode("ascii", "ignore")
674
759
  data = data[7:]
675
760
  data = data.split("\x00")
@@ -689,3 +774,25 @@ def parse_compound_names(path):
689
774
  df["measurments"] = df["compounds"] + df["index"].astype(str)
690
775
 
691
776
  return df
777
+
778
+
779
+ def parse_funcinf_q3(path):
780
+ """
781
+ Parses a Waters _FUNCTNS.INF file for Q3 transitions
782
+
783
+ This file contains mz values for the 2-byte format.
784
+
785
+ Learn more about this file format :ref:`here <funcdat2>`.
786
+
787
+ Args:
788
+ path (str): Path to the _FUNCTNS.INF file.
789
+
790
+ Returns:
791
+ 2D numpy array of mz values where the rows correspond to functions.
792
+
793
+ """
794
+ with open(path, 'rb') as f:
795
+ raw_bytes = f.read()
796
+ num_funcs = os.path.getsize(path) // 416
797
+ mzs = np.ndarray((num_funcs, 32), "<f", raw_bytes, 288, (416, 4))
798
+ return mzs
@@ -1,24 +1,26 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: rainbow-api
3
- Version: 1.0.9
3
+ Version: 1.0.11
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
7
- License: COPYING
7
+ License: COPYING.LESSER
8
8
  Project-URL: Repository, https://github.com/evanyeyeye/rainbow
9
9
  Project-URL: Documentation, https://rainbow-api.readthedocs.io
10
- Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
10
+ Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)
11
11
  Description-Content-Type: text/markdown
12
12
  License-File: COPYING
13
+ License-File: COPYING.LESSER
13
14
  Requires-Dist: numpy
14
15
  Requires-Dist: matplotlib
15
16
  Requires-Dist: lxml
16
17
  Requires-Dist: pandas
18
+ Dynamic: license-file
17
19
 
18
20
  # rainbow
19
21
  [![PyPI](https://img.shields.io/pypi/v/rainbow-api)](https://pypi.org/project/rainbow-api)
20
22
  [![Documentation Status](https://readthedocs.org/projects/rainbow-api/badge/?version=latest)](https://rainbow-api.readthedocs.io/en/latest/?badge=latest)
21
- [![PyPI - Downloads](https://img.shields.io/pypi/dm/rainbow-api)](https://pypi.org/project/rainbow-api)
23
+ [![PyPI - Downloads](https://static.pepy.tech/badge/rainbow-api)](https://pypi.org/project/rainbow-api)
22
24
 
23
25
  *rainbow* provides programmatic access to the raw data encoded in chromatography and mass spectrometry binary files. This library supports the following vendors and detectors:
24
26
 
@@ -1,4 +1,5 @@
1
1
  COPYING
2
+ COPYING.LESSER
2
3
  README.md
3
4
  pyproject.toml
4
5
  rainbow/__init__.py
@@ -45,5 +45,13 @@ class TestWaters(tests.datatester.DataTester):
45
45
  """
46
46
  self._DataTester__test_data_directory("white", "raw")
47
47
 
48
+ def test_turquoise(self):
49
+ """
50
+ Tests a Perkin-Elmer / TurboMass .raw export with
51
+ lowercase filenames and PE _extern.inf polarity format.
52
+
53
+ """
54
+ self._DataTester__test_data_directory("turquoise", "raw")
55
+
48
56
  if __name__ == '__main__':
49
57
  unittest.main()
File without changes
File without changes