-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab_tools.py
More file actions
1265 lines (1031 loc) · 41 KB
/
lab_tools.py
File metadata and controls
1265 lines (1031 loc) · 41 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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""Agent-facing lab-operation wrappers."""
from __future__ import annotations
import contextvars
from typing import Optional
from src.environment import get_or_create_lab_state
from src.environment.observations import render_observation
from src.environment.operations import (
count_colonies,
fit_growth_curve,
gibson_assembly,
golden_gate_assembly,
incubate,
inspect_screening_plate,
inoculate_growth,
ligate,
list_cloning_substrates,
list_gibson_substrates,
list_golden_gate_substrates,
measure_od600,
perform_miniprep,
plate,
prepare_media,
restriction_digest,
run_colony_pcr,
run_gel,
run_nta_purification,
run_pcr,
run_protein_expression,
transform,
transform_assembly,
transform_gibson,
transform_ligation,
)
from src.environment.state import reset_lab_state
_ACTIVE_SAMPLE_ID = contextvars.ContextVar("labcraft_active_sample_id", default="transform_01_default")
_ACTIVE_SAMPLE_SEED = contextvars.ContextVar("labcraft_active_sample_seed", default=None)
def set_active_sample(sample_id: str, seed: Optional[int] = None):
_ACTIVE_SAMPLE_ID.set(sample_id)
_ACTIVE_SAMPLE_SEED.set(seed)
reset_lab_state(sample_id)
get_or_create_lab_state(sample_id, seed=seed)
def cleanup_sample(sample_id: str) -> None:
reset_lab_state(sample_id)
def _current_state():
sample_id = _ACTIVE_SAMPLE_ID.get()
seed = _ACTIVE_SAMPLE_SEED.get()
return get_or_create_lab_state(sample_id, seed=seed)
async def prepare_media_call(
medium: str,
antibiotic: str,
antibiotic_concentration_ug_ml: float,
plate_count: int = 1,
) -> str:
state = _current_state()
try:
payload = prepare_media(
state=state,
medium=medium,
antibiotic=antibiotic,
antibiotic_concentration_ug_ml=antibiotic_concentration_ug_ml,
plate_count=plate_count,
)
except ValueError as exc:
return _tool_error_observation("prepare_media", exc)
return render_observation(payload)
async def transform_call(
plasmid_mass_pg: float,
heat_shock_seconds: int,
recovery_minutes: int,
outgrowth_media: str = "SOC",
shaking: bool = True,
ice_incubation_minutes: int = 30,
) -> str:
state = _current_state()
try:
payload = transform(
state=state,
plasmid_mass_pg=plasmid_mass_pg,
heat_shock_seconds=heat_shock_seconds,
recovery_minutes=recovery_minutes,
outgrowth_media=outgrowth_media,
shaking=shaking,
ice_incubation_minutes=ice_incubation_minutes,
)
except ValueError as exc:
return _tool_error_observation("transform", exc)
return render_observation(payload)
async def plate_call(
culture_id: str,
plate_id: str,
dilution_factor: float,
volume_ul: float,
) -> str:
state = _current_state()
try:
payload = plate(
state=state,
culture_id=culture_id,
plate_id=plate_id,
dilution_factor=dilution_factor,
volume_ul=volume_ul,
)
except ValueError as exc:
return _tool_error_observation("plate", exc)
return render_observation(payload)
async def count_colonies_call(plating_id: str) -> str:
state = _current_state()
return render_observation(count_colonies(state=state, plating_id=plating_id))
async def inoculate_growth_call(condition: str, starting_od600: float) -> str:
state = _current_state()
try:
payload = inoculate_growth(
state=state,
condition=condition,
starting_od600=starting_od600,
)
except ValueError as exc:
return _tool_error_observation("inoculate_growth", exc)
return render_observation(payload)
async def incubate_call(growth_id: str, duration_minutes: int) -> str:
state = _current_state()
try:
payload = incubate(state=state, growth_id=growth_id, duration_minutes=duration_minutes)
except ValueError as exc:
return _tool_error_observation("incubate", exc)
return render_observation(payload)
async def measure_od600_call(growth_id: str, dilution_factor: float = 1.0) -> str:
state = _current_state()
try:
payload = measure_od600(state=state, growth_id=growth_id, dilution_factor=dilution_factor)
except ValueError as exc:
return _tool_error_observation("measure_od600", exc)
return render_observation(payload)
async def fit_growth_curve_call(growth_id: str) -> str:
state = _current_state()
return render_observation(fit_growth_curve(state=state, growth_id=growth_id))
async def run_pcr_call(
polymerase_name: str,
additive: str,
extension_seconds: int,
cycle_count: int,
) -> str:
state = _current_state()
return render_observation(
run_pcr(
state=state,
polymerase_name=polymerase_name,
additive=additive,
extension_seconds=extension_seconds,
cycle_count=cycle_count,
)
)
async def run_gel_call(
reaction_id: str,
agarose_percent: float = 1.0,
ladder_name: str = "1 kb DNA Ladder",
) -> str:
state = _current_state()
return render_observation(
run_gel(
state=state,
reaction_id=reaction_id,
agarose_percent=agarose_percent,
ladder_name=ladder_name,
)
)
async def inspect_screening_plate_call() -> str:
state = _current_state()
return render_observation(inspect_screening_plate(state=state))
async def run_colony_pcr_call(
colony_ids: list[str],
primer_pair: str = "M13/pUC flank primers",
) -> str:
state = _current_state()
try:
payload = run_colony_pcr(
state=state,
colony_ids=colony_ids,
primer_pair=primer_pair,
)
except ValueError as exc:
return _tool_error_observation("run_colony_pcr", exc)
return render_observation(payload)
def _tool_error_observation(tool_name: str, exc: Exception) -> str:
return render_observation(
{
"status": "tool_error",
"tool_name": tool_name,
"error_type": type(exc).__name__,
"message": str(exc),
}
)
async def list_cloning_substrates_call() -> str:
state = _current_state()
return render_observation(list_cloning_substrates(state=state))
async def restriction_digest_call(
fragment_id: str,
enzyme_names: list[str],
buffer: str,
temperature_c: float,
duration_minutes: int,
heat_inactivate_after: bool,
heat_inactivation_temperature_c: float = 65.0,
) -> str:
state = _current_state()
try:
payload = restriction_digest(
state=state,
fragment_id=fragment_id,
enzyme_names=enzyme_names,
buffer=buffer,
temperature_c=temperature_c,
duration_minutes=duration_minutes,
heat_inactivate_after=heat_inactivate_after,
heat_inactivation_temperature_c=heat_inactivation_temperature_c,
)
except ValueError as exc:
return _tool_error_observation("restriction_digest", exc)
return render_observation(payload)
async def ligate_call(
vector_fragment_id: str,
insert_fragment_ids: list[str],
ligase_name: str,
vector_to_insert_molar_ratio: float,
temperature_c: float,
duration_minutes: int,
buffer: str = "T4 DNA ligase buffer",
) -> str:
state = _current_state()
try:
payload = ligate(
state=state,
vector_fragment_id=vector_fragment_id,
insert_fragment_ids=insert_fragment_ids,
ligase_name=ligase_name,
vector_to_insert_molar_ratio=vector_to_insert_molar_ratio,
temperature_c=temperature_c,
duration_minutes=duration_minutes,
buffer=buffer,
)
except ValueError as exc:
return _tool_error_observation("ligate", exc)
return render_observation(payload)
async def transform_ligation_call(
ligation_id: str,
heat_shock_seconds: int = 30,
recovery_minutes: int = 60,
outgrowth_media: str = "SOC",
shaking: bool = True,
ice_incubation_minutes: int = 30,
) -> str:
state = _current_state()
try:
payload = transform_ligation(
state=state,
ligation_id=ligation_id,
heat_shock_seconds=heat_shock_seconds,
recovery_minutes=recovery_minutes,
outgrowth_media=outgrowth_media,
shaking=shaking,
ice_incubation_minutes=ice_incubation_minutes,
)
except ValueError as exc:
return _tool_error_observation("transform_ligation", exc)
return render_observation(payload)
async def list_golden_gate_substrates_call() -> str:
state = _current_state()
return render_observation(list_golden_gate_substrates(state=state))
async def golden_gate_assembly_call(
fragment_ids: list[str],
enzyme_name: str,
ligase_name: str,
buffer: str = "T4 DNA ligase buffer",
cycle_count: int = 25,
digest_temperature_c: float = 37.0,
ligate_temperature_c: float = 16.0,
final_digest_minutes: int = 5,
heat_kill_temperature_c: float = 60.0,
) -> str:
state = _current_state()
try:
payload = golden_gate_assembly(
state=state,
fragment_ids=fragment_ids,
enzyme_name=enzyme_name,
ligase_name=ligase_name,
buffer=buffer,
cycle_count=cycle_count,
digest_temperature_c=digest_temperature_c,
ligate_temperature_c=ligate_temperature_c,
final_digest_minutes=final_digest_minutes,
heat_kill_temperature_c=heat_kill_temperature_c,
)
except ValueError as exc:
return _tool_error_observation("golden_gate_assembly", exc)
return render_observation(payload)
async def transform_assembly_call(
assembly_id: str,
heat_shock_seconds: int = 30,
recovery_minutes: int = 60,
outgrowth_media: str = "SOC",
shaking: bool = True,
ice_incubation_minutes: int = 30,
) -> str:
state = _current_state()
try:
payload = transform_assembly(
state=state,
assembly_id=assembly_id,
heat_shock_seconds=heat_shock_seconds,
recovery_minutes=recovery_minutes,
outgrowth_media=outgrowth_media,
shaking=shaking,
ice_incubation_minutes=ice_incubation_minutes,
)
except ValueError as exc:
return _tool_error_observation("transform_assembly", exc)
return render_observation(payload)
async def list_gibson_substrates_call() -> str:
state = _current_state()
return render_observation(list_gibson_substrates(state=state))
async def gibson_assembly_call(
fragment_ids: list[str],
master_mix_name: str,
temperature_c: float,
duration_minutes: int,
overlap_length_bp: int = 20,
) -> str:
state = _current_state()
try:
payload = gibson_assembly(
state=state,
fragment_ids=fragment_ids,
master_mix_name=master_mix_name,
temperature_c=temperature_c,
duration_minutes=duration_minutes,
overlap_length_bp=overlap_length_bp,
)
except ValueError as exc:
return _tool_error_observation("gibson_assembly", exc)
return render_observation(payload)
async def transform_gibson_call(
gibson_id: str,
heat_shock_seconds: int = 30,
recovery_minutes: int = 60,
outgrowth_media: str = "SOC",
shaking: bool = True,
ice_incubation_minutes: int = 30,
) -> str:
state = _current_state()
try:
payload = transform_gibson(
state=state,
gibson_id=gibson_id,
heat_shock_seconds=heat_shock_seconds,
recovery_minutes=recovery_minutes,
outgrowth_media=outgrowth_media,
shaking=shaking,
ice_incubation_minutes=ice_incubation_minutes,
)
except ValueError as exc:
return _tool_error_observation("transform_gibson", exc)
return render_observation(payload)
async def perform_miniprep_call(
culture_volume_ml: float,
lysis_buffer_sequence: str,
lysis_duration_min: int,
purification_method: str,
elution_volume_ul: float,
) -> str:
state = _current_state()
try:
payload = perform_miniprep(
state=state,
culture_volume_ml=culture_volume_ml,
lysis_buffer_sequence=lysis_buffer_sequence,
lysis_duration_min=lysis_duration_min,
purification_method=purification_method,
elution_volume_ul=elution_volume_ul,
)
except ValueError as exc:
return _tool_error_observation("perform_miniprep", exc)
return render_observation(payload)
async def run_protein_expression_call(
host_strain: str,
iptg_concentration_mm: float,
induction_od600: float,
induction_temperature_c: float,
induction_hours: float,
lysis_buffer_ph: float,
culture_volume_ml: float = 500.0,
) -> str:
state = _current_state()
try:
payload = run_protein_expression(
state=state,
host_strain=host_strain,
iptg_concentration_mm=iptg_concentration_mm,
induction_od600=induction_od600,
induction_temperature_c=induction_temperature_c,
induction_hours=induction_hours,
lysis_buffer_ph=lysis_buffer_ph,
culture_volume_ml=culture_volume_ml,
)
except ValueError as exc:
return _tool_error_observation("run_protein_expression", exc)
return render_observation(payload)
async def run_nta_purification_call(
resin_name: str,
load_imidazole_mm: float,
wash_imidazole_mm: float,
elute_imidazole_mm: float,
flow_rate_ml_per_min: float = 1.0,
column_bed_volume_ml: float = 1.0,
input_mass_mg: float = 18.0,
) -> str:
state = _current_state()
try:
payload = run_nta_purification(
state=state,
resin_name=resin_name,
load_imidazole_mm=load_imidazole_mm,
wash_imidazole_mm=wash_imidazole_mm,
elute_imidazole_mm=elute_imidazole_mm,
flow_rate_ml_per_min=flow_rate_ml_per_min,
column_bed_volume_ml=column_bed_volume_ml,
input_mass_mg=input_mass_mg,
)
except ValueError as exc:
return _tool_error_observation("run_nta_purification", exc)
return render_observation(payload)
def prepare_media_tool():
from inspect_ai.tool import tool
@tool(name="prepare_media")
def prepare_media_tool_impl():
"""Prepare selection plates for a transformation experiment."""
async def execute(
medium: str,
antibiotic: str,
antibiotic_concentration_ug_ml: float,
plate_count: int = 1,
) -> str:
"""Prepare one or more selection plates.
Args:
medium: Plate medium name, such as "LB agar".
antibiotic: Selection antibiotic name.
antibiotic_concentration_ug_ml: Working antibiotic concentration in ug/mL.
plate_count: Number of plates to prepare.
"""
return await prepare_media_call(
medium=medium,
antibiotic=antibiotic,
antibiotic_concentration_ug_ml=antibiotic_concentration_ug_ml,
plate_count=plate_count,
)
return execute
return prepare_media_tool_impl()
def transform_tool():
from inspect_ai.tool import tool
@tool(name="transform")
def transform_tool_impl():
"""Transform chemically competent E. coli with plasmid DNA."""
async def execute(
plasmid_mass_pg: float,
heat_shock_seconds: int,
recovery_minutes: int,
outgrowth_media: str = "SOC",
shaking: bool = True,
ice_incubation_minutes: int = 30,
) -> str:
"""Run a chemical transformation.
Args:
plasmid_mass_pg: DNA mass in picograms.
heat_shock_seconds: Heat shock duration in seconds.
recovery_minutes: Outgrowth duration before plating.
outgrowth_media: Recovery medium name.
shaking: Whether the outgrowth is shaken.
ice_incubation_minutes: Time spent on ice before heat shock.
"""
return await transform_call(
plasmid_mass_pg=plasmid_mass_pg,
heat_shock_seconds=heat_shock_seconds,
recovery_minutes=recovery_minutes,
outgrowth_media=outgrowth_media,
shaking=shaking,
ice_incubation_minutes=ice_incubation_minutes,
)
return execute
return transform_tool_impl()
def plate_tool():
from inspect_ai.tool import tool
@tool(name="plate")
def plate_tool_impl():
"""Plate a transformed culture onto a prepared selection plate."""
async def execute(
culture_id: str,
plate_id: str,
dilution_factor: float,
volume_ul: float,
) -> str:
"""Plate a transformed culture.
Args:
culture_id: Identifier returned by the transform tool.
plate_id: Identifier returned by the prepare_media tool.
dilution_factor: Dilution applied before plating.
volume_ul: Plated volume in microliters.
"""
return await plate_call(
culture_id=culture_id,
plate_id=plate_id,
dilution_factor=dilution_factor,
volume_ul=volume_ul,
)
return execute
return plate_tool_impl()
def count_colonies_tool():
from inspect_ai.tool import tool
@tool(name="count_colonies")
def count_colonies_tool_impl():
"""Count colonies on a plated transformation sample."""
async def execute(plating_id: str) -> str:
"""Count colonies on a plated sample.
Args:
plating_id: Identifier returned by the plate tool.
"""
return await count_colonies_call(plating_id=plating_id)
return execute
return count_colonies_tool_impl()
def inoculate_growth_tool():
from inspect_ai.tool import tool
@tool(name="inoculate_growth")
def inoculate_growth_tool_impl():
"""Start one growth-characterization culture in a named condition."""
async def execute(condition: str, starting_od600: float) -> str:
"""Inoculate a growth culture.
Args:
condition: One of "LB", "M9 + glucose", or "LB + chloramphenicol (1.8 uM)".
starting_od600: Initial OD600 at inoculation.
"""
return await inoculate_growth_call(condition=condition, starting_od600=starting_od600)
return execute
return inoculate_growth_tool_impl()
def incubate_tool():
from inspect_ai.tool import tool
@tool(name="incubate")
def incubate_tool_impl():
"""Advance a growth culture by a specified incubation interval."""
async def execute(growth_id: str, duration_minutes: int) -> str:
"""Advance a culture in time.
Args:
growth_id: Identifier returned by inoculate_growth.
duration_minutes: Incubation duration in minutes.
"""
return await incubate_call(growth_id=growth_id, duration_minutes=duration_minutes)
return execute
return incubate_tool_impl()
def measure_od600_tool():
from inspect_ai.tool import tool
@tool(name="measure_od600")
def measure_od600_tool_impl():
"""Measure the OD600 of a growth culture."""
async def execute(growth_id: str, dilution_factor: float = 1.0) -> str:
"""Record an OD600 measurement.
Args:
growth_id: Identifier returned by inoculate_growth.
dilution_factor: Sample dilution applied before the OD600 reading.
"""
return await measure_od600_call(growth_id=growth_id, dilution_factor=dilution_factor)
return execute
return measure_od600_tool_impl()
def fit_growth_curve_tool():
from inspect_ai.tool import tool
@tool(name="fit_growth_curve")
def fit_growth_curve_tool_impl():
"""Estimate growth-rate parameters from collected OD600 measurements."""
async def execute(growth_id: str) -> str:
"""Fit a simple growth curve summary.
Args:
growth_id: Identifier returned by inoculate_growth.
"""
return await fit_growth_curve_call(growth_id=growth_id)
return execute
return fit_growth_curve_tool_impl()
def run_pcr_tool():
from inspect_ai.tool import tool
@tool(name="run_pcr")
def run_pcr_tool_impl():
"""Run one PCR condition for the GC-rich PCR optimization task."""
async def execute(
polymerase_name: str,
additive: str,
extension_seconds: int,
cycle_count: int,
) -> str:
"""Run a PCR reaction.
Args:
polymerase_name: Polymerase name, such as "Q5 High-Fidelity DNA polymerase".
additive: GC-rich additive choice, such as "DMSO", "Betaine", or "none".
extension_seconds: Extension time per cycle in seconds.
cycle_count: Total cycle count.
Returns:
A PCR result that includes a reaction_id such as "pcr_001". Save that
exact reaction_id and reuse it when calling run_gel.
"""
return await run_pcr_call(
polymerase_name=polymerase_name,
additive=additive,
extension_seconds=extension_seconds,
cycle_count=cycle_count,
)
return execute
return run_pcr_tool_impl()
def run_gel_tool():
from inspect_ai.tool import tool
@tool(name="run_gel")
def run_gel_tool_impl():
"""Visualize a PCR reaction on an agarose gel."""
async def execute(
reaction_id: str,
agarose_percent: float = 1.0,
ladder_name: str = "1 kb DNA Ladder",
) -> str:
"""Run a gel for a PCR reaction.
Args:
reaction_id: Reaction identifier returned by run_pcr, preferably reused
exactly as returned (for example "pcr_001").
agarose_percent: Agarose concentration for the gel.
ladder_name: DNA ladder used for size estimation.
"""
return await run_gel_call(
reaction_id=reaction_id,
agarose_percent=agarose_percent,
ladder_name=ladder_name,
)
return execute
return run_gel_tool_impl()
def inspect_screening_plate_tool():
from inspect_ai.tool import tool
@tool(name="inspect_screening_plate")
def inspect_screening_plate_tool_impl():
"""Inspect the blue-white screening plate used in Screen-01."""
async def execute() -> str:
"""Return the plate composition and available colony identifiers."""
return await inspect_screening_plate_call()
return execute
return inspect_screening_plate_tool_impl()
def run_colony_pcr_tool():
from inspect_ai.tool import tool
@tool(name="run_colony_pcr")
def run_colony_pcr_tool_impl():
"""Run colony PCR on one or more candidate colonies from the screening plate."""
async def execute(
colony_ids: list[str],
primer_pair: str = "M13/pUC flank primers",
) -> str:
"""Run colony PCR on selected colonies.
Args:
colony_ids: Colony identifiers returned by inspect_screening_plate.
primer_pair: Primer pair label for the screening PCR.
"""
return await run_colony_pcr_call(
colony_ids=colony_ids,
primer_pair=primer_pair,
)
return execute
return run_colony_pcr_tool_impl()
def list_cloning_substrates_tool():
from inspect_ai.tool import tool
@tool(name="list_cloning_substrates")
def list_cloning_substrates_tool_impl():
"""List the starting DNA fragments available for Clone-01."""
async def execute() -> str:
"""Return the vector and insert fragments provided for the cloning task."""
return await list_cloning_substrates_call()
return execute
return list_cloning_substrates_tool_impl()
def restriction_digest_tool():
from inspect_ai.tool import tool
@tool(name="restriction_digest")
def restriction_digest_tool_impl():
"""Run a restriction digest on a DNA fragment for cloning."""
async def execute(
fragment_id: str,
enzyme_names: list[str],
buffer: str,
temperature_c: float,
duration_minutes: int,
heat_inactivate_after: bool,
heat_inactivation_temperature_c: float = 65.0,
) -> str:
"""Digest a DNA fragment with one or more restriction enzymes.
Args:
fragment_id: Fragment to digest, as returned by list_cloning_substrates.
enzyme_names: Restriction enzymes (e.g., ["EcoRI", "BamHI"]).
buffer: Reaction buffer (e.g., "CutSmart").
temperature_c: Incubation temperature in Celsius.
duration_minutes: Incubation time in minutes.
heat_inactivate_after: Whether to heat-inactivate the enzymes after digestion.
heat_inactivation_temperature_c: Temperature used for heat inactivation if enabled.
"""
return await restriction_digest_call(
fragment_id=fragment_id,
enzyme_names=enzyme_names,
buffer=buffer,
temperature_c=temperature_c,
duration_minutes=duration_minutes,
heat_inactivate_after=heat_inactivate_after,
heat_inactivation_temperature_c=heat_inactivation_temperature_c,
)
return execute
return restriction_digest_tool_impl()
def ligate_tool():
from inspect_ai.tool import tool
@tool(name="ligate")
def ligate_tool_impl():
"""Set up a ligation reaction from a digested vector and one or more inserts."""
async def execute(
vector_fragment_id: str,
insert_fragment_ids: list[str],
ligase_name: str,
vector_to_insert_molar_ratio: float,
temperature_c: float,
duration_minutes: int,
buffer: str = "T4 DNA ligase buffer",
) -> str:
"""Ligate a digested vector with one or more digested inserts.
Args:
vector_fragment_id: Digested vector fragment id (output of restriction_digest).
insert_fragment_ids: Digested insert fragment ids.
ligase_name: Ligase name (use "T4 DNA ligase" for cohesive-end ligation).
vector_to_insert_molar_ratio: Insert excess over vector (e.g., 3.0 for 1:3 vector:insert).
temperature_c: Ligation temperature (16, 22, or 25 C).
duration_minutes: Ligation duration in minutes.
buffer: Ligation buffer label.
"""
return await ligate_call(
vector_fragment_id=vector_fragment_id,
insert_fragment_ids=insert_fragment_ids,
ligase_name=ligase_name,
vector_to_insert_molar_ratio=vector_to_insert_molar_ratio,
temperature_c=temperature_c,
duration_minutes=duration_minutes,
buffer=buffer,
)
return execute
return ligate_tool_impl()
def transform_ligation_tool():
from inspect_ai.tool import tool
@tool(name="transform_ligation")
def transform_ligation_tool_impl():
"""Transform a ligation reaction into competent E. coli and prepare a screening plate."""
async def execute(
ligation_id: str,
heat_shock_seconds: int = 30,
recovery_minutes: int = 60,
outgrowth_media: str = "SOC",
shaking: bool = True,
ice_incubation_minutes: int = 30,
) -> str:
"""Transform a ligation into competent cells.
Args:
ligation_id: Ligation identifier (e.g., "ligation_001") from the ligate tool.
heat_shock_seconds: Heat shock duration (30 s is standard).
recovery_minutes: Post-shock outgrowth duration in minutes.
outgrowth_media: Outgrowth medium ("SOC" recommended).
shaking: Whether to shake during recovery.
ice_incubation_minutes: Pre-shock ice incubation time.
"""
return await transform_ligation_call(
ligation_id=ligation_id,
heat_shock_seconds=heat_shock_seconds,
recovery_minutes=recovery_minutes,
outgrowth_media=outgrowth_media,
shaking=shaking,
ice_incubation_minutes=ice_incubation_minutes,
)
return execute
return transform_ligation_tool_impl()
def list_golden_gate_substrates_tool():
from inspect_ai.tool import tool
@tool(name="list_golden_gate_substrates")
def list_golden_gate_substrates_tool_impl():
"""List the four starting DNA fragments for the Golden Gate task."""
async def execute() -> str:
"""Return the backbone + three inserts and their BsaI overhangs."""
return await list_golden_gate_substrates_call()
return execute
return list_golden_gate_substrates_tool_impl()
def golden_gate_assembly_tool():
from inspect_ai.tool import tool
@tool(name="golden_gate_assembly")
def golden_gate_assembly_tool_impl():
"""Run a one-pot Golden Gate / Type IIS assembly with thermal cycling."""
async def execute(
fragment_ids: list[str],
enzyme_name: str,
ligase_name: str,
buffer: str = "T4 DNA ligase buffer",
cycle_count: int = 25,
digest_temperature_c: float = 37.0,
ligate_temperature_c: float = 16.0,
final_digest_minutes: int = 5,
heat_kill_temperature_c: float = 60.0,
) -> str:
"""Run a Golden Gate assembly.
Args:
fragment_ids: Fragments to assemble (must be all four Golden Gate substrates).
enzyme_name: Type IIS enzyme (e.g., "BsaI" or "BsmBI").
ligase_name: Ligase (use "T4 DNA ligase").
buffer: Reaction buffer.
cycle_count: Number of 37/16 C cycles (>= 25 recommended).
digest_temperature_c: Digest step temperature (37 C optimal).
ligate_temperature_c: Ligate step temperature (16 C optimal).
final_digest_minutes: Final digest hold after cycling.
heat_kill_temperature_c: Heat-kill temperature (60 C standard for NEB Golden Gate Assembly Mix).
"""