Skip to content

Commit

Permalink
Merge branch 'edge' into opentrons-ai-client-review
Browse files Browse the repository at this point in the history
  • Loading branch information
fbelginetw committed Nov 12, 2024
2 parents b63d70d + cb65905 commit 940c92d
Show file tree
Hide file tree
Showing 33 changed files with 476 additions and 187 deletions.
2 changes: 2 additions & 0 deletions abr-testing/abr_testing/automation/google_drive_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def list_folder(self, delete: Any = False, folder: bool = False) -> Set[str]:
else "" # type: ignore
if self.parent_folder
else None,
supportsAllDrives=True,
includeItemsFromAllDrives=True,
pageSize=1000,
fields="nextPageToken, files(id, name, mimeType)",
pageToken=page_token,
Expand Down
28 changes: 24 additions & 4 deletions abr-testing/abr_testing/data_collection/abr_google_drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ def create_data_dictionary(
plate: str,
accuracy: Any,
hellma_plate_standards: List[Dict[str, Any]],
) -> Tuple[List[List[Any]], List[str], List[List[Any]], List[str]]:
) -> Tuple[List[List[Any]], List[str], List[List[Any]], List[str], List[List[Any]]]:
"""Pull data from run files and format into a dictionary."""
runs_and_robots: List[Any] = []
runs_and_lpc: List[Dict[str, Any]] = []
headers: List[str] = []
headers_lpc: List[str] = []
list_of_heights: List[List[Any]] = [[], [], [], [], [], [], [], []]
for filename in os.listdir(storage_directory):
file_path = os.path.join(storage_directory, filename)
if file_path.endswith(".json"):
Expand Down Expand Up @@ -120,6 +121,9 @@ def create_data_dictionary(
plate_reader_dict = read_robot_logs.plate_reader_commands(
file_results, hellma_plate_standards
)
list_of_heights = read_robot_logs.liquid_height_commands(
file_results, list_of_heights
)
notes = {"Note1": "", "Jira Link": issue_url}
plate_measure = {
"Plate Measured": plate,
Expand Down Expand Up @@ -155,7 +159,13 @@ def create_data_dictionary(
print(f"Number of runs read: {num_of_runs_read}")
transposed_runs_and_robots = list(map(list, zip(*runs_and_robots)))
transposed_runs_and_lpc = list(map(list, zip(*runs_and_lpc)))
return transposed_runs_and_robots, headers, transposed_runs_and_lpc, headers_lpc
return (
transposed_runs_and_robots,
headers,
transposed_runs_and_lpc,
headers_lpc,
list_of_heights,
)


def run(
Expand All @@ -173,7 +183,8 @@ def run(
credentials_path, google_sheet_name, 0
)
# Get run ids on google sheet
run_ids_on_gs = set(google_sheet.get_column(2))
run_ids_on_gs: Set[str] = set(google_sheet.get_column(2))

# Get robots on google sheet
# Uploads files that are not in google drive directory
google_drive.upload_missing_files(storage_directory)
Expand All @@ -191,6 +202,7 @@ def run(
headers,
transposed_runs_and_lpc,
headers_lpc,
list_of_heights,
) = create_data_dictionary(
missing_runs_from_gs,
storage_directory,
Expand All @@ -201,7 +213,15 @@ def run(
)
start_row = google_sheet.get_index_row() + 1
google_sheet.batch_update_cells(transposed_runs_and_robots, "A", start_row, "0")

# Record Liquid Heights Found
google_sheet_ldf = google_sheets_tool.google_sheet(
credentials_path, google_sheet_name, 2
)
google_sheet_ldf.get_row(1)
start_row_lhd = google_sheet_ldf.get_index_row() + 1
google_sheet_ldf.batch_update_cells(
list_of_heights, "A", start_row_lhd, "2075262446"
)
# Add LPC to google sheet
google_sheet_lpc = google_sheets_tool.google_sheet(credentials_path, "ABR-LPC", 0)
start_row_lpc = google_sheet_lpc.get_index_row() + 1
Expand Down
10 changes: 10 additions & 0 deletions abr-testing/abr_testing/data_collection/abr_robot_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,7 @@ def get_run_error_info_from_robot(
headers,
runs_and_lpc,
headers_lpc,
list_of_heights,
) = abr_google_drive.create_data_dictionary(
run_id,
error_folder_path,
Expand All @@ -614,6 +615,15 @@ def get_run_error_info_from_robot(
start_row = google_sheet.get_index_row() + 1
google_sheet.batch_update_cells(runs_and_robots, "A", start_row, "0")
print("Wrote run to ABR-run-data")
# Record Liquid Heights Found
google_sheet_ldf = google_sheets_tool.google_sheet(
credentials_path, google_sheet_name, 4
)
start_row_lhd = google_sheet_ldf.get_index_row() + 1
google_sheet_ldf.batch_update_cells(
list_of_heights, "A", start_row_lhd, "1795535088"
)
print("wrote liquid heights found.")
# Add LPC to google sheet
google_sheet_lpc = google_sheets_tool.google_sheet(
credentials_path, "ABR-LPC", 0
Expand Down
36 changes: 36 additions & 0 deletions abr-testing/abr_testing/data_collection/read_robot_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,42 @@ def instrument_commands(
return pipette_dict


def liquid_height_commands(
file_results: Dict[str, Any], all_heights_list: List[List[Any]]
) -> List[List[Any]]:
"""Record found liquid heights during a protocol."""
commandData = file_results.get("commands", "")
robot = file_results.get("robot_name", "")
run_id = file_results.get("run_id", "")
for command in commandData:
commandType = command["commandType"]
if commandType == "comment":
result = command["params"].get("message", "")
try:
result_str = "'" + result.split("result: {")[1] + "'"
entries = result_str.split(", (")
comment_time = command["completedAt"]
for entry in entries:
height = float(entry.split(": ")[1].split("'")[0].split("}")[0])
labware_type = str(
entry.split(",")[0].replace("'", "").replace("(", "")
)
well_location = str(entry.split(", ")[1].split(" ")[0])
slot_location = str(entry.split("slot ")[1].split(")")[0])
labware_name = str(entry.split("of ")[1].split(" on")[0])
all_heights_list[0].append(robot)
all_heights_list[1].append(run_id)
all_heights_list[2].append(comment_time)
all_heights_list[3].append(labware_type)
all_heights_list[4].append(labware_name)
all_heights_list[5].append(slot_location)
all_heights_list[6].append(well_location)
all_heights_list[7].append(height)
except (IndexError, ValueError):
continue
return all_heights_list


def plate_reader_commands(
file_results: Dict[str, Any], hellma_plate_standards: List[Dict[str, Any]]
) -> Dict[str, object]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
header,
runs_and_lpc,
lpc_headers,
list_of_heights,
) = abr_google_drive.create_data_dictionary(
run_ids_in_storage,
run_log_file_path,
Expand All @@ -42,6 +43,7 @@
"",
hellma_plate_standards=file_values,
)
print("list_of_heights not recorded.")
transposed_list = list(zip(*runs_and_robots))
# Adds Run to local csv
sheet_location = os.path.join(run_log_file_path, "saved_data.csv")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def run(ctx: ProtocolContext) -> None:
"Wash": [{"well": wash, "volume": 750.0}],
"Samples": [{"well": samples, "volume": 250.0}],
}
flattened_wells = helpers.find_liquid_height_of_loaded_liquids(
helpers.find_liquid_height_of_loaded_liquids(
ctx, liquid_vols_and_wells, p1000_single
)

Expand Down Expand Up @@ -268,5 +268,6 @@ def discard(vol3: float, start: List[Well]) -> None:
ctx.delay(minutes=MAG_DELAY_MIN)
transfer_plate_to_plate(ELUTION_VOL * 1.1, working_cols, final_cols, 6)
temp.deactivate()
flattened_wells.append(waste)
helpers.find_liquid_height_of_all_wells(ctx, p1000_single, flattened_wells)
end_wells_to_probe = [reagent_res["A1"], reagent_res["B1"], reagent_res["C1"]]
end_wells_to_probe.extend(wash_res.wells())
helpers.find_liquid_height_of_all_wells(ctx, p1000_single, end_wells_to_probe)
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,10 @@ def tiptrack(rack: int, reuse_col: Optional[int], reuse: bool = False) -> None:
)
p200.pick_up_tip()

tiptrack(tip50, None, reuse=False)
p50.return_tip()
helpers.find_liquid_height_of_loaded_liquids(ctx, liquid_vols_and_wells, p50)

def TipSwap(tipvol: int) -> None:
"""Tip swap."""
if tipvol == 50:
Expand Down Expand Up @@ -1203,18 +1207,11 @@ def lib_cleanup_2() -> None:
# Set Block Temp for Final Plate
tc_mod.set_block_temperature(4)

tiptrack(tip50, None, reuse=False)
p50.return_tip()
probed_wells = helpers.find_liquid_height_of_loaded_liquids(
ctx, liquid_vols_and_wells, p50
)

unused_lids, used_lids = Fragmentation(unused_lids, used_lids)
unused_lids, used_lids = end_repair(unused_lids, used_lids)
unused_lids, used_lids = index_ligation(unused_lids, used_lids)
lib_cleanup()
unused_lids, used_lids = lib_amplification(unused_lids, used_lids)
lib_cleanup_2()
probed_wells.append(waste1_res)
probed_wells.append(waste2_res)
helpers.find_liquid_height_of_all_wells(ctx, p50, probed_wells)
end_probed_wells = [waste1_res, waste2_res]
helpers.find_liquid_height_of_all_wells(ctx, p50, end_probed_wells)
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def plate_reader_actions(
"""Plate reader single and multi wavelength readings."""
wavelengths = [450, 650]
# Single Wavelength Readings
plate_reader.close_lid()
for wavelength in wavelengths:
plate_reader.initialize("single", [wavelength], reference_wavelength=wavelength)
plate_reader.open_lid()
Expand Down Expand Up @@ -156,14 +157,13 @@ def run(protocol: ProtocolContext) -> None:
p50 = protocol.load_instrument(
"flex_8channel_50", "right", tip_racks=[tiprack_50_1, tiprack_50_2]
)

plate_reader_actions(protocol, plate_reader, hellma_plate)
# reagent
AMPure = reservoir["A1"]
SMB = reservoir["A2"]

EtOH = reservoir["A4"]
RSB = reservoir["A5"]

Liquid_trash_well_1 = reservoir["A9"]
Liquid_trash_well_2 = reservoir["A10"]
Liquid_trash_well_3 = reservoir["A11"]
Expand All @@ -181,6 +181,8 @@ def run(protocol: ProtocolContext) -> None:
ET2 = reagent_plate.wells_by_name()["A5"]
PPC = reagent_plate.wells_by_name()["A6"]
EPM = reagent_plate.wells_by_name()["A7"]
# Load Liquids
plate_reader_actions(protocol, plate_reader, hellma_plate)

# tip and sample tracking
if COLUMNS == 1:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,7 @@ def run(ctx: ProtocolContext) -> None:
"Stop": [{"well": stopreaction, "volume": stop_vol}],
}

flattened_list_of_wells = helpers.find_liquid_height_of_loaded_liquids(
ctx, liquid_vols_and_wells, m1000
)
helpers.find_liquid_height_of_loaded_liquids(ctx, liquid_vols_and_wells, m1000)

m1000.flow_rate.aspirate = 50
m1000.flow_rate.dispense = 150
Expand Down Expand Up @@ -556,5 +554,6 @@ def elute(vol: float) -> None:
)
elute(elution_vol)

flattened_list_of_wells.append(waste_reservoir["A1"])
helpers.find_liquid_height_of_all_wells(ctx, m1000, flattened_list_of_wells)
end_list_of_wells_to_probe = [waste_reservoir["A1"], res1["A1"]]
end_list_of_wells_to_probe.extend(elution_samples_m)
helpers.find_liquid_height_of_all_wells(ctx, m1000, end_list_of_wells_to_probe)
10 changes: 10 additions & 0 deletions abr-testing/abr_testing/tools/abr_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def get_most_recent_run_and_record(
headers,
runs_and_lpc,
headers_lpc,
list_of_heights,
) = abr_google_drive.create_data_dictionary(
most_recent_run_id,
storage_directory,
Expand All @@ -163,6 +164,15 @@ def get_most_recent_run_and_record(
start_row = google_sheet_abr_data.get_index_row() + 1
google_sheet_abr_data.batch_update_cells(runs_and_robots, "A", start_row, "0")
print("Wrote run to ABR-run-data")
# Add liquid height detection to abr sheet
google_sheet_ldf = google_sheets_tool.google_sheet(
credentials_path, "ABR-run-data", 4
)
start_row_lhd = google_sheet_ldf.get_index_row() + 1
google_sheet_ldf.batch_update_cells(
list_of_heights, "A", start_row_lhd, "1795535088"
)
print("Wrote found liquid heights to ABR-run-data")
# Add LPC to google sheet
google_sheet_lpc = google_sheets_tool.google_sheet(
credentials_path, "ABR-LPC", tab_number=0
Expand Down
Loading

0 comments on commit 940c92d

Please sign in to comment.