Concatonating across multiple runs with SpecifySPMModel

Hello,

The code below specifies the model for one run (i.e. func1 is the input for ‘functional_runs’). However, I would like to input the files from both run 1 and run 2 (i.e ‘func1’ and ‘func2’).

This obviously involves concatonating them in some way e.g. with some sort of self made concatonate function (see Connect node with multiple output files to another node)

However, I am not sure exactly how this function would fit into my workflow. I have tried writing a few functions but always come back to the same problem… the node has two inputs but just one output!

Any help would be much appreciated.

Many thanks,

Paul

########## code extract ###############

infosource = Node(IdentityInterface(fields=[‘subject_id’,
‘contrasts’],
contrasts=contrast_list),
name=“infosource”)

infosource.iterables = [(‘subject_id’, subject_list)]

templates = {‘func1’: opj(preproc_dir,‘sub-{subject_id}_run-01_bold.nii’),
‘func2’: opj(preproc_dir,‘sub-{subject_id}_run-02_bold.nii’)
}

sf_func = Node(SelectFiles(templates,
base_directory=output_dir,
sort_filelist=True),
name=“sf_func”)

modelspec = Node(SpecifySPMModel(concatenate_runs=True, # FALSE
input_units=‘secs’,
output_units=‘secs’,
time_repetition=TR,
high_pass_filter_cutoff=128),
#functional_runs = [func1, func2],
#subject_info = [evs_run1, evs_run2],
#realignment_parameters = [rp_run1, rp_mov2]),
name=“modelspec”)

l1analysis = Workflow(name=‘l1analysis’)
l1analysis.base_dir = working_dir
l1analysis.connect([(infosource, sf_func, [(‘subject_id’, ‘subject_id’)]),
(sf_func, modelspec, [(‘func1’,‘functional_runs’)])])

Ahoi hoi @PaulF,

to be sure: do you want/need to concatenate runs (e.g., for timeseries extraction) or do you want to include two runs in your GLM?

In case of the latter, you don’t need to concatenate runs. Just set them as input to your modelspec node (in that case, you should set concatenate_runs=False). The nipype beginner’s guide provides a nice example for a two run 1st level GLM here.

HTH, cheers, Peer

Hi @PeerHerholz,

thank you very much for your quick response :slight_smile:

The link is extremely helpful, especially the get_subject_info function.

Also, using

templates = {‘func’: opj(preproc_dir,‘sub-{subject_id}_run-0*_bold.nii’)}

instead of

templates = {‘func1’: opj(preproc_dir,‘sub-{subject_id}_run-01_bold.nii’),
‘func2’: opj(preproc_dir,‘sub-{subject_id}_run-02_bold.nii’)
}

was a real gamechanger as it allows the SelectFiles node to input multiple runs but with just one input (i.e. ‘func’).

Many thanks and best wishes,

Paul

1 Like

Ahoi hoi @PaulF,

no biggie, I’m glad it was helpful.
I’m gonna mark this post as solved.

Have lots of fun with nipype, it’s great to know that you’re using it.

Best, Peer

I found another way which is recommended by nipype tutorial.
https://miykael.github.io/nipype_tutorial/notebooks/basic_mapnodes.html

1 Like