diff --git a/scripts/assign_noIndex.py b/scripts/assign_noIndex.py index d16e4c44..8bb55c15 100644 --- a/scripts/assign_noIndex.py +++ b/scripts/assign_noIndex.py @@ -15,6 +15,11 @@ This is necessary in order for unlabeled samples to pass through a LIMS demultiplexing step. + +Running the script at the start of a demultiplexing step will unfortunately +not work as intended, since LIMS performs the demultiplexing magic +inherent to the step prior to running any EPPs. Running the script on the +step prior to the demux step will work as intended. """ TIMESTAMP: str = dt.now().strftime("%y%m%d_%H%M%S") @@ -26,30 +31,43 @@ def main(args): lims = Lims(BASEURI, USERNAME, PASSWORD) process = Process(lims, id=args.pid) - if args.label == "inputs": + # Determine whether to process input or output analytes + if args.label == "input": arts_list = process.all_inputs() - elif args.label == "outputs": + elif args.label == "output": arts_list = process.all_outputs() else: raise ValueError(f"Invalid value '{args.label}' for argument 'label'") - unlabeled_input_arts = [ - art for art in arts_list if not art.reagent_labels and art.type == "Analyte" - ] + # Filter for unlabeled analytes + unlabeled_analytes = [] + for analyte in arts_list: + if not analyte.type == "Analyte": + continue + if analyte.reagent_labels: + logging.info( + f"{args.label.capitalize()} '{analyte.name}' is already labeled ({analyte.reagent_labels}), skipping." + ) + continue + unlabeled_analytes.append(analyte) + logging.info(f"Found {len(unlabeled_analytes)} unlabeled {args.label} analytes.") xml_element_noIndex = ET.Element("reagent-label", name="NoIndex") - failed_arts = [] - for art in unlabeled_input_arts: + failed_analytes = [] + for analyte in unlabeled_analytes: try: - art.root.append(xml_element_noIndex) - art.put() + analyte.root.append(xml_element_noIndex) + analyte.put() + logging.info( + f"Assigned 'noIndex' reagent label to {args.label} '{analyte.name}'" + ) except Exception as e: logging.error(e) - failed_arts.append(art) + failed_analytes.append(analyte) - if failed_arts: + if failed_analytes: logging.error( - f"Failed to assign 'noIndex' reagent label to the following artifacts: {', '.join(art.name for art in failed_arts)}" + f"Failed to assign 'noIndex' reagent label to the following {args.label}s: {', '.join(art.name for art in failed_analytes)}" ) @@ -58,7 +76,7 @@ def main(args): parser = ArgumentParser(description=DESC) parser.add_argument("--pid", type=str, help="Lims ID for current Process") parser.add_argument("--log", type=str, help="Which log file slot to use") - parser.add_argument("--label", type=str, help="Either 'inputs' or 'outputs'") + parser.add_argument("--label", type=str, help="Either 'input' or 'output'") args = parser.parse_args()