Skip to content

Commit 83d6e70

Browse files
committed
Merge pull request #864 from satra/fix/openfmri
Fix/openfmri
2 parents 2db46c1 + 02b5012 commit 83d6e70

File tree

8 files changed

+68
-48
lines changed

8 files changed

+68
-48
lines changed

examples/fmri_openfmri.py

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def get_subjectinfo(subject_id, base_dir, task_id, model_id):
8787

8888

8989
def analyze_openfmri_dataset(data_dir, subject=None, model_id=None,
90-
task_id=None, output_dir=None):
90+
task_id=None, output_dir=None, subj_prefix='*'):
9191
"""Analyzes an open fmri dataset
9292
9393
Parameters
@@ -122,21 +122,21 @@ def analyze_openfmri_dataset(data_dir, subject=None, model_id=None,
122122
"""
123123

124124
subjects = sorted([path.split(os.path.sep)[-1] for path in
125-
glob(os.path.join(data_dir, 'sub*'))])
125+
glob(os.path.join(data_dir, subj_prefix))])
126126

127127
infosource = pe.Node(niu.IdentityInterface(fields=['subject_id',
128128
'model_id',
129129
'task_id']),
130130
name='infosource')
131-
if subject is None:
131+
if len(subject) == 0:
132132
infosource.iterables = [('subject_id', subjects),
133133
('model_id', [model_id]),
134-
('task_id', [task_id])]
134+
('task_id', task_id)]
135135
else:
136136
infosource.iterables = [('subject_id',
137-
[subjects[subjects.index(subject)]]),
137+
[subjects[subjects.index(subj)] for subj in subject]),
138138
('model_id', [model_id]),
139-
('task_id', [task_id])]
139+
('task_id', task_id)]
140140

141141
subjinfo = pe.Node(niu.Function(input_names=['subject_id', 'base_dir',
142142
'task_id', 'model_id'],
@@ -156,7 +156,7 @@ def analyze_openfmri_dataset(data_dir, subject=None, model_id=None,
156156
name='datasource')
157157
datasource.inputs.base_directory = data_dir
158158
datasource.inputs.template = '*'
159-
datasource.inputs.field_template = {'anat': '%s/anatomy/highres001.nii.gz',
159+
datasource.inputs.field_template = {'anat': '%s/anatomy/T1_001.nii.gz',
160160
'bold': '%s/BOLD/task%03d_r*/bold.nii.gz',
161161
'behav': ('%s/model/model%03d/onsets/task%03d_'
162162
'run%03d/cond*.txt'),
@@ -235,8 +235,19 @@ def get_contrasts(contrast_file, task_id, conds):
235235
name="modelspec")
236236
modelspec.inputs.input_units = 'secs'
237237

238+
def check_behav_list(behav):
239+
out_behav = []
240+
if isinstance(behav, basestring):
241+
behav = [behav]
242+
for val in behav:
243+
if not isinstance(val, list):
244+
out_behav.append([val])
245+
else:
246+
out_behav.append(val)
247+
return out_behav
248+
238249
wf.connect(subjinfo, 'TR', modelspec, 'time_repetition')
239-
wf.connect(datasource, 'behav', modelspec, 'event_files')
250+
wf.connect(datasource, ('behav', check_behav_list), modelspec, 'event_files')
240251
wf.connect(subjinfo, 'TR', modelfit, 'inputspec.interscan_interval')
241252
wf.connect(subjinfo, 'conds', contrastgen, 'conds')
242253
wf.connect(datasource, 'contrasts', contrastgen, 'contrast_file')
@@ -338,6 +349,9 @@ def get_subs(subject_id, conds, model_id, task_id):
338349
subs.append(('task_id_%d/' % task_id, '/task%03d_' % task_id))
339350
subs.append(('bold_dtype_mcf_mask_smooth_mask_gms_tempfilt_mean_warp_warp',
340351
'mean'))
352+
subs.append(('bold_dtype_mcf_mask_smooth_mask_gms_tempfilt_mean_flirt',
353+
'affine'))
354+
341355
for i in range(len(conds)):
342356
subs.append(('_flameo%d/cope1.' % i, 'cope%02d.' % (i + 1)))
343357
subs.append(('_flameo%d/varcope1.' % i, 'varcope%02d.' % (i + 1)))
@@ -376,6 +390,8 @@ def get_subs(subject_id, conds, model_id, task_id):
376390
('varcopes', 'varcopes.mni'),
377391
])])
378392
wf.connect(registration, 'outputspec.transformed_mean', datasink, 'mean.mni')
393+
wf.connect(registration, 'outputspec.func2anat_transform', datasink, 'xfm.mean2anat')
394+
wf.connect(registration, 'outputspec.anat2target_transform', datasink, 'xfm.anat2target')
379395

