Workflows
BRT Workflow
Overview:
A number of parameters can be passed to the “BRT” workflow. There are two types: 1) params that are passed to the adoc file. See adoc / https://bio3d.colorado.edu/imod/doc/directives.html 2) params that are used elsewhere within the worflow, providing metadata etc, eg input_dir.
Note: objects passed between Prefect Tasks (eg FilePath objects), must be considered immutable. Updates to state made in one task will be lost and not available to the next task. Create a new object. The map function is used extensively, and preserves order.
TomoJS 3D pipeline for tomographic reconstruction.
The term “batch run tomo[gram]” is abbreviated BRT.
Processes
Generate BRT Directive File
- Description:
Generate a configuration file of parameter for BRT process.
- Outputs:
a BRT directive file with a .adoc file extension.
Alternatively, the file could be provided and this step skipped. The directive file format is documented IMOD’s batchruntomo documentation. There is specific descriptions of the directives specified in a “directives.csv” file within IMOD.
The following is a Jinja like template for key-value pairs to be configured. The {{ }} denotes where the substitution should be made. Inside the curly brackets is a suggested parameter name for the value with defaults in parenthesis:
setupset.copyarg.name={{ basename }}
setupset.copyarg.gold={{ beadSize (~10)}}
setupset.copyarg.pixel={{ pixelSize }}
comparam.prenewst.newstack.BinByFactor={{ bin (4) }}
comparam.track.beadtrack.LightBeads={{ lightBeads (0) }}
comparam.tilt.tilt.THICKNESS={{ thickness (~256) }}
runtime.AlignedStack.any.binByFactor={{ bin }}
setupset.copyarg.montage={{ montage (0) }}
setupset.datasetDirectory={{ local processing folder (POSIX convention) }}
The existing directive file is dirTemplate.adoc with empty values that can be updated as above.
BRT support multiple layers of “Template Files” so that directives can be defined for a microscope, system, and user. The other directive files can be defined as parameters it the batch directive file provided on the command line.
BatchRunTomo (BRT)
- Description:
Perform computational expensive operations of processing an acquired tomography tilt-series and reconstructing a 3D volume. The process consists of numerous step to prepare, align, and perform 3d reconstruction from the tilt series acquired by the microscope.
- Inputs:
the original image from the microscope usually with an .mrc extension (.st possible ). The filename part before the final “.” is considered the BASENAME.
BRT directive file
- Primary Outputs:
BASENAME_rec.mrc - the source for the reconstruction movie
BASENAME_full_rec.mrc - the source for the Neuroglancer pyramid
BASENAME_ali.mrc - the source for the tilt movie
- Auxiliary Outputs:
Other outputs such as logs and transformation files may need to be saved as well.
The process is IMOD’s batchruntomo, run with the following command line arguments:
batchruntomo -di BASENAME.adoc -gpus 1 -cpus 20
The gpus is for configuring the local GPU, and cpus configures the number of cores to use. Many temporary and log files are created during this process.
Generate tilt movie
- Description:
Convert a MRC file of the aligned tilt series into a movie for easy viewing.
- Inputs:
BASENAME_ali.mrc - the aligned 2d slices of image stack
- Outputs:
Generates a tilt movie for easy viewing
The key thumbnail is keyimg_BASENAME_s.jpg, the corresponding MIDDLE_I is the full size.
dimensions = (header -s ${BASENAME}_ali.mrv) # space separated list of dimensions sizes (x y z)
MIDDLE_I = floor(dimensions.z/2))
for i in dimensions.z\:
newstack -secs {i}-{i} ALI_FILENAME WORKDIR/hedwig/BASENAME_ali{i}.mrc
newstack -float 3 WORKDIR/hedwig/BASENAME_ali*.mrc WORKDIR/hedwig/ali_BASENAME.mrc
mrc2tif -j -C 0,255 WORKDIR/hedwig/ali_BASENAME.mrc WORKDIR/hedwig/BASENAME_ali
gm convert -size 300x300 WORKDIR/hedwig/BASENAME_ali.{MIDDLE_I}.jpg -resize 300x300 -sharpen 2 -quality 70 WORKDIR/hedwig/keyimg_BASENAME_s.jpg
ffmpeg -f image2 -framerate 4 -i ${BASENAME}_ali.%03d.jpg -vcodec libx264 -pix_fmt yuv420p -s 1024,1024 tiltMov_${BASENAME}.mp4
Generate reconstruction movie
- Description:
Convert a MRC file of the reconstructed 3D volume into a movie for easy viewing.
- Inputs:
BASENAME_rec.mrc - the reconstruction of the 3d volume ( may already be binned by some factor when compared to full).
- Outputs:
Generates a movie of the reconstructed 3D volume.
for i in range(2, dimensions.z-2):
IZMIN = i-2
IZMAX = i+2
clip avg -2d -iz IZMIN-IZMAX -m 1 WORKDIR/BASENAME_rec.mrc WORKDIR/hedwig/BASENAME_ave${I}.mrc
newstack -float 3 WORKDIR/hedwig/BASENAME_ave* WORKDIR/hedwig/ave_BASENAME.mrc
binvol -binning 2 WORKDIR/hedwig/ave_BASENAME.mrc WORKDIR/hedwig/avebin8_BASENAME.mrc
mrc2tif -j -C 100,255 WORKDIR/hedwig/ave_BASNAME.mrc hedwig/BASENAME_mp4
ffmpeg -f image2 -framerate 8 -i WORKDIR/hedwig/BASENAME_mp4.%04d.jpg -vcodec libx264 -pix_fmt yuv420p -s 1024,1024 WORKDIR/hedwig/keyMov_BASENAME.mp4
Generate Neuroglancer Pyramid
- Descriptions:
Generates a Neuroglancer precomputed pyramid from an MRC file of a 3D volume. This does not work for tilt series, or other non-volumetric files.
- Inputs:
A MRC file of a 3D volume.
- Outputs:
A directory structure of the precomputed pyramid.
- Steps:
1. Convert the MRC file to NIFTI (.nii). The Neuroglancer file format only support unsigned integer of 8 or 16 bits. When this input is a signed integer the output pixel types needs to be changed and the pixel values adjusted. The NIAID tomojs-pytools mrc2nift command-line tool can do this conversion. 2. The neuroglancer-scripts tools are used to convert the NIFTI file to the precompute format:
volume-to-precomputed-pyramid --downscaling-method=average --no-gzip --flat nifti.nii {WORKDIR}/hedwig/neuro-BASENAME
3. The default minimum and maximum values used for visualization also need to be computed from the NIFTI file. The NIAID tomojs-pytools mrc_visual_min_max performs this computation:
mrc_visual_min_max {WORKDIR}/nifti.nii --mad 5 --output-json mrc2ngpc-output.json
The cloud-volume tool may be an alternative tool for the precompute conversion.
Multi-channel Microscopy Workflow (CZI/SVS/OME-TIFF)
Overview:
This workflow is referred to externally by Hedwig as the Multi-channel pipeline. It processes multidimensional microscopy images stored in CZI (ZEISS), SVS (Aperio), and OME-TIFF file formats. Supported image types include immunofluorescence (IF) multi-channel images (e.g., z-stacks, time lapse, and multiposition experiments) as well as RGB brightfield images such as H&E-stained CZI slides. The workflow converts input files to OME-NGFF zarr format, generates neuroglancer-compatible metadata, and creates thumbnail images for visualization and downstream analysis.
Outputs: 1. OME-NGFF zarr file for each input file, including OME-XML metadata. 2. Neuroglancer metadata for each sub-image (scene/channel) in the zarr file. 3. Thumbnail JPEG image for each label sub-image.
Format Type |
Description |
Extensions |
|---|---|---|
CZI |
ZEISS multidimensional microscopy image (IF multi-channel and RGB H&E brightfield) |
czi, CZI |
SVS |
Aperio whole-slide image |
svs, SVS |
OME-TIFF |
Open Microscopy Environment TIFF; supports single-file and multi-file datasets with modality interpreted from embedded OME-XML metadata |
ome.tiff, OME.TIFF, ome.tif, OME.TIF |
The workflow relies on OME Bio-Formats (via the bioformats2raw tool) for reading CZI, SVS, and OME-TIFF files.
Visualization is performed with Neuroglancer.
Input File to Zarr Conversion - Uses
bioformats2rawto convert CZI, SVS, or OME-TIFF files to OME-NGFF zarr format, preserving OME-XML metadata. - Output:.zarrdirectory for each input file.Rechunking Zarr - Re-chunks the zarr structure so that multi-channel/RGB channels are not split between chunks, using
zarr_rechunkfrom tomojs-pytools.Copy Zarr to Assets Directory - Copies the generated zarr files to the assets directory for downstream use.
Generate ImageSet and Thumbnails - For each sub-image in the zarr file:
Determines the shader type:
RGB(for H&E and other RGB images),Grayscale, orMultiChannel(for IF fluorescence images).Generates neuroglancer metadata (shader, dimensions, shader parameters).
For label sub-images, generates a thumbnail JPEG using SimpleITK (rotated 90° for correct orientation).
Macro sub-images are ignored.
Metadata Attachment - Attaches the OME-XML metadata file location to the zarr group for developer reference and provenance.
Callback and API Notification - Sends results and metadata to the API callback URL if provided.
Format Type |
Description |
Processing Information |
|---|---|---|
CZI (IF multi-channel) |
Multidimensional immunofluorescence image (z-stacks, time lapse, multiposition) |
Converted to OME-NGFF zarr; neuroglancer metadata generated with |
CZI (RGB H&E) |
RGB brightfield whole-slide image (e.g., H&E stained tissue) |
Converted to OME-NGFF zarr; neuroglancer metadata generated with |
SVS |
Aperio whole-slide image |
Converted to OME-NGFF zarr; neuroglancer metadata generated; thumbnails created for label sub-images. |
OME-TIFF |
Open Microscopy Environment TIFF |
Converted to OME-NGFF zarr via |
Note
Macro sub-images in the input file are ignored by the workflow.
Label sub-images are used for thumbnail generation; the thumbnail is rotated 90° for correct orientation.
OME-XML metadata is attached to the output zarr for troubleshooting and provenance.
The shader type (
RGB,Grayscale, orMultiChannel) is determined automatically from the OME-XML metadata of each sub-image.For OME-TIFF files,
bioformats2rawautodetects embedded OME-XML regardless of whether it is stored inline in the TIFF header or as a companion.ome.xmlsidecar file. Theome.tiff/ome.tifcompound extension (case-insensitive) is used to identify OME-TIFF inputs.Multi-file OME-TIFF datasets (where image planes are split across multiple TIFF files) are supported. Set
single_fileto the name of the first TIFF file in the series;bioformats2rawwill locate and assemble the remaining files automatically via the embedded OME-XML file list.
Spatialomics Workflow
Normally the dir structure is : $lab/$pi/$project/$session/$sample
For Spatialomics this is not the case, the $sample is not really a sample, it’s grouping of ROIs, PreROIs, etc from each of the slides.
These grouping directories sit one down from session, in the place a $sample normally would be.
For a single unit of work (eg 8 slides) the set up looks like
$lab/$pi/$project/$session/Pre_ROI_Selection
$lab/$pi/$project/$session/Heatmaps
$lab/$pi/$project/$session/HQ_Images
$lab/$pi/$project/$session/ROI_Images
and eg:
ls $lab/$pi/$project/$session/HQ_Images/
slide_1.czi, slide_2.czi, ...
and
ls $lab/$pi/$project/$session/Pre_ROI_Selection
slide_1_Pre_ROI_a.png, slide_2_Pre_ROI_a.png, ...
Note: Different outputs from different slides are split across different dirs. The pipeline will not parse out or otherwise link slides together in any way. Similarly there is no linking from from heatmaps to any specific slide.
Also, other directories can exist in this directory, which will be ignored.
Small 2D Workflow (EM Microscopy)
Overview:
This workflow generates a thumbnail and a key images for each input image in a directory. Specific EM file formats use enhanced resampling and filtering techniques to reduce noise while adjusting the dynamic range of the images. This workflow originally was designed to handle DM3 files from TEM or STEM microscopes but has been extended to handle other 2D image file formats, including MRC, TIFF files and color figures.
- Outputs:
A thumbnail image for each input image.
An JPEG image with a maximum size of 300 pixels in both dimension.
The aspect ratio is preserved and may be shortened to fit within the maximum size without padding.
The image may be 8-bit RGB(A) or 8-bit gray-scale.
A key image for each input image.
Similar to the thumbnail image but with a maximum size of 1024 pixels in both dimension.
The toolbox of IMOD is used primarily to process the EM images, along with SimpleITK for additional image processing tasks.
Format Type |
Pixel Type |
Description |
Processing Information |
|---|---|---|---|
JPEG, PNG, TIFF |
8-bit RGB (palette) or RGBA |
Example images include figure, TEM grid image or other illustrative images rendered into a color image. |
Images should directly resized without intensity scaling or advanced filtering. |
TIFF, PNG, JPEG |
8-bit gray-scale |
Images may be rendered EM images with captions or annotations. |
Images should directly resized without intensity scaling or advanced filtering. |
TIFF |
16-bit (signed or unsigned) gray-scale |
EM images with a high dynamic range. |
Use IMOD’s newstack tool to resample, filter, and scale intensities to 8-bit. |
DM4 or DM3 Images |
32-bit float (after MRC conversion) |
Minimally processed EM images with a high dynamic range. |
Convert to MRC via dm2mrc command to 32-bit float MRC files, then use newstack to resample, filter, and scale intensities to 8-bit TIFF. |
MRC (2D only) |
32-bit float ( no other current sample inputs ) |
Expected EM images with likely high dynamic range. |
Convert to 8-bit TIFF via newstack command to resample, filter, and scale intensities to 8-bit. |
Large 2D RGB Workflow
Overview:
This workflow is referred to externally by Hedwig as the Flat 2D pipeline. It processes large 2D RGB images (PNG or TIFF) to produce an OME-NGFF zarr pyramid suitable for Neuroglancer visualization, along with a thumbnail and a key image for browsing. The pipeline is intended for any large 2D image that requires Neuroglancer visualization, including annotated micrographs, color composites, and other 2D figures.
- Outputs:
OME-NGFF zarr pyramid (neuroglancerZarr asset) for Neuroglancer visualization, including neuroglancer metadata.
Thumbnail JPEG image — maximum 300 × 300 pixels, aspect ratio preserved.
Key image JPEG — maximum 1024 × 1024 pixels, aspect ratio preserved.
Format Type |
Description |
Extensions |
|---|---|---|
PNG |
Portable Network Graphics |
png, PNG |
TIFF |
Tag Image File Format |
tif, TIF, tiff, TIFF |
The workflow uses ImageMagick for input normalization, OME Bio-Formats (via bioformats2raw) for zarr
conversion, zarr_rechunk from tomojs-pytools for rechunking, and SimpleITK for thumbnail and key image
generation. Visualization is performed with Neuroglancer.
Input Normalization to TIFF - Uses ImageMagick
convertto produce a normalized TIFF from the input PNG or TIFF file. - Alpha transparency is removed and replaced with a white background. - Tile geometry is set to 128 × 128 pixels for downstream processing optimization. - Output:.tifffile in the working directory.TIFF to Zarr Conversion - Uses
bioformats2rawto convert the normalized TIFF to an OME-NGFF zarr pyramid. - Output:.zarrdirectory in the working directory.Rechunking Zarr - Re-chunks the zarr structure so that multi-channel/RGB channels are not split between chunks, using
zarr_rechunkfrom tomojs-pytools.Copy Zarr to Assets Directory - Copies the rechunked zarr to the assets directory for downstream access.
Generate Neuroglancer Asset - Reads the zarr from the working directory to compute metadata. - Determines the shader type (
RGB,Grayscale, orMultiChannel) automatically from the image data. - Produces aneuroglancerZarrasset pointing to the0(full-resolution) level of the zarr in theassets directory, along with neuroglancer metadata (shader, dimensions, shaderParameters).
Note
The
dimensionsfield is currently hardcoded toXYas the GUI does not acceptXYCfor this pipeline.Generate Thumbnail and Key Image - Uses SimpleITK to extract and resize the image from the working zarr. - Thumbnail: maximum 300 × 300 pixels, written as JPEG (quality 90). - Key image: maximum 1024 × 1024 pixels, written as JPEG (quality 90). - Both images are copied to the assets directory.
Callback and API Notification - Sends results and metadata to the API callback URL if provided.
Format Type |
Description |
Processing Information |
|---|---|---|
PNG |
Color or grayscale PNG image, possibly with alpha transparency |
Normalized to TIFF (alpha removed, white background); converted to OME-NGFF zarr; neuroglancer metadata and thumbnail/key image generated. |
TIFF |
Color or grayscale TIFF image |
Normalized to TIFF (alpha removed, white background); converted to OME-NGFF zarr; neuroglancer metadata and thumbnail/key image generated. |
Note
All inputs pass through the TIFF normalization step regardless of format. This ensures a consistent tiled TIFF with alpha removed for reliable zarr conversion.
The shader type (
RGB,Grayscale, orMultiChannel) is determined automatically from the image data.Thumbnail and key image dimensions preserve the aspect ratio and will be at most the stated maximum size.