rainbow-api 1.0.6__tar.gz → 1.0.8__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 (22) hide show
  1. {rainbow-api-1.0.6/rainbow_api.egg-info → rainbow_api-1.0.8}/PKG-INFO +1 -1
  2. {rainbow-api-1.0.6 → rainbow_api-1.0.8}/pyproject.toml +1 -1
  3. {rainbow-api-1.0.6 → rainbow_api-1.0.8}/rainbow/agilent/chemstation.py +94 -48
  4. {rainbow-api-1.0.6 → rainbow_api-1.0.8}/rainbow/waters/masslynx.py +25 -0
  5. {rainbow-api-1.0.6 → rainbow_api-1.0.8/rainbow_api.egg-info}/PKG-INFO +1 -1
  6. {rainbow-api-1.0.6 → rainbow_api-1.0.8}/COPYING +0 -0
  7. {rainbow-api-1.0.6 → rainbow_api-1.0.8}/README.md +0 -0
  8. {rainbow-api-1.0.6 → rainbow_api-1.0.8}/rainbow/__init__.py +0 -0
  9. {rainbow-api-1.0.6 → rainbow_api-1.0.8}/rainbow/agilent/__init__.py +0 -0
  10. {rainbow-api-1.0.6 → rainbow_api-1.0.8}/rainbow/agilent/masshunter.py +0 -0
  11. {rainbow-api-1.0.6 → rainbow_api-1.0.8}/rainbow/datadirectory.py +0 -0
  12. {rainbow-api-1.0.6 → rainbow_api-1.0.8}/rainbow/datafile.py +0 -0
  13. {rainbow-api-1.0.6 → rainbow_api-1.0.8}/rainbow/waters/__init__.py +0 -0
  14. {rainbow-api-1.0.6 → rainbow_api-1.0.8}/rainbow_api.egg-info/SOURCES.txt +0 -0
  15. {rainbow-api-1.0.6 → rainbow_api-1.0.8}/rainbow_api.egg-info/dependency_links.txt +0 -0
  16. {rainbow-api-1.0.6 → rainbow_api-1.0.8}/rainbow_api.egg-info/requires.txt +0 -0
  17. {rainbow-api-1.0.6 → rainbow_api-1.0.8}/rainbow_api.egg-info/top_level.txt +0 -0
  18. {rainbow-api-1.0.6 → rainbow_api-1.0.8}/setup.cfg +0 -0
  19. {rainbow-api-1.0.6 → rainbow_api-1.0.8}/tests/test_agilent.py +0 -0
  20. {rainbow-api-1.0.6 → rainbow_api-1.0.8}/tests/test_datadirectory.py +0 -0
  21. {rainbow-api-1.0.6 → rainbow_api-1.0.8}/tests/test_datafile.py +0 -0
  22. {rainbow-api-1.0.6 → rainbow_api-1.0.8}/tests/test_waters.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: rainbow-api
3
- Version: 1.0.6
3
+ Version: 1.0.8
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.0.6"
7
+ version = "1.0.8"
8
8
  description = "Read chromatography and mass spectrometry binary files"
9
9
  readme = "README.md"
10
10
  license = {text = "COPYING"}
@@ -88,14 +88,14 @@ def parse_ch(path):
88
88
  """
89
89
  with open(path, 'rb') as f:
90
90
  head = read_string(f, offset=0, gap=1)
91
- if head == '179':
92
- return parse_ch_fid(path)
93
- elif head == '130' or head == '30':
91
+ if head in ['179', '181']:
92
+ return parse_ch_fid(path, head)
93
+ elif head in ['130', '30']:
94
94
  return parse_ch_other(path, head)
95
95
  return None
96
96
 
97
97
 
98
- def parse_ch_fid(path):
98
+ def parse_ch_fid(path, head):
99
99
  """
100
100
  Parses an Agilent .ch file with FID channel data.
101
101
 
@@ -110,21 +110,43 @@ def parse_ch_fid(path):
110
110
  DataFile with FID data, if the file can be parsed. Otherwise, None.
111
111
 
