I am trying to write a simple script that just transfers liquid of specified volume from one plate to another in opentrons. I am using the approach specified here:
https://support.opentrons.com/s/article/Using-CSV-input-data-in-Python-protocols
" Embed the data into the protocol itself"
the code is shown below
import csv
import os
from opentrons import protocol_api
metadata = {'apiLevel': '2.13'}
def run(protocol: protocol_api.ProtocolContext):
source_plate = protocol.load_labware(
load_name='nest_96_wellplate_2ml_deep',
location=1)
target_plate = protocol.load_labware(
load_name='armadillo_96_wellplate_200ul_pcr_full_skirt',
location=2)
reservoir = protocol.load_labware(
load_name='opentrons_10_tuberack_falcon_4x50ml_6x15ml_conical',
location=3)
tiprack_1 = protocol.load_labware(
load_name='opentrons_96_tiprack_300ul',
location=4)
tiprack_2 = protocol.load_labware(
load_name='opentrons_96_tiprack_300ul',
location=5)
p300 = protocol.load_instrument(
instrument_name='p300_single',
mount='left',
tip_racks=[tiprack_1, tiprack_2])
p050 = protocol.load_instrument(
instrument_name='p50_single',
mount='right',
tip_racks=[tiprack_1, tiprack_2])
csv_raw = '''
source_well,destination_well,transfer_volume
A1,A2,10
B1,B2,20
'''
csv_data = csv_raw.splitlines()[1:] # Discard the blank first line.
csv_reader = csv.DictReader(csv_data)
for csv_row in csv_reader:
source_well = csv_row['source_well']
target_well = csv_row['destination_well']
transfer_volume = float(csv_row['transfer_volume'])
if (transfer_volume < 50):
p050.transfer(transfer_volume, source_plate.wells(source_well), target_plate.wells(target_well))
else:
p300.transfer(transfer_volume, source_plate.wells(source_well), target_plate.wells(target_well))
When I execute the code in spyder the csv is read as expected, but when I load the protocol into opentrons it produces a line: "protocol analysis failure KeyError [line 40]: âsource_wellâ " this corresponds to the first iteration of the for loop