380396
"""
381397
Set processing parameters
@@ -398,12 +414,15 @@ def get_subs(subject_id, conds, model_id, task_id):
398414
parser = argparse.ArgumentParser(prog='fmri_openfmri.py',
399415
description=__doc__)
400416
parser.add_argument('-d', '--datasetdir', required=True)
401-
parser.add_argument('-s', '--subject', default=None,
417+
parser.add_argument('-s', '--subject', default=[],
418+
nargs='+', type=str,
402419
help="Subject name (e.g. 'sub001')")
403420
parser.add_argument('-m', '--model', default=1,
404421
help="Model index" + defstr)
405-
parser.add_argument('-t', '--task', default=1,
406-
help="Task index" + defstr)
422+
parser.add_argument('-x', '--subjectprefix', default='sub*',
423+
help="Subject prefix" + defstr)
424+
parser.add_argument('-t', '--task', default=1, #nargs='+',
425+
type=int, help="Task index" + defstr)
407426
parser.add_argument("-o", "--output_dir", dest="outdir",
408427
help="Output directory base")
409428
parser.add_argument("-w", "--work_dir", dest="work_dir",
@@ -427,7 +446,8 @@ def get_subs(subject_id, conds, model_id, task_id):
427446
wf = analyze_openfmri_dataset(data_dir=os.path.abspath(args.datasetdir),
428447
subject=args.subject,
429448
model_id=int(args.model),
430-
task_id=int(args.task),
449+
task_id=[int(args.task)],
450+
subj_prefix=args.subjectprefix,
431451
output_dir=outdir)
432452
wf.base_dir = work_dir
433453
if args.plugin_args:

nipype/external/provcopy.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def provn_representation(self):
346346

347347
def json_representation(self):
348348
return {'$': self._uri, 'type': u'xsd:anyURI'}
349-
349+
350350
def rdf_representation(self):
351351
return URIRef(self.get_uri())
352352

@@ -787,7 +787,7 @@ def rdf(self, graph=None, subj=None):
787787
pred = attr.rdf_representation()
788788
graph.add((subj, pred, obj))
789789
return graph
790-
790+
791791
def is_asserted(self):
792792
return self._asserted
793793

@@ -802,7 +802,7 @@ def is_relation(self):
802802
class ProvElement(ProvRecord):
803803
def is_element(self):
804804
return True
805-
805+
806806
def rdf(self, graph=None):
807807
if graph is None:
808808
graph = Graph()
@@ -1673,15 +1673,15 @@ def rdf(self, graph=None):
16731673
# graph should not None here
16741674
uri = self.get_identifier().rdf_representation()
16751675
graph = Graph(graph.store, uri)
1676-
1676+
16771677
for prefix, namespace in self._namespaces.items():
16781678
graph.bind(prefix, namespace.get_uri())
1679-
1679+
16801680
for record in self._records:
16811681
if record.is_asserted():
16821682
record.rdf(graph)
16831683
return graph
1684-
1684+
16851685
def get_provjson(self, **kw):
16861686
"""Return the `PROV-JSON <http://www.w3.org/Submission/prov-json/>`_ representation for the bundle/document.
16871687

nipype/interfaces/freesurfer/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
SynthesizeFLASH)
1010
from .model import (MRISPreproc, GLMFit, OneSampleTTest, Binarize, Concatenate,
1111
SegStats, Label2Vol, MS_LDA)
12-
from .utils import (SampleToSurface, SurfaceSmooth, SurfaceTransform, Surface2VolTransform,
12+
from .utils import (SampleToSurface, SurfaceSmooth, SurfaceTransform, Surface2VolTransform,
1313
SurfaceSnapshots,ApplyMask, MRIsConvert, MRITessellate,
1414
MRIMarchingCubes, SmoothTessellation, MakeAverageSubject,
1515
ExtractMainComponent)

nipype/interfaces/fsl/preprocess.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -678,17 +678,17 @@ def _list_outputs(self):
678678
'_variance.ext', cwd=cwd)
679679
outputs['std_img'] = self._gen_fname(outputs['out_file'] +
680680
'_sigma.ext', cwd=cwd)
681-
681+
682682
# The mean image created if -stats option is specified ('meanvol')
683-
# is missing the top and bottom slices. Therefore we only expose the
684-
# mean image created by -meanvol option ('mean_reg') which isn't
683+
# is missing the top and bottom slices. Therefore we only expose the
684+
# mean image created by -meanvol option ('mean_reg') which isn't
685685
# corrupted.
686686
# Note that the same problem holds for the std and variance image.
687-
687+
688688
if isdefined(self.inputs.mean_vol) and self.inputs.mean_vol:
689689
outputs['mean_img'] = self._gen_fname(outputs['out_file'] +
690690
'_mean_reg.ext', cwd=cwd)
691-
691+
692692
if isdefined(self.inputs.save_mats) and self.inputs.save_mats:
693693
_, filename = os.path.split(outputs['out_file'])
694694
matpathname = os.path.join(cwd, filename + '.mat')

