forked from yunhzou/OT2Demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptimization_workflow.py
More file actions
102 lines (87 loc) · 3.28 KB
/
optimization_workflow.py
File metadata and controls
102 lines (87 loc) · 3.28 KB
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
from OT2wrapper import OT2
from prefect import flow,task,serve
from LabMind import KnowledgeObject,nosql_service
from LabMind.Utils import upload
from optimization_algorithm import optimize
import pandas as pd
session_id="test"
def extract_previous_experiments(session_id):
db="OT2"
collection = "experiments"
# collection to dataframe for this session
collection = nosql_service[db][collection]
df = pd.DataFrame(list(collection.find({"session_id": session_id})))
if len(df) == 0:
return []
else:
relevant_columns = ["R", "G", "B", "mae"]
filtered_df = df[relevant_columns]
# Convert the filtered DataFrame to a list of dictionaries
past_experiments = filtered_df.to_dict(orient="records")
return past_experiments
def find_unused_wells():
db = "OT2"
collection = "wells"
collection = nosql_service[db][collection]
df = pd.DataFrame(list(collection.find({"status": "empty"})))
# return a list of wells that are empty
empty_wells = df["well"].tolist()
if len(empty_wells) == 0:
raise ValueError("No empty wells found")
return empty_wells
@flow(log_prints=True)
def optimization_workflow():
# find parameters
past_experiments = extract_previous_experiments(session_id)
# optimize
next_parameters = optimize(past_experiments)
# find empty wells
empty_well = find_unused_wells()[0]
@flow(log_prints=True)
def setup_target(R,G,B,mix_well="H11"):
# check if they add up to 1
total = R+G+B
if total != 1:
raise ValueError("The sum of the proportions must be 1")
ot2 = OT2()
ot2.home()
position = ["B1", "B2", "B3"]
rows = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']
portion = {"B1": R, "B2": G, "B3": B}
total_volume = 150
red_volume = int(portion["B1"] * total_volume)
green_volume = int(portion["B2"] * total_volume)
blue_volume = int(portion["B3"] * total_volume)
reservoir = {"B1": red_volume, "B2": green_volume, "B3": blue_volume}
columns = [str(i) for i in range(1, 13)]
for i in range(5,6):
row = rows[i // 12]
col = columns[i % 12]
for pos in position:
if float(portion[pos]) != 0.0:
ot2.p_300_pick_up_tip(pos,tiptrack="tiprack_1")
ot2.p_300_aspirate(pos,volume = reservoir[pos])
ot2.dispense(mix_well,volume = reservoir[pos])
ot2.set_speed(100)
ot2.blow_out()
ot2.set_speed(400)
ot2.drop_tip(pos,tiptrack="tiprack_1")
#color sensor
well_color_data = ot2.check_color(target_well=mix_well)
#upload well_color_data
project = "OT2"
collection = "target"
unique_fields = ["R","G","B","well_color_data"]
metadata = {"R":R,
"G":G,
"B":B,
"well_color_data": well_color_data,
"project": project,
"collection": collection,
"unique_fields": unique_fields}
target = KnowledgeObject(metadata=metadata,nosql_service=nosql_service,embedding=False)
upload(target)
print(well_color_data)
print("Protocol execution complete")
ot2.close_session()
print("Session closed")