Skip to content

Commit

Permalink
Merge pull request #9 from DCAN-Labs/develop
Browse files Browse the repository at this point in the history
Sync dev and master
  • Loading branch information
kathy-snider authored May 1, 2020
2 parents b7c6141 + 385be44 commit 42f6051
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RUN python3 -m pip install -r "/app/requirements.txt"

# insert pipeline code
ADD https://github.com/DCAN-Labs/dcan-infant-pipeline.git version.json
RUN git clone -b 'v0.0.1' --single-branch --depth 1 https://github.com/DCAN-Labs/dcan-infant-pipeline.git /opt/pipeline
RUN git clone -b 'v0.0.2' --single-branch --depth 1 https://github.com/DCAN-Labs/dcan-infant-pipeline.git /opt/pipeline

# unless otherwise specified...
ENV OMP_NUM_THREADS=1
Expand Down
22 changes: 22 additions & 0 deletions app/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,25 @@ def validate_config(bids_spec, anat_only):
assert ('bold' in modes) or anat_only, 'Must provide functional data or specify --ignore-func or --anat-only.'


def validate_license(freesurfer_license):
fshome = os.environ['FREESURFER_HOME']
license_txt = os.path.join(fshome, 'license.txt')
if freesurfer_license is None:
print('DEBUG:')
print('default path: %s' % license_txt)
assert os.path.exists(license_txt), \
'freesurfer license.txt not located. You can provide a license ' \
'file using the --freesurfer-license <LICENSE> argument.'
elif os.path.normpath(license_txt) == os.path.normpath(freesurfer_license):
print('DEBUG:')
print('these must be the same:')
print('first: %s' % os.path.normpath(license_txt))
print('second: %s' % os.path.normpath(freesurfer_license))
pass
else:
import shutil
print('DEBUG:')
print('copying: %s' % freesurfer_license)
print('to: %s' % license_txt)
shutil.copy(freesurfer_license, license_txt)

43 changes: 31 additions & 12 deletions app/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import argparse
import os