nipype/interfaces/mrtrix/tensors.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,10 @@ class GenerateDirections(CommandLine):
327327
input_spec=GenerateDirectionsInputSpec
328328
output_spec=GenerateDirectionsOutputSpec
329329

330-
330+
331331
class FindShPeaksInputSpec(CommandLineInputSpec):
332332
in_file = File(exists=True, argstr='%s', mandatory=True, position=-3, desc='the input image of SH coefficients.')
333-
directions_file = File(exists=True, argstr='%s', mandatory=True, position=-2, desc='the set of directions to use as seeds for the peak finding')
333+
directions_file = File(exists=True, argstr='%s', mandatory=True, position=-2, desc='the set of directions to use as seeds for the peak finding')
334334
peaks_image = File(exists=True, argstr='-peaks %s', desc='the program will try to find the peaks that most closely match those in the image provided')
335335
num_peaks = traits.Int(argstr='-num %s', desc='the number of peaks to extract (default is 3)')
336336
peak_directions = traits.List(traits.Float, argstr='-direction %s', sep=' ', minlen=2, maxlen=2,
@@ -342,7 +342,7 @@ class FindShPeaksInputSpec(CommandLineInputSpec):
342342
display_debug = traits.Bool(argstr='-debug', desc='Display debugging messages.')
343343
out_file = File(name_template="%s_peak_dirs.mif", keep_extension=False, argstr='%s', hash_files=False, position= -1,
344344
desc='the output image. Each volume corresponds to the x, y & z component of each peak direction vector in turn', name_source=["in_file"])
345-
345+
346346
class FindShPeaksOutputSpec(TraitedSpec):
347347
out_file = File(exists=True, desc='Peak directions image')
348348

@@ -368,7 +368,7 @@ class FindShPeaks(CommandLine):
368368

369369

370370
class Directions2AmplitudeInputSpec(CommandLineInputSpec):
371-
in_file = File(exists=True, argstr='%s', mandatory=True, position=-2, desc='the input directions image. Each volume corresponds to the x, y & z component of each direction vector in turn.')
371+
in_file = File(exists=True, argstr='%s', mandatory=True, position=-2, desc='the input directions image. Each volume corresponds to the x, y & z component of each direction vector in turn.')
372372
peaks_image = File(exists=True, argstr='-peaks %s', desc='the program will try to find the peaks that most closely match those in the image provided')
373373
num_peaks = traits.Int(argstr='-num %s', desc='the number of peaks to extract (default is 3)')
374374
peak_directions = traits.List(traits.Float, argstr='-direction %s', sep=' ', minlen=2, maxlen=2,
@@ -379,7 +379,7 @@ class Directions2AmplitudeInputSpec(CommandLineInputSpec):
379379
display_debug = traits.Bool(argstr='-debug', desc='Display debugging messages.')
380380
out_file = File(name_template="%s_amplitudes.mif", keep_extension=False, argstr='%s', hash_files=False, position= -1,
381381
desc='the output amplitudes image', name_source=["in_file"])
382-
382+
383383
class Directions2AmplitudeOutputSpec(TraitedSpec):
384384
out_file = File(exists=True, desc='amplitudes image')
385385

nipype/interfaces/mrtrix/tracking.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,22 @@ class StreamlineTrackInputSpec(CommandLineInputSpec):
7575
in_file = File(exists=True, argstr='%s', mandatory=True, position=-2, desc='the image containing the source data.' \
7676
'The type of data required depends on the type of tracking as set in the preceeding argument. For DT methods, ' \
7777
'the base DWI are needed. For SD methods, the SH harmonic coefficients of the FOD are needed.')
78-
78+
7979
seed_xor = ['seed_file', 'seed_spec']
8080
seed_file = File(exists=True, argstr='-seed %s', desc='seed file', xor = seed_xor)
8181
seed_spec = traits.List(traits.Float, desc='seed specification in mm and radius (x y z r)', position=2,
8282
argstr='-seed %s', minlen=4, maxlen=4, sep=',', units='mm', xor = seed_xor)
83-
83+
8484
include_xor = ['include_file', 'include_spec']
8585
include_file = File(exists=True, argstr='-include %s', desc='inclusion file', xor = include_xor)
8686
include_spec = traits.List(traits.Float, desc='inclusion specification in mm and radius (x y z r)', position=2,
8787
argstr='-include %s', minlen=4, maxlen=4, sep=',', units='mm', xor = include_xor)
88-
88+
8989
exclude_xor = ['exclude_file', 'exclude_spec']
9090
exclude_file = File(exists=True, argstr='-exclude %s', desc='exclusion file', xor = exclude_xor)
9191
exclude_spec = traits.List(traits.Float, desc='exclusion specification in mm and radius (x y z r)', position=2,
9292
argstr='-exclude %s', minlen=4, maxlen=4, sep=',', units='mm', xor = exclude_xor)
93-
93+
9494
mask_xor = ['mask_file', 'mask_spec']
9595
mask_file = File(exists=True, argstr='-mask %s', desc='mask file. Only tracks within mask.', xor = mask_xor)
9696
mask_spec = traits.List(traits.Float, desc='Mask specification in mm and radius (x y z r). Tracks will be terminated when they leave the ROI.', position=2,
@@ -127,7 +127,7 @@ class StreamlineTrackInputSpec(CommandLineInputSpec):
127127

128128
initial_direction = traits.List(traits.Int, desc='Specify the initial tracking direction as a vector',
129129
argstr='-initdirection %s', minlen=2, maxlen=2, units='voxels')
130-
out_file = File(argstr='%s', position= -1, name_source = ['in_file'], name_template='%s_tracked.tck',
130+
out_file = File(argstr='%s', position= -1, name_source = ['in_file'], name_template='%s_tracked.tck',
131131
output_name='tracked', desc='output data file')
132132

133133
class StreamlineTrackOutputSpec(TraitedSpec):

nipype/interfaces/vista/vista.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ class Vnifti2Image(CommandLine):
4040
_cmd = 'vnifti2image'
4141
input_spec=Vnifti2ImageInputSpec
4242
output_spec=Vnifti2ImageOutputSpec
43-
44-
43+
44+
4545
class VtoMatInputSpec(CommandLineInputSpec):
4646
in_file = File(exists=True, argstr='-in %s', mandatory=True, position=1, desc='in file')
4747
out_file = File(name_template="%s.mat", keep_extension=False, argstr='-out %s', hash_files=False,

nipype/workflows/smri/freesurfer/recon.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ def create_skullstripped_recon_flow(name="skullstripped_recon_all"):
2626
2727
outputspec.subject_id : freesurfer subject id
2828
outputspec.subjects_dir : freesurfer subjects directory
29-
"""
29+
"""
3030
wf = pe.Workflow(name=name)
31-
31+
3232
inputnode = pe.Node(niu.IdentityInterface(fields=['subject_id',
3333
'subjects_dir',
3434
'T1_files']),
@@ -43,34 +43,34 @@ def create_skullstripped_recon_flow(name="skullstripped_recon_all"):
4343
wf.connect(inputnode, "T1_files", autorecon1, "T1_files")
4444
wf.connect(inputnode, "subjects_dir", autorecon1, "subjects_dir")
4545
wf.connect(inputnode, "subject_id", autorecon1, "subject_id")
46-
47-
46+
47+
4848
def link_masks(subjects_dir, subject_id):
4949
import os
5050
os.symlink(os.path.join(subjects_dir, subject_id, "mri", "T1.mgz"),
5151
os.path.join(subjects_dir, subject_id, "mri", "brainmask.auto.mgz"))
5252
os.symlink(os.path.join(subjects_dir, subject_id, "mri", "brainmask.auto.mgz"),
5353
os.path.join(subjects_dir, subject_id, "mri", "brainmask.mgz"))
5454
return subjects_dir, subject_id
55-
56-
masks = pe.Node(niu.Function(input_names=['subjects_dir', 'subject_id'],
55+
56+
masks = pe.Node(niu.Function(input_names=['subjects_dir', 'subject_id'],
5757
output_names=['subjects_dir', 'subject_id'],
5858
function=link_masks), name="link_masks")
59-
59+
6060
wf.connect(autorecon1, "subjects_dir", masks, "subjects_dir")
61-
wf.connect(autorecon1, "subject_id", masks, "subject_id")
62-
63-
61+
wf.connect(autorecon1, "subject_id", masks, "subject_id")
62+
63+
6464
autorecon_resume = pe.Node(fs.ReconAll(), name="autorecon_resume")
6565
autorecon_resume.plugin_args={'submit_specs': 'request_memory = 2500'}
6666
autorecon_resume.inputs.args = "-no-isrunning"
6767
wf.connect(masks, "subjects_dir", autorecon_resume, "subjects_dir")
6868
wf.connect(masks, "subject_id", autorecon_resume, "subject_id")
69-
69+
7070
outputnode = pe.Node(niu.IdentityInterface(fields=['subject_id',
7171
'subjects_dir']),
7272
name='outputspec')
73-
73+
7474
wf.connect(autorecon_resume, "subjects_dir", outputnode, "subjects_dir")
7575
wf.connect(autorecon_resume, "subject_id", outputnode, "subject_id")
7676
return wf

0 commit comments

Comments
 (0)