nipype icon indicating copy to clipboard operation
nipype copied to clipboard

unequal number of sessions with iterables

Open s2334 opened this issue 4 years ago • 1 comments

In my experiment subjects took part in several fmri sessions on different days. However, some subjects could only attend some of the sessions whereas others attended all of them. I'm struggling to define infosource.iterables such that this is taken into account. For example, let’s say sub-01 took part in session s1 and s2, whereas sub-02 took part in all sessions. If I wanted to extract the anat_file of each subject I could do:

subject_list = ["01","02"]
sessions = ["s1", "s2", "s3"]
infosource = Node(IdentityInterface(fields=[‘subject_id’]), name=“infosource”)
infosource.iterables = [("subject_id", subject_list), ("session", sessions)]

anat_file = opj("sub-{subject_id}", {session}, "sub-{subject_id}_{session}_T1w.nii.gz")

templates = {"anat": anat_file}

selectfiles = Node(SelectFiles(templates), name=“selectfiles”)

wf.connect([( infosource, selectfiles, (["subject_id","subject_id"]), (["session","session"]))])

However this will fail because it assumes both subjects took part in all sessions. Is there a workaround?

s2334 avatar Dec 09 '20 03:12 s2334

Based on this link I also tried:

infosource.iterables = [("subject_id", ["01","02"]), 
                        ("session", {"01":["s1","s2"],"02":["s1","s2","s3"]})]

OSError: No files were found matching anat template: /sub-01/01/sub-01_01_T1w.nii.gz

And also

infosource1 = Node(IdentityInterface(fields=["subject_id"]), name="infosource1")
infosource1.iterables = [("subject_id", ["01","02"])]
infosource2 = Node(IdentityInterface(fields=["session"]), name="infosource2")
infosource2.iterables = [("session", {"01":["s1","s2"],"02":["s1","s2","s3"]})]
infosource2.itersource = ("infosource1","subject_id")

ValueError: The node wf.infosource2 itersource infosource1 was not found among the iterable predecessor nodes

But none of these worked. Any thoughts?

s2334 avatar Dec 10 '20 01:12 s2334