QuPath Multiplex Immunofluorescence: Scripting Reproducible Pipelines
QuPath multiplex immunofluorescence scripting: move every parameter out of the script, run headless in batches, and keep an auditable run manifest.
A reproducible multiplex immunofluorescence (mIF) pipeline is not the one with the cleverest script. It is the one where every parameter that can change a result lives outside the script body, in a versioned parameter file, and where the whole run can be re-executed from a command line against the same inputs — so any number in a report traces back to the code, parameters, model and data that produced it. The rest is about preventing silent drift between the procedure you designed and the one that actually ran.
This article covers only that layer. The method your script executes — tissue and cell segmentation, phenotype assignment, spatial metrics — is in our mIF image analysis workflow. Whether a cell boundary is defensible is the question our cell segmentation article owns, how a phenotype rule is set is in cell phenotyping, and whether to build the pipeline at all is the question our outsourcing guide answers.

Conceptual schematic only: not microscopy data, not a measured result, not a performance curve and not vendor benchmark data. The four-layer structure and the manifest fields below are an editorial framework for this article.
Why an interactive workflow stops working at scale
QuPath is, in the software’s own description, mostly designed to be an interactive application, and that remains the main priority.1 That is why a workflow that works on slide one misbehaves on slide four hundred: not because QuPath fails, but because an interactive session accumulates state that no single file records.
The documentation is candid about where that state hides. Recording commands as a workflow from the command history is a reasonable first step towards reproducibility, since at least it records what has been done to an image.2 But not every command can be logged, and the manual steps matter most: annotations drawn by hand are not logged, because they are assumed relevant only to the current image.2 The consequence is stated plainly — “Steps that are manual in one image will likely have to be manual on another image.”2
There is a second, subtler failure. If cell detection is run twice on the same annotations with different settings, a script generated from that history will run both passes on every subsequent image.2 The workflow you captured is then not the procedure you meant, but the one you performed, mistakes included.
Two further details decide whether a captured workflow becomes a batch job. When a script is applied to a project, the version of the image data processed is the last one that was saved, so previously added objects remain available to the script.2 And the documentation’s advice is not to automate everything: it is often better to break the analysis into smaller pieces, some scripted and some manual.2 The script is only one of four things you must control, and the one most people externalise last.
The four-layer architecture
The practical answer is to separate four layers and give each one a file of its own. The following is an editorial framework written for this article, not a published standard, and it does not correspond to any standard’s own field list.
| Layer | What it holds | What breaks when the layer is skipped |
|---|---|---|
| Data layer | The images, the QuPath project structure, the channel-to-marker map, the pixel calibration, the file format | The script cannot find its inputs, or finds them with channels in a different order than the code assumes |
| Script layer | Versioned script files that contain no tunable values | No way to establish which code produced a number; every re-run means editing code |
| Parameter layer | One external file holding every detection threshold, requested pixel size, channel assignment, rule and output setting | Thresholds hide inside the script body; changing a threshold becomes a code change and is never reviewed |
| Output layer | Machine-readable result tables plus a run manifest that ties every output to its inputs | Numbers arrive with no provenance, so a reviewer question cannot be answered |
The order matters more than the labels. The data layer is the one most people already have, provided the delivery checklist in our mIF file format guide was followed and channel identity is explicit. The parameter layer is usually missing, and it decides whether a re-run is a configuration change or a rewrite. The output layer decides whether the pipeline is auditable: a manifest turns “the analysis was run” into “this analysis was run, with these versions, on these inputs”.
Headless execution and parameter passing
QuPath’s command line is the mechanism that turns a script into a pipeline. The documented capabilities include running scripts headlessly, specifying script parameters with the --args option, and returning a non-zero exit code if an exception is thrown.1 That matters operationally: a batch job that fails loudly is one you can schedule, retry and alert on.
The script subcommand takes an image or a project, and by default does not save changes to any data files; the --save option is what makes the project images actually update.1 Arguments passed with --args arrive in the script as an args array variable, which can be queried to confirm that a parameter was supplied rather than silently defaulting.1 The same command line carries a --project path to a .qpproj file and a --server option for choosing how the image is read.1 QuPath is free, open source and developed in academia, and its scripting API is used extensively when converting workflows into batch scripts.34
Two details deserve more attention than they usually get. The first is version pinning: QuPath’s version policy states that for reproducibility you should not mix the analysis of images using different MAJOR or MINOR versions within the same project or analysis study, because the results of commands such as cell detection or classification, or of scripts, might be different.4 A cohort split across two QuPath versions is not a cohort, it is two cohorts with a shared name. The second is calibration: when a script asks for the pixel size and the image does not carry it, the value returned is NaN, and a threshold expressed in microns silently becomes meaningless.3 The pipeline must fail on absent calibration, not continue with it.
What must leave the script body
The parameter register is the heart of this article. A more useful rule of thumb than any specific list: if changing a value could change a number in a report, that value does not belong inside the script. The table below is an editorial framework, not a published standard; the right-hand column is why each group belongs outside the code.
| Parameter group | Typical entries | Where it must be recorded | What changes when it moves out of the script |
|---|---|---|---|
| Detection and segmentation | Requested pixel size, estimated nucleus diameter, background radius, detection thresholds | Parameter file, keyed to a parameter-set version | Threshold changes become reviewed configuration changes instead of silent code edits |
| Channel and background handling | Channel-to-marker map, stain vector settings, background subtraction | Parameter file and the run manifest | A channel swap becomes a visible diff rather than a mystery |
| Phenotype rules | Marker positivity thresholds, co-expression rules, class hierarchy | Versioned rule file | Rule changes are attributable to a specific parameter version |
| Classification models | Model name, model version, decision thresholds | Parameter file plus model artefact identifier | A model swap is recorded, and its effect on results is a known unknown |
| Regions and sampling | Region definitions, core selection, exclusion rules | Parameter file plus per-image annotation record | Manual region decisions are separated from the automated part |
| Output contract | File names, exported columns, output directory, naming pattern | Parameter file | Downstream consumers get a stable, documented interface |
Marker thresholds, co-expression rules and class hierarchies are covered in our cell phenotyping article; here they appear only as parameter entries. Region selection is the classic trap, because it is where manual judgement meets automation. If the analysis needs regions of interest only a person can place, the honest architecture is a manual step performed and saved for every image, followed by a script running the automated steps across the project — precisely the sequence the documentation describes, and the reason the saved .qpdata state matters.2 Choosing those regions is a sampling decision with statistical weight, and for tissue microarrays it decides whether the unit of analysis is the core or the cell.
Versioning and the run manifest
The run manifest makes a pipeline auditable, and it is the piece most pipelines lack. It is not a log file or a summary table; it ties one output to one set of inputs. The fields below are an editorial framework for this article.
| Manifest field | What it records | Why it is needed |
|---|---|---|
| Software version | QuPath MAJOR.MINOR.PATCH, plus the version of every extension in use | Commands and scripts may behave differently across MAJOR or MINOR versions |
| Script identity | File name and a version identifier for each script in the chain | Establishes which code ran |
| Parameter set identity | Name and version of the external parameter file | Establishes which configuration ran |
| Model identity | Classifier or model name and version, if any | Establishes which trained artefact ran |
| Input identity | Project file, image list, and a stable identifier per image | Establishes what was processed |
| Channel map | Channel-to-marker assignment used by the run | Makes a channel-order change detectable |
| Invocation record | The exact command line, including arguments and flags | Makes the run literally re-runnable |
| Execution record | Start and end timestamps, exit status, log location | Separates a failed run from a successful empty run |
| Output record | File names, row counts, and a checksum per output file | Allows outputs to be matched to the manifest later |
These fields are not arbitrary. The consensus reporting checklist for multiplex IHC/IF studies asks authors to summarise the software and packages used for analysis including name, version and modules, and to provide enough detail to access data and reproduce the study results — for example a GitHub link with a release tag for code or run parameters.8 The best-practice guidance on mIF analysis and data sharing recommends sharing raw outputs, processed results, key analysis programs and source code.9 The minimum-information standard for highly multiplexed tissue images applies genomics and other microscopy best practices to tissue-image data and metadata, and the consortium publishes a field-level, machine-readable specification in which each attribute has a data type and constraints on valid values.1112 The general FAIR principle is that metadata and data should be retrievable by their identifier using a standardised communications protocol, with metadata remaining accessible even when the data are no longer available.13 A run manifest is the smallest thing that satisfies the spirit of all four for a single analysis run. The pipeline run manifest worksheet and its field guide record one run as one row: the versions, the inputs, the invocation, the outputs and the acceptance decision. The CSV ships with headers only — no default thresholds, no sample values, no implied validation and no data rows. Kept with the outputs, it turns “we think that is what we ran” into “here is what we ran” — a lookup rather than an argument.
Validating the pipeline itself
Producing numbers is not the same as being validated, and the burden sits on the pipeline, not only on the biology. Reproducibility must be evaluated at each step of the process: internal quality control addresses day-to-day reproducibility within one laboratory, while external quality assessment is needed to compare results across many laboratories, and standardising exclusion reasons reduces interobserver variability.10
For a pipeline, that means four separate checks. The first is a held-out reference set of images with independently reviewed calls, evaluated with the locked workflow — the segmentation-specific version is in our cell segmentation article. The second is a re-run test: run the identical script, parameter set and model over the same inputs on a second machine, and record what differs. The third is a change-impact test: change one variable and record the direction and size of the effect. Multi-site work shows the value of this discipline, since harmonisation performed step-wise, one variable at a time, makes each difference interpretable, and reference tissues are recommended both to validate markers and to maintain comparability afterwards.14
The fourth check is the one people skip: a human gate between the automated stages and the reported numbers. A published high-throughput mIF workflow built on automated staining and multispectral imaging still had every image manually quality checked for technical and tissue artefacts before acceptance.6 Automation there was described as a potential improvement in reproducibility over manual methods, and as something that would improve it further if reagents were more standardised.6 Neither statement is a guarantee, and neither removes the need for the gate. The four checks together produce an acceptance record: which pipeline version ran on which reference set, who reviewed it, what changed, and whether the change is accepted. That record tells the next analyst whether a re-analysis is needed, and it is what a reviewer can see.
Where automation stops and people start
Every successful mIF pipeline contains steps that should not be automated, and the discipline is knowing which ones. A published protocol for whole-slide analysis of multiplexed tumour tissue is instructive here, because it pairs QuPath for cell segmentation based on DAPI nuclear staining and supervised multi-marker phenotyping with a separate environment for intercellular distance calculation and data visualisation, and opens by noting that the choice of tool should depend on the specific analysis needs.7 QuPath’s own documentation reaches the same conclusion from the scripting side: it is often better to break the analysis up into smaller pieces, some scripted and some manual.2
So the practical test is not “can this step be scripted” but “is this step a rule”. Cell detection with a fixed parameter set is a rule; region selection in a heterogeneous tumour is judgement. Phenotype assignment from a locked rule set is a rule; phenotype discovery by clustering is exploration, and exploratory work is where automation is least safe. QuPath’s open-source architecture was designed to let researchers build and share new algorithms, alongside the batch-processing and scripting functionality the platform ships with.5 Extending the platform and validating a pipeline are different activities; conflating them is how cohorts acquire results nobody can reproduce.
What the existing QuPath content does not cover
The available QuPath guidance is good, and this article builds on it rather than replacing it. But its shape is tutorial-shaped and single-image-shaped. The results returned for a query about QuPath batch processing and multiplex immunofluorescence pipelines included several Chinese-language installation and single-image walkthroughs, an English explainer on applying one workflow to a whole project, a vendor-neutral piece on workflows and scripting, and API reference pages — but no document that treats the pipeline as a parameterised, versioned production system with an auditable run record.
Two gaps follow. First, almost nobody separates the script from the parameters from the model when claiming reproducibility; the parameters usually live inside the script, where a reviewer cannot see them and a re-run cannot change them without a code change. Second, “reproducible” is nearly always asserted rather than operationalised — there is rarely a concrete artefact, a manifest field list, or an acceptance record another analyst could use. A related boundary problem belongs elsewhere: the method itself is in our mIF image analysis workflow article, the acquisition settings the parameter file must reference are covered in signal intensity and autofluorescence, and multi-round alignment in registration. This article is about the layer that runs all of those across a cohort.
Where this leads for TerryDR
If the decision is to build, TerryDR’s own pages describe the pieces such a build is assembled from. The manufacturer describes its analysis platform as nine modules covering the full workflow, and the TR-AI assistant as a component where you state what you need and it plans the analysis, runs the toolchain and shows progress in real time, with remote control from WeChat; the module set includes segmentation, phenotype classification with auditable marker-logic rules, phenotype discovery, spatial decoding, registration, preprocessing and tissue-microarray detection.15 On the solutions page, the manufacturer names the shortage of dedicated image-analysis staff and the learning curve of QuPath and code among the pain points it addresses.16 Its about page gives the origin story: a pathologist and a computer-vision engineer wrote their first QuPath script to quantify tumour-infiltrating lymphocytes, and one of the four stated product principles is “Reproducibility First” — the same protocol should produce the same result on different days, instruments and sites, with every step auditable.17 Those are manufacturer statements, and the question this article has been answering is what a lab must do to earn them.
If the decision is not to build, the service page describes a managed alternative — delivery framed as results plus process plus evidence, separate project accounts per client, cloud storage for long-term retention and on-demand audit, and delivery of raw images, regions of interest, detection results and intermediate data rather than summary tables alone.18 The build-versus-buy reasoning is in our outsourcing guide.
Frequently asked questions
Do I need to write Groovy to build a QuPath batch pipeline?
Not for the first step. QuPath can turn a recorded workflow into a script without you writing code, and the command line can run that script over a project with parameters passed in from outside. You will write Groovy when the recorded workflow stops being enough — when the run must loop over parameter sets, write a manifest, or fail loudly on a missing input. The script editor’s default imports expose the methods QuPath itself uses for batch scripts.
How should I store parameters so a run can be repeated?
Store them outside the script, in a versioned file loaded at run time. The reason is reviewability: a threshold change should show up as a diff in a parameter file that someone signs off, not as a line edited inside a script nobody re-reads. Keep the script free of result-affecting values so the same script can run against several parameter sets — that is what lets you measure the effect of one change instead of guessing at it.
Our workflow relies on hand-drawn regions of interest. How do we automate it?
Accept that some steps are manual, and make the boundary explicit. The documented pattern is to perform the manual steps and save them for every image first, then run the automated script across the project, which processes the last saved version of each image. Treat the saved annotations as a versioned input to the pipeline rather than as part of the script, and record who drew them and under what rule.
What should a run manifest contain to satisfy a journal or reviewer?
The reporting vocabulary already exists: software and package names with versions and modules, plus enough detail to access the data and reproduce the results, ideally with a persistent identifier such as a GitHub release tag for code and run parameters. The best-practice guidance adds raw outputs, processed results, key analysis programs and source code. A manifest recording software version, script identity, parameter-set identity, model identity, input list, channel map and exact command line covers that vocabulary for one run.
When should a lab stop building its own pipeline?
Stop when the pipeline has become the job rather than the tool: when maintaining it consumes more analyst time than running it, when only one person can make a result, or when the questions you cannot answer are about provenance rather than biology. At that point the realistic options are a managed service or a supported platform rather than a better script. The test is whether its output can be defended without its author in the room.
Sources
[1] https://qupath.readthedocs.io/en/latest/docs/advanced/command_line.html — QuPath command line — official documentation (QuPath 0.7.0)
[2] https://qupath.readthedocs.io/en/stable/docs/scripting/workflows_to_scripts.html — QuPath workflows to scripts — official documentation
[3] https://qupath.readthedocs.io/en/latest/docs/scripting/overview.html — QuPath custom scripts (scripting overview) — official documentation
[4] https://qupath.readthedocs.io/en/latest/docs/intro/versions.html — QuPath versions and versioning policy — official documentation
[5] https://pmc.ncbi.nlm.nih.gov/articles/PMC5715110 — Peer-reviewed open-source software paper on QuPath for digital pathology image analysis (PMC5715110)
[6] https://pmc.ncbi.nlm.nih.gov/articles/PMC9033818 — Peer-reviewed report of an automated high-throughput multiplex immunofluorescence staining, imaging and analysis workflow (PMC9033818)
[7] https://pmc.ncbi.nlm.nih.gov/articles/PMC11541771 — Peer-reviewed step-by-step protocol for whole-slide image analysis of multiplexed tumour tissue using QuPath and R (PMC11541771)
[8] https://pmc.ncbi.nlm.nih.gov/articles/PMC12718562 — SITC consensus reporting checklist for multiplex immunohistochemistry/immunofluorescence assays (STORMI, PMC12718562)
[9] https://pmc.ncbi.nlm.nih.gov/articles/PMC11749220 — SITC best-practice guidance on multiplex IHC/IF image analysis and data sharing (PMC11749220)
[10] https://pmc.ncbi.nlm.nih.gov/articles/PMC8438151 — Peer-reviewed review of technical reproducibility assessment for multiplex immunofluorescence (PMC8438151)
[11] https://arxiv.org/abs/2108.09499 — MITI minimum-information standard for highly multiplexed tissue images — abstract record
[12] https://github.com/miti-consortium/MITI — MITI: Minimum Information about Tissue Imaging — consortium specification repository
[13] https://www.gofair.foundation/fair-principles — The FAIR Guiding Principles — GO FAIR Foundation
[14] https://pmc.ncbi.nlm.nih.gov/articles/PMC9777693 — Multicentre multiplex tissue imaging harmonisation report from the CIMAC-CIDC network (PMC9777693)
[15] https://www.pathoaxis.com/software — TerryDR mIF image analysis software page — manufacturer description
[16] https://www.pathoaxis.com/solutions — TerryDR solutions by industry page — manufacturer description
[17] https://www.pathoaxis.com/about — TerryDR about page — manufacturer description
[18] https://www.pathoaxis.com/service — TerryDR mIF image analysis service page — manufacturer description
Ready to run this on your own slides?
Send us a sample image or your panel design. A TerryDR specialist replies within one business day with a flat analysis plan or a product recommendation.