Nipype iterables using different number of runs for each subject?

We have a multi-session scan with several subjects. Each subject completed between 2-4 sessions and each session was between 1-5 runs.

Is there a way we can set up an iterable to take in a different number of runs for every session and every subject?

I was hoping we could pass a dictionary like where the first level is the subject ID, the second level is the session and the third level is the runs that were administered.

subj_dictionary = {'22014': {'1' : ['1','2','3'] ,'2': ['1','2','3','4']},
                   '21008': {'1' : ['2','3','4'] ,'3': ['1','2','3']}}

Currently we are implementing like:

subject_list = [ '22014','21008'#,'11013','12006'] 
session_list = ['1','2','3','4']
run_list = ['1','2','3','4','5']

infosource = pe.Node(
        interface=util.IdentityInterface(
        fields=['subject_id','session_id','run_id']), 
                     name="infosource")

infosource.iterables = ([('subject_id', subject_list), ('run_id',run_list),('session_id',session_list)])

But obviously that assumes the same # of runs for each session and the same number of sessions for each subject.

Is there another approach we’re missing?

Unfortunately nipype iterables are not that flexible. Consider using pydra, the improved semantics of iteration/joining (called split/combine) were a major motivation for rewriting the engine.

Interesting, and a bit of a bummer but I suppose it makes sense to rewrite if iterables can’t handle that (somewhat minimal) kind of flexibility. The docs for pydra look a bit dense and general (e.g., not nipype specific?). Any good tutorials to recommend at this stage?

https://nipype.github.io/pydra-tutorial

The main issue with switching is going to be the limited number of interfaces. You can find and contribute to task packages (Pydra has tasks, which unify interfaces and nodes) under nipype · GitHub, and there’s a wrapper for using nipype 1.x interfaces with pydra: GitHub - nipype/pydra-nipype1: Tools for importing nipype1 interfaces into Pydra.