pychemstation 0.6.2__tar.gz → 0.6.5__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 (57) hide show
  1. {pychemstation-0.6.2 → pychemstation-0.6.5}/PKG-INFO +1 -1
  2. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation/analysis/process_report.py +47 -12
  3. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation/control/controllers/tables/method.py +1 -1
  4. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation/control/controllers/tables/sequence.py +2 -1
  5. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation/control/controllers/tables/table.py +5 -5
  6. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation/control/hplc.py +2 -1
  7. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation/utils/macro.py +1 -0
  8. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation/utils/method_types.py +3 -3
  9. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation/utils/sequence_types.py +1 -1
  10. pychemstation-0.6.5/pychemstation/utils/tray_types.py +163 -0
  11. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation.egg-info/PKG-INFO +1 -1
  12. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation.egg-info/SOURCES.txt +3 -6
  13. {pychemstation-0.6.2 → pychemstation-0.6.5}/setup.py +1 -1
  14. {pychemstation-0.6.2 → pychemstation-0.6.5}/tests/constants.py +19 -0
  15. pychemstation-0.6.5/tests/test_nightly.py +80 -0
  16. pychemstation-0.6.5/tests/test_runs_stable.py +88 -0
  17. pychemstation-0.6.5/tests/test_stable.py +268 -0
  18. pychemstation-0.6.2/pychemstation/utils/tray_types.py +0 -56
  19. pychemstation-0.6.2/tests/test_comb.py +0 -136
  20. pychemstation-0.6.2/tests/test_comm.py +0 -65
  21. pychemstation-0.6.2/tests/test_inj.py +0 -33
  22. pychemstation-0.6.2/tests/test_method.py +0 -99
  23. pychemstation-0.6.2/tests/test_proc_rep.py +0 -27
  24. pychemstation-0.6.2/tests/test_sequence.py +0 -125
  25. {pychemstation-0.6.2 → pychemstation-0.6.5}/LICENSE +0 -0
  26. {pychemstation-0.6.2 → pychemstation-0.6.5}/README.md +0 -0
  27. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation/__init__.py +0 -0
  28. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation/analysis/__init__.py +0 -0
  29. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation/analysis/base_spectrum.py +0 -0
  30. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation/analysis/spec_utils.py +0 -0
  31. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation/analysis/utils.py +0 -0
  32. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation/control/__init__.py +0 -0
  33. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation/control/controllers/__init__.py +0 -0
  34. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation/control/controllers/comm.py +0 -0
  35. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation/control/controllers/devices/__init__.py +0 -0
  36. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation/control/controllers/devices/column.py +0 -0
  37. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation/control/controllers/devices/dad.py +0 -0
  38. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation/control/controllers/devices/device.py +0 -0
  39. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation/control/controllers/devices/injector.py +0 -0
  40. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation/control/controllers/devices/pump.py +0 -0
  41. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation/control/controllers/tables/__init__.py +0 -0
  42. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation/control/controllers/tables/ms.py +0 -0
  43. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation/generated/__init__.py +0 -0
  44. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation/generated/dad_method.py +0 -0
  45. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation/generated/pump_method.py +0 -0
  46. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation/utils/__init__.py +0 -0
  47. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation/utils/chromatogram.py +0 -0
  48. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation/utils/injector_types.py +0 -0
  49. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation/utils/parsing.py +0 -0
  50. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation/utils/pump_types.py +0 -0
  51. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation/utils/table_types.py +0 -0
  52. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation.egg-info/dependency_links.txt +0 -0
  53. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation.egg-info/requires.txt +0 -0
  54. {pychemstation-0.6.2 → pychemstation-0.6.5}/pychemstation.egg-info/top_level.txt +0 -0
  55. {pychemstation-0.6.2 → pychemstation-0.6.5}/pyproject.toml +0 -0
  56. {pychemstation-0.6.2 → pychemstation-0.6.5}/setup.cfg +0 -0
  57. {pychemstation-0.6.2 → pychemstation-0.6.5}/tests/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pychemstation