112
112
  """
113
- data_offsets = {
114
- 'num_times': 0x116,
115
- 'scaling_factor': 0x127C,
116
- 'data_start': 0x1800
117
- }
113
+ if head == '181':
114
+ data_offsets = {
115
+ 'num_times': 0x116,
116
+ 'scaling_factor': 0x127C,
117
+ 'data_start': 0x1800
118
+ }
119
+ metadata_offsets = {
120
+ 'notebook': 0x35A,
121
+ 'date': 0x957,
122
+ 'method': 0xA0E,
123
+ 'instrument': 0xC11,
124
+ 'unit': 0x104C,
125
+ }
126
+ gap = 2
127
+ elif head == '179':
128
+ data_offsets = {
129
+ 'num_times': 0x116,
130
+ 'scaling_factor': 0x127C,
131
+ 'data_start': 0x1800
132
+ }
133
+ metadata_offsets = {
134
+ 'notebook': 0x35A,
135
+ 'date': 0x957,
136
+ 'method': 0xA0E,
137
+ 'instrument': 0xC11,
138
+ 'unit': 0x104C,
139
+ 'signal': 0x1075
140
+ }
118
141
 
119
142
  f = open(path, 'rb')
120
143
  raw_bytes = f.read()
144
+ file_size = f.tell()
121
145
 
122
146
  # Extract the number of retention times.
123
- f.seek(data_offsets['num_times'])
124
- num_times = struct.unpack(">I", f.read(4))[0]
125
- if num_times == 0:
126
- return None
147
+ num_times = (file_size - data_offsets['data_start']) // 8
127
148
 
149
+ f.seek(data_offsets['num_times'] + 4)
128
150
  # Compute retention times using the first and last times.
129
151
  start_time = struct.unpack(">f", f.read(4))[0]
130
152
  end_time = struct.unpack(">f", f.read(4))[0]
@@ -132,8 +154,10 @@ def parse_ch_fid(path):
132
154
  times = np.arange(start_time, end_time + 1e-3, delta_time)
133
155
 
134
156
  # Extract the raw data values.
135
- data = np.ndarray(
136
- num_times, '<d', raw_bytes, data_offsets['data_start'], 8)
157
+ if head == '181':
158
+ data = np.array(decode_double_delta(f, data_offsets['data_start']), dtype=np.float64)
159
+ else:
160
+ data = np.ndarray(num_times, '<d', raw_bytes, data_offsets['data_start'], 8)
137
161
  data = data.copy().reshape(-1, 1)
138
162
 
139
163
  # Convert times into minutes.
@@ -148,14 +172,6 @@ def parse_ch_fid(path):
148
172
  ylabels = np.array([''])
149
173
 
150
174
  # Extract metadata from file header.
151
- metadata_offsets = {
152
- 'notebook': 0x35A,
153
- 'date': 0x957,
154
- 'method': 0xA0E,
155
- 'instrument': 0xC11,
156
- 'unit': 0x104C,
157
- 'signal': 0x1075
158
- }
159
175
  metadata = read_header(f, metadata_offsets)
160
176
  f.close()
161
177
 
@@ -218,31 +234,10 @@ def parse_ch_other(path, head):
218
234
  int_unpack = struct.Struct('>i').unpack
219
235
 
220
236
  # Extract the raw data values.
221
- # Count the total number of retention times.
222
- f.seek(data_offsets['data_start'])
223
- absorbances = []
224
- absorb_accum = 0
225
- while True:
226
- # If the segment header is invalid, stop reading.
227
- head = byte_unpack(f.read(1))[0]
228
- if head != 0x10:
229
- break
230
- num_times_seg = byte_unpack(f.read(1))[0]
231
-
232
- # If the next short is equal to -0x8000
233
- # then the next absorbance value is the next integer.
234
- # Otherwise, the short is a delta from the last absorbance value.
235
- for _ in range(num_times_seg):
236
- check_int = short_unpack(f.read(2))[0]
237
- if check_int == -0x8000:
238
- absorb_accum = int_unpack(f.read(4))[0]
239
- else:
240
- absorb_accum += check_int
241
- absorbances.append(absorb_accum)
242
-
237
+ # Count the total number of retention times.
243
238
  # Process the extracted values.
244
- # If no values are extracted, this file is invalid.
245
- data = np.array(absorbances)
239
+ # If no values are extracted, this file is invalid.
240
+ data = np.array(decode_delta(f, data_offsets['data_start']))
246
241
  num_times = data.size
247
242
  if num_times == 0:
248
243
  return None
@@ -279,6 +274,57 @@ def parse_ch_other(path, head):
279
274
 
280
275
  return DataFile(path, detector, times, ylabels, data, metadata)
281
276
 
277
+ def decode_delta(f, offset):
278
+ byte_unpack = struct.Struct('>B').unpack
279
+ short_unpack = struct.Struct('>h').unpack
280
+ int_unpack = struct.Struct('>i').unpack
281
+ # Extract the raw data values.
282
+ # Count the total number of retention times.
283
+ f.seek(offset)
284
+ absorbances = []
285
+ absorb_accum = 0
286
+ while True:
287
+ # If the segment header is invalid, stop reading.
288
+ head = byte_unpack(f.read(1))[0]
289
+ if head != 0x10:
290
+ break
291
+ num_times_seg = byte_unpack(f.read(1))[0]
292
+
293
+ # If the next short is equal to -0x8000
294
+ # then the next absorbance value is the next integer.
295
+ # Otherwise, the short is a delta from the last absorbance value.
296
+ for _ in range(num_times_seg):
297
+ check_int = short_unpack(f.read(2))[0]
298
+ if check_int == -0x8000:
299
+ absorb_accum = int_unpack(f.read(4))[0]
300
+ else:
301
+ absorb_accum += check_int
302
+ absorbances.append(absorb_accum)
303
+
304
+ return absorbances
305
+
306
+ def decode_double_delta(f, offset):
307
+ byte_unpack = struct.Struct('>B').unpack
308
+ short_unpack = struct.Struct('>h').unpack
309
+ int_unpack = struct.Struct('>i').unpack
310
+ f.seek(0, 2)
311
+ file_size = f.tell()
312
+ f.seek(offset)
313
+ signals = []
314
+ count = 1
315
+ buffer = [0, 0, 0]
316
+
317
+ while f.tell() < file_size:
318
+ buffer[2] = short_unpack(f.read(2))[0]
319
+ if buffer[2] == 0x7fff:
320
+ buffer[0] = short_unpack(f.read(2))[0] << 32 | int_unpack(f.read(4))[0]
321
+ buffer[1] = 0
322
+ else:
323
+ buffer[1] += buffer[2]
324
+ buffer[0] += buffer[1]
325
+ signals.append(buffer[0])
326
+
327
+ return signals
282
328
 
283
329
  """
