Nextflow Workflows Guide#
Overview#
linumpy uses Nextflow for orchestrating complex processing pipelines. Nextflow provides:
Parallelization: Automatic parallel execution of independent tasks
Portability: Run on local machines, clusters, or cloud
Reproducibility: Containerized execution with Apptainer/Singularity
Fault tolerance: Automatic retry and error handling
Available Workflows#
Workflow |
Location |
Purpose |
|---|---|---|
|
|
Raw tiles → Mosaic grids |
|
|
Mosaic grids → 3D volume |
Prerequisites#
Nextflow Installation#
# Install Nextflow
curl -s https://get.nextflow.io | bash
# Or via conda
conda install -c bioconda nextflow
# Verify installation
nextflow -version
Required version: >= 23.10
Apptainer/Singularity (Optional)#
For containerized execution:
# Install Apptainer
sudo apt install apptainer
# Or Singularity
sudo apt install singularity
Preprocessing Workflow#
Location#
workflows/preproc/
├── preproc_rawtiles.nf # Workflow definition
└── nextflow.config # Default configuration
Purpose#
Converts raw OCT tiles into organized mosaic grids and extracts metadata.
Running#
cd workflows/preproc
# Basic usage
nextflow run preproc_rawtiles.nf \
--input /path/to/raw/tiles \
--output /path/to/output
# With options
nextflow run preproc_rawtiles.nf \
--input /path/to/raw/tiles \
--output /path/to/output \
--processes 8 \
--resolution 10 \
--axial_resolution 1.36
Parameters#
Parameter |
Default |
Description |
|---|---|---|
|
(required) |
Raw tiles directory |
|
|
Output directory |
|
|
Use flat folder structure |
|
|
Enable GPU acceleration (auto-fallback to CPU) |
|
|
Parallel Python processes per task (CPU mode only) |
|
|
Max concurrent |
|
|
Max concurrent |
|
|
Axial resolution (µm) |
|
|
Output resolution (-1 = full native resolution) |
|
|
Zarr sharding (NxN chunks/shard) |
|
|
Correct galvo shifts |
|
|
Correct camera shifts |
|
|
Apply rotation/flip preprocessing (true for legacy data) |
|
|
Minimum confidence to apply galvo fix |
|
|
Generate slice_config.csv |
|
|
Number of leading slices to mark as excluded |
|
|
Include galvo detection results in slice_config.csv |
|
|
Generate orthogonal view previews of mosaic grids |
|
|
Generate AIP images from mosaic grids for QC |
Outputs#
output/
├── mosaic_grid_3d_z00.ome.zarr/
├── mosaic_grid_3d_z01.ome.zarr/
├── ...
├── shifts_xy.csv
├── slice_config.csv
├── aips/ # Only when generate_aips = true
│ ├── aip_z00.png
│ └── ...
└── previews/ # Only when generate_previews = true
├── mosaic_grid_z00_preview.png
└── ...
3D Reconstruction Workflow#
Location#
workflows/reconst_3d/
├── soct_3d_reconst.nf # Workflow definition
└── nextflow.config # Default configuration
Purpose#
Processes mosaic grids through multiple correction and stitching steps to produce a final 3D volume.
Running#
cd workflows/reconst_3d
# Basic usage
nextflow run soct_3d_reconst.nf \
--input /path/to/mosaic/grids \
--shifts_xy /path/to/shifts_xy.csv \
--output /path/to/output
# With slice config
nextflow run soct_3d_reconst.nf \
--input /path/to/mosaic/grids \
--shifts_xy /path/to/shifts_xy.csv \
--slice_config /path/to/slice_config.csv \
--output /path/to/output
# Full options
nextflow run soct_3d_reconst.nf \
--input /path/to/mosaic/grids \
--shifts_xy /path/to/shifts_xy.csv \
--output /path/to/output \
--resolution 10 \
--processes 4 \
--fix_curvature_enabled true \
--fix_illum_enabled true
Parameters#
Input/Output#
Parameter |
Default |
Description |
|---|---|---|
|
|
Mosaic grids directory |
|
|
XY shifts file (default: |
|
|
Optional slice config |
|
|
Output directory |
|
|
Subject identifier (auto-extracted from path) |
|
|
Parallel Python processes per task |
Compute Resources#
Parameter |
Default |
Description |
|---|---|---|
|
|
Enable GPU acceleration (auto-fallback to CPU) |
|
|
Enable CPU limiting |
|
|
Maximum CPUs to use (0 = no limit) |
|
|
CPUs reserved for system overhead |
Resolution & Basic Settings#
Parameter |
Default |
Description |
|---|---|---|
|
|
Target resolution (µm/pixel) |
|
|
Upper percentile for intensity clipping |
|
|
Detect and compensate focal curvature artifacts |
|
|
Fix illumination inhomogeneity (BaSiCPy algorithm) |
|
|
Maximum tissue depth after interface crop (µm) |
Tile Stitching#
These parameters control how tiles within each slice are assembled in XY.
Parameter |
Default |
Description |
|---|---|---|
|
|
Use motor encoder positions for tile layout (recommended) |
|
|
Expected tile overlap fraction — should match acquisition settings |
|
|
Tile blending: |
|
|
Maximum sub-pixel refinement shift for blending (pixels) |
Global tile-placement transform (optional). When enabled, one 2×2 affine is fitted across a pool of mid-brain mosaic grids (instrument geometry is slice- invariant) and re-used for every slice. This removes per-slice scale/rotation jitter that the default refined stitcher introduces when the LS fit is underdetermined on small or sparse grids.
Parameter |
Default |
Description |
|---|---|---|
|
|
Enable pooled global affine estimation |
|
|
Optional comma-separated slice IDs to pool from (empty = all) |
|
|
Match overlap histograms before phase correlation |
|
|
Otsu-based empty-overlap filter fraction (null = simpler check) |
|
|
Max pooled pairs for the LS fit (0 = use all) |
|
|
Random seed for pair sub-sampling |
Common Space Alignment#
Aligns each slice into a shared XY canvas using shifts_xy.csv motor positions.
Erroneous shifts are corrected upstream via re-homing detection rather than
post-hoc outlier filtering.
Parameter |
Default |
Description |
|---|---|---|
|
|
Correct encoder glitch spikes (round-trip steps) before alignment |
|
|
Spike sensitivity: lower = fewer corrections (adjacent step must reverse > (1−this) of current) |
|
|
Steps below this magnitude are not checked for spikes |
|
|
Tile field-of-view (mm); set only for legacy shifts files where |
|
|
Fractional tolerance around each tile-FOV multiple |
|
|
Handling for excluded-slice shifts: |
|
|
Window size for |
|
|
Re-estimate |
|
|
Reject image-based estimates differing from motor by more than this (0 = accept all) |
|
|
Minimum NCC to accept an image-based refinement |
Missing Slice Interpolation#
Fill single-slice gaps in the normalized slice sequence. Two-or-more consecutive gaps are not interpolated (insufficient information) and remain as holes.
Parameter |
Default |
Description |
|---|---|---|
|
|
Interpolate single-slice gaps |
|
|
Method: |
|
|
Blend: |
|
|
Similarity metric for boundary-plane registration |
|
|
Maximum registration iterations |
|
|
Z-planes to search at each boundary for best overlap pair |
|
|
Pre-registration NCC threshold below which zmorph falls back |
|
|
Planes averaged around boundary reference plane |
|
|
Minimum foreground fraction for a boundary plane |
|
|
Min post-reg NCC improvement to accept the transform |
When zmorph’s quality gates fail the slot is left as a genuine gap (no zarr output); a manifest fragment and diagnostics JSON are still emitted. See SLICE_INTERPOLATION_FEATURE.md for details.
Automatic Slice Quality Assessment#
Runs linum_assess_slice_quality on normalized slices and stamps a
slice_config.csv that marks degraded slices for exclusion before the common-
space step.
Parameter |
Default |
Description |
|---|---|---|
|
|
Enable automatic quality assessment |
|
|
Exclude slices with quality score below this |
|
|
Exclude first N calibration slices automatically |
|
|
Centre-crop size in XY for quality metrics (0 = full plane) |
Pairwise Registration#
Computes small corrections (rotation, sub-pixel translation) between consecutive slices. The main XY alignment comes from motor positions; these transforms are refinements applied on top.
Parameter |
Default |
Description |
|---|---|---|
|
|
Transform type: |
|
|
Optimizer bound on translation (pixels) |
|
|
Optimizer bound on rotation (degrees) |
|
|
Initial alignment before refinement: |
|
|
Starting Z-index in the moving volume |
|
|
Physical slice thickness (mm) |
|
|
Z-search range (mm) |
Stacking & Output#
Stacking assembles all common-space slices into a 3D volume using motor positions for XY placement, pairwise registration for rotation/translation refinement, and correlation or physics-based Z-matching.
Parameter |
Default |
Description |
|---|---|---|
|
|
Blend overlapping regions between slices |
|
|
Z-blend refinement: phase-correlation XY correction in the overlap zone before blending (0 = disabled) |
|
|
Z-blend position refinement: search up to N voxels below the expected boundary for the best-correlated plane |
Motor stacking / transform application:
Parameter |
Default |
Description |
|---|---|---|
|
|
Use expected Z-overlap instead of correlation-based matching |
|
|
Apply pairwise registration transforms during stacking |
|
|
Apply only the rotation component (keeps XY from motor) |
|
|
Clamp rotation values larger than this before application |
Confidence-based transform degradation. A confidence score (0–1) is computed from Z-correlation, translation magnitude and rotation.
Parameter |
Default |
Description |
|---|---|---|
|
|
Above this: full transform applied |
|
|
Between low and high: rotation-only; below low: skipped |
|
|
Fall back to expected Z-overlap below this NCC score |
|
|
Min confidence to run blend Z-refinement (else use expected overlap) |
Transform gating:
Parameter |
Default |
Description |
|---|---|---|
|
|
Skip transforms flagged |
|
|
Skip transforms flagged |
|
|
Metric-based gating: min z_correlation to load a transform (0 = disabled) |
|
|
Metric-based gating: max rotation (degrees) (0 = disabled) |
Auto-exclude extended low-quality clusters:
Parameter |
Default |
Description |
|---|---|---|
|
|
Enable automatic cluster detection |
|
|
Min consecutive low-quality pairs to trigger exclusion |
|
|
Z-correlation threshold below which a pair is low-quality |
Translation accumulation & smoothing:
Parameter |
Default |
Description |
|---|---|---|
|
|
Accumulate pairwise translations as cumulative canvas offsets |
|
|
Weight each translation by its confidence before accumulating |
|
|
Max cumulative translation drift from motor baseline (0 = unlimited) |
|
|
Values near this limit are assumed optimizer-boundary hits and zeroed out (0 = accumulate all) |
|
|
Moving-average window (slices) for smoothing per-slice rotations (0 = disabled) |
|
|
Gaussian sigma (slices) for smoothing accumulated translations (0 = disabled) |
|
|
Min z_correlation to use a slice’s translation in accumulation |
Output pyramid:
Parameter |
Default |
Description |
|---|---|---|
|
|
Target resolutions (µm) for output pyramid levels |
|
|
Fixed level count (overrides |
|
|
Resample to isotropic voxel spacing |
The pyramid_resolutions parameter controls the multi-resolution pyramid in the final 3D volume. Instead of power-of-2 downsampling, specific analysis-friendly resolutions are used:
10 µm: High-resolution analysis
25 µm: Standard analysis resolution
50 µm: Overview and atlas registration
100 µm: Quick visualization and large-scale analysis
Note: Only resolutions ≥ the base resolution parameter will be included. For example, if resolution = 25, then only 25, 50, and 100 µm levels will be created.
Bias Field Correction#
Corrects slow intensity drift and bias field across serial sections after stacking using N4 bias field correction (SimpleITK). Disabled by default.
Parameter |
Default |
Description |
|---|---|---|
|
|
Enable post-stacking N4 bias field correction |
|
|
Correction mode: |
|
|
Correction mixing strength (0 = passthrough, 1 = full correction) |
Atlas Registration (RAS Alignment)#
Register the final reconstructed volume to the Allen Mouse Brain Atlas (CCF) to produce an RAS-aligned OME-Zarr output. Atlas data is downloaded automatically.
Parameter |
Default |
Description |
|---|---|---|
|
|
Enable Allen atlas registration |
|
|
Atlas resolution for registration (µm): 10, 25, 50, 100 |
|
|
Registration metric: |
|
|
Maximum registration iterations |
|
|
Pyramid level of input zarr for registration (0 = full; level 2 ≈ 50 µm, fast) |
|
|
3-letter orientation code of the INPUT brain volume (see table below) |
|
|
Initial rotation hint |
|
|
Generate a 3-panel alignment comparison image |
Output: align_to_ras/{subject}_ras.ome.zarr with all pyramid resolutions.
RAS Orientation Lookup Table#
The ras_input_orientation parameter is a 3-letter code describing the anatomical direction each axis of the input ZYX zarr points toward. The code is interpreted as:
letter 1 → dim0 (zarr Z) = slice stacking direction (perpendicular to cutting plane)
letter 2 → dim1 (zarr Y) = in-plane row direction
letter 3 → dim2 (zarr X) = in-plane column direction
Each letter is one of: R/L (right/left), A/P (anterior/posterior), S/I (superior/inferior).
The script linum_align_to_ras.py uses the code to permute and flip axes before registration, bringing the volume into approximate RAS space. The ras_initial_rotation then seeds the registration optimizer with a coarse rotation, which is essential for oblique cuts.
Standard setup assumption used in the table below:
Brain mounted with dorsal side up. OCT motor rows (zarr Y) scan dorsal→ventral (I). OCT motor columns (zarr X) scan left→right for coronal/axial (R), or posterior→anterior for sagittal (A).
Cardinal (in-plane) cutting orientations#
Cutting plane |
Stack direction |
Row dir (Y) |
Col dir (X) |
|
|---|---|---|---|---|
Coronal — anterior→posterior |
A→P |
Dorsal→Ventral (I) |
Left→Right (R) |
|
Coronal — posterior→anterior |
P→A |
Dorsal→Ventral (I) |
Left→Right (R) |
|
Sagittal — left→right |
L→R |
Dorsal→Ventral (I) |
Posterior→Anterior (A) |
|
Sagittal — right→left |
R→L |
Dorsal→Ventral (I) |
Posterior→Anterior (A) |
|
Axial/Horizontal — dorsal→ventral |
D→V |
Anterior→Posterior (P) |
Left→Right (R) |
|
Axial/Horizontal — ventral→dorsal |
V→D |
Anterior→Posterior (P) |
Left→Right (R) |
|
Important: The in-plane letters (2nd and 3rd) depend on the physical stage motor orientation and brain mounting. If the output looks mirrored or rotated 90°, swap or negate the in-plane letters. Run
linum_align_to_ras.py --preview-onlyto inspect the raw volume orientation before registering.
45° oblique cutting orientations#
For cuts between two cardinal planes, use the closest cardinal code plus ras_initial_rotation to seed the registration with the approximate tilt angle. The sign depends on which specific diagonal direction the cut follows — verify with --preview after registration.
Cutting plane |
Between planes |
|
|
Rotation axis |
|---|---|---|---|---|
Corono-sagittal 45° |
Coronal ↔ Sagittal |
|
|
Around RAS Superior-Inferior (Rz) |
Corono-axial 45° |
Coronal ↔ Axial |
|
|
Around RAS Right-Left (Rx) |
Sagitto-axial 45° |
Sagittal ↔ Axial |
|
|
Around RAS Anterior-Posterior (Ry) |
¹ Sign (+ or −) depends on the specific oblique direction. Start with +45 and inspect the preview; negate if the alignment is worse.
Rotation axis guide (applied in the approximately-RAS frame after orientation correction):
Rx— tilts the A-P axis toward/away from S-I (e.g., pitch)Ry— tilts the R-L axis toward/away from S-I (e.g., roll)Rz— rotates in the axial plane, mixing R-L and A-P (e.g., yaw)
Example config (coronal A→P, standard setup):
align_to_ras_enabled = true
ras_input_orientation = 'PIR'
ras_initial_rotation = '' // automatic MOMENTS initialization
allen_resolution = 25
allen_registration_level = 2 // ~50 µm pyramid level for speed
Example config (corono-sagittal 45° oblique cut):
align_to_ras_enabled = true
ras_input_orientation = 'PIR'
ras_initial_rotation = '0 0 45' // adjust sign after checking preview
allen_resolution = 25
allen_registration_level = 2
Manual Alignment Export#
Export a lightweight data package for interactive manual alignment of pairwise
slice transforms (tools/manual-align/). When manually corrected transforms
exist, the stack step can pick them up and optionally re-refine them with a
tight image-based registration.
Parameter |
Default |
Description |
|---|---|---|
|
|
Export manual alignment data after |
|
|
Pyramid level for AIP export (0 = full, 1 = 2×, …) |
|
|
Directory of manually-corrected transforms; overrides automated ones for matching slices |
|
|
Re-run pairwise registration on manual pairs, seeded from the manual transform |
|
|
Max residual translation searched during refinement (pixels) |
|
|
Max residual rotation searched during refinement (degrees) |
Previews & Reports#
Parameter |
Default |
Description |
|---|---|---|
|
|
Generate stitched slice preview images |
|
|
Generate common space alignment previews |
|
|
Save |
|
|
Generate interpolated slice previews |
|
|
Generate HTML quality report after stacking |
|
|
Include detailed per-slice metrics in report |
|
|
|
|
|
Label every Nth slice in annotated preview (1 = all slices) |
|
|
Draw slice boundary lines on annotated preview |
Debugging#
Parameter |
Default |
Description |
|---|---|---|
|
|
Generate shifts analysis report and drift plots |
|
|
Comma-separated slice IDs or ranges to process (e.g. |
The analyze_shifts option runs drift analysis on the shifts file before processing, producing:
A text report with statistics and outlier detection
A PNG plot showing drift patterns
A filtered shifts CSV file
Diagnostic Mode#
Diagnostic mode enables additional analysis processes for troubleshooting reconstruction artifacts (edge mismatches, overhangs, alignment issues).
Parameter |
Default |
Description |
|---|---|---|
|
|
Master switch: enables all diagnostic analyses |
|
|
Analyze cumulative rotation between slices |
|
|
Analyze acquisition-time rotation from shifts + registration |
|
|
Stitch slices using motor positions only (no image registration) |
|
|
Stack slices using motor positions only (no pairwise registration) |
|
|
Compare motor-only vs refined stitching side-by-side |
Diagnostic parameters:
Parameter |
Default |
Description |
|---|---|---|
|
|
Expected tile overlap for motor-only diagnostics (matches |
|
|
Blending for motor-only stitching: |
|
|
Blending for motor-only stacking: |
|
|
Rotation warning threshold (degrees) |
|
|
Save refined stitching transform data as JSON |
|
|
Tile step for seam detection in stitching comparison |
Diagnostic outputs are written to {output}/diagnostics/ and include rotation plots, dilation reports, motor-only stitch results, and side-by-side comparisons.
GPU Acceleration#
Parameter |
Default |
Description |
|---|---|---|
|
|
Enable GPU acceleration (auto-fallback to CPU) |
Outputs#
output/
├── README/readme.txt
├── analyze_shifts/ # Only when analyze_shifts = true
├── resample_mosaic_grid/
├── fix_focal_curvature/
├── fix_illumination/
├── stitch_3d_with_refinement/
├── previews/stitched_slices/ # Only when stitch_preview = true
├── beam_profile_correction/
├── crop_interface/
├── normalize/
├── detect_rehoming_events/ # Only when detect_rehoming = true
├── auto_assess_quality/ # Only when auto_assess_quality = true
├── bring_to_common_space/
├── common_space_previews/ # Only when common_space_preview = true
├── interpolate_missing_slice/ # Only when interpolate_missing_slices = true
├── finalise_interpolation/
├── register_pairwise/
├── auto_exclude_slices/ # Only when auto_exclude_enabled = true
├── stack/
│ ├── {subject}.ome.zarr
│ ├── {subject}.ome.zarr.zip
│ ├── {subject}.png
│ └── {subject}_annotated.png
├── correct_bias_field/ # Only when correct_bias_field = true
│ └── {subject}_corrected.ome.zarr
├── align_to_ras/ # Only when align_to_ras_enabled = true
│ ├── {subject}_ras.ome.zarr
│ ├── {subject}_ras_transform.tfm
│ └── {subject}_ras_preview.png
├── diagnostics/ # Only when diagnostic_mode = true or individual flags set
│ ├── rotation_analysis/
│ ├── acquisition_rotation/
│ ├── motor_only_stitch/
│ ├── refined_stitch/
│ ├── motor_only_stack/
│ └── stitch_comparison/
└── {subject}_quality_report.html # Only when generate_report = true
GPU Acceleration#
Both workflows support GPU acceleration using NVIDIA CUDA via CuPy. GPU processing is enabled by default and automatically falls back to CPU if no GPU is available.
GPU-Accelerated Processes#
Workflow |
Process |
GPU Operations |
|---|---|---|
|
|
Galvo detection, volume resize |
|
|
Mean projection |
|
|
Volume resize |
|
|
BaSiCPy background correction (PyTorch on GPU) |
|
|
Intensity normalization, percentile clipping |
Usage#
# GPU enabled (default)
nextflow run preproc_rawtiles.nf --input /data --output /output
# Disable GPU
nextflow run preproc_rawtiles.nf --input /data --output /output --use_gpu false
# 3D reconstruction with GPU
nextflow run soct_3d_reconst.nf --input /mosaics --output /output --use_gpu true
Config-Based Control#
// In nextflow.config
params {
use_gpu = true // Enable GPU (default)
// use_gpu = false // Force CPU only
}
Requirements#
For GPU support:
NVIDIA GPU with CUDA support
CuPy installed:
uv pip install cupy-cuda12xSee GPU_ACCELERATION.md for detailed setup
Expected Speedups#
On NVIDIA A6000 (48GB):
Operation |
Speedup |
|---|---|
Phase correlation |
10-15x |
Volume resize |
5-10x |
AIP projection |
3-4x |
CPU Core Management#
The pipelines provide fine-grained control over CPU usage, allowing you to reserve cores for system overhead and manage the interplay between Nextflow parallelism and Python multiprocessing.
Configuration Options#
Both pipelines support two approaches. Defaults differ between workflows:
the preproc pipeline ships with max_cpus = null and reserved_cpus = 2,
while the 3D reconstruction pipeline uses max_cpus = 16 and
reserved_cpus = 4 (see workflows/<pipeline>/nextflow.config).
Parameter |
preproc default |
reconst_3d default |
Description |
|---|---|---|---|
|
|
|
Explicit maximum CPUs to use (takes precedence) |
|
|
|
Number of cores to keep free for overhead |
|
|
|
Python processes per Nextflow task |
Usage Examples#
Reserve Cores for Overhead (Recommended)#
# Keep 2 cores free for system overhead (default)
nextflow run soct_3d_reconst.nf \
--input /path/to/data \
--reserved_cpus 2
# Keep 4 cores free on a heavily-loaded system
nextflow run soct_3d_reconst.nf \
--input /path/to/data \
--reserved_cpus 4
Set Explicit Core Limit#
# Use exactly 16 cores maximum
nextflow run soct_3d_reconst.nf \
--input /path/to/data \
--max_cpus 16
Understanding the Interplay#
The total CPU usage depends on three factors:
Nextflow parallelism: How many tasks run simultaneously
Python processes per task: The
processesparameterThread libraries: NumPy/SciPy threading (OMP, MKL, OpenBLAS)
The effective formula is:
Total threads ≈ (Nextflow parallel tasks) × (processes) × (threads per process)
The pipeline automatically:
Sets
LINUMPY_MAX_CPUSorLINUMPY_RESERVED_CPUSenvironment variables for Python scriptsConfigures
OMP_NUM_THREADS,MKL_NUM_THREADS,OPENBLAS_NUM_THREADS, andITK_GLOBAL_DEFAULT_NUMBER_OF_THREADSto prevent thread oversubscription
Disabling CPU Limits#
If the CPU limiting system causes issues (e.g., unexpectedly slow performance), you can disable it entirely:
# Disable CPU limits - all cores will be used
nextflow run workflow.nf --enable_cpu_limits false
This will skip all environment variable settings and let processes use all available cores.
Recommended Configurations#
System Type |
reserved_cpus |
processes |
Notes |
|---|---|---|---|
Workstation (8-16 cores) |
2 |
2-4 |
Good balance |
Server (32+ cores) |
4 |
4-8 |
Leave room for I/O |
Shared system |
8+ |
2 |
Conservative to avoid impacting others |
Dedicated processing |
1 |
auto |
Maximum throughput |
Environment Variables#
Python scripts in linumpy respect these environment variables:
Variable |
Description |
|---|---|
|
Maximum CPUs to use (explicit limit) |
|
CPUs to reserve for overhead |
|
Thread limit for SimpleITK operations |
These can also be set manually when running scripts directly:
# Reserve 4 cores when running standalone scripts
LINUMPY_RESERVED_CPUS=4 linum_create_mosaic_grid_3d.py input.ome.zarr output.ome.zarr
# Or set explicit max
LINUMPY_MAX_CPUS=8 linum_stitch_3d.py mosaic_grid.ome.zarr transform.npy output.ome.zarr
Configuration Files#
nextflow.config Structure#
manifest {
nextflowVersion = '>= 23.10'
}
params {
// Default parameter values
input = "."
output = "."
// ... more parameters
}
process {
// Process-level settings
publishDir = {"$params.output/$slice_id/$task.process"}
scratch = true
errorStrategy = { task.attempt <= 2 ? 'retry' : 'ignore' }
maxRetries = 2
}
apptainer {
autoMounts = true
enabled = true
}
profiles {
// Environment-specific profiles
calliste {
// HPC cluster settings
}
}
Using Custom Config#
# Use custom config file
nextflow run workflow.nf -c my_config.config
# Override specific parameters
nextflow run workflow.nf --resolution 5 --processes 8
Execution Profiles#
Reconstruction Robustness Presets#
The 3D reconstruction workflow ships with three preset profiles that bundle related stacking/registration parameters:
Profile |
When to use |
|---|---|
|
Trusts motor positions for XY, applies rotation-only from registration, skips unreliable transforms, interpolates single-slice gaps. Recommended starting point. |
|
Uses full pairwise transforms (XY + rotation) and accumulates them cumulatively. Best alignment when registration is reliable, degrades badly when it is not. |
|
Motor-only stacking — ignores all pairwise registration. Most stable and fastest; use when motor positions are reliable and registration consistently fails. |
# Pick a robustness preset
nextflow run soct_3d_reconst.nf -profile conservative --input ... --output ...
nextflow run soct_3d_reconst.nf -profile aggressive --input ... --output ...
nextflow run soct_3d_reconst.nf -profile minimal --input ... --output ...
Individual parameters may still be overridden on the command line on top of a profile.
Local Execution#
nextflow run workflow.nf
HPC Cluster (SLURM)#
// In nextflow.config
profiles {
slurm {
process.executor = 'slurm'
process.queue = 'normal'
process.memory = '16 GB'
process.cpus = 4
}
}
nextflow run workflow.nf -profile slurm
Containerized Execution#
// In nextflow.config
apptainer {
enabled = true
cacheDir = '/path/to/cache'
}
nextflow run workflow.nf -with-apptainer linumpy.sif
Monitoring and Debugging#
Progress Monitoring#
# Real-time progress
nextflow run workflow.nf
# With execution report
nextflow run workflow.nf -with-report report.html
# With timeline
nextflow run workflow.nf -with-timeline timeline.html
# With DAG visualization
nextflow run workflow.nf -with-dag dag.png
Resume Failed Runs#
# Resume from last checkpoint
nextflow run workflow.nf -resume
Clean Up#
# Clean work directory
nextflow clean -f
# Clean specific run
nextflow clean -f <run_name>
Log Files#
.nextflow.log # Main log file
.nextflow/ # Nextflow cache and history
work/ # Task working directories
Common Issues#
Out of Memory#
// Increase memory in config
process {
memory = '32 GB'
}
Disk Space#
# Check work directory size
du -sh work/
# Clean after successful run
rm -rf work/
Container Issues#
# Pull container manually
apptainer pull linumpy.sif docker://ghcr.io/linum/linumpy:latest
# Run with explicit container
nextflow run workflow.nf -with-apptainer linumpy.sif
Permission Errors#
# Check file permissions
ls -la work/
# Fix ownership
sudo chown -R $USER:$USER work/
Best Practices#
1. Use Version Control for Configs#
# Track your custom configs
git add nextflow.config
git commit -m "Add custom pipeline config"
2. Test with Small Data First#
# Run on subset
nextflow run workflow.nf --input /path/to/test_data
3. Monitor Resource Usage#
# With resource report
nextflow run workflow.nf -with-report -with-trace
4. Use Profiles for Different Environments#
profiles {
local { /* laptop settings */ }
hpc { /* cluster settings */ }
cloud { /* AWS/GCP settings */ }
}
5. Keep Work Directory on Fast Storage#
# Set work directory
nextflow run workflow.nf -w /fast/storage/work