pychemstation 0.5.2__py3-none-any.whl → 0.5.3.dev1__py3-none-any.whl
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.
- pychemstation/analysis/base_spectrum.py +509 -509
- pychemstation/analysis/spec_utils.py +304 -304
- pychemstation/control/comm.py +51 -24
- pychemstation/control/hplc.py +45 -19
- pychemstation/control/table/method.py +77 -61
- pychemstation/control/table/sequence.py +114 -67
- pychemstation/control/table/table_controller.py +72 -35
- pychemstation/utils/macro.py +11 -1
- pychemstation/utils/method_types.py +1 -2
- pychemstation/utils/sequence_types.py +12 -8
- pychemstation/utils/table_types.py +7 -4
- pychemstation/utils/tray_types.py +14 -0
- {pychemstation-0.5.2.dist-info → pychemstation-0.5.3.dev1.dist-info}/METADATA +1 -1
- pychemstation-0.5.3.dev1.dist-info/RECORD +34 -0
- tests/constants.py +58 -5
- tests/test_comb.py +129 -0
- tests/test_comm.py +21 -9
- tests/test_method.py +26 -29
- tests/test_sequence.py +51 -75
- .DS_Store +0 -0
- pychemstation/control/chromatogram.py +0 -128
- pychemstation/control/method.py +0 -232
- pychemstation/control/sequence.py +0 -140
- pychemstation/control/table_controller.py +0 -75
- pychemstation/utils/chemstation.py +0 -290
- pychemstation/utils/constants.py +0 -15
- pychemstation/utils/hplc_param_types.py +0 -185
- pychemstation-0.5.2.dist-info/RECORD +0 -40
- {pychemstation-0.5.2.dist-info → pychemstation-0.5.3.dev1.dist-info}/LICENSE +0 -0
- {pychemstation-0.5.2.dist-info → pychemstation-0.5.3.dev1.dist-info}/WHEEL +0 -0
- {pychemstation-0.5.2.dist-info → pychemstation-0.5.3.dev1.dist-info}/top_level.txt +0 -0
tests/constants.py
CHANGED
@@ -1,12 +1,65 @@
|
|
1
|
+
import random
|
2
|
+
|
3
|
+
from pychemstation.utils.method_types import *
|
4
|
+
from pychemstation.utils.sequence_types import *
|
5
|
+
|
6
|
+
DEFAULT_METHOD = "GENERAL-POROSHELL-OPT"
|
7
|
+
DEFAULT_SEQUENCE = "hplc_testing"
|
1
8
|
|
2
9
|
# CONSTANTS: paths only work in Hein group HPLC machine in room 242
|
3
10
|
DEFAULT_COMMAND_PATH = "C:\\Users\\User\\Desktop\\Lucy\\"
|
4
|
-
DEFAULT_METHOD = "GENERAL-POROSHELL-OPT"
|
5
|
-
DEFAULT_TESTING_METHOD = "GENERAL-POROSHELL-MIN"
|
6
11
|
DEFAULT_METHOD_DIR = "C:\\ChemStation\\1\\Methods\\"
|
7
12
|
DATA_DIR = "C:\\Users\\Public\\Documents\\ChemStation\\3\\Data"
|
8
13
|
SEQUENCE_DIR = "C:\\USERS\\PUBLIC\\DOCUMENTS\\CHEMSTATION\\3\\Sequence"
|
9
|
-
DEFAULT_SEQUENCE = "hplc_testing"
|
10
|
-
METHOD_EXAMPLE = "/Users/lucyhao/Codes/heinanalyticalcontrol/tests/methods/General-Poroshell.M"
|
11
14
|
|
12
|
-
HEIN_LAB_CONSTANTS = [DEFAULT_COMMAND_PATH,
|
15
|
+
HEIN_LAB_CONSTANTS = [DEFAULT_COMMAND_PATH,
|
16
|
+
DEFAULT_METHOD_DIR,
|
17
|
+
DATA_DIR,
|
18
|
+
SEQUENCE_DIR]
|
19
|
+
|
20
|
+
# these CONSTANTS work in rm 254
|
21
|
+
DEFAULT_COMMAND_PATH_254 = "D:\\\git_repositories\\\hplc_comm\\"
|
22
|
+
DEFAULT_METHOD_DIR_254 = "D:\\Chemstation\\1\\Methods\\"
|
23
|
+
DATA_DIR_254 = "D:\\Chemstation\\1\\Data"
|
24
|
+
SEQUENCE_DIR_254 = "C:\\1\\Sequence"
|
25
|
+
|
26
|
+
HEIN_LAB_CONSTANTS_254 = [DEFAULT_COMMAND_PATH_254,
|
27
|
+
DEFAULT_METHOD_DIR_254,
|
28
|
+
DATA_DIR_254,
|
29
|
+
SEQUENCE_DIR_254]
|
30
|
+
|
31
|
+
|
32
|
+
def room(num: int):
|
33
|
+
if num == 242:
|
34
|
+
return HEIN_LAB_CONSTANTS
|
35
|
+
elif num == 254:
|
36
|
+
return HEIN_LAB_CONSTANTS_254
|
37
|
+
|
38
|
+
|
39
|
+
def gen_rand_method():
|
40
|
+
org_modifier = int(random.random() * 10)
|
41
|
+
max_run_time = int(random.random() * 10)
|
42
|
+
return MethodTimetable(
|
43
|
+
first_row=HPLCMethodParams(
|
44
|
+
organic_modifier=org_modifier,
|
45
|
+
flow=random.random(),
|
46
|
+
maximum_run_time=max_run_time),
|
47
|
+
subsequent_rows=[
|
48
|
+
TimeTableEntry(
|
49
|
+
start_time=0.10,
|
50
|
+
organic_modifer=org_modifier,
|
51
|
+
flow=0.34),
|
52
|
+
TimeTableEntry(
|
53
|
+
start_time=1,
|
54
|
+
organic_modifer=100 - int(random.random() * 10),
|
55
|
+
flow=0.55)])
|
56
|
+
|
57
|
+
|
58
|
+
seq_entry = SequenceEntry(
|
59
|
+
vial_location=TenColumn.ONE,
|
60
|
+
method=DEFAULT_METHOD,
|
61
|
+
num_inj=int(random.random() * 10),
|
62
|
+
inj_vol=int(random.random() * 10),
|
63
|
+
sample_name="Test",
|
64
|
+
sample_type=SampleType(int(random.random() * 3)),
|
65
|
+
)
|
tests/test_comb.py
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
import os
|
2
|
+
|
3
|
+
import unittest
|
4
|
+
|
5
|
+
from pychemstation.control import HPLCController
|
6
|
+
from tests.constants import *
|
7
|
+
|
8
|
+
run_too = False
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
class TestCombinations(unittest.TestCase):
|
14
|
+
def setUp(self):
|
15
|
+
path_constants = room(254)
|
16
|
+
for path in path_constants:
|
17
|
+
if not os.path.exists(path):
|
18
|
+
self.fail(
|
19
|
+
f"{path} does not exist on your system. If you would like to run tests, please change this path.")
|
20
|
+
|
21
|
+
self.hplc_controller = HPLCController(comm_dir=path_constants[0],
|
22
|
+
method_dir=path_constants[1],
|
23
|
+
data_dir=path_constants[2],
|
24
|
+
sequence_dir=path_constants[3])
|
25
|
+
|
26
|
+
def test_run_method_after_update(self):
|
27
|
+
self.hplc_controller.method_controller.switch(DEFAULT_METHOD)
|
28
|
+
|
29
|
+
try:
|
30
|
+
rand_method = gen_rand_method()
|
31
|
+
self.hplc_controller.edit_method(rand_method)
|
32
|
+
if run_too:
|
33
|
+
self.hplc_controller.run_method(experiment_name="changed_method")
|
34
|
+
except Exception as e:
|
35
|
+
self.fail(f"Should have not failed: {e}")
|
36
|
+
|
37
|
+
def test_run_after_table_edit(self):
|
38
|
+
try:
|
39
|
+
self.hplc_controller.switch_sequence(sequence_name=DEFAULT_SEQUENCE)
|
40
|
+
seq_table = self.hplc_controller.load_sequence()
|
41
|
+
seq_table.rows[0].vial_location = TenColumn.FIVE
|
42
|
+
seq_table.rows[1].vial_location = TenColumn.ONE
|
43
|
+
seq_table.rows[0].inj_source = InjectionSource.HIP_ALS
|
44
|
+
seq_table.rows[1].inj_source = InjectionSource.MANUAL
|
45
|
+
self.hplc_controller.edit_sequence(seq_table)
|
46
|
+
if run_too:
|
47
|
+
self.hplc_controller.run_sequence(seq_table)
|
48
|
+
chrom = self.hplc_controller.get_last_run_sequence_data()
|
49
|
+
self.assertTrue(len(chrom) == 2)
|
50
|
+
except Exception as e:
|
51
|
+
self.fail("Failed")
|
52
|
+
|
53
|
+
def test_run_after_existing_row_edit(self):
|
54
|
+
try:
|
55
|
+
self.hplc_controller.switch_sequence(sequence_name=DEFAULT_SEQUENCE)
|
56
|
+
seq_table = self.hplc_controller.load_sequence()
|
57
|
+
self.hplc_controller.edit_sequence_row(seq_entry, 1)
|
58
|
+
if run_too:
|
59
|
+
self.hplc_controller.run_sequence(seq_table)
|
60
|
+
chrom = self.hplc_controller.get_last_run_sequence_data()
|
61
|
+
self.assertTrue(len(chrom) == 2)
|
62
|
+
except Exception:
|
63
|
+
self.fail("Failed")
|
64
|
+
|
65
|
+
def test_update_method_update_seq_table_run(self):
|
66
|
+
try:
|
67
|
+
self.hplc_controller.method_controller.switch(DEFAULT_METHOD)
|
68
|
+
rand_method = gen_rand_method()
|
69
|
+
self.hplc_controller.edit_method(rand_method, save=True)
|
70
|
+
|
71
|
+
self.hplc_controller.switch_sequence(sequence_name=DEFAULT_SEQUENCE)
|
72
|
+
seq_table = self.hplc_controller.load_sequence()
|
73
|
+
seq_table.rows[0].vial_location = TenColumn.ONE
|
74
|
+
seq_table.rows[0].inj_source = InjectionSource.HIP_ALS
|
75
|
+
seq_table.rows[1].vial_location = TenColumn.TWO
|
76
|
+
seq_table.rows[1].inj_source = InjectionSource.HIP_ALS
|
77
|
+
self.hplc_controller.edit_sequence(seq_table)
|
78
|
+
|
79
|
+
if run_too:
|
80
|
+
self.hplc_controller.run_sequence(seq_table)
|
81
|
+
chrom = self.hplc_controller.get_last_run_sequence_data()
|
82
|
+
self.assertTrue(len(chrom) == 2)
|
83
|
+
except Exception:
|
84
|
+
self.fail("Failed")
|
85
|
+
|
86
|
+
def test_update_table_then_row(self):
|
87
|
+
try:
|
88
|
+
self.hplc_controller.method_controller.switch(DEFAULT_METHOD)
|
89
|
+
self.hplc_controller.switch_sequence(sequence_name=DEFAULT_SEQUENCE)
|
90
|
+
rand_method = gen_rand_method()
|
91
|
+
self.hplc_controller.edit_method(rand_method, save=True)
|
92
|
+
|
93
|
+
seq_table = self.hplc_controller.load_sequence()
|
94
|
+
seq_table.rows[0].vial_location = TenColumn.ONE
|
95
|
+
seq_table.rows[0].inj_source = InjectionSource.HIP_ALS
|
96
|
+
seq_table.rows[0].method = DEFAULT_METHOD
|
97
|
+
seq_table.rows[1].vial_location = TenColumn.TWO
|
98
|
+
seq_table.rows[1].inj_source = InjectionSource.HIP_ALS
|
99
|
+
seq_table.rows[1].method = DEFAULT_METHOD
|
100
|
+
|
101
|
+
self.hplc_controller.edit_sequence(seq_table)
|
102
|
+
self.hplc_controller.edit_sequence_row(
|
103
|
+
SequenceEntry(
|
104
|
+
vial_location=TenColumn.ONE,
|
105
|
+
method=DEFAULT_METHOD,
|
106
|
+
num_inj=3,
|
107
|
+
inj_vol=4,
|
108
|
+
sample_name="Blank",
|
109
|
+
sample_type=SampleType.BLANK,
|
110
|
+
)
|
111
|
+
)
|
112
|
+
if run_too:
|
113
|
+
self.hplc_controller.run_sequence(seq_table)
|
114
|
+
chrom = self.hplc_controller.get_last_run_sequence_data()
|
115
|
+
self.assertTrue(len(chrom) == 2)
|
116
|
+
except Exception:
|
117
|
+
self.fail("Failed")
|
118
|
+
|
119
|
+
def test_run_after_new_row_edit(self):
|
120
|
+
try:
|
121
|
+
self.hplc_controller.switch_sequence(sequence_name=DEFAULT_SEQUENCE)
|
122
|
+
seq_table = self.hplc_controller.load_sequence()
|
123
|
+
self.hplc_controller.edit_sequence_row(seq_entry, 3)
|
124
|
+
if run_too:
|
125
|
+
self.hplc_controller.run_sequence(seq_table)
|
126
|
+
chrom = self.hplc_controller.get_last_run_sequence_data()
|
127
|
+
self.assertTrue(len(chrom) == 2)
|
128
|
+
except Exception:
|
129
|
+
self.fail("Failed")
|
tests/test_comm.py
CHANGED
@@ -10,24 +10,25 @@ from tests.constants import *
|
|
10
10
|
class TestComm(unittest.TestCase):
|
11
11
|
|
12
12
|
def setUp(self):
|
13
|
-
|
13
|
+
path_constants = room(254)
|
14
|
+
for path in path_constants:
|
14
15
|
if not os.path.exists(path):
|
15
16
|
self.fail(
|
16
17
|
f"{path} does not exist on your system. If you would like to run tests, please change this path.")
|
17
18
|
|
18
|
-
self.hplc_controller = HPLCController(
|
19
|
-
|
20
|
-
|
21
|
-
sequence_dir=
|
19
|
+
self.hplc_controller = HPLCController(comm_dir=path_constants[0],
|
20
|
+
method_dir=path_constants[1],
|
21
|
+
data_dir=path_constants[2],
|
22
|
+
sequence_dir=path_constants[3])
|
22
23
|
|
23
24
|
def test_status_check_standby(self):
|
24
25
|
self.hplc_controller.standby()
|
25
|
-
self.assertTrue(self.hplc_controller.status()
|
26
|
+
self.assertTrue(self.hplc_controller.status() in [HPLCAvailStatus.STANDBY, HPLCRunningStatus.NOTREADY])
|
26
27
|
|
27
28
|
def test_status_check_preprun(self):
|
28
29
|
self.hplc_controller.preprun()
|
29
|
-
self.assertTrue(self.hplc_controller.status()
|
30
|
-
|
30
|
+
self.assertTrue(self.hplc_controller.status() in [HPLCAvailStatus.PRERUN, HPLCAvailStatus.STANDBY,
|
31
|
+
HPLCRunningStatus.NOTREADY])
|
31
32
|
|
32
33
|
def test_send_command(self):
|
33
34
|
try:
|
@@ -39,6 +40,17 @@ class TestComm(unittest.TestCase):
|
|
39
40
|
try:
|
40
41
|
self.hplc_controller.send("Local TestNum")
|
41
42
|
self.hplc_controller.send("TestNum = 0")
|
43
|
+
self.hplc_controller.send("Print TestNum")
|
44
|
+
self.hplc_controller.send("response_num = TestNum")
|
45
|
+
self.hplc_controller.send("Print num_response")
|
46
|
+
except Exception as e:
|
47
|
+
self.fail(f"Should not throw error: {e}")
|
48
|
+
|
49
|
+
def test_get_num(self):
|
50
|
+
try:
|
51
|
+
self.hplc_controller.send("response_num = 10")
|
52
|
+
res = self.hplc_controller.receive().num_response
|
53
|
+
self.assertEqual(res, 10)
|
42
54
|
except Exception as e:
|
43
55
|
self.fail(f"Should not throw error: {e}")
|
44
56
|
|
@@ -47,7 +59,7 @@ class TestComm(unittest.TestCase):
|
|
47
59
|
self.hplc_controller.switch_method(method_name=DEFAULT_METHOD)
|
48
60
|
self.hplc_controller.send(Command.GET_METHOD_CMD)
|
49
61
|
res = self.hplc_controller.receive()
|
50
|
-
self.assertTrue(DEFAULT_METHOD in res)
|
62
|
+
self.assertTrue(DEFAULT_METHOD in res.string_response)
|
51
63
|
except Exception as e:
|
52
64
|
self.fail(f"Should not throw error: {e}")
|
53
65
|
|
tests/test_method.py
CHANGED
@@ -2,51 +2,50 @@ import os
|
|
2
2
|
import unittest
|
3
3
|
|
4
4
|
from pychemstation.control import HPLCController
|
5
|
-
from pychemstation.utils.method_types import *
|
6
5
|
from tests.constants import *
|
7
6
|
|
8
7
|
|
9
8
|
class TestMethod(unittest.TestCase):
|
10
9
|
def setUp(self):
|
11
|
-
|
10
|
+
path_constants = room(254)
|
11
|
+
for path in path_constants:
|
12
12
|
if not os.path.exists(path):
|
13
13
|
self.fail(
|
14
14
|
f"{path} does not exist on your system. If you would like to run tests, please change this path.")
|
15
15
|
|
16
|
-
self.hplc_controller = HPLCController(
|
17
|
-
|
18
|
-
|
19
|
-
sequence_dir=
|
16
|
+
self.hplc_controller = HPLCController(comm_dir=path_constants[0],
|
17
|
+
method_dir=path_constants[1],
|
18
|
+
data_dir=path_constants[2],
|
19
|
+
sequence_dir=path_constants[3])
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
def test_load_method_details(self):
|
21
|
+
def test_load_method_from_disk(self):
|
24
22
|
self.hplc_controller.switch_method(DEFAULT_METHOD)
|
25
23
|
try:
|
26
|
-
gp_mtd = self.hplc_controller.method_controller.
|
27
|
-
self.assertTrue(gp_mtd.first_row.organic_modifier
|
24
|
+
gp_mtd = self.hplc_controller.method_controller.load_from_disk(DEFAULT_METHOD)
|
25
|
+
self.assertTrue(gp_mtd.first_row.organic_modifier == 5)
|
28
26
|
except Exception as e:
|
29
27
|
self.fail(f"Should have not failed, {e}")
|
30
28
|
|
31
|
-
def
|
29
|
+
def test_edit_method(self):
|
30
|
+
self.hplc_controller.method_controller.switch(DEFAULT_METHOD)
|
31
|
+
new_method = gen_rand_method()
|
32
|
+
try:
|
33
|
+
self.hplc_controller.edit_method(new_method)
|
34
|
+
except Exception as e:
|
35
|
+
self.fail(f"Should have not failed: {e}")
|
36
|
+
|
37
|
+
def test_load_method(self):
|
32
38
|
self.hplc_controller.method_controller.switch(DEFAULT_METHOD)
|
33
|
-
new_method =
|
34
|
-
first_row=HPLCMethodParams(
|
35
|
-
organic_modifier=7,
|
36
|
-
flow=0.44,
|
37
|
-
maximum_run_time=2,
|
38
|
-
temperature=15),
|
39
|
-
subsequent_rows=[
|
40
|
-
TimeTableEntry(
|
41
|
-
start_time=0.10,
|
42
|
-
organic_modifer=7,
|
43
|
-
flow=0.34),
|
44
|
-
TimeTableEntry(
|
45
|
-
start_time=1,
|
46
|
-
organic_modifer=99,
|
47
|
-
flow=0.55)])
|
39
|
+
new_method = gen_rand_method()
|
48
40
|
try:
|
49
41
|
self.hplc_controller.edit_method(new_method)
|
42
|
+
loaded_method = self.hplc_controller.load_method()
|
43
|
+
self.assertEqual(new_method.first_row.organic_modifier,
|
44
|
+
loaded_method.first_row.organic_modifier)
|
45
|
+
self.assertEqual(new_method.subsequent_rows,
|
46
|
+
loaded_method.subsequent_rows)
|
47
|
+
self.assertEqual(new_method.first_row.flow,
|
48
|
+
loaded_method.first_row.flow)
|
50
49
|
except Exception as e:
|
51
50
|
self.fail(f"Should have not failed: {e}")
|
52
51
|
|
@@ -58,7 +57,5 @@ class TestMethod(unittest.TestCase):
|
|
58
57
|
self.fail(f"Should have not failed: {e}")
|
59
58
|
|
60
59
|
|
61
|
-
|
62
|
-
|
63
60
|
if __name__ == '__main__':
|
64
61
|
unittest.main()
|
tests/test_sequence.py
CHANGED
@@ -8,15 +8,16 @@ from tests.constants import *
|
|
8
8
|
|
9
9
|
class TestSequence(unittest.TestCase):
|
10
10
|
def setUp(self):
|
11
|
-
|
11
|
+
path_constants = room(254)
|
12
|
+
for path in path_constants:
|
12
13
|
if not os.path.exists(path):
|
13
14
|
self.fail(
|
14
15
|
f"{path} does not exist on your system. If you would like to run tests, please change this path.")
|
15
16
|
|
16
|
-
self.hplc_controller = HPLCController(
|
17
|
-
|
18
|
-
|
19
|
-
sequence_dir=
|
17
|
+
self.hplc_controller = HPLCController(comm_dir=path_constants[0],
|
18
|
+
method_dir=path_constants[1],
|
19
|
+
data_dir=path_constants[2],
|
20
|
+
sequence_dir=path_constants[3])
|
20
21
|
|
21
22
|
def test_switch(self):
|
22
23
|
try:
|
@@ -26,77 +27,52 @@ class TestSequence(unittest.TestCase):
|
|
26
27
|
|
27
28
|
def test_edit_row(self):
|
28
29
|
self.hplc_controller.switch_sequence(sequence_name=DEFAULT_SEQUENCE)
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
30
|
+
try:
|
31
|
+
self.hplc_controller.edit_sequence_row(SequenceEntry(
|
32
|
+
vial_location=TenColumn.TEN,
|
33
|
+
method=DEFAULT_METHOD,
|
34
|
+
num_inj=3,
|
35
|
+
inj_vol=4,
|
36
|
+
sample_name="Blank",
|
37
|
+
sample_type=SampleType.BLANK,
|
38
|
+
inj_source=InjectionSource.HIP_ALS
|
39
|
+
), 1)
|
40
|
+
except Exception:
|
41
|
+
self.fail("Should have not failed")
|
38
42
|
|
39
43
|
def test_edit_entire_table(self):
|
40
44
|
self.hplc_controller.switch_sequence(sequence_name=DEFAULT_SEQUENCE)
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
sample_type=SampleType.BLANK,
|
69
|
-
inj_source=InjectionSource.HIP_ALS
|
70
|
-
),
|
71
|
-
]
|
72
|
-
)
|
73
|
-
self.hplc_controller.edit_sequence(seq_table)
|
74
|
-
|
45
|
+
try:
|
46
|
+
seq_table = SequenceTable(
|
47
|
+
name=DEFAULT_SEQUENCE,
|
48
|
+
rows=[
|
49
|
+
SequenceEntry(
|
50
|
+
vial_location=TenColumn.ONE,
|
51
|
+
method=DEFAULT_METHOD,
|
52
|
+
num_inj=3,
|
53
|
+
inj_vol=4,
|
54
|
+
sample_name="Sampel1",
|
55
|
+
sample_type=SampleType.SAMPLE,
|
56
|
+
inj_source=InjectionSource.HIP_ALS
|
57
|
+
),
|
58
|
+
SequenceEntry(
|
59
|
+
vial_location=TenColumn.TWO,
|
60
|
+
method=DEFAULT_METHOD,
|
61
|
+
num_inj=3,
|
62
|
+
inj_vol=4,
|
63
|
+
sample_name="Sampel2",
|
64
|
+
sample_type=SampleType.SAMPLE,
|
65
|
+
inj_source=InjectionSource.HIP_ALS
|
66
|
+
)
|
67
|
+
]
|
68
|
+
)
|
69
|
+
self.hplc_controller.edit_sequence(seq_table)
|
70
|
+
except Exception:
|
71
|
+
self.fail("Should have not occured")
|
75
72
|
|
76
|
-
def
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
vial_location=1,
|
83
|
-
method="C:\\ChemStation\\1\\Methods\\" + DEFAULT_METHOD,
|
84
|
-
num_inj=1,
|
85
|
-
inj_vol=1,
|
86
|
-
sample_name="Test",
|
87
|
-
sample_type=SampleType.BLANK
|
88
|
-
),
|
89
|
-
SequenceEntry(
|
90
|
-
vial_location=2,
|
91
|
-
method="C:\\ChemStation\\1\\Methods\\" + DEFAULT_METHOD,
|
92
|
-
num_inj=1,
|
93
|
-
inj_vol=1,
|
94
|
-
sample_name="Test2",
|
95
|
-
sample_type=SampleType.BLANK
|
96
|
-
),
|
97
|
-
]
|
98
|
-
)
|
99
|
-
self.hplc_controller.edit_sequence(seq_table)
|
100
|
-
self.hplc_controller.run_sequence(seq_table)
|
101
|
-
chrom = self.hplc_controller.get_last_run_sequence_data()
|
102
|
-
self.assertTrue(len(chrom) == 2)
|
73
|
+
def test_load(self):
|
74
|
+
try:
|
75
|
+
seq = self.hplc_controller.load_sequence()
|
76
|
+
self.assertTrue(len(seq.rows) > 0)
|
77
|
+
except Exception as e:
|
78
|
+
self.fail(f"Should have not expected: {e}")
|
.DS_Store
DELETED
Binary file
|
@@ -1,128 +0,0 @@
|
|
1
|
-
"""Module for HPLC chromatogram data loading and manipulating"""
|
2
|
-
|
3
|
-
import os
|
4
|
-
import logging
|
5
|
-
import time
|
6
|
-
|
7
|
-
import numpy as np
|
8
|
-
|
9
|
-
from ..analysis import AbstractSpectrum
|
10
|
-
from ..utils.chemstation import CHFile
|
11
|
-
|
12
|
-
# Chemstation data path
|
13
|
-
DATA_DIR = r"C:\Chem32\1\Data"
|
14
|
-
|
15
|
-
|
16
|
-
# standard filenames for spectral data
|
17
|
-
CHANNELS = {"A": "01", "B": "02", "C": "03", "D": "04"}
|
18
|
-
|
19
|
-
ACQUISITION_PARAMETERS = "acq.txt"
|
20
|
-
|
21
|
-
# format used in acquisition parameters
|
22
|
-
TIME_FORMAT = "%Y-%m-%d-%H-%M-%S"
|
23
|
-
|
24
|
-
|
25
|
-
class AgilentHPLCChromatogram(AbstractSpectrum):
|
26
|
-
"""Class for HPLC spectrum (chromatogram) loading and handling."""
|
27
|
-
|
28
|
-
AXIS_MAPPING = {"x": "min", "y": "mAu"}
|
29
|
-
|
30
|
-
INTERNAL_PROPERTIES = {
|
31
|
-
"baseline",
|
32
|
-
"parameters",
|
33
|
-
"data_path",
|
34
|
-
}
|
35
|
-
|
36
|
-
# set of properties to be saved
|
37
|
-
PUBLIC_PROPERTIES = {
|
38
|
-
"x",
|
39
|
-
"y",
|
40
|
-
"peaks",
|
41
|
-
"timestamp",
|
42
|
-
}
|
43
|
-
|
44
|
-
def __init__(self, path=None, autosaving=False):
|
45
|
-
|
46
|
-
if path is not None:
|
47
|
-
os.makedirs(path, exist_ok=True)
|
48
|
-
self.path = path
|
49
|
-
else:
|
50
|
-
self.path = os.path.join(".", "hplc_data")
|
51
|
-
os.makedirs(self.path, exist_ok=True)
|
52
|
-
|
53
|
-
self.logger = logging.getLogger("AgilentHPLCChromatogram")
|
54
|
-
|
55
|
-
super().__init__(path=path, autosaving=autosaving)
|
56
|
-
|
57
|
-
def load_spectrum(self, data_path, channel="A"):
|
58
|
-
"""Loads the spectra from the given folder.
|
59
|
-
|
60
|
-
Args:
|
61
|
-
data_path (str): Path where HPLC data has been saved.
|
62
|
-
"""
|
63
|
-
|
64
|
-
# to avoid dropping parameters when called in parent class
|
65
|
-
if self.x is not None:
|
66
|
-
if self.autosaving:
|
67
|
-
self.save_data(filename=f"{data_path}_{channel}")
|
68
|
-
self._dump()
|
69
|
-
|
70
|
-
# get raw data
|
71
|
-
x, y = self.extract_rawdata(data_path, channel)
|
72
|
-
|
73
|
-
# get timestamp
|
74
|
-
tstr = data_path.split(".")[0].split("_")[-1]
|
75
|
-
timestamp = time.mktime(time.strptime(tstr, TIME_FORMAT))
|
76
|
-
|
77
|
-
# loading all data
|
78
|
-
super().load_spectrum(x, y, timestamp)
|
79
|
-
|
80
|
-
### PUBLIC METHODS TO LOAD RAW DATA ###
|
81
|
-
|
82
|
-
def extract_rawdata(self, experiment_dir: str, channel: str):
|
83
|
-
"""
|
84
|
-
Reads raw data from Chemstation .CH files.
|
85
|
-
|
86
|
-
Args:
|
87
|
-
experiment_dir: .D directory with the .CH files
|
88
|
-
|
89
|
-
Returns:
|
90
|
-
np.array(times), np.array(values) Raw chromatogram data
|
91
|
-
"""
|
92
|
-
filename = os.path.join(experiment_dir, f"DAD1{channel}")
|
93
|
-
npz_file = filename + ".npz"
|
94
|
-
|
95
|
-
if os.path.exists(npz_file):
|
96
|
-
# already processed
|
97
|
-
data = np.load(npz_file)
|
98
|
-
return data["times"], data["values"]
|
99
|
-
else:
|
100
|
-
self.logger.debug("NPZ file not found. First time loading data.")
|
101
|
-
ch_file = filename + ".ch"
|
102
|
-
data = CHFile(ch_file)
|
103
|
-
np.savez_compressed(npz_file, times=data.times, values=data.values)
|
104
|
-
return np.array(data.times), np.array(data.values)
|
105
|
-
|
106
|
-
def extract_peakarea(self, experiment_dir: str):
|
107
|
-
"""
|
108
|
-
Reads processed data from Chemstation report files.
|
109
|
-
|
110
|
-
Args:
|
111
|
-
experiment_dir: .D directory with the report files
|
112
|
-
"""
|
113
|
-
# filename = os.path.join(experiment_dir, f"REPORT{CHANNELS[channel]}.csv")
|
114
|
-
# TODO parse file properly
|
115
|
-
# data = np.genfromtxt(filename, delimiter=',')
|
116
|
-
# return data
|
117
|
-
pass
|
118
|
-
|
119
|
-
def default_processing(self):
|
120
|
-
"""
|
121
|
-
Processes the chromatogram in place.
|
122
|
-
"""
|
123
|
-
# trim first 5 min and last 3 min of run
|
124
|
-
self.trim(5, 25)
|
125
|
-
# parameters found to work best for chromatogram data
|
126
|
-
self.correct_baseline(lmbd=1e5, p=0.0001, n_iter=10)
|
127
|
-
# get all peaks in processed chromatogram
|
128
|
-
self.find_peaks()
|