Skip to content

Commit

Permalink
improve docs, factoring, logging and enable labeling in-or-outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
kedhammar committed Jan 15, 2025
1 parent 9eee644 commit 9686ba5
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions scripts/assign_noIndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)}"
)


Expand All @@ -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()

Expand Down

0 comments on commit 9686ba5

Please sign in to comment.