-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflow_cytometry_test.py
148 lines (114 loc) · 4.78 KB
/
flow_cytometry_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import importlib
import pytest
import json
from autoprotocol.harness import get_protocol_preview
from autoprotocol import Protocol, Container, Well, WellGroup
@pytest.fixture(scope="module")
def preview():
protocol = Protocol()
preview = get_protocol_preview(protocol, "FlowCytometry", "manifest.json")
return preview
@pytest.fixture(scope='session')
def flow_cytometry():
loader = importlib.machinery.SourceFileLoader(
'flow_cytometry', 'flow_cytometry.py')
spec = importlib.util.spec_from_loader(loader.name, loader)
flow_cytometry = importlib.util.module_from_spec(spec)
loader.exec_module(flow_cytometry)
return flow_cytometry
def test_preview(preview, flow_cytometry):
protocol = Protocol()
ref = Protocol().ref(name="src_plate", cont_type="96-flat", discard=True)
for well in ref.wells_from(0, 8):
well.set_volume("100:microliter")
preview["samples"]["well"] = list(ref.wells_from(1, 7))
preview["nc_samples"][0]["well"] = ref.well(0)
preview["pc_samples"][0]["well"] = ref.well(0)
preview["containers"] = [ref]
flow_cytometry.flow_cytometry(protocol, params=preview)
assert len(protocol.as_dict()["instructions"]) == 1
def test_protocol_removes_lids(preview, flow_cytometry):
ref = Protocol().ref(name="src_plate", cont_type="96-flat", cover="universal", discard=True)
for well in ref.wells_from(0, 8):
well.set_volume("100:microliter")
preview["samples"]["well"] = list(ref.wells_from(1, 7))
preview["nc_samples"][0]["well"] = ref.well(0)
preview["pc_samples"][0]["well"] = ref.well(0)
protocol = Protocol()
flow_cytometry.flow_cytometry(protocol, params=preview)
operations = []
for instruction in protocol.instructions:
operations.append(instruction.op)
print(operations)
assert 'uncover' in operations
def test_make_samples_returns_the_correct_length(flow_cytometry):
p = Protocol()
plate = p.ref("sample_plate_1",
cont_type="96-flat",
discard=True)
wells = plate.all_wells()
assert len(flow_cytometry.make_samples(wells, "10:microliter")) == 96
def test_make_samples_returns_wells_and_volumes(flow_cytometry):
p = Protocol()
plate = p.ref("sample_plate_1",
cont_type="96-flat",
discard=True)
wells = plate.all_wells()
output = flow_cytometry.make_samples(wells, "10:microliter")
assert isinstance(output[0]["well"], Well)
assert isinstance(output[0]["volume"], str)
def test_make_samples_raises_type_error(flow_cytometry):
p = Protocol()
plate = p.ref("sample_plate_1",
cont_type="96-flat",
discard=True)
wells = ["A1", "A2", "A3", 4, 5, 6]
with pytest.raises(TypeError):
output = flow_cytometry.make_samples(wells, "10:microliter")
def test_flow_cytometry_protocol_contains_flow_analyze_instruction(preview, flow_cytometry):
ref = Protocol().ref(name="src_plate", cont_type="96-flat", discard=True)
for well in ref.wells_from(0, 8):
well.set_volume("100:microliter")
preview["samples"]["well"] = list(ref.wells_from(1, 7))
preview["nc_samples"][0]["well"] = ref.well(0)
preview["pc_samples"][0]["well"] = ref.well(0)
protocol = Protocol()
flow_cytometry.flow_cytometry(protocol, params=preview)
operations = []
for instruction in protocol.instructions:
operations.append(instruction.op)
assert 'flow_analyze' in operations
def test_make_controls_raises_type_error_on_argument(flow_cytometry):
p = Protocol()
plate = p.ref("sample_plate_1",
cont_type="96-flat",
discard=True)
wells = plate.all_wells()
with pytest.raises(TypeError):
output = flow_cytometry.make_controls(wells)
def test_make_controls_returns_listof_dicts(flow_cytometry):
p = Protocol()
plate = p.ref("sample_plate_1",
cont_type="96-flat",
discard=True)
controls = [
{
'well': plate.well(0),
'vol': "50:microliter",
'events': None,
'channel': 'FSC,SSC,FitC,TxR'
}
]
output = flow_cytometry.make_controls(controls)
assert isinstance(output, list)
assert isinstance(output[0], dict)
def test_flow_cytometry_runs_only_one_instruction(preview, flow_cytometry):
ref = Protocol().ref(name="src_plate", cont_type="96-flat", discard=True)
for well in ref.wells_from(0, 8):
well.set_volume("100:microliter")
preview["samples"]["well"] = list(ref.wells_from(1, 7))
preview["nc_samples"][0]["well"] = ref.well(0)
preview["pc_samples"][0]["well"] = ref.well(0)
protocol = Protocol()
flow_cytometry.flow_cytometry(protocol, params=preview)
assert len(protocol.as_dict()["instructions"]) == 1