from helpers import (read_bids_dataset, validate_config)
from helpers import (read_bids_dataset, validate_config, validate_license)
from pipelines import (ParameterSettings, PreFreeSurfer, FreeSurfer,
PostFreeSurfer, FMRIVolume, FMRISurface,
DCANBOLDProcessing, ExecutiveSummary, CustomClean,
Expand All @@ -52,6 +52,7 @@ def _cli():
'atropos_range': args.atropos_range,
'bandstop_params': args.bandstop,
'dcmethod': args.dcmethod,
'freesurfer_license': args.freesurfer_license,
'hyper_norm_method': args.hyper_norm_method,
'jlf_method': args.jlf_method,
'max_cortical_thickness': args.max_cortical_thickness,
Expand Down Expand Up @@ -108,7 +109,8 @@ def generate_parser(parser=None):
# Optional args (now sorted alphabetically:
parser.add_argument(
'--aseg', type=str, dest='aseg',
default="DEFAULT",
default='DEFAULT',
metavar='PATH',
help='specify path to the aseg file to be used by FreeSurfer. '
'Default: aseg generated by PreFreeSurfer. '
)
Expand Down Expand Up @@ -148,22 +150,30 @@ def generate_parser(parser=None):
help='specify a distortion correction method. Default: use auto-'
'detection. '
)
parser.add_argument(
'--freesurfer-license', dest='freesurfer_license',
metavar='PATH',
help='If using docker or singularity, you will need to acquire and '
'provide your own FreeSurfer license. The license can be '
'acquired by filling out this form: '
'https://surfer.nmr.mgh.harvard.edu/registration.html '
)
parser.add_argument(
'--hyper-normalization-method', dest='hyper_norm_method',
default='ADULT_GM_IP',
choices=['ADULT_GM_IP', 'ROI_IPS', 'NONE'],
help='specify the intensity profiles to use for the hyper-'
'normalization step in FreeSurfer: '
'normalization step in FreeSurfer: \n'
'ADULT_GM_IP adjusts the entire base image such that the IP '
'of GM in the target roughly matches the IP of GM of the '
'reference (i.e., the adult freesurfer atlas). Then the WM '
'is shifted in the target image to match the histogram of WM '
'in the reference. '
'in the reference. \n'
'ROI_IPS adjusts the intensity profiles of each ROI (GM, WM, '
'CSF) separately and reassembles the parts. '
'NONE skips hyper-normalization step. This allows the user '
'to run PreFreeSurfer, apply new, experimental hyper-'
'normalization methods and then restart at FreeSurfer. '
'normalization methods and then restart at FreeSurfer. \n'
'Default: ADULT_GM_IP.'
)
parser.add_argument(
Expand All @@ -176,25 +186,28 @@ def generate_parser(parser=None):
parser.add_argument(
'--max-cortical-thickness', type=int, dest='max_cortical_thickness',
default=5,
metavar='MM',
help='maximum cortical thickness to allow in FreeSurfer. '
'Default: 5 mm. '

)
parser.add_argument(
'--motion-control-frame', '--mc-frame', dest='mc_frame',
default=17,
metavar="FRAME",
metavar='FRAME',
help='frame to be used when computing motion-control values. This '
'choosing different frames to see what works best for a run. In '
'future, will add an algorithm to determine best frame(s). '
'Default: 17'
)
parser.add_argument(
'--multi-masking-dir', dest='multi_masking_dir',
metavar='PATH',
help='directory for joint label fusion masks.'
)
parser.add_argument(
'--multi-template-dir', dest='multi_template_dir',
metavar='PATH',
help='directory for joint label fusion templates. It should contain '
'only folders which each contain a "T1w_brain.nii.gz" and a '
'"Segmentation.nii.gz". Each subdirectory may have any name and '
Expand All @@ -208,14 +221,14 @@ def generate_parser(parser=None):
)
parser.add_argument(
'--participant-label', dest='subject_list', nargs='+',
metavar='PARTICIPANT_LABEL',
metavar='LABEL',
help='optional list of participant ids to run. Default is all ids '
'found under the bids input directory. A participant label '
'does not include "sub-"'
)
parser.add_argument(
'--session-id', dest='session_list', nargs='*',
metavar='SESSION_ID',
metavar='LABEL',
help='filter input dataset by session id. Default is all ids '
'found under the subject input directory(s). A session id '
'does not include "ses-"'
Expand All @@ -236,9 +249,10 @@ def generate_parser(parser=None):
parser.add_argument(
'--T1-brain-mask', type=str, dest='t1_brain_mask',
default=None,
metavar='PATH',
help='specify the path to the mask file. The file specified will replace '
'T1w_acpc_brain_mask.nii.gz. '
'Tip: when supplying a brain-mask, you _may_ want to set '
'Tip: when supplying a brain-mask, you may want to set '
'--atropos-mask-method to NONE. '
'Default: mask generated by PreFreeSurfer. '
)
Expand Down Expand Up @@ -276,14 +290,14 @@ def generate_parser(parser=None):
)
extras.add_argument(
'--custom-clean', dest='cleaning_json',
metavar='CC_JSON',
metavar='PATH',
help='runs dcan cleaning script after the pipeline completes '
'successfully, to delete pipeline outputs based on the file '
'structure specified in the custom-clean json.'
)
extras.add_argument(
'--file-mapper-json', dest='file_mapper_json',
metavar='FM_JSON',
metavar='PATH',
help='runs dcan file-mapper after the pipeline completes '
'successfully, to copy pipeline outputs to BIDS-formatted '
'derivatives files based on the file-mapper json.'
Expand Down Expand Up @@ -318,6 +332,7 @@ def generate_parser(parser=None):
)
runopts.add_argument(
'--stage','--stages', dest='stages',
metavar='STAGE',
help='specify a subset of stages to run.'
'If a single stage name is given, the pipeline with be '
'started at that stage. If a string with a ":" is given, '
Expand Down Expand Up @@ -356,7 +371,8 @@ def generate_parser(parser=None):

def interface(bids_dir, output_dir, subject_list=None, session_list=None,
aseg="DEFAULT", atropos_mask_method=None, atropos_range=None,
bandstop_params=None, dcmethod=None, hyper_norm_method=None,
bandstop_params=None, dcmethod=None, freesurfer_license=None,
hyper_norm_method=None,
jlf_method=None, max_cortical_thickness=5, mc_frame=17,
multi_masking_dir=None, multi_template_dir=None, no_crop=False,
smoothing_iterations=10,
Expand All @@ -376,6 +392,7 @@ def interface(bids_dir, output_dir, subject_list=None, session_list=None,
:param atropos_range: tuple of lower and upper bounds for ANTs/Atropos labels.
:param bandstop_params: tuple of lower and upper bounds for stop-band filter.
:param dcmethod: which method will be used for distortion correction.
:param freesurfer_license: path to license to use FreeSurfer.
:param hyper_norm_method: which method will be used for hyper-normalization step.
:param jlf_method: which method to use for joint label fusion.
:param max_cortical_thickness: maximum cortical thickness allowed in FreeSurfer.
Expand All @@ -398,6 +415,8 @@ def interface(bids_dir, output_dir, subject_list=None, session_list=None,
:param stages: only run a subset of stages.
:return:
"""
if not check_only and not print_commands:
validate_license(freesurfer_license)
# Read from bids dataset.
assert os.path.isdir(bids_dir), bids_dir + ' is not a directory!'
if not os.path.isdir(output_dir):
Expand Down

0 comments on commit 42f6051

Please sign in to comment.