8000 WIP: Neuroscout related changes by adelavega · Pull Request #1 · effigies/fitlins · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

WIP: Neuroscout related changes 8000 #1

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

Merged
merged 4 commits into from
Dec 3, 2018
Merged
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
16 changes: 5 additions & 11 deletions fitlins/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ def get_parser():
'removed)')
g_bids.add_argument('-m', '--model', action='store', default='model.json',
help='location of BIDS model description (default bids_dir/model.json)')
g_bids.add_argument('-p', '--preproc-dir', action='store', default='fmriprep',
help='location of preprocessed data (if relative path, search '
'bids_dir/derivatives, followed by output_dir)')
g_bids.add_argument('-d', '--derivatives', action='store', nargs='+',
help='location of derivatives (including preprocessed images).'
'If none specified, indexes all derivatives under bids_dir/derivatives.')
g_bids.add_argument('--derivative-label', action='store', type=str,
help='execution label to append to derivative directory name')
g_bids.add_argument('--space', action='store',
Expand Down Expand Up @@ -139,13 +139,7 @@ def run_fitlins(argv=None):
if opts.model in (None, 'default') and not op.exists(model):
model = 'default'

preproc_dir = default_path(opts.preproc_dir,
op.join(opts.bids_dir, 'derivatives'),
'fmriprep')
if not op.exists(preproc_dir):
preproc_dir = default_path(opts.preproc_dir, opts.output_dir, 'fmriprep')
if not op.exists(preproc_dir):
raise RuntimeError("Preprocessed data could not be found")
derivatives = True if not opts.derivatives else opts.derivatives

pipeline_name = 'fitlins'
if opts.derivative_label:
Expand All @@ -158,7 +152,7 @@ def run_fitlins(argv=None):
work_dir = mkdtemp() if opts.work_dir is None else opts.work_dir

fitlins_wf = init_fitlins_wf(
opts.bids_dir, preproc_dir, deriv_dir, opts.space, model=model,
opts.bids_dir, derivatives, deriv_dir, opts.space, model=model,
participants=subject_list, base_dir=work_dir,
include_pattern=opts.include, exclude_pattern=opts.exclude
)
Expand Down
23 changes: 10 additions & 13 deletions fitlins/interfaces/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ def _run_interface(self, runtime):
layout = bids.BIDSLayout(self.inputs.bids_dir, validate=False)

if not isdefined(models):
models = layout.get(suffix='smdl')
models = layout.get(suffix='smdl', return_type='file')
if not models:
raise ValueError("No models found")
elif models == 'default':
models = auto_model(layout)

models = [_ensure_model(m.path) for m in models]
models = [_ensure_model(m) for m in models]

if self.inputs.selectors:
# This is almost certainly incorrect
Expand All @@ -136,8 +136,8 @@ class LoadBIDSModelInputSpec(BaseInterfaceInputSpec):
bids_dir = Directory(exists=True,
mandatory=True,
desc='BIDS dataset root directory')
preproc_dir = Directory(exists=True,
desc='Optional preprocessed files directory')
derivatives = traits.Either(traits.Bool, InputMultiPath(Directory(exists=True)),
desc='Derivative folders')
model = traits.Dict(desc='Model specification', mandatory=True)
selectors = traits.Dict(desc='Limit collected sessions', usedefault=True)
include_pattern = InputMultiPath(
Expand All @@ -164,16 +164,16 @@ def _run_interface(self, runtime):
import bids
include = self.inputs.include_pattern
exclude = self.inputs.exclude_pattern
derivatives = self.inputs.preproc_dir
derivatives = self.inputs.derivatives
if not isdefined(include):
include = None
if not isdefined(exclude):
exclude = None
if not isdefined(derivatives):
exclude = False

layout = bids.BIDSLayout(self.inputs.bids_dir, include=include, exclude=exclude,
derivatives=derivatives)
layout = bids.BIDSLayout(self.inputs.bids_dir, include=include,
exclude=exclude, derivatives=derivatives)

selectors = self.inputs.selectors

Expand Down Expand Up @@ -364,8 +364,8 @@ class BIDSSelectInputSpec(BaseInterfaceInputSpec):
bids_dir = Directory(exists=True,
mandatory=True,
desc='BIDS dataset root directories')
preproc_dir = Directory(exists=True,
desc='Optional preprocessed files directory')
derivatives = traits.Either(True, InputMultiPath(Directory(exists=True)),
desc='Derivative folders')
entities = InputMultiPath(traits.Dict(), mandatory=True)
selectors = traits.Dict(desc='Additional selectors to be applied',
usedefault=True)
Expand All @@ -384,10 +384,7 @@ class BIDSSelect(SimpleInterface):
def _run_interface(self, runtime):
import bids

derivatives = self.inputs.preproc_dir
if not isdefined(derivatives):
exclude = False

derivatives = self.inputs.derivatives
layout = bids.BIDSLayout(self.inputs.bids_dir, derivatives=derivatives)

bold_files = []
Expand Down
11 changes: 3 additions & 8 deletions fitlins/workflows/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ..interfaces.utils import MergeAll


def init_fitlins_wf(bids_dir, preproc_dir, out_dir, space, exclude_pattern=None,
def init_fitlins_wf(bids_dir, derivatives, out_dir, space, exclude_pattern=None,
include_pattern=None, model=None, participants=None,
base_dir=None, name='fitlins_wf'):
wf = pe.Workflow(name=name, base_dir=base_dir)
Expand All @@ -31,12 +31,10 @@ def init_fitlins_wf(bids_dir, preproc_dir, out_dir, space, exclude_pattern=None,

loader = pe.Node(
LoadBIDSModel(bids_dir=bids_dir,
preproc_dir=preproc_dir,
derivatives=derivatives,
selectors=selectors),
name='loader')

if preproc_dir is not None:
loader.inputs.preproc_dir = preproc_dir
if exclude_pattern is not None:
loader.inputs.exclude_pattern = exclude_pattern
if include_pattern is not None:
Expand All @@ -53,13 +51,10 @@ def init_fitlins_wf(bids_dir, preproc_dir, out_dir, space, exclude_pattern=None,

# Select preprocessed BOLD series to analyze
getter = pe.Node(
BIDSSelect(bids_dir=bids_dir,
BIDSSelect(bids_dir=bids_dir, derivatives=derivatives,
selectors={'type': 'preproc', 'space': space}),
name='getter')

if preproc_dir is not None:
getter.inputs.preproc_dir = preproc_dir

select_l1_contrasts = pe.Node(niu.Select(index=0), name='select_l1_contrasts')

# Run first level model
Expand Down
0