Panels
Runs one chain of plugins over many files, each on its own, and writes every file's table, numbers and figures to an output folder with a summary of all of them.
An analysis that works on one cell usually has to be done on thirty: the same filter, the same drift correction, the same measurement, with the same settings, and the numbers collected into one table. Clicking through it thirty times is slow, and it is easy to change a setting by accident on the seventeenth.
The batch window takes a chain – an ordered list of plugins with their settings, which runs as one – and a list of files, and runs the chain on every file, one after another. Each file is opened in a fresh session of its own, processed, saved and closed, so nothing carries over from one file to the next, and a file that fails is marked failed while the batch goes on with the rest. Every file gets its own output folder, with the processed table, the figures each step drew and a record of each step's numbers; the batch as a whole gets a table with one row per file.
The chain can start with a fit (a Localize plugin), and then the inputs are raw camera images; otherwise they are localization files. The line above the files says which. Either way the batch runs once per data set: a localization file, or one acquisition – a TIFF stack, a Micro-Manager series however many files it fills, an NDTiff folder, a DCIMG series.
With watch the folders ticked, the batch does not end with the files there are: it keeps looking at the folders and runs the chain on each new file as soon as the microscope has finished writing it – for a folder that fills during a day of acquisitions, or the same bead sample measured every week. A summary page in the output folder shows every file with its figures and numbers, and plots chosen numbers across the files in the order they were taken, so a change in the instrument shows as a trend.
It opens from Plugins > Batch..., or on its own as smappy-batch-gui. It is a front end to the job file and the command smappy-batch: everything it does can be repeated from a terminal with the file it writes. The ? at its top right (or F1) opens this page.
1. The job. The files, the chain and the output options together are a job, saved as a .batch.yaml file. Run saves it first (asking for a name the first time), then starts smappy-batch run on it as a separate program. A crash or a file that exhausts the memory ends that program, never this window or the session in the main window behind it.
2. Validation. Before anything runs, the job is checked strictly: every setting a step names must be one the plugin has, every choice one it offers, every file and folder must exist, and the files must resolve to at least one input. Errors stop the run and are listed in the log; warnings – a step saved with an older version of its plugin, a second step that makes a table of its own – are listed and the run goes ahead.
3. The files. A line of the files list is a data set added on its own, or a folder. A folder stays a folder: it unfolds into the data sets found in it and its subfolders, of the kind the chain reads, and they are found again at every run and, while watching, every two seconds – so a data set written later is run too. A folder holding raw stacks and their fits gives the stacks to a chain that fits and the fits to one that does not. A file of the other kind stays in the list, greyed and marked skipped: changing the chain back brings it back. The filter narrows a folder by name (see In detail), and unticking a data set leaves it out. A data set named twice – by a folder and again on its own – is processed once, in its first place. The output folder is never searched, so a second run does not take its own results for input.
4. One file. For each file the chain's settings are put together: the chain's values, then the job file's overrides, if it has any. If the chain starts with a fit, the file becomes the fit's input; otherwise it is opened as a localization file. The chain then runs as it would in a plugin tab – one step after the other, each seeing what the steps before it did – and the result is saved. A step that would ask before running (this will take an afternoon) is answered by when a step asks.
5. What is re-run. Every finished file records a fingerprint of how it was made: every setting of every step after the overrides, the version of every step's plugin, the output options that change what is written, and the input file's size and modification time. With files already done on skip_identical, a file whose last run finished with the same fingerprint is skipped. So editing one step and running again redoes every file, while running again unchanged redoes nothing – and a plugin whose version was bumped because its numbers moved is re-run on every file, while one whose code changed without a new version is not.
6. The report. The output folder holds, per input, a folder named after it, and for the whole batch summary.csv, batch_report.json and the summary page, index.html (see Output), all written again after every file, so they can be read while the batch runs. The list's status follows the run as it goes: running, done, skipped or failed, with the reason in the tooltip, and a folder counts its data sets.
7. Watching. With watch the folders ticked, Run processes the data there is, then looks at the folders every 2 seconds. A new data set appears under its folder and is run once it is complete: a localization file written by SMAPpy's fitter once the fit has closed it – the file says so itself, so a live acquisition that pauses for minutes is never taken half-way – and any other file once neither its size nor its time stamp has changed for 10 seconds (of every file it is written in: all of a Micro-Manager series, all of an NDTiff folder). What is done already is skipped as in step 5, so a watch started again on the same folder carries on where it was, and a file that changes after it was run is run again. The watch runs until Stop.
The filter is shell patterns – * any text, ? one character, [0-9] one of a set, [!0-9] one not in it – matched, regardless of case, against a data set's path inside the folder and against its name, so *640* finds 640 anywhere and beads/* a subfolder. Patterns are joined by , or | (either), & (both) and ! before one (not), or the words OR, AND, NOT, and grouped by parentheses; NOT binds tightest, then AND, then OR, as in most search boxes: (*640* & !*647*), *600* keeps the 640 data sets that are not also 647, and every 600 one. A pattern runs up to the next operator, so a name may hold spaces; one holding an operator or a parenthesis is quoted, "cell (2)*". A filter that cannot be read says where in the folder's status, and the job does not run.
The fingerprint is the first 16 hex digits of a SHA-256 hash of
<step key>.<field>, after the job's and the file's overrides (and with the file itself filled in as the first step's input);(plugin path, version) of every enabled step;A file is skipped only if its folder's results.json says done with the same fingerprint: a failed file, or one skipped because a step asked, is tried again. A file skipped as unchanged keeps its row in summary.csv, read from the results.json of the run that made it. Delete the fitted file afterwards and the output folder are not part of the fingerprint; the output folder does not need to be, since the record lives in it.
The summary has one row per file – the file, its status, the seconds it took, the number of localizations and any message – and a column for every single number or word a step returned in its data, as <step key>.<name> (nested dictionaries give dotted names). Columns appear in the order they are first met. In results.json a step's data is kept as far as it is JSON: arrays and lists of up to 1000 values, nested dictionaries; tables and anything larger are left out, and a NaN is written as null.
The trends on the summary page are the summary.csv columns named in trend columns (patterns such as stats.* allowed), one panel each, against the time each file was taken: Micro-Manager's StartTime where the file's metadata has it, else the input's modification time, else simply the files in order. A failed file has no point; the dashed line is the median. With trend columns empty, every number that differs between the files is plotted, except one that repeats a column before it, at most twelve, the seconds each file took last. A number the same in every file is usually a setting echoed back, and is left out.
Names. A file's output folder is its name without the extension (and without .ome.tif or _sml.mat); two inputs with the same name get their parent folder's name in front, and a number if even that is not enough.
The run exits with 0 when every file was done (or already was), 1 when any failed or the batch was stopped by a step's abort, and 2 when the job did not validate; the log's last line says which. A watch exits with 0 once stopped.
What the batch runs. The line at the top says what the chain reads. A folder unfolds into the data sets found in it: untick one to leave it out. The filter column narrows a folder by name – double-click it to type, for example *640*, !*bead* or (*640* & !*647*), *600* (see In detail). The status column says how many data sets a folder gives, why a file is skipped, and, while the batch runs, what became of each. Files, folders, a .chain.yaml or a .batch.yaml can also be dropped onto the window.
Adds files. On a Mac it takes files and folders together, several at once; elsewhere the system's dialog takes files only, and a folder is added with the arrow beside it. A folder is added as a folder, and an NDTiff folder, which is one acquisition, as a data set.
In the arrow beside Add...: a dialog in which several folders can be selected at once (Cmd- or Ctrl-click). It is not the system's own dialog, which takes only one folder.
Removes the selected inputs; a data set selected inside a folder is unticked instead, since the folder would find it again.
Removes every input.
Whether a folder's data sets are looked for in its subfolders too.
Runs the data there is, then each new data set in the folders as soon as it is complete (see How it works), until Stop. The folders may be empty at the start. first file only does not apply. Not needed after a live fit: a fitter's after the fit runs its steps there already.
The chain to run: pick a saved one from the list (the chains in the plugin folders and the chains folder), open a file, or start a new one. It shows the same panel a chain has in a plugin tab, so a chain is edited here as it is there; it cannot be run on the session from here, only saved and run over the files. Each step is a folded section with a tick in its title: ticked, the step runs; unticked, it stays in the chain with its settings and is skipped. Unfolding a step shows its settings. A right click on a step's title renames it, moves it up or down, or removes it. The label a step is renamed to, made into an identifier, is the step's key: what overrides and the summary's columns are named by (NPC radius -> npc_radius). To set up the layers and filters every file is to get, put a Layers step first: without it each file is filtered as a freshly opened one is.
Opens a .chain.yaml file.
Starts an empty chain, with build open.
Folded under the chain's file name: the tools that change which steps it has. Opened by itself for a new, empty chain.
In build's title line, so it is there with build folded: adds a plugin as a step, after the step last opened, or into it if it is a block.
In build: adds a block, steps repeated in each ROI or in each region of an id attribute (see docs/regions.md).
In build: times a block in a few of its regions and says what the whole will take, and which attributes its steps change without writing them back.
Chooses the settings the chain asks: tick a step's setting and type the label it goes by in the chain. The chain's form then shows those at the top and folds its steps away behind show the steps, a tick that only such a chain has: every step's settings are still saved and run, and the tick shows them. The batch window shows the chain the same way. Saved with the chain (interface: in its file); see docs/batch.md, "A chain's interface".
In the ⋯ menu beside the chain's file name. Writes the chain to its file; one that has none asks where, starting in the chains folder. Saved in a plugin folder or the chains folder, the chain also appears in the plugin tree. A job refers to a saved, unchanged chain by its file; a chain that is not saved or has changes is written into the job itself.
In the ⋯ menu. Writes the chain to a new file.
In the ⋯ menu. Replaces the chain shown by a saved one; the same as open... above it.
Whether a step reads every localization or the blinks merged – merge blinks (also called grouping or linking) combines the localizations in consecutive frames that come from one blinking event into one row: per step, and for the whole chain under more. The choices are merged, not merged and auto (the chain's) or, for the chain, as each layer (as the Render tab has it). The rules are in docs/batch.md ("Grouping"): the plugin's own requirement wins, then the step's choice, then the chain's, then each layer's.
Where the results go and what is written.
The output folder. Empty: <job>_output beside the job file.
Folds out the options most batches leave as they are: the file suffix, where a fit writes its file, what to do when a step asks, which files are re-run, and the trend columns.
Added to the input's name for the processed table: cell3_proc.h5. An input .h5 is never overwritten.
Writes each file's table, with its history (which ends with the chain's entry, every step's settings in it) and what each step kept. Untick it for a chain that only measures and whose numbers are all you want.
The format the steps' figures are saved in, one file per figure, or none.
For a chain that starts with a fit: where the fit writes its own localization file, beside_image (where the fit would put it anyway) or in the file's output folder.
Deletes the fit's own file once the processed table is saved, which then is the only copy.
What to do with a file a step would ask about before running (COMET's "this will take hours"): skip the file, proceed anyway, or abort the whole batch.
skip_identical skips a file whose last run finished with the same settings, plugin versions, output options and input file (see How it works); always runs every file again.
Empty plots every number that differs between the files. Name a few to follow over time, the ones that say the instrument is as it was – the precision, the photons, the number of localizations – and leave out the ones that differ because the cells do.
A menu: Open job... opens a .batch.yaml file into the window; Save job... writes the job to one, which smappy-batch run can run from a terminal. Run saves it too.
Opens a .batch.yaml file into the window.
Writes the job to a .batch.yaml file.
Runs only the first file: a trial run, to check the numbers and figures before the rest.
Checks the job – every setting a step names, every file and folder, every filter – and lists what is wrong in the log, then saves the job (asking for a name the first time) and starts the batch. The progress bar counts files; the status bar shows what the current step says.
Ends the batch program. A file cut off half-way has no finished record, so the next run does it again; the files already done are kept. A watch is asked to stop instead, and ends once the file in hand is done, with its summary written; pressing Stop again ends it at once.
A menu of what the batch wrote.
Opens the summary page, index.html, in the system's browser.
Opens the output folder in the system's file browser. Opened from the main window, it asks for a processed file instead and opens it there.
In the output folder, per input, a folder of its name with
<name><suffix>.h5 – the processed table (if save the processed localizations);<name>_locs.hdf5, if fitted file is output (and not deleted);figures/<step key>_<figure>.<format>;results.json – the status, the time it took, the fingerprint, and per step the line it reported, its settings and its numbers; a traceback if it failed.and for the batch
summary.csv – one row per file, a column per number any step returned: the table to take to a statistics program;batch_report.json – the job and the chain as they were resolved, the plugin versions, the list of files the folders resolved to, and each file's status, message and traceback. It is the record of which files a run saw;index.html – the summary page: a row per file with its status, when it was taken, its figures as thumbnails (click for the full figure) and its numbers, and above them trends.png, the trend columns across the files. It is a plain page with relative links: the output folder can be zipped or copied and the page still works. While a batch or a watch runs it reloads itself every 20 seconds.A good run ends with finished in the log and every row done or skipped. finished, with failures: hover over a failed status or read that file's results.json for the reason, fix it, and run again – only what failed or changed is redone.
Based on SMAP's BatchAnalysis (Analyze plugins over a list of files) and its fitting Batchprocessor (Ries 2020). The main changes:
BatchAnalysis the per-plugin error handling is commented out, so one failure ends the batch; here the file is marked failed, the reason recorded, and the batch goes on._results.mat struct; here each file's numbers go into its results.json and into one summary.csv.