Tutorial

Defining a new experiment

Experiments are generally defined by two parts: a temperature qslib.protocol.Protocol, which tells the machine how to run the experiment, and a qslib.plate_setup.PlateSetup, which describes the samples without changing how the machine runs.

Protocols are hierarchical sets of instructions with three levels:

  • A protocol is made up of qslib.protocol.Stage objects, which it runs in sequence. Each stage repeats for one or more cycles.

  • For every cycle, a stage runs one or more steps. Steps may change on each cycle. A qslib.protocol.Step holds temperatures for a duration and can take a fluorescence reading.

  • qslib.protocol.CustomStep supports lower-level sequences of SCPI commands, such as exposure changes.

QSLib also has convenience methods for constructing some common stages:

Stage.stepped_ramp(from_temperature, ...[, ...])

Hold at a series of temperatures, from one to another.

Stage.hold_for(temperature, total_time[, ...])

Hold at a temperature for a set amount of time, with steps of a configurable fixed time.

So, to make a protocol that does a quick anneal and melt, then holds at 50°C to 45°C, with some interesting details, we could do:

>>> protocol = Protocol(
        [
            Stage.stepped_ramp("80 °C", 60, "20 minutes"),  # A unitless temperature is degrees Celsius
            Stage.hold_for("60 degC", total_time=120),      # A unitless time is seconds
            Stage.stepped_ramp(from_temperature=60.0, to_temperature=30.0, total_time="1 hour", collect=True),
            # Collects the protocol default
            Stage.stepped_ramp(from_temperature=30, to_temperature=60.0, total_time="1 hour", temperature_step=2, collect=True),
            Stage.hold_for("60 degC", total_time="9 minutes", step_time="3 minutes",
                        filters=["x1-m4", "x3-m5"]), # Collects a different set of filters
            Stage.stepped_ramp(60, [50, 49, 48, 47, 46, 45], total_time="40 minutes", filters=["x1-m4"], n_steps=5), # Try this in AB's software!
            Stage.hold_for([50, 49, 48, 47, 46, 45], total_time="1 hour", step_time="10 minutes", filters=["x1-m4"]),
            Stage([Step("10 minutes", [50, 49, 48, 47, 46, 45], filters=["x1-m4"])], repeat=6) # An alternative
        ], filters=["x3-m5"]
    )

Plate setups contain qslib.plate_setup.Sample objects, which may be assigned to one or more wells:

>>> plate_setup = PlateSetup({"sample_A": "A1", "sample_B": ["A2", "A3"]})

Use qslib.plate_setup.PlateSetup.from_array() for a plate-sized array of sample names.

However, note that the plate setup does not change the data the machine collects: all filters collected by the protocol are collected for all wells, in the same way.

With these two components, you can create an experiment, which also needs a name (spaces are supported, and unicode is somewhat supported, but discretion on these is advisable):

>>> exp = Experiment("example-experiment", protocol, plate_setup)

At this point, you might want to check that your protocol is doing what you expect it to do. A convenient way of checking is to plot it:

>>> exp.plot_protocol()

You could also use protocol.plot_protocol().

You can get a summary of the experiment with

>>> print(exp)

Or, if you’re running Jupyter, you might want to try just

>>> exp

or

>>> display(exp)

Running and controlling the experiment

QSLib’s preferred setup isolates the QuantStudio machine from the internet. See Setup for details. With this setup, commands can use the machine’s hostname directly:

>>> exp.run("example-qpcr")

But perhaps we’d like to make sure the machine is free first:

>>> Machine("example-qpcr").run_status()

As the run progresses, we can get its status from the machine. Once we’ve run the experiment, it should remember (on our computer) the machine it is runnnig on, so we could get the status with:

>>> exp.get_status()

We can, with reasonable efficiency, update the experiment on our computer with the latest data from the machine using

>>> exp.sync_from_machine()

The updated experiment then exposes the data described below. Only new or changed files are copied; a record of copied files is kept in the experiment’s folder. Acquisition images (TIFFs, saved only when a protocol asks for them) are large and left out unless you pass include_images=True. For a long copy, progress takes a function that is called with the file name, the bytes copied so far and the total.

At some point, we might want to pause the run, and take out a sample.

>>> exp.pause()

or, if we want to specify the machine:

>>> exp.pause("example-qpcr")

Then:

>>> Machine("example-qpcr").drawer_open()

And after handling our samples,

>>> Machine("example-qpcr").drawer_close()
>>> exp.resume()

