Skip to content
52 changes: 52 additions & 0 deletions scripts/linum_get_slices_ids.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""List the slice ids from a tiles directory"""

import argparse
import csv
from pathlib import Path
import numpy as np

from linumpy.reconstruction import get_tiles_ids


def _build_arg_parser():
p = argparse.ArgumentParser(
description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
p.add_argument("directory",
help="Tiles directory")
p.add_argument("output_file",
help="Output CSV file")
return p


def main():
# Parse arguments
p = _build_arg_parser()
args = p.parse_args()

# Extract the parameters
tiles_directory = Path(args.directory)
output_file = Path(args.output_file)
assert output_file.name.endswith(".csv"), "The output file must be as csv file"

# Detect the tiles
tiles, tiles_ids = get_tiles_ids(tiles_directory)

# Extract the list of slice ids
z_list = []
for id in tiles_ids:
z_list.append(id[2])
z_list = list(set(z_list))

# Save the ids to a csv file
data = np.array([z_list, ]).T
with open(output_file, "w") as csv_file:
writer = csv.writer(csv_file, delimiter=",")
writer.writerow(["slice_id"])
writer.writerows(data)


if __name__ == "__main__":
main()
77 changes: 77 additions & 0 deletions workflows/workflow_2.5d_preprocessing.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env nextflow
nextflow.enable.dsl=2

/* S-OCT 2.5D Preprocessing */
/* This workflow will generate the mosaic grids and compute the XY shifts between slices

To execute this script, you can use the following command (example):

nextflow run workflow_2.5d_preprocessing.nf --directory <PATH_TO_DATADIR> --output_directory . -resume

Notes
-----
Copy this workflow in the processing directory.
Add the -resume flag to resume the pipeline from the last successfully completed process.
*/

// Parameters
params.directory = ""
params.tiles_directory = params.directory + "/tiles"
params.output_directory = params.directory
params.mosaicgrids_directory = params.output_directory + "/mosaic_grids_2d"

/* Processes */
// Compute the shift between the slices
process compute_xy_shifts{
input:
path directory
output:
path "shifts_xy.csv"
publishDir path: "${params.output_directory}", mode: "copy"
script:
"""
linum_estimate_xyShift_fromMetadata $directory shifts_xy.csv
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these script names won't work with our new build system. You need the .py at the end.

"""
}

// Detect the slices to process
process detect_slices{
input:
path directory
output:
path "slice_ids.csv"
script:
"""
linum_get_slices_ids $directory slice_ids.csv
"""
}

// Create the 2D mosaic grid
process create_mosaicgrid_2d{
input:
path(directory)
val(slice_id)
output:
path "*.tiff"
maxForks 1
publishDir path: "${params.mosaicgrids_directory}", mode: "copy"
script:
"""
linum_create_mosaic_grid $directory "mosaic_grid_z${slice_id}.tiff" -z $slice_id --normalize --n_cpus 1
"""
}

workflow{
// Estimate the shifts between slices
compute_xy_shifts(params.tiles_directory)

// Detect the slices to process
detect_slices(params.tiles_directory)

// Split the slice ids
slice_ids = detect_slices.out.splitCsv(header: false, skip: 1).map{it->it[0]}

// Create all the mosaic grids
create_mosaicgrid_2d(params.tiles_directory, slice_ids)
}