From 7e244a55c5698cc6035106c49f5cd50572061a8d Mon Sep 17 00:00:00 2001 From: Emilia Allison Date: Thu, 24 Oct 2024 13:59:10 -0500 Subject: [PATCH] Scripts as written on 1991 --- verso_spelling/verso_spell_via_script.py | 88 +++++++++++++++++++ .../ziath_read_to_available_tubes.py | 16 ++++ 2 files changed, 104 insertions(+) create mode 100644 verso_spelling/verso_spell_via_script.py create mode 100644 verso_spelling/ziath_read_to_available_tubes.py diff --git a/verso_spelling/verso_spell_via_script.py b/verso_spelling/verso_spell_via_script.py new file mode 100644 index 0000000..4e4c568 --- /dev/null +++ b/verso_spelling/verso_spell_via_script.py @@ -0,0 +1,88 @@ +#Cellario modules +from HRB.Cellario.Scripting import * +from HRB.Cellario.Scripting.API import * +import json +from sys import argv +from os import path, listdir +from dataclasses import dataclass + + +def Execute(api : PythonScriptingApi): + available_barcodes = "C:/temp/availabletubes.txt" + letter_dir = "C:/temp/letters" + input = "EH" + + available_tubes = read_available(available_barcodes) + letters = [] + for letter in input: + x = get_tubes_for_letter(letter, + len(letters) + 1, + available_tubes, + letter_dir) + available_tubes = available_tubes[len(x):] + letters += x + + output = letter_tubes_to_obj(letters) + + api.Messaging.WriteDiagnostic(ScriptLogLevel.Normal, json.dumps(output)) + list(api.CurrentRun.RunOrderParameters)[0].ParameterValue = json.dumps(output) + + +@dataclass(frozen=True) +class Tube: + barcode: str + row: int + col: int + + +@dataclass(frozen=True) +class LetterTube: + barcode: str + index: int + group: int + + +def letter_tubes_to_obj(x): + output = {} + output["Items"] = [{"BarcodeValue": y.barcode} for y in x] + output["TargetPositions"] = [{"PositionIndex": y.index, + "GroupIndex": y.group} + for y in x] + + return output + + +def get_tubes_for_letter(letter: str, + letter_index: int, + available_tubes, + letter_dir: str): + positions = get_letter_positions(letter, letter_dir) + + if len(positions) > len(available_tubes): + raise Exception("Insufficient tubes to fill order") + + pixels = [] + for i, position in enumerate(positions): + pixel = LetterTube(available_tubes[i], + position, + letter_index) + pixels.append(pixel) + return pixels + + +def read_available(p: str): + with open(p, 'r') as file: + return [x.strip() for x in file.readlines()] + + +def validate_word(input: str, letter_dir: str) -> bool: + letters_available = [x[0] for x in listdir(letter_dir)] + has_required_letters = all([x in letters_available for x in input]) + + return has_required_letters + + +def get_letter_positions(letter: str, letter_dir: str): + filename = [f for f in listdir(letter_dir) if f[0] == letter][0] + with open(path.join(letter_dir, filename), 'r') as file: + return [int(x.strip()) for x in file.readlines()] \ No newline at end of file diff --git a/verso_spelling/ziath_read_to_available_tubes.py b/verso_spelling/ziath_read_to_available_tubes.py new file mode 100644 index 0000000..ea6f11b --- /dev/null +++ b/verso_spelling/ziath_read_to_available_tubes.py @@ -0,0 +1,16 @@ +#Cellario modules +from HRB.Cellario.Scripting import * +from HRB.Cellario.Scripting.API import * +import json + + +def Execute(api : PythonScriptingApi): + sampleName = api.CurrentPlate.Name + with open(f"C:/temp/{sampleName}.txt", "r") as file: + j = json.load(file) + tubes = j["tubeBarcode"] + barcodes = [tube["barcode"] for tube in tubes] + with open("C:/temp/availabletubes.txt","a") as file: + for barcode in barcodes: + file.write(f"{barcode}\n") +