3
- Version: 0.6.2
3
+ Version: 0.6.5
4
4
  Summary: Library to interact with Chemstation software, primarily used in Hein lab
5
5
  Home-page: https://gitlab.com/heingroup/device-api/pychemstation
6
6
  Author: Lucy Hao
@@ -1,18 +1,15 @@
1
- """
2
- pip install pandas
3
- pip install aghplctools==4.8.6
4
- """
5
-
6
1
  import os
7
2
  import re
8
3
  from dataclasses import dataclass
9
- from typing import List, AnyStr
4
+ from typing import List, AnyStr, Dict
10
5
 
11
6
  import pandas as pd
12
7
  from aghplctools.ingestion.text import _no_peaks_re, _area_report_re, _header_block_re, _signal_info_re, \
13
8
  _signal_table_re, chunk_string
14
9
  from result import Result, Err, Ok
15
10
 
11
+ from pychemstation.utils.tray_types import Tray, FiftyFourVialPlate
12
+
16
13
 
17
14
  @dataclass
18
15
  class AgilentPeak:
@@ -25,6 +22,13 @@ class AgilentPeak:
25
22
  height_percent: float
26
23
 
27
24
 
25
+ @dataclass
26
+ class AgilentReport:
27
+ vial_location: Tray
28
+ signals: Dict[AnyStr, List[AgilentPeak]]
29
+ solvents: Dict[AnyStr, AnyStr]
30
+
31
+
28
32
  _column_re_dictionary = { # regex matches for column and unit combinations
29
33
  'Peak': { # peak index
30
34
  '#': '[ ]+(?P<Peak>[\d]+)', # number
@@ -51,7 +55,7 @@ _column_re_dictionary = { # regex matches for column and unit combinations
51
55
  }
52
56
 
53
57
 
54
- def build_peak_regex(signal_table: str):
58
+ def build_peak_regex(signal_table: str) -> re.Pattern[AnyStr]:
55
59
  """
56
60
  Builds a peak regex from a signal table
57
61
 
@@ -211,9 +215,40 @@ def process_folder(folder_path, target_wavelengths=None, min_retention_time=0, m
211
215
  return results_df
212
216
 
213
217
 
214
- def process_csv_report(folder_path: str, num: int) -> Result[List[AgilentPeak], AnyStr]:
215
- potential_report = os.path.join(folder_path, f'REPORT0{num}.CSV')
216
- if os.path.exists(potential_report):
217
- df = pd.read_csv(potential_report, encoding="utf-16", header=None)
218
- return Ok(df.apply(lambda row: AgilentPeak(*row), axis=1))
218
+ def process_csv_report(folder_path: str) -> Result[AgilentReport, AnyStr]:
219
+ labels = os.path.join(folder_path, f'REPORT00.CSV')
220
+ if os.path.exists(labels):
221
+ df_labels: Dict[int, Dict[int: AnyStr]] = pd.read_csv(labels, encoding="utf-16", header=None).to_dict()
222
+ vial_location = []
223
+ signals = {}
224
+ solvents = {}
225
+ for pos, val in df_labels[0].items():
226
+ if val == "Location":
227
+ vial_location = df_labels[1][pos]
228
+ elif "Solvent" in val:
229
+ if val not in solvents.keys():
230
+ solvents[val] = df_labels[2][pos]
231
+ elif val == "Number of Signals":
232
+ num_signals = int(df_labels[1][pos])
233
+ for s in range(1, num_signals + 1):
234
+ peaks = process_peaks(os.path.join(folder_path, f'REPORT0{s}.CSV'))
235
+ if peaks.is_ok():
236
+ wavelength = df_labels[1][pos + s].partition(",4 Ref=off")[0][-3:]
237
+ signals[wavelength] = peaks.ok_value
238
+ break
239
+
240
+ return Ok(AgilentReport(
241
+ signals=signals,
242
+ vial_location=FiftyFourVialPlate.from_int(vial_location),
243
+ solvents=solvents
244
+ ))
245
+
219
246
  return Err("No report found")
247
+
248
+
249
+ def process_peaks(folder_path: str) -> Result[List[AgilentPeak], AnyStr]:
250
+ try:
251
+ df = pd.read_csv(folder_path, encoding="utf-16", header=None)
252
+ return Ok(df.apply(lambda row: AgilentPeak(*row), axis=1))
253
+ except Exception:
254
+ return Err("Trouble reading report")
@@ -132,7 +132,7 @@ class MethodController(TableController):
132
132
  :raise IndexError: Response did not have expected format. Try again.
133
133
  :raise AssertionError: The desired method is not selected. Try again.
134
134
  """
135
- self.send(Command.SWITCH_METHOD_CMD.value.format(method_dir=self.src,
135
+ self.send(Command.SWITCH_METHOD_CMD_SPECIFIC.value.format(method_dir=self.src,
136
136
  method_name=method_name))
137
137
 
138
138
  time.sleep(2)
@@ -41,8 +41,9 @@ class SequenceController(TableController):
41
41
  inj_vol = int(self.get_text(row, RegisterFlag.INJ_VOL))
42
42
  inj_source = InjectionSource(self.get_text(row, RegisterFlag.INJ_SOR))
43
43
  sample_type = SampleType(self.get_num(row, RegisterFlag.SAMPLE_TYPE))
44
+ vial_enum = TenVialColumn(vial_location) if vial_location <= 10 else FiftyFourVialPlate.from_int(num=vial_location)
44
45
  return SequenceEntry(sample_name=sample_name,
45
- vial_location=vial_location,
46
+ vial_location=vial_enum,
46
47
  method=None if len(method) == 0 else method,
47
48
  num_inj=num_inj,
48
49
  inj_vol=inj_vol,
@@ -8,7 +8,7 @@ import abc
8
8
  import os
9
9
  import warnings
10
10
  from dataclasses import dataclass
11
- from typing import Union, Optional
11
+ from typing import Union, Optional, AnyStr
12
12
 
13
13
  import numpy as np
14
14
  import polling
@@ -48,13 +48,13 @@ class TableController(abc.ABC):
48
48
 
49
49
  if src and os.path.isdir(src):
50
50
  self.src: str = src
51
- else:
52
- warnings.warn(f"dir: {src} not found.")
51
+ elif isinstance(src, str):
52
+ raise FileNotFoundError(f"dir: {src} not found.")
53
53
 
54
54
  if data_dir and os.path.isdir(data_dir):
55
55
  self.data_dir: str = data_dir
56
- else:
57
- warnings.warn(f"dir: {data_dir} not found.")
56
+ elif isinstance(data_dir, str):
57
+ raise FileNotFoundError(f"dir: {data_dir} not found.")
58
58
 
59
59
  if hasattr(self, "data_dir"):
60
60
  self.spectra: dict[str, Optional[AgilentHPLCChromatogram]] = {
@@ -43,6 +43,7 @@ class HPLCController:
43
43
  data_dir: str,
44
44
  method_dir: str,
45
45
  sequence_dir: str,
46
+ secondary_data_dir: Optional[str] = None,
46
47
  offline: bool = False):
47
48
  """Initialize HPLC controller. The `hplc_talk.mac` macro file must be loaded in the Chemstation software.
48
49
  `comm_dir` must match the file path in the macro file.
@@ -61,7 +62,7 @@ class HPLCController:
61
62
  offline=offline))
62
63
  self.sequence_controller = SequenceController(controller=self.comm,
63
64
  src=sequence_dir,
64
- data_dir=data_dir,
65
+ data_dir=data_dir if not secondary_data_dir else secondary_data_dir,
65
66
  table=self.SEQUENCE_TABLE,
66
67
  method_dir=method_dir,
67
68
  offline=offline)
@@ -38,6 +38,7 @@ class Command(Enum):
38
38
  GET_METHOD_CMD = "response$ = _MethFile$"
39
39
  GET_ROWS_CMD = 'response_num = TabHdrVal({register}, "{table_name}", "{col_name}")'
40
40
  SWITCH_METHOD_CMD = 'LoadMethod _MethPath$, _MethFile$'
41
+ SWITCH_METHOD_CMD_SPECIFIC = 'LoadMethod "{method_dir}", "{method_name}.M"'
41
42
  START_METHOD_CMD = "StartMethod"
42
43
  RUN_METHOD_CMD = 'RunMethod "{data_dir}",, "{experiment_name}_{timestamp}"'
43
44
  STOP_METHOD_CMD = "StopMethod"
@@ -23,7 +23,7 @@ class Param:
23
23
 
24
24
  @dataclass
25
25
  class HPLCMethodParams:
26
- organic_modifier: int
26
+ organic_modifier: float
27
27
  flow: float
28
28
  pressure: Optional[float] = None # TODO: find this
29
29
 
@@ -51,6 +51,6 @@ class MethodDetails:
51
51
  params: HPLCMethodParams
52
52
  timetable: list[TimeTableEntry]
53
53
  injector_program: Optional[InjectorTable] = None
54
- stop_time: Optional[int] = None
55
- post_time: Optional[int] = None
54
+ stop_time: Optional[float] = None
55
+ post_time: Optional[float] = None
56
56
  dad_wavelengthes: Optional[list[Signal]] = None
@@ -43,7 +43,7 @@ class SequenceEntry:
43
43
  data_file: Optional[str] = None
44
44
  method: Optional[str] = None
45
45
  num_inj: Optional[int] = 1
46
- inj_vol: Optional[int] = 2
46
+ inj_vol: Optional[float] = 2
47
47
  inj_source: Optional[InjectionSource] = InjectionSource.HIP_ALS
48
48
  sample_type: Optional[SampleType] = SampleType.SAMPLE
49
49
 
@@ -0,0 +1,163 @@
1
+ from __future__ import annotations
2
+
3
+ import math
4
+ from dataclasses import dataclass
5
+ from enum import Enum
6
+ from typing import Union
7
+
8
+
9
+ class Num(Enum):
10
+ ONE = 1
11
+ TWO = 2
12
+ THREE = 3
13
+ FOUR = 4
14
+ FIVE = 5
15
+ SIX = 6
16
+ SEVEN = 7
17
+ EIGHT = 8
18
+ NINE = 9
19
+
20
+ @classmethod
21
+ def from_num(cls, num: int) -> Num:
22
+ match num:
23
+ case 1:
24
+ return Num.ONE
25
+ case 2:
26
+ return Num.TWO
27
+ case 3:
28
+ return Num.THREE
29
+ case 4:
30
+ return Num.FOUR
31
+ case 5:
32
+ return Num.FIVE
33
+ case 6:
34
+ return Num.SIX
35
+ case 7:
36
+ return Num.SEVEN
37
+ case 8:
38
+ return Num.EIGHT
39
+ case 9:
40
+ return Num.NINE
41
+ case _:
42
+ raise ValueError("Num is one of 1 to 9")
43
+
44
+
45
+ class Plate(Enum):
46
+ ONE = -96
47
+ TWO = 4000
48
+
49
+ @classmethod
50
+ def from_num(cls, plate: int) -> Plate:
51
+ if 1 <= plate <= 2:
52
+ return Plate.ONE if plate == 1 else Plate.TWO
53
+ raise ValueError("Plate is one or 1 or 2")
54
+
55
+
56
+ class Letter(Enum):
57
+ A = 4191
58
+ B = 4255
59
+ C = 4319
60
+ D = 4383
61
+ E = 4447
62
+ F = 4511
63
+
64
+ @classmethod
65
+ def from_str(cls, let: str) -> Letter:
66
+ match let:
67
+ case "A":
68
+ return Letter.A
69
+ case "B":
70
+ return Letter.B
71
+ case "C":
72
+ return Letter.C
73
+ case "D":
74
+ return Letter.D
75
+ case "E":
76
+ return Letter.E
77
+ case "F":
78
+ return Letter.F
79
+ case _:
80
+ raise ValueError("Letter is one of A to F")
81
+
82
+
83
+ @dataclass
84
+ class FiftyFourVialPlate:
85
+ plate: Plate
86
+ letter: Letter
87
+ num: Num
88
+
89
+ def value(self) -> int:
90
+ return self.plate.value + self.letter.value + self.num.value
91
+
92
+ @classmethod
93
+ def from_str(cls, loc: str):
94
+ if len(loc) != 5:
95
+ raise ValueError("Plate locations must be PX-LY, where X is either 1 or 2 and Y is 1 to 9")
96
+ try:
97
+ plate = int(loc[1])
98
+ letter = loc[3]
99
+ num = int(loc[4])
100
+ return FiftyFourVialPlate(plate=Plate.from_num(plate),
101
+ letter=Letter.from_str(letter),
102
+ num=Num.from_num(num))
103
+ except Exception as e:
104
+ raise ValueError("Plate locations must be PX-LY, where X is either 1 or 2 and Y is 1 to 9")
105
+
106
+ @classmethod
107
+ def from_int(cls, num: int) -> FiftyFourVialPlate:
108
+ row_starts = [
109
+ # plate 1
110
+ FiftyFourVialPlate.from_str('P1-F1'),
111
+ FiftyFourVialPlate.from_str('P1-E1'),
112
+ FiftyFourVialPlate.from_str('P1-D1'),
113
+ FiftyFourVialPlate.from_str('P1-C1'),
114
+ FiftyFourVialPlate.from_str('P1-B1'),
115
+ FiftyFourVialPlate.from_str('P1-A1'),
116
+ # plate 2
117
+ FiftyFourVialPlate.from_str('P2-F1'),
118
+ FiftyFourVialPlate.from_str('P2-E1'),
119
+ FiftyFourVialPlate.from_str('P2-D1'),
120
+ FiftyFourVialPlate.from_str('P2-C1'),
121
+ FiftyFourVialPlate.from_str('P2-B1'),
122
+ FiftyFourVialPlate.from_str('P2-A1'),
123
+ ]
124
+
125
+ # find which row
126
+ possible_row = None
127
+ for i in range(0, 6):
128
+ p1_val = row_starts[i].value()
129
+ p2_val = row_starts[6 + i].value()
130
+ if num >= p2_val:
131
+ possible_row = row_starts[6 + i]
132
+ elif p1_val <= num < row_starts[-1].value():
133
+ possible_row = row_starts[i]
134
+ if possible_row:
135
+ break
136
+
137
+ # determine which num
138
+ if possible_row:
139
+ starting_loc = possible_row
140
+ base_val = starting_loc.plate.value + starting_loc.letter.value
141
+ for i in range(1, 10):
142
+ if num - i == base_val:
143
+ return FiftyFourVialPlate(
144
+ plate=starting_loc.plate,
145
+ letter=starting_loc.letter,
146
+ num=Num.from_num(i))
147
+ raise ValueError("Number didn't match any location. " + str(num))
148
+
149
+
150
+ class TenVialColumn(Enum):
151
+ ONE = 1
152
+ TWO = 2
153
+ THREE = 3
154
+ FOUR = 4
155
+ FIVE = 5
156
+ SIX = 6
157
+ SEVEN = 7
158
+ EIGHT = 8
159
+ NINE = 9
160
+ TEN = 10
161
+
162
+
163
+ Tray = Union[FiftyFourVialPlate, TenVialColumn]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pychemstation
3
- Version: 0.6.2
3
+ Version: 0.6.5
4
4
  Summary: Library to interact with Chemstation software, primarily used in Hein lab
5
5
  Home-page: https://gitlab.com/heingroup/device-api/pychemstation
6
6
  Author: Lucy Hao
@@ -43,9 +43,6 @@ pychemstation/utils/table_types.py
43
43
  pychemstation/utils/tray_types.py
44
44
  tests/__init__.py
45
45
  tests/constants.py
46
- tests/test_comb.py
47
- tests/test_comm.py
48
- tests/test_inj.py
49
- tests/test_method.py
50
- tests/test_proc_rep.py
51
- tests/test_sequence.py
46
+ tests/test_nightly.py
47
+ tests/test_runs_stable.py
48
+ tests/test_stable.py
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
5
5
 
6
6
  setuptools.setup(
7
7
  name="pychemstation",
8
- version="0.6.2",
8
+ version="0.6.5",
9
9
  author="Lucy Hao",
10
10
  author_email="lhao03@student.ubc.ca",
11
11
  description="Library to interact with Chemstation software, primarily used in Hein lab",
@@ -1,5 +1,8 @@
1
+ import os
1
2
  import random
2
3
 
4
+ from pychemstation.control import HPLCController
5
+ from pychemstation.utils.macro import Command
3
6
  from pychemstation.utils.method_types import *
4
7
  from pychemstation.utils.sequence_types import *
5
8
 
@@ -63,3 +66,19 @@ seq_entry = SequenceEntry(
63
66
  sample_name="Test",
64
67
  sample_type=SampleType(int(random.random() * 3)),
65
68
  )
69
+
70
+
71
+ def set_up_utils(num: int) -> HPLCController:
72
+ path_constants = room(num)
73
+ for path in path_constants:
74
+ if not os.path.exists(path):
75
+ raise FileNotFoundError(
76
+ f"{path} does not exist on your system. If you would like to run tests, please change this path.")
77
+
78
+ controller = HPLCController(comm_dir=path_constants[0],
79
+ method_dir=path_constants[1],
80
+ data_dir=path_constants[2],
81
+ sequence_dir=path_constants[3])
82
+ controller.send(Command.SAVE_METHOD_CMD.value.format(commit_msg="method saved by pychemstation"))
83
+ controller.send(Command.SAVE_SEQUENCE_CMD)
84
+ return controller
@@ -0,0 +1,80 @@
1
+ import unittest
2
+
3
+ from pluggy import Result
4
+
5
+ from pychemstation.analysis.process_report import process_csv_report
6
+ from pychemstation.utils.tray_types import FiftyFourVialPlate, Letter, Plate, Num
7
+ from tests.constants import *
8
+
9
+ offline = True
10
+
11
+
12
+ class TestNightly(unittest.TestCase):
13
+ def setUp(self):
14
+ path_constants = room(254)
15
+ for path in path_constants:
16
+ if not offline and not os.path.exists(path):
17
+ self.fail(
18
+ f"{path} does not exist on your system. If you would like to run tests, please change this path.")
19
+
20
+ self.hplc_controller = HPLCController(offline=offline,
21
+ comm_dir=path_constants[0],
22
+ method_dir=path_constants[1],
23
+ data_dir=path_constants[2],
24
+ sequence_dir=path_constants[3])
25
+ if not offline:
26
+ self.hplc_controller.switch_method(DEFAULT_METHOD)
27
+
28
+ def test_load_inj(self):
29
+ try:
30
+ inj_table = self.hplc_controller.load_injector_program()
31
+ self.assertTrue(len(inj_table.functions) == 2)
32
+ except Exception as e:
33
+ self.fail(f"Should have not failed, {e}")
34
+
35
+ def test_plate_number(self):
36
+ self.assertEqual(4096, FiftyFourVialPlate(plate=Plate.ONE, letter=Letter.A, num=Num.FOUR).value())
37
+
38
+ def test_build_peak_regex(self):
39
+ try:
40
+ # TODO
41
+ print('yes')
42
+ except Exception as e:
43
+ self.fail(f"Should have not failed, {e}")
44
+
45
+ def test_parse_area_report(self):
46
+ try:
47
+ # TODO
48
+ print('yes')
49
+ except Exception as e:
50
+ self.fail(f"Should have not failed, {e}")
51
+
52
+ def test_process_export_report(self):
53
+ try:
54
+ import pandas as pd
55
+
56
+ file_path = "/Users/lucyhao/Codes/pychemstation/tests/0_2025-03-15 19-14-35.D/Report00.CSV"
57
+ df = pd.read_csv(file_path, encoding="utf-16")
58
+
59
+ # Print the first column
60
+ print(df)
61
+ except Exception as e:
62
+ self.fail(f"Should have not failed, {e}")
63
+
64
+ def test_process_folder(self):
65
+ try:
66
+ # TODO
67
+ print('yes')
68
+ except Exception as e:
69
+ self.fail(f"Should have not failed, {e}")
70
+
71
+ def test_report_csv(self):
72
+ try:
73
+ report: Result = process_csv_report(folder_path="0_2025-03-15 19-14-35.D")
74
+ print(report)
75
+ except Exception as e:
76
+ self.fail(f"Should have not failed: {e}")
77
+
78
+
79
+ if __name__ == '__main__':
80
+ unittest.main()
@@ -0,0 +1,88 @@
1
+
2
+ import unittest
3
+
4
+ from pychemstation.utils.tray_types import FiftyFourVialPlate, Plate, Letter, Num
5
+ from tests.constants import *
6
+
7
+ run_too = True
8
+
9
+
10
+ class TestRunsStable(unittest.TestCase):
11
+ def setUp(self):
12
+ self.hplc_controller = set_up_utils(254)
13
+
14
+ def test_run_method(self):
15
+ try:
16
+ self.hplc_controller.run_method(experiment_name="test_experiment")
17
+ chrom = self.hplc_controller.get_last_run_method_data()
18
+ except Exception as e:
19
+ self.fail(f"Should have not failed: {e}")
20
+
21
+ def test_run_10_times(self):
22
+ self.hplc_controller.method_controller.switch(DEFAULT_METHOD)
23
+ rand_method = MethodDetails(
24
+ name=DEFAULT_METHOD,
25
+ params=HPLCMethodParams(
26
+ organic_modifier=5,
27
+ flow=0.65),
28
+ timetable=[TimeTableEntry(
29
+ start_time=0.50,
30
+ organic_modifer=99,
31
+ flow=0.65)],
32
+ stop_time=1,
33
+ post_time=0)
34
+ self.hplc_controller.edit_method(rand_method, save=True)
35
+ try:
36
+ for _ in range(10):
37
+ self.hplc_controller.run_method(experiment_name="limiting_testing")
38
+ except Exception as e:
39
+ self.fail(f"Should have not failed: {e}")
40
+
41
+ def test_update_method_update_seq_table_run(self):
42
+ try:
43
+ loc = FiftyFourVialPlate(plate=Plate.ONE, letter=Letter.F, num=Num.TWO)
44
+ self.hplc_controller.switch_sequence(sequence_name=DEFAULT_SEQUENCE)
45
+ seq_table = SequenceTable(
46
+ name=DEFAULT_SEQUENCE,
47
+ rows=[SequenceEntry(
48
+ vial_location=loc,
49
+ sample_name="run seq with new method",
50
+ method=DEFAULT_METHOD,
51
+ inj_source=InjectionSource.HIP_ALS,
52
+ inj_vol=0.5,
53
+ num_inj=1,
54
+ sample_type=SampleType.SAMPLE
55
+ )])
56
+ self.hplc_controller.edit_sequence(seq_table) # bug didnt delete all the rows, left an extra
57
+
58
+ self.hplc_controller.method_controller.switch(DEFAULT_METHOD)
59
+ rand_method = MethodDetails(
60
+ name=DEFAULT_METHOD,
61
+ params=HPLCMethodParams(
62
+ organic_modifier=5,
63
+ flow=0.65),
64
+ timetable=[TimeTableEntry(
65
+ start_time=random.randint(1, 3) + 0.50,
66
+ organic_modifer=100,
67
+ flow=0.65)],
68
+ stop_time=random.randint(4, 6),
69
+ post_time=1)
70
+ self.hplc_controller.edit_method(rand_method, save=True)
71
+ if run_too:
72
+ self.hplc_controller.preprun()
73
+ self.hplc_controller.run_sequence()
74
+ chrom = self.hplc_controller.get_last_run_sequence_data()
75
+ # report = process_csv_report(self.hplc_controller.sequence_controller.data_files[-1].child_dirs[-1])
76
+ # self.assertEqual(loc, report.ok_value.vial_location)
77
+ except Exception:
78
+ self.fail("Failed")
79
+
80
+ def test_run_sequence(self):
81
+ try:
82
+ self.hplc_controller.switch_sequence(sequence_name=DEFAULT_SEQUENCE)
83
+ self.hplc_controller.preprun()
84
+ self.hplc_controller.run_sequence()
85
+ chrom = self.hplc_controller.get_last_run_sequence_data()
86
+ self.assertTrue(len(chrom) == 1)
87
+ except Exception:
88
+ self.fail("Failed")