From 5ddcc4281b39f2b1db9d872138df965553f1ab4d Mon Sep 17 00:00:00 2001 From: PeerHerholz Date: Mon, 7 Jun 2021 16:11:14 -0400 Subject: [PATCH] mridefacer fix and update This commit and PR fixes and updates mridefacer, as it crashed based on inconsistencies in the respective function's setup. The following files were changed: - generate_iamges.sh & Dockerfile -> FSL templates were added to the container as they are needed by mridefacer - defacing_algorithms -> mridefacer commands and workflow were updated to remove problems wrt copying of the face mask & add the --outdir argument to write defaced images to the respective BIDS root directory - run_deeid -> updated to reflect the changes made in defacing_algorithms --- Dockerfile | 123 +++++++++++++++++++++++++++++++- bidsonym/defacing_algorithms.py | 21 ++---- bidsonym/run_deeid.py | 4 +- generate_images.sh | 2 +- 4 files changed, 131 insertions(+), 19 deletions(-) diff --git a/Dockerfile b/Dockerfile index 11cd38b..7aae307 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ # Your version: 0.6.0 Latest version: 0.7.0 # Generated by Neurodocker version 0.6.0 -# Timestamp: 2021-04-13 14:10:53 UTC +# Timestamp: 2021-06-07 18:59:26 UTC # # Thank you for using Neurodocker. If you discover any issues # or ways to improve this software, please submit an issue or @@ -44,6 +44,7 @@ ENTRYPOINT ["/neurodocker/startup.sh"] RUN apt-get update -qq \ && apt-get install -y -q --no-install-recommends \ fsl-core \ + fsl-mni152-templates \ git \ num-utils \ gcc \ @@ -116,4 +117,122 @@ ENV IS_DOCKER="1" WORKDIR /tmp/ -ENTRYPOINT ["/neurodocker/startup.sh", "bidsonym"] \ No newline at end of file +ENTRYPOINT ["/neurodocker/startup.sh", "bidsonym"] + +RUN echo '{ \ + \n "pkg_manager": "apt", \ + \n "instructions": [ \ + \n [ \ + \n "base", \ + \n "neurodebian:stretch-non-free" \ + \n ], \ + \n [ \ + \n "install", \ + \n [ \ + \n "fsl-core", \ + \n "fsl-mni152-templates", \ + \n "git", \ + \n "num-utils", \ + \n "gcc", \ + \n "g++", \ + \n "curl", \ + \n "build-essential", \ + \n "nano" \ + \n ] \ + \n ], \ + \n [ \ + \n "run_bash", \ + \n "curl -sL https://deb.nodesource.com/setup_10.x | bash - && apt-get install -y nodejs && apt-get install -y npm" \ + \n ], \ + \n [ \ + \n "add_to_entrypoint", \ + \n "source /etc/fsl/fsl.sh" \ + \n ], \ + \n [ \ + \n "miniconda", \ + \n { \ + \n "conda_install": [ \ + \n "python=3.6", \ + \n "numpy", \ + \n "nipype", \ + \n "nibabel", \ + \n "pandas" \ + \n ], \ + \n "pip_install": [ \ + \n "deepdefacer", \ + \n "tensorflow", \ + \n "scikit-image" \ + \n ], \ + \n "create_env": "bidsonym", \ + \n "activate": true \ + \n } \ + \n ], \ + \n [ \ + \n "run_bash", \ + \n "source activate bidsonym && git clone https://github.com/poldracklab/pydeface.git && cd pydeface && python setup.py install && cd -" \ + \n ], \ + \n [ \ + \n "run_bash", \ + \n "source activate bidsonym && git clone https://github.com/nipy/quickshear.git && cd quickshear && python setup.py install && cd -" \ + \n ], \ + \n [ \ + \n "run_bash", \ + \n "source activate bidsonym && git clone https://github.com/neuronets/nobrainer.git && cd nobrainer && python setup.py install && cd -" \ + \n ], \ + \n [ \ + \n "run_bash", \ + \n "mkdir -p /opt/nobrainer/models && cd /opt/nobrainer/models && curl -LJO https://github.com/neuronets/nobrainer-models/releases/download/0.1/brain-extraction-unet-128iso-model.h5 && cd ~ " \ + \n ], \ + \n [ \ + \n "run_bash", \ + \n "git clone https://github.com/mih/mridefacer" \ + \n ], \ + \n [ \ + \n "env", \ + \n { \ + \n "MRIDEFACER_DATA_DIR": "/mridefacer/data" \ + \n } \ + \n ], \ + \n [ \ + \n "run_bash", \ + \n "npm install -g bids-validator@1.5.4" \ + \n ], \ + \n [ \ + \n "run_bash", \ + \n "mkdir /home/mri-deface-detector && cd /home/mri-deface-detector && npm install sharp --unsafe-perm && npm install -g mri-deface-detector --unsafe-perm && cd ~" \ + \n ], \ + \n [ \ + \n "run_bash", \ + \n "git clone https://github.com/miykael/gif_your_nifti && cd gif_your_nifti && source activate bidsonym && python setup.py install" \ + \n ], \ + \n [ \ + \n "copy", \ + \n [ \ + \n ".", \ + \n "/home/bm" \ + \n ] \ + \n ], \ + \n [ \ + \n "run_bash", \ + \n "chmod a+x /home/bm/bidsonym/fs_data/mri_deface" \ + \n ], \ + \n [ \ + \n "run_bash", \ + \n "source activate bidsonym && cd /home/bm && pip install -e ." \ + \n ], \ + \n [ \ + \n "env", \ + \n { \ + \n "IS_DOCKER": "1" \ + \n } \ + \n ], \ + \n [ \ + \n "workdir", \ + \n "/tmp/" \ + \n ], \ + \n [ \ + \n "entrypoint", \ + \n "/neurodocker/startup.sh bidsonym" \ + \n ] \ + \n ] \ + \n}' > /neurodocker/neurodocker_specs.json diff --git a/bidsonym/defacing_algorithms.py b/bidsonym/defacing_algorithms.py index ce55a12..c1122d1 100644 --- a/bidsonym/defacing_algorithms.py +++ b/bidsonym/defacing_algorithms.py @@ -128,7 +128,7 @@ def run_quickshear(image, outfile): deface_wf.run() -def mridefacer_cmd(image, subject_label, bids_dir): +def mridefacer_cmd(image, T1_file): """ Setup mridefacer command. @@ -146,20 +146,14 @@ def mridefacer_cmd(image, subject_label, bids_dir): import os from shutil import move - cmd = ["/mridefacer/mridefacer", "--apply", image] + outdir = T1_file[:T1_file.rfind('/')] + + cmd = ["/mridefacer/mridefacer", "--apply", image, "--outdir", outdir] check_call(cmd) - path = os.path.join(bids_dir, "sourcedata/bidsonym/sub-%s" % subject_label) - facemask = os.path.join(bids_dir, "sub-%s" % subject_label, - "anat/sub-%s_T1w_defacemask.nii.gz" % subject_label) - if os.path.isdir(path) is True: - move(facemask, os.path.join(path)) - else: - os.makedirs(path) - move(facemask, os.path.join(path)) return -def run_mridefacer(image, subject_label, bids_dir): +def run_mridefacer(image, T1_file): """ Setup and mridefacer workflow. @@ -176,14 +170,13 @@ def run_mridefacer(image, subject_label, bids_dir): deface_wf = pe.Workflow('deface_wf') inputnode = pe.Node(niu.IdentityInterface(['in_file']), name='inputnode') - mridefacer = pe.Node(Function(input_names=['image', 'subject_label', 'bids_dir'], + mridefacer = pe.Node(Function(input_names=['image', 'T1_file'], output_names=['outfile'], function=mridefacer_cmd), name='mridefacer') deface_wf.connect([(inputnode, mridefacer, [('in_file', 'image')])]) inputnode.inputs.in_file = image - mridefacer.inputs.subject_label = subject_label - mridefacer.inputs.bids_dir = bids_dir + mridefacer.inputs.T1_file = T1_file deface_wf.run() diff --git a/bidsonym/run_deeid.py b/bidsonym/run_deeid.py index 1b0a068..c97a42e 100644 --- a/bidsonym/run_deeid.py +++ b/bidsonym/run_deeid.py @@ -75,7 +75,7 @@ def run_deeid(): if args.brainextraction is None: raise Exception("For post defacing quality it is required to run a form of brainextraction" - "on the non-deindentified data. Thus please either indicate bet" + "on the non-deindentified data. Thus please either indicate bet " "(--brainextration bet) or nobrainer (--brainextraction nobrainer).") if args.skip_bids_validation: @@ -146,7 +146,7 @@ def run_deeid(): elif args.deid == "quickshear": run_quickshear(source_t1w, T1_file) elif args.deid == "mridefacer": - run_mridefacer(source_t1w, subject_label, args.bids_dir) + run_mridefacer(source_t1w, T1_file) elif args.deid == "deepdefacer": run_deepdefacer(source_t1w, subject_label, args.bids_dir) diff --git a/generate_images.sh b/generate_images.sh index b65bb1b..1694af6 100644 --- a/generate_images.sh +++ b/generate_images.sh @@ -8,7 +8,7 @@ generate_docker() { docker run --rm kaczmarj/neurodocker:0.6.0 generate docker \ --base neurodebian:stretch-non-free \ --pkg-manager apt \ - --install fsl-core git num-utils gcc g++ curl build-essential nano\ + --install fsl-core fsl-mni152-templates git num-utils gcc g++ curl build-essential nano\ --run-bash "curl -sL https://deb.nodesource.com/setup_10.x | bash - && apt-get install -y nodejs && apt-get install -y npm"\ --add-to-entrypoint "source /etc/fsl/fsl.sh" \ --miniconda \