From bf3f2fc1913d6f16de527b2bacd0feb7c59ebbe4 Mon Sep 17 00:00:00 2001 From: Sebastien Tourbier Date: Tue, 8 Dec 2020 16:35:48 +0100 Subject: [PATCH 1/6] MAINT: add postfix _docker in bidsapp docker wrapper script filename --- ...it_bidsapp.py => mialsuperresolutiontoolkit_bidsapp_docker.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename pymialsrtk/cli/{mialsuperresolutiontoolkit_bidsapp.py => mialsuperresolutiontoolkit_bidsapp_docker.py} (100%) diff --git a/pymialsrtk/cli/mialsuperresolutiontoolkit_bidsapp.py b/pymialsrtk/cli/mialsuperresolutiontoolkit_bidsapp_docker.py similarity index 100% rename from pymialsrtk/cli/mialsuperresolutiontoolkit_bidsapp.py rename to pymialsrtk/cli/mialsuperresolutiontoolkit_bidsapp_docker.py From 10d3af1cd43cf556657ecab3e9a30b345fa266ff Mon Sep 17 00:00:00 2001 From: Sebastien Tourbier Date: Tue, 8 Dec 2020 16:36:36 +0100 Subject: [PATCH 2/6] DOC: updated module docstring of docker wrapper script --- pymialsrtk/cli/mialsuperresolutiontoolkit_bidsapp_docker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymialsrtk/cli/mialsuperresolutiontoolkit_bidsapp_docker.py b/pymialsrtk/cli/mialsuperresolutiontoolkit_bidsapp_docker.py index cbf97549b..30e73d53a 100644 --- a/pymialsrtk/cli/mialsuperresolutiontoolkit_bidsapp_docker.py +++ b/pymialsrtk/cli/mialsuperresolutiontoolkit_bidsapp_docker.py @@ -7,7 +7,7 @@ # # This software is distributed under the open-source license Modified BSD. -"""This module defines the mialsuperresolutiontoolkit-bidsapp script that wraps calls to the BIDS APP.""" +"""This module defines the `mialsuperresolutiontoolkit_bidsapp_docker` script that wraps calls to the Docker BIDS APP image.""" # General imports import sys From d4295cd059f80bf081847ae9b8d71913f646c683 Mon Sep 17 00:00:00 2001 From: Sebastien Tourbier Date: Tue, 8 Dec 2020 16:37:40 +0100 Subject: [PATCH 3/6] ENH: Add new script that wraps singularity run command --- ...erresolutiontoolkit_bidsapp_singularity.py | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 pymialsrtk/cli/mialsuperresolutiontoolkit_bidsapp_singularity.py diff --git a/pymialsrtk/cli/mialsuperresolutiontoolkit_bidsapp_singularity.py b/pymialsrtk/cli/mialsuperresolutiontoolkit_bidsapp_singularity.py new file mode 100644 index 000000000..7192ecc90 --- /dev/null +++ b/pymialsrtk/cli/mialsuperresolutiontoolkit_bidsapp_singularity.py @@ -0,0 +1,103 @@ +#!/usr/bin/env python +# +# Copyright © 2016-2020 +# Medical Image Analysis Laboratory, +# University Hospital Center and University of Lausanne (UNIL-CHUV), Switzerland, +# and Contributors +# +# This software is distributed under the open-source license Modified BSD. + +"""This module defines the `mialsuperresolutiontoolkit_bidsapp_singularity` script that wraps calls to the Singularity BIDS APP image.""" + +# General imports +import sys + +# Own imports +from pymialsrtk.info import __version__ +from pymialsrtk.parser import get_parser +from pymialsrtk.interfaces.utils import run + + +def create_singularity_cmd(args): + """Function that creates and returns the BIDS App singularity run command. + + Parameters + ---------- + args : dict + Dictionary of parsed input argument in the form:: + + { + 'bids_dir': "/path/to/bids/dataset/directory", + 'output_dir': "/path/to/output/directory", + 'param_file': "/path/to/configuration/parameter/file", + 'analysis_level': "participant", + 'participant_label': ['01', '02', '03'], + 'openmp_nb_of_cores': 1, + 'nipype_nb_of_cores': 1, + 'masks_derivatives_dir': 'manual_masks' + } + + Returns + ------- + cmd : string + String containing the command to be run via `subprocess.run()` + """ + # Docker run command prelude + cmd = 'singularity run --no-home ' + cmd += f'--bind {args.bids_dir}:/bids_dir ' + cmd += f'--bind {args.output_dir}:/output_dir ' + cmd += f'--bind {args.param_file}:/bids_dir/code/participants_params.json ' + cmd += f'library://tourbier/mialsuperresolutiontoolkit-bidsapp:v{__version__} ' + + # Standard BIDS App inputs + cmd += '/bids_dir ' + cmd += '/output_dir ' + cmd += f'{args.analysis_level} ' + cmd += '--participant_label ' + for label in args.participant_label: + cmd += f'{label} ' + + # MIALSRTK BIDS App inputs + cmd += '--param_file /bids_dir/code/participants_params.json ' + if args.masks_derivatives_dir != '': + cmd += f'--masks_derivatives_dir {args.masks_derivatives_dir} ' + cmd += f'--openmp_nb_of_cores {args.openmp_nb_of_cores} ' + cmd += f'--nipype_nb_of_cores {args.nipype_nb_of_cores}' + + return cmd + + +def main(): + """Main function that creates and executes the BIDS App singularity command. + + Returns + ------- + exit_code : {0, 1} + An exit code given to `sys.exit()` that can be: + + * '0' in case of successful completion + + * '1' in case of an error + """ + # Create and parse arguments + parser = get_parser() + args = parser.parse_args() + + # Create the singularity run command + cmd = create_singularity_cmd(args) + + # Execute the singularity run command + try: + print(f'... cmd: {cmd}') + run(cmd) + exit_code = 0 + except Exception as e: + print('Failed') + print(e) + exit_code = 1 + + return exit_code + + +if __name__ == '__main__': + sys.exit(main()) From 2fc622c1bb20d56f8f813ec7daabbf12d91cfae5 Mon Sep 17 00:00:00 2001 From: Sebastien Tourbier Date: Tue, 8 Dec 2020 16:38:28 +0100 Subject: [PATCH 4/6] UPD: update entry_points in setup.py and setup_pypi.py --- setup.py | 3 ++- setup_pypi.py | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 9385a467b..e5d051d9a 100644 --- a/setup.py +++ b/setup.py @@ -86,7 +86,8 @@ def main(): url='https://github.com/Medical-Image-Analysis-Laboratory/mialsuperresolutiontoolkit', entry_points={ "console_scripts": [ - 'mialsuperresolutiontoolkit_bidsapp = pymialsrtk.cli.mialsuperresolutiontoolkit_bidsapp:main' + 'mialsuperresolutiontoolkit_bidsapp_docker = pymialsrtk.cli.mialsuperresolutiontoolkit_bidsapp_docker:main', + 'mialsuperresolutiontoolkit_bidsapp_singularity = pymialsrtk.cli.mialsuperresolutiontoolkit_bidsapp_singularity:main' ] }, license='BSD-3-Clause', diff --git a/setup_pypi.py b/setup_pypi.py index 92dea90b0..b49e92dac 100644 --- a/setup_pypi.py +++ b/setup_pypi.py @@ -80,9 +80,10 @@ def main(): author_email='sebastien.tourbier@alumni.epfl.ch', url='https://github.com/Medical-Image-Analysis-Laboratory/mialsuperresolutiontoolkit', entry_points={ - "console_scripts": [ - 'mialsuperresolutiontoolkit_bidsapp = pymialsrtk.cli.mialsuperresolutiontoolkit_bidsapp:main' - ] + "console_scripts": [ + 'mialsuperresolutiontoolkit_bidsapp_docker = pymialsrtk.cli.mialsuperresolutiontoolkit_bidsapp_docker:main', + 'mialsuperresolutiontoolkit_bidsapp_singularity = pymialsrtk.cli.mialsuperresolutiontoolkit_bidsapp_singularity:main' + ] }, license='BSD-3-Clause', classifiers=[ From 25ff3ac952e26ad2de74919ae9f475d9235d372f Mon Sep 17 00:00:00 2001 From: Sebastien Tourbier Date: Wed, 9 Dec 2020 12:35:41 +0100 Subject: [PATCH 5/6] MAINT: update singularity exec command in wrapper --- .../cli/mialsuperresolutiontoolkit_bidsapp_singularity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymialsrtk/cli/mialsuperresolutiontoolkit_bidsapp_singularity.py b/pymialsrtk/cli/mialsuperresolutiontoolkit_bidsapp_singularity.py index 7192ecc90..3c70908da 100644 --- a/pymialsrtk/cli/mialsuperresolutiontoolkit_bidsapp_singularity.py +++ b/pymialsrtk/cli/mialsuperresolutiontoolkit_bidsapp_singularity.py @@ -43,7 +43,7 @@ def create_singularity_cmd(args): String containing the command to be run via `subprocess.run()` """ # Docker run command prelude - cmd = 'singularity run --no-home ' + cmd = 'singularity run --contain ' cmd += f'--bind {args.bids_dir}:/bids_dir ' cmd += f'--bind {args.output_dir}:/output_dir ' cmd += f'--bind {args.param_file}:/bids_dir/code/participants_params.json ' From 3bbae6db0e7369deef3751230f1a93e1ca222e51 Mon Sep 17 00:00:00 2001 From: Sebastien Tourbier Date: Thu, 10 Dec 2020 10:37:26 +0100 Subject: [PATCH 6/6] UPD: update --contain to --containall in the singularity run command --- .../cli/mialsuperresolutiontoolkit_bidsapp_singularity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymialsrtk/cli/mialsuperresolutiontoolkit_bidsapp_singularity.py b/pymialsrtk/cli/mialsuperresolutiontoolkit_bidsapp_singularity.py index 3c70908da..6aaf5a73e 100644 --- a/pymialsrtk/cli/mialsuperresolutiontoolkit_bidsapp_singularity.py +++ b/pymialsrtk/cli/mialsuperresolutiontoolkit_bidsapp_singularity.py @@ -43,7 +43,7 @@ def create_singularity_cmd(args): String containing the command to be run via `subprocess.run()` """ # Docker run command prelude - cmd = 'singularity run --contain ' + cmd = 'singularity run --containall ' cmd += f'--bind {args.bids_dir}:/bids_dir ' cmd += f'--bind {args.output_dir}:/output_dir ' cmd += f'--bind {args.param_file}:/bids_dir/code/participants_params.json '