-
Notifications
You must be signed in to change notification settings - Fork 6
Workflow to preprocess the tiles for the 2.5D reconstruction #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
joe-from-mtl
wants to merge
8
commits into
main
Choose a base branch
from
flow_preproc_2-5d
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b10d427
Adding a script to detect the slice ids from the tiles directory
joe-from-mtl a77702a
Creating a workflow to preprocess the data for the 2.5D reconstruction
joe-from-mtl 7457ff9
Adding a script to detect the slice ids from the tiles directory
joe-from-mtl 7508dca
Creating a workflow to preprocess the data for the 2.5D reconstruction
joe-from-mtl d39a861
Merge remote-tracking branch 'origin/flow_preproc_2-5d' into flow_pre…
joe-from-mtl 143f3a4
Limiting the number of CPU due to data server constraints
joe-from-mtl 589f854
Merge branch 'refs/heads/main' into flow_preproc_2-5d
joe-from-mtl 7320a95
PEP8 coding style
joe-from-mtl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| """ | ||
| } | ||
|
|
||
| // 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) | ||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.