284
330
  .uv PARSING METHODS
@@ -559,7 +605,7 @@ def parse_ms(path, prec=0):
559
605
  num_times = int_unpack(f.read(4))[0]
560
606
  else:
561
607
  f.seek(data_offsets['gc_num_times'])
562
- num_times = struct.unpack('<I', f.read(4))[0]
608
+ num_times = struct.unpack('<H', f.read(2))[0]
563
609
 
564
610
  # Go to the data start offset.
565
611
  f.seek(data_offsets['data_start'])
@@ -6,6 +6,7 @@ import os
6
6
  import re
7
7
  import numpy as np
8
8
  from rainbow.datafile import DataFile
9
+ import pandas as pd
9
10
 
10
11
  """
11
12
  SPECTRUM PARSING METHODS
@@ -664,3 +665,27 @@ def parse_metadata(path):
664
665
  if not value.isspace():
665
666
  metadata['vialpos'] = value
666
667
  return metadata
668
+
669
+
670
+
671
+ def parse_compound_names(path):
672
+ with open(os.path.join(path, "_FUNC001.CMP"), "rb") as f:
673
+ data = f.read().decode("ascii", "ignore")
674
+ data = data[7:]
675
+ data = data.split("\x00")
676
+ data = list(filter(lambda x: x != "", data))
677
+ # loop through the da{}ta and remove the byte sequences x18
678
+ data = [re.sub(r'\x18', '', x) for x in data]
679
+ data
680
+
681
+ compounds = []
682
+ transition = []
683
+ for i in range(0, len(data), 3):
684
+ compounds.append(data[i])
685
+ transition.append(data[i+1])
686
+ df = pd.DataFrame({"compounds": compounds, "transition": transition})
687
+
688
+ df["index"] = [i for i in range(1, len(transition)+1)]
689
+ df["measurments"] = df["compounds"] + df["index"].astype(str)
690
+
691
+ return df
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: rainbow-api
3
- Version: 1.0.6
3
+ Version: 1.0.8
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