Skip to content

Keeping track of fMRIPrep. #192

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
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,8 @@ ENV/

#kubernetes stuff
kubernetes/jobs/

# Local tests
dmriprep/data/tests/local
*.ipynb
run_tests.py
67 changes: 50 additions & 17 deletions dmriprep/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@
"""Parser."""
import os
import sys

from .. import config


def _build_parser():
"""Build parser object."""
from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser
from functools import partial
from pathlib import Path
from argparse import (
ArgumentParser,
ArgumentDefaultsHelpFormatter,
)

from niworkflows.utils.spaces import OutputReferencesAction, Reference
from packaging.version import Version

from .version import check_latest, is_flagged
from niworkflows.utils.spaces import Reference, OutputReferencesAction

def _path_exists(path, parser):
"""Ensure a given path exists."""
Expand All @@ -52,7 +52,7 @@ def _min_one(value, parser):
return value

def _to_gb(value):
scale = {"G": 1, "T": 10 ** 3, "M": 1e-3, "K": 1e-6, "B": 1e-9}
scale = {"G": 1, "T": 10**3, "M": 1e-3, "K": 1e-6, "B": 1e-9}
digits = "".join([c for c in value if c.isdigit()])
units = value[len(digits) :] or "M"
return int(digits) * scale[units[0]]
Expand All @@ -70,7 +70,11 @@ def _bids_filter(value):
verstr = f"dMRIPrep v{config.environment.version}"
currentv = Version(config.environment.version)
is_release = not any(
(currentv.is_devrelease, currentv.is_prerelease, currentv.is_postrelease)
(
currentv.is_devrelease,
currentv.is_prerelease,
currentv.is_postrelease,
)
)

parser = ArgumentParser(
Expand All @@ -96,7 +100,8 @@ def _bids_filter(value):
"output_dir",
action="store",
type=Path,
help="the output path for the outcomes of preprocessing and visual " "reports",
help="the output path for the outcomes of preprocessing and visual "
"reports",
)
parser.add_argument(
"analysis_level",
Expand Down Expand Up @@ -181,7 +186,9 @@ def _bids_filter(value):
help="nipype plugin configuration file",
)
g_perfm.add_argument(
"--anat-only", action="store_true", help="run anatomical workflows only"
"--anat-only",
action="store_true",
help="run anatomical workflows only",
)
g_perfm.add_argument(
"--boilerplate_only",
Expand Down Expand Up @@ -249,7 +256,9 @@ def _bids_filter(value):
)

# ANTs options
g_ants = parser.add_argument_group("Specific options for ANTs registrations")
g_ants = parser.add_argument_group(
"Specific options for ANTs registrations"
)
g_ants.add_argument(
"--skull-strip-template",
default="OASIS30ANTs",
Expand All @@ -264,7 +273,9 @@ def _bids_filter(value):
)

# SyN-unwarp options
g_syn = parser.add_argument_group("Specific options for SyN distortion correction")
g_syn = parser.add_argument_group(
"Specific options for SyN distortion correction"
)
g_syn.add_argument(
"--use-syn-sdc",
action="store_true",
Expand All @@ -287,7 +298,9 @@ def _bids_filter(value):
)

# FreeSurfer options
g_fs = parser.add_argument_group("Specific options for FreeSurfer preprocessing")
g_fs = parser.add_argument_group(
"Specific options for FreeSurfer preprocessing"
)
g_fs.add_argument(
"--fs-license-file",
metavar="PATH",
Expand Down Expand Up @@ -415,11 +428,14 @@ def _bids_filter(value):
def parse_args(args=None, namespace=None):
"""Parse args and run further checks on the command line."""
import logging

from niworkflows.utils.spaces import Reference, SpatialReferences

parser = _build_parser()
opts = parser.parse_args(args, namespace)
config.execution.log_level = int(max(25 - 5 * opts.verbose_count, logging.DEBUG))
config.execution.log_level = int(
max(25 - 5 * opts.verbose_count, logging.DEBUG)
)
config.from_dict(vars(opts))
config.loggers.init()

Expand Down Expand Up @@ -469,18 +485,33 @@ def parse_args(args=None, namespace=None):
output_dir = config.execution.output_dir
work_dir = config.execution.work_dir
version = config.environment.version
output_layout = config.execution.output_layout

if config.execution.fs_subjects_dir is None:
config.execution.fs_subjects_dir = output_dir / "freesurfer"

if config.execution.fs_subjects_dir is None:
if output_layout == "bids":
config.execution.fs_subjects_dir = (
output_dir / "sourcedata" / "freesurfer"
)
elif output_layout == "legacy":
config.execution.fs_subjects_dir = output_dir / "freesurfer"
if config.execution.dmriprep_dir is None:
if output_layout == "bids":
config.execution.dmriprep_dir = output_dir
elif output_layout == "legacy":
config.execution.dmriprep_dir = output_dir / "dmriprep"
# Wipe out existing work_dir
if opts.clean_workdir and work_dir.exists():
from niworkflows.utils.misc import clean_directory

build_log.log("Clearing previous dMRIPrep working directory: %s", work_dir)
build_log.log(
"Clearing previous dMRIPrep working directory: %s", work_dir
)
if not clean_directory(work_dir):
build_log.warning(
"Could not clear all contents of working directory: %s", work_dir
"Could not clear all contents of working directory: %s",
work_dir,
)

# Ensure input and output folders are not the same
Expand Down Expand Up @@ -533,4 +564,6 @@ def parse_args(args=None, namespace=None):
)

config.execution.participant_label = sorted(participant_label)
config.workflow.skull_strip_template = config.workflow.skull_strip_template[0]
config.workflow.skull_strip_template = (
config.workflow.skull_strip_template[0]
)
Loading