For a long run, we may not keep Python running the whole time, and so we may need to reload the experiment from the machine. This can be done with:

>>> exp = Experiment.from_running("example-qpcr")

Eventually, we might decide that we’d like the rest of our protocol to be different, for example, to add a new hold temperature. We can do this by making a new protocol:

>>> prot = exp.protocol.copy()
>>> prot.stages[7].repeat = 20
>>> prot.stages[7].steps[0].temperature = [49, 48, 47, 46, 45, 44]
>>> exp.change_protocol(prot)

QSLib will ensure that the new protocol is compatible with the running protocol before replacing it. Generally, in order to be compatible:

  • Every stage that has already done must be the same.

  • The current stage can’t have its steps modified (one or more cycles may have already run), but can have the number of repeats/cycles changed, so long as the number is greater than or equal to the current cycle number (keep in mind that for fast stages, the machine may finish a cycle while you are writing the new protocol). This is primarily useful for extending, or cutting short, the current cycle. (FIXME: it may be useful to have a “I don’t care what the current cycle is, just end the stage after the current one” designation, like setting the repeats to -1.)

  • Anything that is past the current stage can be modified arbitrarily (new stages can be added, and stages can be deleted or modified in any way).

LLM-written (Claude Opus 5.5, GPT-6)

The plate setup can also be changed on the machine, for example if the run was started without one:

>>> exp.change_plate_setup({"sample_A": "A1", "sample_B": ["A2", "A3"]})

This replaces all samples in the run’s plate setup file on the machine, keeping the file’s other contents, and then updates the local copy. The instrument does not use this file to run the protocol, so the change affects only the records of the run. The file is included when the machine collects the run into an EDS file; a change made after that does not alter the EDS file. Assigning to plate_setup or sample_wells changes only the local copy; exp.change_plate_setup() with no argument then writes the experiment’s current plate setup to the machine. The run folder must already exist over direct SCPI; HTTP file writes can create missing folders.

If the run has already finished, it is usually simpler to change the plate setup of a saved file, which does not need the machine at all:

>>> exp = Experiment.from_file("example-file-name.eds")
>>> exp.plate_setup = PlateSetup({"sample_A": "A1", "sample_B": ["A2", "A3"]})
>>> exp.save_file("example-file-name.eds", overwrite=True)

Use qslib.experiment.Experiment.stop() to stop after the current cycle or qslib.experiment.Experiment.abort() to stop immediately.

After a run finishes, use qslib.experiment.Experiment.sync_from_machine() to update the local copy, or load a clean copy:

>>> exp = Experiment.from_machine("example-experiment")

LLM-written (Claude Opus 5.5)

Every loader that reads from a machine takes include_images. Images are left out of running and uncollected runs by default, and included from completed runs in storage, so that a copy of a stored run is complete. With include_images=False and qslib-server, the image data of a stored run is not transferred. The loaders do not report progress or continue an interrupted copy; for a long transfer, such as a run with many images, use qslib.experiment.Experiment.sync_from_machine(), which does both.

You can save the experiment to a file with

>>> exp.save_file("example-file-name.eds")

If you want to save power, you can also put the machine in power-save mode when you are done:

>>> Machine("example-qpcr").power = False

Loading existing experiments

Experiment.from_running(machine, *[, ...])

Create an experiment from the one currently running on a machine.

Experiment.from_machine(machine, name, *[, ...])

Create an experiment from data on a machine, checking the running experiment if any, the machine's public_run_complete storage, and the machine's uncollected storage.

Experiment.from_file(file)

Load an experiment from an EDS file.

Accessing experiment data

QSLib can provide access to most data collected by QuantStudio machines, at a lower level and significantly beyond what AB’s software provides (please contact me if there is something you’d like easier access to). However, the two main items are temperature readings during the run, and machine-calibrated, but not fluorophore-calibrated, fluorescence measurements, roughly what you might expect as a reasonably raw reading (with some no-fluorophore background subtraction).

Temperature readings are available through qslib.experiment.Experiment.temperatures; fluorescence data and collection temperatures are available through qslib.experiment.Experiment.welldata.

To plot temperatures, you can use:

>>> exp.plot_temperatures()

To plot fluorescence data, you can use:

>>> exp.plot_over_time()

For an anneal-and-melt experiment, use qslib.experiment.Experiment.plot_anneal_melt():

>>> exp.plot_anneal_melt()

Both of these functions are designed to be flexible in selection of samples or wells, filters, and stages, cycles, and steps.

Other topics and possibilities